AddDoctor.xaml.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. /// AddDoctor是添加医师的交互界面
  19. /// AddDoctor.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class AddDoctor : Window
  22. {
  23. MainWindow father;
  24. //int check = 0;
  25. public AddDoctor(MainWindow father)
  26. {
  27. this.father = father;
  28. InitializeComponent();
  29. }
  30. /*
  31. private void radioButton_Checked(object sender, RoutedEventArgs e)
  32. {
  33. check = 1;
  34. }
  35. */
  36. //添加按钮
  37. private void addButtonClick(object sender, RoutedEventArgs e)
  38. {
  39. if (name.Text == "")
  40. {
  41. MessageBox.Show("请填写用户名!");
  42. name.Focus();
  43. return;
  44. }
  45. if (pwd.Password == "")
  46. {
  47. MessageBox.Show("请填写密码!");
  48. pwd.Focus();
  49. return;
  50. }
  51. if (pwd_1.Password == "")
  52. {
  53. MessageBox.Show("请填写确认密码!");
  54. pwd_1.Focus();
  55. return;
  56. }
  57. if (phone.Text == "")
  58. {
  59. MessageBox.Show("请填写联系电话!");
  60. phone.Focus();
  61. return;
  62. }
  63. if (pwd_1.Password != pwd.Password)
  64. {
  65. MessageBox.Show("两次输入的密码不一致,请重新输入!");
  66. pwd.Focus();
  67. return;
  68. }
  69. string doctor_name = FilterDangerousCharacter.filter(name.Text);
  70. string doctor_pwd = Toolkits.ComputeHash.GetMD5(FilterDangerousCharacter.filter(pwd.Password));
  71. string doctor_phone = FilterDangerousCharacter.filter(phone.Text);
  72. int doctor_dir_flag = 0;
  73. if ((Boolean)(radioButton.IsChecked)) doctor_dir_flag = 1;
  74. int doctor_del_flag = 0;
  75. bool success_flag = true;
  76. try
  77. {
  78. if (SQLite.SQLiteModel.checkRepeatDoctor(doctor_name))
  79. {
  80. MessageBox.Show("用户名选择重复,请选择新的用户名!");
  81. name.Focus();
  82. return;
  83. }
  84. SQLite.SQLiteModel.InsertDoctorData(doctor_name,
  85. doctor_pwd,
  86. doctor_phone,
  87. Convert.ToBoolean(doctor_dir_flag),
  88. Convert.ToBoolean(doctor_del_flag)
  89. );
  90. }
  91. catch (Exception err)
  92. {
  93. success_flag = false;
  94. MessageBox.Show("数据库错误.\r\n调试信息:" + err.Message, "错误");
  95. }
  96. if (success_flag)
  97. {
  98. MessageBox.Show("添加医生成功", "提示");
  99. father.LoadDoctorDataGrid();
  100. this.Close();
  101. }
  102. }
  103. //重置按钮
  104. private void resetButtonClick(object sender, RoutedEventArgs e)
  105. {
  106. name.Text = "";
  107. phone.Text = "";
  108. pwd.Password = "";
  109. pwd_1.Password = "";
  110. radioButton.IsChecked = false;
  111. name.Focus();
  112. }
  113. //取消按钮
  114. private void cancelButtonClick(object sender, RoutedEventArgs e)
  115. {
  116. MessageBoxResult dr = MessageBox.Show("是否放弃添加?", "提示", MessageBoxButton.OKCancel);
  117. if (dr == MessageBoxResult.OK)
  118. {
  119. this.Close();
  120. }
  121. else if (dr == MessageBoxResult.Cancel)
  122. {
  123. return;
  124. }
  125. //this.Close();
  126. }
  127. }
  128. }