123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- using WpfTest1.Toolkits;
- namespace WpfTest1
- {
- /// <summary>
- /// ModifyDoctor.xaml 的交互逻辑
- /// </summary>
- public partial class ModifyDoctor : Window
- {
- string id;
- SQLite.doctor target;
- MainWindow father;
- //int check = 0;
- public ModifyDoctor(MainWindow father, string id)
- {
- this.father = father;
- InitializeComponent();
- this.id = id;
- if (id == "")
- {
- MessageBox.Show("未查找到该医生记录", "错误");
- this.Close();
- }
- this.id = id;
- try
- {
- target = SQLite.SQLiteModel.getDoctorById(id);
- if (target == null)
- {
- MessageBox.Show("未查找到该医生记录", "错误");
- this.Close();
- }
- else
- {
- //查找完毕开始填充
- fillBlanks();
- }
- }
- catch (Exception err)
- {
- MessageBox.Show("数据库错误\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
- this.Close();
- }
- }
- //填充数据
- private void fillBlanks()
- {
- name.Text = target.name;
- //pwd.Password = target.pwd_hash;
- //pwd_1.Password = target.pwd_hash;
- phone.Text = target.phone_number;
- if (target.director_flag == 1)
- {
- radioButton.IsChecked = true;
- }
- }
- /*
- private void radioButton_Checked(object sender, RoutedEventArgs e)
- {
- check = 1;
- }
- */
- //修改按钮
- private void modifyButtonClick(object sender, RoutedEventArgs e)
- {
- if (name.Text == "")
- {
- MessageBox.Show("请填写用户名!");
- name.Focus();
- return;
- }
- /*
- if (pwd.Password == "")
- {
- MessageBox.Show("请填写密码!");
- pwd.Focus();
- return;
- }
- if (pwd_1.Password == "")
- {
- MessageBox.Show("请填写确认密码!");
- pwd_1.Focus();
- return;
- }
- */
- if (phone.Text == "")
- {
- MessageBox.Show("请填写联系电话!");
- phone.Focus();
- return;
- }
- /*
- if (pwd_1.Password != pwd.Password)
- {
- MessageBox.Show("两次输入的密码不一致,请重新输入!");
- pwd.Focus();
- return;
- }
- */
- string doctor_name = FilterDangerousCharacter.filter(name.Text);
- //string doctor_pwd = Toolkits.ComputeHash.GetMD5(FilterDangerousCharacter.filter(pwd.Password));
- string doctor_phone = FilterDangerousCharacter.filter(phone.Text);
- int doctor_dir_flag = 0;
- if ((Boolean)(radioButton.IsChecked)) doctor_dir_flag = 1;
- int doctor_del_flag = 0;
- bool success_flag = true;
- try
- {//防止修改之后和其他数据的name重复
- if (doctor_name != target.name)
- {
- if (SQLite.SQLiteModel.checkRepeatDoctor(doctor_name))
- {
- MessageBox.Show("用户名选择重复,请选择新的用户名!");
- name.Focus();
- return;
- }
- }
- SQLite.SQLiteModel.UpdateDoctorData(id,
- doctor_name,
- target.pwd_hash,
- doctor_phone,
- Convert.ToBoolean(doctor_dir_flag),
- Convert.ToBoolean(doctor_del_flag)
- );
- }
- catch (Exception err)
- {
- success_flag = false;
- MessageBox.Show("数据库错误.\r\n调试信息:" + err.Message, "错误");
- }
- if (success_flag)
- {
- MessageBox.Show("修改医生信息成功", "提示");
- father.LoadDoctorDataGrid();
- this.Close();
- }
- }
- //重置按钮
- private void resetButtonClick(object sender, RoutedEventArgs e)
- {
- fillBlanks();
- }
- //取消按钮
- private void cancelButtonClick(object sender, RoutedEventArgs e)
- {
- MessageBoxResult dr = MessageBox.Show("是否放弃添加?", "提示", MessageBoxButton.OKCancel);
- if (dr == MessageBoxResult.OK)
- {
- this.Close();
- }
- else if (dr == MessageBoxResult.Cancel)
- {
- return;
- }
- //this.Close();
- }
- }
- }
|