Esempio n. 1
0
        public void Start(out string errMsg)
        {
            errMsg = "";

            if (IsRuning)
            {
                return;
            }

            try
            {
                // 环境检查
                if (!EnvChecker.Check(out errMsg))
                {
                    return;
                }
                TraceManagerForPumpAlarm.AppendDebug("环境检查通过");

                // 控制器服务
                if (commandManager != null)
                {
                    commandManager.Stop();
                }
                commandManager = new CommandManager();
                commandManager.Start();
                if (commandManager.IsRuning)
                {
                    TraceManagerForPumpAlarm.AppendDebug("控制器服务已经打开");
                }
                else
                {
                    TraceManagerForPumpAlarm.AppendErrMsg("控制器服务打开失败");
                    Stop();
                    return;
                }
            }
            catch (Exception e)
            {
                errMsg = e.Message;
                Stop();
                return;
            }

            IsRuning = true;
        }
Esempio n. 2
0
        public void Stop()
        {
            try
            {
                // 控制器服务
                if (commandManager != null)
                {
                    commandManager.Stop();
                    if (!commandManager.IsRuning)
                    {
                        TraceManagerForPumpAlarm.AppendDebug("控制器服务已停止");
                        this.commandManager = null;
                    }
                    else
                    {
                        TraceManagerForPumpAlarm.AppendErrMsg("控制器服务停止失败");
                    }
                }
            }
            catch { }

            IsRuning = false;
        }
Esempio n. 3
0
        private void RunPumpAlarm()
        {
            System.Diagnostics.Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start(); //  开始监视代码运行时间

            #region 查询机组实时表
            string    sqlPumpRealData = @"select t1.* from PumpRealData t1,Pump t2, PumpJZ t3 where t2.ID=t3.PumpId and (t2.是否删除=0 or t2.是否删除 is null) and (t3.是否删除=0 or t3.是否删除 is null)  and t1.BASEID= CONVERT(varchar(50), t3.ID);";
            DataTable dtRealData      = DBUtil.ExecuteDataTable(sqlPumpRealData, out string errMsg);
            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                TraceManagerForPumpAlarm.AppendErrMsg("查询二供实时数据失败:" + errMsg);
                return;
            }
            #endregion

            #region 查询报警参数表
            string    sqlPumpAlarmParam = @"select t1.* from PumpAlarmParam t1,Pump t2, PumpJZ t3 where t2.ID=t3.PumpId and (t2.是否删除=0 or t2.是否删除 is null) and (t3.是否删除=0 or t3.是否删除 is null) and t1.是否启用=1 and t1.PumpJZID= CONVERT(varchar(50), t3.ID);";
            DataTable dtAlarmParam      = DBUtil.ExecuteDataTable(sqlPumpAlarmParam, out errMsg);
            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                TraceManagerForPumpAlarm.AppendErrMsg("查询二供报警参数失败:" + errMsg);
                return;
            }
            List <PumpAlarmParam> alarmParams = new List <PumpAlarmParam>();
            foreach (DataRow dr in dtAlarmParam.Rows)
            {
                PumpAlarmParam pumpAlarmParam = new PumpAlarmParam()
                {
                    _ID          = DataUtil.ToInt(dr["ID"]),
                    _FCreateDate = DataUtil.ToDateString(dr["FCreateDate"]).Trim(),
                    _StartTime   = DataUtil.ToString(dr["StartTime"]).Trim(),
                    _EndTime     = DataUtil.ToString(dr["EndTime"]).Trim(),
                    _PumpJZID    = DataUtil.ToString(dr["PumpJZID"]).Trim(),
                    _Standard    = DataUtil.ToDouble(dr["Standard"]),
                    _Standardlev = DataUtil.ToDouble(dr["Standardlev"]),
                    _IsUsed      = DataUtil.ToInt(dr["是否启用"]),
                    _FKey        = DataUtil.ToString(dr["FKey"]).Trim(),
                    _FType       = DataUtil.ToString(dr["FType"]).Trim(),
                    _Unit        = DataUtil.ToString(dr["Unit"]).Trim(),
                    _FMsg        = DataUtil.ToString(dr["FMsg"]).Trim(),
                    _FLev        = DataUtil.ToInt(dr["FLev"])
                };
                alarmParams.Add(pumpAlarmParam);
            }
            #endregion

            #region 查询实时报警表
            string    sqlPumpAlarmTimely = @"select * from PumpAlarmTimely where AlarmOrWarn=1";
            DataTable dtAlarmTimely      = DBUtil.ExecuteDataTable(sqlPumpAlarmTimely, out errMsg);
            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                TraceManagerForPumpAlarm.AppendErrMsg("查询二供实时报警失败:" + errMsg);
                return;
            }
            List <PumpAlarmTimely> alarmTimelys = new List <PumpAlarmTimely>();
            foreach (DataRow dr in dtAlarmTimely.Rows)
            {
                PumpAlarmTimely alarmTimely = new PumpAlarmTimely()
                {
                    _ID              = DataUtil.ToInt(dr["ID"]),
                    _PumpJZID        = DataUtil.ToString(dr["PumpJZID"]).Trim(),
                    _ParamID         = DataUtil.ToInt(dr["ParamID"]),
                    _FStatus         = DataUtil.ToInt(dr["FStatus"]),
                    _FIsPhone        = DataUtil.ToInt(dr["FIsPhone"]),
                    _BeginAlarmTime  = DataUtil.ToDateString(dr["BeginAlarmTime"]).Trim(),
                    _UpdateAlarmTime = DataUtil.ToDateString(dr["UpdateAlarmTime"]).Trim(),
                    _AlarmOrWarn     = DataUtil.ToInt(dr["AlarmOrWarn"]),
                    _Tips            = DataUtil.ToString(dr["Tips"]).Trim(),
                    _Fvalue          = DataUtil.ToString(dr["Fvalue"]).Trim()
                };
                alarmTimelys.Add(alarmTimely);
            }
            #endregion

            #region 执行报警维护SQL
            GetRealAlarmValues(dtRealData, ref alarmParams); // 得到报警参数里面的值

            string sql = GetHisAlarmSQL(alarmParams, alarmTimelys);
            string errHis = "", errReal = "";
            if (!string.IsNullOrWhiteSpace(sql))
            {
                DBUtil.ExecuteNonQuery(sql, out errHis);
                if (!string.IsNullOrEmpty(errHis))
                {
                    TraceManagerForPumpAlarm.AppendErrMsg("更新历史报警信息失败" + errHis);
                }
            }
            sql = GetRealAlarmSQL(alarmParams);
            if (!string.IsNullOrWhiteSpace(sql))
            {
                DBUtil.ExecuteNonQuery(sql, out errReal);
                if (!string.IsNullOrEmpty(errReal))
                {
                    TraceManagerForPumpAlarm.AppendErrMsg("更新实时报警信息失败" + errReal);
                }
            }
            stopwatch.Stop();                                   //  停止监视
            TimeSpan timespan     = stopwatch.Elapsed;          //  获取当前实例测量得出的总时间
            double   milliseconds = timespan.TotalMilliseconds; //  总毫秒数

            if (string.IsNullOrWhiteSpace(errHis) && string.IsNullOrWhiteSpace(errReal))
            {
                TraceManagerForPumpAlarm.AppendDebug("已更新报警信息" + ",耗时:" + milliseconds.ToString() + "毫秒");
            }

            //string sql = GetAlarmHisSQL(alarmParams, alarmTimelys) + GetAlarmRealSQL(alarmParams);
            //if (string.IsNullOrEmpty(sql))
            //{
            //    TraceManager.AppendErrMsg("未查询到相关报警点信息");
            //    return;
            //}
            //DBUtil.ExecuteNonQuery(sql, out string err);
            //if (!string.IsNullOrEmpty(err))
            //    TraceManager.AppendErrMsg("更新报警信息失败" + err);
            //else
            //    TraceManager.AppendDebug("已更新报警信息");
            #endregion
        }