123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- using MahApps.Metro.Controls.Dialogs;
- 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>
- /// AddPatient.xaml 为病例管理功能中添加病例的界面和逻辑
- /// </summary>
- public partial class AddPatient : Window
- {
- MainWindow father;
- public AddPatient(MainWindow father)
- {
- this.father = father;
- InitializeComponent();
- }
- //每输一个姓名摘取其拼音缩写
- 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 buttonAddPatinetcCancel_Click(object sender, RoutedEventArgs e)
- {
- MessageBoxResult dr = MessageBox.Show("是否放弃添加?", "提示", MessageBoxButton.OKCancel);
- if (dr == MessageBoxResult.OK)
- {
- this.Close();
- }
- else if (dr == MessageBoxResult.Cancel)
- {
- return;
- }
- //this.Close();
- }
- //重置按钮
- private void buttonAddPatinetcReset_Click(object sender, RoutedEventArgs e)
- {
- this.doResetInfo();
- }
- //重置执行的内容
- private void doResetInfo()
- {
- textBoxCaseId.Text = "";
- textBoxGender.Text = "";
- textBoxName.Text = "";
- textBoxPY.Text = "";
- textBoxHeight.Text = "";
- textBoxWeight.Text = "";
- textBoxPregnancyTimes.Text = "";
- //textBoxBirthTimes.Text = "";
- //textBoxPregnancyDate.Text = "";
- textBoxMobile.Text = "";
- //textBoxProfession.Text = "";
- textBoxAddress.Text = "";
- textBoxHistory.Text = "";
- textBoxDiagnosis.Text = "";
- textBoxBirthDate.Text = "";
- //textBoxDescription.Text = "";
- }
- //提交按钮
- private void buttonAddPatinetcSubmit_Click(object sender, RoutedEventArgs e)
- {
- if(textBoxCaseId.Text == "")
- {
- MessageBox.Show("必要信息未填写");
- textBoxCaseId.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 (textBoxGender.Text == "")
- {
- MessageBox.Show("必要信息未填写");
- textBoxGender.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
- {
- if(SQLite.SQLiteModel.checkRepeatPatient(record_id))
- {
- MessageBox.Show("病历号重复","错误");
- textBoxCaseId.Focus();
- return;
- }
- SQLite.SQLiteModel.InsertPatientData(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, "错误");
- }
- if(success_flag)
- {
- //MessageBox.Show("插入成功", "提示");
- father.selectUserPatientManagent.LoadDataGrid();
- //father.selectUserMeasure.LoadDataGrid();
- //father.selectUserHistory.LoadDataGrid();
- MessageBoxResult dr = MessageBox.Show("插入成功,是否继续添加?", "提示", MessageBoxButton.OKCancel);
- if (dr == MessageBoxResult.OK)
- {
- this.doResetInfo();
- return;
- }
- else if (dr == MessageBoxResult.Cancel)
- {
- this.Close();
- }
-
-
- }
-
-
- }
- }
- }
|