selectUser.xaml.cs 9.6 KB

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