123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SQLite;
- 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.Navigation;
- using System.Windows.Shapes;
- using WpfTest1.SQLite;
- namespace WpfTest1
- {
- /// <summary>
- /// selectUser.xaml 的交互逻辑
- /// </summary>
- public partial class selectUser : UserControl
- {
- DataSet ds;
- //SQLiteCommandBuilder cmdb;
- SQLiteDataAdapter da;
- //DataRow dr;
- MainWindow father;
- public selectUser()
- {
- InitializeComponent();
- SQLiteLogic.createDBAndTables();
- //dataGrid.LoadingRow += new EventHandler<DataGridRowEventArgs>(dataGrid_LoadingRow);
- }
- public selectUser(MainWindow father)
- {
- InitializeComponent();
- SQLiteLogic.createDBAndTables();
- this.father = father;
- //dataGrid.LoadingRow += new EventHandler<DataGridRowEventArgs>(dataGrid_LoadingRow);
- }
- public void setMainWindow(MainWindow father)
- {
- this.father = father;
- }
- public void dataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
- {
- e.Row.Header = e.Row.GetIndex() + 1;
- }
- //筛选得到符合条件的用户数据
- private void dataGrid_Loaded(object sender, RoutedEventArgs e)
- {
- LoadDataGrid();
- }
- public void LoadDataGrid()
- {
- ////连接字符串
- //string Connstr = "Data Source=" + System.Environment.CurrentDirectory + "\\Junde.db3"; ;
- ////连接对象
- //SQLiteConnection con = new SQLiteConnection(Connstr);
- ////Sql语句
- string orderCondition = "p_last_filter_time desc";
- if (this.Name == "selectUserPatientManagent")
- {
- orderCondition = "p_id asc";
- }
- if (this.Name == "selectUserfilter")
- {
- orderCondition = "p_last_filter_time desc";
- }
- List<Patient> patientList = SQLiteModel.getAllNotLogicDeletePatient(orderCondition);
- //string selectCmd = "SELECT * FROM Patient WHERE p_delete_flag = 0 ORDER BY " + orderCondition + " LIMIT 100";
- //con.Open();
- //da = new SQLiteDataAdapter(selectCmd, con);
- //ds = new DataSet();
- //da.Fill(ds);
- //dataGrid.ItemsSource = ds.Tables[0].DefaultView;
- dataGrid.ItemsSource = patientList;
- //con.Close();
- }
- //点击重置的效果
- private void buttonReset_Click(object sender, RoutedEventArgs e)
- {
- textBoxName.Text = "姓名或者拼音首字母";
- textBoxCaseID.Text = "";
- textBoxPregnancyTime.Text = "";
- textBoxHeightStart.Text = "";
- textBoxHeightEnd.Text = "";
- textBoxWeightStart.Text = "";
- textBoxWeightEnd.Text = "";
- datePickerBirthTimeStart.Text = "";
- datePickerBirthTimeEnd.Text = "";
- LoadDataGrid();
- }
- private void textBoxName_GotFocus(object sender, RoutedEventArgs e)
- {
- if (sender != null)
- {
- TextBox tbx = sender as TextBox;
- tbx.SelectAll();
- tbx.PreviewMouseDown -= new MouseButtonEventHandler(textBoxName_PreviewMouseDown);
- }
- }
- private void textBoxName_PreviewMouseDown(object sender, MouseButtonEventArgs e)
- {
- TextBox tb = sender as TextBox;
- if (tb != null)
- {
- tb.Focus();
- e.Handled = true;
- }
- }
- private void textBoxName_LostFocus(object sender, RoutedEventArgs e)
- {
- TextBox tb = sender as TextBox;
- if (tb != null)
- {
- tb.PreviewMouseDown += new MouseButtonEventHandler(textBoxName_PreviewMouseDown);
- }
- }
- //点击筛选用户
- private void buttonQuery_Click(object sender, RoutedEventArgs e)
- {
- List<string> condition_list = new List<string>();
- //姓名或拼音
- string name_or_py = textBoxName.Text;
- if (name_or_py != "姓名或者拼音首字母" && name_or_py != "")
- {
- condition_list.Add(" and (p_name LIKE \'%"+ name_or_py +"%\' or p_name_py LIKE \'%"+ name_or_py +"%\') ");
- }
- //病例编号
- if(textBoxCaseID.Text != "")
- {
- condition_list.Add(" and p_record_id = '" + textBoxCaseID.Text + "' ");
- }
- //孕次
- if (textBoxPregnancyTime.Text != "")
- {
- string pt_temp = "";
- try
- {
- pt_temp = Convert.ToString(Convert.ToInt32(textBoxPregnancyTime.Text));
- }
- catch(Exception err)
- {
- MessageBox.Show("孕次信息格式不正确,请填写一个整数数字。\r\n调试信息:"+err.Message,"警告");
- return;
- }
- condition_list.Add(" and p_pregnancy_time = " + pt_temp + " ");
- }
- //出生日期
- if (datePickerBirthTimeStart.Text != "" && datePickerBirthTimeEnd.Text != "")
- {
- DateTime dt;
- System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
- //MessageBox.Show(pregnancydate);
- dtFormat.ShortDatePattern = "yyyy/M/d";
- string dateStart = datePickerBirthTimeStart.Text;
- string dateEnd = datePickerBirthTimeEnd.Text;
- try
- {
- dt = Convert.ToDateTime(dateStart, dtFormat);
- dateStart = dt.ToString("yyyy-MM-dd");
- dt = Convert.ToDateTime(dateEnd, dtFormat);
- dateEnd = dt.ToString("yyyy-MM-dd");
- }
- catch (Exception err)
- {
- MessageBox.Show("孕妇出生日期格式不正确,请通过栏中日历的按钮选择日期。\r\n调试信息:" + err.Message, "警告");
- return;
- }
- condition_list.Add(" and (p_birthdate between '" + dateStart + "' and '" + dateEnd + "') ");
- }
- //身高条件
- if (textBoxHeightStart.Text != "" && textBoxHeightEnd.Text != "")
- {
- string hs_temp = "";
- string he_temp = "";
- try
- {
- hs_temp = Convert.ToString(Convert.ToDouble(textBoxHeightStart.Text));
- he_temp = Convert.ToString(Convert.ToDouble(textBoxHeightEnd.Text));
- }
- catch (Exception err)
- {
- MessageBox.Show("身高信息格式不正确,请填写一个整数数字。\r\n调试信息:" + err.Message, "警告");
- return;
- }
- condition_list.Add(" and (p_height between " + hs_temp + " and "+ he_temp + ") ");
- }
- //体重条件
- if (textBoxWeightStart.Text != "" && textBoxWeightEnd.Text != "")
- {
- string ws_temp = "";
- string we_temp = "";
- try
- {
- ws_temp = Convert.ToString(Convert.ToInt32(textBoxWeightStart.Text));
- we_temp = Convert.ToString(Convert.ToInt32(textBoxWeightEnd.Text));
- }
- catch (Exception err)
- {
- MessageBox.Show("体重信息格式不正确,请填写一个整数数字。\r\n调试信息:" + err.Message, "警告");
- return;
- }
- condition_list.Add(" and (p_weight between " + ws_temp + " and " + we_temp + ") ");
- }
- //连接字符串
- string Connstr = "Data Source=" + System.Environment.CurrentDirectory + "\\Junde.db3"; ;
- //连接对象
- SQLiteConnection con = new SQLiteConnection(Connstr);
- //Sql语句
- string selectCmd = "SELECT * FROM Patient WHERE p_delete_flag = 0";
- foreach(string one_more_condition in condition_list)
- {
- selectCmd += one_more_condition;
- }
- selectCmd += " ORDER BY p_last_filter_time desc LIMIT 1000;";
- con.Open();
- da = new SQLiteDataAdapter(selectCmd, con);
- ds = new DataSet();
- da.Fill(ds);
- dataGrid.ItemsSource = ds.Tables[0].DefaultView;
- con.Close();
- }
- //双击某一行触发的事件
- private void dataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
- if (father != null)
- {
- if (this.Name == "selectUserfilter")
- {
- father.buttonFilterSelectTreatment_Click(this.father, e);
- }
- if (this.Name == "selectUserPatientManagent")
- {
- father.buttonModifyPatient_Click(this.father, e);
- }
- if (this.Name == "selectUserevaluation")
- {
- father.buttonEvaluationSelectPatient_Click(this.father, e);
- }
- if (this.Name == "selectUserHistory")
- {
- father.buttonHistorySelectPatient_Click(this.father, e);
- }
- }
- }
- }
- }
|