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

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. //该源码下载自win.51aspx.com(51aspx.com)
  9. namespace 医院管理系统
  10. {
  11. /// <summary>
  12. /// ClinicPriceConfirm 的摘要说明。
  13. /// </summary>
  14. public class ClinicPriceConfirm : System.Windows.Forms.Form
  15. {
  16. private DataTable newTable;//保存门诊划价中的药品和收费项目信息
  17. private System.Windows.Forms.GroupBox groupBox1;
  18. private System.Windows.Forms.DataGrid dataGrid1;
  19. private System.Windows.Forms.GroupBox groupBox2;
  20. private System.Windows.Forms.Label label1;
  21. private System.Windows.Forms.Label label2;
  22. private System.Windows.Forms.Label label3;
  23. private System.Windows.Forms.Label label4;
  24. private System.Windows.Forms.Label label5;
  25. private System.Windows.Forms.Label label6;
  26. private System.Windows.Forms.DataGrid dataGrid3;
  27. private System.Data.SqlClient.SqlDataAdapter da1;
  28. private 医院管理系统.DataSet2 dataSet21;
  29. private System.Data.SqlClient.SqlDataAdapter da2;
  30. private System.Windows.Forms.TextBox txt1;
  31. private System.Windows.Forms.ComboBox cmb1;
  32. private System.Windows.Forms.TextBox txt2;
  33. private System.Windows.Forms.TextBox txt4;
  34. private System.Windows.Forms.TextBox txt3;
  35. private System.Windows.Forms.TextBox txt5;
  36. private System.Windows.Forms.DataGrid dataGrid2;
  37. private System.Data.DataView dataView1;
  38. private System.Windows.Forms.Button btnOK;
  39. private System.Windows.Forms.Button btnCancel;
  40. private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
  41. private System.Data.SqlClient.SqlConnection sqlConnection1;
  42. private System.Data.SqlClient.SqlCommand sqlSelectCommand2;
  43. /// <summary>
  44. /// 必需的设计器变量。
  45. /// </summary>
  46. private System.ComponentModel.Container components = null;
  47. public ClinicPriceConfirm()
  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(ClinicPriceConfirm));
  79. this.groupBox1 = new System.Windows.Forms.GroupBox();
  80. this.txt1 = new System.Windows.Forms.TextBox();
  81. this.label1 = new System.Windows.Forms.Label();
  82. this.cmb1 = new System.Windows.Forms.ComboBox();
  83. this.label2 = new System.Windows.Forms.Label();
  84. this.txt2 = new System.Windows.Forms.TextBox();
  85. this.label3 = new System.Windows.Forms.Label();
  86. this.dataSet21 = new 医院管理系统.DataSet2();
  87. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  88. this.groupBox2 = new System.Windows.Forms.GroupBox();
  89. this.btnOK = new System.Windows.Forms.Button();
  90. this.txt4 = new System.Windows.Forms.TextBox();
  91. this.label4 = new System.Windows.Forms.Label();
  92. this.txt3 = new System.Windows.Forms.TextBox();
  93. this.label5 = new System.Windows.Forms.Label();
  94. this.txt5 = new System.Windows.Forms.TextBox();
  95. this.label6 = new System.Windows.Forms.Label();
  96. this.btnCancel = new System.Windows.Forms.Button();
  97. this.dataGrid3 = new System.Windows.Forms.DataGrid();
  98. this.dataView1 = new System.Data.DataView();
  99. this.da1 = new System.Data.SqlClient.SqlDataAdapter();
  100. this.da2 = new System.Data.SqlClient.SqlDataAdapter();
  101. this.dataGrid2 = new System.Windows.Forms.DataGrid();
  102. this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
  103. this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
  104. this.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand();
  105. this.groupBox1.SuspendLayout();
  106. ((System.ComponentModel.ISupportInitialize)(this.dataSet21)).BeginInit();
  107. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  108. this.groupBox2.SuspendLayout();
  109. ((System.ComponentModel.ISupportInitialize)(this.dataGrid3)).BeginInit();
  110. ((System.ComponentModel.ISupportInitialize)(this.dataView1)).BeginInit();
  111. ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).BeginInit();
  112. this.SuspendLayout();
  113. // 
  114. // groupBox1
  115. // 
  116. this.groupBox1.Controls.Add(this.txt1);
  117. this.groupBox1.Controls.Add(this.label1);
  118. this.groupBox1.Controls.Add(this.cmb1);
  119. this.groupBox1.Controls.Add(this.label2);
  120. this.groupBox1.Controls.Add(this.txt2);
  121. this.groupBox1.Controls.Add(this.label3);
  122. this.groupBox1.Location = new System.Drawing.Point(0, 0);
  123. this.groupBox1.Name = "groupBox1";
  124. this.groupBox1.Size = new System.Drawing.Size(704, 88);
  125. this.groupBox1.TabIndex = 0;
  126. this.groupBox1.TabStop = false;
  127. this.groupBox1.Text = "挂号信息";
  128. // 
  129. // txt1
  130. // 
  131. this.txt1.Location = new System.Drawing.Point(232, 56);
  132. this.txt1.Name = "txt1";
  133. this.txt1.ReadOnly = true;
  134. this.txt1.Size = new System.Drawing.Size(128, 21);
  135. this.txt1.TabIndex = 2;
  136. this.txt1.Text = "";
  137. // 
  138. // label1
  139. // 
  140. this.label1.Location = new System.Drawing.Point(56, 40);
  141. this.label1.Name = "label1";
  142. this.label1.Size = new System.Drawing.Size(100, 16);
  143. this.label1.TabIndex = 1;
  144. this.label1.Text = "门诊号";
  145. // 
  146. // cmb1
  147. // 
  148. this.cmb1.Location = new System.Drawing.Point(56, 56);
  149. this.cmb1.Name = "cmb1";
  150. this.cmb1.Size = new System.Drawing.Size(136, 20);
  151. this.cmb1.TabIndex = 0;
  152. this.cmb1.DropDown += new System.EventHandler(this.cmb1_DropDown);
  153. // 
  154. // label2
  155. // 
  156. this.label2.Location = new System.Drawing.Point(232, 40);
  157. this.label2.Name = "label2";
  158. this.label2.Size = new System.Drawing.Size(100, 16);
  159. this.label2.TabIndex = 1;
  160. this.label2.Text = "姓名";
  161. // 
  162. // txt2
  163. // 
  164. this.txt2.Location = new System.Drawing.Point(416, 56);
  165. this.txt2.Name = "txt2";
  166. this.txt2.ReadOnly = true;
  167. this.txt2.Size = new System.Drawing.Size(128, 21);
  168. this.txt2.TabIndex = 2;
  169. this.txt2.Text = "";
  170. // 
  171. // label3
  172. // 
  173. this.label3.Location = new System.Drawing.Point(416, 40);
  174. this.label3.Name = "label3";
  175. this.label3.Size = new System.Drawing.Size(100, 16);
  176. this.label3.TabIndex = 1;
  177. this.label3.Text = "性别";
  178. // 
  179. // dataSet21
  180. // 
  181. this.dataSet21.DataSetName = "DataSet2";
  182. this.dataSet21.Locale = new System.Globalization.CultureInfo("zh-CN");
  183. // 
  184. // dataGrid1
  185. // 
  186. this.dataGrid1.CaptionVisible = false;
  187. this.dataGrid1.DataMember = "";
  188. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  189. this.dataGrid1.Location = new System.Drawing.Point(0, 88);
  190. this.dataGrid1.Name = "dataGrid1";
  191. this.dataGrid1.Size = new System.Drawing.Size(712, 328);
  192. this.dataGrid1.TabIndex = 1;
  193. // 
  194. // groupBox2
  195. // 
  196. this.groupBox2.Controls.Add(this.btnOK);
  197. this.groupBox2.Controls.Add(this.txt4);
  198. this.groupBox2.Controls.Add(this.label4);
  199. this.groupBox2.Controls.Add(this.txt3);
  200. this.groupBox2.Controls.Add(this.label5);
  201. this.groupBox2.Controls.Add(this.txt5);
  202. this.groupBox2.Controls.Add(this.label6);
  203. this.groupBox2.Controls.Add(this.btnCancel);
  204. this.groupBox2.Location = new System.Drawing.Point(0, 416);
  205. this.groupBox2.Name = "groupBox2";
  206. this.groupBox2.Size = new System.Drawing.Size(704, 100);
  207. this.groupBox2.TabIndex = 2;
  208. this.groupBox2.TabStop = false;
  209. // 
  210. // btnOK
  211. // 
  212. this.btnOK.Image = ((System.Drawing.Image)(resources.GetObject("btnOK.Image")));
  213. this.btnOK.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  214. this.btnOK.Location = new System.Drawing.Point(512, 54);
  215. this.btnOK.Name = "btnOK";
  216. this.btnOK.TabIndex = 3;
  217. this.btnOK.Text = "保存";
  218. this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
  219. // 
  220. // txt4
  221. // 
  222. this.txt4.Location = new System.Drawing.Point(200, 56);
  223. this.txt4.Name = "txt4";
  224. this.txt4.ReadOnly = true;
  225. this.txt4.Size = new System.Drawing.Size(128, 21);
  226. this.txt4.TabIndex = 2;
  227. this.txt4.Text = "";
  228. // 
  229. // label4
  230. // 
  231. this.label4.Location = new System.Drawing.Point(200, 40);
  232. this.label4.Name = "label4";
  233. this.label4.Size = new System.Drawing.Size(100, 16);
  234. this.label4.TabIndex = 1;
  235. this.label4.Text = "医生";
  236. // 
  237. // txt3
  238. // 
  239. this.txt3.Location = new System.Drawing.Point(48, 56);
  240. this.txt3.Name = "txt3";
  241. this.txt3.ReadOnly = true;
  242. this.txt3.Size = new System.Drawing.Size(128, 21);
  243. this.txt3.TabIndex = 2;
  244. this.txt3.Text = "";
  245. // 
  246. // label5
  247. // 
  248. this.label5.Location = new System.Drawing.Point(48, 40);
  249. this.label5.Name = "label5";
  250. this.label5.Size = new System.Drawing.Size(100, 16);
  251. this.label5.TabIndex = 1;
  252. this.label5.Text = "科室";
  253. // 
  254. // txt5
  255. // 
  256. this.txt5.Location = new System.Drawing.Point(360, 56);
  257. this.txt5.Name = "txt5";
  258. this.txt5.ReadOnly = true;
  259. this.txt5.Size = new System.Drawing.Size(128, 21);
  260. this.txt5.TabIndex = 2;
  261. this.txt5.Text = "";
  262. // 
  263. // label6
  264. // 
  265. this.label6.Location = new System.Drawing.Point(360, 40);
  266. this.label6.Name = "label6";
  267. this.label6.Size = new System.Drawing.Size(100, 16);
  268. this.label6.TabIndex = 1;
  269. this.label6.Text = "金额合计";
  270. // 
  271. // btnCancel
  272. // 
  273. this.btnCancel.Image = ((System.Drawing.Image)(resources.GetObject("btnCancel.Image")));
  274. this.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  275. this.btnCancel.Location = new System.Drawing.Point(608, 54);
  276. this.btnCancel.Name = "btnCancel";
  277. this.btnCancel.TabIndex = 3;
  278. this.btnCancel.Text = "取消";
  279. this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
  280. // 
  281. // dataGrid3
  282. // 
  283. this.dataGrid3.CaptionVisible = false;
  284. this.dataGrid3.DataMember = "";
  285. this.dataGrid3.DataSource = this.dataView1;
  286. this.dataGrid3.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  287. this.dataGrid3.Location = new System.Drawing.Point(56, 264);
  288. this.dataGrid3.Name = "dataGrid3";
  289. this.dataGrid3.ReadOnly = true;
  290. this.dataGrid3.Size = new System.Drawing.Size(496, 120);
  291. this.dataGrid3.TabIndex = 4;
  292. this.dataGrid3.Visible = false;
  293. this.dataGrid3.DoubleClick += new System.EventHandler(this.dataGrid3_DoubleClick);
  294. // 
  295. // dataView1
  296. // 
  297. this.dataView1.Table = this.dataSet21.v收费项目及药品;
  298. // 
  299. // da1
  300. // 
  301. this.da1.SelectCommand = this.sqlSelectCommand1;
  302. this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
  303.   new System.Data.Common.DataTableMapping("Table", "门诊挂号", new System.Data.Common.DataColumnMapping[] {
  304.   new System.Data.Common.DataColumnMapping("编号", "编号"),
  305.   new System.Data.Common.DataColumnMapping("病人编号", "病人编号"),
  306.   new System.Data.Common.DataColumnMapping("姓名", "姓名"),
  307.   new System.Data.Common.DataColumnMapping("性别", "性别"),
  308.   new System.Data.Common.DataColumnMapping("挂号科室", "挂号科室"),
  309.   new System.Data.Common.DataColumnMapping("费用类型", "费用类型"),
  310.   new System.Data.Common.DataColumnMapping("挂号类型", "挂号类型"),
  311.   new System.Data.Common.DataColumnMapping("挂号费用", "挂号费用"),
  312.   new System.Data.Common.DataColumnMapping("医生", "医生"),
  313.   new System.Data.Common.DataColumnMapping("时间", "时间"),
  314.   new System.Data.Common.DataColumnMapping("是否已划价", "是否已划价")})});
  315. // 
  316. // da2
  317. // 
  318. this.da2.SelectCommand = this.sqlSelectCommand2;
  319. this.da2.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
  320.   new System.Data.Common.DataTableMapping("Table", "v收费项目及药品", 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.   new System.Data.Common.DataColumnMapping("拼音码", "拼音码")})});
  327. // 
  328. // dataGrid2
  329. // 
  330. this.dataGrid2.CaptionVisible = false;
  331. this.dataGrid2.DataMember = "门诊挂号";
  332. this.dataGrid2.DataSource = this.dataSet21;
  333. this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  334. this.dataGrid2.Location = new System.Drawing.Point(56, 96);
  335. this.dataGrid2.Name = "dataGrid2";
  336. this.dataGrid2.ReadOnly = true;
  337. this.dataGrid2.Size = new System.Drawing.Size(560, 144);
  338. this.dataGrid2.TabIndex = 6;
  339. this.dataGrid2.Visible = false;
  340. this.dataGrid2.DoubleClick += new System.EventHandler(this.dataGrid2_DoubleClick);
  341. // 
  342. // sqlSelectCommand1
  343. // 
  344. this.sqlSelectCommand1.CommandText = "SELECT 编号, 病人编号, 姓名, 性别, 挂号科室, 费用类型, 挂号类型, 挂号费用, 医生, 时间, 是否已划价 FROM 门诊挂号 WHERE (是" +
  345. "否已划价 = '否')";
  346. this.sqlSelectCommand1.Connection = this.sqlConnection1;
  347. // 
  348. // sqlConnection1
  349. // 
  350. this.sqlConnection1.ConnectionString = "workstation id=localhost;packet size=4096;integrated security=SSPI;data source="." +
  351. "";persist security info=False;initial catalog=hisbook";
  352. // 
  353. // sqlSelectCommand2
  354. // 
  355. this.sqlSelectCommand2.CommandText = "SELECT 编号, 名称, 规格, 单位, 单价, 拼音码 FROM v收费项目及药品";
  356. this.sqlSelectCommand2.Connection = this.sqlConnection1;
  357. // 
  358. // ClinicPriceConfirm
  359. // 
  360. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  361. this.ClientSize = new System.Drawing.Size(704, 517);
  362. this.Controls.Add(this.dataGrid2);
  363. this.Controls.Add(this.dataGrid3);
  364. this.Controls.Add(this.groupBox2);
  365. this.Controls.Add(this.dataGrid1);
  366. this.Controls.Add(this.groupBox1);
  367. this.Name = "ClinicPriceConfirm";
  368. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  369. this.Text = "【门诊划价】";
  370. this.Load += new System.EventHandler(this.ClinicPriceConfirm_Load);
  371. this.groupBox1.ResumeLayout(false);
  372. ((System.ComponentModel.ISupportInitialize)(this.dataSet21)).EndInit();
  373. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  374. this.groupBox2.ResumeLayout(false);
  375. ((System.ComponentModel.ISupportInitialize)(this.dataGrid3)).EndInit();
  376. ((System.ComponentModel.ISupportInitialize)(this.dataView1)).EndInit();
  377. ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
  378. this.ResumeLayout(false);
  379. }
  380. #endregion
  381. //--------------读入全部信息-----------------
  382. private void ClinicPriceConfirm_Load(object sender, System.EventArgs e)
  383. {
  384. da1.Fill(dataSet21);
  385. da2.Fill(dataSet21);
  386. this.DataGridStateControl();
  387. //每当表格中数据变化时,计算金额
  388. newTable.RowChanged+=new DataRowChangeEventHandler(newTable_RowChanged);
  389. }
  390. //----------设置明细表格各列的属性----------
  391. private void DataGridStateControl()
  392. {
  393. newTable = new DataTable();
  394. newTable.Columns.Add("编号",typeof(string));
  395. newTable.Columns.Add("名称",typeof(string));
  396. newTable.Columns.Add("规格",typeof(string));
  397. newTable.Columns.Add("单位",typeof(string));
  398. newTable.Columns.Add("单价",typeof(decimal));
  399. newTable.Columns.Add("数量",typeof(int));
  400. newTable.Columns.Add("金额",typeof(decimal),"单价*数量");
  401. this.dataGrid1.DataSource = newTable;
  402. DataGridTableStyle ts = new DataGridTableStyle();
  403. DataGridTextBoxColumn aColumnTextColumn;
  404. ts.AllowSorting = false;
  405. ts.AlternatingBackColor = Color.LightGray;
  406. ts.MappingName = newTable.TableName;
  407. int numCols = newTable.Columns.Count;
  408. for (int i = 0;i< numCols;i++)
  409. {
  410. aColumnTextColumn = new DataGridTextBoxColumn();
  411. if( i==5 )//表中只允许编辑【数量】字段
  412. {
  413. aColumnTextColumn.ReadOnly=false;
  414. }
  415. else
  416. {
  417. aColumnTextColumn.ReadOnly=true;
  418. }
  419. if (i == 0)//当在第0列中输入后并按enter后,允许响应
  420. {
  421. aColumnTextColumn.TextBox.DoubleClick+=new EventHandler(TextBox_DoubleClick);
  422. }
  423. if(i==0)
  424. {
  425. aColumnTextColumn.Width=130;//设置药品编号字段宽度
  426. }
  427. if ( i == 1 )
  428. {
  429. aColumnTextColumn.Width = 150;//设置药品名称字段宽度
  430. }
  431. aColumnTextColumn.MappingName = newTable.Columns[i].ColumnName;
  432. aColumnTextColumn.HeaderText = newTable.Columns[i].ColumnName;
  433. if(i==0)
  434. {
  435. aColumnTextColumn.HeaderText ="编号【双击输入拼音】";
  436. }
  437. aColumnTextColumn.NullText = "";
  438. aColumnTextColumn.Format = "N"; //设置为数字格式显示
  439. ts.GridColumnStyles.Add(aColumnTextColumn);
  440. }
  441. dataGrid1.TableStyles.Add(ts);
  442. }
  443. //-----------显示选择已经挂号但还未划价的病人名单----------
  444. private void cmb1_DropDown(object sender, System.EventArgs e)
  445. {
  446. this.clearInfo();//先清空信息
  447. dataGrid2.Left=cmb1.Left;//设置表格位置
  448. dataGrid2.Top=cmb1.Bottom+2;
  449. dataGrid2.Visible=true;//显示表格
  450. dataGrid2.Show();
  451. dataGrid2.Focus();
  452. }
  453. //------------双击病人清单,选择门诊挂号记录------------
  454. private void dataGrid2_DoubleClick(object sender, System.EventArgs e)
  455. {
  456. int rowIndex=dataGrid2.CurrentCell.RowNumber;
  457.             cmb1.Text=dataGrid2[rowIndex,0].ToString().Trim();//病人编号
  458.             txt1.Text=dataGrid2[rowIndex,2].ToString().Trim();//姓名
  459. txt2.Text=dataGrid2[rowIndex,3].ToString().Trim();//性别
  460. txt3.Text=dataGrid2[rowIndex,4].ToString().Trim();//挂号科室
  461. txt4.Text=dataGrid2[rowIndex,8].ToString().Trim();//挂号医生
  462. dataGrid2.Visible=false;
  463. }
  464. //---------双击编号栏输入拼音后,显示药品和医疗项目表格-----------
  465. private void TextBox_DoubleClick(object sender, EventArgs e)
  466. {
  467. string pym;//通过输入框输入拼音码
  468. InputBox newfrm = new InputBox();
  469.             newfrm.label1.Text = "请输入药品或收费项目的拼音码:";
  470. newfrm.Text="输入";
  471. newfrm.Top=this.Top+this.Height/2;
  472. newfrm.Left=this.Left+this.Width/2;
  473.             newfrm.ShowDialog();
  474.             pym = newfrm.result;
  475. newfrm.Dispose();
  476. dataView1.RowFilter="拼音码 like '%"+pym+"%'";
  477. dataGrid3.Left=dataGrid1.Left+10;
  478. dataGrid3.Top=(dataGrid1.CurrentCell.RowNumber+1)*17+20+dataGrid1.Top;
  479. if(dataView1.Count!=0)
  480. {
  481. dataGrid3.Visible=true;//显示表格
  482. dataGrid3.Show();
  483. dataGrid3.Focus();
  484. }
  485. }
  486. //-----------双击药品和收费项目清单,添加划价明细--------------
  487. private void dataGrid3_DoubleClick(object sender, System.EventArgs e)
  488. {
  489. int rowIndex=dataGrid3.CurrentCell.RowNumber;//药品和收费清单表格中当前行号
  490. DataRow aRow=newTable.NewRow();
  491. aRow["编号"]=dataGrid3[rowIndex,0].ToString();//输入编号
  492. aRow["名称"]=dataGrid3[rowIndex,1].ToString();//输入名称
  493. aRow["规格"]=dataGrid3[rowIndex,2].ToString();//输入规格
  494. aRow["单位"]=dataGrid3[rowIndex,3].ToString();//输入单位
  495. aRow["单价"]=Convert.ToDecimal(dataGrid3[rowIndex,4]).ToString();//输入单价
  496. newTable.Rows.Add(aRow);
  497. dataGrid3.Visible=false;//隐藏表格
  498. }
  499. //--------计算合计金额----------
  500. private void sumMoney()
  501. {
  502. decimal total=0;//总金额
  503. foreach(DataRow aRow in newTable.Rows)
  504. {
  505. if(aRow["金额"].ToString().Trim()!="")
  506. {
  507. total+=Convert.ToDecimal(aRow["金额"]);
  508. }
  509. }
  510. txt5.Text=total.ToString();
  511. }
  512. //---------每当明细表发生变化,则计算总计金额------------
  513. private void newTable_RowChanged(object sender, DataRowChangeEventArgs e)
  514. {
  515. this.sumMoney();
  516. }
  517. //-----------保存成功或取消后,设置窗体中文本框等的显示----------
  518. private void clearInfo()
  519. {
  520. newTable.Clear();
  521. txt1.Clear();
  522. txt2.Clear();
  523. txt3.Clear();
  524. txt4.Clear();
  525. txt5.Clear();
  526. cmb1.Text="";
  527. }
  528. //---------在新增信息时,根据sql语句计算并设置新的门诊挂号编号和病人信息---------
  529. private string CreateNewID(string sql)
  530. {
  531. string strConn="workstation id=localhost;Integrated Security=SSPI;database=hisbook;";
  532. SqlConnection cn=new SqlConnection(strConn);
  533. cn.Open();
  534. SqlCommand cmb=cn.CreateCommand();
  535. cmb.CommandText=sql;
  536. string result;
  537. if(cmb.ExecuteScalar()!=System.DBNull.Value)
  538. {
  539. result=cmb.ExecuteScalar().ToString().Trim();
  540. }
  541. else
  542. {
  543. return(System.DateTime.Now.Year.ToString()+"0000001");//命名规则为年份+7位编号
  544. }
  545. result=result.Substring(4,7);
  546. int newID=Convert.ToInt32(result)+1;
  547. int length=newID.ToString().Length;
  548. string returnStr=System.DateTime.Now.Year.ToString();
  549. switch(length)//生成新的编码
  550. {
  551. case 1:
  552. returnStr+="000000"+newID.ToString();
  553. break;
  554. case 2:
  555. returnStr+="00000"+newID.ToString();
  556. break;
  557. case 3:
  558. returnStr+="0000"+newID.ToString();
  559. break;
  560. case 4:
  561. returnStr+="000"+newID.ToString();
  562. break;
  563. case 5:
  564. returnStr+="00"+newID.ToString();
  565. break;
  566. case 6:
  567. returnStr+="0"+newID.ToString();
  568. break;
  569. case 7:
  570. returnStr+=newID.ToString();
  571. break;
  572. }
  573. return(returnStr);
  574. }
  575. //-------------保存门诊划价记录---------------
  576. private void btnOK_Click(object sender, System.EventArgs e)
  577. {
  578. //先检查是否输入完全
  579. if(cmb1.Text=="")
  580. {
  581. MessageBox.Show("请先选择门诊号","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  582. return;
  583. }
  584. if(newTable.Rows.Count==0)
  585. {
  586. MessageBox.Show("请填写药品和收费项目明细表","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  587. return;
  588. }
  589. foreach(DataRow aRow in newTable.Rows)//逐行检查明细数据是否已经全部输入了数量
  590. {
  591. if(aRow["金额"].ToString().Trim()=="")
  592. {
  593. MessageBox.Show("请填写药品或收费项目数量","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  594. return;
  595. }
  596. }
  597. string strConn="workstation id=localhost;Integrated Security=SSPI;database=hisbook;";
  598. SqlConnection cn=new SqlConnection(strConn);
  599. cn.Open();
  600. SqlCommand cmd=cn.CreateCommand();
  601. string newID=this.CreateNewID("select max(编号) 最大编号 from 门诊划价");//计算新的门诊划价编号
  602. //保存门诊划价数据
  603. string insertStr="insert into 门诊划价([编号], [科室], [挂号编号], [医生], [划价时间],"
  604. +"[是否收费], [划价金额], [是否发药]) values('"+newID+"','"+txt3.Text+"','"+cmb1.Text
  605. +"','"+txt4.Text+"','"+System.DateTime.Now.ToString()+"','否',CAST('"+txt5.Text+"' as money)"
  606. +",'否')";
  607. try
  608. {
  609. cmd.CommandText=insertStr;
  610. cmd.ExecuteNonQuery();
  611. }
  612. catch(Exception express)
  613. {
  614. MessageBox.Show(express.ToString(),"新增门诊挂号错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
  615. return;
  616. }
  617. foreach(DataRow aRow in newTable.Rows)//保存明细
  618. {
  619. insertStr="insert into 门诊划价明细([划价编号], [药品编号], [单价], [数量], [金额]) "
  620. +"values('"+newID+"','"+aRow["编号"].ToString()+"','"+aRow["单价"].ToString()+"','"
  621. +aRow["数量"].ToString()+"','"+aRow["金额"].ToString()+"')";
  622. try
  623. {
  624. cmd.CommandText=insertStr;
  625. cmd.ExecuteNonQuery();
  626. }
  627. catch(Exception express)
  628. {
  629. MessageBox.Show(express.ToString(),"新增门诊明细错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
  630. return;
  631. }
  632. }
  633. cmd.CommandText="update 门诊挂号 set 是否已划价='是' where 编号='"+cmb1.Text+"'";//记录已经划价的门诊挂号
  634. cmd.ExecuteNonQuery();
  635. this.clearInfo();
  636. dataSet21.Clear();//刷新数据集
  637. da1.Fill(dataSet21);
  638. da2.Fill(dataSet21);
  639. }
  640. //------------取消保存------------
  641. private void btnCancel_Click(object sender, System.EventArgs e)
  642. {
  643. this.clearInfo();
  644. }
  645. }
  646. }