基于MYSQL的医院综合信息管理系统设计报告 下载本文

// 异常: OCX 属性页应返回 FALSE }

void CDurgDlg::AddToGrid(CString str) { CADOConn m_AdoConn; m_AdoConn.OnInitADOConn(); CString sql; sql.Format(str); _RecordsetPtr m_pRecordset; m_pRecordset = m_AdoConn.GetRecordSet((_bstr_t)sql); while(m_AdoConn.m_pRecordset->adoEOF==0) { m_grid.InsertItem(0,CString(\ m_grid.SetItemText(0,0,(CString)(char*)(_bstr_t)m_pRecordset->GetCollect(\ m_grid.SetItemText(0,1,(CString)(char*)(_bstr_t)m_pRecordset->GetCollect(\ m_grid.SetItemText(0,2,(CString)(char*)(_bstr_t)m_pRecordset->GetCollect(\ m_grid.SetItemText(0,3,(CString)(char*)(_bstr_t)m_pRecordset->GetCollect(\ m_pRecordset->MoveNext(); } m_AdoConn.ExitConnect(); UpdateData(true); }

void CDurgDlg::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代码 // CDialogEx::OnOK(); UpdateData(true); if(m_no.IsEmpty()) { MessageBox(CString(\编号不能为空!\ return; } if(m_name.IsEmpty()) { MessageBox(CString(\名称不能为空!\ return; } CADOConn m_AdoConn;

49

m_AdoConn.OnInitADOConn(); _bstr_t sql; sql = \ _RecordsetPtr m_pRecordset;

m_pRecordset=m_AdoConn.GetRecordSet(sql); try { m_pRecordset->AddNew();//添加新行 m_pRecordset->PutCollect(\ m_pRecordset->PutCollect(\ m_pRecordset->PutCollect(\ m_pRecordset->PutCollect(\ m_pRecordset->Update();//更新数据库 m_AdoConn.ExitConnect();//断开数据库连接 } catch(...) { MessageBox(CString(\操作失败\ return; } MessageBox(CString(\保存成功.\ m_grid.DeleteAllItems();//删除grid中原来的数据 CString str; str=\ AddToGrid(str);//重新遍历 }

void CDurgDlg::OnBnClickedChange() { // TODO: 在此添加控件通知处理程序代码 UpdateData(true); CADOConn m_AdoConn; m_AdoConn.OnInitADOConn(); CString tempSql; tempSql.Format(CString(\`mydb`.`durg` `name`='%s',`price`='%s',`inventory`='%s'

`durgno`='%s'\ m_AdoConn.ExecuteSQL((_bstr_t)tempSql); m_AdoConn.ExitConnect();

SET

WHERE

50

MessageBox(CString(\修改成功.\ m_grid.DeleteAllItems();//删除grid中原来的数据 CString str; str=\ AddToGrid(str);//重新遍历 }

void CDurgDlg::OnBnClickedDelete() { // TODO: 在此添加控件通知处理程序代码 UpdateData(true); CADOConn m_AdoConn; m_AdoConn.OnInitADOConn(); CString tempSql; tempSql.Format(CString(\ CString tenpstr; tenpstr.Format(CString(\是否要删除%s的记录\ if(MessageBox(tenpstr,CString(\提示\ { m_AdoConn.ExecuteSQL((_bstr_t)tempSql); m_AdoConn.ExitConnect(); MessageBox(CString(\删除成功.\ m_grid.DeleteAllItems();//删除grid中原来的数据 CString str; str=\ AddToGrid(str);//重新遍历 } }

void CDurgDlg::OnBnClickedClear() { // TODO: 在此添加控件通知处理程序代码 m_no = _T(\ m_price = _T(\ m_name = _T(\

51

m_inventory = _T(\ UpdateData(false); }

void CDurgDlg::OnBnClickedSelect() { // TODO: 在此添加控件通知处理程序代码 m_grid.DeleteAllItems(); UpdateData(true); CString str1,str2; GetDlgItem(IDC_EDIT_NO)->GetWindowText(str1); str2=CString(\ AddToGrid(str2);// 遍历功能信息记录 }

void CDurgDlg::OnNMClickDurg(NMHDR *pNMHDR, LRESULT *pResult) { LPNMITEMACTIVATE pNMItemActivate reinterpret_cast(pNMHDR); // TODO: 在此添加控件通知处理程序代码 int nItem=0; POSITION pos = m_grid.GetFirstSelectedItemPosition(); if (pos == NULL) TRACE0(\ else { while (pos) { nItem = m_grid.GetNextSelectedItem(pos);//找到被选中的行号 TRACE1(\ } //读取被选中行的数据 m_no=m_grid.GetItemText(nItem,0); m_name=m_grid.GetItemText(nItem,1); m_price=m_grid.GetItemText(nItem,2); m_inventory=m_grid.GetItemText(nItem,3); UpdateData(FALSE);//更新对话框 }

=

52