MainWindow.xaml.cs 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826
  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. using System.Windows.Media.Imaging;
  15. using System.Windows.Documents;
  16. using System.Windows.Media;
  17. using WpfTest1.ComAgent;
  18. using System.Collections;
  19. using Com = WpfTest1.ComAgent.ComAgent;
  20. using System.Diagnostics;
  21. namespace WpfTest1
  22. {
  23. /// <summary>
  24. /// MainWindow.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class MainWindow : MetroWindow
  27. {
  28. #region 系统基本参数
  29. System.Data.SQLite.SQLiteDataAdapter daHistoryRecord; //选择记录页面查询记录条目的数据集容器
  30. public doctor loginDoctor = null; //所登录的医师
  31. DataSet ds; //其他界面的DataSet
  32. System.Data.SQLite.SQLiteDataAdapter da; //其他界面的DataAdapter
  33. //double highBp; //BP界面高压
  34. //double lowBp; //BP界面低压
  35. DateTime lastSettingLogin; //上一次在系统设置界面登录的时间
  36. public Toolkits.Config cfg; //从数据库取配置的类
  37. DogOperator dop = new DogOperator(Constants.registerPid, Constants.registerUid);
  38. Patient filterPatient;
  39. Patient evaluationPatient;
  40. Patient historyPatient;
  41. Record filterReportForEvaluation;
  42. bool flagEvaluationWithoutFilter = true;
  43. List<QuestionAnswerPair> filterQuestionaire = new List<QuestionAnswerPair>();
  44. List<QuestionAnswerPair> evaluationQuestionaire = new List<QuestionAnswerPair>();
  45. List<UserSelection> filterUserSelection = new List<UserSelection>();
  46. List<UserSelection> evaluationUserSelection = new List<UserSelection>();
  47. string resultsFilter;
  48. string resultsEvaluation;
  49. int currentFilterCount = 0;
  50. int currentEvaluationCount = 0;
  51. List<Record> recordsFromOnePatient;
  52. BindingList<Record> bindingRecords;
  53. Dictionary<string, int> mapKeyToDigit = new Dictionary<string, int>();
  54. Treatment targetTreatment = null;
  55. List <TreatmentCustomItem> treatmentCustomModeList;
  56. //DataTable treatmentCustomDataTable;
  57. #endregion
  58. public MainWindow()
  59. {
  60. InitializeComponent();
  61. //加载配置
  62. cfg = new Toolkits.Config();
  63. //绑定三个selectUser的父类
  64. //selectUserMeasure.setMainWindow(this);
  65. selectUserPatientManagent.setMainWindow(this);
  66. selectUserfilter.setMainWindow(this);
  67. selectUserevaluation.setMainWindow(this);
  68. selectUserHistory.setMainWindow(this);
  69. treatmentPlanPage.setMainWindow(this);
  70. textBoxOrganizationName.Text = cfg.organization_name;
  71. }
  72. #region 初始化与系统调用部分
  73. //初始化全部组件后需要先输入医生密码才能进入
  74. private void mainWndGrid_Loaded(object sender, RoutedEventArgs e)
  75. {
  76. //Application.Current.Dispatcher.UnhandledException += Dispatcher_UnhandledException;
  77. labelHomepageCversion.Content = "编译日期:" + Toolkits.Constants.compileDate;
  78. labelSoftwareName.Content = String.Format("欢迎使用{0}", Constants.softwareName);
  79. //之后测试登录
  80. SmallDialogs.LoginWindow lw = new SmallDialogs.LoginWindow(this);
  81. lw.ShowDialog();
  82. if (loginDoctor == null)
  83. {
  84. this.Close();
  85. }
  86. bool registerFlag = dop.checkSoftwareRegister();
  87. if (!registerFlag && Constants.productionEnvironment)
  88. {
  89. MessageBox.Show("未找到硬件授权Key,请确认插入后重试", "错误");
  90. this.Close();
  91. }
  92. loadUSBDogStatus();
  93. string datestr = "2050-12-31 00:00:00";
  94. DateTime dtStandard = DateTime.Parse(datestr);
  95. DateTime now = DateTime.Now;
  96. if(DateTime.Compare(dtStandard, now) < 0)
  97. {
  98. MessageBox.Show("系统数据异常,请联系管理员", "错误");
  99. this.Close();
  100. }
  101. //显示医生姓名
  102. if (loginDoctor != null)
  103. {
  104. loginedDoctorName.Content = "欢迎您, " + loginDoctor.name;
  105. return;
  106. }
  107. loadQuestionaire(filterQuestionaire, "filter");
  108. loadQuestionaire(evaluationQuestionaire, "evaluation");
  109. }
  110. private void Dispatcher_UnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
  111. {
  112. Debug.WriteLine(e.ToString());
  113. }
  114. private void loadUSBDogStatus()
  115. {
  116. int[] timesLimit = dop.getTimesCount();
  117. if(timesLimit[0] != -1 && timesLimit[1]!= -1)
  118. {
  119. labelHomepageUSBDogStatus.Content = String.Format("系统Key已授权,当前Key可使用{0}次,已使用{1}次", timesLimit[0], timesLimit[1]);
  120. labelHomepageUSBDogStatus.Visibility = Visibility.Visible;
  121. }
  122. else
  123. {
  124. labelHomepageUSBDogStatus.Visibility = Visibility.Hidden;
  125. }
  126. }
  127. private void loadQuestionaire(List<QuestionAnswerPair> oneQuestionaire, string type = "filter")
  128. {
  129. oneQuestionaire.Clear();
  130. List<Question> questions = SQLite.SQLiteModel.getQuestions(type);
  131. foreach (Question oneQuestion in questions)
  132. {
  133. List<Answer> answers = SQLite.SQLiteModel.getAnswersByQid(oneQuestion.q_id);
  134. QuestionAnswerPair temp = new QuestionAnswerPair(oneQuestion, answers);
  135. oneQuestionaire.Add(temp);
  136. }
  137. }
  138. /// <summary>
  139. /// 筛查或评估流程页面识别快捷键的操作
  140. /// </summary>
  141. /// <param name="sender">默认</param>
  142. /// <param name="e">默认</param>
  143. private void processGrid_KeyDown(object sender, KeyEventArgs e)
  144. {
  145. //System.Console.WriteLine(String.Format("KeyDown detected. {0} is detected.", e.Key.ToString()));
  146. if (tabControlGeneral.SelectedIndex == 2 && tabFilter.SelectedIndex == 1)
  147. {
  148. /*//筛查流程中
  149. if (e.Key == Key.N && buttonFilterNext.IsEnabled)
  150. {
  151. buttonFilterNext_Click(sender, (RoutedEventArgs)e);
  152. return;
  153. }
  154. if (e.Key == Key.P && buttonFilterPrevious.IsEnabled)
  155. {
  156. buttonFilterPrevious_Click(sender, (RoutedEventArgs)e);
  157. return;
  158. }
  159. if (e.Key == Key.E)
  160. {
  161. buttonAbortFilter_Click(sender, (RoutedEventArgs)e);
  162. return;
  163. }
  164. if(e.Key == Key.S && buttonSubmitFilter.IsEnabled)
  165. {
  166. buttonSubmitFilter_Click(sender, (RoutedEventArgs)e);
  167. return;
  168. }
  169. if (Constants.keyboardToDigit.ContainsKey(e.Key.ToString()))
  170. {
  171. int numInput = Constants.keyboardToDigit[e.Key.ToString()];
  172. try
  173. {
  174. RadioButton rbTemp = (RadioButton)gridFilterSelection.Children[numInput - 1];
  175. rbTemp.IsChecked = true;
  176. radioButtonFilter_Checked(rbTemp, e);
  177. }
  178. catch (Exception)
  179. {
  180. return;
  181. }
  182. return;
  183. }*/
  184. }
  185. else if(tabControlGeneral.SelectedIndex == 3 && tabEvaluation.SelectedIndex == 1)
  186. {
  187. //评估流程中
  188. if (e.Key == Key.N && buttonEvaluationNext.IsEnabled)
  189. {
  190. buttonEvaluationNext_Click(sender, (RoutedEventArgs)e);
  191. return;
  192. }
  193. if (e.Key == Key.E)
  194. {
  195. buttonAbortEvaluation_Click(sender, (RoutedEventArgs)e);
  196. return;
  197. }
  198. if (e.Key == Key.S && buttonSubmitEvaluation.IsEnabled)
  199. {
  200. buttonSubmitEvaluation_Click(sender, (RoutedEventArgs)e);
  201. return;
  202. }
  203. if (Constants.keyboardToDigit.ContainsKey(e.Key.ToString()))
  204. {
  205. int numInput = Constants.keyboardToDigit[e.Key.ToString()];
  206. try
  207. {
  208. RadioButton rbTemp = (RadioButton)gridEvaluationSelection.Children[numInput - 1];
  209. rbTemp.IsChecked = true;
  210. radioButtonEvaluation_Checked(rbTemp, e);
  211. }
  212. catch (Exception)
  213. {
  214. return;
  215. }
  216. }
  217. }
  218. else
  219. {
  220. return;
  221. }
  222. }
  223. #endregion
  224. #region 首页功能
  225. //标题栏快速添加病例的接口
  226. private void Fast_Add_Patient_Button_Click(object sender, RoutedEventArgs e)
  227. {
  228. buttonAddPatient_Click(this, e);
  229. }
  230. //首页--新建用户
  231. private void buttonHomePageAddPatient_Click(object sender, RoutedEventArgs e)
  232. {
  233. buttonAddPatient_Click(this, e);
  234. }
  235. //首页--用户管理
  236. private void buttonHomePagePatientManagent_Click(object sender, RoutedEventArgs e)
  237. {
  238. tabControlGeneral.SelectedIndex = 1;
  239. }
  240. private void buttonHomePageFilterFunction_Click(object sender, RoutedEventArgs e)
  241. {
  242. tabControlGeneral.SelectedIndex = 2;
  243. }
  244. private void buttonHomePageEvaluationFunction_Click(object sender, RoutedEventArgs e)
  245. {
  246. tabControlGeneral.SelectedIndex = 3;
  247. }
  248. //首页--检测报告
  249. private void buttonHomeHistoryRecords_Click(object sender, RoutedEventArgs e)
  250. {
  251. tabControlGeneral.SelectedIndex = 4;
  252. }
  253. //首页--系统设置
  254. private void buttonHomePageSystemSettings_Click(object sender, RoutedEventArgs e)
  255. {
  256. tabControlGeneral.SelectedIndex = 5;
  257. }
  258. //首页--诊疗记录
  259. private void buttonHomePageTreatmentRecords_Click(object sender, RoutedEventArgs e)
  260. {
  261. tabControlGeneral.SelectedIndex = 6;
  262. }
  263. //首页--诊疗记录
  264. private void buttonHomePageTreatmentPlan_Click(object sender, RoutedEventArgs e)
  265. {
  266. tabControlGeneral.SelectedIndex = 7;
  267. }
  268. //关于程序
  269. private void buttonHomePageDataTransfer_Click(object sender, RoutedEventArgs e)
  270. {
  271. SmallDialogs.AboutBox ab = new SmallDialogs.AboutBox();
  272. ab.Show();
  273. }
  274. //首页--操作帮助
  275. private void buttonHomePageHelp_Click(object sender, RoutedEventArgs e)
  276. {
  277. System.Diagnostics.Process.Start(Constants.template_custom + "\\" + "manual.pdf");
  278. //manual.pdf
  279. //Record one_record = SQLiteModel.getRecordByID(24);
  280. //Patient one_patient = SQLiteModel.getPatientById("5");
  281. //ReportGenerater.generateReport_constum(one_record, one_patient,cfg);
  282. }
  283. #endregion
  284. #region 病例管理
  285. //病例管理
  286. //病例管理--病例管理
  287. #region 病例管理--添加病例
  288. //添加病例
  289. private void buttonAddPatient_Click(object sender, RoutedEventArgs e)
  290. {
  291. AddPatient a_new_one = new AddPatient(this);
  292. a_new_one.Show();
  293. //selectUserPatientManagent.LoadDataGrid();
  294. }
  295. #endregion
  296. #region 病例管理--修改病例
  297. //修改病例
  298. public void buttonModifyPatient_Click(object sender, RoutedEventArgs e)
  299. {
  300. try
  301. {
  302. var target = (DataRowView)this.selectUserPatientManagent.dataGrid.SelectedItem;
  303. //MessageBox.Show(target["id"].ToString());
  304. ModifyUser modify_one = new ModifyUser(this, target["p_id"].ToString());
  305. modify_one.Show();
  306. }
  307. catch(Exception err)
  308. {
  309. //this.ShowMessageAsync("警告","请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace );
  310. MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace,"警告");
  311. }
  312. }
  313. #endregion
  314. #region 病例管理--删除病例
  315. //删除病例
  316. private void buttonDeletePatient_Click(object sender, RoutedEventArgs e)
  317. {
  318. try
  319. {
  320. var target = (DataRowView)this.selectUserPatientManagent.dataGrid.SelectedItem;
  321. if(target == null)
  322. {
  323. MessageBox.Show("请选择一个病例进行删除", "提示");
  324. return;
  325. }
  326. MessageBoxResult clickresult = MessageBox.Show("确认删除该病例?", "提示", MessageBoxButton.OKCancel);
  327. if (clickresult == MessageBoxResult.OK)
  328. {
  329. int status = SQLite.SQLiteModel.DeletePatientItem(target["p_id"].ToString());
  330. if (status > 0)
  331. {
  332. MessageBox.Show("删除成功","提示");
  333. }
  334. else
  335. {
  336. MessageBox.Show("已删除", "提示");
  337. }
  338. }
  339. else if (clickresult == MessageBoxResult.Cancel)
  340. {
  341. return;
  342. }
  343. }
  344. catch (Exception err)
  345. {
  346. MessageBox.Show("数据库故障\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  347. }
  348. selectUserPatientManagent.LoadDataGrid();
  349. }
  350. #endregion
  351. #endregion
  352. #region 治疗功能 原筛查功能
  353. /// <summary>
  354. /// 点击治疗后触发的事件
  355. /// </summary>
  356. /// <param name="sender">默认</param>
  357. /// <param name="e">默认</param>
  358. public void buttonFilterSelectTreatment_Click(object sender, RoutedEventArgs e)
  359. {
  360. try
  361. {
  362. var target = (DataRowView)this.selectUserfilter.dataGrid.SelectedItem;
  363. if (target == null)
  364. {
  365. MessageBox.Show("请先选择病人!");
  366. return;
  367. }
  368. filterPatient = SQLite.SQLiteModel.getPatientById(target["p_id"].ToString());
  369. }
  370. catch (Exception err)
  371. {
  372. MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "警告");
  373. return;
  374. }
  375. if(filterPatient == null)
  376. {
  377. MessageBox.Show("数据库加载异常", "错误");
  378. return;
  379. }
  380. try
  381. {
  382. loadQuestionaire(filterQuestionaire, "filter");
  383. filterUserSelection.Clear();
  384. foreach(QuestionAnswerPair qa in filterQuestionaire)
  385. {
  386. filterUserSelection.Add(new UserSelection(qa.question.q_id, 0));
  387. }
  388. }
  389. catch (Exception err)
  390. {
  391. MessageBox.Show("治疗数据加载失败\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  392. return;
  393. }
  394. currentFilterCount = 1;
  395. tabFilter.SelectedIndex += 1;
  396. textBoxCaseId.Text = filterPatient.p_record_id;
  397. textBoxGender.Text = filterPatient.p_gender;
  398. textBoxName.Text = filterPatient.p_name;
  399. textBoxHeight.Text = filterPatient.p_height.ToString();
  400. textBoxWeight.Text = filterPatient.p_weight.ToString();
  401. textBoxPregnancyTimes.Text = filterPatient.p_pregnancy_time.ToString();
  402. textBoxBirthDate.Text = filterPatient.p_birthdate.ToString("yyyy/M/d");
  403. textBoxMobile.Text = filterPatient.p_phone;
  404. textBoxAddress.Text = filterPatient.p_address;
  405. textBoxHistory.Text = filterPatient.p_history;
  406. textBoxDiagnosis.Text = filterPatient.p_diagnosis;
  407. //*/
  408. treatmentCustomModeList = new List<TreatmentCustomItem>();
  409. //dataGridCustomMode.ItemsSource = treatmentCustomModeList;/*/
  410. //treatmentCustomDataTable = new DataTable();
  411. //treatmentCustomDataTable.Columns.Add("tcID", typeof(int));
  412. //treatmentCustomDataTable.Columns.Add("tcRate", typeof(double));
  413. //treatmentCustomDataTable.Columns.Add("tcActiveTime", typeof(double));
  414. //treatmentCustomDataTable.Columns.Add("tcInactiveTime", typeof(double));
  415. //dataGridCustomMode.ItemsSource = treatmentCustomDataTable.DefaultView;//*/
  416. }
  417. /// <summary>
  418. /// 重选用户
  419. /// </summary>
  420. /// <param name="sender">默认</param>
  421. /// <param name="e">默认</param>
  422. private void buttonFilterBackToSelectUser_Click(object sender, RoutedEventArgs e)
  423. {
  424. tabFilter.SelectedIndex = 0;
  425. }
  426. /// <summary>
  427. /// 治疗方案
  428. /// </summary>
  429. /// <param name="sender">默认</param>
  430. /// <param name="e">默认</param>
  431. //private void buttonChooseTreatmentPlan_Click(object sender, RoutedEventArgs e)
  432. //{
  433. // TreatmentPlan a_new_one = new TreatmentPlan(this);
  434. // a_new_one.Show();
  435. //}
  436. public void setTreatment(Treatment target)
  437. {
  438. targetTreatment = target;
  439. labelTreatmentName.Content = targetTreatment.disease;
  440. sliderStrength.Value = 100;
  441. }
  442. private void sliderStrength_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
  443. {
  444. labelStrength.Content = sliderStrength.Value.ToString("0.");
  445. comAgent.enqueueCommand(Com.createChangeStrongthCommand((byte)sliderStrength.Value));
  446. }
  447. /// <summary>
  448. /// 自定义模式
  449. /// </summary>
  450. /// <param name="sender">默认</param>
  451. /// <param name="e">默认</param>
  452. //private void checkBoxCustomMode_CheckedChanged(object sender, RoutedEventArgs e)
  453. //{
  454. // if (checkBoxCustomMode.IsChecked == true) {
  455. // labelTreatmentName.Content = "自定义模式";
  456. // buttonSelectTreatment.IsEnabled = false;
  457. // dataGridCustomMode.IsEnabled = true;
  458. // //dataGridCustomMode.CanUserAddRows = true;
  459. // //dataGridCustomMode.CanUserDeleteRows = true;
  460. // buttonAddCustomModeItem.IsEnabled = true;
  461. // buttonDelCustomModeItem.IsEnabled = true;
  462. // } else {
  463. // if (targetTreatment == null) {
  464. // labelTreatmentName.Content = "请选择治疗方案";
  465. // } else {
  466. // labelTreatmentName.Content = targetTreatment.disease;
  467. // }
  468. // buttonSelectTreatment.IsEnabled = true;
  469. // dataGridCustomMode.IsEnabled = false;
  470. // buttonAddCustomModeItem.IsEnabled = false;
  471. // buttonDelCustomModeItem.IsEnabled = false;
  472. // }
  473. //}
  474. //private void buttonAddCustomModeItem_Click(object sender, RoutedEventArgs e)
  475. //{
  476. // TreatmentCustomItem item = new TreatmentCustomItem();
  477. // item.tcID = treatmentCustomModeList.Count + 1;
  478. // treatmentCustomModeList.Add(item);
  479. // dataGridCustomMode.ItemsSource = null;
  480. // dataGridCustomMode.ItemsSource = treatmentCustomModeList;
  481. //}
  482. //private void buttonDelCustomModeItem_Click(object sender, RoutedEventArgs e)
  483. //{
  484. // int index = dataGridCustomMode.SelectedIndex;
  485. // if (index == -1) { return; }
  486. // treatmentCustomModeList.RemoveAt(index);
  487. // for (int i = 0; i < treatmentCustomModeList.Count; i++)
  488. // {
  489. // treatmentCustomModeList[i].tcID = i + 1;
  490. // }
  491. // dataGridCustomMode.ItemsSource = null;
  492. // dataGridCustomMode.ItemsSource = treatmentCustomModeList;
  493. //}
  494. private void dataGridCustomMode_SelectionChanged(object sender, SelectionChangedEventArgs e)
  495. {
  496. //System.Console.WriteLine("asdasdasd");
  497. }
  498. private void dataGridCustomMode_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
  499. {
  500. //System.Console.WriteLine("asdasdasd");
  501. }
  502. /// <summary>
  503. /// 点击筛查上一步后触发的事件
  504. /// </summary>
  505. /// <param name="sender">默认</param>
  506. /// <param name="e">默认</param>
  507. /*private void buttonFilterPrevious_Click(object sender, RoutedEventArgs e)
  508. {
  509. currentFilterCount -= 1;
  510. loadQuestionViewFilter(currentFilterCount);
  511. checkFilterButtonStatues();
  512. }*/
  513. /// <summary>
  514. /// 点击筛查下一步后触发的事件
  515. /// </summary>
  516. /// <param name="sender">默认</param>
  517. /// <param name="e">默认</param>
  518. /*private void buttonFilterNext_Click(object sender, RoutedEventArgs e)
  519. {
  520. checkFilterButtonStatues();
  521. }*/
  522. /// <summary>
  523. /// 确认筛查阶段各个按钮应当处于的状态
  524. /// </summary>
  525. /*private void checkFilterButtonStatues()
  526. {
  527. bool radioCheckFlag = false;
  528. foreach(RadioButton rb in gridFilterSelection.Children){
  529. if(rb.IsChecked == true)
  530. {
  531. radioCheckFlag = true;
  532. }
  533. }
  534. if (radioCheckFlag && currentFilterCount < filterQuestionaire.Count)
  535. buttonFilterNext.IsEnabled = true;
  536. else
  537. buttonFilterNext.IsEnabled = false;
  538. if (currentFilterCount > 1)
  539. buttonFilterPrevious.IsEnabled = true;
  540. else
  541. buttonFilterPrevious.IsEnabled = false;
  542. bool allFilledFlag = true;
  543. foreach (UserSelection us in filterUserSelection)
  544. {
  545. if (us.a_id == 0)
  546. allFilledFlag = false;
  547. }
  548. if (allFilledFlag)
  549. buttonSubmitFilter.IsEnabled = true;
  550. else
  551. buttonSubmitFilter.IsEnabled = false;
  552. }*/
  553. /// <summary>
  554. /// 加载题目和选项界面
  555. /// </summary>
  556. /*private void loadQuestionViewFilter(int currentIndex)
  557. {
  558. labelFilterNumberofTotalQuestions.Content = filterQuestionaire.Count.ToString();
  559. labelFilterNumberofCurrentQuestion.Content = currentIndex.ToString();
  560. labelFilterQuestionTitle.Content = filterQuestionaire[currentIndex - 1].question.q_title;
  561. textBlockFilterQuetionContent.Text = "";
  562. string[] splitedContentTemp = filterQuestionaire[currentIndex - 1].question.q_content.Split('$');
  563. for(int i = 0;i< splitedContentTemp.Length; ++i)
  564. {
  565. Run aRunTemp = new Run();
  566. aRunTemp.Text = splitedContentTemp[i];
  567. if (i % 2 == 0)
  568. {
  569. textBlockFilterQuetionContent.Inlines.Add(aRunTemp);
  570. }
  571. else
  572. {
  573. aRunTemp.Foreground = Brushes.Red;
  574. textBlockFilterQuetionContent.Inlines.Add(aRunTemp);
  575. }
  576. }
  577. string quetionPic_start = Constants.imgPath + "\\" + filterQuestionaire[currentIndex - 1].question.q_id.ToString() + "-起始位.png";
  578. if (File.Exists(quetionPic_start))
  579. {
  580. BitmapImage bi = new BitmapImage();
  581. bi.BeginInit();
  582. bi.UriSource = new Uri(quetionPic_start, UriKind.RelativeOrAbsolute);
  583. bi.EndInit();
  584. imageFilterQuestion_start.Source = bi;
  585. }
  586. else
  587. {
  588. imageFilterQuestion_start.Source = null;
  589. }
  590. string quetionPic_active = Constants.imgPath + "\\" + filterQuestionaire[currentIndex - 1].question.q_id.ToString() + "-动作位.png";
  591. if (File.Exists(quetionPic_active))
  592. {
  593. BitmapImage bi = new BitmapImage();
  594. bi.BeginInit();
  595. bi.UriSource = new Uri(quetionPic_active, UriKind.RelativeOrAbsolute);
  596. bi.EndInit();
  597. imageFilterQuestion_active.Source = bi;
  598. }
  599. else
  600. {
  601. imageFilterQuestion_active.Source = null;
  602. }
  603. int countOptions = filterQuestionaire[currentIndex - 1].answers.Count;
  604. gridFilterSelection.Children.Clear();
  605. for (int i = 0; i< countOptions; ++i)
  606. {
  607. RadioButton oneOption = new RadioButton();
  608. oneOption.Height = 30;
  609. oneOption.HorizontalAlignment = HorizontalAlignment.Left;
  610. oneOption.VerticalAlignment = VerticalAlignment.Top;
  611. oneOption.Margin = new Thickness(i/6*300, i%6*30, 0, 0);
  612. if(filterUserSelection[currentIndex-1].a_id == filterQuestionaire[currentIndex - 1].answers[i].a_id)
  613. oneOption.IsChecked = true;
  614. else
  615. oneOption.IsChecked = false;
  616. oneOption.Content = String.Format("[选项{0}]:{1}", i+1, filterQuestionaire[currentIndex - 1].answers[i].a_content) ;
  617. oneOption.Checked += radioButtonFilter_Checked;
  618. oneOption.GroupName = "filterOption";
  619. oneOption.FontSize = 18;
  620. oneOption.Name = "rbf" + filterQuestionaire[currentIndex - 1].answers[i].a_id.ToString();
  621. gridFilterSelection.Children.Add(oneOption);
  622. }
  623. }*/
  624. /*private void radioButtonFilter_Checked(object sender, RoutedEventArgs e)
  625. {
  626. //首先,记录该选择
  627. RadioButton oneSelection = (RadioButton)sender;
  628. filterUserSelection[currentFilterCount - 1].a_id = Convert.ToInt32(oneSelection.Name.Substring(3));
  629. //MessageBox.Show(filterUserSelection[currentFilterCount - 1].a_id.ToString());
  630. //然后,确认各个按钮状态
  631. checkFilterButtonStatues();
  632. }*/
  633. /// <summary>
  634. /// 点击筛查提交后触发的事件
  635. /// </summary>
  636. /// <param name="sender">默认</param>
  637. /// <param name="e">默认</param>
  638. /*private void buttonSubmitFilter_Click(object sender, RoutedEventArgs e)
  639. {
  640. int[] timesLimit = dop.getTimesCount();
  641. if (Constants.productionEnvironment && (timesLimit[1] >= timesLimit[0]))
  642. {
  643. MessageBox.Show("此功能已超过Key授权次数,请使用一个新的Key进行操作。", "提示");
  644. return;
  645. }
  646. int inserted_r_id;
  647. resultsFilter = JsonMapper.ToJson(filterUserSelection);
  648. //MessageBox.Show(results);
  649. try
  650. {
  651. inserted_r_id = SQLiteModel.insertRecord(1, filterPatient.p_id, loginDoctor.id, 0, DateTime.Now, 0, resultsFilter);
  652. SQLiteModel.UpdatePatientDataWithLastDate(filterPatient.p_id, "p_last_filter_time", DateTime.Now);
  653. }
  654. catch (Exception err)
  655. {
  656. MessageBox.Show("储存筛查报告错误\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  657. return;
  658. }
  659. dop.addOneCount();
  660. MessageBoxResult dr = MessageBox.Show("保存筛查结果成功,是否生成报告?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
  661. if (dr == MessageBoxResult.OK)
  662. {
  663. try
  664. {
  665. Record targetRecord = SQLiteModel.getRecordByID(inserted_r_id);
  666. //ReportGenerater.generateReport(1, filterPatient, loginDoctor, targetRecord, cfg.organization_name);
  667. ReportGenerater.generateReport_constum(targetRecord, filterPatient, cfg);
  668. SQLiteModel.plusOneCountOnRecordByRid(inserted_r_id);
  669. }
  670. catch (Exception err)
  671. {
  672. MessageBox.Show("报告生成异常,可能是这份报告当前已被打开无法写入,请尝试关闭该报告后重试。\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  673. return;
  674. }
  675. tabFilter.SelectedIndex = 2;
  676. }
  677. else
  678. {
  679. buttonAbortFilter_Click(sender, e);
  680. }
  681. return;
  682. }*/
  683. #endregion
  684. #region 评估功能
  685. /// <summary>
  686. /// 点击开始评估后触发的事件
  687. /// </summary>
  688. /// <param name="sender">默认</param>
  689. /// <param name="e">默认</param>
  690. public void buttonEvaluationSelectPatient_Click(object sender, RoutedEventArgs e)
  691. {
  692. //基本逻辑如下:先找七天内与病例相匹配的筛查记录,如果有,那么要取出结果一题一题比对
  693. //如果没有,那么应当把筛查题进行加载处理
  694. try
  695. {
  696. var target = (DataRowView)this.selectUserevaluation.dataGrid.SelectedItem;
  697. evaluationPatient = SQLite.SQLiteModel.getPatientById(target["p_id"].ToString());
  698. }
  699. catch (Exception err)
  700. {
  701. MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "警告");
  702. return;
  703. }
  704. if (evaluationPatient == null)
  705. {
  706. MessageBox.Show("数据库加载异常", "错误");
  707. return;
  708. }
  709. try
  710. {
  711. loadQuestionaire(filterQuestionaire, "filter");
  712. evaluationQuestionaire.Clear();
  713. filterUserSelection.Clear();
  714. evaluationUserSelection.Clear();
  715. //这里尝试加载用户的筛查记录
  716. /*20200507:根据甲方要求不再提供初筛功能,这里停止加载最新的筛查记录,所有人都做最复杂的问卷*/
  717. //filterReportForEvaluation = SQLiteModel.getLatestXTypeRecordInYDays(evaluationPatient.p_id, 1, 7);
  718. filterReportForEvaluation = null;
  719. if (filterReportForEvaluation == null)
  720. {
  721. flagEvaluationWithoutFilter = true;
  722. foreach (QuestionAnswerPair qa in filterQuestionaire)
  723. {
  724. filterUserSelection.Add(new UserSelection(qa.question.q_id, 0));
  725. }
  726. }
  727. else
  728. {
  729. var jsonUserSelections = filterReportForEvaluation.r_selection;
  730. filterUserSelection = JsonMapper.ToObject<List<UserSelection>>(jsonUserSelections);
  731. flagEvaluationWithoutFilter = false;
  732. }
  733. }
  734. catch (Exception err)
  735. {
  736. MessageBox.Show("筛查题目加载失败\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  737. return;
  738. }
  739. if (filterQuestionaire.Count == 0)
  740. {
  741. MessageBox.Show("筛查题目加载失败\r\n数据库中无有效问卷", "错误");
  742. return;
  743. }
  744. if (flagEvaluationWithoutFilter)
  745. {
  746. /*20200507:根据甲方要求不再提供初筛功能,这里停止加载最新的筛查记录,所有人都做最复杂的问卷*/
  747. //MessageBox.Show("发现该病例一周内未进行初筛,评估过程中将自动进行初筛。","提示");
  748. }
  749. else
  750. {
  751. MessageBox.Show("发现该病例于"+ filterReportForEvaluation.r_time.ToString("yyyy-MM-dd HH:mm:ss") +"进行过初筛,评估过程中将使用此初筛结果。", "提示");
  752. }
  753. labelEvaluationName.Content = evaluationPatient.p_name;
  754. labelEvaluationRecordid.Content = evaluationPatient.p_record_id;
  755. currentFilterCount = 1;
  756. currentEvaluationCount = 1;
  757. evaluationQuestionaire.Add(filterQuestionaire[currentFilterCount - 1]);
  758. evaluationUserSelection.Add(filterUserSelection[currentFilterCount - 1]);
  759. tabEvaluation.SelectedIndex += 1;
  760. checkStatusEvaluation();
  761. }
  762. /// <summary>
  763. /// 加载currentIndex的评估题目功能
  764. /// </summary>
  765. /// <param name="currentIndex">需要显示题目的题号</param>
  766. private void loadQuestionViewEvaluation(int currentIndex)
  767. {
  768. labelQuestionNumberofCurrentQuestion.Content = currentIndex.ToString();
  769. labelEvaluationQuestionTitle.Content = evaluationQuestionaire[currentIndex - 1].question.q_title;
  770. textBlockEvaluationQuetionContent.Text = "";
  771. string[] splitedContentTemp = evaluationQuestionaire[currentIndex - 1].question.q_content.Split('$');
  772. for (int i = 0; i < splitedContentTemp.Length; ++i)
  773. {
  774. Run aRunTemp = new Run();
  775. aRunTemp.Text = splitedContentTemp[i];
  776. if (i % 2 == 0)
  777. {
  778. textBlockEvaluationQuetionContent.Inlines.Add(aRunTemp);
  779. }
  780. else
  781. {
  782. //aRunTemp.Foreground = Brushes.Red;
  783. aRunTemp.FontWeight = FontWeights.Bold;
  784. aRunTemp.Text = "· " + aRunTemp.Text;
  785. textBlockEvaluationQuetionContent.Inlines.Add(aRunTemp);
  786. }
  787. }
  788. string quetionPic_start = Constants.imgPath + "\\" + evaluationQuestionaire[currentIndex - 1].question.q_id.ToString() + "-起始位.png";
  789. if (File.Exists(quetionPic_start))
  790. {
  791. BitmapImage bi = new BitmapImage();
  792. bi.BeginInit();
  793. bi.UriSource = new Uri(quetionPic_start, UriKind.RelativeOrAbsolute);
  794. bi.EndInit();
  795. imageEvaluationQuestion_start.Source = bi;
  796. }
  797. else
  798. {
  799. imageEvaluationQuestion_start.Source = null;
  800. }
  801. string quetionPic_active = Constants.imgPath + "\\" + evaluationQuestionaire[currentIndex - 1].question.q_id.ToString() + "-动作位.png";
  802. if (File.Exists(quetionPic_active))
  803. {
  804. BitmapImage bi = new BitmapImage();
  805. bi.BeginInit();
  806. bi.UriSource = new Uri(quetionPic_active, UriKind.RelativeOrAbsolute);
  807. bi.EndInit();
  808. imageEvaluationQuestion_active.Source = bi;
  809. }
  810. else
  811. {
  812. imageEvaluationQuestion_active.Source = null;
  813. }
  814. int countOptions = evaluationQuestionaire[currentIndex - 1].answers.Count;
  815. gridEvaluationSelectionNormalOptions.Children.Clear();
  816. gridEvaluationSelection.Children.Clear();
  817. //i=0,添加一个正常选项
  818. if (countOptions > 0)
  819. {
  820. Label normalWithoutPain = new Label();
  821. normalWithoutPain.HorizontalAlignment = HorizontalAlignment.Center;
  822. normalWithoutPain.VerticalAlignment = VerticalAlignment.Top;
  823. normalWithoutPain.Margin = new Thickness(0, 0, 0, 0);
  824. normalWithoutPain.Content = "动作标准";
  825. normalWithoutPain.Foreground = new SolidColorBrush(Color.FromRgb(39, 64, 90));
  826. normalWithoutPain.FontWeight = FontWeights.Bold;
  827. normalWithoutPain.FontSize = 20;
  828. gridEvaluationSelectionNormalOptions.Children.Add(normalWithoutPain);
  829. RadioButton oneOption = new RadioButton();
  830. oneOption.Height = 30;
  831. oneOption.HorizontalAlignment = HorizontalAlignment.Center;
  832. oneOption.VerticalAlignment = VerticalAlignment.Center;
  833. oneOption.Margin = new Thickness(0, 0, 0, 0);
  834. if (evaluationUserSelection[currentIndex - 1].a_id == evaluationQuestionaire[currentIndex - 1].answers[0].a_id)
  835. oneOption.IsChecked = true;
  836. else
  837. oneOption.IsChecked = false;
  838. oneOption.Content = String.Format("{0}", evaluationQuestionaire[currentIndex - 1].answers[0].a_content);
  839. oneOption.Checked += radioButtonEvaluation_Checked;
  840. oneOption.GroupName = "evaluationOption";
  841. oneOption.FontSize = 18;
  842. oneOption.Name = "rbe" + evaluationQuestionaire[currentIndex - 1].answers[0].a_id.ToString();
  843. gridEvaluationSelectionNormalOptions.Children.Add(oneOption);
  844. }
  845. //i>=1
  846. for (int i = 1; i < countOptions; ++i)
  847. {
  848. Label abnormalWithPain = new Label();
  849. abnormalWithPain.HorizontalAlignment = HorizontalAlignment.Center;
  850. abnormalWithPain.VerticalAlignment = VerticalAlignment.Top;
  851. abnormalWithPain.Margin = new Thickness(0, 0, 0, 0);
  852. abnormalWithPain.Content = "动作不标准";
  853. abnormalWithPain.Foreground = new SolidColorBrush(Color.FromRgb(39, 64, 90));
  854. abnormalWithPain.FontWeight = FontWeights.Bold;
  855. abnormalWithPain.FontSize = 20;
  856. gridEvaluationSelection.Children.Add(abnormalWithPain);
  857. RadioButton oneOption = new RadioButton();
  858. oneOption.Height = 30;
  859. oneOption.HorizontalAlignment = HorizontalAlignment.Left;
  860. oneOption.VerticalAlignment = VerticalAlignment.Top;
  861. oneOption.Margin = new Thickness( (i-1)/ 3 * 170 + 30, (i-1) % 3 * 30+40, 0, 0);
  862. if (evaluationUserSelection[currentIndex - 1].a_id == evaluationQuestionaire[currentIndex - 1].answers[i].a_id)
  863. oneOption.IsChecked = true;
  864. else
  865. oneOption.IsChecked = false;
  866. oneOption.Content = String.Format("{0}", evaluationQuestionaire[currentIndex - 1].answers[i].a_content);
  867. oneOption.Checked += radioButtonEvaluation_Checked;
  868. oneOption.GroupName = "evaluationOption";
  869. oneOption.FontSize = 18;
  870. oneOption.Name = "rbe" + evaluationQuestionaire[currentIndex - 1].answers[i].a_id.ToString();
  871. gridEvaluationSelection.Children.Add(oneOption);
  872. }
  873. }
  874. /// <summary>
  875. /// 检查当前答题状态,判断是否需要跳过该题和控制加载题目的功能,能够维护userselection和questionaire
  876. /// </summary>
  877. private void checkStatusEvaluation()
  878. {
  879. if(!flagEvaluationWithoutFilter && evaluationQuestionaire[currentEvaluationCount-1].question.q_type == 1)
  880. {
  881. //有预加载的筛查报告且当前问题是一道筛查题
  882. Answer aTemp = SQLiteModel.getAnswerById(filterUserSelection[currentFilterCount - 1].a_id);
  883. if (aTemp == null || aTemp.next_q_id == 0)
  884. {
  885. if(currentFilterCount == filterQuestionaire.Count)
  886. {
  887. //当前所有题目都已经做完了
  888. buttonEvaluationNext.IsEnabled = false;
  889. bool allQuestionAreSeleceted = true;
  890. foreach (UserSelection us in evaluationUserSelection)
  891. {
  892. if (us.a_id == 0)
  893. allQuestionAreSeleceted = false;
  894. }
  895. //经过检查可以提交
  896. buttonSubmitEvaluation.IsEnabled = allQuestionAreSeleceted;
  897. }
  898. else
  899. {
  900. //还有剩下的筛选题没有过
  901. QuestionAnswerPair qaPairEvaluation = filterQuestionaire[currentFilterCount];
  902. //当前元素后面的题目和选项都清空
  903. for (int i = evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i)
  904. {
  905. evaluationQuestionaire.RemoveAt(i);
  906. evaluationUserSelection.RemoveAt(i);
  907. }
  908. evaluationQuestionaire.Add(qaPairEvaluation);
  909. evaluationUserSelection.Add(filterUserSelection[currentFilterCount]);
  910. //再刷新一次
  911. ++currentFilterCount;
  912. ++currentEvaluationCount;
  913. checkStatusEvaluation();
  914. }
  915. }
  916. else
  917. {
  918. //否则还有评估题没做
  919. Question aEvaluationQuestion = SQLiteModel.getQuestionById(aTemp.next_q_id);
  920. List<Answer> answersToTheEvaluation = SQLiteModel.getAnswersByQid(aEvaluationQuestion.q_id);
  921. QuestionAnswerPair qaPairEvaluation = new QuestionAnswerPair(aEvaluationQuestion, answersToTheEvaluation);
  922. //当前元素后面的题目和选项都清空
  923. for(int i= evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i)
  924. {
  925. evaluationQuestionaire.RemoveAt(i);
  926. evaluationUserSelection.RemoveAt(i);
  927. }
  928. evaluationQuestionaire.Add(qaPairEvaluation);
  929. evaluationUserSelection.Add(new UserSelection(aEvaluationQuestion.q_id, 0));
  930. //再刷新一次
  931. ++currentEvaluationCount;
  932. checkStatusEvaluation();
  933. }
  934. }
  935. else
  936. {
  937. //其他情况:没有预加载的筛选题或者有预加载的筛选题但是是一道评估题
  938. loadQuestionViewEvaluation(currentEvaluationCount);
  939. buttonEvaluationNext.IsEnabled = false;
  940. buttonSubmitEvaluation.IsEnabled = false;
  941. }
  942. }
  943. /// <summary>
  944. /// 评估单选选项被选中的触发事件,主要是修改内存中的选择和判断下一题及提交按钮是否可用
  945. /// </summary>
  946. /// <param name="sender">默认</param>
  947. /// <param name="e">默认</param>
  948. private void radioButtonEvaluation_Checked(object sender, RoutedEventArgs e)
  949. {
  950. //首先,记录该选择
  951. RadioButton oneSelection = (RadioButton)sender;
  952. evaluationUserSelection[currentEvaluationCount - 1].a_id = Convert.ToInt32(oneSelection.Name.Substring(3));
  953. if (flagEvaluationWithoutFilter && evaluationQuestionaire[currentEvaluationCount-1].question.q_type ==1)
  954. {
  955. filterUserSelection[currentFilterCount - 1].a_id = Convert.ToInt32(oneSelection.Name.Substring(3));
  956. }
  957. //MessageBox.Show(filterUserSelection[currentFilterCount - 1].a_id.ToString());
  958. Answer oneAnswer = SQLiteModel.getAnswerById(evaluationUserSelection[currentEvaluationCount - 1].a_id);
  959. if(currentFilterCount == filterQuestionaire.Count && oneAnswer.next_q_id == 0)
  960. {
  961. //后面没有题目了,可以提交
  962. buttonEvaluationNext.IsEnabled = false;
  963. bool allQuestionAreSeleceted = true;
  964. foreach (UserSelection us in evaluationUserSelection)
  965. {
  966. if (us.a_id == 0)
  967. allQuestionAreSeleceted = false;
  968. }
  969. //经过检查可以提交
  970. buttonSubmitEvaluation.IsEnabled = allQuestionAreSeleceted;
  971. }
  972. else
  973. {
  974. //否则可以做下一题
  975. buttonEvaluationNext.IsEnabled = true;
  976. buttonSubmitEvaluation.IsEnabled = false;
  977. }
  978. }
  979. /// <summary>
  980. /// (未实现)评估过程中点击上一题的触发事件
  981. /// </summary>
  982. /// <param name="sender">默认</param>
  983. /// <param name="e">默认</param>
  984. private void buttonEvaluationPrevious_Click(object sender, RoutedEventArgs e)
  985. {
  986. }
  987. /// <summary>
  988. /// 点击评估页下一题后触发的事件,主要是判断接下来加载哪一题
  989. /// </summary>
  990. /// <param name="sender">默认</param>
  991. /// <param name="e">默认</param>
  992. private void buttonEvaluationNext_Click(object sender, RoutedEventArgs e)
  993. {
  994. //先看看后面有没有进退阶题目了
  995. Answer oneAnswer = SQLiteModel.getAnswerById(evaluationUserSelection[currentEvaluationCount - 1].a_id);
  996. if(oneAnswer.next_q_id!= 0)
  997. {
  998. //还有后续题目
  999. Question aEvaluationQuestion = SQLiteModel.getQuestionById(oneAnswer.next_q_id);
  1000. List<Answer> answersToTheEvaluation = SQLiteModel.getAnswersByQid(aEvaluationQuestion.q_id);
  1001. QuestionAnswerPair qaPairEvaluation = new QuestionAnswerPair(aEvaluationQuestion, answersToTheEvaluation);
  1002. //当前元素后面的题目和选项都清空
  1003. for (int i = evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i)
  1004. {
  1005. evaluationQuestionaire.RemoveAt(i);
  1006. evaluationUserSelection.RemoveAt(i);
  1007. }
  1008. evaluationQuestionaire.Add(qaPairEvaluation);
  1009. evaluationUserSelection.Add(new UserSelection(aEvaluationQuestion.q_id, 0));
  1010. //再刷新一次
  1011. ++currentEvaluationCount;
  1012. checkStatusEvaluation();
  1013. }
  1014. else
  1015. {
  1016. //否则跳到下一个筛选题上面
  1017. QuestionAnswerPair qaPairEvaluation = filterQuestionaire[currentFilterCount];
  1018. //当前元素后面的题目和选项都清空
  1019. for (int i = evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i)
  1020. {
  1021. evaluationQuestionaire.RemoveAt(i);
  1022. evaluationUserSelection.RemoveAt(i);
  1023. }
  1024. evaluationQuestionaire.Add(qaPairEvaluation);
  1025. evaluationUserSelection.Add(filterUserSelection[currentFilterCount]);
  1026. //再刷新一次
  1027. ++currentFilterCount;
  1028. ++currentEvaluationCount;
  1029. checkStatusEvaluation();
  1030. }
  1031. }
  1032. /// <summary>
  1033. /// 点击评估页提交后触发的事件
  1034. /// </summary>
  1035. /// <param name="sender">默认</param>
  1036. /// <param name="e">默认</param>
  1037. private void buttonSubmitEvaluation_Click(object sender, RoutedEventArgs e)
  1038. {
  1039. int[] timesLimit = dop.getTimesCount();
  1040. //MessageBox.Show(String.Format("生产环境状态标识:{0}, 授权阈值: {1}, 已使用次数:{2}", Constants.productionEnvironment, timesLimit[0], timesLimit[1]));
  1041. if (Constants.productionEnvironment && (timesLimit[1] >= timesLimit[0]))
  1042. {
  1043. MessageBox.Show("此功能已超过Key授权次数,请使用一个新的Key进行操作。", "提示");
  1044. return;
  1045. }
  1046. int inserted_r_id;
  1047. resultsFilter = JsonMapper.ToJson(filterUserSelection);
  1048. resultsEvaluation = JsonMapper.ToJson(evaluationUserSelection);
  1049. try
  1050. {
  1051. int tempRId;
  1052. if (flagEvaluationWithoutFilter)
  1053. {
  1054. tempRId = SQLiteModel.insertRecord(1, evaluationPatient.p_id, loginDoctor.id, 0, DateTime.Now, 0, resultsFilter);
  1055. SQLiteModel.UpdatePatientDataWithLastDate(evaluationPatient.p_id, "p_last_filter_time", DateTime.Now);
  1056. }
  1057. else
  1058. {
  1059. tempRId = filterReportForEvaluation.r_id;
  1060. }
  1061. inserted_r_id = SQLiteModel.insertRecord(2, evaluationPatient.p_id, loginDoctor.id, tempRId, DateTime.Now, 0, resultsEvaluation);
  1062. SQLiteModel.UpdatePatientDataWithLastDate(evaluationPatient.p_id, "p_last_evaluation_time", DateTime.Now);
  1063. }
  1064. catch (Exception err)
  1065. {
  1066. MessageBox.Show("储存报告错误\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  1067. return;
  1068. }
  1069. dop.addOneCount();
  1070. loadUSBDogStatus();
  1071. MessageBoxResult dr = MessageBox.Show("保存成功,是否生成报告?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
  1072. if (dr == MessageBoxResult.OK)
  1073. {
  1074. try
  1075. {
  1076. Record targetRecord = SQLiteModel.getRecordByID(inserted_r_id);
  1077. SQLiteModel.plusOneCountOnRecordByRid(inserted_r_id);
  1078. //ReportGenerater.generateReport(2, evaluationPatient, loginDoctor, targetRecord, cfg.organization_name);
  1079. ReportGenerater.generateReport_constum(targetRecord, evaluationPatient, cfg);
  1080. }
  1081. catch (Exception err)
  1082. {
  1083. MessageBox.Show("报告生成异常,可能是这份报告当前已被打开无法写入,请尝试关闭该报告后重试。\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误");
  1084. return;
  1085. }
  1086. tabEvaluation.SelectedIndex = 2;
  1087. }
  1088. else
  1089. {
  1090. buttonAbortEvaluation_Click(sender, e);
  1091. }
  1092. return;
  1093. }
  1094. /// <summary>
  1095. /// 点击评估页中止评估后触发的事件
  1096. /// </summary>
  1097. /// <param name="sender">默认</param>
  1098. /// <param name="e">默认</param>
  1099. private void buttonAbortEvaluation_Click(object sender, RoutedEventArgs e)
  1100. {
  1101. //清理相关变量
  1102. filterQuestionaire.Clear();
  1103. filterUserSelection.Clear();
  1104. evaluationQuestionaire.Clear();
  1105. evaluationUserSelection.Clear();
  1106. flagEvaluationWithoutFilter = true;
  1107. filterReportForEvaluation = null;
  1108. evaluationPatient = null;
  1109. resultsFilter = "";
  1110. resultsEvaluation = "";
  1111. currentFilterCount = 0;
  1112. currentEvaluationCount = 0;
  1113. //buttonFilterPrevious.IsEnabled = false;
  1114. buttonEvaluationNext.IsEnabled = false;
  1115. buttonSubmitEvaluation.IsEnabled = false;
  1116. tabEvaluation.SelectedIndex = 0;
  1117. }
  1118. /// <summary>
  1119. /// 返回至选择用户页
  1120. /// </summary>
  1121. /// <param name="sender">默认</param>
  1122. /// <param name="e">默认</param>
  1123. private void buttonEvaluationBackToSelectUser_Click(object sender, RoutedEventArgs e)
  1124. {
  1125. buttonAbortEvaluation_Click(sender, e);
  1126. }
  1127. /// <summary>
  1128. /// 返回至选择首页
  1129. /// </summary>
  1130. /// <param name="sender">默认</param>
  1131. /// <param name="e">默认</param>
  1132. private void buttonEvaluationBackToHome_Click(object sender, RoutedEventArgs e)
  1133. {
  1134. buttonAbortEvaluation_Click(sender, e);
  1135. tabControlGeneral.SelectedIndex = 0;
  1136. }
  1137. #endregion
  1138. #region 历史记录
  1139. /// <summary>
  1140. /// 点击选择病例查看其历史记录后触发的事件
  1141. /// </summary>
  1142. /// <param name="sender">默认</param>
  1143. /// <param name="e">默认</param>
  1144. public void buttonHistorySelectPatient_Click(object sender, RoutedEventArgs e)
  1145. {
  1146. try
  1147. {
  1148. var target = (DataRowView)this.selectUserHistory.dataGrid.SelectedItem;
  1149. historyPatient = SQLiteModel.getPatientById(Convert.ToString(target["p_id"]));
  1150. recordsFromOnePatient = SQLiteModel.getRecordsByPid(Convert.ToInt32(target["p_id"]),true);
  1151. }
  1152. catch (Exception err)
  1153. {
  1154. MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "警告");
  1155. return;
  1156. }
  1157. if (recordsFromOnePatient == null || historyPatient == null)
  1158. {
  1159. MessageBox.Show("数据库加载异常", "错误");
  1160. return;
  1161. }
  1162. try
  1163. {
  1164. bindingRecords = new BindingList<Record>(recordsFromOnePatient);
  1165. dataGridRecords.ItemsSource = bindingRecords;
  1166. }
  1167. catch(Exception err)
  1168. {
  1169. MessageBox.Show("数据库加载异常\r\n调试信息:\r\n"+err.StackTrace, "错误");
  1170. return;
  1171. }
  1172. tabHistoryRecords.SelectedIndex = 1;
  1173. }
  1174. /// <summary>
  1175. /// 在选择记录页面,点击返回上一级触发的事件
  1176. /// </summary>
  1177. /// <param name="sender">默认</param>
  1178. /// <param name="e">默认</param>
  1179. private void buttonHistoryBackToSelectUser_Click(object sender, RoutedEventArgs e)
  1180. {
  1181. recordsFromOnePatient.Clear();
  1182. tabHistoryRecords.SelectedIndex = 0;
  1183. }
  1184. /// <summary>
  1185. /// 由历史记录相关页面返回至首页的事件
  1186. /// </summary>
  1187. /// <param name="sender">默认</param>
  1188. /// <param name="e">默认</param>
  1189. private void buttonHistoryBackToHome_Click(object sender, RoutedEventArgs e)
  1190. {
  1191. recordsFromOnePatient.Clear();
  1192. tabHistoryRecords.SelectedIndex = 0;
  1193. tabControlGeneral.SelectedIndex = 0;
  1194. }
  1195. /// <summary>
  1196. /// 点击生成报告的页面
  1197. /// </summary>
  1198. /// <param name="sender">默认</param>
  1199. /// <param name="e">默认</param>
  1200. private void buttonRegenerateReport_Click(object sender, RoutedEventArgs e)
  1201. {
  1202. Record targetRecord;
  1203. try
  1204. {
  1205. var target = this.dataGridRecords.SelectedItem as Record;
  1206. targetRecord = SQLiteModel.getRecordByID(Convert.ToInt32(target.r_id));
  1207. }
  1208. catch (Exception err)
  1209. {
  1210. MessageBox.Show("请选择一个记录进行生成\r\n" + err.StackTrace, "提示");
  1211. return;
  1212. }
  1213. if (targetRecord == null)
  1214. {
  1215. MessageBox.Show("数据库加载异常", "错误");
  1216. return;
  1217. }
  1218. try
  1219. {
  1220. //ReportGenerater.generateReport(targetRecord.r_type, historyPatient, loginDoctor, targetRecord, cfg.organization_name);
  1221. ReportGenerater.generateReport_constum(targetRecord, historyPatient, cfg);
  1222. SQLiteModel.plusOneCountOnRecordByRid(targetRecord.r_id);
  1223. }
  1224. catch(Exception err)
  1225. {
  1226. MessageBox.Show("报告生成异常,可能是这份报告当前已被打开无法写入,请尝试关闭该报告后重试。\r\n调试信息:\r\n" + err.StackTrace, "错误");
  1227. return;
  1228. }
  1229. tabHistoryRecords.SelectedIndex = 2;
  1230. }
  1231. /// <summary>
  1232. /// 从报告生成页点击返回上一页的事件
  1233. /// </summary>
  1234. /// <param name="sender">默认</param>
  1235. /// <param name="e">默认</param>
  1236. private void buttonHistoryBackToSelectRecord_Click(object sender, RoutedEventArgs e)
  1237. {
  1238. tabHistoryRecords.SelectedIndex = 1;
  1239. }
  1240. /// <summary>
  1241. /// 双击报告也要生成报告的功能
  1242. /// </summary>
  1243. /// <param name="sender">默认</param>
  1244. /// <param name="e">默认</param>
  1245. private void dataGridRecords_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  1246. {
  1247. buttonRegenerateReport_Click(sender, e);
  1248. }
  1249. #endregion
  1250. #region 系统设置
  1251. //系统设置
  1252. //进入系统设置前主任级别用户的身份验证
  1253. async private void tabControlGeneral_SelectionChanged(object sender, SelectionChangedEventArgs e)
  1254. {
  1255. //System.Console.WriteLine(Convert.ToString(tabControlGeneral.SelectedIndex));
  1256. if (e.Source is TabControl)
  1257. {
  1258. //系统设置页验证
  1259. if (tabitemDoctorSetting.IsSelected)
  1260. {
  1261. DateTime now = DateTime.Now;
  1262. if (lastSettingLogin != null && (now - lastSettingLogin).Minutes <= 10)
  1263. {
  1264. //如果上次有登录而且登录时间在10分钟以内,则免登录
  1265. return;
  1266. }
  1267. bool dialogLoop = true;
  1268. bool wrongPassword = false;
  1269. string description;
  1270. int x = 1;
  1271. while (dialogLoop)
  1272. {
  1273. x++;
  1274. if (wrongPassword)
  1275. {
  1276. description = "用户名或密码不正确,请重新输入账号和密码进入系统设置";
  1277. }
  1278. else
  1279. {
  1280. description = "请输入账号和密码进入系统设置";
  1281. }
  1282. LoginDialogData loginDialogData;
  1283. loginDialogData = await this.ShowLoginAsync
  1284. (
  1285. "输入科室主任级别账号密码以继续..." + Convert.ToString(x),
  1286. description,
  1287. new LoginDialogSettings
  1288. {
  1289. ColorScheme = MetroDialogColorScheme.Accented,
  1290. UsernameWatermark = "用户名",
  1291. PasswordWatermark = "密码",
  1292. NegativeButtonVisibility = Visibility.Visible
  1293. }
  1294. );
  1295. if (loginDialogData == null)
  1296. {
  1297. dialogLoop = false;
  1298. tabControlGeneral.SelectedIndex = 0;
  1299. return;
  1300. //break;
  1301. }
  1302. //调用数据库验证
  1303. string doctorName = loginDialogData.Username;
  1304. string doctorPassword = loginDialogData.Password;
  1305. string doctorPWD = Toolkits.ComputeHash.GetMD5(doctorPassword);
  1306. doctor loginDirector = SQLiteModel.directorLogin(doctorName, doctorPWD);
  1307. if (loginDirector == null)
  1308. {
  1309. //MessageBox.Show("admin");
  1310. wrongPassword = true;
  1311. dialogLoop = true;
  1312. }
  1313. else
  1314. {
  1315. lastSettingLogin = DateTime.Now;
  1316. dialogLoop = false;
  1317. return;
  1318. //break;
  1319. }
  1320. }
  1321. }
  1322. //高级系统设置验证页
  1323. //if (tabitemOEMSetting.IsSelected)
  1324. }
  1325. }
  1326. #region 医师管理
  1327. //系统设置--医师管理
  1328. private void LoadDoctorDataGrid(object sender, RoutedEventArgs e)
  1329. {
  1330. LoadDoctorDataGrid();
  1331. }
  1332. public void LoadDoctorDataGrid()
  1333. {
  1334. //连接字符串
  1335. string Connstr = Toolkits.Constants.Connstr;
  1336. //连接对象
  1337. System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(Connstr);
  1338. //Sql语句
  1339. string selectCmd = "SELECT * FROM Doctor WHERE delete_flag=0 AND name != '" + Constants.adminUsername + "' LIMIT 100";
  1340. con.Open();
  1341. da = new System.Data.SQLite.SQLiteDataAdapter(selectCmd, con);
  1342. ds = new DataSet();
  1343. da.Fill(ds);
  1344. dataGridDoctor.ItemsSource = ds.Tables[0].DefaultView;
  1345. con.Close();
  1346. }
  1347. //新增医师
  1348. private void buttonAddDoctor_Click(object sender, RoutedEventArgs e)
  1349. {
  1350. AddDoctor a_new_doctor = new AddDoctor(this);
  1351. a_new_doctor.Show();
  1352. }
  1353. //修改医师
  1354. private void buttonChangeDoctor_Click(object sender, RoutedEventArgs e)
  1355. {
  1356. try
  1357. {
  1358. var target = (DataRowView)this.dataGridDoctor.SelectedItem;
  1359. //MessageBox.Show(target["id"].ToString());
  1360. ModifyDoctor modify_one = new ModifyDoctor(this, target["id"].ToString());
  1361. modify_one.Show();
  1362. }
  1363. catch (Exception err)
  1364. {
  1365. this.ShowMessageAsync("警告", "请选择一个医生进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace);
  1366. }
  1367. }
  1368. //双击表格触发修改医师的方法
  1369. private void dataGridDoctor_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  1370. {
  1371. buttonChangeDoctor_Click(this, e);
  1372. }
  1373. //修改医师密码
  1374. private void buttonChangeDoctorPWD_Click(object sender, RoutedEventArgs e)
  1375. {
  1376. try
  1377. {
  1378. var target = (DataRowView)this.dataGridDoctor.SelectedItem;
  1379. //MessageBox.Show(target["id"].ToString());
  1380. ModifyDoctorPWD modify_one = new ModifyDoctorPWD(this, target["id"].ToString());
  1381. modify_one.Show();
  1382. }
  1383. catch (Exception err)
  1384. {
  1385. this.ShowMessageAsync("警告", "请选择一个医生进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace);
  1386. }
  1387. }
  1388. //删除医师
  1389. private async void buttonDeleteDoctor_Click(object sender, RoutedEventArgs e)
  1390. {
  1391. try
  1392. {
  1393. var target = (DataRowView)this.dataGridDoctor.SelectedItem;
  1394. if (target == null)
  1395. {
  1396. await this.ShowMessageAsync("提示", "请选择一个医生进行删除");
  1397. return;
  1398. }
  1399. MessageDialogResult clickresult = await this.ShowMessageAsync("提示", "确认删除该医生信息吗?", MessageDialogStyle.AffirmativeAndNegative);
  1400. if (clickresult == MessageDialogResult.Affirmative)//确认
  1401. {
  1402. int status = SQLite.SQLiteModel.DeleteDoctorItem(target["id"].ToString());
  1403. if (status > 0)
  1404. {
  1405. await this.ShowMessageAsync("提示", "删除成功!");
  1406. }
  1407. else
  1408. {
  1409. await this.ShowMessageAsync("警告", "目标已被删除");
  1410. }
  1411. }
  1412. else//取消
  1413. {
  1414. return;
  1415. }
  1416. }
  1417. catch (Exception err)
  1418. {
  1419. await this.ShowMessageAsync("警告", "请选择一个医生进行删除!\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace);
  1420. }
  1421. LoadDoctorDataGrid();
  1422. }
  1423. //筛选医师
  1424. private void buttonFindDoctor_Click(object sender, RoutedEventArgs e)
  1425. {
  1426. try
  1427. {
  1428. //连接字符串
  1429. string Connstr = "Data Source=" + System.Environment.CurrentDirectory + "\\Junde.db3"; ;
  1430. //连接对象
  1431. System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(Connstr);
  1432. string namelike = textBoxFindDoctor.Text;
  1433. //MessageBox.Show(namelike);
  1434. //Sql语句
  1435. string selectCmd = "SELECT * FROM Doctor WHERE NAME LIKE \'%" + namelike + "%\' AND delete_flag=0 LIMIT 100";
  1436. con.Open();
  1437. System.Data.SQLite.SQLiteDataAdapter da_1 = new System.Data.SQLite.SQLiteDataAdapter(selectCmd, con);
  1438. DataSet ds_1 = new DataSet();
  1439. da_1.Fill(ds_1);
  1440. dataGridDoctor.ItemsSource = ds_1.Tables[0].DefaultView;
  1441. con.Close();
  1442. }
  1443. catch (Exception err)
  1444. {
  1445. MessageBox.Show("数据库错误.\r\n调试信息:" + err.Message, "错误");
  1446. }
  1447. }
  1448. #endregion
  1449. #region 其他设置
  1450. /// <summary>
  1451. /// 更换医疗机构名称
  1452. /// </summary>
  1453. /// <param name="sender">默认</param>
  1454. /// <param name="e">默认</param>
  1455. private void buttonModifyRegisterInfo_Click(object sender, RoutedEventArgs e)
  1456. {
  1457. try
  1458. {
  1459. SQLiteModel.UpdateOrganizationName(Toolkits.FilterDangerousCharacter.filter(textBoxOrganizationName.Text));
  1460. }
  1461. catch (Exception)
  1462. {
  1463. MessageBox.Show("更新失败!", "错误");
  1464. }
  1465. MessageBox.Show("更新成功", "提示");
  1466. }
  1467. /// <summary>
  1468. /// buttonOptmizeDatabase_Click:点击优化数据库的方法,把已经被删除的数据进行彻底清除
  1469. /// </summary>
  1470. /// <param name="sender">默认</param>
  1471. /// <param name="e">默认</param>
  1472. private void buttonOptmizeDatabase_Click(object sender, RoutedEventArgs e)
  1473. {
  1474. try
  1475. {
  1476. //获取标记为删除的病人记录
  1477. List<int> ids_to_be_deleted = SQLite.SQLiteModel.getDeletedPatients();
  1478. //确实删除这些病人记录
  1479. SQLite.SQLiteModel.realDeleteRecords();
  1480. //确实删除这些病人所含有的检查记录
  1481. foreach(int each_line in ids_to_be_deleted)
  1482. {
  1483. SQLite.SQLiteModel.deleteRecordByPid(each_line);
  1484. }
  1485. //SQLiteModel.optmizeDatabase();
  1486. MessageBox.Show("操作完成", "信息");
  1487. }
  1488. catch (Exception err)
  1489. {
  1490. MessageBox.Show("数据库异常\r\b"+err.Message+"\r\b"+err.StackTrace, "错误");
  1491. }
  1492. }
  1493. /// <summary>
  1494. /// buttonDeleteAllPdfReport_Click:点击删除某一目录下所有文件的方法
  1495. /// </summary>
  1496. /// <param name="sender">默认</param>
  1497. /// <param name="e">默认</param>
  1498. private void buttonDeleteFiles_Click(object sender, RoutedEventArgs e)
  1499. {
  1500. string target_path = "";
  1501. if (((Button)sender).Equals(buttonDeleteAllPdfReport))
  1502. {
  1503. target_path = Constants.reportPath;
  1504. }
  1505. try
  1506. {
  1507. DirectoryInfo dir = new DirectoryInfo(target_path);
  1508. FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
  1509. foreach (FileSystemInfo i in fileinfo)
  1510. {
  1511. if (i is DirectoryInfo) //判断是否文件夹
  1512. {
  1513. DirectoryInfo subdir = new DirectoryInfo(i.FullName);
  1514. subdir.Delete(true); //删除子目录和文件
  1515. }
  1516. else
  1517. {
  1518. File.Delete(i.FullName); //删除指定文件
  1519. }
  1520. }
  1521. MessageBox.Show("操作完成", "信息");
  1522. }
  1523. catch (Exception)
  1524. {
  1525. MessageBox.Show("文件系统异常", "错误");
  1526. }
  1527. }
  1528. #endregion
  1529. #endregion
  1530. #region 测试功能
  1531. private void buttonTest1_Click(object sender, RoutedEventArgs e)
  1532. {
  1533. int res_flag = SQLiteModel.loopInsertAnswers();
  1534. if(res_flag == 0)
  1535. {
  1536. MessageBox.Show("操作成功");
  1537. }
  1538. }
  1539. #endregion
  1540. private float treatmentTime_ = 30, treatmentTimeMin = 1, treatmentTimeMax = 100;
  1541. public float treatmentTime
  1542. {
  1543. get => treatmentTime_;
  1544. set
  1545. {
  1546. treatmentTime_ = value > treatmentTimeMax ? treatmentTimeMax : value < treatmentTimeMin ? treatmentTimeMin : value;
  1547. labelTreatmentTime.Content = $"{(int)treatmentTime_}:";
  1548. int sec = (int)((treatmentTime_ - (int)treatmentTime_) * 60);
  1549. if (sec < 10) labelTreatmentTime.Content += "0";
  1550. labelTreatmentTime.Content += sec.ToString();
  1551. }
  1552. }
  1553. private void increaseTreatmentTime(object sender, RoutedEventArgs e)
  1554. {
  1555. treatmentTime += 0.5f;
  1556. }
  1557. private void decreaseTreatmentTime(object sender, RoutedEventArgs e)
  1558. {
  1559. treatmentTime -= 0.5f;
  1560. }
  1561. private Com comAgent => SingleInstance<Com>.getInstance();
  1562. private bool isRunning;
  1563. private void updateUIIsRunning()
  1564. {
  1565. buttonStart.IsEnabled = !isRunning;
  1566. buttonStop.IsEnabled = isRunning;
  1567. }
  1568. private void MetroWindow_Activated(object sender, EventArgs e)
  1569. {
  1570. }
  1571. private void MetroWindow_Closing(object sender, CancelEventArgs e)
  1572. {
  1573. comAgent.shutdown();
  1574. }
  1575. private void buttonStartTreat_Click(object sender, RoutedEventArgs e)
  1576. {
  1577. //if (targetTreatment == null && !checkBoxCustomMode.IsChecked.Value)
  1578. if (targetTreatment == null)
  1579. {
  1580. MessageBox.Show("请选择或添加一个治疗方案", "", MessageBoxButton.OK, MessageBoxImage.Error);
  1581. return;
  1582. }
  1583. //if (checkBoxCustomMode.IsChecked.Value)
  1584. //{
  1585. // TreatmentStep[] steps = new TreatmentStep[treatmentCustomModeList.Count];
  1586. // for (int i = 0; i < steps.Length; i++)
  1587. // {
  1588. // steps[i] = new TreatmentStep((ushort)treatmentCustomModeList[i].tcRate,
  1589. // (byte)treatmentCustomModeList[i].tcActiveTime,
  1590. // (byte)treatmentCustomModeList[i].tcInactiveTime,
  1591. // (ushort)(treatmentCustomModeList[i].tcActiveTime + treatmentCustomModeList[i].tcInactiveTime));
  1592. // }
  1593. // comAgent.enqueueCommand(Com.createStartManualCommand(parseTreatmentTime(treatmentTime), (byte)sliderStrength.Value, steps));
  1594. //}
  1595. //else
  1596. //{
  1597. // //获取当前时间戳并转换为格式化日期 yyyy-MM-dd hh:mm:ss
  1598. // DateTime_TimeStamp dateTimeFormatter = new DateTime_TimeStamp();
  1599. // int timestamp = dateTimeFormatter.GetTimeStamp(DateTime.Now);
  1600. // DateTime now = dateTimeFormatter.GetDateTime(timestamp);
  1601. // //装配诊疗记录对象
  1602. // TreatmentRecord treatmentRecordToInsert = new TreatmentRecord();
  1603. // treatmentRecordToInsert.patient_record_id = filterPatient.p_record_id;
  1604. // treatmentRecordToInsert.patient_id = filterPatient.p_id;
  1605. // treatmentRecordToInsert.strength = Convert.ToInt32(sliderStrength.Value.ToString("0."));
  1606. // treatmentRecordToInsert.duration = treatmentTime;
  1607. // treatmentRecordToInsert.start_time = now;
  1608. // //插入诊疗记录
  1609. // int inserted_row_id = SQLiteModel.insertTreatmentRecord(treatmentRecordToInsert);
  1610. // comAgent.enqueueCommand(Com.createStartDefinedCommand(targetTreatment.id, parseTreatmentTime(treatmentTime), (byte)sliderStrength.Value));
  1611. //}
  1612. //获取当前时间戳并转换为格式化日期 yyyy-MM - dd hh: mm: ss
  1613. DateTime_TimeStamp dateTimeFormatter = new DateTime_TimeStamp();
  1614. int timestamp = dateTimeFormatter.GetTimeStamp(DateTime.Now);
  1615. DateTime now = dateTimeFormatter.GetDateTime(timestamp);
  1616. //装配诊疗记录对象
  1617. TreatmentRecord treatmentRecordToInsert = new TreatmentRecord();
  1618. treatmentRecordToInsert.patient_record_id = filterPatient.p_record_id;
  1619. treatmentRecordToInsert.patient_id = filterPatient.p_id;
  1620. treatmentRecordToInsert.strength = Convert.ToInt32(sliderStrength.Value.ToString("0."));
  1621. treatmentRecordToInsert.duration = treatmentTime;
  1622. treatmentRecordToInsert.start_time = now;
  1623. //插入诊疗记录
  1624. int inserted_row_id = SQLiteModel.insertTreatmentRecord(treatmentRecordToInsert);
  1625. comAgent.enqueueCommand(Com.createStartDefinedCommand(targetTreatment.id, parseTreatmentTime(treatmentTime), (byte)sliderStrength.Value));
  1626. isRunning = true;
  1627. updateUIIsRunning();
  1628. }
  1629. private short parseTreatmentTime(float f)
  1630. {
  1631. return (short)(f * 60);
  1632. }
  1633. private void buttonStop_Click(object sender, RoutedEventArgs e)
  1634. {
  1635. //if (checkBoxCustomMode.IsChecked.Value)
  1636. //{
  1637. // comAgent.enqueueCommand(Com.createStopCommand());
  1638. //}
  1639. //else
  1640. //{
  1641. // comAgent.enqueueCommand(Com.createStopCommand(Com.getTCIDByIndex(targetTreatment.id)));
  1642. //}
  1643. comAgent.enqueueCommand(Com.createStopCommand(Com.getTCIDByIndex(targetTreatment.id)));
  1644. isRunning = false;
  1645. updateUIIsRunning();
  1646. }
  1647. }
  1648. /// <summary>
  1649. /// C#时间戳转换为时间格式(互转)
  1650. /// 时间戳定义为从格林威治时间 1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
  1651. /// </summary>
  1652. public class DateTime_TimeStamp
  1653. {
  1654. protected int m_timestamp;
  1655. /// <summary>
  1656. /// 获取时间戳Timestamp
  1657. /// </summary>
  1658. /// <param name="dt"></param>
  1659. /// <returns></returns>
  1660. public int GetTimeStamp(DateTime dt)
  1661. {
  1662. DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
  1663. int timeStamp = Convert.ToInt32((dt - dateStart).TotalSeconds);
  1664. return timeStamp;
  1665. }
  1666. /// <summary>
  1667. /// 时间戳Timestamp转换成日期
  1668. /// </summary>
  1669. /// <param name="timeStamp"></param>
  1670. /// <returns></returns>
  1671. public DateTime GetDateTime(int timeStamp)
  1672. {
  1673. DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  1674. long lTime = ((long)timeStamp * 10000000);
  1675. TimeSpan toNow = new TimeSpan(lTime);
  1676. DateTime targetDt = dtStart.Add(toNow);
  1677. return targetDt;
  1678. }
  1679. }
  1680. }