selectUser.xaml.cs 9.8 KB

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