ModifyDoctorPWD.xaml.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.SQLite;
  15. namespace WpfTest1
  16. {
  17. /// <summary>
  18. /// ModifyDoctorPWD.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class ModifyDoctorPWD : Window
  21. {
  22. string id;
  23. MainWindow father;
  24. doctor target;
  25. public ModifyDoctorPWD(MainWindow father,string id)
  26. {
  27. InitializeComponent();
  28. this.father = father;
  29. if (id == "")
  30. {
  31. MessageBox.Show("未查找到该记录", "错误");
  32. this.Close();
  33. }
  34. this.id = id;
  35. try
  36. {
  37. target = SQLite.SQLiteModel.getDoctorById(id);
  38. if (target == null)
  39. {
  40. MessageBox.Show("未查找到该记录", "错误");
  41. this.Close();
  42. }
  43. }
  44. catch (Exception err)
  45. {
  46. MessageBox.Show("数据库错误\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  47. this.Close();
  48. }
  49. }
  50. private void buttonSubmit_Click(object sender, RoutedEventArgs e)
  51. {
  52. if(passwordBoxNewPWD.Password != passwordBoxRepeatBox.Password)
  53. {
  54. MessageBox.Show("两次输入密码不一致","提示");
  55. return;
  56. }
  57. else
  58. {
  59. bool success_flag = true;
  60. try
  61. {
  62. string pwdHash = Toolkits.ComputeHash.GetMD5(Toolkits.FilterDangerousCharacter.filter(passwordBoxNewPWD.Password));
  63. bool director_flag = target.director_flag == 1 ? true : false;
  64. SQLiteModel.UpdateDoctorData(target.id.ToString(), target.name, pwdHash, target.phone_number, director_flag, false);
  65. }
  66. catch(Exception err)
  67. {
  68. success_flag = false;
  69. MessageBox.Show("数据库故障\r\n调试信息:"+err.StackTrace,"错误");
  70. }
  71. if (success_flag)
  72. {
  73. MessageBox.Show("修改成功","提示");
  74. this.Close();
  75. }
  76. }
  77. }
  78. private void buttonCancel_Click(object sender, RoutedEventArgs e)
  79. {
  80. MessageBoxResult dr = MessageBox.Show("是否放弃添加?", "提示", MessageBoxButton.OKCancel);
  81. if (dr == MessageBoxResult.OK)
  82. {
  83. this.Close();
  84. }
  85. else if (dr == MessageBoxResult.Cancel)
  86. {
  87. return;
  88. }
  89. }
  90. }
  91. }