void CDataBunchGridCtrl::InsertDataBunch(int rowIndex, const DataBunch& dataBunch, const tstring& baseDirectory){ DataConverter converter; GV_ITEM item; item.mask = GVIF_TEXT; item.row = rowIndex; int colIndex = 0; item.col = colIndex; item.strText = converter.ConvertIntToString(rowIndex).c_str(); this->SetItem(&item); this->SetItemState(rowIndex, colIndex, GVIS_READONLY); colIndex++; item.col = colIndex; item.strText = dataBunch.GetName().c_str(); this->SetItem(&item); this->SetItemState(rowIndex, colIndex, GVIS_READONLY); colIndex++; CGridCellCheck* pCheckBoxCell = NULL; this->SetCellType(rowIndex, colIndex, RUNTIME_CLASS(CGridCellCheck)); pCheckBoxCell = (CGridCellCheck*)this->GetCell(rowIndex, colIndex); if (dataBunch.GetSaveYN() == TRUE){ pCheckBoxCell->SetCheck(TRUE); } else{ pCheckBoxCell->SetCheck(FALSE); } colIndex++; tstring fullDirectoryWithFileName = baseDirectory + TEXT("\\") + dataBunch.GetName() + TEXT("\\"); item.col = colIndex; item.strText = fullDirectoryWithFileName.c_str(); this->SetItem(&item); this->SetItemState(rowIndex, colIndex, GVIS_READONLY); }
void CItemCommerceSearchView::RefreshGrid(_RecordsetPtr& pSet,int row) { int iCol = m_cDisplay.GetColumnCount()-1; GV_ITEM Item; COleDateTime dTemp,dCompare; CGridCellCheck* pCell; BOOL bCheck; CString str; Item.mask = GVIF_TEXT|GVIF_FORMAT|GVL_BOTH|GVL_VERT ; Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS; m_cDisplay.SetListMode(TRUE); m_cDisplay.SetSingleRowSelection(FALSE); Item.row = row; Item.col = 0; Item.strText.Format("%d",row); m_cDisplay.SetItem(&Item); for(int i = 0; i<iCol; i++) { Item.col = i+1; Holder = pSet->GetCollect(m_iName[i].sItem.AllocSysString()); switch(m_iName[i].tType) { case 1: Item.strText = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder; break; case 2: dTemp = Holder.date; str = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder; if(str.IsEmpty()) { Item.strText = _T("- -"); } else Item.strText = dTemp.Format("%Y-%m-%d"); break; case 3: // dbNum = (double)Holder; // Item.strText.Format("%f",dbNum); Item.strText = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder; break; case 4: m_cDisplay.SetCellType(row,i+1, RUNTIME_CLASS(CGridCellCheck)); pCell = (CGridCellCheck*)m_cDisplay.GetCell(row,i+1); bCheck = (bool)Holder; if(bCheck) pCell->SetCheck(TRUE); else pCell->SetCheck(FALSE); Item.strText = ""; break; default: break; } m_cDisplay.SetItem(&Item); } m_cDisplay.Invalidate(); m_cDisplay.AutoSizeColumns(); }
void CItemCommerceSearchView::LoadData(void) { CGridCellCheck* pCellCheck; CGridCellDateTime* pCellDate; GV_ITEM Item; m_cSearchCase.DeleteNonFixedRows(); try{ int iCount ; strSQL = " select * from SearchCase where Check = TRUE order by ID"; theApp.ADOExecute(m_pTempSet, theApp.m_pSearchConn, strSQL); iCount = theApp.GetRecordCountEx(m_pTempSet); // if(m_iType) // delete [] m_iType; // m_iType = new int[iCount]; CString str; if(iCount !=0) m_pTempSet->MoveFirst(); int i = 0; if(m_iType) delete [] m_iType; m_iType = new ItemRow[iCount]; while(!m_pTempSet->EndOfFile) { str.Format("%d",i+1); m_cSearchCase.InsertRow(str, -1); Holder = m_pTempSet->GetCollect(_T("Name")); m_iType[i].sName = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder; Holder = m_pTempSet->GetCollect(_T("Item")); m_iType[i].sItem = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder; Holder = m_pTempSet->GetCollect(_T("Type")); m_iType[i].tType = (int)Holder; Holder = m_pTempSet->GetCollect(_T("Table")); m_iType[i].sTable = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder; Item.row = i+1; for(int j = 0;j<6; j++) { Item.mask = GVIF_TEXT|GVIF_FORMAT|GVL_BOTH|GVL_VERT ; Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS; Item.col = j; switch(j) { case 0: Item.strText.Format("%d",i+1); break; case 1: Item.strText = m_iType[i].sName; break; case 2: if(m_iType[i].tType==2) { m_cSearchCase.SetCellType(i+1,j, RUNTIME_CLASS(CGridCellDateTime)); pCellDate = (CGridCellDateTime*) m_cSearchCase.GetCell(i+1,j); pCellDate->SetTime(CTime::GetCurrentTime()); // Item.strText = _T("1900-1-1"); } // else Item.strText = _T(""); break; case 3: if(m_iType[i].tType == 2) { m_cSearchCase.SetCellType(i+1,j, RUNTIME_CLASS(CGridCellDateTime)); pCellDate = (CGridCellDateTime*) m_cSearchCase.GetCell(i+1,j); pCellDate->SetTime(CTime::GetCurrentTime()); // Item.strText = m_dCurrent.Format("%Y-%m-%d"); } // else Item.strText = _T(""); break; case 4: Item.strText = _T(""); break; case 5: if(m_iType[i].tType == 4) { m_cSearchCase.SetCellType(i+1,j, RUNTIME_CLASS(CGridCellCheck)); pCellCheck = (CGridCellCheck*)m_cSearchCase.GetCell(i+1,j); pCellCheck->SetCheck(FALSE); } Item.strText = _T(""); break; default: break; } m_cSearchCase.SetItem(&Item); } m_cSearchCase.Invalidate(); m_pTempSet->MoveNext(); i++; } m_cSearchCase.AutoSizeRows(); m_cSearchCase.SetColumnWidth(2,100); m_cSearchCase.SetColumnWidth(3,100); m_cSearchCase.SetColumnWidth(4,100); for(int m= 0; m<iCount;m++) { switch(m_iType[m].tType) { //RGB(0xFF, 0xFF, 0xE0) case 1: m_cSearchCase.SetItemBkColour(m+1,2,RGB(0,0,0)); m_cSearchCase.SetItemBkColour(m+1,3,RGB(0,0,0)); m_cSearchCase.SetItemBkColour(m+1,5,RGB(0,0,0)); m_cSearchCase.SetItemBkColour(m+1,4,RGB(0xFF, 0xFF, 0xE0)); m_cSearchCase.SetItemState(m+1,4,m_cSearchCase.GetItemState(m+1,4) & ~GVIS_READONLY); m_cSearchCase.SetItemState(m+1,2,m_cSearchCase.GetItemState(m+1,2) | GVIS_READONLY); m_cSearchCase.SetItemState(m+1,3,m_cSearchCase.GetItemState(m+1,3) | GVIS_READONLY); m_cSearchCase.SetItemState(m+1,5,m_cSearchCase.GetItemState(m+1,5) | GVIS_READONLY); break; case 2: m_cSearchCase.SetItemBkColour(m+1,2,RGB(0xFF, 0xFF, 0xE0)); m_cSearchCase.SetItemBkColour(m+1,3,RGB(0xFF, 0xFF, 0xE0)); m_cSearchCase.SetItemBkColour(m+1,5,RGB(0,0,0)); m_cSearchCase.SetItemBkColour(m+1,4,RGB(0, 0, 0)); m_cSearchCase.SetItemState(m+1,4,m_cSearchCase.GetItemState(m+1,4) | GVIS_READONLY); m_cSearchCase.SetItemState(m+1,2,m_cSearchCase.GetItemState(m+1,2) & ~GVIS_READONLY); m_cSearchCase.SetItemState(m+1,3,m_cSearchCase.GetItemState(m+1,3) & ~GVIS_READONLY); m_cSearchCase.SetItemState(m+1,5,m_cSearchCase.GetItemState(m+1,5) | GVIS_READONLY); break; case 3: m_cSearchCase.SetItemBkColour(m+1,2,RGB(0xFF, 0xFF, 0xE0)); m_cSearchCase.SetItemBkColour(m+1,3,RGB(0xFF, 0xFF, 0xE0)); m_cSearchCase.SetItemBkColour(m+1,5,RGB(0,0,0)); m_cSearchCase.SetItemBkColour(m+1,4,RGB(0, 0, 0)); m_cSearchCase.SetItemState(m+1,4, m_cSearchCase.GetItemState(m+1,4) | GVIS_READONLY); m_cSearchCase.SetItemState(m+1,2,m_cSearchCase.GetItemState(m+1,2) & ~GVIS_READONLY); m_cSearchCase.SetItemState(m+1,3,m_cSearchCase.GetItemState(m+1,3) & ~GVIS_READONLY); m_cSearchCase.SetItemState(m+1,5,m_cSearchCase.GetItemState(m+1,5) | GVIS_READONLY); break; case 4: m_cSearchCase.SetItemBkColour(m+1,2,RGB(0, 0, 0)); m_cSearchCase.SetItemBkColour(m+1,3,RGB(0, 0, 0)); m_cSearchCase.SetItemBkColour(m+1,5,RGB(0xFF, 0xFF, 0xE0)); m_cSearchCase.SetItemBkColour(m+1,4,RGB(0, 0, 0)); m_cSearchCase.SetItemState(m+1,4, m_cSearchCase.GetItemState(m+1,4) | GVIS_READONLY); m_cSearchCase.SetItemState(m+1,2, m_cSearchCase.GetItemState(m+1,2) | GVIS_READONLY); m_cSearchCase.SetItemState(m+1,3, m_cSearchCase.GetItemState(m+1,3) | GVIS_READONLY); m_cSearchCase.SetItemState(m+1,5, m_cSearchCase.GetItemState(m+1,5) & ~GVIS_READONLY); break; default: break; } m_cSearchCase.SetItemState(m+1,1,m_cSearchCase.GetItemState(m+1,1) | GVIS_READONLY); } m_pTempSet->Close(); } catch(_com_error &e)///捕捉异常 { CString errormessage; errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage()); AfxMessageBox(errormessage);///显示错误信 return; } catch(...) { AfxMessageBox("未知错误..."); return; } }