TreatmentPlan.xaml.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. using WpfTest1.SQLite;
  15. namespace WpfTest1
  16. {
  17. /// <summary>
  18. /// TreatmentPlanPage.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class TreatmentPlanPage : UserControl
  21. {
  22. MainWindow father;
  23. public List<Treatment> treatmentList;
  24. private Treatment target = null;
  25. public TreatmentPlanPage()
  26. {
  27. InitializeComponent();
  28. loadDataGrid();
  29. }
  30. public TreatmentPlanPage(MainWindow father)
  31. {
  32. this.father = father;
  33. InitializeComponent();
  34. loadDataGrid();
  35. }
  36. public void setMainWindow(MainWindow father)
  37. {
  38. this.father = father;
  39. }
  40. public void loadDataGrid()
  41. {
  42. treatmentList = SQLiteModel.getALLTreatment();
  43. dataGrid.ItemsSource = treatmentList;
  44. target = null;
  45. }
  46. private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
  47. {
  48. target = (Treatment)dataGrid.CurrentItem;
  49. if (target != null)
  50. {
  51. textBoxDisease.Text = target.disease;
  52. textBoxBodyParts.Text = target.bodyParts;
  53. textBoxRate1.Text = target.rate1.ToString();
  54. textBoxRate2.Text = target.rate2.ToString();
  55. textBoxRate3.Text = target.rate3.ToString();
  56. textBoxRate4.Text = target.rate4.ToString();
  57. textBoxRate5.Text = target.rate5.ToString();
  58. textBoxRate6.Text = target.rate6.ToString();
  59. textBoxRate7.Text = target.rate7.ToString();
  60. textBoxRate8.Text = target.rate8.ToString();
  61. textBoxRate9.Text = target.rate9.ToString();
  62. textBoxRate10.Text = target.rate10.ToString();
  63. textBoxNum1.Text = target.num1.ToString();
  64. textBoxNum2.Text = target.num2.ToString();
  65. textBoxNum3.Text = target.num3.ToString();
  66. textBoxNum4.Text = target.num4.ToString();
  67. textBoxNum5.Text = target.num5.ToString();
  68. textBoxNum6.Text = target.num6.ToString();
  69. textBoxNum7.Text = target.num7.ToString();
  70. textBoxNum8.Text = target.num8.ToString();
  71. textBoxNum9.Text = target.num9.ToString();
  72. textBoxNum10.Text = target.num10.ToString();
  73. textBoxIntervalTime.Text = target.intervalTime.ToString();
  74. textBoxRepeatTimes.Text = target.repeatTimes.ToString();
  75. textBoxTotalTime.Text = target.totalTime.ToString();
  76. textBoxTotalNum.Text = target.totalNum.ToString();
  77. } else {
  78. textBoxDisease.Text = "";
  79. textBoxBodyParts.Text = "";
  80. textBoxRate1.Text = "";
  81. textBoxRate2.Text = "";
  82. textBoxRate3.Text = "";
  83. textBoxRate4.Text = "";
  84. textBoxRate5.Text = "";
  85. textBoxRate6.Text = "";
  86. textBoxRate7.Text = "";
  87. textBoxRate8.Text = "";
  88. textBoxRate9.Text = "";
  89. textBoxRate10.Text = "";
  90. textBoxNum1.Text = "";
  91. textBoxNum2.Text = "";
  92. textBoxNum3.Text = "";
  93. textBoxNum4.Text = "";
  94. textBoxNum5.Text = "";
  95. textBoxNum6.Text = "";
  96. textBoxNum7.Text = "";
  97. textBoxNum8.Text = "";
  98. textBoxNum9.Text = "";
  99. textBoxNum10.Text = "";
  100. textBoxIntervalTime.Text = "";
  101. textBoxRepeatTimes.Text = "";
  102. textBoxTotalTime.Text = "";
  103. textBoxTotalNum.Text = "";
  104. }
  105. }
  106. private void textBoxDisease_TextChanged(object sender, TextChangedEventArgs e)
  107. {
  108. checkChange();
  109. }
  110. private void textBoxBodyParts_TextChanged(object sender, TextChangedEventArgs e)
  111. {
  112. checkChange();
  113. }
  114. private void textBoxRateAll_TextChanged(object sender, TextChangedEventArgs e)
  115. {
  116. checkChange();
  117. }
  118. private void textBoxIntervalTime_TextChanged(object sender, TextChangedEventArgs e)
  119. {
  120. checkChange();
  121. }
  122. private void textBoxRepeatTimes_TextChanged(object sender, TextChangedEventArgs e)
  123. {
  124. checkChange();
  125. }
  126. private void checkChange()
  127. {
  128. if (target != null)
  129. {
  130. textBoxDisease.Background = textBoxDisease.Text == target.disease ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  131. textBoxBodyParts.Background = textBoxBodyParts.Text == target.bodyParts ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  132. textBoxRate1.Background = textBoxRate1.Text == target.rate1.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  133. textBoxRate2.Background = textBoxRate2.Text == target.rate2.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  134. textBoxRate3.Background = textBoxRate3.Text == target.rate3.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  135. textBoxRate4.Background = textBoxRate4.Text == target.rate4.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  136. textBoxRate5.Background = textBoxRate5.Text == target.rate5.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  137. textBoxRate6.Background = textBoxRate6.Text == target.rate6.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  138. textBoxRate7.Background = textBoxRate7.Text == target.rate7.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  139. textBoxRate8.Background = textBoxRate8.Text == target.rate8.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  140. textBoxRate9.Background = textBoxRate9.Text == target.rate9.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  141. textBoxRate10.Background = textBoxRate10.Text == target.rate10.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  142. textBoxNum1.Background = textBoxNum1.Text == target.num1.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  143. textBoxNum2.Background = textBoxNum2.Text == target.num2.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  144. textBoxNum3.Background = textBoxNum3.Text == target.num3.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  145. textBoxNum4.Background = textBoxNum4.Text == target.num4.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  146. textBoxNum5.Background = textBoxNum5.Text == target.num5.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  147. textBoxNum6.Background = textBoxNum6.Text == target.num6.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  148. textBoxNum7.Background = textBoxNum7.Text == target.num7.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  149. textBoxNum8.Background = textBoxNum8.Text == target.num8.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  150. textBoxNum9.Background = textBoxNum9.Text == target.num9.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  151. textBoxNum10.Background = textBoxNum10.Text == target.num10.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  152. textBoxIntervalTime.Background = textBoxIntervalTime.Text == target.intervalTime.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  153. textBoxRepeatTimes.Background = textBoxRepeatTimes.Text == target.repeatTimes.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
  154. checkError();
  155. } else {
  156. textBoxDisease.Background = Brushes.White;
  157. textBoxBodyParts.Background = Brushes.White;
  158. textBoxRate1.Background = Brushes.White;
  159. textBoxRate2.Background = Brushes.White;
  160. textBoxRate3.Background = Brushes.White;
  161. textBoxRate4.Background = Brushes.White;
  162. textBoxRate5.Background = Brushes.White;
  163. textBoxRate6.Background = Brushes.White;
  164. textBoxRate7.Background = Brushes.White;
  165. textBoxRate8.Background = Brushes.White;
  166. textBoxRate9.Background = Brushes.White;
  167. textBoxRate10.Background = Brushes.White;
  168. textBoxNum1.Background = Brushes.White;
  169. textBoxNum2.Background = Brushes.White;
  170. textBoxNum3.Background = Brushes.White;
  171. textBoxNum4.Background = Brushes.White;
  172. textBoxNum5.Background = Brushes.White;
  173. textBoxNum6.Background = Brushes.White;
  174. textBoxNum7.Background = Brushes.White;
  175. textBoxNum8.Background = Brushes.White;
  176. textBoxNum9.Background = Brushes.White;
  177. textBoxNum10.Background = Brushes.White;
  178. textBoxIntervalTime.Background = Brushes.White;
  179. textBoxRepeatTimes.Background = Brushes.White;
  180. }
  181. }
  182. private bool checkError()
  183. {
  184. bool error = false;
  185. TextBox[] textBoxRateList = { textBoxRate1, textBoxRate2, textBoxRate3, textBoxRate4, textBoxRate5, textBoxRate6, textBoxRate7, textBoxRate8, textBoxRate9, textBoxRate10 };
  186. for (int i = 0; i < 10; i++)
  187. {
  188. double t = 0;
  189. if (double.TryParse(textBoxRateList[i].Text, out t))
  190. {
  191. if (t >= 0 & t < 1)
  192. {
  193. if ((t * 10 % 1).Equals(0))
  194. {
  195. continue;
  196. }
  197. }
  198. else if (t >= 1 & t <= 100)
  199. {
  200. if (t % 1 == 0)
  201. {
  202. continue;
  203. }
  204. }
  205. }
  206. textBoxRateList[i].Background = (Brush)new BrushConverter().ConvertFrom("#FFFFB5B5");
  207. error = true;
  208. }
  209. TextBox[] textBoxNumList = { textBoxNum1, textBoxNum2, textBoxNum3, textBoxNum4, textBoxNum5, textBoxNum6, textBoxNum7, textBoxNum8, textBoxNum9, textBoxNum10, textBoxIntervalTime, textBoxRepeatTimes };
  210. for (int i = 0; i < 12; i++)
  211. {
  212. int t = 0;
  213. if (int.TryParse(textBoxNumList[i].Text, out t))
  214. {
  215. if (t >= 0 & t <= 100)
  216. {
  217. if (t % 1 == 0)
  218. {
  219. continue;
  220. }
  221. }
  222. }
  223. textBoxNumList[i].Background = (Brush)new BrushConverter().ConvertFrom("#FFFFB5B5");
  224. error = true;
  225. }
  226. return error;
  227. }
  228. private bool isEqualsTarget()
  229. {
  230. if (target == null) return true;
  231. int changenum = 0;
  232. changenum = textBoxDisease.Text == target.disease ? changenum : changenum + 1;
  233. changenum = textBoxBodyParts.Text == target.bodyParts ? changenum : changenum + 1;
  234. changenum = textBoxRate1.Text == target.rate1.ToString() ? changenum : changenum + 1;
  235. changenum = textBoxRate2.Text == target.rate2.ToString() ? changenum : changenum + 1;
  236. changenum = textBoxRate3.Text == target.rate3.ToString() ? changenum : changenum + 1;
  237. changenum = textBoxRate4.Text == target.rate4.ToString() ? changenum : changenum + 1;
  238. changenum = textBoxRate5.Text == target.rate5.ToString() ? changenum : changenum + 1;
  239. changenum = textBoxRate6.Text == target.rate6.ToString() ? changenum : changenum + 1;
  240. changenum = textBoxRate7.Text == target.rate7.ToString() ? changenum : changenum + 1;
  241. changenum = textBoxRate8.Text == target.rate8.ToString() ? changenum : changenum + 1;
  242. changenum = textBoxRate9.Text == target.rate9.ToString() ? changenum : changenum + 1;
  243. changenum = textBoxRate10.Text == target.rate10.ToString() ? changenum : changenum + 1;
  244. changenum = textBoxNum1.Text == target.num1.ToString() ? changenum : changenum + 1;
  245. changenum = textBoxNum2.Text == target.num2.ToString() ? changenum : changenum + 1;
  246. changenum = textBoxNum3.Text == target.num3.ToString() ? changenum : changenum + 1;
  247. changenum = textBoxNum4.Text == target.num4.ToString() ? changenum : changenum + 1;
  248. changenum = textBoxNum5.Text == target.num5.ToString() ? changenum : changenum + 1;
  249. changenum = textBoxNum6.Text == target.num6.ToString() ? changenum : changenum + 1;
  250. changenum = textBoxNum7.Text == target.num7.ToString() ? changenum : changenum + 1;
  251. changenum = textBoxNum8.Text == target.num8.ToString() ? changenum : changenum + 1;
  252. changenum = textBoxNum9.Text == target.num9.ToString() ? changenum : changenum + 1;
  253. changenum = textBoxNum10.Text == target.num10.ToString() ? changenum : changenum + 1;
  254. changenum = textBoxIntervalTime.Text == target.intervalTime.ToString() ? changenum : changenum + 1;
  255. changenum = textBoxRepeatTimes.Text == target.repeatTimes.ToString() ? changenum : changenum + 1;
  256. return changenum == 0 ? true : false;
  257. }
  258. private void buttonChange_Click(object sender, RoutedEventArgs e)
  259. {
  260. if (target == null)
  261. {
  262. MessageBox.Show("请选择要修改的治疗方案!");
  263. return;
  264. }
  265. int id = target.id;
  266. string disease = textBoxDisease.Text;
  267. string bodyParts = textBoxBodyParts.Text;
  268. double.TryParse(textBoxRate1.Text, out double rate1);
  269. double.TryParse(textBoxRate2.Text, out double rate2);
  270. double.TryParse(textBoxRate3.Text, out double rate3);
  271. double.TryParse(textBoxRate4.Text, out double rate4);
  272. double.TryParse(textBoxRate5.Text, out double rate5);
  273. double.TryParse(textBoxRate6.Text, out double rate6);
  274. double.TryParse(textBoxRate7.Text, out double rate7);
  275. double.TryParse(textBoxRate8.Text, out double rate8);
  276. double.TryParse(textBoxRate9.Text, out double rate9);
  277. double.TryParse(textBoxRate10.Text, out double rate10);
  278. int.TryParse(textBoxNum1.Text, out int num1);
  279. int.TryParse(textBoxNum2.Text, out int num2);
  280. int.TryParse(textBoxNum3.Text, out int num3);
  281. int.TryParse(textBoxNum4.Text, out int num4);
  282. int.TryParse(textBoxNum5.Text, out int num5);
  283. int.TryParse(textBoxNum6.Text, out int num6);
  284. int.TryParse(textBoxNum7.Text, out int num7);
  285. int.TryParse(textBoxNum8.Text, out int num8);
  286. int.TryParse(textBoxNum9.Text, out int num9);
  287. int.TryParse(textBoxNum10.Text, out int num10);
  288. double.TryParse(textBoxIntervalTime.Text, out double intervalTime);
  289. int.TryParse(textBoxRepeatTimes.Text, out int repeatTimes);
  290. if (checkError())
  291. {
  292. MessageBox.Show("存在无效数据,请检查后再点击修改按钮!");
  293. return;
  294. }
  295. if (isEqualsTarget())
  296. {
  297. MessageBox.Show("未进行任何修改!");
  298. return;
  299. }
  300. SQLiteModel.updateTreatment(id, disease, bodyParts, rate1, rate2, rate3, rate4, rate5, rate6, rate7, rate8, rate9, rate10, num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, intervalTime, repeatTimes);
  301. loadDataGrid();
  302. }
  303. private void buttonAdd_Click(object sender, RoutedEventArgs e)
  304. {
  305. if (target == null)
  306. {
  307. MessageBox.Show("请先随意选择一个方案,修改完成后再点击新增按钮。");
  308. return;
  309. }
  310. string disease = textBoxDisease.Text;
  311. string bodyParts = textBoxBodyParts.Text;
  312. double.TryParse(textBoxRate1.Text, out double rate1);
  313. double.TryParse(textBoxRate2.Text, out double rate2);
  314. double.TryParse(textBoxRate3.Text, out double rate3);
  315. double.TryParse(textBoxRate4.Text, out double rate4);
  316. double.TryParse(textBoxRate5.Text, out double rate5);
  317. double.TryParse(textBoxRate6.Text, out double rate6);
  318. double.TryParse(textBoxRate7.Text, out double rate7);
  319. double.TryParse(textBoxRate8.Text, out double rate8);
  320. double.TryParse(textBoxRate9.Text, out double rate9);
  321. double.TryParse(textBoxRate10.Text, out double rate10);
  322. int.TryParse(textBoxNum1.Text, out int num1);
  323. int.TryParse(textBoxNum2.Text, out int num2);
  324. int.TryParse(textBoxNum3.Text, out int num3);
  325. int.TryParse(textBoxNum4.Text, out int num4);
  326. int.TryParse(textBoxNum5.Text, out int num5);
  327. int.TryParse(textBoxNum6.Text, out int num6);
  328. int.TryParse(textBoxNum7.Text, out int num7);
  329. int.TryParse(textBoxNum8.Text, out int num8);
  330. int.TryParse(textBoxNum9.Text, out int num9);
  331. int.TryParse(textBoxNum10.Text, out int num10);
  332. double.TryParse(textBoxIntervalTime.Text, out double intervalTime);
  333. int.TryParse(textBoxRepeatTimes.Text, out int repeatTimes);
  334. if (checkError())
  335. {
  336. MessageBox.Show("存在无效数据,请检查后再点击修改按钮!");
  337. return;
  338. }
  339. if (isEqualsTarget())
  340. {
  341. MessageBox.Show("新方案与旧方案重复!");
  342. return;
  343. }
  344. SQLiteModel.insertTreatment(disease, bodyParts, rate1, rate2, rate3, rate4, rate5, rate6, rate7, rate8, rate9, rate10, num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, intervalTime, repeatTimes);
  345. loadDataGrid();
  346. }
  347. private void buttonDelete_Click(object sender, RoutedEventArgs e)
  348. {
  349. if (target == null)
  350. {
  351. MessageBox.Show("请选择要删除的治疗方案!");
  352. return;
  353. }
  354. int id = target.id;
  355. SQLiteModel.deleteTreatment(id);
  356. loadDataGrid();
  357. }
  358. private void buttonSelect_Click(object sender, RoutedEventArgs e)
  359. {
  360. if (target == null)
  361. {
  362. MessageBox.Show("请选择治疗方案!");
  363. return;
  364. }
  365. father.setTreatment(target);
  366. }
  367. }
  368. }