using System; using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using System.IO; using System.Windows.Input; using MahApps.Metro.Controls; using MahApps.Metro.Controls.Dialogs; using System.Data; using WpfTest1.SQLite; using WpfTest1.Toolkits; using LitJson; using System.ComponentModel; namespace WpfTest1 { /// /// MainWindow.xaml 的交互逻辑 /// public partial class MainWindow : MetroWindow { #region 系统基本参数 System.Data.SQLite.SQLiteDataAdapter daHistoryRecord; //选择记录页面查询记录条目的数据集容器 public doctor loginDoctor = null; //所登陆的医师 DataSet ds; //其他界面的DataSet System.Data.SQLite.SQLiteDataAdapter da; //其他界面的DataAdapter //double highBp; //BP界面高压 //double lowBp; //BP界面低压 DateTime lastSettingLogin; //上一次在系统设置界面登陆的时间 public Toolkits.Config cfg; //从数据库取配置的类 DogOperator dop = new DogOperator(Constants.registerPid, Constants.registerUid); Patient filterPatient; Patient evaluationPatient; Patient historyPatient; Record filterReportForEvaluation; bool flagEvaluationWithoutFilter = true; List filterQuestionaire = new List(); List evaluationQuestionaire = new List(); List filterUserSelection = new List(); List evaluationUserSelection = new List(); string resultsFilter; string resultsEvaluation; int currentFilterCount = 0; int currentEvaluationCount = 0; List recordsFromOnePatient; BindingList bindingRecords; Dictionary mapKeyToDigit = new Dictionary(); #endregion public MainWindow() { InitializeComponent(); //加载配置 cfg = new Toolkits.Config(); //绑定三个selectUser的父类 //selectUserMeasure.setMainWindow(this); selectUserPatientManagent.setMainWindow(this); selectUserfilter.setMainWindow(this); selectUserevaluation.setMainWindow(this); selectUserHistory.setMainWindow(this); textBoxOrganizationName.Text = cfg.organization_name; } #region 初始化与系统调用部分 //初始化全部组件后需要先输入医生密码才能进入 private void MetroWindow_Loaded(object sender, RoutedEventArgs e) { //之后测试登陆 SmallDialogs.LoginWindow lw = new SmallDialogs.LoginWindow(this); lw.ShowDialog(); if(loginDoctor == null) { this.Close(); } bool registerFlag = dop.checkSoftwareRegister(); if (!registerFlag && Constants.productionEnvironment) { MessageBox.Show("未找到硬件授权Key,请确认插入后重试", "错误"); this.Close(); } //显示医生姓名 if (loginDoctor != null) { loginedDoctorName.Content = "欢迎您, " + loginDoctor.name; return; } loadQuestionaire(filterQuestionaire, "filter"); loadQuestionaire(evaluationQuestionaire, "evaluation"); labelHomepageCversion.Content = "编译日期:" + Toolkits.Constants.compileDate; labelSoftwareName.Content = String.Format("欢迎使用{0}", Constants.softwareName); } private void loadQuestionaire(List oneQuestionaire, string type = "filter") { oneQuestionaire.Clear(); List questions = SQLite.SQLiteModel.getQuestions(type); foreach (Question oneQuestion in questions) { List answers = SQLite.SQLiteModel.getAnswersByQid(oneQuestion.q_id); QuestionAnswerPair temp = new QuestionAnswerPair(oneQuestion, answers); oneQuestionaire.Add(temp); } } /// /// 筛查或评估流程页面识别快捷键的操作 /// /// 默认 /// 默认 private void processGrid_KeyDown(object sender, KeyEventArgs e) { //System.Console.WriteLine(String.Format("KeyDown detected. {0} is detected.", e.Key.ToString())); if (tabControlGeneral.SelectedIndex == 2 && tabFilter.SelectedIndex == 1) { //筛查流程中 if (e.Key == Key.N && buttonFilterNext.IsEnabled) { buttonFilterNext_Click(sender, (RoutedEventArgs)e); return; } if (e.Key == Key.P && buttonFilterPrevious.IsEnabled) { buttonFilterPrevious_Click(sender, (RoutedEventArgs)e); return; } if (e.Key == Key.E) { buttonAbortFilter_Click(sender, (RoutedEventArgs)e); return; } if(e.Key == Key.S && buttonSubmitFilter.IsEnabled) { buttonSubmitFilter_Click(sender, (RoutedEventArgs)e); return; } if (Constants.keyboardToDigit.ContainsKey(e.Key.ToString())) { int numInput = Constants.keyboardToDigit[e.Key.ToString()]; try { RadioButton rbTemp = (RadioButton)gridFilterSelection.Children[numInput - 1]; rbTemp.IsChecked = true; radioButtonFilter_Checked(rbTemp, e); } catch (Exception) { return; } return; } } else if(tabControlGeneral.SelectedIndex == 3 && tabEvaluation.SelectedIndex == 1) { //评估流程中 if (e.Key == Key.N && buttonEvaluationNext.IsEnabled) { buttonEvaluationNext_Click(sender, (RoutedEventArgs)e); return; } if (e.Key == Key.E) { buttonAbortEvaluation_Click(sender, (RoutedEventArgs)e); return; } if (e.Key == Key.S && buttonSubmitEvaluation.IsEnabled) { buttonSubmitEvaluation_Click(sender, (RoutedEventArgs)e); return; } if (Constants.keyboardToDigit.ContainsKey(e.Key.ToString())) { int numInput = Constants.keyboardToDigit[e.Key.ToString()]; try { RadioButton rbTemp = (RadioButton)gridEvaluationSelection.Children[numInput - 1]; rbTemp.IsChecked = true; radioButtonEvaluation_Checked(rbTemp, e); } catch (Exception) { return; } } } else { return; } } #endregion #region 首页功能 //标题栏快速添加病例的接口 private void Fast_Add_Patient_Button_Click(object sender, RoutedEventArgs e) { buttonAddPatient_Click(this, e); } //首页--新建用户 private void buttonHomePageAddPatient_Click(object sender, RoutedEventArgs e) { buttonAddPatient_Click(this, e); } //首页--用户管理 private void buttonHomePagePatientManagent_Click(object sender, RoutedEventArgs e) { tabControlGeneral.SelectedIndex = 1; } private void buttonHomePageFilterFunction_Click(object sender, RoutedEventArgs e) { tabControlGeneral.SelectedIndex = 2; } private void buttonHomePageEvaluationFunction_Click(object sender, RoutedEventArgs e) { tabControlGeneral.SelectedIndex = 3; } //首页--检测报告 private void buttonHomeHistoryRecords_Click(object sender, RoutedEventArgs e) { tabControlGeneral.SelectedIndex = 4; } //首页--系统设置 private void buttonHomePageSystemSettings_Click(object sender, RoutedEventArgs e) { tabControlGeneral.SelectedIndex = 5; } //关于程序 private void buttonHomePageDataTransfer_Click(object sender, RoutedEventArgs e) { SmallDialogs.AboutBox ab = new SmallDialogs.AboutBox(); ab.Show(); } //首页--操作帮助 private void buttonHomePageHelp_Click(object sender, RoutedEventArgs e) { System.Diagnostics.Process.Start("https://www.baidu.com"); } #endregion #region 病例管理 //病例管理 //病例管理--病例管理 #region 病例管理--添加病例 //添加病例 private void buttonAddPatient_Click(object sender, RoutedEventArgs e) { AddPatient a_new_one = new AddPatient(this); a_new_one.Show(); //selectUserPatientManagent.LoadDataGrid(); } #endregion #region 病例管理--修改病例 //修改病例 public void buttonModifyPatient_Click(object sender, RoutedEventArgs e) { try { var target = (DataRowView)this.selectUserPatientManagent.dataGrid.SelectedItem; //MessageBox.Show(target["id"].ToString()); ModifyUser modify_one = new ModifyUser(this, target["p_id"].ToString()); modify_one.Show(); } catch(Exception err) { //this.ShowMessageAsync("警告","请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace ); MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace,"警告"); } } #endregion #region 病例管理--删除病例 //删除病例 private void buttonDeletePatient_Click(object sender, RoutedEventArgs e) { try { var target = (DataRowView)this.selectUserPatientManagent.dataGrid.SelectedItem; if(target == null) { MessageBox.Show("请选择一个病例进行删除", "提示"); return; } MessageBoxResult clickresult = MessageBox.Show("确认删除该病例?", "提示", MessageBoxButton.OKCancel); if (clickresult == MessageBoxResult.OK) { int status = SQLite.SQLiteModel.DeletePatientItem(target["p_id"].ToString()); if (status > 0) { MessageBox.Show("删除成功","提示"); } else { MessageBox.Show("已删除", "提示"); } } else if (clickresult == MessageBoxResult.Cancel) { return; } } catch (Exception err) { MessageBox.Show("数据库故障\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误"); } selectUserPatientManagent.LoadDataGrid(); } #endregion #endregion #region 筛查功能 /// /// 点击开始筛查后触发的事件 /// /// 默认 /// 默认 public void buttonFilterSelectPatient_Click(object sender, RoutedEventArgs e) { try { var target = (DataRowView)this.selectUserfilter.dataGrid.SelectedItem; filterPatient = SQLite.SQLiteModel.getPatientById(target["p_id"].ToString()); } catch (Exception err) { MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "警告"); return; } if(filterPatient == null) { MessageBox.Show("数据库加载异常", "错误"); return; } try { loadQuestionaire(filterQuestionaire, "filter"); filterUserSelection.Clear(); foreach(QuestionAnswerPair qa in filterQuestionaire) { filterUserSelection.Add(new UserSelection(qa.question.q_id, 0)); } } catch (Exception err) { MessageBox.Show("筛查题目加载失败\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误"); return; } if(filterQuestionaire.Count == 0) { MessageBox.Show("筛查题目加载失败\r\n数据库中无有效问卷", "错误"); return; } currentFilterCount = 1; loadQuestionViewFilter(currentFilterCount); tabFilter.SelectedIndex += 1; } /// /// 点击中止筛查后触发的事件 /// /// 默认 /// 默认 private void buttonAbortFilter_Click(object sender, RoutedEventArgs e) { filterUserSelection.Clear(); filterPatient = null; resultsFilter = ""; currentFilterCount = 0; buttonFilterPrevious.IsEnabled = false; buttonFilterNext.IsEnabled = false; buttonSubmitFilter.IsEnabled = false; tabFilter.SelectedIndex = 0; } /// /// 点击筛查上一步后触发的事件 /// /// 默认 /// 默认 private void buttonFilterPrevious_Click(object sender, RoutedEventArgs e) { currentFilterCount -= 1; loadQuestionViewFilter(currentFilterCount); checkFilterButtonStatues(); } /// /// 点击筛查下一步后触发的事件 /// /// 默认 /// 默认 private void buttonFilterNext_Click(object sender, RoutedEventArgs e) { currentFilterCount += 1; loadQuestionViewFilter(currentFilterCount); checkFilterButtonStatues(); } /// /// 确认筛查阶段各个按钮应当处于的状态 /// private void checkFilterButtonStatues() { bool radioCheckFlag = false; foreach(RadioButton rb in gridFilterSelection.Children){ if(rb.IsChecked == true) { radioCheckFlag = true; } } if (radioCheckFlag && currentFilterCount < filterQuestionaire.Count) buttonFilterNext.IsEnabled = true; else buttonFilterNext.IsEnabled = false; if (currentFilterCount > 1) buttonFilterPrevious.IsEnabled = true; else buttonFilterPrevious.IsEnabled = false; bool allFilledFlag = true; foreach (UserSelection us in filterUserSelection) { if (us.a_id == 0) allFilledFlag = false; } if (allFilledFlag) buttonSubmitFilter.IsEnabled = true; else buttonSubmitFilter.IsEnabled = false; } /// /// 加载题目和选项界面 /// private void loadQuestionViewFilter(int currentIndex) { labelFilterNumberofTotalQuestions.Content = filterQuestionaire.Count.ToString(); labelFilterNumberofCurrentQuestion.Content = currentIndex.ToString(); labelFilterQuestionTitle.Content = filterQuestionaire[currentIndex - 1].question.q_title; textBlockFilterQuetionContent.Text = filterQuestionaire[currentIndex - 1].question.q_content; int countOptions = filterQuestionaire[currentIndex - 1].answers.Count; gridFilterSelection.Children.Clear(); for (int i = 0; i< countOptions; ++i) { RadioButton oneOption = new RadioButton(); oneOption.Height = 30; oneOption.HorizontalAlignment = HorizontalAlignment.Left; oneOption.VerticalAlignment = VerticalAlignment.Top; oneOption.Margin = new Thickness(i/5*200, i%5*40, 0, 0); if(filterUserSelection[currentIndex-1].a_id == filterQuestionaire[currentIndex - 1].answers[i].a_id) oneOption.IsChecked = true; else oneOption.IsChecked = false; oneOption.Content = String.Format("[选项{0}]:{1}", i+1, filterQuestionaire[currentIndex - 1].answers[i].a_content) ; oneOption.Checked += radioButtonFilter_Checked; oneOption.GroupName = "filterOption"; oneOption.FontSize = 18; oneOption.Name = "rbf" + filterQuestionaire[currentIndex - 1].answers[i].a_id.ToString(); gridFilterSelection.Children.Add(oneOption); } } private void radioButtonFilter_Checked(object sender, RoutedEventArgs e) { //首先,记录该选择 RadioButton oneSelection = (RadioButton)sender; filterUserSelection[currentFilterCount - 1].a_id = Convert.ToInt32(oneSelection.Name.Substring(3)); //MessageBox.Show(filterUserSelection[currentFilterCount - 1].a_id.ToString()); //然后,确认各个按钮状态 checkFilterButtonStatues(); } /// /// 点击筛查提交后触发的事件 /// /// 默认 /// 默认 private void buttonSubmitFilter_Click(object sender, RoutedEventArgs e) { int[] timesLimit = dop.getTimesCount(); if(Constants.productionEnvironment && timesLimit[1] > timesLimit[0]) { MessageBox.Show("此功能已超过Key授权次数,请使用一个新的Key进行操作。", "提示"); return; } int inserted_r_id; resultsFilter = JsonMapper.ToJson(filterUserSelection); //MessageBox.Show(results); try { inserted_r_id = SQLiteModel.insertRecord(1, filterPatient.p_id, loginDoctor.id, 0, DateTime.Now, 0, resultsFilter); SQLiteModel.UpdatePatientDataWithLastDate(filterPatient.p_id, "p_last_filter_time", DateTime.Now); } catch (Exception err) { MessageBox.Show("储存筛查报告错误\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误"); return; } dop.addOneCount(); MessageBoxResult dr = MessageBox.Show("保存筛查结果成功,是否生成报告?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (dr == MessageBoxResult.OK) { try { Record targetRecord = SQLiteModel.getRecordByID(inserted_r_id); ReportGenerater.generateReport(1, filterPatient, loginDoctor, targetRecord, cfg.organization_name); SQLiteModel.plusOneCountOnRecordByRid(inserted_r_id); } catch (Exception err) { MessageBox.Show("报告生成异常,可能是这份报告当前已被打开无法写入,请尝试关闭该报告后重试。\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误"); return; } tabFilter.SelectedIndex = 2; } else { buttonAbortFilter_Click(sender, e); } return; } /// /// 返回至选择用户页 /// /// 默认 /// 默认 private void buttonFilterBackToSelectUser_Click(object sender, RoutedEventArgs e) { buttonAbortFilter_Click(sender, e); } /// /// 返回至选择首页 /// /// 默认 /// 默认 private void buttonFilterBackToHome_Click(object sender, RoutedEventArgs e) { buttonAbortFilter_Click(sender, e); tabControlGeneral.SelectedIndex = 0; } #endregion #region 评估功能 /// /// 点击开始评估后触发的事件 /// /// 默认 /// 默认 public void buttonEvaluationSelectPatient_Click(object sender, RoutedEventArgs e) { //基本逻辑如下:先找七天内与病例相匹配的筛查记录,如果有,那么要取出结果一题一题比对 //如果没有,那么应当把筛查题进行加载处理 try { var target = (DataRowView)this.selectUserevaluation.dataGrid.SelectedItem; evaluationPatient = SQLite.SQLiteModel.getPatientById(target["p_id"].ToString()); } catch (Exception err) { MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "警告"); return; } if (evaluationPatient == null) { MessageBox.Show("数据库加载异常", "错误"); return; } try { loadQuestionaire(filterQuestionaire, "filter"); evaluationQuestionaire.Clear(); filterUserSelection.Clear(); evaluationUserSelection.Clear(); //这里尝试加载用户的筛查记录 filterReportForEvaluation = SQLiteModel.getLatestXTypeRecordInYDays(evaluationPatient.p_id, 1, 7); if(filterReportForEvaluation == null) { flagEvaluationWithoutFilter = true; foreach (QuestionAnswerPair qa in filterQuestionaire) { filterUserSelection.Add(new UserSelection(qa.question.q_id, 0)); } } else { var jsonUserSelections = filterReportForEvaluation.r_selection; filterUserSelection = JsonMapper.ToObject>(jsonUserSelections); flagEvaluationWithoutFilter = false; } } catch (Exception err) { MessageBox.Show("筛查题目加载失败\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误"); return; } if (filterQuestionaire.Count == 0) { MessageBox.Show("筛查题目加载失败\r\n数据库中无有效问卷", "错误"); return; } if (flagEvaluationWithoutFilter) { MessageBox.Show("发现该病例一周内未进行初筛,评估过程中将自动进行初筛。","提示"); } else { MessageBox.Show("发现该病例于"+ filterReportForEvaluation.r_time.ToString("yyyy-MM-dd HH:mm:ss") +"进行过初筛,评估过程中将使用此初筛结果。", "提示"); } currentFilterCount = 1; currentEvaluationCount = 1; evaluationQuestionaire.Add(filterQuestionaire[currentFilterCount - 1]); evaluationUserSelection.Add(filterUserSelection[currentFilterCount - 1]); tabEvaluation.SelectedIndex += 1; checkStatusEvaluation(); } /// /// 加载currentIndex的评估题目功能 /// /// 需要显示题目的题号 private void loadQuestionViewEvaluation(int currentIndex) { labelQuestionNumberofCurrentQuestion.Content = currentIndex.ToString(); labelEvaluationQuestionTitle.Content = evaluationQuestionaire[currentIndex - 1].question.q_title; textBlockEvaluationQuetionContent.Text = evaluationQuestionaire[currentIndex - 1].question.q_content; int countOptions = evaluationQuestionaire[currentIndex - 1].answers.Count; gridEvaluationSelection.Children.Clear(); for (int i = 0; i < countOptions; ++i) { RadioButton oneOption = new RadioButton(); oneOption.Height = 30; oneOption.HorizontalAlignment = HorizontalAlignment.Left; oneOption.VerticalAlignment = VerticalAlignment.Top; oneOption.Margin = new Thickness(i / 5 * 200, i % 5 * 40, 0, 0); if (evaluationUserSelection[currentIndex - 1].a_id == evaluationQuestionaire[currentIndex - 1].answers[i].a_id) oneOption.IsChecked = true; else oneOption.IsChecked = false; oneOption.Content = String.Format("[选项{0}]:{1}", i + 1, evaluationQuestionaire[currentIndex - 1].answers[i].a_content); oneOption.Checked += radioButtonEvaluation_Checked; oneOption.GroupName = "evaluationOption"; oneOption.FontSize = 18; oneOption.Name = "rbe" + evaluationQuestionaire[currentIndex - 1].answers[i].a_id.ToString(); gridEvaluationSelection.Children.Add(oneOption); } } /// /// 检查当前答题状态,判断是否需要跳过该题和控制加载题目的功能,能够维护userselection和questionaire /// private void checkStatusEvaluation() { if(!flagEvaluationWithoutFilter && evaluationQuestionaire[currentEvaluationCount-1].question.q_type == 1) { //有预加载的筛查报告且当前问题是一道筛查题 Answer aTemp = SQLiteModel.getAnswerById(filterUserSelection[currentFilterCount - 1].a_id); if (aTemp == null || aTemp.next_q_id == 0) { if(currentFilterCount == filterQuestionaire.Count) { //当前所有题目都已经做完了 buttonEvaluationNext.IsEnabled = false; bool allQuestionAreSeleceted = true; foreach (UserSelection us in evaluationUserSelection) { if (us.a_id == 0) allQuestionAreSeleceted = false; } //经过检查可以提交 buttonSubmitEvaluation.IsEnabled = allQuestionAreSeleceted; } else { //还有剩下的筛选题没有过 QuestionAnswerPair qaPairEvaluation = filterQuestionaire[currentFilterCount]; //当前元素后面的题目和选项都清空 for (int i = evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i) { evaluationQuestionaire.RemoveAt(i); evaluationUserSelection.RemoveAt(i); } evaluationQuestionaire.Add(qaPairEvaluation); evaluationUserSelection.Add(filterUserSelection[currentFilterCount]); //再刷新一次 ++currentFilterCount; ++currentEvaluationCount; checkStatusEvaluation(); } } else { //否则还有评估题没做 Question aEvaluationQuestion = SQLiteModel.getQuestionById(aTemp.next_q_id); List answersToTheEvaluation = SQLiteModel.getAnswersByQid(aEvaluationQuestion.q_id); QuestionAnswerPair qaPairEvaluation = new QuestionAnswerPair(aEvaluationQuestion, answersToTheEvaluation); //当前元素后面的题目和选项都清空 for(int i= evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i) { evaluationQuestionaire.RemoveAt(i); evaluationUserSelection.RemoveAt(i); } evaluationQuestionaire.Add(qaPairEvaluation); evaluationUserSelection.Add(new UserSelection(aEvaluationQuestion.q_id, 0)); //再刷新一次 ++currentEvaluationCount; checkStatusEvaluation(); } } else { //其他情况:没有预加载的筛选题或者有预加载的筛选题但是是一道评估题 loadQuestionViewEvaluation(currentEvaluationCount); buttonEvaluationNext.IsEnabled = false; buttonSubmitEvaluation.IsEnabled = false; } } /// /// 评估单选选项被选中的触发事件,主要是修改内存中的选择和判断下一题及提交按钮是否可用 /// /// 默认 /// 默认 private void radioButtonEvaluation_Checked(object sender, RoutedEventArgs e) { //首先,记录该选择 RadioButton oneSelection = (RadioButton)sender; evaluationUserSelection[currentEvaluationCount - 1].a_id = Convert.ToInt32(oneSelection.Name.Substring(3)); if (flagEvaluationWithoutFilter && evaluationQuestionaire[currentEvaluationCount-1].question.q_type ==1) { filterUserSelection[currentFilterCount - 1].a_id = Convert.ToInt32(oneSelection.Name.Substring(3)); } //MessageBox.Show(filterUserSelection[currentFilterCount - 1].a_id.ToString()); Answer oneAnswer = SQLiteModel.getAnswerById(evaluationUserSelection[currentEvaluationCount - 1].a_id); if(currentFilterCount == filterQuestionaire.Count && oneAnswer.next_q_id == 0) { //后面没有题目了,可以提交 buttonEvaluationNext.IsEnabled = false; bool allQuestionAreSeleceted = true; foreach (UserSelection us in evaluationUserSelection) { if (us.a_id == 0) allQuestionAreSeleceted = false; } //经过检查可以提交 buttonSubmitEvaluation.IsEnabled = allQuestionAreSeleceted; } else { //否则可以做下一题 buttonEvaluationNext.IsEnabled = true; buttonSubmitEvaluation.IsEnabled = false; } } /// /// (未实现)评估过程中点击上一题的触发事件 /// /// 默认 /// 默认 private void buttonEvaluationPrevious_Click(object sender, RoutedEventArgs e) { } /// /// 点击评估页下一题后触发的事件,主要是判断接下来加载哪一题 /// /// 默认 /// 默认 private void buttonEvaluationNext_Click(object sender, RoutedEventArgs e) { //先看看后面有没有进退阶题目了 Answer oneAnswer = SQLiteModel.getAnswerById(evaluationUserSelection[currentEvaluationCount - 1].a_id); if(oneAnswer.next_q_id!= 0) { //还有后续题目 Question aEvaluationQuestion = SQLiteModel.getQuestionById(oneAnswer.next_q_id); List answersToTheEvaluation = SQLiteModel.getAnswersByQid(aEvaluationQuestion.q_id); QuestionAnswerPair qaPairEvaluation = new QuestionAnswerPair(aEvaluationQuestion, answersToTheEvaluation); //当前元素后面的题目和选项都清空 for (int i = evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i) { evaluationQuestionaire.RemoveAt(i); evaluationUserSelection.RemoveAt(i); } evaluationQuestionaire.Add(qaPairEvaluation); evaluationUserSelection.Add(new UserSelection(aEvaluationQuestion.q_id, 0)); //再刷新一次 ++currentEvaluationCount; checkStatusEvaluation(); } else { //否则跳到下一个筛选题上面 QuestionAnswerPair qaPairEvaluation = filterQuestionaire[currentFilterCount]; //当前元素后面的题目和选项都清空 for (int i = evaluationQuestionaire.Count - 1; i > currentEvaluationCount - 1; --i) { evaluationQuestionaire.RemoveAt(i); evaluationUserSelection.RemoveAt(i); } evaluationQuestionaire.Add(qaPairEvaluation); evaluationUserSelection.Add(filterUserSelection[currentFilterCount]); //再刷新一次 ++currentFilterCount; ++currentEvaluationCount; checkStatusEvaluation(); } } /// /// 点击评估页提交后触发的事件 /// /// 默认 /// 默认 private void buttonSubmitEvaluation_Click(object sender, RoutedEventArgs e) { int[] timesLimit = dop.getTimesCount(); if (Constants.productionEnvironment && timesLimit[1] > timesLimit[0]) { MessageBox.Show("此功能已超过Key授权次数,请使用一个新的Key进行操作。", "提示"); return; } int inserted_r_id; resultsFilter = JsonMapper.ToJson(filterUserSelection); resultsEvaluation = JsonMapper.ToJson(evaluationUserSelection); try { int tempRId; if (flagEvaluationWithoutFilter) { tempRId = SQLiteModel.insertRecord(1, evaluationPatient.p_id, loginDoctor.id, 0, DateTime.Now, 0, resultsFilter); SQLiteModel.UpdatePatientDataWithLastDate(evaluationPatient.p_id, "p_last_filter_time", DateTime.Now); } else { tempRId = filterReportForEvaluation.r_id; } inserted_r_id = SQLiteModel.insertRecord(2, evaluationPatient.p_id, loginDoctor.id, tempRId, DateTime.Now, 0, resultsEvaluation); SQLiteModel.UpdatePatientDataWithLastDate(evaluationPatient.p_id, "p_last_evaluation_time", DateTime.Now); } catch (Exception err) { MessageBox.Show("储存筛查报告错误\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误"); return; } dop.addOneCount(); MessageBoxResult dr = MessageBox.Show("保存成功,是否生成报告?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question); if (dr == MessageBoxResult.OK) { try { Record targetRecord = SQLiteModel.getRecordByID(inserted_r_id); SQLiteModel.plusOneCountOnRecordByRid(inserted_r_id); ReportGenerater.generateReport(2, evaluationPatient, loginDoctor, targetRecord, cfg.organization_name); } catch (Exception err) { MessageBox.Show("报告生成异常,可能是这份报告当前已被打开无法写入,请尝试关闭该报告后重试。\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "错误"); return; } tabEvaluation.SelectedIndex = 2; } else { buttonAbortEvaluation_Click(sender, e); } return; } /// /// 点击评估页中止评估后触发的事件 /// /// 默认 /// 默认 private void buttonAbortEvaluation_Click(object sender, RoutedEventArgs e) { //清理相关变量 filterQuestionaire.Clear(); filterUserSelection.Clear(); evaluationQuestionaire.Clear(); evaluationUserSelection.Clear(); flagEvaluationWithoutFilter = true; filterReportForEvaluation = null; evaluationPatient = null; resultsFilter = ""; resultsEvaluation = ""; currentFilterCount = 0; currentEvaluationCount = 0; //buttonFilterPrevious.IsEnabled = false; buttonEvaluationNext.IsEnabled = false; buttonSubmitEvaluation.IsEnabled = false; tabEvaluation.SelectedIndex = 0; } /// /// 返回至选择用户页 /// /// 默认 /// 默认 private void buttonEvaluationBackToSelectUser_Click(object sender, RoutedEventArgs e) { buttonAbortEvaluation_Click(sender, e); } /// /// 返回至选择首页 /// /// 默认 /// 默认 private void buttonEvaluationBackToHome_Click(object sender, RoutedEventArgs e) { buttonAbortEvaluation_Click(sender, e); tabControlGeneral.SelectedIndex = 0; } #endregion #region 历史记录 /// /// 点击选择病例查看其历史记录后触发的事件 /// /// 默认 /// 默认 public void buttonHistorySelectPatient_Click(object sender, RoutedEventArgs e) { try { var target = (DataRowView)this.selectUserHistory.dataGrid.SelectedItem; historyPatient = SQLiteModel.getPatientById(Convert.ToString(target["p_id"])); recordsFromOnePatient = SQLiteModel.getRecordsByPid(Convert.ToInt32(target["p_id"])); } catch (Exception err) { MessageBox.Show("请选择一个病例进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace, "警告"); return; } if (recordsFromOnePatient == null || historyPatient == null) { MessageBox.Show("数据库加载异常", "错误"); return; } try { bindingRecords = new BindingList(recordsFromOnePatient); dataGridRecords.ItemsSource = bindingRecords; } catch(Exception err) { MessageBox.Show("数据库加载异常\r\n调试信息:\r\n"+err.StackTrace, "错误"); return; } tabHistoryRecords.SelectedIndex = 1; } /// /// 在选择记录页面,点击返回上一级触发的事件 /// /// 默认 /// 默认 private void buttonHistoryBackToSelectUser_Click(object sender, RoutedEventArgs e) { recordsFromOnePatient.Clear(); tabHistoryRecords.SelectedIndex = 0; } /// /// 由历史记录相关页面返回至首页的事件 /// /// 默认 /// 默认 private void buttonHistoryBackToHome_Click(object sender, RoutedEventArgs e) { recordsFromOnePatient.Clear(); tabHistoryRecords.SelectedIndex = 0; tabControlGeneral.SelectedIndex = 0; } /// /// 点击生成报告的页面 /// /// 默认 /// 默认 private void buttonRegenerateReport_Click(object sender, RoutedEventArgs e) { Record targetRecord; try { var target = this.dataGridRecords.SelectedItem as Record; targetRecord = SQLiteModel.getRecordByID(Convert.ToInt32(target.r_id)); } catch (Exception err) { MessageBox.Show("请选择一个记录进行生成\r\n" + err.StackTrace, "提示"); return; } if (targetRecord == null) { MessageBox.Show("数据库加载异常", "错误"); return; } try { ReportGenerater.generateReport(targetRecord.r_type, historyPatient, loginDoctor, targetRecord, cfg.organization_name); SQLiteModel.plusOneCountOnRecordByRid(targetRecord.r_id); } catch(Exception err) { MessageBox.Show("报告生成异常,可能是这份报告当前已被打开无法写入,请尝试关闭该报告后重试。\r\n调试信息:\r\n" + err.StackTrace, "错误"); return; } tabHistoryRecords.SelectedIndex = 2; } /// /// 从报告生成页点击返回上一页的事件 /// /// 默认 /// 默认 private void buttonHistoryBackToSelectRecord_Click(object sender, RoutedEventArgs e) { tabHistoryRecords.SelectedIndex = 1; } /// /// 双击报告也要生成报告的功能 /// /// 默认 /// 默认 private void dataGridRecords_MouseDoubleClick(object sender, MouseButtonEventArgs e) { buttonRegenerateReport_Click(sender, e); } #endregion #region 系统设置 //系统设置 //进入系统设置前主任级别用户的身份验证 async private void tabControlGeneral_SelectionChanged(object sender, SelectionChangedEventArgs e) { //System.Console.WriteLine(Convert.ToString(tabControlGeneral.SelectedIndex)); if (e.Source is TabControl) { //系统设置页验证 if (tabitemDoctorSetting.IsSelected) { DateTime now = DateTime.Now; if (lastSettingLogin != null && (now - lastSettingLogin).Minutes <= 10) { //如果上次有登陆而且登陆时间在10分钟以内,则免登陆 return; } bool dialogLoop = true; bool wrongPassword = false; string description; int x = 1; while (dialogLoop) { x++; if (wrongPassword) { description = "用户名或密码不正确,请重新输入账号和密码进入系统设置"; } else { description = "请输入账号和密码进入系统设置"; } LoginDialogData loginDialogData; loginDialogData = await this.ShowLoginAsync ( "输入科室主任级别账号密码以继续..." + Convert.ToString(x), description, new LoginDialogSettings { ColorScheme = MetroDialogColorScheme.Accented, UsernameWatermark = "用户名", PasswordWatermark = "密码", NegativeButtonVisibility = Visibility.Visible } ); if (loginDialogData == null) { dialogLoop = false; tabControlGeneral.SelectedIndex = 0; return; //break; } //调用数据库验证 string doctorName = loginDialogData.Username; string doctorPassword = loginDialogData.Password; string doctorPWD = Toolkits.ComputeHash.GetMD5(doctorPassword); doctor loginDirector = SQLiteModel.directorLogin(doctorName, doctorPWD); if (loginDirector == null) { //MessageBox.Show("admin"); wrongPassword = true; dialogLoop = true; } else { lastSettingLogin = DateTime.Now; dialogLoop = false; return; //break; } } } //高级系统设置验证页 //if (tabitemOEMSetting.IsSelected) } } private void tabControlSystemSetting_SelectionChanged(object sender, SelectionChangedEventArgs e) { lastSettingLogin = DateTime.Now; } #region 医师管理 //系统设置--医师管理 private void LoadDoctorDataGrid(object sender, RoutedEventArgs e) { LoadDoctorDataGrid(); } public void LoadDoctorDataGrid() { //连接字符串 string Connstr = Toolkits.Constants.Connstr; //连接对象 System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(Connstr); //Sql语句 string selectCmd = "SELECT * FROM Doctor WHERE delete_flag=0 AND name != '" + Constants.adminUsername + "' LIMIT 100"; con.Open(); da = new System.Data.SQLite.SQLiteDataAdapter(selectCmd, con); ds = new DataSet(); da.Fill(ds); dataGridDoctor.ItemsSource = ds.Tables[0].DefaultView; con.Close(); } //新增医师 private void buttonAddDoctor_Click(object sender, RoutedEventArgs e) { AddDoctor a_new_doctor = new AddDoctor(this); a_new_doctor.Show(); } //修改医师 private void buttonChangeDoctor_Click(object sender, RoutedEventArgs e) { try { var target = (DataRowView)this.dataGridDoctor.SelectedItem; //MessageBox.Show(target["id"].ToString()); ModifyDoctor modify_one = new ModifyDoctor(this, target["id"].ToString()); modify_one.Show(); } catch (Exception err) { this.ShowMessageAsync("警告", "请选择一个医生进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace); } } //双击表格触发修改医师的方法 private void dataGridDoctor_MouseDoubleClick(object sender, MouseButtonEventArgs e) { buttonChangeDoctor_Click(this, e); } //修改医师密码 private void buttonChangeDoctorPWD_Click(object sender, RoutedEventArgs e) { try { var target = (DataRowView)this.dataGridDoctor.SelectedItem; //MessageBox.Show(target["id"].ToString()); ModifyDoctorPWD modify_one = new ModifyDoctorPWD(this, target["id"].ToString()); modify_one.Show(); } catch (Exception err) { this.ShowMessageAsync("警告", "请选择一个医生进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace); } } //删除医师 private async void buttonDeleteDoctor_Click(object sender, RoutedEventArgs e) { try { var target = (DataRowView)this.dataGridDoctor.SelectedItem; if (target == null) { await this.ShowMessageAsync("提示", "请选择一个医生进行删除"); return; } MessageDialogResult clickresult = await this.ShowMessageAsync("提示", "确认删除该医生信息吗?", MessageDialogStyle.AffirmativeAndNegative); if (clickresult == MessageDialogResult.Affirmative)//确认 { int status = SQLite.SQLiteModel.DeleteDoctorItem(target["id"].ToString()); if (status > 0) { await this.ShowMessageAsync("提示", "删除成功!"); } else { await this.ShowMessageAsync("警告", "目标已被删除"); } } else//取消 { return; } } catch (Exception err) { await this.ShowMessageAsync("警告", "请选择一个医生进行删除!\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace); } LoadDoctorDataGrid(); } //筛选医师 private void buttonFindDoctor_Click(object sender, RoutedEventArgs e) { try { //连接字符串 string Connstr = "Data Source=" + System.Environment.CurrentDirectory + "\\Junde.db3"; ; //连接对象 System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(Connstr); string namelike = textBoxFindDoctor.Text; //MessageBox.Show(namelike); //Sql语句 string selectCmd = "SELECT * FROM Doctor WHERE NAME LIKE \'%" + namelike + "%\' AND delete_flag=0 LIMIT 100"; con.Open(); System.Data.SQLite.SQLiteDataAdapter da_1 = new System.Data.SQLite.SQLiteDataAdapter(selectCmd, con); DataSet ds_1 = new DataSet(); da_1.Fill(ds_1); dataGridDoctor.ItemsSource = ds_1.Tables[0].DefaultView; con.Close(); } catch (Exception err) { MessageBox.Show("数据库错误.\r\n调试信息:" + err.Message, "错误"); } } #endregion #region 其他设置 /// /// 更换医疗机构名称 /// /// 默认 /// 默认 private void buttonModifyRegisterInfo_Click(object sender, RoutedEventArgs e) { try { SQLiteModel.UpdateOrganizationName(Toolkits.FilterDangerousCharacter.filter(textBoxOrganizationName.Text)); } catch (Exception) { MessageBox.Show("更新失败!", "错误"); } MessageBox.Show("更新成功", "提示"); } /// /// buttonOptmizeDatabase_Click:点击优化数据库的方法,把已经被删除的数据进行彻底清除 /// /// 默认 /// 默认 private void buttonOptmizeDatabase_Click(object sender, RoutedEventArgs e) { try { //获取标记为删除的病人记录 List ids_to_be_deleted = SQLite.SQLiteModel.getDeletedPatients(); //确实删除这些病人记录 SQLite.SQLiteModel.realDeleteRecords(); //确实删除这些病人所含有的检查记录 foreach(int each_line in ids_to_be_deleted) { SQLite.SQLiteModel.deleteRecordByPid(each_line); } //SQLiteModel.optmizeDatabase(); MessageBox.Show("操作完成", "信息"); } catch (Exception err) { MessageBox.Show("数据库异常\r\b"+err.Message+"\r\b"+err.StackTrace, "错误"); } } /// /// buttonDeleteAllPdfReport_Click:点击删除某一目录下所有文件的方法 /// /// 默认 /// 默认 private void buttonDeleteFiles_Click(object sender, RoutedEventArgs e) { string target_path = ""; if (((Button)sender).Equals(buttonDeleteAllPdfReport)) { target_path = Constants.reportPath; } try { DirectoryInfo dir = new DirectoryInfo(target_path); FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录 foreach (FileSystemInfo i in fileinfo) { if (i is DirectoryInfo) //判断是否文件夹 { DirectoryInfo subdir = new DirectoryInfo(i.FullName); subdir.Delete(true); //删除子目录和文件 } else { File.Delete(i.FullName); //删除指定文件 } } MessageBox.Show("操作完成", "信息"); } catch (Exception) { MessageBox.Show("文件系统异常", "错误"); } } #endregion #endregion } }