MainWindow.xaml.cs 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.IO;
  6. using System.Windows.Input;
  7. using MahApps.Metro.Controls;
  8. using MahApps.Metro.Controls.Dialogs;
  9. using System.Data;
  10. using WpfTest1.SQLite;
  11. using WpfTest1.Toolkits;
  12. using LitJson;
  13. using System.ComponentModel;
  14. namespace WpfTest1
  15. {
  16. /// <summary>
  17. /// MainWindow.xaml 的交互逻辑
  18. /// </summary>
  19. public partial class MainWindow : MetroWindow
  20. {
  21. #region 系统基本参数
  22. System.Data.SQLite.SQLiteDataAdapter daHistoryRecord; //选择记录页面查询记录条目的数据集容器
  23. public doctor loginDoctor = null; //所登陆的医师
  24. DataSet ds; //其他界面的DataSet
  25. System.Data.SQLite.SQLiteDataAdapter da; //其他界面的DataAdapter
  26. //double highBp; //BP界面高压
  27. //double lowBp; //BP界面低压
  28. DateTime lastSettingLogin; //上一次在系统设置界面登陆的时间
  29. public Toolkits.Config cfg; //从数据库取配置的类
  30. Patient filterPatient;
  31. Patient evaluationPatient;
  32. Patient historyPatient;
  33. Record filterReportForEvaluation;
  34. bool flagEvaluationWithoutFilter = true;
  35. List<QuestionAnswerPair> filterQuestionaire = new List<QuestionAnswerPair>();
  36. List<QuestionAnswerPair> evaluationQuestionaire = new List<QuestionAnswerPair>();
  37. List<UserSelection> filterUserSelection = new List<UserSelection>();
  38. List<UserSelection> evaluationUserSelection = new List<UserSelection>();
  39. string resultsFilter;
  40. string resultsEvaluation;
  41. int currentFilterCount = 0;
  42. int currentEvaluationCount = 0;
  43. List<Record> recordsFromOnePatient;
  44. BindingList<Record> bindingRecords;
  45. #endregion
  46. public MainWindow()
  47. {
  48. InitializeComponent();
  49. //加载配置
  50. cfg = new Toolkits.Config();
  51. //绑定三个selectUser的父类
  52. //selectUserMeasure.setMainWindow(this);
  53. selectUserPatientManagent.setMainWindow(this);
  54. selectUserfilter.setMainWindow(this);
  55. selectUserevaluation.setMainWindow(this);
  56. selectUserHistory.setMainWindow(this);
  57. }
  58. #region 初始化与系统调用部分
  59. //初始化全部组件后需要先输入医生密码才能进入
  60. //async
  61. private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
  62. {
  63. //Thread.Sleep(2000);
  64. //首先验证注册机制
  65. bool registerSuccess = cfg.CheckRegisterCode();
  66. if (!registerSuccess)
  67. {
  68. SmallDialogs.RegisterCode rc = new SmallDialogs.RegisterCode(this,cfg,true);
  69. rc.ShowDialog();
  70. }
  71. //之后测试登陆
  72. SmallDialogs.LoginWindow lw = new SmallDialogs.LoginWindow(this);
  73. lw.ShowDialog();
  74. if(loginDoctor == null)
  75. {
  76. this.Close();
  77. }
  78. //显示医生姓名
  79. if (loginDoctor != null)
  80. {
  81. loginedDoctorName.Content = "欢迎您, " + loginDoctor.name;
  82. return;
  83. }
  84. loadQuestionaire(filterQuestionaire, "filter");
  85. loadQuestionaire(evaluationQuestionaire, "evaluation");
  86. }
  87. private void loadQuestionaire(List<QuestionAnswerPair> oneQuestionaire, string type = "filter")
  88. {
  89. oneQuestionaire.Clear();
  90. List<Question> questions = SQLite.SQLiteModel.getQuestions(type);
  91. foreach (Question oneQuestion in questions)
  92. {
  93. List<Answer> answers = SQLite.SQLiteModel.getAnswersByQid(oneQuestion.q_id);
  94. QuestionAnswerPair temp = new QuestionAnswerPair(oneQuestion, answers);
  95. oneQuestionaire.Add(temp);
  96. }
  97. }
  98. #endregion
  99. #region 首页功能
  100. //标题栏快速添加病例的接口
  101. private void Fast_Add_Patient_Button_Click(object sender, RoutedEventArgs e)
  102. {
  103. buttonAddPatient_Click(this, e);
  104. }
  105. //首页--新建用户
  106. private void buttonHomePageAddPatient_Click(object sender, RoutedEventArgs e)
  107. {
  108. buttonAddPatient_Click(this, e);
  109. }
  110. //首页--用户管理
  111. private void buttonHomePagePatientManagent_Click(object sender, RoutedEventArgs e)
  112. {
  113. tabControlGeneral.SelectedIndex = 1;
  114. }
  115. //首页--检测报告
  116. private void buttonHomePageReport_Click(object sender, RoutedEventArgs e)
  117. {
  118. //buttonResultOpenDirHistory_Click(this, e);
  119. }
  120. //首页--系统设置
  121. private void buttonHomePageSystemSettings_Click(object sender, RoutedEventArgs e)
  122. {
  123. tabControlGeneral.SelectedIndex = 2;
  124. }
  125. //首页--操作帮助
  126. private void buttonHomePageHelp_Click(object sender, RoutedEventArgs e)
  127. {
  128. System.Diagnostics.Process.Start("https://www.baidu.com");
  129. }
  130. #endregion
  131. #region 病例管理
  132. //病例管理
  133. //病例管理--病例管理
  134. #region 病例管理--添加病例
  135. //添加病例
  136. private void buttonAddPatient_Click(object sender, RoutedEventArgs e)
  137. {
  138. AddPatient a_new_one = new AddPatient(this);
  139. a_new_one.Show();
  140. //selectUserPatientManagent.LoadDataGrid();
  141. }
  142. #endregion
  143. #region 病例管理--修改病例
  144. //修改病例
  145. public void buttonModifyPatient_Click(object sender, RoutedEventArgs e)
  146. {
  147. try
  148. {
  149. var target = (DataRowView)this.selectUserPatientManagent.dataGrid.SelectedItem;
  150. //MessageBox.Show(target["id"].ToString());
  151. ModifyUser modify_one = new ModifyUser(this, target["p_id"].ToString());
  152. modify_one.Show();
  153. }
  154. catch(Exception err)
  155. {
  156. //this.ShowMessageAsync("警告","请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace );
  157. MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace,"警告");
  158. }
  159. }
  160. #endregion
  161. #region 病例管理--删除病例
  162. //删除病例
  163. private void buttonDeletePatient_Click(object sender, RoutedEventArgs e)
  164. {
  165. try
  166. {
  167. var target = (DataRowView)this.selectUserPatientManagent.dataGrid.SelectedItem;
  168. if(target == null)
  169. {
  170. MessageBox.Show("请选择一个病例进行删除", "提示");
  171. return;
  172. }
  173. MessageBoxResult clickresult = MessageBox.Show("确认删除该病例?", "提示", MessageBoxButton.OKCancel);
  174. if (clickresult == MessageBoxResult.OK)
  175. {
  176. int status = SQLite.SQLiteModel.DeletePatientItem(target["p_id"].ToString());
  177. if (status > 0)
  178. {
  179. MessageBox.Show("删除成功","提示");
  180. }
  181. else
  182. {
  183. MessageBox.Show("已删除", "提示");
  184. }
  185. }
  186. else if (clickresult == MessageBoxResult.Cancel)
  187. {
  188. return;
  189. }
  190. }
  191. catch (Exception err)
  192. {
  193. MessageBox.Show("数据库故障\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  194. }
  195. selectUserPatientManagent.LoadDataGrid();
  196. }
  197. #endregion
  198. #endregion
  199. #region 筛查功能
  200. /// <summary>
  201. /// 点击开始筛查后触发的事件
  202. /// </summary>
  203. /// <param name="sender">默认</param>
  204. /// <param name="e">默认</param>
  205. public void buttonFilterSelectPatient_Click(object sender, RoutedEventArgs e)
  206. {
  207. try
  208. {
  209. var target = (DataRowView)this.selectUserfilter.dataGrid.SelectedItem;
  210. filterPatient = SQLite.SQLiteModel.getPatientById(target["p_id"].ToString());
  211. }
  212. catch (Exception err)
  213. {
  214. MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "警告");
  215. return;
  216. }
  217. if(filterPatient == null)
  218. {
  219. MessageBox.Show("数据库加载异常", "错误");
  220. return;
  221. }
  222. try
  223. {
  224. loadQuestionaire(filterQuestionaire, "filter");
  225. filterUserSelection.Clear();
  226. foreach(QuestionAnswerPair qa in filterQuestionaire)
  227. {
  228. filterUserSelection.Add(new UserSelection(qa.question.q_id, 0));
  229. }
  230. }
  231. catch (Exception err)
  232. {
  233. MessageBox.Show("筛查题目加载失败\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  234. return;
  235. }
  236. if(filterQuestionaire.Count == 0)
  237. {
  238. MessageBox.Show("筛查题目加载失败\r\n数据库中无有效问卷", "错误");
  239. return;
  240. }
  241. currentFilterCount = 1;
  242. loadQuestionViewFilter(currentFilterCount);
  243. tabFilter.SelectedIndex += 1;
  244. }
  245. /// <summary>
  246. /// 点击中止筛查后触发的事件
  247. /// </summary>
  248. /// <param name="sender">默认</param>
  249. /// <param name="e">默认</param>
  250. private void buttonAbortFilter_Click(object sender, RoutedEventArgs e)
  251. {
  252. filterUserSelection.Clear();
  253. filterPatient = null;
  254. resultsFilter = "";
  255. currentFilterCount = 0;
  256. buttonFilterPrevious.IsEnabled = false;
  257. buttonFilterNext.IsEnabled = false;
  258. buttonSubmitFilter.IsEnabled = false;
  259. tabFilter.SelectedIndex = 0;
  260. }
  261. /// <summary>
  262. /// 点击筛查上一步后触发的事件
  263. /// </summary>
  264. /// <param name="sender">默认</param>
  265. /// <param name="e">默认</param>
  266. private void buttonFilterPrevious_Click(object sender, RoutedEventArgs e)
  267. {
  268. currentFilterCount -= 1;
  269. loadQuestionViewFilter(currentFilterCount);
  270. checkFilterButtonStatues();
  271. }
  272. /// <summary>
  273. /// 点击筛查下一步后触发的事件
  274. /// </summary>
  275. /// <param name="sender">默认</param>
  276. /// <param name="e">默认</param>
  277. private void buttonFilterNext_Click(object sender, RoutedEventArgs e)
  278. {
  279. currentFilterCount += 1;
  280. loadQuestionViewFilter(currentFilterCount);
  281. checkFilterButtonStatues();
  282. }
  283. /// <summary>
  284. /// 确认筛查阶段各个按钮应当处于的状态
  285. /// </summary>
  286. private void checkFilterButtonStatues()
  287. {
  288. bool radioCheckFlag = false;
  289. foreach(RadioButton rb in gridFilterSelection.Children){
  290. if(rb.IsChecked == true)
  291. {
  292. radioCheckFlag = true;
  293. }
  294. }
  295. if (radioCheckFlag && currentFilterCount < filterQuestionaire.Count)
  296. buttonFilterNext.IsEnabled = true;
  297. else
  298. buttonFilterNext.IsEnabled = false;
  299. if (currentFilterCount > 1)
  300. buttonFilterPrevious.IsEnabled = true;
  301. else
  302. buttonFilterPrevious.IsEnabled = false;
  303. bool allFilledFlag = true;
  304. foreach (UserSelection us in filterUserSelection)
  305. {
  306. if (us.a_id == 0)
  307. allFilledFlag = false;
  308. }
  309. if (allFilledFlag)
  310. buttonSubmitFilter.IsEnabled = true;
  311. else
  312. buttonSubmitFilter.IsEnabled = false;
  313. }
  314. /// <summary>
  315. /// 加载题目和选项界面
  316. /// </summary>
  317. private void loadQuestionViewFilter(int currentIndex)
  318. {
  319. labelFilterNumberofTotalQuestions.Content = filterQuestionaire.Count.ToString();
  320. labelFilterNumberofCurrentQuestion.Content = currentIndex.ToString();
  321. labelFilterQuestionTitle.Content = filterQuestionaire[currentIndex - 1].question.q_title;
  322. textBlockFilterQuetionContent.Text = filterQuestionaire[currentIndex - 1].question.q_content;
  323. int countOptions = filterQuestionaire[currentIndex - 1].answers.Count;
  324. gridFilterSelection.Children.Clear();
  325. for (int i = 0; i< countOptions; ++i)
  326. {
  327. RadioButton oneOption = new RadioButton();
  328. oneOption.Height = 30;
  329. oneOption.HorizontalAlignment = HorizontalAlignment.Left;
  330. oneOption.VerticalAlignment = VerticalAlignment.Top;
  331. oneOption.Margin = new Thickness(i/5*200, i%5*40, 0, 0);
  332. if(filterUserSelection[currentIndex-1].a_id == filterQuestionaire[currentIndex - 1].answers[i].a_id)
  333. oneOption.IsChecked = true;
  334. else
  335. oneOption.IsChecked = false;
  336. oneOption.Content = filterQuestionaire[currentIndex - 1].answers[i].a_content;
  337. oneOption.Checked += radioButtonFilter_Checked;
  338. oneOption.GroupName = "filterOption";
  339. oneOption.FontSize = 18;
  340. oneOption.Name = "rbf" + filterQuestionaire[currentIndex - 1].answers[i].a_id.ToString();
  341. gridFilterSelection.Children.Add(oneOption);
  342. }
  343. }
  344. private void radioButtonFilter_Checked(object sender, RoutedEventArgs e)
  345. {
  346. //首先,记录该选择
  347. RadioButton oneSelection = (RadioButton)sender;
  348. filterUserSelection[currentFilterCount - 1].a_id = Convert.ToInt32(oneSelection.Name.Substring(3));
  349. //MessageBox.Show(filterUserSelection[currentFilterCount - 1].a_id.ToString());
  350. //然后,确认各个按钮状态
  351. checkFilterButtonStatues();
  352. }
  353. /// <summary>
  354. /// 点击筛查提交后触发的事件
  355. /// </summary>
  356. /// <param name="sender">默认</param>
  357. /// <param name="e">默认</param>
  358. private void buttonSubmitFilter_Click(object sender, RoutedEventArgs e)
  359. {
  360. int inserted_r_id;
  361. resultsFilter = JsonMapper.ToJson(filterUserSelection);
  362. //MessageBox.Show(results);
  363. try
  364. {
  365. inserted_r_id = SQLiteModel.insertRecord(1, filterPatient.p_id, loginDoctor.id, 0, DateTime.Now, 0, resultsFilter);
  366. SQLiteModel.UpdatePatientDataWithLastDate(filterPatient.p_id, "p_last_filter_time", DateTime.Now);
  367. }
  368. catch (Exception err)
  369. {
  370. MessageBox.Show("储存筛查报告错误\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  371. return;
  372. }
  373. MessageBoxResult dr = MessageBox.Show("保存筛查结果成功,是否生成报告?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
  374. if (dr == MessageBoxResult.OK)
  375. {
  376. Record targetRecord = SQLiteModel.getRecordByID(inserted_r_id);
  377. ReportGenerater.generateReport(1, filterPatient, loginDoctor, targetRecord, cfg.organization_name);
  378. SQLiteModel.plusOneCountOnRecordByRid(inserted_r_id);
  379. tabFilter.SelectedIndex = 2;
  380. }
  381. else
  382. {
  383. buttonAbortFilter_Click(sender, e);
  384. }
  385. return;
  386. }
  387. /// <summary>
  388. /// 返回至选择用户页
  389. /// </summary>
  390. /// <param name="sender">默认</param>
  391. /// <param name="e">默认</param>
  392. private void buttonFilterBackToSelectUser_Click(object sender, RoutedEventArgs e)
  393. {
  394. buttonAbortFilter_Click(sender, e);
  395. }
  396. /// <summary>
  397. /// 返回至选择首页
  398. /// </summary>
  399. /// <param name="sender">默认</param>
  400. /// <param name="e">默认</param>
  401. private void buttonFilterBackToHome_Click(object sender, RoutedEventArgs e)
  402. {
  403. buttonAbortFilter_Click(sender, e);
  404. tabControlGeneral.SelectedIndex = 0;
  405. }
  406. #endregion
  407. #region 评估功能
  408. /// <summary>
  409. /// 点击开始评估后触发的事件
  410. /// </summary>
  411. /// <param name="sender">默认</param>
  412. /// <param name="e">默认</param>
  413. public void buttonEvaluationSelectPatient_Click(object sender, RoutedEventArgs e)
  414. {
  415. //基本逻辑如下:先找七天内与病例相匹配的筛查记录,如果有,那么要取出结果一题一题比对
  416. //如果没有,那么应当把筛查题进行加载处理
  417. try
  418. {
  419. var target = (DataRowView)this.selectUserevaluation.dataGrid.SelectedItem;
  420. evaluationPatient = SQLite.SQLiteModel.getPatientById(target["p_id"].ToString());
  421. }
  422. catch (Exception err)
  423. {
  424. MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "警告");
  425. return;
  426. }
  427. if (evaluationPatient == null)
  428. {
  429. MessageBox.Show("数据库加载异常", "错误");
  430. return;
  431. }
  432. try
  433. {
  434. loadQuestionaire(filterQuestionaire, "filter");
  435. evaluationQuestionaire.Clear();
  436. filterUserSelection.Clear();
  437. evaluationUserSelection.Clear();
  438. //这里尝试加载用户的筛查记录
  439. filterReportForEvaluation = SQLiteModel.getLatestXTypeRecordInYDays(evaluationPatient.p_id, 1, 7);
  440. if(filterReportForEvaluation == null)
  441. {
  442. flagEvaluationWithoutFilter = true;
  443. foreach (QuestionAnswerPair qa in filterQuestionaire)
  444. {
  445. filterUserSelection.Add(new UserSelection(qa.question.q_id, 0));
  446. }
  447. }
  448. else
  449. {
  450. var jsonUserSelections = filterReportForEvaluation.r_selection;
  451. filterUserSelection = JsonMapper.ToObject<List<UserSelection>>(jsonUserSelections);
  452. flagEvaluationWithoutFilter = false;
  453. }
  454. }
  455. catch (Exception err)
  456. {
  457. MessageBox.Show("筛查题目加载失败\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  458. return;
  459. }
  460. if (filterQuestionaire.Count == 0)
  461. {
  462. MessageBox.Show("筛查题目加载失败\r\n数据库中无有效问卷", "错误");
  463. return;
  464. }
  465. if (flagEvaluationWithoutFilter)
  466. {
  467. MessageBox.Show("发现该病例一周内未进行初筛,评估过程中将自动进行初筛。","提示");
  468. }
  469. else
  470. {
  471. MessageBox.Show("发现该病例于"+ filterReportForEvaluation.r_time.ToString("yyyy-MM-dd HH:mm:ss") +"进行过初筛,评估过程中将使用此初筛结果。", "提示");
  472. }
  473. currentFilterCount = 1;
  474. currentEvaluationCount = 1;
  475. evaluationQuestionaire.Add(filterQuestionaire[currentFilterCount - 1]);
  476. evaluationUserSelection.Add(filterUserSelection[currentFilterCount - 1]);
  477. tabEvaluation.SelectedIndex += 1;
  478. checkStatusEvaluation();
  479. }
  480. /// <summary>
  481. /// 加载currentIndex的评估题目功能
  482. /// </summary>
  483. /// <param name="currentIndex">需要显示题目的题号</param>
  484. private void loadQuestionViewEvaluation(int currentIndex)
  485. {
  486. labelQuestionNumberofCurrentQuestion.Content = currentIndex.ToString();
  487. labelEvaluationQuestionTitle.Content = evaluationQuestionaire[currentIndex - 1].question.q_title;
  488. textBlockEvaluationQuetionContent.Text = evaluationQuestionaire[currentIndex - 1].question.q_content;
  489. int countOptions = evaluationQuestionaire[currentIndex - 1].answers.Count;
  490. gridEvaluationSelection.Children.Clear();
  491. for (int i = 0; i < countOptions; ++i)
  492. {
  493. RadioButton oneOption = new RadioButton();
  494. oneOption.Height = 30;
  495. oneOption.HorizontalAlignment = HorizontalAlignment.Left;
  496. oneOption.VerticalAlignment = VerticalAlignment.Top;
  497. oneOption.Margin = new Thickness(i / 5 * 200, i % 5 * 40, 0, 0);
  498. if (evaluationUserSelection[currentIndex - 1].a_id == evaluationQuestionaire[currentIndex - 1].answers[i].a_id)
  499. oneOption.IsChecked = true;
  500. else
  501. oneOption.IsChecked = false;
  502. oneOption.Content = evaluationQuestionaire[currentIndex - 1].answers[i].a_content;
  503. oneOption.Checked += radioButtonEvaluation_Checked;
  504. oneOption.GroupName = "evaluationOption";
  505. oneOption.FontSize = 18;
  506. oneOption.Name = "rbe" + evaluationQuestionaire[currentIndex - 1].answers[i].a_id.ToString();
  507. gridEvaluationSelection.Children.Add(oneOption);
  508. }
  509. }
  510. /// <summary>
  511. /// 检查当前答题状态,判断是否需要跳过该题和控制加载题目的功能,能够维护userselection和questionaire
  512. /// </summary>
  513. private void checkStatusEvaluation()
  514. {
  515. if(!flagEvaluationWithoutFilter && evaluationQuestionaire[currentEvaluationCount-1].question.q_type == 1)
  516. {
  517. //有预加载的筛查报告且当前问题是一道筛查题
  518. Answer aTemp = SQLiteModel.getAnswerById(filterUserSelection[currentFilterCount - 1].a_id);
  519. if (aTemp == null || aTemp.next_q_id == 0)
  520. {
  521. if(currentFilterCount == filterQuestionaire.Count)
  522. {
  523. //当前所有题目都已经做完了
  524. buttonEvaluationNext.IsEnabled = false;
  525. bool allQuestionAreSeleceted = true;
  526. foreach (UserSelection us in evaluationUserSelection)
  527. {
  528. if (us.a_id == 0)
  529. allQuestionAreSeleceted = false;
  530. }
  531. //经过检查可以提交
  532. buttonSubmitEvaluation.IsEnabled = allQuestionAreSeleceted;
  533. }
  534. else
  535. {
  536. //还有剩下的筛选题没有过
  537. QuestionAnswerPair qaPairEvaluation = filterQuestionaire[currentFilterCount];
  538. //当前元素后面的题目和选项都清空
  539. for (int i = evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i)
  540. {
  541. evaluationQuestionaire.RemoveAt(i);
  542. evaluationUserSelection.RemoveAt(i);
  543. }
  544. evaluationQuestionaire.Add(qaPairEvaluation);
  545. evaluationUserSelection.Add(filterUserSelection[currentFilterCount]);
  546. //再刷新一次
  547. ++currentFilterCount;
  548. ++currentEvaluationCount;
  549. checkStatusEvaluation();
  550. }
  551. }
  552. else
  553. {
  554. //否则还有评估题没做
  555. Question aEvaluationQuestion = SQLiteModel.getQuestionById(aTemp.next_q_id);
  556. List<Answer> answersToTheEvaluation = SQLiteModel.getAnswersByQid(aEvaluationQuestion.q_id);
  557. QuestionAnswerPair qaPairEvaluation = new QuestionAnswerPair(aEvaluationQuestion, answersToTheEvaluation);
  558. //当前元素后面的题目和选项都清空
  559. for(int i= evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i)
  560. {
  561. evaluationQuestionaire.RemoveAt(i);
  562. evaluationUserSelection.RemoveAt(i);
  563. }
  564. evaluationQuestionaire.Add(qaPairEvaluation);
  565. evaluationUserSelection.Add(new UserSelection(aEvaluationQuestion.q_id, 0));
  566. //再刷新一次
  567. ++currentEvaluationCount;
  568. checkStatusEvaluation();
  569. }
  570. }
  571. else
  572. {
  573. //其他情况:没有预加载的筛选题或者有预加载的筛选题但是是一道评估题
  574. loadQuestionViewEvaluation(currentEvaluationCount);
  575. buttonEvaluationNext.IsEnabled = false;
  576. buttonSubmitEvaluation.IsEnabled = false;
  577. }
  578. }
  579. /// <summary>
  580. /// 评估单选选项被选中的触发事件,主要是修改内存中的选择和判断下一题及提交按钮是否可用
  581. /// </summary>
  582. /// <param name="sender">默认</param>
  583. /// <param name="e">默认</param>
  584. private void radioButtonEvaluation_Checked(object sender, RoutedEventArgs e)
  585. {
  586. //首先,记录该选择
  587. RadioButton oneSelection = (RadioButton)sender;
  588. evaluationUserSelection[currentEvaluationCount - 1].a_id = Convert.ToInt32(oneSelection.Name.Substring(3));
  589. if (flagEvaluationWithoutFilter)
  590. {
  591. filterUserSelection[currentFilterCount - 1].a_id = Convert.ToInt32(oneSelection.Name.Substring(3));
  592. }
  593. //MessageBox.Show(filterUserSelection[currentFilterCount - 1].a_id.ToString());
  594. Answer oneAnswer = SQLiteModel.getAnswerById(evaluationUserSelection[currentEvaluationCount - 1].a_id);
  595. if(currentFilterCount == filterQuestionaire.Count && oneAnswer.next_q_id == 0)
  596. {
  597. //后面没有题目了,可以提交
  598. buttonEvaluationNext.IsEnabled = false;
  599. bool allQuestionAreSeleceted = true;
  600. foreach (UserSelection us in evaluationUserSelection)
  601. {
  602. if (us.a_id == 0)
  603. allQuestionAreSeleceted = false;
  604. }
  605. //经过检查可以提交
  606. buttonSubmitEvaluation.IsEnabled = allQuestionAreSeleceted;
  607. }
  608. else
  609. {
  610. //否则可以做下一题
  611. buttonEvaluationNext.IsEnabled = true;
  612. buttonSubmitEvaluation.IsEnabled = false;
  613. }
  614. }
  615. /// <summary>
  616. /// (未实现)评估过程中点击上一题的触发事件
  617. /// </summary>
  618. /// <param name="sender">默认</param>
  619. /// <param name="e">默认</param>
  620. private void buttonEvaluationPrevious_Click(object sender, RoutedEventArgs e)
  621. {
  622. }
  623. /// <summary>
  624. /// 点击评估页下一题后触发的事件,主要是判断接下来加载哪一题
  625. /// </summary>
  626. /// <param name="sender">默认</param>
  627. /// <param name="e">默认</param>
  628. private void buttonEvaluationNext_Click(object sender, RoutedEventArgs e)
  629. {
  630. //先看看后面有没有进退阶题目了
  631. Answer oneAnswer = SQLiteModel.getAnswerById(evaluationUserSelection[currentEvaluationCount - 1].a_id);
  632. if(oneAnswer.next_q_id!= 0)
  633. {
  634. //还有后续题目
  635. Question aEvaluationQuestion = SQLiteModel.getQuestionById(oneAnswer.next_q_id);
  636. List<Answer> answersToTheEvaluation = SQLiteModel.getAnswersByQid(aEvaluationQuestion.q_id);
  637. QuestionAnswerPair qaPairEvaluation = new QuestionAnswerPair(aEvaluationQuestion, answersToTheEvaluation);
  638. //当前元素后面的题目和选项都清空
  639. for (int i = evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i)
  640. {
  641. evaluationQuestionaire.RemoveAt(i);
  642. evaluationUserSelection.RemoveAt(i);
  643. }
  644. evaluationQuestionaire.Add(qaPairEvaluation);
  645. evaluationUserSelection.Add(new UserSelection(aEvaluationQuestion.q_id, 0));
  646. //再刷新一次
  647. ++currentEvaluationCount;
  648. checkStatusEvaluation();
  649. }
  650. else
  651. {
  652. //否则跳到下一个筛选题上面
  653. QuestionAnswerPair qaPairEvaluation = filterQuestionaire[currentFilterCount];
  654. //当前元素后面的题目和选项都清空
  655. for (int i = evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i)
  656. {
  657. evaluationQuestionaire.RemoveAt(i);
  658. evaluationUserSelection.RemoveAt(i);
  659. }
  660. evaluationQuestionaire.Add(qaPairEvaluation);
  661. evaluationUserSelection.Add(filterUserSelection[currentFilterCount]);
  662. //再刷新一次
  663. ++currentFilterCount;
  664. ++currentEvaluationCount;
  665. checkStatusEvaluation();
  666. }
  667. }
  668. /// <summary>
  669. /// 点击评估页提交后触发的事件
  670. /// </summary>
  671. /// <param name="sender">默认</param>
  672. /// <param name="e">默认</param>
  673. private void buttonSubmitEvaluation_Click(object sender, RoutedEventArgs e)
  674. {
  675. int inserted_r_id;
  676. resultsFilter = JsonMapper.ToJson(filterUserSelection);
  677. resultsEvaluation = JsonMapper.ToJson(evaluationUserSelection);
  678. try
  679. {
  680. if (flagEvaluationWithoutFilter)
  681. {
  682. int tempRId = SQLiteModel.insertRecord(1, evaluationPatient.p_id, loginDoctor.id, 0, DateTime.Now, 0, resultsFilter);
  683. SQLiteModel.UpdatePatientDataWithLastDate(evaluationPatient.p_id, "p_last_filter_time", DateTime.Now);
  684. filterReportForEvaluation.r_id = tempRId;
  685. }
  686. inserted_r_id = SQLiteModel.insertRecord(2, evaluationPatient.p_id, loginDoctor.id, filterReportForEvaluation.r_id, DateTime.Now, 0, resultsEvaluation);
  687. }
  688. catch (Exception err)
  689. {
  690. MessageBox.Show("储存筛查报告错误\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  691. return;
  692. }
  693. MessageBoxResult dr = MessageBox.Show("保存成功,是否生成报告?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
  694. if (dr == MessageBoxResult.OK)
  695. {
  696. Record targetRecord = SQLiteModel.getRecordByID(inserted_r_id);
  697. SQLiteModel.plusOneCountOnRecordByRid(inserted_r_id);
  698. ReportGenerater.generateReport(2, evaluationPatient, loginDoctor, targetRecord, cfg.organization_name);
  699. tabEvaluation.SelectedIndex = 2;
  700. }
  701. else
  702. {
  703. buttonAbortEvaluation_Click(sender, e);
  704. }
  705. return;
  706. }
  707. /// <summary>
  708. /// 点击评估页中止评估后触发的事件
  709. /// </summary>
  710. /// <param name="sender">默认</param>
  711. /// <param name="e">默认</param>
  712. private void buttonAbortEvaluation_Click(object sender, RoutedEventArgs e)
  713. {
  714. //清理相关变量
  715. filterQuestionaire.Clear();
  716. filterUserSelection.Clear();
  717. evaluationQuestionaire.Clear();
  718. evaluationUserSelection.Clear();
  719. flagEvaluationWithoutFilter = true;
  720. filterReportForEvaluation = null;
  721. evaluationPatient = null;
  722. resultsFilter = "";
  723. resultsEvaluation = "";
  724. currentFilterCount = 0;
  725. currentEvaluationCount = 0;
  726. //buttonFilterPrevious.IsEnabled = false;
  727. buttonEvaluationNext.IsEnabled = false;
  728. buttonSubmitEvaluation.IsEnabled = false;
  729. tabEvaluation.SelectedIndex = 0;
  730. }
  731. /// <summary>
  732. /// 返回至选择用户页
  733. /// </summary>
  734. /// <param name="sender">默认</param>
  735. /// <param name="e">默认</param>
  736. private void buttonEvaluationBackToSelectUser_Click(object sender, RoutedEventArgs e)
  737. {
  738. buttonAbortEvaluation_Click(sender, e);
  739. }
  740. /// <summary>
  741. /// 返回至选择首页
  742. /// </summary>
  743. /// <param name="sender">默认</param>
  744. /// <param name="e">默认</param>
  745. private void buttonEvaluationBackToHome_Click(object sender, RoutedEventArgs e)
  746. {
  747. buttonAbortEvaluation_Click(sender, e);
  748. tabControlGeneral.SelectedIndex = 0;
  749. }
  750. #endregion
  751. #region 历史记录
  752. /// <summary>
  753. /// 点击选择病例查看其历史记录后触发的事件
  754. /// </summary>
  755. /// <param name="sender">默认</param>
  756. /// <param name="e">默认</param>
  757. public void buttonHistorySelectPatient_Click(object sender, RoutedEventArgs e)
  758. {
  759. try
  760. {
  761. var target = (DataRowView)this.selectUserHistory.dataGrid.SelectedItem;
  762. historyPatient = SQLiteModel.getPatientById(Convert.ToString(target["p_id"]));
  763. recordsFromOnePatient = SQLiteModel.getRecordsByPid(Convert.ToInt32(target["p_id"]));
  764. }
  765. catch (Exception err)
  766. {
  767. MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "警告");
  768. return;
  769. }
  770. if (recordsFromOnePatient == null || historyPatient == null)
  771. {
  772. MessageBox.Show("数据库加载异常", "错误");
  773. return;
  774. }
  775. try
  776. {
  777. bindingRecords = new BindingList<Record>(recordsFromOnePatient);
  778. dataGridRecords.ItemsSource = bindingRecords;
  779. }
  780. catch(Exception err)
  781. {
  782. MessageBox.Show("数据库加载异常\r\n调试信息:\r\n"+err.StackTrace, "错误");
  783. return;
  784. }
  785. tabHistoryRecords.SelectedIndex = 1;
  786. }
  787. private void buttonHistoryBackToSelectUser_Click(object sender, RoutedEventArgs e)
  788. {
  789. recordsFromOnePatient.Clear();
  790. tabHistoryRecords.SelectedIndex = 0;
  791. }
  792. private void buttonHistoryBackToHome_Click(object sender, RoutedEventArgs e)
  793. {
  794. recordsFromOnePatient.Clear();
  795. tabHistoryRecords.SelectedIndex = 0;
  796. tabControlGeneral.SelectedIndex = 0;
  797. }
  798. private void buttonRegenerateReport_Click(object sender, RoutedEventArgs e)
  799. {
  800. Record targetRecord;
  801. try
  802. {
  803. var target = this.dataGridRecords.SelectedItem as Record;
  804. targetRecord = SQLiteModel.getRecordByID(Convert.ToInt32(target.r_id));
  805. }
  806. catch (Exception err)
  807. {
  808. MessageBox.Show("请选择一个记录进行生成\r\n" + err.StackTrace, "提示");
  809. return;
  810. }
  811. if (targetRecord == null)
  812. {
  813. MessageBox.Show("数据库加载异常", "错误");
  814. return;
  815. }
  816. try
  817. {
  818. ReportGenerater.generateReport(targetRecord.r_type, historyPatient, loginDoctor, targetRecord, cfg.organization_name);
  819. SQLiteModel.plusOneCountOnRecordByRid(targetRecord.r_id);
  820. }
  821. catch(Exception err)
  822. {
  823. MessageBox.Show("报告生成异常\r\n调试信息:\r\n" + err.StackTrace, "错误");
  824. return;
  825. }
  826. tabHistoryRecords.SelectedIndex = 2;
  827. }
  828. private void dataGridRecords_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  829. {
  830. buttonRegenerateReport_Click(sender, e);
  831. }
  832. #endregion
  833. #region 系统设置
  834. //系统设置
  835. //进入系统设置前主任级别用户的身份验证
  836. async private void tabControlGeneral_SelectionChanged(object sender, SelectionChangedEventArgs e)
  837. {
  838. //System.Console.WriteLine(Convert.ToString(tabControlGeneral.SelectedIndex));
  839. if (e.Source is TabControl)
  840. {
  841. //系统设置页验证
  842. if (tabitemDoctorSetting.IsSelected)
  843. {
  844. DateTime now = DateTime.Now;
  845. if (lastSettingLogin != null && (now - lastSettingLogin).Minutes <= 10)
  846. {
  847. //如果上次有登陆而且登陆时间在10分钟以内,则免登陆
  848. return;
  849. }
  850. bool dialogLoop = true;
  851. bool wrongPassword = false;
  852. string description;
  853. int x = 1;
  854. while (dialogLoop)
  855. {
  856. x++;
  857. if (wrongPassword)
  858. {
  859. description = "用户名或密码不正确,请重新输入账号和密码进入系统设置";
  860. }
  861. else
  862. {
  863. description = "请输入账号和密码进入系统设置";
  864. }
  865. LoginDialogData loginDialogData;
  866. loginDialogData = await this.ShowLoginAsync
  867. (
  868. "输入科室主任级别账号密码以继续..." + Convert.ToString(x),
  869. description,
  870. new LoginDialogSettings
  871. {
  872. ColorScheme = MetroDialogColorScheme.Accented,
  873. UsernameWatermark = "用户名",
  874. PasswordWatermark = "密码",
  875. NegativeButtonVisibility = Visibility.Visible
  876. }
  877. );
  878. if (loginDialogData == null)
  879. {
  880. dialogLoop = false;
  881. tabControlGeneral.SelectedIndex = 0;
  882. return;
  883. //break;
  884. }
  885. //调用数据库验证
  886. string doctorName = loginDialogData.Username;
  887. string doctorPassword = loginDialogData.Password;
  888. string doctorPWD = Toolkits.ComputeHash.GetMD5(doctorPassword);
  889. doctor loginDirector = SQLiteModel.directorLogin(doctorName, doctorPWD);
  890. if (loginDirector == null)
  891. {
  892. //MessageBox.Show("admin");
  893. wrongPassword = true;
  894. dialogLoop = true;
  895. }
  896. else
  897. {
  898. lastSettingLogin = DateTime.Now;
  899. dialogLoop = false;
  900. return;
  901. //break;
  902. }
  903. }
  904. }
  905. //高级系统设置验证页
  906. //if (tabitemOEMSetting.IsSelected)
  907. }
  908. }
  909. private void tabControlSystemSetting_SelectionChanged(object sender, SelectionChangedEventArgs e)
  910. {
  911. lastSettingLogin = DateTime.Now;
  912. }
  913. #region 医师管理
  914. //系统设置--医师管理
  915. private void LoadDoctorDataGrid(object sender, RoutedEventArgs e)
  916. {
  917. LoadDoctorDataGrid();
  918. }
  919. public void LoadDoctorDataGrid()
  920. {
  921. //连接字符串
  922. string Connstr = Toolkits.Constants.Connstr;
  923. //连接对象
  924. System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(Connstr);
  925. //Sql语句
  926. string selectCmd = "SELECT * FROM Doctor WHERE delete_flag=0 AND name != '" + Constants.adminUsername + "' LIMIT 100";
  927. con.Open();
  928. da = new System.Data.SQLite.SQLiteDataAdapter(selectCmd, con);
  929. ds = new DataSet();
  930. da.Fill(ds);
  931. dataGridDoctor.ItemsSource = ds.Tables[0].DefaultView;
  932. con.Close();
  933. }
  934. //新增医师
  935. private void buttonAddDoctor_Click(object sender, RoutedEventArgs e)
  936. {
  937. AddDoctor a_new_doctor = new AddDoctor(this);
  938. a_new_doctor.Show();
  939. }
  940. //修改医师
  941. private void buttonChangeDoctor_Click(object sender, RoutedEventArgs e)
  942. {
  943. try
  944. {
  945. var target = (DataRowView)this.dataGridDoctor.SelectedItem;
  946. //MessageBox.Show(target["id"].ToString());
  947. ModifyDoctor modify_one = new ModifyDoctor(this, target["id"].ToString());
  948. modify_one.Show();
  949. }
  950. catch (Exception err)
  951. {
  952. this.ShowMessageAsync("警告", "请选择一个医生进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace);
  953. }
  954. }
  955. //双击表格触发修改医师的方法
  956. private void dataGridDoctor_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  957. {
  958. buttonChangeDoctor_Click(this, e);
  959. }
  960. //修改医师密码
  961. private void buttonChangeDoctorPWD_Click(object sender, RoutedEventArgs e)
  962. {
  963. try
  964. {
  965. var target = (DataRowView)this.dataGridDoctor.SelectedItem;
  966. //MessageBox.Show(target["id"].ToString());
  967. ModifyDoctorPWD modify_one = new ModifyDoctorPWD(this, target["id"].ToString());
  968. modify_one.Show();
  969. }
  970. catch (Exception err)
  971. {
  972. this.ShowMessageAsync("警告", "请选择一个医生进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace);
  973. }
  974. }
  975. //删除医师
  976. private async void buttonDeleteDoctor_Click(object sender, RoutedEventArgs e)
  977. {
  978. try
  979. {
  980. var target = (DataRowView)this.dataGridDoctor.SelectedItem;
  981. if (target == null)
  982. {
  983. await this.ShowMessageAsync("提示", "请选择一个医生进行删除");
  984. return;
  985. }
  986. MessageDialogResult clickresult = await this.ShowMessageAsync("提示", "确认删除该医生信息吗?", MessageDialogStyle.AffirmativeAndNegative);
  987. if (clickresult == MessageDialogResult.Affirmative)//确认
  988. {
  989. int status = SQLite.SQLiteModel.DeleteDoctorItem(target["id"].ToString());
  990. if (status > 0)
  991. {
  992. await this.ShowMessageAsync("提示", "删除成功!");
  993. }
  994. else
  995. {
  996. await this.ShowMessageAsync("警告", "目标已被删除");
  997. }
  998. }
  999. else//取消
  1000. {
  1001. return;
  1002. }
  1003. }
  1004. catch (Exception err)
  1005. {
  1006. await this.ShowMessageAsync("警告", "请选择一个医生进行删除!\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace);
  1007. }
  1008. LoadDoctorDataGrid();
  1009. }
  1010. //筛选医师
  1011. private void buttonFindDoctor_Click(object sender, RoutedEventArgs e)
  1012. {
  1013. try
  1014. {
  1015. //连接字符串
  1016. string Connstr = "Data Source=" + System.Environment.CurrentDirectory + "\\Junde.db3"; ;
  1017. //连接对象
  1018. System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(Connstr);
  1019. string namelike = textBoxFindDoctor.Text;
  1020. //MessageBox.Show(namelike);
  1021. //Sql语句
  1022. string selectCmd = "SELECT * FROM Doctor WHERE NAME LIKE \'%" + namelike + "%\' AND delete_flag=0 LIMIT 100";
  1023. con.Open();
  1024. System.Data.SQLite.SQLiteDataAdapter da_1 = new System.Data.SQLite.SQLiteDataAdapter(selectCmd, con);
  1025. DataSet ds_1 = new DataSet();
  1026. da_1.Fill(ds_1);
  1027. dataGridDoctor.ItemsSource = ds_1.Tables[0].DefaultView;
  1028. con.Close();
  1029. }
  1030. catch (Exception err)
  1031. {
  1032. MessageBox.Show("数据库错误.\r\n调试信息:" + err.Message, "错误");
  1033. }
  1034. }
  1035. #endregion
  1036. #region 常用语编辑
  1037. /*
  1038. //系统设置--常用语编辑
  1039. private void commlangGrid_Loaded(object sender, RoutedEventArgs e)
  1040. {
  1041. LoadCommlangDataGrid();
  1042. }
  1043. public void LoadCommlangDataGrid()
  1044. {
  1045. //连接字符串
  1046. string Connstr = "Data Source=" + System.Environment.CurrentDirectory + "\\Junde.db3"; ;
  1047. //连接对象
  1048. System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(Connstr);
  1049. //Sql语句
  1050. string selectCmd = "SELECT * FROM CommonWords LIMIT 100";
  1051. con.Open();
  1052. da = new System.Data.SQLite.SQLiteDataAdapter(selectCmd, con);
  1053. ds = new DataSet();
  1054. da.Fill(ds);
  1055. dataGridCommlang.ItemsSource = ds.Tables[0].DefaultView;
  1056. con.Close();
  1057. }
  1058. //新增常用语
  1059. private void buttonAddCommlang_Click(object sender, RoutedEventArgs e)
  1060. {
  1061. AddCommonWords a_new_commonword = new AddCommonWords(this);
  1062. a_new_commonword.Show();
  1063. }
  1064. //编辑常用语
  1065. private void buttonChangeCommlang_Click(object sender, RoutedEventArgs e)
  1066. {
  1067. try
  1068. {
  1069. var target = (DataRowView)this.dataGridCommlang.SelectedItem;
  1070. //MessageBox.Show(target["id"].ToString());
  1071. ModifyCommonWords modify_one = new ModifyCommonWords(this, target["id"].ToString());
  1072. modify_one.Show();
  1073. }
  1074. catch (Exception err)
  1075. {
  1076. this.ShowMessageAsync("警告", "请选择一个常用语进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace);
  1077. }
  1078. }
  1079. //删除常用语
  1080. private async void buttonDeleteCommlang_Click(object sender, RoutedEventArgs e)
  1081. {
  1082. try
  1083. {
  1084. var target = (DataRowView)this.dataGridCommlang.SelectedItem;
  1085. if (target == null)
  1086. {
  1087. await this.ShowMessageAsync("提示", "请选择一个常用语进行删除");
  1088. return;
  1089. }
  1090. MessageDialogResult clickresult = await this.ShowMessageAsync("提示", "确认删除该常用语吗?", MessageDialogStyle.AffirmativeAndNegative);
  1091. if (clickresult == MessageDialogResult.Affirmative)//确认
  1092. {
  1093. int status = SQLite.SQLiteModel.DeleteCommonWordsItem(target["id"].ToString());
  1094. if (status > 0)
  1095. {
  1096. await this.ShowMessageAsync("提示", "删除成功!");
  1097. }
  1098. else
  1099. {
  1100. await this.ShowMessageAsync("警告", "目标已被删除");
  1101. }
  1102. }
  1103. else//取消
  1104. {
  1105. return;
  1106. }
  1107. }
  1108. catch (Exception err)
  1109. {
  1110. await this.ShowMessageAsync("警告", "请选择一个常用语进行删除!\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace);
  1111. }
  1112. LoadCommlangDataGrid();
  1113. }
  1114. //双击表格触发修改常用语的功能
  1115. private void dataGridCommlang_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  1116. {
  1117. buttonChangeCommlang_Click(sender, e);
  1118. }
  1119. //*/
  1120. #endregion
  1121. #region 软件激活管理
  1122. //重新激活程序
  1123. private void buttonModifyRegisterInfo_Click(object sender, RoutedEventArgs e)
  1124. {
  1125. SmallDialogs.RegisterCode rc = new SmallDialogs.RegisterCode(this, cfg, false);
  1126. rc.ShowDialog();
  1127. }
  1128. //保存其他医生级别的设置,如显示血压的单位
  1129. private void buttonSaveDocSetting_Click(object sender, RoutedEventArgs e)
  1130. {
  1131. string bp_unit_temp = "1";
  1132. if (radioButtonBP_kpa.IsChecked == true)
  1133. {
  1134. bp_unit_temp = "2";
  1135. }
  1136. try
  1137. {
  1138. SQLite.SQLiteModel.UpdateDocSetting(bp_unit_temp);
  1139. }
  1140. catch (Exception err)
  1141. {
  1142. this.ShowMessageAsync("错误", "数据库读写失败,调试信息:\r\n" + err.StackTrace);
  1143. }
  1144. cfg.refresh();
  1145. this.ShowMessageAsync("提示", "修改成功");
  1146. }
  1147. /// <summary>
  1148. /// buttonOptmizeDatabase_Click:点击优化数据库的方法,把已经被删除的数据进行彻底清除
  1149. /// </summary>
  1150. /// <param name="sender">默认</param>
  1151. /// <param name="e">默认</param>
  1152. private void buttonOptmizeDatabase_Click(object sender, RoutedEventArgs e)
  1153. {
  1154. try
  1155. {
  1156. //获取标记为删除的病人记录
  1157. List<string> ids_to_be_deleted = SQLite.SQLiteModel.getDeletedPatients();
  1158. //确实删除这些病人记录
  1159. SQLite.SQLiteModel.realDeleteRecords();
  1160. //确实删除这些病人所含有的检查记录
  1161. foreach(string each_line in ids_to_be_deleted)
  1162. {
  1163. //SQLite.SQLiteModel.DeleteRecordItem(each_line);
  1164. }
  1165. MessageBox.Show("操作完成", "信息");
  1166. }
  1167. catch (Exception)
  1168. {
  1169. MessageBox.Show("数据库异常", "错误");
  1170. }
  1171. }
  1172. /// <summary>
  1173. /// buttonDeleteAllPdfReport_Click:点击删除某一目录下所有文件的方法
  1174. /// </summary>
  1175. /// <param name="sender">默认</param>
  1176. /// <param name="e">默认</param>
  1177. private void buttonDeleteFiles_Click(object sender, RoutedEventArgs e)
  1178. {
  1179. string target_path = "";
  1180. if (((Button)sender).Equals(buttonDeleteAllPdfReport))
  1181. {
  1182. target_path = Constants.reportPath;
  1183. }else if (((Button)sender).Equals(buttonDeleteAllCSVWave))
  1184. {
  1185. target_path = Constants.exportWavePath;
  1186. }
  1187. try
  1188. {
  1189. DirectoryInfo dir = new DirectoryInfo(target_path);
  1190. FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
  1191. foreach (FileSystemInfo i in fileinfo)
  1192. {
  1193. if (i is DirectoryInfo) //判断是否文件夹
  1194. {
  1195. DirectoryInfo subdir = new DirectoryInfo(i.FullName);
  1196. subdir.Delete(true); //删除子目录和文件
  1197. }
  1198. else
  1199. {
  1200. File.Delete(i.FullName); //删除指定文件
  1201. }
  1202. }
  1203. MessageBox.Show("操作完成", "信息");
  1204. }
  1205. catch (Exception)
  1206. {
  1207. MessageBox.Show("文件系统异常", "错误");
  1208. }
  1209. }
  1210. #endregion
  1211. #endregion
  1212. private void buttonHomePageMeasureFunction_Click(object sender, RoutedEventArgs e)
  1213. {
  1214. Patient onePatient = SQLiteModel.getPatientById("1");
  1215. Record oneRecord = SQLiteModel.getRecordByID(7);
  1216. ReportGenerater.generateReport(2, onePatient, loginDoctor, oneRecord, cfg.organization_name);
  1217. }
  1218. private void buttonHomePageHistoryRecord_Click(object sender, RoutedEventArgs e)
  1219. {
  1220. string filename = Constants.reportPath + "\\" + "8" + ".pdf";
  1221. System.Diagnostics.Process.Start(filename);
  1222. }
  1223. }
  1224. }