MainWindow.xaml.cs 59 KB

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