ClinicCharge.cs
上传用户:hjieqiu
上传日期:2013-05-11
资源大小:16494k
文件大小:19k
源码类别:

企业管理

开发平台:

C#

  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. /// ClinicCharge 的摘要说明。
  12. /// </summary>
  13. public class ClinicCharge : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.GroupBox groupBox1;
  16. private System.Windows.Forms.DataGrid dataGrid1;
  17. private System.Windows.Forms.DataGrid dataGrid2;
  18. private System.Windows.Forms.Label label1;
  19. private System.Windows.Forms.Label label2;
  20. private System.Windows.Forms.Label label3;
  21. private System.Data.SqlClient.SqlDataAdapter da2;
  22. private System.Data.SqlClient.SqlDataAdapter da1;
  23. private 医院管理系统.DataSet2 dataSet21;
  24. private System.Data.DataView dataView1;
  25. private System.Data.DataView dataView2;
  26. private System.Windows.Forms.TextBox txt5;
  27. private System.Windows.Forms.TextBox txt6;
  28. private System.Windows.Forms.TextBox txt7;
  29. private System.Windows.Forms.TextBox txt1;
  30. private System.Windows.Forms.TextBox txt2;
  31. private System.Windows.Forms.Label label4;
  32. private System.Windows.Forms.Label label5;
  33. private System.Windows.Forms.TextBox txt4;
  34. private System.Windows.Forms.TextBox txt3;
  35. private System.Windows.Forms.Label label6;
  36. private System.Windows.Forms.Label label7;
  37. private System.Windows.Forms.Label label8;
  38. private System.Windows.Forms.Button btnCash;
  39. private System.Windows.Forms.Button btnSearch;
  40. private System.Data.SqlClient.SqlCommand sqlSelectCommand2;
  41. private System.Data.SqlClient.SqlConnection sqlConnection1;
  42. private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
  43. /// <summary>
  44. /// 必需的设计器变量。
  45. /// </summary>
  46. private System.ComponentModel.Container components = null;
  47. public ClinicCharge()
  48. {
  49. //
  50. // Windows 窗体设计器支持所必需的
  51. //
  52. InitializeComponent();
  53. //
  54. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  55. //
  56. }
  57. /// <summary>
  58. /// 清理所有正在使用的资源。
  59. /// </summary>
  60. protected override void Dispose( bool disposing )
  61. {
  62. if( disposing )
  63. {
  64. if(components != null)
  65. {
  66. components.Dispose();
  67. }
  68. }
  69. base.Dispose( disposing );
  70. }
  71. #region Windows 窗体设计器生成的代码
  72. /// <summary>
  73. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  74. /// 此方法的内容。
  75. /// </summary>
  76. private void InitializeComponent()
  77. {
  78. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ClinicCharge));
  79. this.groupBox1 = new System.Windows.Forms.GroupBox();
  80. this.label8 = new System.Windows.Forms.Label();
  81. this.label4 = new System.Windows.Forms.Label();
  82. this.btnSearch = new System.Windows.Forms.Button();
  83. this.txt1 = new System.Windows.Forms.TextBox();
  84. this.txt2 = new System.Windows.Forms.TextBox();
  85. this.label5 = new System.Windows.Forms.Label();
  86. this.txt4 = new System.Windows.Forms.TextBox();
  87. this.txt3 = new System.Windows.Forms.TextBox();
  88. this.label6 = new System.Windows.Forms.Label();
  89. this.label7 = new System.Windows.Forms.Label();
  90. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  91. this.dataView1 = new System.Data.DataView();
  92. this.dataSet21 = new 医院管理系统.DataSet2();
  93. this.dataGrid2 = new System.Windows.Forms.DataGrid();
  94. this.dataView2 = new System.Data.DataView();
  95. this.txt5 = new System.Windows.Forms.TextBox();
  96. this.txt6 = new System.Windows.Forms.TextBox();
  97. this.txt7 = new System.Windows.Forms.TextBox();
  98. this.label1 = new System.Windows.Forms.Label();
  99. this.label2 = new System.Windows.Forms.Label();
  100. this.label3 = new System.Windows.Forms.Label();
  101. this.btnCash = new System.Windows.Forms.Button();
  102. this.da2 = new System.Data.SqlClient.SqlDataAdapter();
  103. this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
  104. this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
  105. this.da1 = new System.Data.SqlClient.SqlDataAdapter();
  106. this.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand();
  107. this.groupBox1.SuspendLayout();
  108. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  109. ((System.ComponentModel.ISupportInitialize)(this.dataView1)).BeginInit();
  110. ((System.ComponentModel.ISupportInitialize)(this.dataSet21)).BeginInit();
  111. ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).BeginInit();
  112. ((System.ComponentModel.ISupportInitialize)(this.dataView2)).BeginInit();
  113. this.SuspendLayout();
  114. // 
  115. // groupBox1
  116. // 
  117. this.groupBox1.Controls.Add(this.label8);
  118. this.groupBox1.Controls.Add(this.label4);
  119. this.groupBox1.Controls.Add(this.btnSearch);
  120. this.groupBox1.Controls.Add(this.txt1);
  121. this.groupBox1.Controls.Add(this.txt2);
  122. this.groupBox1.Controls.Add(this.label5);
  123. this.groupBox1.Controls.Add(this.txt4);
  124. this.groupBox1.Controls.Add(this.txt3);
  125. this.groupBox1.Controls.Add(this.label6);
  126. this.groupBox1.Controls.Add(this.label7);
  127. this.groupBox1.Location = new System.Drawing.Point(0, 0);
  128. this.groupBox1.Name = "groupBox1";
  129. this.groupBox1.Size = new System.Drawing.Size(712, 100);
  130. this.groupBox1.TabIndex = 0;
  131. this.groupBox1.TabStop = false;
  132. this.groupBox1.Text = "搜索";
  133. // 
  134. // label8
  135. // 
  136. this.label8.Location = new System.Drawing.Point(352, 56);
  137. this.label8.Name = "label8";
  138. this.label8.Size = new System.Drawing.Size(144, 16);
  139. this.label8.TabIndex = 3;
  140. this.label8.Text = "格式如'2004-1-1'";
  141. // 
  142. // label4
  143. // 
  144. this.label4.Location = new System.Drawing.Point(64, 37);
  145. this.label4.Name = "label4";
  146. this.label4.Size = new System.Drawing.Size(32, 16);
  147. this.label4.TabIndex = 2;
  148. this.label4.Text = "编号";
  149. // 
  150. // btnSearch
  151. // 
  152. this.btnSearch.Image = ((System.Drawing.Image)(resources.GetObject("btnSearch.Image")));
  153. this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  154. this.btnSearch.Location = new System.Drawing.Point(584, 48);
  155. this.btnSearch.Name = "btnSearch";
  156. this.btnSearch.Size = new System.Drawing.Size(104, 32);
  157. this.btnSearch.TabIndex = 1;
  158. this.btnSearch.Text = "搜索";
  159. this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
  160. // 
  161. // txt1
  162. // 
  163. this.txt1.Location = new System.Drawing.Point(96, 32);
  164. this.txt1.Name = "txt1";
  165. this.txt1.Size = new System.Drawing.Size(144, 21);
  166. this.txt1.TabIndex = 0;
  167. this.txt1.Text = "";
  168. // 
  169. // txt2
  170. // 
  171. this.txt2.Location = new System.Drawing.Point(96, 72);
  172. this.txt2.Name = "txt2";
  173. this.txt2.Size = new System.Drawing.Size(144, 21);
  174. this.txt2.TabIndex = 0;
  175. this.txt2.Text = "";
  176. // 
  177. // label5
  178. // 
  179. this.label5.Location = new System.Drawing.Point(64, 72);
  180. this.label5.Name = "label5";
  181. this.label5.Size = new System.Drawing.Size(32, 16);
  182. this.label5.TabIndex = 2;
  183. this.label5.Text = "姓名";
  184. // 
  185. // txt4
  186. // 
  187. this.txt4.Location = new System.Drawing.Point(352, 72);
  188. this.txt4.Name = "txt4";
  189. this.txt4.Size = new System.Drawing.Size(144, 21);
  190. this.txt4.TabIndex = 0;
  191. this.txt4.Text = "";
  192. // 
  193. // txt3
  194. // 
  195. this.txt3.Location = new System.Drawing.Point(352, 32);
  196. this.txt3.Name = "txt3";
  197. this.txt3.Size = new System.Drawing.Size(144, 21);
  198. this.txt3.TabIndex = 0;
  199. this.txt3.Text = "";
  200. // 
  201. // label6
  202. // 
  203. this.label6.Location = new System.Drawing.Point(296, 36);
  204. this.label6.Name = "label6";
  205. this.label6.Size = new System.Drawing.Size(56, 16);
  206. this.label6.TabIndex = 2;
  207. this.label6.Text = "开始时间";
  208. // 
  209. // label7
  210. // 
  211. this.label7.Location = new System.Drawing.Point(296, 76);
  212. this.label7.Name = "label7";
  213. this.label7.Size = new System.Drawing.Size(56, 16);
  214. this.label7.TabIndex = 2;
  215. this.label7.Text = "结束时间";
  216. // 
  217. // dataGrid1
  218. // 
  219. this.dataGrid1.CaptionVisible = false;
  220. this.dataGrid1.DataMember = "";
  221. this.dataGrid1.DataSource = this.dataView1;
  222. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  223. this.dataGrid1.Location = new System.Drawing.Point(0, 104);
  224. this.dataGrid1.Name = "dataGrid1";
  225. this.dataGrid1.ReadOnly = true;
  226. this.dataGrid1.Size = new System.Drawing.Size(720, 200);
  227. this.dataGrid1.TabIndex = 1;
  228. // 
  229. // dataView1
  230. // 
  231. this.dataView1.Table = this.dataSet21.门诊划价;
  232. // 
  233. // dataSet21
  234. // 
  235. this.dataSet21.DataSetName = "DataSet2";
  236. this.dataSet21.Locale = new System.Globalization.CultureInfo("zh-CN");
  237. // 
  238. // dataGrid2
  239. // 
  240. this.dataGrid2.CaptionVisible = false;
  241. this.dataGrid2.DataMember = "";
  242. this.dataGrid2.DataSource = this.dataView2;
  243. this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  244. this.dataGrid2.Location = new System.Drawing.Point(0, 304);
  245. this.dataGrid2.Name = "dataGrid2";
  246. this.dataGrid2.ReadOnly = true;
  247. this.dataGrid2.Size = new System.Drawing.Size(720, 168);
  248. this.dataGrid2.TabIndex = 2;
  249. // 
  250. // dataView2
  251. // 
  252. this.dataView2.Table = this.dataSet21.门诊划价明细;
  253. // 
  254. // txt5
  255. // 
  256. this.txt5.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataView1, "划价金额"));
  257. this.txt5.Location = new System.Drawing.Point(72, 496);
  258. this.txt5.Name = "txt5";
  259. this.txt5.ReadOnly = true;
  260. this.txt5.TabIndex = 3;
  261. this.txt5.Text = "";
  262. // 
  263. // txt6
  264. // 
  265. this.txt6.Location = new System.Drawing.Point(264, 496);
  266. this.txt6.Name = "txt6";
  267. this.txt6.TabIndex = 3;
  268. this.txt6.Text = "";
  269. this.txt6.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt6_KeyPress);
  270. this.txt6.TextChanged += new System.EventHandler(this.txt6_TextChanged);
  271. // 
  272. // txt7
  273. // 
  274. this.txt7.Location = new System.Drawing.Point(432, 496);
  275. this.txt7.Name = "txt7";
  276. this.txt7.ReadOnly = true;
  277. this.txt7.TabIndex = 3;
  278. this.txt7.Text = "";
  279. // 
  280. // label1
  281. // 
  282. this.label1.Location = new System.Drawing.Point(72, 480);
  283. this.label1.Name = "label1";
  284. this.label1.Size = new System.Drawing.Size(100, 16);
  285. this.label1.TabIndex = 4;
  286. this.label1.Text = "合计金额";
  287. // 
  288. // label2
  289. // 
  290. this.label2.Location = new System.Drawing.Point(264, 480);
  291. this.label2.Name = "label2";
  292. this.label2.Size = new System.Drawing.Size(100, 16);
  293. this.label2.TabIndex = 4;
  294. this.label2.Text = "收款";
  295. // 
  296. // label3
  297. // 
  298. this.label3.Location = new System.Drawing.Point(432, 480);
  299. this.label3.Name = "label3";
  300. this.label3.Size = new System.Drawing.Size(100, 16);
  301. this.label3.TabIndex = 4;
  302. this.label3.Text = "找零";
  303. // 
  304. // btnCash
  305. // 
  306. this.btnCash.Image = ((System.Drawing.Image)(resources.GetObject("btnCash.Image")));
  307. this.btnCash.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  308. this.btnCash.Location = new System.Drawing.Point(576, 488);
  309. this.btnCash.Name = "btnCash";
  310. this.btnCash.TabIndex = 5;
  311. this.btnCash.Text = "收费";
  312. this.btnCash.Click += new System.EventHandler(this.btnCash_Click);
  313. // 
  314. // da2
  315. // 
  316. this.da2.SelectCommand = this.sqlSelectCommand1;
  317. this.da2.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
  318.   new System.Data.Common.DataTableMapping("Table", "门诊划价明细", new System.Data.Common.DataColumnMapping[] {
  319. new System.Data.Common.DataColumnMapping("编号", "编号"),
  320. new System.Data.Common.DataColumnMapping("药品编号", "药品编号"),
  321. new System.Data.Common.DataColumnMapping("名称", "名称"),
  322. new System.Data.Common.DataColumnMapping("单价", "单价"),
  323. new System.Data.Common.DataColumnMapping("数量", "数量"),
  324. new System.Data.Common.DataColumnMapping("金额", "金额"),
  325. new System.Data.Common.DataColumnMapping("划价编号", "划价编号")})});
  326. // 
  327. // sqlSelectCommand1
  328. // 
  329. this.sqlSelectCommand1.CommandText = "SELECT DISTINCT a.编号, a.药品编号, b.名称, a.单价, a.数量, a.金额, a.划价编号 FROM 门诊划价明细 a INNER " +
  330. "JOIN v收费项目及药品 b ON a.药品编号 = b.编号";
  331. this.sqlSelectCommand1.Connection = this.sqlConnection1;
  332. // 
  333. // sqlConnection1
  334. // 
  335. this.sqlConnection1.ConnectionString = "workstation id=localhost;packet size=4096;integrated security=SSPI;data source="." +
  336. "";persist security info=False;initial catalog=hisbook";
  337. // 
  338. // da1
  339. // 
  340. this.da1.SelectCommand = this.sqlSelectCommand2;
  341. this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
  342.   new System.Data.Common.DataTableMapping("Table", "门诊划价", new System.Data.Common.DataColumnMapping[] {
  343.   new System.Data.Common.DataColumnMapping("姓名", "姓名"),
  344.   new System.Data.Common.DataColumnMapping("性别", "性别"),
  345.   new System.Data.Common.DataColumnMapping("编号", "编号"),
  346.   new System.Data.Common.DataColumnMapping("科室", "科室"),
  347.   new System.Data.Common.DataColumnMapping("挂号编号", "挂号编号"),
  348.   new System.Data.Common.DataColumnMapping("医生", "医生"),
  349.   new System.Data.Common.DataColumnMapping("划价时间", "划价时间"),
  350.   new System.Data.Common.DataColumnMapping("划价员", "划价员"),
  351.   new System.Data.Common.DataColumnMapping("是否收费", "是否收费"),
  352.   new System.Data.Common.DataColumnMapping("收费员", "收费员"),
  353.   new System.Data.Common.DataColumnMapping("收费时间", "收费时间"),
  354.   new System.Data.Common.DataColumnMapping("划价金额", "划价金额"),
  355.   new System.Data.Common.DataColumnMapping("是否发药", "是否发药"),
  356.   new System.Data.Common.DataColumnMapping("发药时间", "发药时间"),
  357.   new System.Data.Common.DataColumnMapping("发药员", "发药员")})});
  358. // 
  359. // sqlSelectCommand2
  360. // 
  361. this.sqlSelectCommand2.CommandText = "SELECT b.姓名, b.性别, a.编号, a.科室, a.挂号编号, a.医生, a.划价时间, a.划价员, a.是否收费, a.收费员, a.收费时间" +
  362. ", a.划价金额, a.是否发药, a.发药时间, a.发药员 FROM 门诊划价 a INNER JOIN 门诊挂号 b ON a.挂号编号 = b.编号 W" +
  363. "HERE (a.是否收费 = '否')";
  364. this.sqlSelectCommand2.Connection = this.sqlConnection1;
  365. // 
  366. // ClinicCharge
  367. // 
  368. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  369. this.ClientSize = new System.Drawing.Size(720, 525);
  370. this.Controls.Add(this.btnCash);
  371. this.Controls.Add(this.label1);
  372. this.Controls.Add(this.txt5);
  373. this.Controls.Add(this.dataGrid2);
  374. this.Controls.Add(this.dataGrid1);
  375. this.Controls.Add(this.groupBox1);
  376. this.Controls.Add(this.txt6);
  377. this.Controls.Add(this.txt7);
  378. this.Controls.Add(this.label2);
  379. this.Controls.Add(this.label3);
  380. this.Name = "ClinicCharge";
  381. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  382. this.Text = "【门诊收费】";
  383. this.Load += new System.EventHandler(this.ClinicCharge_Load);
  384. this.groupBox1.ResumeLayout(false);
  385. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  386. ((System.ComponentModel.ISupportInitialize)(this.dataView1)).EndInit();
  387. ((System.ComponentModel.ISupportInitialize)(this.dataSet21)).EndInit();
  388. ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
  389. ((System.ComponentModel.ISupportInitialize)(this.dataView2)).EndInit();
  390. this.ResumeLayout(false);
  391. }
  392. #endregion
  393. //---------初始化窗体,填充数据集----------
  394. private void ClinicCharge_Load(object sender, System.EventArgs e)
  395. {
  396. //填充数据集
  397. da1.Fill(dataSet21);
  398. da2.Fill(dataSet21);
  399. //显示时,首先显示第一个划价单的明细
  400. dataView2.RowFilter="划价编号='"+dataGrid1[0,2].ToString().Trim()+"'";
  401. //明细数据根据选择的划价单编号而变化
  402. dataGrid1.CurrentCellChanged+=new EventHandler(dataGrid1_CurrentCellChanged);
  403. }
  404. //-------------显示划价单明细----------------
  405. private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
  406. {
  407. txt6.Clear();
  408. txt7.Clear();
  409. int i=dataGrid1.CurrentRowIndex;
  410.             dataView2.RowFilter="划价编号='"+dataGrid1[i,2].ToString().Trim()+"'";
  411. }
  412. //------------根据输入条件检索划价数据--------------
  413. private void btnSearch_Click(object sender, System.EventArgs e)
  414. {
  415. string filter="";
  416. if(txt1.Text.Trim()!="")
  417. {
  418. filter+="编号 like '%"+txt1.Text.Trim()+"%' AND ";
  419. }
  420. if(txt2.Text.Trim()!="")
  421. {
  422. filter+="姓名 like '%"+txt2.Text.Trim()+"%' AND ";
  423. }
  424. if(txt3.Text.Trim()!="")
  425. {
  426. filter+="划价时间>='"+txt3.Text.Trim()+"' AND ";
  427. }
  428. if(txt4.Text.Trim()!="")
  429. {
  430. filter+="划价时间<='"+txt4.Text.Trim()+"' AND ";
  431. }
  432. int length=filter.Length;
  433. if(length>0)
  434. {
  435. filter=filter.Substring(0,length-5);
  436. }
  437. dataView1.RowFilter=filter;
  438. if(dataView1.Count>0)//有确定的划价数据再显示明细
  439. {
  440. dataView2.RowFilter="划价编号='"+dataGrid1[0,2].ToString().Trim()+"'";
  441. }
  442. }
  443. //-----------根据输入金额计算找零-------------
  444. private void txt6_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  445. {
  446. //除小数点,数字和Del键之外,不相应其他键
  447. if(!(e.KeyChar=='.'||(e.KeyChar>='0'&&e.KeyChar<='9'))||e.KeyChar=='8')
  448. {
  449. e.Handled=true;
  450. }
  451. }
  452. //-----------随时计算找零金额------------
  453. private void txt6_TextChanged(object sender, System.EventArgs e)
  454. {
  455. if(txt5.Text.Trim()=="")//无合计金额不计算
  456. {
  457. return;
  458. }
  459. decimal money=0;
  460. money=Convert.ToDecimal(txt6.Text)-Convert.ToDecimal(txt5.Text);
  461. txt7.Text=money.ToString();
  462. }
  463. //------------执行收费-----------
  464. private void btnCash_Click(object sender, System.EventArgs e)
  465. {
  466. if(txt7.Text=="")//检查收款金额
  467. {
  468. MessageBox.Show("未输入收款金额","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  469. return;
  470. }
  471. if(Convert.ToDecimal(txt7.Text)<0)
  472. {
  473. MessageBox.Show("收款不足支付费用","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  474. return;
  475. }
  476. //收取款项,更新数据库
  477. string strConn="workstation id=localhost;Integrated Security=SSPI;Database=hisbook;";
  478. SqlConnection cn=new SqlConnection(strConn);
  479. cn.Open();
  480. SqlCommand cmd=cn.CreateCommand();
  481. cmd.CommandText="update 门诊划价 set 是否收费='是',收费时间='"+System.DateTime.Now.ToString()
  482. +"' where 编号='"+dataGrid1[dataGrid1.CurrentRowIndex,2].ToString().Trim()+"'";
  483. cmd.ExecuteNonQuery();
  484. dataSet21.Clear();//刷新数据集
  485. da1.Fill(dataSet21);
  486. da2.Fill(dataSet21);
  487. }
  488. }
  489. }