ModifyDoctor.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. /// ModifyDoctor.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class ModifyDoctor : Window
  21. {
  22. string id;
  23. SQLite.doctor target;
  24. MainWindow father;
  25. //int check = 0;
  26. public ModifyDoctor(MainWindow father, string id)
  27. {
  28. this.father = father;
  29. InitializeComponent();
  30. this.id = id;
  31. if (id == "")
  32. {
  33. MessageBox.Show("未查找到该医生记录", "错误");
  34. this.Close();
  35. }
  36. this.id = id;
  37. try
  38. {
  39. target = SQLite.SQLiteModel.getDoctorById(id);
  40. if (target == null)
  41. {
  42. MessageBox.Show("未查找到该医生记录", "错误");
  43. this.Close();
  44. }
  45. else
  46. {
  47. //查找完毕开始填充
  48. fillBlanks();
  49. }
  50. }
  51. catch (Exception err)
  52. {
  53. MessageBox.Show("数据库错误\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  54. this.Close();
  55. }
  56. }
  57. //填充数据
  58. private void fillBlanks()
  59. {
  60. name.Text = target.name;
  61. //pwd.Password = target.pwd_hash;
  62. //pwd_1.Password = target.pwd_hash;
  63. phone.Text = target.phone_number;
  64. if (target.director_flag == 1)
  65. {
  66. radioButton.IsChecked = true;
  67. }
  68. }
  69. /*
  70. private void radioButton_Checked(object sender, RoutedEventArgs e)
  71. {
  72. check = 1;
  73. }
  74. */
  75. //修改按钮
  76. private void modifyButtonClick(object sender, RoutedEventArgs e)
  77. {
  78. if (name.Text == "")
  79. {
  80. MessageBox.Show("请填写用户名!");
  81. name.Focus();
  82. return;
  83. }
  84. /*
  85. if (pwd.Password == "")
  86. {
  87. MessageBox.Show("请填写密码!");
  88. pwd.Focus();
  89. return;
  90. }
  91. if (pwd_1.Password == "")
  92. {
  93. MessageBox.Show("请填写确认密码!");
  94. pwd_1.Focus();
  95. return;
  96. }
  97. */
  98. if (phone.Text == "")
  99. {
  100. MessageBox.Show("请填写联系电话!");
  101. phone.Focus();
  102. return;
  103. }
  104. /*
  105. if (pwd_1.Password != pwd.Password)
  106. {
  107. MessageBox.Show("两次输入的密码不一致,请重新输入!");
  108. pwd.Focus();
  109. return;
  110. }
  111. */
  112. string doctor_name = FilterDangerousCharacter.filter(name.Text);
  113. //string doctor_pwd = Toolkits.ComputeHash.GetMD5(FilterDangerousCharacter.filter(pwd.Password));
  114. string doctor_phone = FilterDangerousCharacter.filter(phone.Text);
  115. int doctor_dir_flag = 0;
  116. if ((Boolean)(radioButton.IsChecked)) doctor_dir_flag = 1;
  117. int doctor_del_flag = 0;
  118. bool success_flag = true;
  119. try
  120. {//防止修改之后和其他数据的name重复
  121. if (doctor_name != target.name)
  122. {
  123. if (SQLite.SQLiteModel.checkRepeatDoctor(doctor_name))
  124. {
  125. MessageBox.Show("用户名选择重复,请选择新的用户名!");
  126. name.Focus();
  127. return;
  128. }
  129. }
  130. SQLite.SQLiteModel.UpdateDoctorData(id,
  131. doctor_name,
  132. target.pwd_hash,
  133. doctor_phone,
  134. Convert.ToBoolean(doctor_dir_flag),
  135. Convert.ToBoolean(doctor_del_flag)
  136. );
  137. }
  138. catch (Exception err)
  139. {
  140. success_flag = false;
  141. MessageBox.Show("数据库错误.\r\n调试信息:" + err.Message, "错误");
  142. }
  143. if (success_flag)
  144. {
  145. MessageBox.Show("修改医生信息成功", "提示");
  146. father.LoadDoctorDataGrid();
  147. this.Close();
  148. }
  149. }
  150. //重置按钮
  151. private void resetButtonClick(object sender, RoutedEventArgs e)
  152. {
  153. fillBlanks();
  154. }
  155. //取消按钮
  156. private void cancelButtonClick(object sender, RoutedEventArgs e)
  157. {
  158. MessageBoxResult dr = MessageBox.Show("是否放弃添加?", "提示", MessageBoxButton.OKCancel);
  159. if (dr == MessageBoxResult.OK)
  160. {
  161. this.Close();
  162. }
  163. else if (dr == MessageBoxResult.Cancel)
  164. {
  165. return;
  166. }
  167. //this.Close();
  168. }
  169. }
  170. }