TreatmentRecordsPageSelectUser.xaml.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SQLite;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using WpfTest1.SQLite;
  10. namespace WpfTest1
  11. {
  12. /// <summary>
  13. /// TreatmentRecordsPageSelectUser.xaml 的交互逻辑
  14. /// </summary>
  15. public partial class TreatmentRecordsPageSelectUser : UserControl
  16. {
  17. DataSet ds;
  18. //SQLiteCommandBuilder cmdb;
  19. SQLiteDataAdapter da;
  20. //DataRow dr;
  21. MainWindow father;
  22. public TreatmentRecordsPageSelectUser()
  23. {
  24. InitializeComponent();
  25. SQLiteLogic.createDBAndTables();
  26. //dataGrid.LoadingRow += new EventHandler<DataGridRowEventArgs>(dataGrid_LoadingRow);
  27. }
  28. public void setMainWindow(MainWindow father)
  29. {
  30. this.father = father;
  31. }
  32. public void dataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
  33. {
  34. e.Row.Header = e.Row.GetIndex() + 1;
  35. }
  36. //筛选得到符合条件的用户数据
  37. private void dataGrid_Loaded(object sender, RoutedEventArgs e)
  38. {
  39. #if !DEBUG
  40. LoadDataGrid();
  41. #endif
  42. }
  43. public void LoadDataGrid()
  44. {
  45. //连接字符串
  46. string Connstr = "Data Source=" + System.Environment.CurrentDirectory + "\\Junde.db3"; ;
  47. //连接对象
  48. SQLiteConnection con = new SQLiteConnection(Connstr);
  49. //Sql语句
  50. string orderCondition = "p_last_filter_time desc";
  51. if (this.Name == "selectUserPatientManagent")
  52. {
  53. orderCondition = "p_id asc";
  54. }
  55. if (this.Name == "selectUserfilter")
  56. {
  57. orderCondition = "p_last_filter_time desc";
  58. }
  59. string selectCmd = "SELECT * FROM Patient WHERE p_delete_flag = 0 ORDER BY " + orderCondition + " LIMIT 100";
  60. con.Open();
  61. da = new SQLiteDataAdapter(selectCmd, con);
  62. ds = new DataSet();
  63. da.Fill(ds);
  64. dataGrid.ItemsSource = ds.Tables[0].DefaultView;
  65. con.Close();
  66. }
  67. //点击重置的效果
  68. //private void buttonReset_Click(object sender, RoutedEventArgs e)
  69. //{
  70. // textBoxName.Text = "姓名或者拼音首字母";
  71. // textBoxCaseID.Text = "";
  72. // textBoxPregnancyTime.Text = "";
  73. // textBoxHeightStart.Text = "";
  74. // textBoxHeightEnd.Text = "";
  75. // textBoxWeightStart.Text = "";
  76. // textBoxWeightEnd.Text = "";
  77. // datePickerBirthTimeStart.Text = "";
  78. // datePickerBirthTimeEnd.Text = "";
  79. // LoadDataGrid();
  80. //}
  81. private void textBoxName_GotFocus(object sender, RoutedEventArgs e)
  82. {
  83. if (sender != null)
  84. {
  85. TextBox tbx = sender as TextBox;
  86. tbx.SelectAll();
  87. tbx.PreviewMouseDown -= new MouseButtonEventHandler(textBoxName_PreviewMouseDown);
  88. }
  89. }
  90. private void textBoxName_PreviewMouseDown(object sender, MouseButtonEventArgs e)
  91. {
  92. TextBox tb = sender as TextBox;
  93. if (tb != null)
  94. {
  95. tb.Focus();
  96. e.Handled = true;
  97. }
  98. }
  99. private void textBoxName_LostFocus(object sender, RoutedEventArgs e)
  100. {
  101. TextBox tb = sender as TextBox;
  102. if (tb != null)
  103. {
  104. tb.PreviewMouseDown += new MouseButtonEventHandler(textBoxName_PreviewMouseDown);
  105. }
  106. }
  107. ////点击筛选用户
  108. //private void buttonQuery_Click(object sender, RoutedEventArgs e)
  109. //{
  110. // List<string> condition_list = new List<string>();
  111. // //姓名或拼音
  112. // string name_or_py = textBoxName.Text;
  113. // if (name_or_py != "姓名或者拼音首字母" && name_or_py != "")
  114. // {
  115. // condition_list.Add(" and (p_name LIKE \'%"+ name_or_py +"%\' or p_name_py LIKE \'%"+ name_or_py +"%\') ");
  116. // }
  117. // //病例编号
  118. // if(textBoxCaseID.Text != "")
  119. // {
  120. // condition_list.Add(" and p_record_id = '" + textBoxCaseID.Text + "' ");
  121. // }
  122. // //孕次
  123. // if (textBoxPregnancyTime.Text != "")
  124. // {
  125. // string pt_temp = "";
  126. // try
  127. // {
  128. // pt_temp = Convert.ToString(Convert.ToInt32(textBoxPregnancyTime.Text));
  129. // }
  130. // catch(Exception err)
  131. // {
  132. // MessageBox.Show("孕次信息格式不正确,请填写一个整数数字。\r\n调试信息:"+err.Message,"警告");
  133. // return;
  134. // }
  135. // condition_list.Add(" and p_pregnancy_time = " + pt_temp + " ");
  136. // }
  137. // //出生日期
  138. // if (datePickerBirthTimeStart.Text != "" && datePickerBirthTimeEnd.Text != "")
  139. // {
  140. // DateTime dt;
  141. // System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
  142. // //MessageBox.Show(pregnancydate);
  143. // dtFormat.ShortDatePattern = "yyyy/M/d";
  144. // string dateStart = datePickerBirthTimeStart.Text;
  145. // string dateEnd = datePickerBirthTimeEnd.Text;
  146. // try
  147. // {
  148. // dt = Convert.ToDateTime(dateStart, dtFormat);
  149. // dateStart = dt.ToString("yyyy-MM-dd");
  150. // dt = Convert.ToDateTime(dateEnd, dtFormat);
  151. // dateEnd = dt.ToString("yyyy-MM-dd");
  152. // }
  153. // catch (Exception err)
  154. // {
  155. // MessageBox.Show("孕妇出生日期格式不正确,请通过栏中日历的按钮选择日期。\r\n调试信息:" + err.Message, "警告");
  156. // return;
  157. // }
  158. // condition_list.Add(" and (p_birthdate between '" + dateStart + "' and '" + dateEnd + "') ");
  159. // }
  160. // //身高条件
  161. // if (textBoxHeightStart.Text != "" && textBoxHeightEnd.Text != "")
  162. // {
  163. // string hs_temp = "";
  164. // string he_temp = "";
  165. // try
  166. // {
  167. // hs_temp = Convert.ToString(Convert.ToDouble(textBoxHeightStart.Text));
  168. // he_temp = Convert.ToString(Convert.ToDouble(textBoxHeightEnd.Text));
  169. // }
  170. // catch (Exception err)
  171. // {
  172. // MessageBox.Show("身高信息格式不正确,请填写一个整数数字。\r\n调试信息:" + err.Message, "警告");
  173. // return;
  174. // }
  175. // condition_list.Add(" and (p_height between " + hs_temp + " and "+ he_temp + ") ");
  176. // }
  177. // //体重条件
  178. // if (textBoxWeightStart.Text != "" && textBoxWeightEnd.Text != "")
  179. // {
  180. // string ws_temp = "";
  181. // string we_temp = "";
  182. // try
  183. // {
  184. // ws_temp = Convert.ToString(Convert.ToInt32(textBoxWeightStart.Text));
  185. // we_temp = Convert.ToString(Convert.ToInt32(textBoxWeightEnd.Text));
  186. // }
  187. // catch (Exception err)
  188. // {
  189. // MessageBox.Show("体重信息格式不正确,请填写一个整数数字。\r\n调试信息:" + err.Message, "警告");
  190. // return;
  191. // }
  192. // condition_list.Add(" and (p_weight between " + ws_temp + " and " + we_temp + ") ");
  193. // }
  194. // //连接字符串
  195. // string Connstr = "Data Source=" + System.Environment.CurrentDirectory + "\\Junde.db3"; ;
  196. // //连接对象
  197. // SQLiteConnection con = new SQLiteConnection(Connstr);
  198. // //Sql语句
  199. // string selectCmd = "SELECT * FROM Patient WHERE p_delete_flag = 0";
  200. // foreach(string one_more_condition in condition_list)
  201. // {
  202. // selectCmd += one_more_condition;
  203. // }
  204. // selectCmd += " ORDER BY p_last_filter_time desc LIMIT 1000;";
  205. // con.Open();
  206. // da = new SQLiteDataAdapter(selectCmd, con);
  207. // ds = new DataSet();
  208. // da.Fill(ds);
  209. // dataGrid.ItemsSource = ds.Tables[0].DefaultView;
  210. // con.Close();
  211. //}
  212. //双击用户列表某一行触发的事件
  213. private void dataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  214. {
  215. DataRowView selectedPatient = (DataRowView)dataGrid.SelectedItem;
  216. int patientId = Convert.ToInt32(selectedPatient["p_id"].ToString());
  217. List<TreatmentRecord> treatmentRecordOfSelectedPatient = SQLiteModel.getAllTreatmentRecordByPatientId(patientId);
  218. treatmentRecords_DataGrid.ItemsSource = treatmentRecordOfSelectedPatient;
  219. }
  220. }
  221. }