?? schoolmanagesys_2dlg.cpp
字號:
{
// TODO: 在此添加命令處理程序代碼
CAdoConnection* tmp;
tmp=&m_AdoConnection;
CDialog_Amend_users *dlg=new CDialog_Amend_users(NULL,tmp);
ASSERT(dlg);
dlg->DoModal();
}
void CSchoolManageSys_2Dlg::OnTvnSelchangedTreeMain(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
// TODO: 在此添加控件通知處理程序代碼
//取當前項
m_isstudent=TRUE;
h_current=m_Treeinfo.GetSelectedItem();
h_parent=m_Treeinfo.GetParentItem(h_current);
if(m_Treeinfo.GetChildItem(h_current)==NULL){
CString tmp;
tmp=m_Treeinfo.GetItemText(h_current);
this->ShowBaseinfo(tmp);
}else {
}
*pResult = 0;
}
// 顯示基本信息在List控件中
BOOL CSchoolManageSys_2Dlg::ShowBaseinfo(CString m_info)
{
CString tmp;
int cid;
//CAdoRecordSet m_AdoRecordSet_Studentinfo;
if(m_info=="") return FALSE;
tmp.Format("classname=\'%s\'",m_info);
if(!m_AdoRecordSet_Classinfo.IsBOF())
m_AdoRecordSet_Classinfo.MoveFirst();
m_AdoRecordSet_Classinfo.Find(tmp);
if(!m_AdoRecordSet_Classinfo.IsEOF()){
m_AdoRecordSet_Classinfo.GetCollect("classid",cid);
tmp.Format("SELECT *from studentrecord WHERE classid=%d",cid);
//tmp.Format("classid=%d",cid);
//打開學生記錄集
//m_AdoRecordSet_Studentinfo.SetAdoConnection(&m_AdoConnection);
//m_AdoRecordSet_Studentinfo.SetCursorLocation();
if(m_AdoRecordSet_Studentinfo.IsOpen()){
m_AdoRecordSet_Studentinfo.Requery();
m_AdoRecordSet_Studentinfo.Close();
}
m_AdoRecordSet_Studentinfo.Open(tmp,adCmdText);
if(!m_AdoRecordSet_Studentinfo.IsEOF()){
m_AdoRecordSet_Studentinfo.MoveFirst();
//顯示數據在List控件里
//清除List控件里的數據
int nField=m_AdoRecordSet_Studentinfo.GetFieldsCount();
if(nField){
for(int i=0;i<nField;i++){
m_Listinfo.DeleteColumn(0);
}
}
m_Listinfo.DeleteAllItems();
DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | /*LVS_EX_SUBITEMIMAGES |*/
m_Listinfo.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;
CString fieldinfo;
for(int i=0;i<nField-1;i++){
fieldinfo=m_AdoRecordSet_Studentinfo.GetFieldName(i);
int len=fieldinfo.GetLength();
TCHAR* szBuffer = new TCHAR[len + 1];
strcpy(szBuffer, fieldinfo.GetBuffer(len));
fieldinfo.ReleaseBuffer();
lvColumn.pszText = szBuffer;
m_Listinfo.InsertColumn(i,&lvColumn);
}
long count=m_AdoRecordSet_Studentinfo.GetRecordCount();
for(int i=0;i<count;i++){
for(int j=0;j<nField-1;j++){
m_AdoRecordSet_Studentinfo.GetCollect(j,tmp);
if(j==0){
m_Listinfo.InsertItem(i,tmp,0);
m_Listinfo.SetTextColor(RGB(128,0,200));
continue;
}
m_Listinfo.SetItemText(i,j,tmp);
}
if(!m_AdoRecordSet_Studentinfo.IsEOF())
m_AdoRecordSet_Studentinfo.MoveNext();
}
m_AdoRecordSet_Studentinfo.Cancel();
}
else{
AfxMessageBox("沒有這個班級的相關信息");
m_Listinfo.DeleteAllItems();
m_AdoRecordSet_Studentinfo.Cancel();
return FALSE;
}
}
else return FALSE;
return TRUE;
}
void CSchoolManageSys_2Dlg::OnNMRclickTreeMain(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知處理程序代碼
*pResult = 0;
SetFocus();
POINT p;
::GetCursorPos(&p);
HTREEITEM h_current=m_Treeinfo.GetSelectedItem();
CPoint point(p);
ClientToScreen(&point);
HTREEITEM hNewSel=m_Treeinfo.HitTest(point);
if(NULL==hNewSel){
m_Treeinfo.SelectItem(NULL);
}else if(h_current!=hNewSel){
m_Treeinfo.SelectItem(hNewSel);
SetFocus();
}
/*CString tmp;
tmp=m_Treeinfo.GetItemText(hNewSel);
AfxMessageBox(tmp);*/
CMenu *psubmenu=popmenu->GetSubMenu(0);
psubmenu->TrackPopupMenu(TPM_LEFTALIGN|
TPM_RIGHTBUTTON,
point.x-230,
point.y-215,
AfxGetMainWnd());
}
void CSchoolManageSys_2Dlg::OnLvnItemActivateListInfo(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMIA = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
*pResult = 0;
// TODO: 在此添加控件通知處理程序代碼
ischangephoto=TRUE;
int i=m_Listinfo.GetNextItem(-1,LVNI_SELECTED);
m_bitmap.DeleteObject();
CString tmp,str;
tmp=m_Listinfo.GetItemText(i,1);
str.Format("studynum=\'%s\'",tmp);
if(!m_AdoRecordSet_Studentinfo.IsBOF())
m_AdoRecordSet_Studentinfo.MoveFirst();
m_AdoRecordSet_Studentinfo.Find(str);
str.Format("SELECT *FROM lessonrecord WHERE studynum=\'%s\'",tmp);
if(m_AdoRecordSet_Lessoninfo.IsOpen())
m_AdoRecordSet_Lessoninfo.Close();
if(!m_AdoRecordSet_Lessoninfo.IsOpen())
m_AdoRecordSet_Lessoninfo.Open(str,adCmdText);
if(!m_AdoRecordSet_Studentinfo.IsEOF()){
m_AdoRecordSet_Studentinfo.GetChunk("photo",m_bitmap);
CRect rect(370, 100, 500, 260);
InvalidateRect(rect);
CString tmpname;
m_AdoRecordSet_Studentinfo.GetCollect("姓名",tmpname);
str.Format("%s 的課程信息",tmpname);
if(!m_AdoRecordSet_Lessoninfo.IsEOF())
{
m_Datagridinfo.put_Caption(str);
m_Datagridinfo.putref_DataSource(NULL);
m_Datagridinfo.putref_DataSource((LPUNKNOWN)m_AdoRecordSet_Lessoninfo.GetRecordset());
m_Datagridinfo.put_AllowAddNew(TRUE);
m_Datagridinfo.put_AllowDelete(TRUE);
m_Datagridinfo.put_AllowUpdate(TRUE);
m_Datagridinfo.Refresh();
}
else {
AfxMessageBox("沒有相關課程信息");
return;
}
}else {
AfxMessageBox("沒有相關信息");
return ;
}
UpdateData(FALSE);
}
void CSchoolManageSys_2Dlg::OnBnClickedButtonChanagePhoto()
{
// TODO: 在此添加控件通知處理程序代碼
if(!ischangephoto){
AfxMessageBox("請選擇一個人進行編輯");
return;
}
if(m_isstudent){
if(m_AdoRecordSet_Studentinfo.GetRecordCount()<1) return ;
static char BASED_CODE szFilter[] = "BMP Files (*.bmp)|*.bmp|All Files (*.*)|*.*||";
CFileDialog dlg(TRUE,"BMP",NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);
if(dlg.DoModal()==IDOK){
strpathname=dlg.GetPathName();
if(strpathname!=""){
if(m_AdoRecordSet_Studentinfo.AppendChunk("photo",LPCTSTR(strpathname))){
CFile file;
if (file.Open(LPCTSTR(strpathname), CFile::modeRead))
{
long length = (long)file.GetLength();
char *pdata = new char[length + 1];
if (file.Read(pdata, length) == (DWORD)length)
{
BITMAPFILEHEADER bmfHeader;
DWORD bmfHeaderLen = sizeof(bmfHeader);
strncpy((LPSTR)&bmfHeader, (LPSTR)pdata, bmfHeaderLen);
if (bmfHeader.bfType == (*(WORD*)"BM") )
{
LPSTR lpDIB = pdata + bmfHeaderLen;
BITMAPINFOHEADER &bmiHeader = *(LPBITMAPINFOHEADER)lpDIB;
BITMAPINFO &bmInfo = *(LPBITMAPINFO)lpDIB;
LPVOID lpDIBBits = pdata + ((BITMAPFILEHEADER *)pdata)->bfOffBits;
CWindowDC dc(this);
HBITMAP hBmp = CreateDIBitmap(dc.m_hDC, &bmiHeader, CBM_INIT, lpDIBBits, &bmInfo, DIB_RGB_COLORS);
if (m_bitmap.GetSafeHandle() != NULL) m_bitmap.DeleteObject();
m_bitmap.Attach(hBmp);
Invalidate();
}
}
delete[] pdata;
pdata = NULL;
}
}
}
}
}
Invalidate();
UpdateData(FALSE);
}
void CSchoolManageSys_2Dlg::OnBnClickedButtonFlushnew()
{
// TODO: 在此添加控件通知處理程序代碼
if(UpdateData(FALSE)){
strpathname="";
if(!m_AdoRecordSet_Bookinfo.Update()){
AfxMessageBox("刷新失敗!");
}
}
}
void CSchoolManageSys_2Dlg::OnBnClickedButtonQuery()
{
// TODO: 在此添加控件通知處理程序代碼
CDialog_Query *dlg=new CDialog_Query;
ASSERT(dlg);
dlg->DoModal();
}
void CSchoolManageSys_2Dlg::OnDisplayselected()
{
// TODO: 在此添加命令處理程序代碼
CDataGridShow *dlg=new CDataGridShow;
ASSERT(dlg);
dlg->DoModal();
}
void CSchoolManageSys_2Dlg::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
{
// TODO: 在此處添加消息處理程序代碼
SetFocus();
ClientToScreen(&point);
CMenu * psubmenu=popmenu->GetSubMenu(1);
psubmenu->TrackPopupMenu(TPM_LEFTALIGN|
TPM_RIGHTBUTTON,
point.x-230,
point.y-215,
this);
}
void CSchoolManageSys_2Dlg::OnBnClickedButtonChe()
{
// TODO: 在此添加控件通知處理程序代碼
if(!m_AdoConnection.RollbackTrans()){
AfxMessageBox("操作失敗");
return;
}
}
void CSchoolManageSys_2Dlg::OnBnClickedButtonHui()
{
// TODO: 在此添加控件通知處理程序代碼
if(!m_AdoConnection.CommitTrans()){
AfxMessageBox("操作失敗");
return ;
}
}
void CSchoolManageSys_2Dlg::OnQuery()
{
// TODO: 在此添加命令處理程序代碼
CDialog_Query *dlg=new CDialog_Query;
ASSERT(dlg);
dlg->DoModal();
}
void CSchoolManageSys_2Dlg::OnNewclass()
{
// TODO: 在此添加命令處理程序代碼
CDialogNew *dlg=new CDialogNew;
ASSERT(dlg);
dlg->m_select=1;
dlg->DoModal();
}
void CSchoolManageSys_2Dlg::OnNewstudent()
{
// TODO: 在此添加命令處理程序代碼
CDialogNew *dlg=new CDialogNew;
ASSERT(dlg);
dlg->m_select=0;
dlg->DoModal();
}
void CSchoolManageSys_2Dlg::OnNewteacher()
{
// TODO: 在此添加命令處理程序代碼
CDialogNew *dlg=new CDialogNew;
ASSERT(dlg);
dlg->m_select=3;
dlg->DoModal();
}
void CSchoolManageSys_2Dlg::OnNewdepartment()
{
// TODO: 在此添加命令處理程序代碼
CDialogNew *dlg=new CDialogNew;
ASSERT(dlg);
dlg->m_select=2;
dlg->DoModal();
}
void CSchoolManageSys_2Dlg::OnNewconsortium()
{
// TODO: 在此添加命令處理程序代碼
CDialogNew *dlg=new CDialogNew;
ASSERT(dlg);
dlg->m_select=4;
dlg->DoModal();
}
void CSchoolManageSys_2Dlg::OnNewcollege()
{
// TODO: 在此添加命令處理程序代碼
CDialogNew *dlg=new CDialogNew;
ASSERT(dlg);
dlg->m_select=5;
dlg->DoModal();
}
void CSchoolManageSys_2Dlg::OnDelete()
{
// TODO: 在此添加命令處理程序代碼
CDialog_DeleteData *dlg=new CDialog_DeleteData;
ASSERT(dlg);
dlg->DoModal();
}
void CSchoolManageSys_2Dlg::OnAmend()
{
// TODO: 在此添加命令處理程序代碼
CDialogAmendData *dlg=new CDialogAmendData;
ASSERT(dlg);
dlg->DoModal();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -