1、数据库实验报告 医院综合信息管理系统 专 业 班 级 组 长 组 员 指导教师 目录 一、 需求分析: 2 1.1人员信息管理系统 2 1.2门诊信息管理系统 3 1.3收费信息管理系统 3 二、系统分析: 3 2.1系统功能介绍 3 2.2功能模块 3 三、数据库设计:
2、 4 3.1 E-R图: 4 3.2数据字典: 6 四、前台设计: 8 4.1.医生信息管理: 8 4.2.病人信息管理: 8 4.3.药品信息管理: 9 4.4.诊断界面: 10 4.5.处方界面: 10 4.6.病人处方查询: 10 4.7.收费信息管理: 11 五、程序调试结果: 12 六、总结: 22 内容提要 : 本系统是一个基于MYSQL而建立的医院综合信息管理系统。用Microsoft Visual Studio 2010结合MYSQL开发了3个模块。包括有人员信息管理,门诊信息管理,收费信息管理。其中人员信息管理其中有医生信息管理,病人信息管
3、理和药品信息管理。门诊信息管理其中则含有就诊信息管理,病人处方管理。这3模块基本实现了医院综合信息管理系统的需求。 【关键词】: Microsoft Visual Studio 2010,MYSQL,人员信息管理,门诊信息管理,收费信息管理 一、 需求分析: 整个医院综合信息管理系统可分为三个子系统:人员信息管理系统,门诊信息管理系统,收费信息管理系统。 1.1人员信息管理系统 人员信息管理即对于人和物品的管理,人则包含医生及医护人员,就诊病人,还有药品等。我们需要对他们的基本信息进行记录,并且还要具有增加,删除,修改,查询等基本功能,所以我建立了一个基本信息管理模块来专门处理。
4、我也在数据库中对应了三张表:doctor,patient,durg以便对人员信息管理信息进行存储。 1.2门诊信息管理系统 对于就诊信息的管理,病人看病后会产生新的数据,例如医生对病人的诊断信息,以及药品处方信息。而与其对应的则是我做的门诊信息管理,其中我做了两个窗口,一个是诊断信息窗口,主要实现对诊断信息的储存;另一个是处方信息窗口,有增加、删除、修改药品等功能。然后我另做了一个查询的窗口,以便病人查询自己的处方记录。对应数据库,我做了两张表:diagnosis,prescription。 1.3收费信息管理系统 对于收费信息管理,病人拿到处方后,就会取药,付款。则我需要对其总价进行
5、计算,再者就是对于药品库存进行修改。于是对应要求我做了一个收费前台。虽然在数据库中没有对应相应的表。可是它的操作主要是对prescription的读取,以及对durg库存的修改。 二、系统分析: 整个医院综合信息管理系统可分为三个子系统:人员信息管理系统,门诊信息管理系统,收费信息管理系统。 2.1系统功能介绍 2. 1. 1 人员信息管理系统的功能 对医生、病人、药品的基本信息进行增加,删除,修改,查询等的基本功能 2. 1. 2 门诊信息管理系统的功能 对就诊信息的存储功能和对处方信息进行增加、删除、修改药品等的基本功能 3. 2. 3 收费信息管理系统 对医疗费用
6、进行总和计算的功能和对药品库存进行修改的功能 2.2功能模块 系统主要功能模块图如下: 医院综合信息管理系统 人员信息管理系统 门诊信息管理系统 收费信息管理系统 医生信息管理 病人信息管理 药品信息管理 就诊信息管理 病人处方管理 收费信息管理 药品库存管理 三、数据库设计: 3.1 E-R图: 3.1.1医生信息doctor E-R图 name sex age employno phone doctor 3.1.2病人信息patient E-R图
7、name sex age patientno no phone patient 3.1.3药品信息drug E-R图 drug drugno no name no price no inventory no 3.1.4诊断信息diagnosis E-R图 diagnosis diagnosisno no no employno no patientno no condition no 3.1.5处方信息prescription E-R图 prescription
8、prescription no no no patientno no name no time no account 3.1.6实体间主要关系E-R图 Doctor Paitient Durg Diagnosis Prescription N 1 1 1 1 1 1 1 3.2数据字典: 表1:doctor: 表2:patient 表3:durg 表4:diagnosis 表5:prescription 四、前台设计: 4.1.医生信息管理: 4.2.病人信息管理:
9、 4.3.药品信息管理: 4.4.诊断界面: 4.5.处方界面: 4.6.病人处方查询: 4.7.收费信息管理: 五、程序调试结果: 1.主界面: 2.添加功能: 实现代码: void CEmployeeDlg::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代码 //CDialogEx::OnOK(); UpdateData(true); if(m_number.IsEmpty()) { M
10、essageBox(CString("编号不能为空”)); return; } if(m_name.IsEmpty()) { MessageBox(CString("名称不能为空!")); return; } if(m_idcard.IsEmpty()) { MessageBox(CString("省份证号码不能为空!")); return; } CADOConn m_AdoConn; m_AdoConn.OnInitADOConn(); _bstr_t sql; sql = "select* from doctor";
11、 _RecordsetPtr m_pRecordset; m_pRecordset=m_AdoConn.GetRecordSet(sql); try { m_pRecordset->AddNew();//添加新行 m_pRecordset->PutCollect("employeeno",(_bstr_t)m_number); m_pRecordset->PutCollect("name",(_bstr_t)m_name); m_pRecordset->PutCollect("sex",(_bstr_t)m_sex); m_pRecor
12、dset->PutCollect("age",(_bstr_t)m_age); m_pRecordset->PutCollect("native",(_bstr_t)m_native); m_pRecordset->PutCollect("nation",(_bstr_t)m_nation); m_pRecordset->PutCollect("office",(_bstr_t)m_office); m_pRecordset->PutCollect("position",(_bstr_t)m_position); m_pRecordset->PutCollect
13、"idcard",(_bstr_t)m_idcard); m_pRecordset->PutCollect("phone",(_bstr_t)m_phone); m_pRecordset->Update();//更新数据库 m_AdoConn.ExitConnect();//断开数据库连接 } catch(...) { MessageBox(CString("操作失败")); return; } MessageBox(CString("保存成功")); m_grid.DeleteAllItems();//删¦除grid中原来的数据
14、 CString str; str="select* from doctor"; AddToGrid(str);//重新遍历 } 2.修改功能: 实现代码: void CEmployeeDlg::OnBnClickedChange() { // TODO: 在此添加控件通知处理程序代码 UpdateData(true); CADOConn m_AdoConn; m_AdoConn.OnInitADOConn(); CString tempSql; tempSql.Format(CString("UPDATE`mydb`.`doctor`SE
15、T `name`='%s',`sex`='%s',`age`='%s',`native`='%s',`nation`='%s',`office`='%s',`position`='%s',`idcard`='%s',`phone`='%s'WHERE `employeeno`='%s'"),m_name,m_sex,m_age,m_native,m_nation,m_office,m_position,m_idcard,m_phone,m_number); m_AdoConn.ExecuteSQL((_bstr_t)tempSql); m_AdoConn.ExitConnect();
16、 MessageBox(CString("修改成功.")); m_grid.DeleteAllItems();//删除grid中原来的数据 CString str; str="select* from doctor"; AddToGrid(str);//重新遍历 } 3.删除功能: 代码实现: void CEmployeeDlg::OnBnClickedDelete() { // TODO: 在此添加控件通知处理程序代码 UpdateData(true); CADOConn m_AdoConn; m_AdoCon
17、n.OnInitADOConn(); CString tempSql; tempSql.Format(CString("delete from doctor where employeeno = '%s'"),m_number); CString tenpstr; tenpstr.Format(CString("是否要删除%s的记录"),m_name); if(MessageBox(tenpstr,CString("提示"),MB_OKCANCEL)==IDOK) { m_AdoConn.ExecuteSQL((_bstr_t)tempSql); m_A
18、doConn.ExitConnect(); MessageBox(CString("删除成功.")); m_grid.DeleteAllItems();//删除grid中原来的数据 CString str; str="select* from doctor"; AddToGrid(str);//重新遍历 } } 4.查询功能: 实现代码: void CEmployeeDlg::OnBnClickedSelect() { // TODO: 在此添加控件通知处理程序代码 m_grid.DeleteAllItems(
19、); UpdateData(true); CString str1,str2; int num1,num2; num1=m_combo.GetCurSel(); if(0==num1) { GetDlgItem(IDC_EDIT_CONTENT)->GetWindowText(str1); str2=CString("select* from doctor where employeeno like ")+CString("'")+str1+CString("'"); AddToGrid(str2);// 遍历功能信息记录 } if(1==
20、num1) { GetDlgItem(IDC_EDIT_CONTENT)->GetWindowText(str1); str2=CString("select* from doctor where name like ")+CString("'")+str1+CString("'"); AddToGrid(str2);// 遍历功能信息记录 } if(2==num1) { GetDlgItem(IDC_EDIT_CONTENT)->GetWindowText(str1); str2=CString("select* from doctor wher
21、e office like ")+CString("'")+str1+CString("'"); AddToGrid(str2);// 遍历功能信息记录 } if(3==num1) { GetDlgItem(IDC_EDIT_CONTENT)->GetWindowText(str1); str2=CString("select* from doctor where position like ")+CString("'")+str1+CString("'"); AddToGrid(str2);// 遍历功能信息记录 } if(4==num1) {
22、 GetDlgItem(IDC_EDIT_CONTENT)->GetWindowText(str1); str2=CString("select* from doctor where idcard like ")+CString("'")+str1+CString("'"); AddToGrid(str2);// 遍历功能信息记录 } if(5==num1) { GetDlgItem(IDC_EDIT_CONTENT)->GetWindowText(str1); str2="select* from doctor order by employeeno
23、 DESC"; AddToGrid(str2);// 遍历功能信息记录 } } 5.诊断界面: 6.处方界面: 7.处方查询: 8.付款界面: 9.修改库存: 对比图: 付款前: 付款后: 六、总结: 通过这次数据库大作业,我们熟悉了vs2010的数据库ADO编程。对于它的添加,修改,删除步骤都有了较大的理解。在此次作业当中遇到两大问题。一是:数据库连接问题,本来开始准备用access做后台,可是不知道为什么我的电脑一直连接
24、不上,于是改用了MYAQL连接。二是:在是使用记录集指针的问题_RecordsetPtr m_pRecordset,在实现添加,删除,修改,查询等操作时,只能执行一次就出现指针无效的结果。最后发现是在连接数据库时没有初始化COM,所以导致有指针无效的结果。然后,最让我开心的是,是实现总价的计算。我是用两个数组,amount[20],和price[20]记住数量和单价,利用for循环计算总价的。然后,就是在 vs2010中字符之间的转换也是我们应该注意的问题。 总之,这次实验,让我们学到了许多课本上学不到的知识,也锻炼了我们的思考问题,解决问题的能力。 附录:医院综合信息管
25、理系统源代码 // ADOConn.cpp : 实现文件 // #include "stdafx.h" #include "hospital.h" #include "ADOConn.h" // CADOConn CADOConn::CADOConn() { } CADOConn::~CADOConn() { } // CADOConn 成员函数 bool CADOConn::OnInitADOConn(void) { HRESULT hr; ::CoInitialize(NULL); try { hr=m
26、pDBConnection.CreateInstance("ADODB.Connection"); if(SUCCEEDED(hr)) { m_pDBConnection->ConnectionTimeout=3; //设置连接字符串 _bstr_t strConnection="Driver={MySQL ODBC 5.2 Unicode Driver};SERVER=127.0.0.1;DATABASE=mydb;UID=root;PASSWORD=123456;PORT=3306"; hr=m_pDBConnection->Open(strC
27、onnection,"","",adModeUnknown); } } catch(_com_error e)//捕捉异常 { CString temp; temp.Format(CString("连接数据库错误信息:%s"),e.ErrorMessage()); ::MessageBox(NULL,temp,CString("提示信息"),NULL); return false; } return false; } // 断开数据库连接 void CADOConn::ExitConnect(void) { if (m_pR
28、ecordset!=NULL) m_pRecordset->Close(); m_pDBConnection->Close(); //释放环境 ::CoUninitialize(); } // 获取记录集 _RecordsetPtr& CADOConn::GetRecordSet(_bstr_t bstrSQL) { try { if(m_pDBConnection==NULL) OnInitADOConn(); m_pRecordset.CreateInstance(__uuidof(Recordset))
29、 m_pRecordset->Open(bstrSQL,m_pDBConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText); } catch(_com_error e) { CString temp; temp.Format(CString("读取数据库错误信息:%s"),e.ErrorMessage()); ::MessageBox(NULL,temp,CString("提示信息"),NULL); } return m_pRecordset;
30、} // 执行SQL语句 bool CADOConn::ExecuteSQL(_bstr_t bstrSQL) { _variant_t RecordsAffected; try { if(m_pDBConnection==NULL) OnInitADOConn(); m_pDBConnection->Execute(bstrSQL,NULL,adCmdText); return true; } catch(_com_error e) { CString temp; temp.Format(CStr
31、ing("执行SQL语句错误信息:%s"),e.Description()); ::MessageBox(NULL,temp,CString("提示信息"),NULL); return false; } } // 返回记录集对象指针的SQL执行函数 _RecordsetPtr CADOConn::ExcuteSQLObj(_bstr_t bstrSQL) { try { if(m_pDBConnection==NULL) OnInitADOConn(); m_pRecordset=m_pDBConnectio
32、n->Execute(bstrSQL,NULL,adCmdText); } catch(_com_error e) { CString temp; m_pRecordset=NULL; temp.Format(CString("执行SQL语句错误信息:%s"),e.ErrorMessage()); ::MessageBox(NULL,temp,CString("提示信息"),NULL); } return m_pRecordset; } // PrescriptionDlg.cpp : 实现文件 //处方:万淑妍 #inclu
33、de "stdafx.h" #include "hospital.h" #include "PrescriptionDlg.h" #include "afxdialogex.h" #include "ADOConn.h" // CPrescriptionDlg 对话框 IMPLEMENT_DYNAMIC(CPrescriptionDlg, CDialogEx) CPrescriptionDlg::CPrescriptionDlg(CWnd* pParent /*=NULL*/) : CDialogEx(CPrescriptionDlg::IDD, pParen
34、t) { m_patientno = _T(""); m_amount = _T(""); m_name = _T(""); m_no = 0; } CPrescriptionDlg::~CPrescriptionDlg() { } void CPrescriptionDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST1, m_grid); DDX_Text(pDX, IDC_PATIENTNO
35、 m_patientno); DDX_Text(pDX, IDC_AMOUNT, m_amount); DDX_Text(pDX, IDC_DURGNAME, m_name); DDX_Control(pDX, IDC_DATETIMEPICKER1, m_time); } BEGIN_MESSAGE_MAP(CPrescriptionDlg, CDialogEx) ON_BN_CLICKED(IDOK, &CPrescriptionDlg::OnBnClickedOk) ON_BN_CLICKED(IDC_CHANGE, &CPrescriptionDlg:
36、OnBnClickedChange) ON_NOTIFY(NM_CLICK, IDC_LIST1, &CPrescriptionDlg::OnNMClickList1) ON_BN_CLICKED(IDC_DELETE, &CPrescriptionDlg::OnBnClickedDelete) ON_BN_CLICKED(IDC_CLEAR, &CPrescriptionDlg::OnBnClickedClear) END_MESSAGE_MAP() // CPrescriptionDlg 消息处理程序 BOOL CPrescriptionDlg::OnI
37、nitDialog() { CDialogEx::OnInitDialog(); // TODO: 在此添加额外的初始化 flag=0; return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } void CPrescriptionDlg::AddToGrid(CString str) { CADOConn m_AdoConn; m_AdoConn.OnInitADOConn(); CString sql;
38、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("prescriptionno")); m_grid.SetItemT
39、ext(0,1,(CString)(char*)(_bstr_t)m_pRecordset->GetCollect("patientno")); m_grid.SetItemText(0,2,(CString)(char*)(_bstr_t)m_pRecordset->GetCollect("name")); m_grid.SetItemText(0,3,(CString)(char*)(_bstr_t)m_pRecordset->GetCollect("amount")); m_grid.SetItemText(0,4,(CString)(char*)(_bstr_t)m_
40、pRecordset->GetCollect("time")); m_pRecordset->MoveNext(); } m_AdoConn.ExitConnect(); UpdateData(true); } void CPrescriptionDlg::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代码 //CDialogEx::OnOK(); m_no=1; if(flag==0) { m_grid.SetExtendedStyle(LVS_EX_FLATSB |LVS_E
41、X_FULLROWSELECT |LVS_EX_HEADERDRAGDROP |LVS_EX_ONECLICKACTIVATE |LVS_EX_GRIDLINES); m_grid.InsertColumn(0,CString("处方编号"),LVCFMT_LEFT,100,0); m_grid.InsertColumn(1,CString("病人编号"),LVCFMT_LEFT,100,1); m_grid.InsertColumn(2,CString("药品名称"),LVCFMT_LEFT,100,2); m_grid.InsertColumn(3,CSt
42、ring("使用数量"),LVCFMT_LEFT,100,3); m_grid.InsertColumn(4,CString("用药时间"),LVCFMT_LEFT,100,4); flag= !flag; //自动编号 CADOConn m_AdoConn; m_AdoConn.OnInitADOConn(); _bstr_t sql; sql = "select prescriptionno from prescription"; _RecordsetPtr m_pRecordset; m_pRecordset = m_AdoConn.GetRec
43、ordSet((_bstr_t)sql); while(m_AdoConn.m_pRecordset->adoEOF==0) { if(m_no<(int)_ttoi((CString)(char*)(_bstr_t)m_pRecordset->GetCollect("prescriptionno"))) m_no=(int)_ttoi((CString)(char*)(_bstr_t)m_pRecordset->GetCollect("prescriptionno")); m_pRecordset->MoveNext(); } m_AdoConn.Ex
44、itConnect(); m_no++; CString str,str1; GetDlgItem(IDC_PATIENTNO)->GetWindowText(str1); str=CString("select* from prescription where patientno like ")+CString("'")+str1+CString("'"); AddToGrid(str);// 遍历员工信息记录 } UpdateData(true); if(m_patientno.IsEmpty()) { MessageBox(CString
45、"病人编号不能为空!")); return; } if(m_name.IsEmpty()) { MessageBox(CString("名称不能为空!")); return; } CADOConn m_AdoConn; m_AdoConn.OnInitADOConn(); _bstr_t sql; sql = "select * from prescription"; _RecordsetPtr m_pRecordset; m_pRecordset=m_AdoConn.GetRecordSet(sql); //获取工作时间
46、 CTime time; m_time.GetTime(time); COleDateTime convert_time; convert_time.SetDate(time.GetYear(),time.GetMonth(),time.GetDay()); try { m_pRecordset->AddNew();//添加新行 m_pRecordset->PutCollect("patientno",(_bstr_t)m_patientno); m_pRecordset->PutCollect("name",(_bstr_t)m_name);
47、 m_pRecordset->PutCollect("amount",(_bstr_t)m_amount); m_pRecordset->PutCollect("time",(_variant_t)convert_time); m_pRecordset->PutCollect("prescriptionno",(_bstr_t)m_no); m_pRecordset->Update();//更新数据库 m_AdoConn.ExitConnect();//断开数据库连接 } catch(...) { MessageBox(CString("操作失败"
48、)); return; } MessageBox(CString("保存成功.")); m_grid.DeleteAllItems();//删除grid中原来的数据 CString str,str1; GetDlgItem(IDC_PATIENTNO)->GetWindowText(str1); str=CString("select* from prescription where patientno like ")+CString("'")+str1+CString("'"); AddToGrid(str);// 遍历员工信息记录 }
49、 void CPrescriptionDlg::OnBnClickedChange() { // TODO: 在此添加控件通知处理程序代码 UpdateData(true); CADOConn m_AdoConn; m_AdoConn.OnInitADOConn();//创建连接 CString tempSql; //删除的字符类型为CString CString sextemp; //获取用药时间 CTime time; m_time.GetTime(time); COleDateTime convert_time; convert_t
50、ime.SetDate(time.GetYear(),time.GetMonth(),time.GetDay()); CString timetemp = convert_time.Format(); tempSql.Format(CString("update mydb.prescription set name='%s',amount='%s',time='%s' where name = '%s'"),m_patientno,m_amount,timetemp,m_name); m_AdoConn.ExecuteSQL((_bstr_t)t






