AddPatient.xaml.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using MahApps.Metro.Controls.Dialogs;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. using WpfTest1.Toolkits;
  16. namespace WpfTest1
  17. {
  18. /// <summary>
  19. /// AddPatient.xaml 为病例管理功能中添加病例的界面和逻辑
  20. /// </summary>
  21. public partial class AddPatient : Window
  22. {
  23. MainWindow father;
  24. public AddPatient(MainWindow father)
  25. {
  26. this.father = father;
  27. InitializeComponent();
  28. }
  29. //每输一个姓名摘取其拼音缩写
  30. private void textBoxName_TextChanged(object sender, TextChangedEventArgs e)
  31. {
  32. string source_text = textBoxName.Text;
  33. string result_PY = "";
  34. for (int i = 0;i<source_text.Length;i++)
  35. {
  36. result_PY += Toolkits.StringToPY.GetCharSpellCode(Convert.ToString(source_text[i]));
  37. }
  38. textBoxPY.Text = result_PY;
  39. }
  40. //取消按钮
  41. private void buttonAddPatinetcCancel_Click(object sender, RoutedEventArgs e)
  42. {
  43. MessageBoxResult dr = MessageBox.Show("是否放弃添加?", "提示", MessageBoxButton.OKCancel);
  44. if (dr == MessageBoxResult.OK)
  45. {
  46. this.Close();
  47. }
  48. else if (dr == MessageBoxResult.Cancel)
  49. {
  50. return;
  51. }
  52. //this.Close();
  53. }
  54. //重置按钮
  55. private void buttonAddPatinetcReset_Click(object sender, RoutedEventArgs e)
  56. {
  57. this.doResetInfo();
  58. }
  59. //重置执行的内容
  60. private void doResetInfo()
  61. {
  62. textBoxCaseId.Text = "";
  63. textBoxGender.Text = "";
  64. textBoxName.Text = "";
  65. textBoxPY.Text = "";
  66. textBoxHeight.Text = "";
  67. textBoxWeight.Text = "";
  68. textBoxPregnancyTimes.Text = "";
  69. //textBoxBirthTimes.Text = "";
  70. //textBoxPregnancyDate.Text = "";
  71. textBoxMobile.Text = "";
  72. //textBoxProfession.Text = "";
  73. textBoxAddress.Text = "";
  74. textBoxHistory.Text = "";
  75. textBoxDiagnosis.Text = "";
  76. textBoxBirthDate.Text = "";
  77. //textBoxDescription.Text = "";
  78. }
  79. //提交按钮
  80. private void buttonAddPatinetcSubmit_Click(object sender, RoutedEventArgs e)
  81. {
  82. if(textBoxCaseId.Text == "")
  83. {
  84. MessageBox.Show("必要信息未填写");
  85. textBoxCaseId.Focus();
  86. return;
  87. }
  88. if (textBoxName.Text == "")
  89. {
  90. MessageBox.Show("必要信息未填写");
  91. textBoxName.Focus();
  92. return;
  93. }
  94. if (textBoxPY.Text == "")
  95. {
  96. MessageBox.Show("必要信息未填写");
  97. textBoxPY.Focus();
  98. return;
  99. }
  100. if (textBoxHeight.Text == "")
  101. {
  102. MessageBox.Show("必要信息未填写");
  103. textBoxHeight.Focus();
  104. return;
  105. }
  106. if (textBoxWeight.Text == "")
  107. {
  108. MessageBox.Show("必要信息未填写");
  109. textBoxWeight.Focus();
  110. return;
  111. }
  112. if (textBoxGender.Text == "")
  113. {
  114. MessageBox.Show("必要信息未填写");
  115. textBoxGender.Focus();
  116. return;
  117. }
  118. if (textBoxPregnancyTimes.Text == "")
  119. {
  120. MessageBox.Show("必要信息未填写");
  121. textBoxPregnancyTimes.Focus();
  122. return;
  123. }
  124. if (textBoxBirthDate.Text == "")
  125. {
  126. MessageBox.Show("必要信息未填写");
  127. textBoxBirthDate.Focus();
  128. return;
  129. }
  130. //筛选通过后调用数据库进行存储
  131. string record_id = FilterDangerousCharacter.filter(textBoxCaseId.Text);
  132. string name = FilterDangerousCharacter.filter(textBoxName.Text);
  133. string py = FilterDangerousCharacter.filter(textBoxPY.Text);
  134. string height = FilterDangerousCharacter.filter(textBoxHeight.Text);
  135. string weight = FilterDangerousCharacter.filter(textBoxWeight.Text);
  136. string gender = FilterDangerousCharacter.filter(textBoxGender.Text);
  137. string pregnancytimes = FilterDangerousCharacter.filter(textBoxPregnancyTimes.Text);
  138. string birthdate = FilterDangerousCharacter.filter(textBoxBirthDate.Text);
  139. DateTime dt;
  140. System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
  141. //MessageBox.Show(pregnancydate);
  142. dtFormat.ShortDatePattern = "yyyy/M/d";
  143. dt = Convert.ToDateTime(birthdate, dtFormat);
  144. string mobile = FilterDangerousCharacter.filter(textBoxMobile.Text);
  145. string address = FilterDangerousCharacter.filter(textBoxAddress.Text);
  146. string history = FilterDangerousCharacter.filter(textBoxHistory.Text);
  147. string diagnosis = FilterDangerousCharacter.filter(textBoxDiagnosis.Text);
  148. bool success_flag = true;
  149. try
  150. {
  151. if(SQLite.SQLiteModel.checkRepeatPatient(record_id))
  152. {
  153. MessageBox.Show("病历号重复","错误");
  154. textBoxCaseId.Focus();
  155. return;
  156. }
  157. SQLite.SQLiteModel.InsertPatientData(record_id,
  158. name,
  159. gender,
  160. Convert.ToDouble(height),
  161. Convert.ToDouble(weight),
  162. Convert.ToInt32(pregnancytimes),
  163. dt,
  164. mobile,
  165. address,
  166. history,
  167. diagnosis,
  168. py);
  169. }catch(Exception err)
  170. {
  171. success_flag = false;
  172. MessageBox.Show("数据库错误.\r\n调试信息:" + err.Message, "错误");
  173. }
  174. if(success_flag)
  175. {
  176. //MessageBox.Show("插入成功", "提示");
  177. father.selectUserPatientManagent.LoadDataGrid();
  178. //father.selectUserMeasure.LoadDataGrid();
  179. //father.selectUserHistory.LoadDataGrid();
  180. MessageBoxResult dr = MessageBox.Show("插入成功,是否继续添加?", "提示", MessageBoxButton.OKCancel);
  181. if (dr == MessageBoxResult.OK)
  182. {
  183. this.doResetInfo();
  184. return;
  185. }
  186. else if (dr == MessageBoxResult.Cancel)
  187. {
  188. this.Close();
  189. }
  190. }
  191. }
  192. }
  193. }