123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- 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>
- /// ModifyUser.xaml 的交互逻辑
- /// </summary>
- 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;
- }
- }
- }
- }
|