SendMedicine.cs
上传用户:yongjiajia
上传日期:2021-01-30
资源大小:686k
文件大小:16k
开发平台:

ASP/ASPX

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. namespace 医院管理系统
  9. {
  10. /// <summary>
  11. /// SendMedicine 的摘要说明。
  12. /// </summary>
  13. public class SendMedicine : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.DataGrid dataGrid2;
  16. private System.Data.DataView dataView2;
  17. private System.Windows.Forms.DataGrid dataGrid1;
  18. private System.Data.DataView dataView1;
  19. private System.Data.SqlClient.SqlDataAdapter da2;
  20. private System.Windows.Forms.GroupBox groupBox1;
  21. private System.Windows.Forms.Label label8;
  22. private System.Windows.Forms.Label label4;
  23. private System.Windows.Forms.Button btnSearch;
  24. private System.Windows.Forms.TextBox txt1;
  25. private System.Windows.Forms.TextBox txt2;
  26. private System.Windows.Forms.Label label5;
  27. private System.Windows.Forms.TextBox txt4;
  28. private System.Windows.Forms.TextBox txt3;
  29. private System.Windows.Forms.Label label6;
  30. private System.Windows.Forms.Label label7;
  31. private System.Data.SqlClient.SqlDataAdapter da1;
  32. private 医院管理系统.DataSet3 dataSet31;
  33. private System.Windows.Forms.Button btnSend;
  34. private System.Data.SqlClient.SqlCommand sqlSelectCommand2;
  35. private System.Data.SqlClient.SqlConnection sqlConnection1;
  36. private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
  37. /// <summary>
  38. /// 必需的设计器变量。
  39. /// </summary>
  40. private System.ComponentModel.Container components = null;
  41. public SendMedicine()
  42. {
  43. //
  44. // Windows 窗体设计器支持所必需的
  45. //
  46. InitializeComponent();
  47. //
  48. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  49. //
  50. }
  51. /// <summary>
  52. /// 清理所有正在使用的资源。
  53. /// </summary>
  54. protected override void Dispose( bool disposing )
  55. {
  56. if( disposing )
  57. {
  58. if(components != null)
  59. {
  60. components.Dispose();
  61. }
  62. }
  63. base.Dispose( disposing );
  64. }
  65. #region Windows 窗体设计器生成的代码
  66. /// <summary>
  67. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  68. /// 此方法的内容。
  69. /// </summary>
  70. private void InitializeComponent()
  71. {
  72. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(SendMedicine));
  73. this.dataGrid2 = new System.Windows.Forms.DataGrid();
  74. this.dataView2 = new System.Data.DataView();
  75. this.dataSet31 = new 医院管理系统.DataSet3();
  76. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  77. this.dataView1 = new System.Data.DataView();
  78. this.da2 = new System.Data.SqlClient.SqlDataAdapter();
  79. this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
  80. this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
  81. this.groupBox1 = new System.Windows.Forms.GroupBox();
  82. this.btnSend = new System.Windows.Forms.Button();
  83. this.label8 = new System.Windows.Forms.Label();
  84. this.label4 = new System.Windows.Forms.Label();
  85. this.btnSearch = new System.Windows.Forms.Button();
  86. this.txt1 = new System.Windows.Forms.TextBox();
  87. this.txt2 = new System.Windows.Forms.TextBox();
  88. this.label5 = new System.Windows.Forms.Label();
  89. this.txt4 = new System.Windows.Forms.TextBox();
  90. this.txt3 = new System.Windows.Forms.TextBox();
  91. this.label6 = new System.Windows.Forms.Label();
  92. this.label7 = new System.Windows.Forms.Label();
  93. this.da1 = new System.Data.SqlClient.SqlDataAdapter();
  94. this.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand();
  95. ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).BeginInit();
  96. ((System.ComponentModel.ISupportInitialize)(this.dataView2)).BeginInit();
  97. ((System.ComponentModel.ISupportInitialize)(this.dataSet31)).BeginInit();
  98. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  99. ((System.ComponentModel.ISupportInitialize)(this.dataView1)).BeginInit();
  100. this.groupBox1.SuspendLayout();
  101. this.SuspendLayout();
  102. // 
  103. // dataGrid2
  104. // 
  105. this.dataGrid2.CaptionVisible = false;
  106. this.dataGrid2.DataMember = "";
  107. this.dataGrid2.DataSource = this.dataView2;
  108. this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  109. this.dataGrid2.Location = new System.Drawing.Point(0, 304);
  110. this.dataGrid2.Name = "dataGrid2";
  111. this.dataGrid2.ReadOnly = true;
  112. this.dataGrid2.Size = new System.Drawing.Size(712, 168);
  113. this.dataGrid2.TabIndex = 5;
  114. // 
  115. // dataView2
  116. // 
  117. this.dataView2.Table = this.dataSet31.门诊划价明细;
  118. // 
  119. // dataSet31
  120. // 
  121. this.dataSet31.DataSetName = "DataSet3";
  122. this.dataSet31.Locale = new System.Globalization.CultureInfo("zh-CN");
  123. // 
  124. // dataGrid1
  125. // 
  126. this.dataGrid1.CaptionVisible = false;
  127. this.dataGrid1.DataMember = "";
  128. this.dataGrid1.DataSource = this.dataView1;
  129. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  130. this.dataGrid1.Location = new System.Drawing.Point(0, 104);
  131. this.dataGrid1.Name = "dataGrid1";
  132. this.dataGrid1.ReadOnly = true;
  133. this.dataGrid1.Size = new System.Drawing.Size(712, 200);
  134. this.dataGrid1.TabIndex = 4;
  135. // 
  136. // dataView1
  137. // 
  138. this.dataView1.Table = this.dataSet31.门诊划价;
  139. // 
  140. // da2
  141. // 
  142. this.da2.SelectCommand = this.sqlSelectCommand1;
  143. this.da2.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
  144.   new System.Data.Common.DataTableMapping("Table", "门诊划价明细", new System.Data.Common.DataColumnMapping[] {
  145. new System.Data.Common.DataColumnMapping("编号", "编号"),
  146. new System.Data.Common.DataColumnMapping("药品编号", "药品编号"),
  147. new System.Data.Common.DataColumnMapping("名称", "名称"),
  148. new System.Data.Common.DataColumnMapping("单价", "单价"),
  149. new System.Data.Common.DataColumnMapping("数量", "数量"),
  150. new System.Data.Common.DataColumnMapping("金额", "金额"),
  151. new System.Data.Common.DataColumnMapping("划价编号", "划价编号")})});
  152. // 
  153. // sqlSelectCommand1
  154. // 
  155. this.sqlSelectCommand1.CommandText = "SELECT DISTINCT a.编号, a.药品编号, b.名称, a.单价, a.数量, a.金额, a.划价编号 FROM 门诊划价明细 a INNER " +
  156. "JOIN v收费项目及药品 b ON a.药品编号 = b.编号";
  157. this.sqlSelectCommand1.Connection = this.sqlConnection1;
  158. // 
  159. // sqlConnection1
  160. // 
  161. this.sqlConnection1.ConnectionString = "workstation id=localhost;packet size=4096;integrated security=SSPI;data source="." +
  162. "";persist security info=False;initial catalog=hisbook";
  163. // 
  164. // groupBox1
  165. // 
  166. this.groupBox1.Controls.Add(this.btnSend);
  167. this.groupBox1.Controls.Add(this.label8);
  168. this.groupBox1.Controls.Add(this.label4);
  169. this.groupBox1.Controls.Add(this.btnSearch);
  170. this.groupBox1.Controls.Add(this.txt1);
  171. this.groupBox1.Controls.Add(this.txt2);
  172. this.groupBox1.Controls.Add(this.label5);
  173. this.groupBox1.Controls.Add(this.txt4);
  174. this.groupBox1.Controls.Add(this.txt3);
  175. this.groupBox1.Controls.Add(this.label6);
  176. this.groupBox1.Controls.Add(this.label7);
  177. this.groupBox1.Location = new System.Drawing.Point(0, 2);
  178. this.groupBox1.Name = "groupBox1";
  179. this.groupBox1.Size = new System.Drawing.Size(712, 100);
  180. this.groupBox1.TabIndex = 3;
  181. this.groupBox1.TabStop = false;
  182. this.groupBox1.Text = "搜索";
  183. // 
  184. // btnSend
  185. // 
  186. this.btnSend.Image = ((System.Drawing.Image)(resources.GetObject("btnSend.Image")));
  187. this.btnSend.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  188. this.btnSend.Location = new System.Drawing.Point(608, 56);
  189. this.btnSend.Name = "btnSend";
  190. this.btnSend.TabIndex = 6;
  191. this.btnSend.Text = "发药";
  192. this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
  193. // 
  194. // label8
  195. // 
  196. this.label8.Location = new System.Drawing.Point(352, 56);
  197. this.label8.Name = "label8";
  198. this.label8.Size = new System.Drawing.Size(144, 16);
  199. this.label8.TabIndex = 3;
  200. this.label8.Text = "格式如'2004-1-1'";
  201. // 
  202. // label4
  203. // 
  204. this.label4.Location = new System.Drawing.Point(64, 37);
  205. this.label4.Name = "label4";
  206. this.label4.Size = new System.Drawing.Size(32, 16);
  207. this.label4.TabIndex = 2;
  208. this.label4.Text = "编号";
  209. // 
  210. // btnSearch
  211. // 
  212. this.btnSearch.Image = ((System.Drawing.Image)(resources.GetObject("btnSearch.Image")));
  213. this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  214. this.btnSearch.Location = new System.Drawing.Point(512, 56);
  215. this.btnSearch.Name = "btnSearch";
  216. this.btnSearch.Size = new System.Drawing.Size(80, 24);
  217. this.btnSearch.TabIndex = 1;
  218. this.btnSearch.Text = "搜索";
  219. this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
  220. // 
  221. // txt1
  222. // 
  223. this.txt1.Location = new System.Drawing.Point(96, 32);
  224. this.txt1.Name = "txt1";
  225. this.txt1.Size = new System.Drawing.Size(144, 21);
  226. this.txt1.TabIndex = 0;
  227. this.txt1.Text = "";
  228. // 
  229. // txt2
  230. // 
  231. this.txt2.Location = new System.Drawing.Point(96, 72);
  232. this.txt2.Name = "txt2";
  233. this.txt2.Size = new System.Drawing.Size(144, 21);
  234. this.txt2.TabIndex = 0;
  235. this.txt2.Text = "";
  236. // 
  237. // label5
  238. // 
  239. this.label5.Location = new System.Drawing.Point(64, 72);
  240. this.label5.Name = "label5";
  241. this.label5.Size = new System.Drawing.Size(32, 16);
  242. this.label5.TabIndex = 2;
  243. this.label5.Text = "姓名";
  244. // 
  245. // txt4
  246. // 
  247. this.txt4.Location = new System.Drawing.Point(352, 72);
  248. this.txt4.Name = "txt4";
  249. this.txt4.Size = new System.Drawing.Size(144, 21);
  250. this.txt4.TabIndex = 0;
  251. this.txt4.Text = "";
  252. // 
  253. // txt3
  254. // 
  255. this.txt3.Location = new System.Drawing.Point(352, 32);
  256. this.txt3.Name = "txt3";
  257. this.txt3.Size = new System.Drawing.Size(144, 21);
  258. this.txt3.TabIndex = 0;
  259. this.txt3.Text = "";
  260. // 
  261. // label6
  262. // 
  263. this.label6.Location = new System.Drawing.Point(296, 36);
  264. this.label6.Name = "label6";
  265. this.label6.Size = new System.Drawing.Size(56, 16);
  266. this.label6.TabIndex = 2;
  267. this.label6.Text = "开始时间";
  268. // 
  269. // label7
  270. // 
  271. this.label7.Location = new System.Drawing.Point(296, 76);
  272. this.label7.Name = "label7";
  273. this.label7.Size = new System.Drawing.Size(56, 16);
  274. this.label7.TabIndex = 2;
  275. this.label7.Text = "结束时间";
  276. // 
  277. // da1
  278. // 
  279. this.da1.SelectCommand = this.sqlSelectCommand2;
  280. this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
  281.   new System.Data.Common.DataTableMapping("Table", "门诊划价", new System.Data.Common.DataColumnMapping[] {
  282.   new System.Data.Common.DataColumnMapping("姓名", "姓名"),
  283.   new System.Data.Common.DataColumnMapping("性别", "性别"),
  284.   new System.Data.Common.DataColumnMapping("编号", "编号"),
  285.   new System.Data.Common.DataColumnMapping("科室", "科室"),
  286.   new System.Data.Common.DataColumnMapping("挂号编号", "挂号编号"),
  287.   new System.Data.Common.DataColumnMapping("医生", "医生"),
  288.   new System.Data.Common.DataColumnMapping("划价时间", "划价时间"),
  289.   new System.Data.Common.DataColumnMapping("划价员", "划价员"),
  290.   new System.Data.Common.DataColumnMapping("是否收费", "是否收费"),
  291.   new System.Data.Common.DataColumnMapping("收费员", "收费员"),
  292.   new System.Data.Common.DataColumnMapping("收费时间", "收费时间"),
  293.   new System.Data.Common.DataColumnMapping("划价金额", "划价金额"),
  294.   new System.Data.Common.DataColumnMapping("是否发药", "是否发药"),
  295.   new System.Data.Common.DataColumnMapping("发药时间", "发药时间"),
  296.   new System.Data.Common.DataColumnMapping("发药员", "发药员")})});
  297. // 
  298. // sqlSelectCommand2
  299. // 
  300. this.sqlSelectCommand2.CommandText = "SELECT b.姓名, b.性别, a.编号, a.科室, a.挂号编号, a.医生, a.划价时间, a.划价员, a.是否收费, a.收费员, a.收费时间" +
  301. ", a.划价金额, a.是否发药, a.发药时间, a.发药员 FROM 门诊划价 a INNER JOIN 门诊挂号 b ON a.挂号编号 = b.编号 W" +
  302. "HERE (a.是否发药 = '否') AND (a.是否收费 = '是')";
  303. this.sqlSelectCommand2.Connection = this.sqlConnection1;
  304. // 
  305. // SendMedicine
  306. // 
  307. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  308. this.ClientSize = new System.Drawing.Size(712, 477);
  309. this.Controls.Add(this.dataGrid2);
  310. this.Controls.Add(this.dataGrid1);
  311. this.Controls.Add(this.groupBox1);
  312. this.Name = "SendMedicine";
  313. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  314. this.Text = "【药房发药】";
  315. this.Load += new System.EventHandler(this.SendMedicine_Load);
  316. ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
  317. ((System.ComponentModel.ISupportInitialize)(this.dataView2)).EndInit();
  318. ((System.ComponentModel.ISupportInitialize)(this.dataSet31)).EndInit();
  319. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  320. ((System.ComponentModel.ISupportInitialize)(this.dataView1)).EndInit();
  321. this.groupBox1.ResumeLayout(false);
  322. this.ResumeLayout(false);
  323. }
  324. #endregion
  325. //------------初始化窗体时读入全部数据-------------
  326. private void SendMedicine_Load(object sender, System.EventArgs e)
  327. {
  328. //填充数据集
  329. da1.Fill(dataSet31);
  330. da2.Fill(dataSet31);
  331. //显示时,首先显示第一个划价单的明细
  332. dataView2.RowFilter="划价编号='"+dataGrid1[0,2].ToString().Trim()+"'";
  333. //明细数据根据选择的划价单编号而变化
  334. dataGrid1.CurrentCellChanged+=new EventHandler(dataGrid1_CurrentCellChanged);
  335. }
  336. //------------根据输入条件检索划价数据--------------
  337. private void btnSearch_Click(object sender, System.EventArgs e)
  338. {
  339. string filter="";
  340. if(txt1.Text.Trim()!="")
  341. {
  342. filter+="编号 like '%"+txt1.Text.Trim()+"%' AND ";
  343. }
  344. if(txt2.Text.Trim()!="")
  345. {
  346. filter+="姓名 like '%"+txt2.Text.Trim()+"%' AND ";
  347. }
  348. if(txt3.Text.Trim()!="")
  349. {
  350. filter+="划价时间>='"+txt3.Text.Trim()+"' AND ";
  351. }
  352. if(txt4.Text.Trim()!="")
  353. {
  354. filter+="划价时间<='"+txt4.Text.Trim()+"' AND ";
  355. }
  356. int length=filter.Length;
  357. if(length>0)
  358. {
  359. filter=filter.Substring(0,length-5);
  360. }
  361. dataView1.RowFilter=filter;
  362. if(dataView1.Count>0)//有确定的划价数据再显示明细
  363. {
  364. dataView2.RowFilter="划价编号='"+dataGrid1[0,2].ToString().Trim()+"'";
  365. }
  366. }
  367. //------------执行收费-----------
  368. private void btnSend_Click(object sender, System.EventArgs e)
  369. {
  370. if(dataView1.Count==0)//必须有选中的数据
  371. {
  372. MessageBox.Show("表中为空,无法执行发药","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  373. return;
  374. }
  375. //执行发药,更新数据库
  376. string strConn="workstation id=localhost;Integrated Security=SSPI;Database=hisbook;";
  377. SqlConnection cn=new SqlConnection(strConn);
  378. cn.Open();
  379. SqlCommand cmd=cn.CreateCommand();
  380. cmd.CommandText="exec sf_药品发出 "+dataGrid1[dataGrid1.CurrentRowIndex,2].ToString().Trim();
  381. cmd.ExecuteNonQuery();
  382. dataSet31.Clear();//刷新数据集
  383. da1.Fill(dataSet31);
  384. da2.Fill(dataSet31);
  385. if(dataView1.Count>0)//若已收费的划价单已空,则不需要再显示明细
  386. {
  387. dataView2.RowFilter="划价编号='"+dataGrid1[0,2].ToString().Trim()+"'";
  388. }
  389. }
  390. //-------------显示单据明细----------------
  391. private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
  392. {
  393. int i=dataGrid1.CurrentRowIndex;
  394. dataView2.RowFilter="划价编号='"+dataGrid1[i,2].ToString().Trim()+"'";
  395. }
  396. }
  397. }