using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using WpfTest1.SQLite;
namespace WpfTest1
{
///
/// TreatmentRecordsPageSelectUser.xaml 的交互逻辑
///
public partial class TreatmentRecordsPageSelectUser : UserControl
{
DataSet ds;
//SQLiteCommandBuilder cmdb;
SQLiteDataAdapter da;
//DataRow dr;
MainWindow father;
public TreatmentRecordsPageSelectUser()
{
InitializeComponent();
SQLiteLogic.createDBAndTables();
//dataGrid.LoadingRow += new EventHandler(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)
{
#if !DEBUG
LoadDataGrid();
#endif
}
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";
}
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;
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 condition_list = new List();
// //姓名或拼音
// 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)
{
DataRowView selectedPatient = (DataRowView)dataGrid.SelectedItem;
int patientId = Convert.ToInt32(selectedPatient["p_id"].ToString());
List treatmentRecordOfSelectedPatient = SQLiteModel.getAllTreatmentRecordByPatientId(patientId);
treatmentRecords_DataGrid.ItemsSource = treatmentRecordOfSelectedPatient;
}
}
}