2008年(909)
分类:
2008-05-06 21:32:20
下载源代码
BOOL CListDlg::OnInitDialog() { CDialog::OnInitDialog(); SetWindowText("学生成绩管理"); // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon GetDlgItem(IDC_STRAT)->EnableWindow(FALSE); this->Enable(FALSE); m_pDB=new CDaoDatabase; CString sPath; GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH 1),MAX_PATH); sPath.ReleaseBuffer (); int nPos; nPos=sPath.ReverseFind (''\\''); sPath=sPath.Left (nPos); nPos=sPath.ReverseFind(''\\''); sPath=sPath.Left (nPos); CString lpszFile = sPath "\\db6.mdb"; try{ m_pDB->Open(lpszFile); } catch(CDaoException* e) { AfxMessageBox(e->m_pErrorInfo->m_strDescription,MB_ICONEXCLAMATION); delete m_pDB; e->Delete(); return FALSE; } CDaoTableDefInfo tabInfo; int nTableDefCount = m_pDB->GetTableDefCount(); for (int i = 0; i < nTableDefCount; i ) { m_pDB->GetTableDefInfo(i,tabInfo); if (tabInfo.m_lAttributes & dbSystemObject) continue; m_Com.AddString(tabInfo.m_strName); } m_pRecordSet=new CDaoRecordset(m_pDB); m_bTF=TRUE; m_bCR=FALSE; return TRUE; // return TRUE unless you set the focus to a control }它的主要任务是打开数据库和表的名字
void CListDlg::OnStrat() { if(m_pRecordSet->IsOpen()) m_pRecordSet->Close(); m_List1.DeleteAllItems(); if(nField!=0) { for(long i=0;i3、而OnGetdispinfoList(long row,long column) 最为有用,可以在很多方面调用:Open(dbOpenDynaset, strSQL); m_pRecordSet->m_strFilter.Empty(); } catch(CDaoException *e) { AfxMessageBox(e->m_pErrorInfo->m_strDescription,MB_ICONEXCLAMATION); delete m_pRecordSet; m_pDB->Close(); delete m_pDB; e->Delete(); return ; } if(m_pRecordSet != NULL) { m_pImageList = new CImageList(); m_pImageList->Create(IDB_BITMAP4, 16, 1, RGB(255,0,0)); m_List1.SetImageList(m_pImageList, LVSIL_SMALL); /* set extended stlyes*/ DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | /*LVS_EX_SUBITEMIMAGES |*/ m_List1.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); LVS_EX_HEADERDRAGDROP | LVS_EX_TRACKSELECT; LV_COLUMN lvColumn; lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; lvColumn.fmt = LVCFMT_LEFT; lvColumn.cx = 67; nField=m_pRecordSet->GetFieldCount(); for(int i = 0; i < nField; i ) // set up columns { CDaoFieldInfo m_fieldinfo; m_pRecordSet->GetFieldInfo(i, m_fieldinfo);//get field name int len = m_fieldinfo.m_strName.GetLength(); CString temp = m_fieldinfo.m_strName; TCHAR* szBuffer = new TCHAR[len 1]; strcpy(szBuffer, temp.GetBuffer(len)); temp.ReleaseBuffer(); lvColumn.pszText = szBuffer; m_List1.InsertColumn(i, &lvColumn);//insert column delete szBuffer; } /*set number of items in ListView*/ m_pRecordSet->MoveFirst(); m_pRecordSet->MoveLast(); long count =m_pRecordSet->GetRecordCount();//Get number of records this->OnGetdispinfoList( count, nField); } GetDlgItem(IDC_STRAT)->EnableWindow(FALSE); this->Enable(TRUE); }
void CListDlg::OnGetdispinfoList(long row,long column) { if(!m_pRecordSet) return; COleVariant varValue; for(long i=0;i其它的可以看源码。SetAbsolutePosition(i);//Set the file to desired index } catch(CDaoException* e) { AfxMessageBox(e->m_pErrorInfo->m_strDescription, MB_ICONEXCLAMATION ); e->Delete(); return; } for(long j=0;j
GetFieldValue(j, varValue); else m_pRecordSet->GetFieldValue(0, varValue); } catch(CDaoException* e) { AfxMessageBox(e->m_pErrorInfo->m_strDescription, MB_ICONEXCLAMATION ); e->Delete(); return; } const VARIANT* variant = LPCVARIANT(varValue); if(variant->vt & VT_BYREF) return; CString st; switch(variant->vt) { case VT_ERROR:{ st="Error"; break; } case VT_I2:{ st.Format("%d", variant->iVal); break; } case VT_I4:{ st.Format( "%d", variant->lVal); break; } case VT_R4:{ st.Format( "%.2f", variant->fltVal); break;} case VT_R8:{ st.Format( "%.2f", variant->dblVal); break; } case VT_CY:{ COleCurrency c(varValue); st = c.Format();//ie. 1.00 break; } case VT_DATE:{ COleDateTime t(variant->date); st = t.Format( "%B %d, %Y" );//Day of Week, Month Day, Year break; } case VT_BSTR:{ st = V_BSTRT( &varValue );//convert BSTR to CString break; } case VT_BOOL:{ if(variant->boolVal) st="TRUE"; else st= "FALSE"; break; } case VT_UI1:{st=(CString)((char*)variant->bVal); break; } default:{ break; } } if(j==0) m_List1.InsertItem(i,st,0); else m_List1.SetItemText(i,j,st); } } }