毕业设计--药品管理系统的设计与实现 下载本文

药品管理系统的设计与实现

按钮实现的功能都分为管理员和收银员两种权限。同时提供多种查询方式,例如按拼音码、按药品名称、按编号、按时间查询。更多入口更方便更安全。点击生成报表按钮会取得当前显示的表信息传到报表预览窗口,只有管理员才能预览报表,在报表预览窗口可以实现数据导出到Word、Excel、PDF,也可以连接打印机直接打印。报表中心界面如图32所示,.RDLC报表设计相关的DataTable如图33所示。

图32 报表中心界面

图33 .RDLC报表设计相关的DataTable

第31页,共48页

药品管理系统的设计与实现

实现多条件查询的关键代码如下:

private void Search(string strSQL, string strIdColumn, string strPYMColumn, string strNameColumn, string strTimeColumn, string strOther) { string str1 = txtKeywords.Text; string str2 = dateBegin.Value.ToString(\); string str3 = dateEnd.Value.ToString(\); if (checkBoxKey.Checked == true && checkBoxTime.Checked == true) { if (cboKeywords.Text == \编号\) { string sqlstr = @\ + strSQL + \\ + strIdColumn + \ + str1 + \ + strTimeColumn + \ + str2 + \'\ + str3 + \ + strOther + \; Binddgv(sqlstr); } if (cboKeywords.Text == \拼音码\) { string sqlstr = @\ + strSQL + \where \ + strPYMColumn + \ + str1 + \ + strTimeColumn + \ + str2 + \'\ + str3 + \ + strOther + \; Binddgv(sqlstr); } if (cboKeywords.Text == \药品名称\) { string sqlstr = @\ + strSQL + \where \ + strNameColumn + \ + str1 + \ + strTimeColumn + \ + str2 + \'\ + str3 + \ + strOther + \; Binddgv(sqlstr); } } else if (checkBoxKey.Checked == true && checkBoxTime.Checked == false) { if (cboKeywords.Text == \编号\) { string sqlstr = @\ + strSQL + \\ + strIdColumn + \ + str1 + \ + strOther + \; Binddgv(sqlstr); } if (cboKeywords.Text == \拼音码\) { string sqlstr = @\ + strSQL + \where \ + strPYMColumn + \ + str1 + \ + strOther + \; Binddgv(sqlstr); } if (cboKeywords.Text == \药品名称\) { string sqlstr = @\ + strSQL + \where \ + strNameColumn + \ + str1 + \ + strOther + \; Binddgv(sqlstr); } } else if (checkBoxKey.Checked == false && checkBoxTime.Checked == true) { string sqlstr = @\ + strSQL + \ + strTimeColumn + \ + str2 + \ + str3 + \ + strOther + \; Binddgv(sqlstr); } } 实现报表预览的关键代码如下:

private void btnCreate_Click(object sender, EventArgs e) { if (frm_Login.flagAdmin == \管理员\) { table = dgvShow.DataSource as DataTable; frm_Reports rf = new frm_Reports(); rf.Owner = this; rf.ShowDialog(); 第32页,共48页

药品管理系统的设计与实现

rf.Dispose(); } else { MessageBox.Show(\没有这个权限!\); } } // strPath为相应的报表 private void BindReportViewer(string strPath,string strDataSet) { frm_AllReport fm = (frm_AllReport)this.Owner; //this.reportViewer1.LocalReport.ReportPath = @\用绝对路径 //取相对路径 string path = System.Windows.Forms.Application.StartupPath + @\; System.IO.Directory.SetCurrentDirectory(path); string strFilePath = System.IO.Directory.GetCurrentDirectory() + @\ + strPath + \; //用相对路径 this.reportViewer1.LocalReport.ReportPath = strFilePath; this.reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout); this.reportViewer1.LocalReport.DataSources.Clear(); this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource(\+strDataSet+\, fm.table)); this.reportViewer1.RefreshReport(); } private void frm_Reports_Load(object sender, EventArgs e) { switch (frm_AllReport.tag1) { case 1: { BindReportViewer(\, \); break; } case 2: { BindReportViewer(\, \); break; } case 3: { BindReportViewer(\, \); break; } case 4: { BindReportViewer(\, \); break; } case 5: { BindReportViewer(\, \); break; } case 6: { BindReportViewer(\, \); break; } case 7: { BindReportViewer(\, \); break; } case 8: { BindReportViewer(\, \); break; } case 9: { BindReportViewer(\, \); break; } case 10: { BindReportViewer(\, \); break; } case 11: { BindReportViewer(\, \); break; } case 12: { BindReportViewer(\, \); break; } } } 第33页,共48页

药品管理系统的设计与实现

4.1.12系统部分公有类或方法的设计与实现

连接数据库

public SqlConnection GetConnection() { return new SqlConnection(@\); } 事务处理

public bool ExecDataBySqls(List strSqls) //事务处理 { SqlConnection conn = GetConnection(); SqlCommand comn = new SqlCommand(); bool booIsSucceed; if (conn.State == ConnectionState.Closed) { conn.Open(); } SqlTransaction sqlTran = conn.BeginTransaction(); try { comn.Connection = conn; comn.Transaction = sqlTran; foreach (string item in strSqls) { comn.CommandType = CommandType.Text; comn.CommandText = item; comn.ExecuteNonQuery(); } sqlTran.Commit(); booIsSucceed = true; } catch { sqlTran.Rollback(); booIsSucceed = false; } finally { conn.Close(); strSqls.Clear(); } return booIsSucceed;} //事务处理 第34页,共48页