selectUser.xaml.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. #if !DEBUG
  55. LoadDataGrid();
  56. #endif
  57. }
  58. public void LoadDataGrid()
  59. {
  60. ////连接字符串
  61. //string Connstr = "Data Source=" + System.Environment.CurrentDirectory + "\\Junde.db3"; ;
  62. ////连接对象
  63. //SQLiteConnection con = new SQLiteConnection(Connstr);
  64. ////Sql语句
  65. string orderCondition = "p_last_filter_time desc";
  66. if (this.Name == "selectUserPatientManagent")
  67. {
  68. orderCondition = "p_id asc";
  69. }
  70. if (this.Name == "selectUserfilter")
  71. {
  72. orderCondition = "p_last_filter_time desc";
  73. }
  74. List<Patient> patientList = SQLiteModel.getAllNotLogicDeletePatient(orderCondition);
  75. //string selectCmd = "SELECT * FROM Patient WHERE p_delete_flag = 0 ORDER BY " + orderCondition + " LIMIT 100";
  76. //con.Open();
  77. //da = new SQLiteDataAdapter(selectCmd, con);
  78. //ds = new DataSet();
  79. //da.Fill(ds);
  80. //dataGrid.ItemsSource = ds.Tables[0].DefaultView;
  81. dataGrid.ItemsSource = patientList;
  82. //con.Close();
  83. }
  84. //点击重置的效果
  85. private void buttonReset_Click(object sender, RoutedEventArgs e)
  86. {
  87. textBoxName.Text = "姓名或者拼音首字母";
  88. textBoxCaseID.Text = "";
  89. textBoxPregnancyTime.Text = "";
  90. textBoxHeightStart.Text = "";
  91. textBoxHeightEnd.Text = "";
  92. textBoxWeightStart.Text = "";
  93. textBoxWeightEnd.Text = "";
  94. datePickerBirthTimeStart.Text = "";
  95. datePickerBirthTimeEnd.Text = "";
  96. LoadDataGrid();
  97. }
  98. private void textBoxName_GotFocus(object sender, RoutedEventArgs e)
  99. {
  100. if (sender != null)
  101. {
  102. TextBox tbx = sender as TextBox;
  103. tbx.SelectAll();
  104. tbx.PreviewMouseDown -= new MouseButtonEventHandler(textBoxName_PreviewMouseDown);
  105. }
  106. }
  107. private void textBoxName_PreviewMouseDown(object sender, MouseButtonEventArgs e)
  108. {
  109. TextBox tb = sender as TextBox;
  110. if (tb != null)
  111. {
  112. tb.Focus();
  113. e.Handled = true;
  114. }
  115. }
  116. private void textBoxName_LostFocus(object sender, RoutedEventArgs e)
  117. {
  118. TextBox tb = sender as TextBox;
  119. if (tb != null)
  120. {
  121. tb.PreviewMouseDown += new MouseButtonEventHandler(textBoxName_PreviewMouseDown);
  122. }
  123. }
  124. //点击筛选用户
  125. private void buttonQuery_Click(object sender, RoutedEventArgs e)
  126. {
  127. List<string> condition_list = new List<string>();
  128. //姓名或拼音
  129. string name_or_py = textBoxName.Text;
  130. if (name_or_py != "姓名或者拼音首字母" && name_or_py != "")
  131. {
  132. condition_list.Add(" and (p_name LIKE \'%"+ name_or_py +"%\' or p_name_py LIKE \'%"+ name_or_py +"%\') ");
  133. }
  134. //病例编号
  135. if(textBoxCaseID.Text != "")
  136. {
  137. condition_list.Add(" and p_record_id = '" + textBoxCaseID.Text + "' ");
  138. }
  139. //孕次
  140. if (textBoxPregnancyTime.Text != "")
  141. {
  142. string pt_temp = "";
  143. try
  144. {
  145. pt_temp = Convert.ToString(Convert.ToInt32(textBoxPregnancyTime.Text));
  146. }
  147. catch(Exception err)
  148. {
  149. MessageBox.Show("孕次信息格式不正确,请填写一个整数数字。\r\n调试信息:"+err.Message,"警告");
  150. return;
  151. }
  152. condition_list.Add(" and p_pregnancy_time = " + pt_temp + " ");
  153. }
  154. //出生日期
  155. if (datePickerBirthTimeStart.Text != "" && datePickerBirthTimeEnd.Text != "")
  156. {
  157. DateTime dt;
  158. System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
  159. //MessageBox.Show(pregnancydate);
  160. dtFormat.ShortDatePattern = "yyyy/M/d";
  161. string dateStart = datePickerBirthTimeStart.Text;
  162. string dateEnd = datePickerBirthTimeEnd.Text;
  163. try
  164. {
  165. dt = Convert.ToDateTime(dateStart, dtFormat);
  166. dateStart = dt.ToString("yyyy-MM-dd");
  167. dt = Convert.ToDateTime(dateEnd, dtFormat);
  168. dateEnd = dt.ToString("yyyy-MM-dd");
  169. }
  170. catch (Exception err)
  171. {
  172. MessageBox.Show("孕妇出生日期格式不正确,请通过栏中日历的按钮选择日期。\r\n调试信息:" + err.Message, "警告");
  173. return;
  174. }
  175. condition_list.Add(" and (p_birthdate between '" + dateStart + "' and '" + dateEnd + "') ");
  176. }
  177. //身高条件
  178. if (textBoxHeightStart.Text != "" && textBoxHeightEnd.Text != "")
  179. {
  180. string hs_temp = "";
  181. string he_temp = "";
  182. try
  183. {
  184. hs_temp = Convert.ToString(Convert.ToDouble(textBoxHeightStart.Text));
  185. he_temp = Convert.ToString(Convert.ToDouble(textBoxHeightEnd.Text));
  186. }
  187. catch (Exception err)
  188. {
  189. MessageBox.Show("身高信息格式不正确,请填写一个整数数字。\r\n调试信息:" + err.Message, "警告");
  190. return;
  191. }
  192. condition_list.Add(" and (p_height between " + hs_temp + " and "+ he_temp + ") ");
  193. }
  194. //体重条件
  195. if (textBoxWeightStart.Text != "" && textBoxWeightEnd.Text != "")
  196. {
  197. string ws_temp = "";
  198. string we_temp = "";
  199. try
  200. {
  201. ws_temp = Convert.ToString(Convert.ToInt32(textBoxWeightStart.Text));
  202. we_temp = Convert.ToString(Convert.ToInt32(textBoxWeightEnd.Text));
  203. }
  204. catch (Exception err)
  205. {
  206. MessageBox.Show("体重信息格式不正确,请填写一个整数数字。\r\n调试信息:" + err.Message, "警告");
  207. return;
  208. }
  209. condition_list.Add(" and (p_weight between " + ws_temp + " and " + we_temp + ") ");
  210. }
  211. //连接字符串
  212. string Connstr = "Data Source=" + System.Environment.CurrentDirectory + "\\Junde.db3"; ;
  213. //连接对象
  214. SQLiteConnection con = new SQLiteConnection(Connstr);
  215. //Sql语句
  216. string selectCmd = "SELECT * FROM Patient WHERE p_delete_flag = 0";
  217. foreach(string one_more_condition in condition_list)
  218. {
  219. selectCmd += one_more_condition;
  220. }
  221. selectCmd += " ORDER BY p_last_filter_time desc LIMIT 1000;";
  222. con.Open();
  223. da = new SQLiteDataAdapter(selectCmd, con);
  224. ds = new DataSet();
  225. da.Fill(ds);
  226. dataGrid.ItemsSource = ds.Tables[0].DefaultView;
  227. con.Close();
  228. }
  229. //双击某一行触发的事件
  230. private void dataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  231. {
  232. if (father != null)
  233. {
  234. if (this.Name == "selectUserfilter")
  235. {
  236. father.buttonFilterSelectTreatment_Click(this.father, e);
  237. }
  238. if (this.Name == "selectUserPatientManagent")
  239. {
  240. father.buttonModifyPatient_Click(this.father, e);
  241. }
  242. if (this.Name == "selectUserevaluation")
  243. {
  244. father.buttonEvaluationSelectPatient_Click(this.father, e);
  245. }
  246. if (this.Name == "selectUserHistory")
  247. {
  248. father.buttonHistorySelectPatient_Click(this.father, e);
  249. }
  250. }
  251. }
  252. }
  253. }