Exemplo n.º 1
0
void CNPBPSType1Grid::filter()
{
	try
	{
	 CMenu *pMnenu;
	pMnenu= GetPopupMenu();

	if ( CNPBPSType1Grid::insertFilterFlag==0)
	{
			addItemToCombobox();
			CNPBPSType1Grid::insertFilterFlag=1;
			InsertRow(0);
			for (int col_count=0;col_count<13;col_count++)
			{
				CUGCell cell;
				int row=0;
				int col=col_count;
				cell.ClearAll();
				cell.SetCellType(UGCT_DROPLIST);
				cell.SetCellTypeEx(UGCT_DROPLISTHIDEBUTTON);
				cell.SetParam(CELLTYPE_IS_EDITABLE);
				QuickSetRange(col,row,col,row,&cell);
				QuickSetLabelText(col,row,str[col_count]);
			}
			pMnenu->CheckMenuItem(2001,MF_CHECKED);

	}
	else
	{
		
		DeleteRow(0);
		CNPBPSType1Grid::insertFilterFlag=0;
		
		pMnenu->CheckMenuItem(2001,MF_UNCHECKED);
	}
	RedrawAll();
	}
	catch(_com_error & ce)
	{
		AfxMessageBox(ce.Description()+L"   filter");			
	} 
 }
Exemplo n.º 2
0
int CUGMem::SortBy(long startRow, long endRow, int *cols,int numCols,int flags)
{
	if(m_rowInfo == NULL)
		return UG_ERROR;

	if(startRow >= endRow)
		return UG_ERROR;


	UGMemRI *OldListRowInfo;
	UGMemRI *OldListNextRowInfo;
	UGMemRI *NewListRowInfo;
	UGMemRI *NewListStartRowInfo;

	UGMemRI *NewListRowInfo_HalfPt;
	
	CUGCell* cell1;
	CUGCell* cell2;
	CUGCell	 blankCell;

	int		index;
	int		rt;
	BOOL    bInserted = FALSE;
	int		halfPtOffset = 0;

	BOOL	bSkip;
	UGMemRI* lastSkipRow;

	long	rowCount = startRow;
		
	//goto the first row, and copy the first row over to the sorted list
	GotoRow(startRow);
	NewListRowInfo		= m_rowInfo;
	NewListStartRowInfo = m_rowInfo;
	NewListRowInfo_HalfPt = NewListRowInfo;
	//goto the second row and make that the unsorted list
	OldListRowInfo = m_rowInfo->next;	
	m_rowInfo->next = NULL;

	//copy the (pointers to) cells from the columns to be sorted into the lookup list
	NewListRowInfo->cellLookup = new CUGCell*[numCols];
	m_colInfo = NewListRowInfo->col;
	m_currentCol = 0;	// TD JF added (for init as below) 
	for(index =0; index < numCols;index++){
		if(GotoCol(cols[index])==UG_SUCCESS)
			NewListRowInfo->cellLookup[index] = m_colInfo->cell;
		else
			NewListRowInfo->cellLookup[index] = NULL;
	}

	
	//main row sort loop - while there are items in the unsorted list
	while(OldListRowInfo != NULL && (rowCount < endRow) ){
		
		//save the next row pointer
		OldListNextRowInfo = OldListRowInfo->next;

		//copy the (pointers to) cells from the columns to be sorted into the lookup list
		OldListRowInfo->cellLookup = new CUGCell*[numCols];
		m_colInfo = OldListRowInfo->col;
		m_currentCol = 0;
		for(index =0; index < numCols;index++){
			if(GotoCol(cols[index])==UG_SUCCESS)
			{
				OldListRowInfo->cellLookup[index] = m_colInfo->cell;
			}
			else
			{
				OldListRowInfo->cellLookup[index] = NULL;
		}
		}

		//check the half point 
		//================================================
		//get a cell from the unsorted list
		if(OldListRowInfo->cellLookup[0] != NULL)
			cell1 = OldListRowInfo->cellLookup[0];
		else{
			blankCell.ClearAll();
			blankCell.ClearMemory();
			cell1 = &blankCell;
		}

		//get a cell from the sorted list
		if(NewListRowInfo_HalfPt->cellLookup[0] != NULL)
			cell2 = NewListRowInfo_HalfPt->cellLookup[0];
		else{
			blankCell.ClearAll();
			blankCell.ClearMemory();
			cell2 = &blankCell;
		}
		
		//call the evaluation function
		rt = m_ctrl->OnSortEvaluate(cell1,cell2,flags);
		if(rt <= 0){
			NewListRowInfo = NewListStartRowInfo;
			halfPtOffset -=1;
		}
		else{
			NewListRowInfo = NewListRowInfo_HalfPt;
			halfPtOffset +=1;
		}
		if(halfPtOffset == -2){
			halfPtOffset = 0;
			if(NewListRowInfo_HalfPt->prev != NULL)
				if(NewListRowInfo_HalfPt->prev->cellLookup != NULL)
					NewListRowInfo_HalfPt = NewListRowInfo_HalfPt->prev;
		}
		if(halfPtOffset == 2){
			halfPtOffset = 0;
			if(NewListRowInfo_HalfPt->next != NULL)
				NewListRowInfo_HalfPt = NewListRowInfo_HalfPt->next;
		}
		//================================================

		bSkip = TRUE;
		lastSkipRow = NULL;

		//main loop to check an unsorted item against the sorted list
		//NewListRowInfo = NewListStartRowInfo;
		bInserted = FALSE;
		while(NewListRowInfo != NULL){

			//sort by the columns in their given order
			for(index = 0; index < numCols; index++){

				//get a cell from the unsorted list
				if(OldListRowInfo->cellLookup[index] != NULL)
					cell1 = OldListRowInfo->cellLookup[index];
				else{
					blankCell.ClearAll();
					blankCell.ClearMemory();
					cell1 = &blankCell;
				}

				//get a cell from the sorted list
				if(NewListRowInfo->cellLookup[index] != NULL)
					cell2 = NewListRowInfo->cellLookup[index];
				else{
					blankCell.ClearAll();
					blankCell.ClearMemory();
					cell2 = &blankCell;
				}
				
				//call the evaluation function
				rt = m_ctrl->OnSortEvaluate(cell1,cell2,flags);
				if(rt < 0){					
					if(bSkip && lastSkipRow != NULL){
						NewListRowInfo = lastSkipRow;
						bSkip = FALSE;
						break;
					}
					OldListRowInfo->next = NewListRowInfo;
					OldListRowInfo->prev = NewListRowInfo->prev;
					NewListRowInfo->prev = OldListRowInfo;
					if(OldListRowInfo->prev !=NULL)
						OldListRowInfo->prev->next = OldListRowInfo;
					if(NewListRowInfo == NewListStartRowInfo)
						NewListStartRowInfo = OldListRowInfo;
					bInserted = TRUE;
					rowCount++;
					break;
				}
				//if equal then check the next column to sort by
				else if(rt == 0){
				}
				else{
					break;
				}
			}
		
			//if the item was inserted into the sorted then then break
			if(bInserted == TRUE)
				break;

			//if at the end of the sorted list then add the item
			if(NewListRowInfo->next == NULL){
				NewListRowInfo->next = OldListRowInfo;
				OldListRowInfo->prev = NewListRowInfo;
				OldListRowInfo->next = NULL;
				rowCount++;
				break;
			}

			//perform row skips
			if(bSkip){
				lastSkipRow = NewListRowInfo;
				for(int loop = 0; loop< 100; loop++){
					if(NewListRowInfo->next != NULL){
						NewListRowInfo = NewListRowInfo->next;
					}
					else{
						NewListRowInfo = lastSkipRow;
						bSkip = FALSE;
						break;
					}
				}
			}
			else{
				NewListRowInfo = NewListRowInfo->next;
			}
		}

		OldListRowInfo = OldListNextRowInfo;
	}

	//reset the linked list positioning pointers
	m_currentRow = startRow;
	m_currentCol = 0;
	m_rowInfo = NewListStartRowInfo;
	m_colInfo = NewListStartRowInfo->col;

	//add the rest of the rows, if they were not part of the sort
	if(rowCount == endRow && OldListRowInfo != NULL){
		GotoRow(endRow);
		m_rowInfo->next = OldListRowInfo;
		OldListRowInfo->prev = m_rowInfo;
		
		m_currentRow = startRow;
		m_rowInfo = NewListStartRowInfo;
	}

	//delete all of the cell lookups
	GotoRow(0);
	do
	{
		if(m_rowInfo->cellLookup != NULL)
		{
			delete[] m_rowInfo->cellLookup;
		}
		m_rowInfo->cellLookup = NULL;
	}while(NextRow() == UG_SUCCESS);
	GotoRow(0);

	return UG_SUCCESS;
}