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

企业管理

开发平台:

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