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; using System.Windows.Media.Imaging; using System.Windows.Documents; using System.Windows.Media; using WpfTest1.ComAgent; using System.Collections; using Com = WpfTest1.ComAgent.ComAgent; using System.Diagnostics; 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(); Treatment targetTreatment = null; List treatmentCustomModeList; //DataTable treatmentCustomDataTable; #endregion public MainWindow() { InitializeComponent(); //加载配置 cfg = new Toolkits.Config(); //绑定三个selectUser的父类 //selectUserMeasure.setMainWindow(this); selectUserPatientManagent.setMainWindow(this); selectUserfilter.setMainWindow(this); selectUserevaluation.setMainWindow(this); selectUserHistory.setMainWindow(this); treatmentPlanPage.setMainWindow(this); textBoxOrganizationName.Text = cfg.organization_name; } #region 初始化与系统调用部分 //初始化全部组件后需要先输入医生密码才能进入 private void mainWndGrid_Loaded(object sender, RoutedEventArgs e) { //Application.Current.Dispatcher.UnhandledException += Dispatcher_UnhandledException; labelHomepageCversion.Content = "编译日期:" + Toolkits.Constants.compileDate; labelSoftwareName.Content = String.Format("欢迎使用{0}", Constants.softwareName); //之后测试登录 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(); } loadUSBDogStatus(); string datestr = "2050-12-31 00:00:00"; DateTime dtStandard = DateTime.Parse(datestr); DateTime now = DateTime.Now; if(DateTime.Compare(dtStandard, now) < 0) { MessageBox.Show("系统数据异常,请联系管理员", "错误"); this.Close(); } //显示医生姓名 if (loginDoctor != null) { loginedDoctorName.Content = "欢迎您, " + loginDoctor.name; return; } loadQuestionaire(filterQuestionaire, "filter"); loadQuestionaire(evaluationQuestionaire, "evaluation"); } private void Dispatcher_UnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { Debug.WriteLine(e.ToString()); } private void loadUSBDogStatus() { int[] timesLimit = dop.getTimesCount(); if(timesLimit[0] != -1 && timesLimit[1]!= -1) { labelHomepageUSBDogStatus.Content = String.Format("系统Key已授权,当前Key可使用{0}次,已使用{1}次", timesLimit[0], timesLimit[1]); labelHomepageUSBDogStatus.Visibility = Visibility.Visible; } else { labelHomepageUSBDogStatus.Visibility = Visibility.Hidden; } } 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 buttonHomePageTreatmentRecords_Click(object sender, RoutedEventArgs e) { tabControlGeneral.SelectedIndex = 6; } //首页--诊疗记录 private void buttonHomePageTreatmentPlan_Click(object sender, RoutedEventArgs e) { tabControlGeneral.SelectedIndex = 7; } //关于程序 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(Constants.template_custom + "\\" + "manual.pdf"); //manual.pdf //Record one_record = SQLiteModel.getRecordByID(24); //Patient one_patient = SQLiteModel.getPatientById("5"); //ReportGenerater.generateReport_constum(one_record, one_patient,cfg); } #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 buttonFilterSelectTreatment_Click(object sender, RoutedEventArgs e) { try { var target = (DataRowView)this.selectUserfilter.dataGrid.SelectedItem; if (target == null) { MessageBox.Show("请先选择病人!"); return; } 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; } currentFilterCount = 1; tabFilter.SelectedIndex += 1; textBoxCaseId.Text = filterPatient.p_record_id; textBoxGender.Text = filterPatient.p_gender; textBoxName.Text = filterPatient.p_name; textBoxHeight.Text = filterPatient.p_height.ToString(); textBoxWeight.Text = filterPatient.p_weight.ToString(); textBoxPregnancyTimes.Text = filterPatient.p_pregnancy_time.ToString(); textBoxBirthDate.Text = filterPatient.p_birthdate.ToString("yyyy/M/d"); textBoxMobile.Text = filterPatient.p_phone; textBoxAddress.Text = filterPatient.p_address; textBoxHistory.Text = filterPatient.p_history; textBoxDiagnosis.Text = filterPatient.p_diagnosis; //*/ treatmentCustomModeList = new List(); //dataGridCustomMode.ItemsSource = treatmentCustomModeList;/*/ //treatmentCustomDataTable = new DataTable(); //treatmentCustomDataTable.Columns.Add("tcID", typeof(int)); //treatmentCustomDataTable.Columns.Add("tcRate", typeof(double)); //treatmentCustomDataTable.Columns.Add("tcActiveTime", typeof(double)); //treatmentCustomDataTable.Columns.Add("tcInactiveTime", typeof(double)); //dataGridCustomMode.ItemsSource = treatmentCustomDataTable.DefaultView;//*/ } /// /// 重选用户 /// /// 默认 /// 默认 private void buttonFilterBackToSelectUser_Click(object sender, RoutedEventArgs e) { tabFilter.SelectedIndex = 0; } /// /// 治疗方案 /// /// 默认 /// 默认 //private void buttonChooseTreatmentPlan_Click(object sender, RoutedEventArgs e) //{ // TreatmentPlan a_new_one = new TreatmentPlan(this); // a_new_one.Show(); //} public void setTreatment(Treatment target) { targetTreatment = target; labelTreatmentName.Content = targetTreatment.disease; sliderStrength.Value = 100; } private void sliderStrength_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { labelStrength.Content = sliderStrength.Value.ToString("0."); comAgent.enqueueCommand(Com.createChangeStrongthCommand((byte)sliderStrength.Value)); } /// /// 自定义模式 /// /// 默认 /// 默认 //private void checkBoxCustomMode_CheckedChanged(object sender, RoutedEventArgs e) //{ // if (checkBoxCustomMode.IsChecked == true) { // labelTreatmentName.Content = "自定义模式"; // buttonSelectTreatment.IsEnabled = false; // dataGridCustomMode.IsEnabled = true; // //dataGridCustomMode.CanUserAddRows = true; // //dataGridCustomMode.CanUserDeleteRows = true; // buttonAddCustomModeItem.IsEnabled = true; // buttonDelCustomModeItem.IsEnabled = true; // } else { // if (targetTreatment == null) { // labelTreatmentName.Content = "请选择治疗方案"; // } else { // labelTreatmentName.Content = targetTreatment.disease; // } // buttonSelectTreatment.IsEnabled = true; // dataGridCustomMode.IsEnabled = false; // buttonAddCustomModeItem.IsEnabled = false; // buttonDelCustomModeItem.IsEnabled = false; // } //} //private void buttonAddCustomModeItem_Click(object sender, RoutedEventArgs e) //{ // TreatmentCustomItem item = new TreatmentCustomItem(); // item.tcID = treatmentCustomModeList.Count + 1; // treatmentCustomModeList.Add(item); // dataGridCustomMode.ItemsSource = null; // dataGridCustomMode.ItemsSource = treatmentCustomModeList; //} //private void buttonDelCustomModeItem_Click(object sender, RoutedEventArgs e) //{ // int index = dataGridCustomMode.SelectedIndex; // if (index == -1) { return; } // treatmentCustomModeList.RemoveAt(index); // for (int i = 0; i < treatmentCustomModeList.Count; i++) // { // treatmentCustomModeList[i].tcID = i + 1; // } // dataGridCustomMode.ItemsSource = null; // dataGridCustomMode.ItemsSource = treatmentCustomModeList; //} private void dataGridCustomMode_SelectionChanged(object sender, SelectionChangedEventArgs e) { //System.Console.WriteLine("asdasdasd"); } private void dataGridCustomMode_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) { //System.Console.WriteLine("asdasdasd"); } /// /// 点击筛查上一步后触发的事件 /// /// 默认 /// 默认 /*private void buttonFilterPrevious_Click(object sender, RoutedEventArgs e) { currentFilterCount -= 1; loadQuestionViewFilter(currentFilterCount); checkFilterButtonStatues(); }*/ /// /// 点击筛查下一步后触发的事件 /// /// 默认 /// 默认 /*private void buttonFilterNext_Click(object sender, RoutedEventArgs e) { 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 = ""; string[] splitedContentTemp = filterQuestionaire[currentIndex - 1].question.q_content.Split('$'); for(int i = 0;i< splitedContentTemp.Length; ++i) { Run aRunTemp = new Run(); aRunTemp.Text = splitedContentTemp[i]; if (i % 2 == 0) { textBlockFilterQuetionContent.Inlines.Add(aRunTemp); } else { aRunTemp.Foreground = Brushes.Red; textBlockFilterQuetionContent.Inlines.Add(aRunTemp); } } string quetionPic_start = Constants.imgPath + "\\" + filterQuestionaire[currentIndex - 1].question.q_id.ToString() + "-起始位.png"; if (File.Exists(quetionPic_start)) { BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri(quetionPic_start, UriKind.RelativeOrAbsolute); bi.EndInit(); imageFilterQuestion_start.Source = bi; } else { imageFilterQuestion_start.Source = null; } string quetionPic_active = Constants.imgPath + "\\" + filterQuestionaire[currentIndex - 1].question.q_id.ToString() + "-动作位.png"; if (File.Exists(quetionPic_active)) { BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri(quetionPic_active, UriKind.RelativeOrAbsolute); bi.EndInit(); imageFilterQuestion_active.Source = bi; } else { imageFilterQuestion_active.Source = null; } 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/6*300, i%6*30, 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); ReportGenerater.generateReport_constum(targetRecord, filterPatient, cfg); 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; }*/ #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(); //这里尝试加载用户的筛查记录 /*20200507:根据甲方要求不再提供初筛功能,这里停止加载最新的筛查记录,所有人都做最复杂的问卷*/ //filterReportForEvaluation = SQLiteModel.getLatestXTypeRecordInYDays(evaluationPatient.p_id, 1, 7); filterReportForEvaluation = null; 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) { /*20200507:根据甲方要求不再提供初筛功能,这里停止加载最新的筛查记录,所有人都做最复杂的问卷*/ //MessageBox.Show("发现该病例一周内未进行初筛,评估过程中将自动进行初筛。","提示"); } else { MessageBox.Show("发现该病例于"+ filterReportForEvaluation.r_time.ToString("yyyy-MM-dd HH:mm:ss") +"进行过初筛,评估过程中将使用此初筛结果。", "提示"); } labelEvaluationName.Content = evaluationPatient.p_name; labelEvaluationRecordid.Content = evaluationPatient.p_record_id; 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 = ""; string[] splitedContentTemp = evaluationQuestionaire[currentIndex - 1].question.q_content.Split('$'); for (int i = 0; i < splitedContentTemp.Length; ++i) { Run aRunTemp = new Run(); aRunTemp.Text = splitedContentTemp[i]; if (i % 2 == 0) { textBlockEvaluationQuetionContent.Inlines.Add(aRunTemp); } else { //aRunTemp.Foreground = Brushes.Red; aRunTemp.FontWeight = FontWeights.Bold; aRunTemp.Text = "· " + aRunTemp.Text; textBlockEvaluationQuetionContent.Inlines.Add(aRunTemp); } } string quetionPic_start = Constants.imgPath + "\\" + evaluationQuestionaire[currentIndex - 1].question.q_id.ToString() + "-起始位.png"; if (File.Exists(quetionPic_start)) { BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri(quetionPic_start, UriKind.RelativeOrAbsolute); bi.EndInit(); imageEvaluationQuestion_start.Source = bi; } else { imageEvaluationQuestion_start.Source = null; } string quetionPic_active = Constants.imgPath + "\\" + evaluationQuestionaire[currentIndex - 1].question.q_id.ToString() + "-动作位.png"; if (File.Exists(quetionPic_active)) { BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri(quetionPic_active, UriKind.RelativeOrAbsolute); bi.EndInit(); imageEvaluationQuestion_active.Source = bi; } else { imageEvaluationQuestion_active.Source = null; } int countOptions = evaluationQuestionaire[currentIndex - 1].answers.Count; gridEvaluationSelectionNormalOptions.Children.Clear(); gridEvaluationSelection.Children.Clear(); //i=0,添加一个正常选项 if (countOptions > 0) { Label normalWithoutPain = new Label(); normalWithoutPain.HorizontalAlignment = HorizontalAlignment.Center; normalWithoutPain.VerticalAlignment = VerticalAlignment.Top; normalWithoutPain.Margin = new Thickness(0, 0, 0, 0); normalWithoutPain.Content = "动作标准"; normalWithoutPain.Foreground = new SolidColorBrush(Color.FromRgb(39, 64, 90)); normalWithoutPain.FontWeight = FontWeights.Bold; normalWithoutPain.FontSize = 20; gridEvaluationSelectionNormalOptions.Children.Add(normalWithoutPain); RadioButton oneOption = new RadioButton(); oneOption.Height = 30; oneOption.HorizontalAlignment = HorizontalAlignment.Center; oneOption.VerticalAlignment = VerticalAlignment.Center; oneOption.Margin = new Thickness(0, 0, 0, 0); if (evaluationUserSelection[currentIndex - 1].a_id == evaluationQuestionaire[currentIndex - 1].answers[0].a_id) oneOption.IsChecked = true; else oneOption.IsChecked = false; oneOption.Content = String.Format("{0}", evaluationQuestionaire[currentIndex - 1].answers[0].a_content); oneOption.Checked += radioButtonEvaluation_Checked; oneOption.GroupName = "evaluationOption"; oneOption.FontSize = 18; oneOption.Name = "rbe" + evaluationQuestionaire[currentIndex - 1].answers[0].a_id.ToString(); gridEvaluationSelectionNormalOptions.Children.Add(oneOption); } //i>=1 for (int i = 1; i < countOptions; ++i) { Label abnormalWithPain = new Label(); abnormalWithPain.HorizontalAlignment = HorizontalAlignment.Center; abnormalWithPain.VerticalAlignment = VerticalAlignment.Top; abnormalWithPain.Margin = new Thickness(0, 0, 0, 0); abnormalWithPain.Content = "动作不标准"; abnormalWithPain.Foreground = new SolidColorBrush(Color.FromRgb(39, 64, 90)); abnormalWithPain.FontWeight = FontWeights.Bold; abnormalWithPain.FontSize = 20; gridEvaluationSelection.Children.Add(abnormalWithPain); RadioButton oneOption = new RadioButton(); oneOption.Height = 30; oneOption.HorizontalAlignment = HorizontalAlignment.Left; oneOption.VerticalAlignment = VerticalAlignment.Top; oneOption.Margin = new Thickness( (i-1)/ 3 * 170 + 30, (i-1) % 3 * 30+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}", 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(); //MessageBox.Show(String.Format("生产环境状态标识:{0}, 授权阈值: {1}, 已使用次数:{2}", Constants.productionEnvironment, timesLimit[0], timesLimit[1])); 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(); loadUSBDogStatus(); 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); ReportGenerater.generateReport_constum(targetRecord, evaluationPatient, cfg); } 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"]),true); } 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); ReportGenerater.generateReport_constum(targetRecord, historyPatient, cfg); 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) } } #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 #region 测试功能 private void buttonTest1_Click(object sender, RoutedEventArgs e) { int res_flag = SQLiteModel.loopInsertAnswers(); if(res_flag == 0) { MessageBox.Show("操作成功"); } } #endregion private float treatmentTime_ = 30, treatmentTimeMin = 1, treatmentTimeMax = 100; public float treatmentTime { get => treatmentTime_; set { treatmentTime_ = value > treatmentTimeMax ? treatmentTimeMax : value < treatmentTimeMin ? treatmentTimeMin : value; labelTreatmentTime.Content = $"{(int)treatmentTime_}:"; int sec = (int)((treatmentTime_ - (int)treatmentTime_) * 60); if (sec < 10) labelTreatmentTime.Content += "0"; labelTreatmentTime.Content += sec.ToString(); } } private void increaseTreatmentTime(object sender, RoutedEventArgs e) { treatmentTime += 0.5f; } private void decreaseTreatmentTime(object sender, RoutedEventArgs e) { treatmentTime -= 0.5f; } private Com comAgent => SingleInstance.getInstance(); private bool isRunning; private void updateUIIsRunning() { buttonStart.IsEnabled = !isRunning; buttonStop.IsEnabled = isRunning; } private void MetroWindow_Activated(object sender, EventArgs e) { } private void MetroWindow_Closing(object sender, CancelEventArgs e) { comAgent.shutdown(); } private void buttonStartTreat_Click(object sender, RoutedEventArgs e) { //if (targetTreatment == null && !checkBoxCustomMode.IsChecked.Value) if (targetTreatment == null) { MessageBox.Show("请选择或添加一个治疗方案", "", MessageBoxButton.OK, MessageBoxImage.Error); return; } //if (checkBoxCustomMode.IsChecked.Value) //{ // TreatmentStep[] steps = new TreatmentStep[treatmentCustomModeList.Count]; // for (int i = 0; i < steps.Length; i++) // { // steps[i] = new TreatmentStep((ushort)treatmentCustomModeList[i].tcRate, // (byte)treatmentCustomModeList[i].tcActiveTime, // (byte)treatmentCustomModeList[i].tcInactiveTime, // (ushort)(treatmentCustomModeList[i].tcActiveTime + treatmentCustomModeList[i].tcInactiveTime)); // } // comAgent.enqueueCommand(Com.createStartManualCommand(parseTreatmentTime(treatmentTime), (byte)sliderStrength.Value, steps)); //} //else //{ // //获取当前时间戳并转换为格式化日期 yyyy-MM-dd hh:mm:ss // DateTime_TimeStamp dateTimeFormatter = new DateTime_TimeStamp(); // int timestamp = dateTimeFormatter.GetTimeStamp(DateTime.Now); // DateTime now = dateTimeFormatter.GetDateTime(timestamp); // //装配诊疗记录对象 // TreatmentRecord treatmentRecordToInsert = new TreatmentRecord(); // treatmentRecordToInsert.patient_record_id = filterPatient.p_record_id; // treatmentRecordToInsert.patient_id = filterPatient.p_id; // treatmentRecordToInsert.strength = Convert.ToInt32(sliderStrength.Value.ToString("0.")); // treatmentRecordToInsert.duration = treatmentTime; // treatmentRecordToInsert.start_time = now; // //插入诊疗记录 // int inserted_row_id = SQLiteModel.insertTreatmentRecord(treatmentRecordToInsert); // comAgent.enqueueCommand(Com.createStartDefinedCommand(targetTreatment.id, parseTreatmentTime(treatmentTime), (byte)sliderStrength.Value)); //} //获取当前时间戳并转换为格式化日期 yyyy-MM - dd hh: mm: ss DateTime_TimeStamp dateTimeFormatter = new DateTime_TimeStamp(); int timestamp = dateTimeFormatter.GetTimeStamp(DateTime.Now); DateTime now = dateTimeFormatter.GetDateTime(timestamp); //装配诊疗记录对象 TreatmentRecord treatmentRecordToInsert = new TreatmentRecord(); treatmentRecordToInsert.patient_record_id = filterPatient.p_record_id; treatmentRecordToInsert.patient_id = filterPatient.p_id; treatmentRecordToInsert.strength = Convert.ToInt32(sliderStrength.Value.ToString("0.")); treatmentRecordToInsert.duration = treatmentTime; treatmentRecordToInsert.start_time = now; //插入诊疗记录 int inserted_row_id = SQLiteModel.insertTreatmentRecord(treatmentRecordToInsert); comAgent.enqueueCommand(Com.createStartDefinedCommand(targetTreatment.id, parseTreatmentTime(treatmentTime), (byte)sliderStrength.Value)); isRunning = true; updateUIIsRunning(); } private short parseTreatmentTime(float f) { return (short)(f * 60); } private void buttonStop_Click(object sender, RoutedEventArgs e) { //if (checkBoxCustomMode.IsChecked.Value) //{ // comAgent.enqueueCommand(Com.createStopCommand()); //} //else //{ // comAgent.enqueueCommand(Com.createStopCommand(Com.getTCIDByIndex(targetTreatment.id))); //} comAgent.enqueueCommand(Com.createStopCommand(Com.getTCIDByIndex(targetTreatment.id))); isRunning = false; updateUIIsRunning(); } } /// /// C#时间戳转换为时间格式(互转) /// 时间戳定义为从格林威治时间 1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。 /// public class DateTime_TimeStamp { protected int m_timestamp; /// /// 获取时间戳Timestamp /// /// /// public int GetTimeStamp(DateTime dt) { DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0); int timeStamp = Convert.ToInt32((dt - dateStart).TotalSeconds); return timeStamp; } /// /// 时间戳Timestamp转换成日期 /// /// /// public DateTime GetDateTime(int timeStamp) { DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lTime = ((long)timeStamp * 10000000); TimeSpan toNow = new TimeSpan(lTime); DateTime targetDt = dtStart.Add(toNow); return targetDt; } } }