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

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. /// ClinicReg 的摘要说明。
  12. /// </summary>
  13. public class ClinicReg : System.Windows.Forms.Form
  14. {
  15. private string regID,infoID;//保存门诊挂号编号和病人信息库编号
  16. private System.Windows.Forms.GroupBox groupBox1;
  17. private System.Windows.Forms.GroupBox groupBox2;
  18. private System.Windows.Forms.GroupBox groupBox3;
  19. private System.Windows.Forms.Label label1;
  20. private System.Windows.Forms.TextBox txt1;
  21. private System.Windows.Forms.Label label2;
  22. private System.Windows.Forms.ComboBox cmb1;
  23. private System.Windows.Forms.TextBox txt2;
  24. private System.Windows.Forms.Label label3;
  25. private System.Windows.Forms.Label label4;
  26. private System.Windows.Forms.ComboBox cmb2;
  27. private System.Windows.Forms.Label label5;
  28. private System.Windows.Forms.ComboBox cmb3;
  29. private System.Windows.Forms.Label label6;
  30. private System.Windows.Forms.ComboBox cmb4;
  31. private System.Windows.Forms.Label label7;
  32. private System.Windows.Forms.ComboBox cmb5;
  33. private System.Windows.Forms.Label label8;
  34. private System.Windows.Forms.ComboBox cmb6;
  35. private System.Windows.Forms.Label label9;
  36. private System.Windows.Forms.Label label10;
  37. private System.Windows.Forms.ImageList imageList1;
  38. protected System.Windows.Forms.ToolBar toolBar1;
  39. private System.Windows.Forms.ToolBarButton tBtnNew;
  40. private System.Windows.Forms.ToolBarButton tBtnSubmit;
  41. private System.Windows.Forms.ToolBarButton tBtnCancel;
  42. private System.Windows.Forms.ToolBarButton tBtnQuit;
  43. private System.Windows.Forms.TextBox txt3;
  44. private System.Windows.Forms.TextBox txt4;
  45. private System.Windows.Forms.TextBox txt5;
  46. private System.Windows.Forms.TextBox txt6;
  47. private System.Windows.Forms.TextBox txt7;
  48. private System.Windows.Forms.TextBox txt8;
  49. private System.ComponentModel.IContainer components;
  50. public ClinicReg()
  51. {
  52. //
  53. // Windows 窗体设计器支持所必需的
  54. //
  55. InitializeComponent();
  56. //
  57. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  58. //
  59. }
  60. /// <summary>
  61. /// 清理所有正在使用的资源。
  62. /// </summary>
  63. protected override void Dispose( bool disposing )
  64. {
  65. if( disposing )
  66. {
  67. if(components != null)
  68. {
  69. components.Dispose();
  70. }
  71. }
  72. base.Dispose( disposing );
  73. }
  74. #region Windows 窗体设计器生成的代码
  75. /// <summary>
  76. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  77. /// 此方法的内容。
  78. /// </summary>
  79. private void InitializeComponent()
  80. {
  81. this.components = new System.ComponentModel.Container();
  82. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ClinicReg));
  83. this.txt5 = new System.Windows.Forms.TextBox();
  84. this.txt6 = new System.Windows.Forms.TextBox();
  85. this.txt7 = new System.Windows.Forms.TextBox();
  86. this.txt8 = new System.Windows.Forms.TextBox();
  87. this.groupBox1 = new System.Windows.Forms.GroupBox();
  88. this.label5 = new System.Windows.Forms.Label();
  89. this.cmb1 = new System.Windows.Forms.ComboBox();
  90. this.txt1 = new System.Windows.Forms.TextBox();
  91. this.label1 = new System.Windows.Forms.Label();
  92. this.groupBox2 = new System.Windows.Forms.GroupBox();
  93. this.groupBox3 = new System.Windows.Forms.GroupBox();
  94. this.label2 = new System.Windows.Forms.Label();
  95. this.txt2 = new System.Windows.Forms.TextBox();
  96. this.label3 = new System.Windows.Forms.Label();
  97. this.label4 = new System.Windows.Forms.Label();
  98. this.cmb2 = new System.Windows.Forms.ComboBox();
  99. this.cmb3 = new System.Windows.Forms.ComboBox();
  100. this.label6 = new System.Windows.Forms.Label();
  101. this.cmb4 = new System.Windows.Forms.ComboBox();
  102. this.label7 = new System.Windows.Forms.Label();
  103. this.cmb5 = new System.Windows.Forms.ComboBox();
  104. this.label8 = new System.Windows.Forms.Label();
  105. this.cmb6 = new System.Windows.Forms.ComboBox();
  106. this.label9 = new System.Windows.Forms.Label();
  107. this.txt3 = new System.Windows.Forms.TextBox();
  108. this.txt4 = new System.Windows.Forms.TextBox();
  109. this.label10 = new System.Windows.Forms.Label();
  110. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  111. this.toolBar1 = new System.Windows.Forms.ToolBar();
  112. this.tBtnNew = new System.Windows.Forms.ToolBarButton();
  113. this.tBtnSubmit = new System.Windows.Forms.ToolBarButton();
  114. this.tBtnCancel = new System.Windows.Forms.ToolBarButton();
  115. this.tBtnQuit = new System.Windows.Forms.ToolBarButton();
  116. this.groupBox1.SuspendLayout();
  117. this.SuspendLayout();
  118. // 
  119. // txt5
  120. // 
  121. this.txt5.BackColor = System.Drawing.SystemColors.Desktop;
  122. this.txt5.Enabled = false;
  123. this.txt5.Location = new System.Drawing.Point(0, 472);
  124. this.txt5.Name = "txt5";
  125. this.txt5.TabIndex = 0;
  126. this.txt5.Text = "必填";
  127. this.txt5.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
  128. // 
  129. // txt6
  130. // 
  131. this.txt6.Enabled = false;
  132. this.txt6.Location = new System.Drawing.Point(104, 472);
  133. this.txt6.Name = "txt6";
  134. this.txt6.TabIndex = 0;
  135. this.txt6.Text = "选填";
  136. this.txt6.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
  137. // 
  138. // txt7
  139. // 
  140. this.txt7.BackColor = System.Drawing.SystemColors.ControlLight;
  141. this.txt7.Enabled = false;
  142. this.txt7.Location = new System.Drawing.Point(208, 472);
  143. this.txt7.Name = "txt7";
  144. this.txt7.TabIndex = 0;
  145. this.txt7.Text = "自动";
  146. this.txt7.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
  147. // 
  148. // txt8
  149. // 
  150. this.txt8.BackColor = System.Drawing.SystemColors.Control;
  151. this.txt8.Enabled = false;
  152. this.txt8.Location = new System.Drawing.Point(312, 472);
  153. this.txt8.Name = "txt8";
  154. this.txt8.Size = new System.Drawing.Size(368, 21);
  155. this.txt8.TabIndex = 0;
  156. this.txt8.Text = "";
  157. // 
  158. // groupBox1
  159. // 
  160. this.groupBox1.Controls.Add(this.label5);
  161. this.groupBox1.Controls.Add(this.cmb1);
  162. this.groupBox1.Controls.Add(this.txt1);
  163. this.groupBox1.Controls.Add(this.label1);
  164. this.groupBox1.Controls.Add(this.groupBox2);
  165. this.groupBox1.Controls.Add(this.groupBox3);
  166. this.groupBox1.Controls.Add(this.label2);
  167. this.groupBox1.Controls.Add(this.txt2);
  168. this.groupBox1.Controls.Add(this.label3);
  169. this.groupBox1.Controls.Add(this.label4);
  170. this.groupBox1.Controls.Add(this.cmb2);
  171. this.groupBox1.Controls.Add(this.cmb3);
  172. this.groupBox1.Controls.Add(this.label6);
  173. this.groupBox1.Controls.Add(this.cmb4);
  174. this.groupBox1.Controls.Add(this.label7);
  175. this.groupBox1.Controls.Add(this.cmb5);
  176. this.groupBox1.Controls.Add(this.label8);
  177. this.groupBox1.Controls.Add(this.cmb6);
  178. this.groupBox1.Controls.Add(this.label9);
  179. this.groupBox1.Controls.Add(this.txt3);
  180. this.groupBox1.Controls.Add(this.txt4);
  181. this.groupBox1.Controls.Add(this.label10);
  182. this.groupBox1.Location = new System.Drawing.Point(0, 40);
  183. this.groupBox1.Name = "groupBox1";
  184. this.groupBox1.Size = new System.Drawing.Size(680, 432);
  185. this.groupBox1.TabIndex = 1;
  186. this.groupBox1.TabStop = false;
  187. this.groupBox1.Text = "挂号信息";
  188. // 
  189. // label5
  190. // 
  191. this.label5.Location = new System.Drawing.Point(72, 160);
  192. this.label5.Name = "label5";
  193. this.label5.Size = new System.Drawing.Size(56, 16);
  194. this.label5.TabIndex = 4;
  195. this.label5.Text = "费用类型";
  196. // 
  197. // cmb1
  198. // 
  199. this.cmb1.Items.AddRange(new object[] {
  200.   "男",
  201.   "女"});
  202. this.cmb1.Location = new System.Drawing.Point(208, 61);
  203. this.cmb1.Name = "cmb1";
  204. this.cmb1.Size = new System.Drawing.Size(104, 20);
  205. this.cmb1.TabIndex = 3;
  206. // 
  207. // txt1
  208. // 
  209. this.txt1.BackColor = System.Drawing.SystemColors.Desktop;
  210. this.txt1.Location = new System.Drawing.Point(56, 61);
  211. this.txt1.Name = "txt1";
  212. this.txt1.TabIndex = 2;
  213. this.txt1.Text = "";
  214. // 
  215. // label1
  216. // 
  217. this.label1.Location = new System.Drawing.Point(24, 64);
  218. this.label1.Name = "label1";
  219. this.label1.Size = new System.Drawing.Size(32, 16);
  220. this.label1.TabIndex = 1;
  221. this.label1.Text = "姓名";
  222. // 
  223. // groupBox2
  224. // 
  225. this.groupBox2.Location = new System.Drawing.Point(8, 120);
  226. this.groupBox2.Name = "groupBox2";
  227. this.groupBox2.Size = new System.Drawing.Size(664, 8);
  228. this.groupBox2.TabIndex = 0;
  229. this.groupBox2.TabStop = false;
  230. // 
  231. // groupBox3
  232. // 
  233. this.groupBox3.Location = new System.Drawing.Point(8, 288);
  234. this.groupBox3.Name = "groupBox3";
  235. this.groupBox3.Size = new System.Drawing.Size(664, 8);
  236. this.groupBox3.TabIndex = 0;
  237. this.groupBox3.TabStop = false;
  238. // 
  239. // label2
  240. // 
  241. this.label2.Location = new System.Drawing.Point(176, 64);
  242. this.label2.Name = "label2";
  243. this.label2.Size = new System.Drawing.Size(32, 16);
  244. this.label2.TabIndex = 1;
  245. this.label2.Text = "性别";
  246. // 
  247. // txt2
  248. // 
  249. this.txt2.Location = new System.Drawing.Point(368, 61);
  250. this.txt2.Name = "txt2";
  251. this.txt2.TabIndex = 2;
  252. this.txt2.Text = "";
  253. // 
  254. // label3
  255. // 
  256. this.label3.Location = new System.Drawing.Point(488, 64);
  257. this.label3.Name = "label3";
  258. this.label3.Size = new System.Drawing.Size(32, 16);
  259. this.label3.TabIndex = 1;
  260. this.label3.Text = "民族";
  261. // 
  262. // label4
  263. // 
  264. this.label4.Location = new System.Drawing.Point(336, 64);
  265. this.label4.Name = "label4";
  266. this.label4.Size = new System.Drawing.Size(32, 16);
  267. this.label4.TabIndex = 1;
  268. this.label4.Text = "年龄";
  269. // 
  270. // cmb2
  271. // 
  272. this.cmb2.Items.AddRange(new object[] {
  273.   "汉族",
  274.   "满族",
  275.   "蒙古族",
  276.   "回族",
  277.   "藏族",
  278.   "维吾尔族",
  279.   "哈萨克族"});
  280. this.cmb2.Location = new System.Drawing.Point(520, 61);
  281. this.cmb2.Name = "cmb2";
  282. this.cmb2.Size = new System.Drawing.Size(104, 20);
  283. this.cmb2.TabIndex = 3;
  284. // 
  285. // cmb3
  286. // 
  287. this.cmb3.BackColor = System.Drawing.SystemColors.Desktop;
  288. this.cmb3.Items.AddRange(new object[] {
  289.   "自费",
  290.   "公费",
  291.   "离休"});
  292. this.cmb3.Location = new System.Drawing.Point(128, 160);
  293. this.cmb3.Name = "cmb3";
  294. this.cmb3.Size = new System.Drawing.Size(136, 20);
  295. this.cmb3.TabIndex = 3;
  296. // 
  297. // label6
  298. // 
  299. this.label6.Location = new System.Drawing.Point(328, 160);
  300. this.label6.Name = "label6";
  301. this.label6.Size = new System.Drawing.Size(56, 16);
  302. this.label6.TabIndex = 4;
  303. this.label6.Text = "挂号类型";
  304. // 
  305. // cmb4
  306. // 
  307. this.cmb4.Items.AddRange(new object[] {
  308.   "普通",
  309.   "专家号20元",
  310.   "专家号5元"});
  311. this.cmb4.Location = new System.Drawing.Point(384, 160);
  312. this.cmb4.Name = "cmb4";
  313. this.cmb4.Size = new System.Drawing.Size(144, 20);
  314. this.cmb4.TabIndex = 3;
  315. this.cmb4.SelectionChangeCommitted += new System.EventHandler(this.cmb4_SelectionChangeCommitted);
  316. // 
  317. // label7
  318. // 
  319. this.label7.Location = new System.Drawing.Point(72, 220);
  320. this.label7.Name = "label7";
  321. this.label7.Size = new System.Drawing.Size(56, 16);
  322. this.label7.TabIndex = 4;
  323. this.label7.Text = "挂号科室";
  324. // 
  325. // cmb5
  326. // 
  327. this.cmb5.BackColor = System.Drawing.SystemColors.Desktop;
  328. this.cmb5.Location = new System.Drawing.Point(128, 216);
  329. this.cmb5.Name = "cmb5";
  330. this.cmb5.Size = new System.Drawing.Size(136, 20);
  331. this.cmb5.TabIndex = 3;
  332. // 
  333. // label8
  334. // 
  335. this.label8.Location = new System.Drawing.Point(328, 219);
  336. this.label8.Name = "label8";
  337. this.label8.Size = new System.Drawing.Size(56, 16);
  338. this.label8.TabIndex = 4;
  339. this.label8.Text = "医生";
  340. this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  341. // 
  342. // cmb6
  343. // 
  344. this.cmb6.BackColor = System.Drawing.SystemColors.Desktop;
  345. this.cmb6.Location = new System.Drawing.Point(384, 216);
  346. this.cmb6.Name = "cmb6";
  347. this.cmb6.Size = new System.Drawing.Size(144, 20);
  348. this.cmb6.TabIndex = 3;
  349. this.cmb6.DropDown += new System.EventHandler(this.cmb6_DropDown);
  350. // 
  351. // label9
  352. // 
  353. this.label9.Location = new System.Drawing.Point(128, 328);
  354. this.label9.Name = "label9";
  355. this.label9.Size = new System.Drawing.Size(56, 16);
  356. this.label9.TabIndex = 1;
  357. this.label9.Text = "挂号费用";
  358. // 
  359. // txt3
  360. // 
  361. this.txt3.Location = new System.Drawing.Point(128, 344);
  362. this.txt3.Name = "txt3";
  363. this.txt3.ReadOnly = true;
  364. this.txt3.Size = new System.Drawing.Size(136, 21);
  365. this.txt3.TabIndex = 2;
  366. this.txt3.Text = "";
  367. // 
  368. // txt4
  369. // 
  370. this.txt4.Location = new System.Drawing.Point(384, 344);
  371. this.txt4.Name = "txt4";
  372. this.txt4.ReadOnly = true;
  373. this.txt4.Size = new System.Drawing.Size(144, 21);
  374. this.txt4.TabIndex = 2;
  375. this.txt4.Text = "";
  376. // 
  377. // label10
  378. // 
  379. this.label10.Location = new System.Drawing.Point(384, 328);
  380. this.label10.Name = "label10";
  381. this.label10.Size = new System.Drawing.Size(64, 16);
  382. this.label10.TabIndex = 1;
  383. this.label10.Text = "挂号时间";
  384. // 
  385. // imageList1
  386. // 
  387. this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
  388. this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
  389. this.imageList1.TransparentColor = System.Drawing.SystemColors.ControlLightLight;
  390. // 
  391. // toolBar1
  392. // 
  393. this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
  394. this.tBtnNew,
  395. this.tBtnSubmit,
  396. this.tBtnCancel,
  397. this.tBtnQuit});
  398. this.toolBar1.DropDownArrows = true;
  399. this.toolBar1.ImageList = this.imageList1;
  400. this.toolBar1.Location = new System.Drawing.Point(0, 0);
  401. this.toolBar1.Name = "toolBar1";
  402. this.toolBar1.ShowToolTips = true;
  403. this.toolBar1.Size = new System.Drawing.Size(680, 41);
  404. this.toolBar1.TabIndex = 30;
  405. this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
  406. // 
  407. // tBtnNew
  408. // 
  409. this.tBtnNew.ImageIndex = 4;
  410. this.tBtnNew.Text = "新增";
  411. this.tBtnNew.ToolTipText = "新增";
  412. // 
  413. // tBtnSubmit
  414. // 
  415. this.tBtnSubmit.ImageIndex = 7;
  416. this.tBtnSubmit.Text = "保存";
  417. this.tBtnSubmit.ToolTipText = "保存";
  418. // 
  419. // tBtnCancel
  420. // 
  421. this.tBtnCancel.ImageIndex = 8;
  422. this.tBtnCancel.Text = "取消";
  423. this.tBtnCancel.ToolTipText = "取消";
  424. // 
  425. // tBtnQuit
  426. // 
  427. this.tBtnQuit.ImageIndex = 9;
  428. this.tBtnQuit.Text = "退出";
  429. this.tBtnQuit.ToolTipText = "退出";
  430. // 
  431. // ClinicReg
  432. // 
  433. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  434. this.ClientSize = new System.Drawing.Size(680, 493);
  435. this.Controls.Add(this.groupBox1);
  436. this.Controls.Add(this.txt5);
  437. this.Controls.Add(this.txt6);
  438. this.Controls.Add(this.txt7);
  439. this.Controls.Add(this.txt8);
  440. this.Controls.Add(this.toolBar1);
  441. this.Name = "ClinicReg";
  442. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  443. this.Text = "【门诊挂号】";
  444. this.Load += new System.EventHandler(this.ClinicReg_Load);
  445. this.groupBox1.ResumeLayout(false);
  446. this.ResumeLayout(false);
  447. }
  448. #endregion
  449. //-----------创建窗体时设置下拉列表框项目---------------
  450. private void ClinicReg_Load(object sender, System.EventArgs e)
  451. {
  452. //设置【科室资料】下拉列表框的下拉选项
  453. string strConn="workstation id=localhost;Integrated Security=SSPI;database=hisbook;";
  454. SqlConnection cn=new SqlConnection(strConn);
  455. cn.Open();
  456. SqlCommand cmb=cn.CreateCommand();
  457. cmb.CommandText="select distinct 名称 from 科室资料";
  458. SqlDataReader dr=cmb.ExecuteReader();
  459. cmb5.Items.Clear();
  460. while(dr.Read())
  461. {
  462. cmb5.Items.Add(dr.GetValue(0).ToString().Trim());
  463. }
  464. dr.Close();
  465. }
  466. //--------------工具栏控制代码------------------
  467. private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
  468. {
  469. if(e.Button.ToolTipText=="新增")
  470. {
  471. this.SetDefaultValue();//设置默认值
  472. //生成新编号
  473. this.regID=this.CreateNewID("select max(编号) 最大编号 from 门诊挂号");
  474. this.infoID=this.CreateNewID("select max(编号) 最大编号 from 病人信息库");
  475. }
  476. if(e.Button.ToolTipText=="保存")
  477. {
  478. if(this.CheckNotNull()==false)
  479. {
  480. return;
  481. }
  482. this.SaveReg();
  483. this.clearInfo();
  484. }
  485. if(e.Button.ToolTipText=="取消")
  486. {
  487. this.clearInfo();
  488. }
  489. if(e.Button.ToolTipText=="退出")
  490. {
  491. this.Close();
  492. }
  493. }
  494. //-------------根据选择的科室显示医生清单------------
  495. private void cmb6_DropDown(object sender, System.EventArgs e)
  496. {
  497. //设置【医生】下拉列表框的下拉选项
  498. cmb6.Items.Clear();//清空原有下拉选项
  499. if(cmb5.Text.Trim()=="")
  500. {
  501. return;
  502. }
  503. string strConn="workstation id=localhost;Integrated Security=SSPI;database=hisbook;";
  504. SqlConnection cn=new SqlConnection(strConn);
  505. cn.Open();
  506. SqlCommand cmb=cn.CreateCommand();
  507. cmb.CommandText="select distinct 姓名 from 医生资料 where 科室='"+cmb5.Text.Trim()+"'";
  508. SqlDataReader dr=cmb.ExecuteReader();
  509. while(dr.Read())
  510. {
  511. cmb6.Items.Add(dr.GetValue(0).ToString().Trim());
  512. }
  513. dr.Close();
  514. }
  515. //-----------清空面板中的信息------------
  516. private void clearInfo()
  517. {
  518. txt1.Clear();
  519. txt2.Clear();
  520. txt3.Clear();
  521. txt4.Clear();
  522. cmb1.Text="";
  523. cmb2.Text="";
  524. cmb3.Text="";
  525. cmb4.Text="";
  526. cmb5.Text="";
  527. cmb6.Text="";
  528. }
  529. //-----------新增病人时设置默认信息------------
  530. private void SetDefaultValue()
  531. {
  532. cmb1.SelectedText="男";//默认性别为男性
  533. cmb2.SelectedText="汉族";//默认民族为汉族
  534. cmb3.SelectedText="自费";//默认费用类型为自费
  535. cmb4.SelectedText="普通";//默认挂号类型为普通
  536. cmb5.SelectedText="内科";//默认挂号科室为内科
  537. txt3.Text="1";//默认挂号费1元
  538. txt4.Text=System.DateTime.Now.ToString();//当前系统时间为挂号时间
  539. }
  540. //----------根据挂号类型设置挂号费用-----------
  541. private void cmb4_SelectionChangeCommitted(object sender, System.EventArgs e)
  542. {
  543. if(cmb4.SelectedIndex==0)//普通号1元
  544. {
  545. txt3.Text="1";
  546. }
  547. if(cmb4.SelectedIndex==1)//20元专家号
  548. {
  549. txt3.Text="20";
  550. }
  551. if(cmb4.SelectedIndex==2)//5元专家号
  552. {
  553. txt3.Text="5";
  554. }
  555. }
  556. //---------------检查非空字段--------------
  557. private bool CheckNotNull()
  558. {
  559. if(txt1.Text.Trim()=="")
  560. {
  561. MessageBox.Show("病人姓名不能为空,请输入姓名","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  562. return(false);
  563. }
  564. if(cmb3.Text.Trim()=="")
  565. {
  566. MessageBox.Show("费用类型不能为空,请选择费用类型","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  567. return(false);
  568. }
  569. if(cmb5.Text.Trim()=="")
  570. {
  571. MessageBox.Show("挂号科室不能为空,请选择挂号科室","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  572. return(false);
  573. }
  574. if(cmb6.Text.Trim()=="")
  575. {
  576. MessageBox.Show("未选择医生或您选择的挂号科室没有医生","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);
  577. return(false);
  578. }
  579. return(true);
  580. }
  581. //-----------保存挂号信息和病人信息-------------
  582. private void SaveReg()
  583. {
  584. string strConn="workstation id=localhost;Integrated Security=SSPI;database=hisbook;";
  585. SqlConnection cn=new SqlConnection(strConn);
  586. cn.Open();
  587. SqlCommand cmb=cn.CreateCommand();
  588. string insertStr="insert into 病人信息库([编号], [姓名], [性别], [年龄], [民族], [费用类型]) "
  589. +"values('"+infoID+"','"+txt1.Text.Trim()+"','"+cmb1.Text.Trim()+"','"+txt2.Text.Trim()
  590. +"','"+cmb2.Text.Trim()+"','"+cmb3.Text.Trim()+"')";
  591. cmb.CommandText=insertStr;
  592. try
  593. {
  594. cmb.ExecuteNonQuery();
  595. }
  596. catch(Exception express)
  597. {
  598. MessageBox.Show(express.ToString(),"新增病人信息错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
  599. return;
  600. }
  601. insertStr="insert into 门诊挂号([编号], [病人编号], [姓名], [性别], [挂号科室], [费用类型],"
  602.                 +"[挂号类型], [挂号费用], [医生], [时间], [是否已划价]) "
  603. +"values('"+regID+"','"+infoID+"','"+txt1.Text.Trim()+"','"+cmb1.Text.Trim()+"','"
  604. +cmb5.Text.Trim()+"','"+cmb3.Text.Trim()+"','"+cmb4.Text.Trim()+"',CAST('"+txt3.Text
  605. +"' as decimal),'"+cmb6.Text.Trim()+"','"+txt4.Text+"','否')";
  606. cmb.CommandText=insertStr;
  607. try
  608. {
  609. cmb.ExecuteNonQuery();
  610. }
  611. catch(Exception express)
  612. {
  613. MessageBox.Show(express.ToString(),"新增门诊挂号错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
  614. return;
  615. }
  616. }
  617. //---------在新增信息时,根据sql语句计算并设置新的门诊挂号编号和病人信息---------
  618. private string CreateNewID(string sql)
  619. {
  620. string strConn="workstation id=localhost;Integrated Security=SSPI;database=hisbook;";
  621. SqlConnection cn=new SqlConnection(strConn);
  622. cn.Open();
  623. SqlCommand cmb=cn.CreateCommand();
  624. cmb.CommandText=sql;
  625. string result;
  626. if(cmb.ExecuteScalar()!=System.DBNull.Value)
  627. {
  628. result=cmb.ExecuteScalar().ToString().Trim();
  629. }
  630. else
  631. {
  632. return(System.DateTime.Now.Year.ToString()+"0000001");//命名规则为年份+7位编号
  633. }
  634. result=result.Substring(4,7);
  635. int newID=Convert.ToInt32(result)+1;
  636. int length=newID.ToString().Length;
  637. string returnStr=System.DateTime.Now.Year.ToString();
  638. switch(length)//生成新的编码
  639. {
  640. case 1:
  641. returnStr+="000000"+newID.ToString();
  642. break;
  643. case 2:
  644. returnStr+="00000"+newID.ToString();
  645. break;
  646. case 3:
  647. returnStr+="0000"+newID.ToString();
  648. break;
  649. case 4:
  650. returnStr+="000"+newID.ToString();
  651. break;
  652. case 5:
  653. returnStr+="00"+newID.ToString();
  654. break;
  655. case 6:
  656. returnStr+="0"+newID.ToString();
  657. break;
  658. case 7:
  659. returnStr+=newID.ToString();
  660. break;
  661. }
  662. return(returnStr);
  663. }
  664. }
  665. }