12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466 |
- 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
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- 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; //从数据库取配置的类
- Patient filterPatient;
- Patient evaluationPatient;
- Patient historyPatient;
- Record filterReportForEvaluation;
- bool flagEvaluationWithoutFilter = true;
- List<QuestionAnswerPair> filterQuestionaire = new List<QuestionAnswerPair>();
- List<QuestionAnswerPair> evaluationQuestionaire = new List<QuestionAnswerPair>();
- List<UserSelection> filterUserSelection = new List<UserSelection>();
- List<UserSelection> evaluationUserSelection = new List<UserSelection>();
- string resultsFilter;
- string resultsEvaluation;
- int currentFilterCount = 0;
- int currentEvaluationCount = 0;
- List<Record> recordsFromOnePatient;
- BindingList<Record> bindingRecords;
- Dictionary<string, int> mapKeyToDigit = new Dictionary<string, int>();
- #endregion
- public MainWindow()
- {
- InitializeComponent();
- //加载配置
- cfg = new Toolkits.Config();
- //绑定三个selectUser的父类
- //selectUserMeasure.setMainWindow(this);
- selectUserPatientManagent.setMainWindow(this);
- selectUserfilter.setMainWindow(this);
- selectUserevaluation.setMainWindow(this);
- selectUserHistory.setMainWindow(this);
- }
- #region 初始化与系统调用部分
- //初始化全部组件后需要先输入医生密码才能进入
- //async
- private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
- {
- //Thread.Sleep(2000);
- //首先验证注册机制
-
- bool registerSuccess = cfg.CheckRegisterCode();
- if (!registerSuccess)
- {
- SmallDialogs.RegisterCode rc = new SmallDialogs.RegisterCode(this,cfg,true);
- rc.ShowDialog();
- }
- //之后测试登陆
- SmallDialogs.LoginWindow lw = new SmallDialogs.LoginWindow(this);
- lw.ShowDialog();
- if(loginDoctor == null)
- {
- this.Close();
- }
- //显示医生姓名
- if (loginDoctor != null)
- {
- loginedDoctorName.Content = "欢迎您, " + loginDoctor.name;
- return;
- }
- loadQuestionaire(filterQuestionaire, "filter");
- loadQuestionaire(evaluationQuestionaire, "evaluation");
- labelHomepageCversion.Content = "编译日期:" + Toolkits.Constants.compileDate;
- }
- private void loadQuestionaire(List<QuestionAnswerPair> oneQuestionaire, string type = "filter")
- {
- oneQuestionaire.Clear();
- List<Question> questions = SQLite.SQLiteModel.getQuestions(type);
- foreach (Question oneQuestion in questions)
- {
- List<Answer> answers = SQLite.SQLiteModel.getAnswersByQid(oneQuestion.q_id);
- QuestionAnswerPair temp = new QuestionAnswerPair(oneQuestion, answers);
- oneQuestionaire.Add(temp);
- }
- }
- /// <summary>
- /// 筛查或评估流程页面识别快捷键的操作
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- 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 筛查功能
- /// <summary>
- /// 点击开始筛查后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- 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;
- }
- /// <summary>
- /// 点击中止筛查后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- 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;
- }
- /// <summary>
- /// 点击筛查上一步后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonFilterPrevious_Click(object sender, RoutedEventArgs e)
- {
- currentFilterCount -= 1;
- loadQuestionViewFilter(currentFilterCount);
- checkFilterButtonStatues();
- }
- /// <summary>
- /// 点击筛查下一步后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonFilterNext_Click(object sender, RoutedEventArgs e)
- {
- currentFilterCount += 1;
- loadQuestionViewFilter(currentFilterCount);
- checkFilterButtonStatues();
- }
- /// <summary>
- /// 确认筛查阶段各个按钮应当处于的状态
- /// </summary>
- 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;
- }
- /// <summary>
- /// 加载题目和选项界面
- /// </summary>
- 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();
- }
- /// <summary>
- /// 点击筛查提交后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonSubmitFilter_Click(object sender, RoutedEventArgs e)
- {
- 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;
- }
- 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;
- }
- /// <summary>
- /// 返回至选择用户页
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonFilterBackToSelectUser_Click(object sender, RoutedEventArgs e)
- {
- buttonAbortFilter_Click(sender, e);
- }
- /// <summary>
- /// 返回至选择首页
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonFilterBackToHome_Click(object sender, RoutedEventArgs e)
- {
- buttonAbortFilter_Click(sender, e);
- tabControlGeneral.SelectedIndex = 0;
- }
- #endregion
- #region 评估功能
- /// <summary>
- /// 点击开始评估后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- 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<List<UserSelection>>(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();
- }
- /// <summary>
- /// 加载currentIndex的评估题目功能
- /// </summary>
- /// <param name="currentIndex">需要显示题目的题号</param>
- 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);
- }
- }
- /// <summary>
- /// 检查当前答题状态,判断是否需要跳过该题和控制加载题目的功能,能够维护userselection和questionaire
- /// </summary>
- 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<Answer> 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;
- }
- }
- /// <summary>
- /// 评估单选选项被选中的触发事件,主要是修改内存中的选择和判断下一题及提交按钮是否可用
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- 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;
- }
-
- }
- /// <summary>
- /// (未实现)评估过程中点击上一题的触发事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonEvaluationPrevious_Click(object sender, RoutedEventArgs e)
- {
- }
- /// <summary>
- /// 点击评估页下一题后触发的事件,主要是判断接下来加载哪一题
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- 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<Answer> 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();
- }
- }
- /// <summary>
- /// 点击评估页提交后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonSubmitEvaluation_Click(object sender, RoutedEventArgs e)
- {
- 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;
- }
- 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;
- }
- /// <summary>
- /// 点击评估页中止评估后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- 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;
- }
- /// <summary>
- /// 返回至选择用户页
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonEvaluationBackToSelectUser_Click(object sender, RoutedEventArgs e)
- {
- buttonAbortEvaluation_Click(sender, e);
- }
- /// <summary>
- /// 返回至选择首页
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonEvaluationBackToHome_Click(object sender, RoutedEventArgs e)
- {
- buttonAbortEvaluation_Click(sender, e);
- tabControlGeneral.SelectedIndex = 0;
- }
- #endregion
- #region 历史记录
- /// <summary>
- /// 点击选择病例查看其历史记录后触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- 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<Record>(recordsFromOnePatient);
- dataGridRecords.ItemsSource = bindingRecords;
- }
- catch(Exception err)
- {
- MessageBox.Show("数据库加载异常\r\n调试信息:\r\n"+err.StackTrace, "错误");
- return;
- }
- tabHistoryRecords.SelectedIndex = 1;
- }
- /// <summary>
- /// 在选择记录页面,点击返回上一级触发的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonHistoryBackToSelectUser_Click(object sender, RoutedEventArgs e)
- {
- recordsFromOnePatient.Clear();
- tabHistoryRecords.SelectedIndex = 0;
- }
- /// <summary>
- /// 由历史记录相关页面返回至首页的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonHistoryBackToHome_Click(object sender, RoutedEventArgs e)
- {
- recordsFromOnePatient.Clear();
- tabHistoryRecords.SelectedIndex = 0;
- tabControlGeneral.SelectedIndex = 0;
- }
- /// <summary>
- /// 点击生成报告的页面
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- 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;
- }
- /// <summary>
- /// 从报告生成页点击返回上一页的事件
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonHistoryBackToSelectRecord_Click(object sender, RoutedEventArgs e)
- {
- tabHistoryRecords.SelectedIndex = 1;
- }
- /// <summary>
- /// 双击报告也要生成报告的功能
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- 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 commlangGrid_Loaded(object sender, RoutedEventArgs e)
- {
- LoadCommlangDataGrid();
- }
- public void LoadCommlangDataGrid()
- {
- //连接字符串
- string Connstr = "Data Source=" + System.Environment.CurrentDirectory + "\\Junde.db3"; ;
- //连接对象
- System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(Connstr);
- //Sql语句
- string selectCmd = "SELECT * FROM CommonWords LIMIT 100";
- con.Open();
- da = new System.Data.SQLite.SQLiteDataAdapter(selectCmd, con);
- ds = new DataSet();
- da.Fill(ds);
- dataGridCommlang.ItemsSource = ds.Tables[0].DefaultView;
- con.Close();
- }
- //新增常用语
- private void buttonAddCommlang_Click(object sender, RoutedEventArgs e)
- {
- AddCommonWords a_new_commonword = new AddCommonWords(this);
- a_new_commonword.Show();
- }
- //编辑常用语
- private void buttonChangeCommlang_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- var target = (DataRowView)this.dataGridCommlang.SelectedItem;
- //MessageBox.Show(target["id"].ToString());
- ModifyCommonWords modify_one = new ModifyCommonWords(this, target["id"].ToString());
- modify_one.Show();
- }
- catch (Exception err)
- {
- this.ShowMessageAsync("警告", "请选择一个常用语进行修改\r\n调试信息:" + err.Message + "\r\n" + err.StackTrace);
- }
- }
- //删除常用语
- private async void buttonDeleteCommlang_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- var target = (DataRowView)this.dataGridCommlang.SelectedItem;
- if (target == null)
- {
- await this.ShowMessageAsync("提示", "请选择一个常用语进行删除");
- return;
- }
- MessageDialogResult clickresult = await this.ShowMessageAsync("提示", "确认删除该常用语吗?", MessageDialogStyle.AffirmativeAndNegative);
- if (clickresult == MessageDialogResult.Affirmative)//确认
- {
- int status = SQLite.SQLiteModel.DeleteCommonWordsItem(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);
- }
- LoadCommlangDataGrid();
- }
- //双击表格触发修改常用语的功能
- private void dataGridCommlang_MouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
- buttonChangeCommlang_Click(sender, e);
- }
- //*/
- #endregion
- #region 软件激活管理
- //重新激活程序
- private void buttonModifyRegisterInfo_Click(object sender, RoutedEventArgs e)
- {
- SmallDialogs.RegisterCode rc = new SmallDialogs.RegisterCode(this, cfg, false);
- rc.ShowDialog();
- }
- //保存其他医生级别的设置,如显示血压的单位
- private void buttonSaveDocSetting_Click(object sender, RoutedEventArgs e)
- {
- string bp_unit_temp = "1";
- if (radioButtonBP_kpa.IsChecked == true)
- {
- bp_unit_temp = "2";
- }
- try
- {
- SQLite.SQLiteModel.UpdateDocSetting(bp_unit_temp);
- }
- catch (Exception err)
- {
- this.ShowMessageAsync("错误", "数据库读写失败,调试信息:\r\n" + err.StackTrace);
- }
- cfg.refresh();
- this.ShowMessageAsync("提示", "修改成功");
- }
- /// <summary>
- /// buttonOptmizeDatabase_Click:点击优化数据库的方法,把已经被删除的数据进行彻底清除
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- private void buttonOptmizeDatabase_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- //获取标记为删除的病人记录
- List<string> ids_to_be_deleted = SQLite.SQLiteModel.getDeletedPatients();
- //确实删除这些病人记录
- SQLite.SQLiteModel.realDeleteRecords();
- //确实删除这些病人所含有的检查记录
- foreach(string each_line in ids_to_be_deleted)
- {
- //SQLite.SQLiteModel.DeleteRecordItem(each_line);
- }
- MessageBox.Show("操作完成", "信息");
- }
- catch (Exception)
- {
- MessageBox.Show("数据库异常", "错误");
- }
- }
- /// <summary>
- /// buttonDeleteAllPdfReport_Click:点击删除某一目录下所有文件的方法
- /// </summary>
- /// <param name="sender">默认</param>
- /// <param name="e">默认</param>
- 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
-
- }
- }
|