ModifyUser.xaml.cs 7.6 KB

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