/// <summary> /// 新建治疗的Command /// </summary> /// <param name="param"></param> void NewCureSetupExecute(object param) { ViewModelNewCureSetup vm = ((ViewModelLocator)Application.Current.Resources["Locator"]).NewCureSetup; vm.LoadParameters(); Messenger.Default.Send <ViewModelNewCureSetup>(vm, "NewCureSetup"); if (vm.Result) { /* * 清空上次的治疗信息 */ this.ClearLastCureContent(); this.CureSN = vm.CureSN; this.PatientName = vm.PatientName; this.PresettedSequence = vm.Sequence; // Save the basic info of the cure progress // Which contains Patient name, sequence binary array, Cure SN, etc. using (CDatabase db = new CDatabase()) { if (db.CreateCureHistory(CureSN, PatientName, Channel, PresettedSequence) == false) { MessageBox.Show("创建新的治疗记录时发生错误\r\n错误:" + db.LastError, "错误", MessageBoxButton.OK, MessageBoxImage.Error); } } } }
public CConfiguration(CConfiguration Cloned) { strStationName = Cloned.StationName; strSystemUserName = Cloned.SystemUserName; strSystemIP = Cloned.SystemIP; this.ControllerPort = Cloned.ControllerPort; this.SqlServerIP = Cloned.SqlServerIP; this.SqlServerUser = Cloned.SqlServerUser; this.SqlServerPassword = Cloned.SqlServerPassword; this.BloodType = Cloned.BloodType; this.TargetTemperature = Cloned.TargetTemperature; this.ZoneCode = Cloned.ZoneCode; this.TempTuneSilence = Cloned.TempTuneSilence; this.TemperatureTuneDeadArea = Cloned.TemperatureTuneDeadArea; this.TemperatureTuneThreshold = Cloned.TemperatureTuneThreshold; strMachineCode = Cloned.MachineCode; strActiveCode = Cloned.ActiveCode; strCDKEY = Cloned.CDKEY; this.CDKEY_Expired = Cloned.CDKEY_Expired; this.CDKEY_DaysLeft = Cloned.CDKEY_DaysLeft; this.LastCureDuration = Cloned.LastCureDuration; this.MaxCureTimeAllowed = Cloned.MaxCureTimeAllowed; /* 获取设备使用时长 */ Int64 duration; using (CDatabase db = new CDatabase()) { db.GetRunDuration(out duration); this.RunningHours = duration; } this.HVGLevel = Cloned.HVGLevel; /* 返回程序版本号 */ this.AssemblyVersion = Cloned.AssemblyVersion; this.MaxCureBandServieTime = Cloned.MaxCureBandServieTime; this.CompleteVoiceFilePrefix = Cloned.CompleteVoiceFilePrefix; }
/// <summary> /// Load sequence with name /// </summary> /// <param name="SeqName"></param> /// <returns></returns> public bool LoadSequence(string SeqName) { bool ret = false; using(CDatabase db = new CDatabase()) { if(db.GetTemperatureSequence(SeqName, out _Sequence)) { this.SequenceName = SeqName; ret = true; } else { strLastErr = db.LastError; ret = false; } } RaisePropertyChangedEvent("Sequence"); return ret; }
/// <summary> /// 保存温度序列 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_Save_Click(object sender, RoutedEventArgs e) { /* 如果Sequence为空,即还没有编辑Sequence,则提示并且不保存 */ if(_vm.Sequence.Count == 0) { MessageBox.Show("当前温度序列为空", "警告", MessageBoxButton.OK, MessageBoxImage.Warning); return; } /* 检查总时间是否超过60分钟 */ if(_vm.Sequence.TotalTime > CPublicVariables.Configuration.MaxCureTimeAllowed) { MessageBox.Show("总治疗时间不能超过60分钟", "警告", MessageBoxButton.OK, MessageBoxImage.Error); return; } SequenceNameInput f = new SequenceNameInput(); bool? r = f.ShowDialog(); if(r.HasValue && r.Value == true) { /* 保存Sequence到数据库 */ using(CDatabase db = new CDatabase()) { /* 检查名称是否已经存在 */ CTemperatureSequence seq; r = db.GetTemperatureSequence(f.SequenceName, out seq); if(r == false) // 查询时发生错误 { MessageBox.Show("查询温度序列时发生错误\r\n" + db.LastError, "错误", MessageBoxButton.OK, MessageBoxImage.Error); } else { if(seq != null && seq.Count > 0) // 如果当前Sequence name已存在,询问用户是否覆盖 { // 如果不覆盖,则退出保存过程 if(MessageBox.Show(string.Format("{0}已存在,是否覆盖?", f.SequenceName), "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { return; } // 如果覆盖,则先删除旧的Sequence,再保存 else { /* 删除Sequence */ r = db.DeleteTemperatureSequence(f.SequenceName); if(r == false) { MessageBox.Show("删除温度序列时发生错误\r\n" + db.LastError, "错误", MessageBoxButton.OK, MessageBoxImage.Error); return; } } } /* 保存Sequence */ r = db.SaveTemperatureSequence(f.SequenceName, _vm.Sequence); if (r == false) // 如果发生错误 { MessageBox.Show("保存温度序列时发生错误\r\n" + db.LastError, "错误", MessageBoxButton.OK, MessageBoxImage.Error); } else { /* 重新加载Sequence Names列表 */ bgw_Init.RunWorkerAsync(f.SequenceName); } } } } else { // Do Nothing } }
private void btn_Delete_Click(object sender, RoutedEventArgs e) { if(_vm.Sequence.Count > 0) { if (MessageBox.Show(string.Format("是否删除温度序列{0}?", _vm.SequenceName), "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { using(CDatabase db = new CDatabase()) { bool r = db.DeleteTemperatureSequence(_vm.SequenceName); if(r == false) // 删除失败 { MessageBox.Show("删除温度序列时发生错误\r\n" + db.LastError, "错误", MessageBoxButton.OK, MessageBoxImage.Error); } else // 删除成功 { MessageBox.Show("删除成功", "信息", MessageBoxButton.OK, MessageBoxImage.Information); bgw_Init.RunWorkerAsync(); } } } } }
void bgw_Init_DoWork(object sender, DoWorkEventArgs e) { /* 如果参数中传入了字符串,说明加载完Sequence Names以后切换到字符串指定的Sequence */ string seq_name_to_display; if (e.Argument != null) seq_name_to_display = e.Argument.ToString(); else seq_name_to_display = ""; /* 清空列表,启动Busy进度条 */ bgw_Init.ReportProgress(1); /* 加载Sequence Names */ using (CDatabase db = new CDatabase()) { if (db.GetSequenceNames(out seq_names)) { bgw_Init.ReportProgress(100, seq_name_to_display); } else { bgw_Init.ReportProgress(0, db.LastError); } } }
/// <summary> /// 开始治疗 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void bgw_cure_DoWork(object sender, DoWorkEventArgs e) { /*=========================================== 判断治疗带是否过期 ===============================================*/ /* * 如果治疗带过期,并且治疗还未启动,则退出 * 如果正在治疗中,则继续治疗,但是避免下一次启动治疗 */ if (this.CureBandState == ENUM_STATE.Overdue && this.CureElapsedEffective == 0) { bgw_cure.ReportProgress(CURE_PROG_REPORT_CUREBAND_EXPIRED); return; } /*=========================================================================================================*/ CDatabase db = new CDatabase(); /* * 启动控制板 */ control_central.SetControllerWorks(new CCommandQueueItem(CCommandQueueItem.ENUM_CMD.SetTemper, this.Channel, this.PresetTemperatureInCurrentStage)); Thread.Sleep(1000); control_central.SetControllerWorks(new CCommandQueueItem(CCommandQueueItem.ENUM_CMD.Start, this.Channel, 0)); Thread.Sleep(2000); /* * 这里必须将cure_stage赋值为-1,第一次进入this.PresettedSequence.WhichStageBelongTo()函数时会产生一次StageChanged, * 这样可以触发一次SetTemperature事件;否则,第一个stage的温度没有机会设置到主控板 */ cure_stage = -1; /* 获取治疗总时间 */ this.CureTimeNeeded = (int)this.PresettedSequence.Sum(t => t.HoldTime) * 60; this.StartCure = DateTime.Now; /* 启动1s时基定时器 */ timer_countdown_tick.Change(100, COUNTDOWN_BASETIME_MS); while (true) { /* 等待倒计时时基中断 */ sem_countdown_tick.WaitOne(); #region Obsolete segment /* +++++++++++++++++++++++++++++++++++ + 获取数据的部分被移至通讯成功事件 +++++++++++++++++++++++++++++++++++ */ /* 获取治疗带数据 */ //if (control_central.BoardInfo.State.Length > 0) //{ /* 获取实时温度 */ //this.RealtimeTemperature = control_central.BoardInfo.Temperature[this.Channel]; /* 获取状态 */ //this.CureBandState = control_central.BoardInfo.State[this.Channel]; /* 获取治疗带使用时间 */ //this.CureBandServiceTime = control_central.BoardInfo.CureBandServiceTime[this.Channel]; //} #endregion #region Check user's interrupt /*============== 检查用户是否请求停止治疗过程 ==============*/ if (bgw_cure.CancellationPending) { bgw_cure.ReportProgress(CURE_PROG_REPORT_CANCELED); return; } /*=================================================*/ #endregion /*============================================= 判断治疗带是否在加热 ============================================*/ /* * 检查治疗带是否已启动 * 因为控制板有可能因为I2C通讯问题重启,此时所有通道会重置到停止状态,这种情况下需要返回的治疗带状态是停止, * 此时则需要重新启动一下 */ if (this.CureBandState == ENUM_STATE.Standby) { control_central.SetControllerWorks(new CCommandQueueItem(CCommandQueueItem.ENUM_CMD.SetTemper, this.Channel, this.PresetTemperatureInCurrentStage)); control_central.SetControllerWorks(new CCommandQueueItem(CCommandQueueItem.ENUM_CMD.Start, this.Channel, 0)); Thread.Sleep(2000); // 等待启动 continue; } /*=========================================================================================================*/ #region Check user's interrupt /*============== 检查用户是否请求停止治疗过程 ==============*/ if (bgw_cure.CancellationPending) { bgw_cure.ReportProgress(CURE_PROG_REPORT_CANCELED); return; } /*=================================================*/ #endregion /* 如果状态是正在加热,则等待,同时发送设置温度的命令,以确保目标温度写入控制板 */ if (this.CureBandState == ENUM_STATE.Heating) { control_central.SetControllerWorks(new CCommandQueueItem(CCommandQueueItem.ENUM_CMD.SetTemper, this.Channel, this.PresetTemperatureInCurrentStage)); Thread.Sleep(2000); continue; } /*================================================ 具体的业务逻辑 =============================================*/ /* 检查控制板返回的治疗带状态是否正常 ** 如果不在Curing状态,说明出现故障,则暂停计时,等待用户处理硬件故障 */ if (this.CureBandState == ENUM_STATE.Curing) { /* 检查当前治疗属于哪个阶段 */ this.PresettedSequence.WhichStageBelongTo(this.CureElapsedEffective, cure_stage, out cure_stage, out bln_stage_changed, out time_remained_in_stage, out dbl_progress_in_stage); this.CureProgressInStage = dbl_progress_in_stage; this.TimeRemainedInStage = time_remained_in_stage; // 如果温度阶段发生变化,则读取预设温度,并将预设温度写入控制板 if (bln_stage_changed) { /* 预设温度 */ this.PresetTemperatureInCurrentStage = this.PresettedSequence[cure_stage].TargetTemperature; /* 向控制板设置加热温度 */ control_central.SetControllerWorks( new CCommandQueueItem(CCommandQueueItem.ENUM_CMD.SetTemper, this.Channel, this.PresetTemperatureInCurrentStage)); } /* 添加实时温度 */ bgw_cure.ReportProgress(CURE_PROG_REPORT_ADD_RTT); /* 每一秒获取的温度均保存在数据库中 */ if (db.InsertNewCureDetail(this.CureSN, this.RealtimeTemperature, this.CureElapsedEffective) == false) { // 如果保存数据失败,退出治疗过程 bgw_cure.ReportProgress(CURE_PROG_REPORT_DB_ERR, db.LastError); return; } /* * 检查治疗是否完成 */ if (this.CureElapsedEffective >= this.CureTimeNeeded) // 治疗完成 { bgw_cure.ReportProgress(CURE_PROG_REPORT_DONE); return; } /* 增加治疗时间 */ this.CureElapsedEffective++; } /*=========================================================================================================*/ #region Check user's interrupt /*============== 检查用户是否请求停止治疗过程 ==============*/ if (bgw_cure.CancellationPending) { bgw_cure.ReportProgress(CURE_PROG_REPORT_CANCELED); return; } /*=================================================*/ #endregion } }
/// <summary> /// 新建治疗的Command /// </summary> /// <param name="param"></param> void NewCureSetupExecute(object param) { ViewModelNewCureSetup vm = ((ViewModelLocator)Application.Current.Resources["Locator"]).NewCureSetup; vm.LoadParameters(); Messenger.Default.Send<ViewModelNewCureSetup>(vm, "NewCureSetup"); if (vm.Result) { /* * 清空上次的治疗信息 */ this.ClearLastCureContent(); this.CureSN = vm.CureSN; this.PatientName = vm.PatientName; this.PresettedSequence = vm.Sequence; // Save the basic info of the cure progress // Which contains Patient name, sequence binary array, Cure SN, etc. using (CDatabase db = new CDatabase()) { if (db.CreateCureHistory(CureSN, PatientName, Channel, PresettedSequence) == false) { MessageBox.Show("创建新的治疗记录时发生错误\r\n错误:" + db.LastError, "错误", MessageBoxButton.OK, MessageBoxImage.Error); } } } }
/// <summary> /// Load sequence with name /// </summary> /// <param name="SeqName"></param> /// <returns></returns> public void LoadSequence(string SequenceName) { using (CDatabase db = new CDatabase()) { CTemperatureSequence _Sequence; if (db.GetTemperatureSequence(SequenceName, out _Sequence)) { this.Sequence = _Sequence; if (_Sequence == null) this.SelectedSeqName = ""; else this.SelectedSeqName = _Sequence.SequenceName; } else { } } }
/// <summary> /// 启动一个加载SequenceNames和生成CureSN的线程 /// </summary> /// <param name="param"></param> public void LoadParameters() { string[] seq_names = null; string cure_sn = string.Empty; new Thread(() => { using (CDatabase db = new CDatabase()) { // 从数据库获取温度预设曲线名称列表 if (!db.GetSequenceNames(out seq_names)) { // 如果错误,通知View弹出错误对话框 Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>(db.LastError), "DBError"); return; } else { this.SequenceNames = seq_names; RaisePropertyChanged("SequenceNames"); } if (!db.GetNewCureSN(ref cure_sn)) { // 如果错误,通知View弹出错误对话框 Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>(db.LastError), "DBError"); } else { this.CureSN = cure_sn; RaisePropertyChanged("CureSN"); return; } } }).Start(); this.SelectedSeqName = null; this.Sequence = null; this.PatientName = ""; this.Result = false; }
public CConfiguration(CConfiguration Cloned) { strStationName = Cloned.StationName; strSystemUserName = Cloned.SystemUserName; strSystemIP = Cloned.SystemIP; this.ControllerPort = Cloned.ControllerPort; this.SqlServerIP = Cloned.SqlServerIP; this.SqlServerUser = Cloned.SqlServerUser; this.SqlServerPassword = Cloned.SqlServerPassword; this.BloodType = Cloned.BloodType; this.TargetTemperature = Cloned.TargetTemperature; this.ZoneCode = Cloned.ZoneCode; this.TempTuneSilence = Cloned.TempTuneSilence; this.TemperatureTuneDeadArea = Cloned.TemperatureTuneDeadArea; this.TemperatureTuneThreshold = Cloned.TemperatureTuneThreshold; strMachineCode = Cloned.MachineCode; strActiveCode = Cloned.ActiveCode; strCDKEY = Cloned.CDKEY; this.CDKEY_Expired = Cloned.CDKEY_Expired; this.CDKEY_DaysLeft = Cloned.CDKEY_DaysLeft; this.LastCureDuration = Cloned.LastCureDuration; this.MaxCureTimeAllowed = Cloned.MaxCureTimeAllowed; /* 获取设备使用时长 */ Int64 duration; using (CDatabase db = new CDatabase()) { db.GetRunDuration(out duration); this.RunningHours = duration; } this.HVGLevel = Cloned.HVGLevel; /* 返回程序版本号 */ this.AssemblyVersion = Cloned.AssemblyVersion; this.MaxCureBandServieTime = Cloned.MaxCureBandServieTime; this.CompleteVoiceFilePrefix = Cloned.CompleteVoiceFilePrefix; }
/// <summary> /// 开始治疗 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void bgw_cure_DoWork(object sender, DoWorkEventArgs e) { /*=========================================== 判断治疗带是否过期 ===============================================*/ /* * 如果治疗带过期,并且治疗还未启动,则退出 * 如果正在治疗中,则继续治疗,但是避免下一次启动治疗 */ if (this.CureBandState == ENUM_STATE.Overdue && this.CureElapsedEffective == 0) { bgw_cure.ReportProgress(CURE_PROG_REPORT_CUREBAND_EXPIRED); return; } /*=========================================================================================================*/ CDatabase db = new CDatabase(); /* * 启动控制板 */ control_central.SetControllerWorks(new CCommandQueueItem(CCommandQueueItem.ENUM_CMD.SetTemper, this.Channel, this.PresetTemperatureInCurrentStage)); Thread.Sleep(1000); control_central.SetControllerWorks(new CCommandQueueItem(CCommandQueueItem.ENUM_CMD.Start, this.Channel, 0)); Thread.Sleep(2000); /* * 这里必须将cure_stage赋值为-1,第一次进入this.PresettedSequence.WhichStageBelongTo()函数时会产生一次StageChanged, * 这样可以触发一次SetTemperature事件;否则,第一个stage的温度没有机会设置到主控板 */ cure_stage = -1; /* 获取治疗总时间 */ this.CureTimeNeeded = (int)this.PresettedSequence.Sum(t => t.HoldTime) * 60; this.StartCure = DateTime.Now; /* 启动1s时基定时器 */ timer_countdown_tick.Change(100, COUNTDOWN_BASETIME_MS); while (true) { /* 等待倒计时时基中断 */ sem_countdown_tick.WaitOne(); #region Obsolete segment /* +++++++++++++++++++++++++++++++++++ + 获取数据的部分被移至通讯成功事件 +++++++++++++++++++++++++++++++++++ */ /* 获取治疗带数据 */ //if (control_central.BoardInfo.State.Length > 0) //{ /* 获取实时温度 */ //this.RealtimeTemperature = control_central.BoardInfo.Temperature[this.Channel]; /* 获取状态 */ //this.CureBandState = control_central.BoardInfo.State[this.Channel]; /* 获取治疗带使用时间 */ //this.CureBandServiceTime = control_central.BoardInfo.CureBandServiceTime[this.Channel]; //} #endregion #region Check user's interrupt /*============== 检查用户是否请求停止治疗过程 ==============*/ if (bgw_cure.CancellationPending) { bgw_cure.ReportProgress(CURE_PROG_REPORT_CANCELED); return; } /*=================================================*/ #endregion /*============================================= 判断治疗带是否在加热 ============================================*/ /* * 检查治疗带是否已启动 * 因为控制板有可能因为I2C通讯问题重启,此时所有通道会重置到停止状态,这种情况下需要返回的治疗带状态是停止, * 此时则需要重新启动一下 */ if (this.CureBandState == ENUM_STATE.Standby) { control_central.SetControllerWorks(new CCommandQueueItem(CCommandQueueItem.ENUM_CMD.SetTemper, this.Channel, this.PresetTemperatureInCurrentStage)); control_central.SetControllerWorks(new CCommandQueueItem(CCommandQueueItem.ENUM_CMD.Start, this.Channel, 0)); Thread.Sleep(2000); // 等待启动 continue; } /*=========================================================================================================*/ #region Check user's interrupt /*============== 检查用户是否请求停止治疗过程 ==============*/ if (bgw_cure.CancellationPending) { bgw_cure.ReportProgress(CURE_PROG_REPORT_CANCELED); return; } /*=================================================*/ #endregion /* 如果状态是正在加热,则等待,同时发送设置温度的命令,以确保目标温度写入控制板 */ if (this.CureBandState == ENUM_STATE.Heating) { control_central.SetControllerWorks(new CCommandQueueItem(CCommandQueueItem.ENUM_CMD.SetTemper, this.Channel, this.PresetTemperatureInCurrentStage)); Thread.Sleep(2000); continue; } /*================================================ 具体的业务逻辑 =============================================*/ /* 检查控制板返回的治疗带状态是否正常 ** 如果不在Curing状态,说明出现故障,则暂停计时,等待用户处理硬件故障 */ if (this.CureBandState == ENUM_STATE.Curing) { /* 检查当前治疗属于哪个阶段 */ this.PresettedSequence.WhichStageBelongTo(this.CureElapsedEffective, cure_stage, out cure_stage, out bln_stage_changed, out time_remained_in_stage, out dbl_progress_in_stage); this.CureProgressInStage = dbl_progress_in_stage; this.TimeRemainedInStage = time_remained_in_stage; // 如果温度阶段发生变化,则读取预设温度,并将预设温度写入控制板 if (bln_stage_changed) { /* 预设温度 */ this.PresetTemperatureInCurrentStage = this.PresettedSequence[cure_stage].TargetTemperature; /* 向控制板设置加热温度 */ control_central.SetControllerWorks( new CCommandQueueItem(CCommandQueueItem.ENUM_CMD.SetTemper, this.Channel, this.PresetTemperatureInCurrentStage)); } /* 添加实时温度 */ bgw_cure.ReportProgress(CURE_PROG_REPORT_ADD_RTT); /* 每一秒获取的温度均保存在数据库中 */ if (db.InsertNewCureDetail(this.CureSN, this.RealtimeTemperature, this.CureElapsedEffective) == false) { // 如果保存数据失败,退出治疗过程 bgw_cure.ReportProgress(CURE_PROG_REPORT_DB_ERR, db.LastError); return; } /* * 检查治疗是否完成 */ if (this.CureElapsedEffective >= this.CureTimeNeeded) // 治疗完成 { bgw_cure.ReportProgress(CURE_PROG_REPORT_DONE); return; } /* 增加治疗时间 */ this.CureElapsedEffective++; } /*=========================================================================================================*/ #region Check user's interrupt /*============== 检查用户是否请求停止治疗过程 ==============*/ if (bgw_cure.CancellationPending) { bgw_cure.ReportProgress(CURE_PROG_REPORT_CANCELED); return; } /*=================================================*/ #endregion } }
public void LoadHistorySummary(string CureSN, int Limit) { int item_cnt = 0; _realtime_temper_collection.Clear(); _history_collection.Clear(); new Thread(() => { DataTable dt = null; // 加载History列表 using (CDatabase db = new CDatabase()) { if (!db.GetCureHistoryList(CureSN, out dt)) { // 如果错误,通知View弹出错误对话框 Messenger.Default.Send<NotificationMessage<string>>(new NotificationMessage<string>(db.LastError, "获取历史列表时发生错误"), "DBError"); } else { foreach (DataRow dr in dt.Rows) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { _history_collection.Add( new CCureHistory( dr["cure_sn"].ToString(), dr["patient_name"].ToString(), Convert.ToInt16(dr["cure_channel"]), Convert.ToDateTime(dr["created_time"]), Convert.ToDateTime(dr["updated_time"]), (byte[])dr["seq_snapshot"])); })); item_cnt++; if(Limit > 0) { if (item_cnt > Limit) break; } } } } }).Start(); }