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 { /// /// ModifyUser.xaml 的交互逻辑 /// public partial class ModifyUser : Window { string id; MainWindow father; SQLite.Patient target; //构造函数,首先查找所需要修改的记录并填充,之后修改 public ModifyUser(MainWindow father,string id) { InitializeComponent(); this.father = father; if (id == "") { MessageBox.Show("未查找到该记录", "错误"); this.Close(); } this.id = id; try { target = SQLite.SQLiteModel.getPatientById(id); if(target == null) { MessageBox.Show("未查找到该记录", "错误"); this.Close(); } }catch(Exception err) { MessageBox.Show("数据库错误\r\n调试信息:"+err.Message+"\r\n"+err.StackTrace, "错误"); this.Close(); } //查找完毕开始填充 fillBlanks(); } //用系统中的Patient target 填充所有空格 private void fillBlanks() { textBoxCaseId.Text = target.p_record_id; textBoxGender.Text = target.p_gender; textBoxName.Text = target.p_name; textBoxPY.Text = target.p_name_py; textBoxHeight.Text = target.p_height.ToString(); textBoxWeight.Text = target.p_weight.ToString(); textBoxPregnancyTimes.Text = target.p_pregnancy_time.ToString(); textBoxBirthDate.Text = target.p_birthdate.ToString("yyyy/M/d"); textBoxMobile.Text = target.p_phone; textBoxAddress.Text = target.p_address; textBoxHistory.Text = target.p_history; textBoxDiagnosis.Text = target.p_diagnosis; } //每输一个姓名摘取其拼音缩写 private void textBoxName_TextChanged(object sender, TextChangedEventArgs e) { string source_text = textBoxName.Text; string result_PY = ""; for (int i = 0; i < source_text.Length; i++) { result_PY += Toolkits.StringToPY.GetCharSpellCode(Convert.ToString(source_text[i])); } textBoxPY.Text = result_PY; } private void buttonAddPatinetcSubmit_Click(object sender, RoutedEventArgs e) { if (textBoxCaseId.Text == "") { MessageBox.Show("必要信息未填写"); textBoxCaseId.Focus(); return; } if (textBoxGender.Text == "") { MessageBox.Show("必要信息未填写"); textBoxGender.Focus(); return; } if (textBoxName.Text == "") { MessageBox.Show("必要信息未填写"); textBoxName.Focus(); return; } if (textBoxPY.Text == "") { MessageBox.Show("必要信息未填写"); textBoxPY.Focus(); return; } if (textBoxHeight.Text == "") { MessageBox.Show("必要信息未填写"); textBoxHeight.Focus(); return; } if (textBoxWeight.Text == "") { MessageBox.Show("必要信息未填写"); textBoxWeight.Focus(); return; } if (textBoxPregnancyTimes.Text == "") { MessageBox.Show("必要信息未填写"); textBoxPregnancyTimes.Focus(); return; } if (textBoxBirthDate.Text == "") { MessageBox.Show("出生日期未选择"); textBoxBirthDate.Focus(); return; } //筛选通过后调用数据库进行存储 string record_id = FilterDangerousCharacter.filter(textBoxCaseId.Text); string name = FilterDangerousCharacter.filter(textBoxName.Text); string py = FilterDangerousCharacter.filter(textBoxPY.Text); string height = FilterDangerousCharacter.filter(textBoxHeight.Text); string weight = FilterDangerousCharacter.filter(textBoxWeight.Text); string gender = FilterDangerousCharacter.filter(textBoxGender.Text); string pregnancytimes = FilterDangerousCharacter.filter(textBoxPregnancyTimes.Text); string birthdate = FilterDangerousCharacter.filter(textBoxBirthDate.Text); DateTime dt; System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo(); //MessageBox.Show(pregnancydate); dtFormat.ShortDatePattern = "yyyy/M/d"; dt = Convert.ToDateTime(birthdate, dtFormat); string mobile = FilterDangerousCharacter.filter(textBoxMobile.Text); string address = FilterDangerousCharacter.filter(textBoxAddress.Text); string history = FilterDangerousCharacter.filter(textBoxHistory.Text); string diagnosis = FilterDangerousCharacter.filter(textBoxDiagnosis.Text); bool success_flag = true; try { SQLite.SQLiteModel.UpdatePatientData(id, record_id, name, gender, Convert.ToDouble(height), Convert.ToDouble(weight), Convert.ToInt32(pregnancytimes), dt, mobile, address, history, diagnosis, py); } catch (Exception err) { success_flag = false; MessageBox.Show("数据库错误.\r\n调试信息:" + err.Message+"\r\n"+err.StackTrace, "错误"); } if (success_flag) { MessageBox.Show("修改成功", "提示"); father.selectUserPatientManagent.LoadDataGrid(); this.Close(); } } //点击重置按钮的效果 private void buttonAddPatinetcReset_Click(object sender, RoutedEventArgs e) { fillBlanks(); } private void buttonAddPatinetcCancel_Click(object sender, RoutedEventArgs e) { MessageBoxResult dr = MessageBox.Show("是否放弃修改?", "提示", MessageBoxButton.OKCancel); if (dr == MessageBoxResult.OK) { this.Close(); } else if (dr == MessageBoxResult.Cancel) { return; } } } }