Beispiel #1
0
        /// <summary>
        /// 类初始化时执行的公共代码
        /// </summary>
        public void ClassInit(ref CControlCentral Controller)
        {
            control_central = Controller;
            control_central.ControllerCommStatusChanged += Control_central_ControllerCommStatusChanged;

            bgw_cure = new BackgroundWorker();
            bgw_cure.WorkerSupportsCancellation = true;
            bgw_cure.WorkerReportsProgress      = true;
            bgw_cure.DoWork             += bgw_cure_DoWork;
            bgw_cure.ProgressChanged    += bgw_cure_ProgressChanged;
            bgw_cure.RunWorkerCompleted += Bgw_cure_RunWorkerCompleted;
            //bgw_cure.RunWorkerAsync();

            realtime_temperature_collection = new CRealtimeTemperatureCollection();
            presetted_sequence = new CTemperatureSequence();

            /* 初始化倒计时时基的定时器 */
            timer_countdown_tick = new Timer(OnTimerIntervalEvent, null, Timeout.Infinite, COUNTDOWN_BASETIME_MS);
            sem_countdown_tick   = new Semaphore(0, 1);

            /* 初始化Command */
            command_start_resume = new RelayCommand <object>(p => StartOrResumeExecute(p));

            this.patient_name = "";
        }
 public CCureHistory(string CureSN, string PatientName, int CureChannel, DateTime CreatedTime, DateTime UpdatedTime, byte[] SequenceSnapshot)
 {
     _cure_sn      = CureSN;
     _patient_name = PatientName;
     _cure_channel = CureChannel;
     _created_time = CreatedTime;
     _updated_time = UpdatedTime;
     _seq_snapshot = (CTemperatureSequence)CPublicMethods.DeserializeObjectFromBinaryArray(SequenceSnapshot);
 }
        /// <summary>
        /// Get the temperature sequence from the database
        /// </summary>
        /// <param name="SequenceName">温度序列名称</param>
        /// <param name="SequenceInstance">获取到的温度序列实例</param>
        /// <returns></returns>
        public bool GetTemperatureSequence(string SequenceName, out CTemperatureSequence SequenceInstance)
        {
            SequenceInstance = new CTemperatureSequence();

            bool ret = false;

            using (MySqlCommand cmd = new MySqlCommand()
            {
                CommandTimeout = COMMAND_TIMEOUT
            })
            {
                try
                {
                    if (Open())
                    {
                        cmd.Connection  = conn;
                        cmd.CommandText = "SELECT `name`, `order`, `temper`, `consume`, `add_time` FROM `temperature_sequence` WHERE `name` = '" + SequenceName + "' AND `using`='E' ORDER BY `order` ASC";
                        MySqlDataReader dr = cmd.ExecuteReader();
                        if (dr.HasRows)
                        {
                            while (dr.Read())
                            {
                                CTemperatureSequenceKeyPoint p = new CTemperatureSequenceKeyPoint(Convert.ToDouble(dr["temper"]), Convert.ToInt16(dr["consume"]));
                                SequenceInstance.Add(p);
                            }
                        }

                        if (SequenceInstance.Count == 0)
                        {
                            SequenceInstance = null;
                        }
                        else
                        {
                            SequenceInstance.SequenceName = SequenceName;
                        }

                        ret = true;
                    }
                    else
                    {
                        ret = false;
                    }
                }
                catch (Exception ex)
                {
                    strLastError = ex.Message;
                    ret          = false;
                }
            }

            Close();
            return(ret);
        }
Beispiel #4
0
        public ViewModel_TemperatureSequenceEditor()
        {
            /*
             * _Sequence = new CTemperatureSequence();
             * _Sequence.Add(new CTemperatureSequenceKeyPoint() { StartTime = DateTime.Now, HoldTime = 30, TargetTemperature = 41 });
             * _Sequence.Add(new CTemperatureSequenceKeyPoint() { StartTime = DateTime.Now, HoldTime = 32, TargetTemperature = 42 });
             * _Sequence.Add(new CTemperatureSequenceKeyPoint() { StartTime = DateTime.Now, HoldTime = 33, TargetTemperature = 43 });
             * _Sequence.Add(new CTemperatureSequenceKeyPoint() { StartTime = DateTime.Now, HoldTime = 34, TargetTemperature = 44 });
             * _Sequence.Add(new CTemperatureSequenceKeyPoint() { StartTime = DateTime.Now, HoldTime = 35, TargetTemperature = 41 });
             */
            //new CDatabase().GetTemperatureSequence("测试1", out _Sequence);

            _Sequence = new CTemperatureSequence();
        }
        public ViewModel_TemperatureSequenceEditor()
        {
            /*
            _Sequence = new CTemperatureSequence();
            _Sequence.Add(new CTemperatureSequenceKeyPoint() { StartTime = DateTime.Now, HoldTime = 30, TargetTemperature = 41 });
            _Sequence.Add(new CTemperatureSequenceKeyPoint() { StartTime = DateTime.Now, HoldTime = 32, TargetTemperature = 42 });
            _Sequence.Add(new CTemperatureSequenceKeyPoint() { StartTime = DateTime.Now, HoldTime = 33, TargetTemperature = 43 });
            _Sequence.Add(new CTemperatureSequenceKeyPoint() { StartTime = DateTime.Now, HoldTime = 34, TargetTemperature = 44 });
            _Sequence.Add(new CTemperatureSequenceKeyPoint() { StartTime = DateTime.Now, HoldTime = 35, TargetTemperature = 41 });
               */
               //new CDatabase().GetTemperatureSequence("测试1", out _Sequence);

            _Sequence = new CTemperatureSequence();
        }
        /// <summary>
        /// Save the temperature sequence
        /// </summary>
        /// <param name="SequenceName"></param>
        /// <param name="SequenceInstance"></param>
        /// <returns></returns>
        public bool SaveTemperatureSequence(string SequenceName, CTemperatureSequence SequenceInstance)
        {
            bool ret = false;

            using (MySqlCommand cmd = new MySqlCommand()
            {
                CommandTimeout = COMMAND_TIMEOUT
            })
            {
                try
                {
                    if (Open())
                    {
                        StringBuilder cmdstr = new StringBuilder();
                        int           order  = 0;
                        cmdstr.Append("START TRANSACTION;");
                        foreach (CTemperatureSequenceKeyPoint p in SequenceInstance)
                        {
                            cmdstr.Append(
                                string.Format(
                                    "INSERT INTO `temperature_sequence` (`name`, `order`, `temper`, `consume`) VALUE (\"{0}\", {1}, {2}, {3});",
                                    new string[] { SequenceName, order.ToString(), p.TargetTemperature.ToString(), p.HoldTime.ToString() }));
                            order++;
                        }
                        cmdstr.Append("COMMIT;");
                        cmd.Connection = conn;

                        cmd.CommandText = cmdstr.ToString();
                        cmd.ExecuteNonQuery();
                        ret = true;
                    }
                    else
                    {
                        ret = false;
                    }
                }
                catch (Exception ex)
                {
                    strLastError = ex.Message;
                    ret          = false;
                }
            }

            Close();
            return(ret);
        }
        private static void OnPresettedSequenceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            StepAreaAndLineChart owner = d as StepAreaAndLineChart;

            /*
             * 重新生成一个CTemperatureSequence对象,这个对象和传入的对象区别是:
             * 重新生成的CTemperatureSequence对象会在尾部多加一个Point,这个Point用来
             * 正确产生Step Series的最后一个横阶梯
             */

            CTemperatureSequence seq;

            if (e.NewValue == null)
            {
                seq = new CTemperatureSequence();
            }
            else
            {
                seq = ((CTemperatureSequence)e.NewValue).Clone() as CTemperatureSequence;
                if (seq.Count > 0)
                {
                    /* 这里在最后加入一个Point用来修正Step Chart的View */
                    CTemperatureSequenceKeyPoint point = seq[seq.Count - 1];
                    seq.Add(new CTemperatureSequenceKeyPoint()
                    {
                        HoldTime          = 0,
                        TargetTemperature = point.TargetTemperature
                    });
                }
            }
            owner._SeriesSequence.DataSource = seq;

            /* 更新实时温度曲线的描点间隔 */
            if (seq != null && seq.Count > 0 && owner.RealtimeTemperatureCollection != null)
            {
                owner.RealtimeTemperatureCollection.TotalTime = owner.PresettedSequence.TotalTime;
            }
        }
        private static void OnPresettedSequenceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            StepAreaAndLineChart owner = d as StepAreaAndLineChart;

            /*
            * 重新生成一个CTemperatureSequence对象,这个对象和传入的对象区别是:
            * 重新生成的CTemperatureSequence对象会在尾部多加一个Point,这个Point用来
            * 正确产生Step Series的最后一个横阶梯
            */

            CTemperatureSequence seq;

            if (e.NewValue == null)
                seq = new CTemperatureSequence();
            else
            {
                seq = ((CTemperatureSequence)e.NewValue).Clone() as CTemperatureSequence;
                if (seq.Count > 0)
                {
                    /* 这里在最后加入一个Point用来修正Step Chart的View */
                    CTemperatureSequenceKeyPoint point = seq[seq.Count - 1];
                    seq.Add(new CTemperatureSequenceKeyPoint()
                    {
                        HoldTime = 0,
                        TargetTemperature = point.TargetTemperature
                    });
                }
            }
            owner._SeriesSequence.DataSource = seq;

            /* 更新实时温度曲线的描点间隔 */
            if (seq != null && seq.Count > 0 && owner.RealtimeTemperatureCollection != null)
                owner.RealtimeTemperatureCollection.TotalTime = owner.PresettedSequence.TotalTime;
        }
        /// <summary>
        /// Save the temperature sequence
        /// </summary>
        /// <param name="SequenceName"></param>
        /// <param name="SequenceInstance"></param>
        /// <returns></returns>
        public bool SaveTemperatureSequence(string SequenceName, CTemperatureSequence SequenceInstance)
        {
            bool ret = false;
            using (MySqlCommand cmd = new MySqlCommand() { CommandTimeout = COMMAND_TIMEOUT })
            {
                try
                {
                    if (Open())
                    {
                        StringBuilder cmdstr = new StringBuilder();
                        int order = 0;
                        cmdstr.Append("START TRANSACTION;");
                        foreach (CTemperatureSequenceKeyPoint p in SequenceInstance)
                        {
                            cmdstr.Append(
                                string.Format(
                                    "INSERT INTO `temperature_sequence` (`name`, `order`, `temper`, `consume`) VALUE (\"{0}\", {1}, {2}, {3});",
                                    new string[] { SequenceName, order.ToString(), p.TargetTemperature.ToString(), p.HoldTime.ToString() }));
                            order++;
                        }
                        cmdstr.Append("COMMIT;");
                        cmd.Connection = conn;

                        cmd.CommandText = cmdstr.ToString();
                        cmd.ExecuteNonQuery();
                        ret = true;
                    }
                    else
                    {
                        ret = false;
                    }
                }
                catch (Exception ex)
                {
                    strLastError = ex.Message;
                    ret = false;
                }
            }

            Close();
            return ret;
        }
        /// <summary>
        /// Save the basic info of a curing progress
        /// </summary>
        /// <param name="CureSN"></param>
        /// <param name="PatientName"></param>
        /// <param name="Sequence"></param>
        /// <returns></returns>
        public bool CreateCureHistory(string CureSN, string PatientName, int Channel, CTemperatureSequence Sequence)
        {
            bool ret = false;
            using (MySqlCommand cmd = new MySqlCommand() { CommandTimeout = COMMAND_TIMEOUT })
            {
                try
                {
                    if (Open())
                    {
                        cmd.Connection = conn;

                        MySqlParameter para = new MySqlParameter();
                        para.ParameterName = "cure_sn";
                        para.DbType = DbType.String;
                        para.Value = CureSN;
                        cmd.Parameters.Add(para);

                        para = new MySqlParameter();
                        para.ParameterName = "patient_name";
                        para.DbType = DbType.String;
                        para.Value = PatientName;
                        cmd.Parameters.Add(para);

                        para = new MySqlParameter();
                        para.ParameterName = "cure_channel";
                        para.DbType = DbType.Int16;
                        para.Value = Channel;
                        cmd.Parameters.Add(para);

                        para = new MySqlParameter();
                        para.ParameterName = "sequence_name";
                        para.DbType = DbType.String;
                        para.Value = Sequence.SequenceName;
                        cmd.Parameters.Add(para);

                        para = new MySqlParameter();
                        para.ParameterName = "updated_time";
                        para.DbType = DbType.DateTime;
                        para.Value = DateTime.MinValue;
                        cmd.Parameters.Add(para);

                        para = new MySqlParameter();
                        para.ParameterName = "seq_snapshot";
                        para.DbType = DbType.Binary;
                        para.Value = CPublicMethods.SerializeObjectToBinaryArray(Sequence);
                        cmd.Parameters.Add(para);

                        cmd.CommandText =
                            @"
                                INSERT INTO `xuanjiyi`.`cure_history` (
                                  `cure_sn`,
                                  `patient_name`,
                                  `cure_channel`,
                                  `sequence_name`,
                                  `created_time`,
                                  `updated_time`,
                                  `seq_snapshot`
                                )
                                VALUES
                                  (
                                    @cure_sn,
                                    @patient_name,
                                    @cure_channel,
                                    @sequence_name,
                                    NOW(),
                                    @updated_time,
                                    @seq_snapshot
                                  );commit;";

                        if (cmd.ExecuteNonQuery() > 0)
                            ret = true;
                        else
                            ret = false;
                    }
                    else
                    {
                        ret = false;
                    }
                }
                catch (Exception ex)
                {
                    strLastError = ex.Message;
                    ret = false;
                }
            }

            Close();
            return ret;
        }
        /// <summary>
        /// Get the temperature sequence from the database
        /// </summary>
        /// <param name="SequenceName">温度序列名称</param>
        /// <param name="SequenceInstance">获取到的温度序列实例</param>
        /// <returns></returns>
        public bool GetTemperatureSequence(string SequenceName, out CTemperatureSequence SequenceInstance)
        {
            SequenceInstance = new CTemperatureSequence();

            bool ret = false;
            using (MySqlCommand cmd = new MySqlCommand() { CommandTimeout = COMMAND_TIMEOUT })
            {
                try
                {
                    if (Open())
                    {
                        cmd.Connection = conn;
                        cmd.CommandText = "SELECT `name`, `order`, `temper`, `consume`, `add_time` FROM `temperature_sequence` WHERE `name` = '" + SequenceName + "' AND `using`='E' ORDER BY `order` ASC" ;
                        MySqlDataReader dr = cmd.ExecuteReader();
                        if(dr.HasRows)
                        {
                            while(dr.Read())
                            {
                                CTemperatureSequenceKeyPoint p = new CTemperatureSequenceKeyPoint(Convert.ToDouble(dr["temper"]), Convert.ToInt16(dr["consume"]));
                                SequenceInstance.Add(p);
                            }
                        }

                        if (SequenceInstance.Count == 0)
                            SequenceInstance = null;
                        else
                            SequenceInstance.SequenceName = SequenceName;

                        ret = true;
                    }
                    else
                    {
                        ret = false;
                    }
                }
                catch (Exception ex)
                {
                    strLastError = ex.Message;
                    ret = false;
                }
            }

            Close();
            return ret;
        }
        /// <summary>
        /// 类初始化时执行的公共代码
        /// </summary>
        public void ClassInit(ref CControlCentral Controller)
        {
            control_central = Controller;
            control_central.ControllerCommStatusChanged += Control_central_ControllerCommStatusChanged;

            bgw_cure = new BackgroundWorker();
            bgw_cure.WorkerSupportsCancellation = true;
            bgw_cure.WorkerReportsProgress = true;
            bgw_cure.DoWork += bgw_cure_DoWork;
            bgw_cure.ProgressChanged += bgw_cure_ProgressChanged;
            bgw_cure.RunWorkerCompleted += Bgw_cure_RunWorkerCompleted;
            //bgw_cure.RunWorkerAsync();

            realtime_temperature_collection = new CRealtimeTemperatureCollection();
            presetted_sequence = new CTemperatureSequence();

            /* 初始化倒计时时基的定时器 */
            timer_countdown_tick = new Timer(OnTimerIntervalEvent, null, Timeout.Infinite, COUNTDOWN_BASETIME_MS);
            sem_countdown_tick = new Semaphore(0, 1);

            /* 初始化Command */
            command_start_resume = new RelayCommand<object>(p => StartOrResumeExecute(p));

            this.patient_name = "";
        }
        /// <summary>
        /// Save the basic info of a curing progress
        /// </summary>
        /// <param name="CureSN"></param>
        /// <param name="PatientName"></param>
        /// <param name="Sequence"></param>
        /// <returns></returns>
        public bool CreateCureHistory(string CureSN, string PatientName, int Channel, CTemperatureSequence Sequence)
        {
            bool ret = false;

            using (MySqlCommand cmd = new MySqlCommand()
            {
                CommandTimeout = COMMAND_TIMEOUT
            })
            {
                try
                {
                    if (Open())
                    {
                        cmd.Connection = conn;

                        MySqlParameter para = new MySqlParameter();
                        para.ParameterName = "cure_sn";
                        para.DbType        = DbType.String;
                        para.Value         = CureSN;
                        cmd.Parameters.Add(para);

                        para = new MySqlParameter();
                        para.ParameterName = "patient_name";
                        para.DbType        = DbType.String;
                        para.Value         = PatientName;
                        cmd.Parameters.Add(para);

                        para = new MySqlParameter();
                        para.ParameterName = "cure_channel";
                        para.DbType        = DbType.Int16;
                        para.Value         = Channel;
                        cmd.Parameters.Add(para);

                        para = new MySqlParameter();
                        para.ParameterName = "sequence_name";
                        para.DbType        = DbType.String;
                        para.Value         = Sequence.SequenceName;
                        cmd.Parameters.Add(para);

                        para = new MySqlParameter();
                        para.ParameterName = "updated_time";
                        para.DbType        = DbType.DateTime;
                        para.Value         = DateTime.MinValue;
                        cmd.Parameters.Add(para);

                        para = new MySqlParameter();
                        para.ParameterName = "seq_snapshot";
                        para.DbType        = DbType.Binary;
                        para.Value         = CPublicMethods.SerializeObjectToBinaryArray(Sequence);
                        cmd.Parameters.Add(para);

                        cmd.CommandText =
                            @"
                                INSERT INTO `xuanjiyi`.`cure_history` (
                                  `cure_sn`,
                                  `patient_name`,
                                  `cure_channel`,
                                  `sequence_name`,
                                  `created_time`,
                                  `updated_time`,
                                  `seq_snapshot`
                                ) 
                                VALUES
                                  (
                                    @cure_sn,
                                    @patient_name,
                                    @cure_channel,
                                    @sequence_name,
                                    NOW(),
                                    @updated_time,
                                    @seq_snapshot
                                  );commit;";

                        if (cmd.ExecuteNonQuery() > 0)
                        {
                            ret = true;
                        }
                        else
                        {
                            ret = false;
                        }
                    }
                    else
                    {
                        ret = false;
                    }
                }
                catch (Exception ex)
                {
                    strLastError = ex.Message;
                    ret          = false;
                }
            }

            Close();
            return(ret);
        }