示例#1
0
        public void Start()
        {
            if (IsRuning)
            {
                return;
            }

            LoadConfig();

            timer          = new System.Timers.Timer();
            timer.Interval = alarmUpdateInterval * 1000;
            timer.Elapsed += (o, e) =>
            {
                try
                {
                    ReceiveCommand(new RequestCommand());
                }
                catch (Exception ee)
                {
                    TraceManagerForPumpAlarm.AppendErrMsg("二供报警定时任务执行失败:" + ee.Message);
                }
            };
            timer.Enabled = true;

            IsRuning = true;

            Action <RequestCommand> action = ReceiveCommand;

            action.BeginInvoke(new RequestCommand(), null, null);
        }
示例#2
0
        private bool IsAlarm(PumpAlarmParam alarmParam)
        {
            if (!alarmParam.IsOkay)
            {
                return(false);
            }

            DateTime lastTime;
            DateTime startTime;
            DateTime endtime;

            try
            {
                // 截取出时间部分,转成当天时间比较
                var time = DataUtil.ToDateTime(alarmParam.lastTime);
                lastTime  = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, time.Hour, time.Minute, time.Second);
                startTime = Convert.ToDateTime(alarmParam._StartTime);
                endtime   = Convert.ToDateTime(alarmParam._EndTime);
            }
            catch (Exception e)
            {
                TraceManagerForPumpAlarm.AppendErrMsg(string.Format("报警参数表ID:{0} 报警时间点设置错误", e.Message));
                return(false);
            }
            if (DateTime.Compare(lastTime, startTime) >= 0 && DateTime.Compare(lastTime, endtime) <= 0)  // 时间判断
            {
                if (alarmParam._FType == "硬件报警")
                {
                    if (alarmParam.value == alarmParam._Standard)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (alarmParam._FType == "阈值报警")
                {
                    // 上阈值判断
                    if (alarmParam._Standardlev == 1 && alarmParam.value > alarmParam._Standard)
                    {
                        return(true);
                    }
                    // 下阈值判断
                    if (alarmParam._Standardlev == 0 && alarmParam.value < alarmParam._Standard)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#3
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;
        }
示例#4
0
        // 获取报警参数表对应的实时值
        private void GetRealAlarmValues(DataTable dtRealData, ref List <PumpAlarmParam> alarmParams)
        {
            foreach (PumpAlarmParam alarmParam in alarmParams)
            {
                // 是否启用
                if (alarmParam._IsUsed != 1)
                {
                    alarmParam.IsOkay = false;
                    continue;
                }

                // 判断报警类型
                if (alarmParam._FType != "阈值报警" && alarmParam._FType != "硬件报警")
                {
                    TraceManagerForPumpAlarm.AppendErrMsg(string.Format("报警参数表ID:{0}报警类型:{1}配置错误:", alarmParam._ID, alarmParam._FType));
                    alarmParam.IsOkay = false;
                    continue;
                }

                // 报警点
                DataRow[] drs = dtRealData.Select(string.Format(@"BASEID = '{0}'", alarmParam._PumpJZID));
                if (drs.Length == 0)
                {
                    TraceManagerForPumpAlarm.AppendErrMsg(string.Format("报警参数表绑定的机组ID:{0}未查询到相关实时信息,请及时删除:", alarmParam._PumpJZID));
                    alarmParam.IsOkay = false;
                    continue;
                }
                try
                {
                    alarmParam.value    = DataUtil.ToDouble(drs[0][alarmParam._FKey]);
                    alarmParam.lastTime = DataUtil.ToDateString(drs[0]["FUpdateDate"]);
                }
                catch (Exception e)
                {
                    TraceManagerForPumpAlarm.AppendErrMsg("匹配报警业务点实时值失败" + e.Message);
                    alarmParam.IsOkay = false;
                    continue;
                }

                alarmParam.IsOkay = true; //成功读取
            }
        }
示例#5
0
        public void Stop()
        {
            try
            {
                // 控制器服务
                if (commandManager != null)
                {
                    commandManager.Stop();
                    if (!commandManager.IsRuning)
                    {
                        TraceManagerForPumpAlarm.AppendDebug("控制器服务已停止");
                        this.commandManager = null;
                    }
                    else
                    {
                        TraceManagerForPumpAlarm.AppendErrMsg("控制器服务停止失败");
                    }
                }
            }
            catch { }

            IsRuning = false;
        }
示例#6
0
        public void Start(out string errMsg)
        {
            // 子服务启动失败,应该不影响其他子服务
            errMsg = "";

            try
            {
                // Pump-OPC通信子服务
                if (Config.configInfo.confSonOPCPumpDataService != null && Config.configInfo.confSonOPCPumpDataService.IsNeedRun)
                {
                    opcPumpService = new OPCPumpService(Config.configInfo.confSonOPCPumpDataService);
                    opcPumpService.Start(out errMsg);
                    if (opcPumpService.IsRuning)
                    {
                        TraceManagerForOPC.AppendInfo("Pump-OPC通信子服务已经启动");
                    }
                    else
                    {
                        errMsg = "Pump-OPC通信子服务启动失败:" + errMsg;
                        TraceManagerForOPC.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForOPC.AppendErrMsg("Pump-OPC通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // Scada-OPC通信子服务
                if (Config.configInfo.confSonOPCScadaDataService != null && Config.configInfo.confSonOPCScadaDataService.IsNeedRun)
                {
                    opcScadaService = new OPCScadaService(Config.configInfo.confSonOPCScadaDataService);
                    opcScadaService.Start(out errMsg);
                    if (opcScadaService.IsRuning)
                    {
                        TraceManagerForOPC.AppendInfo("Scada-OPC通信子服务已经启动");
                    }
                    else
                    {
                        errMsg = "Scada-OPC通信子服务启动失败:" + errMsg;
                        TraceManagerForOPC.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForOPC.AppendErrMsg("Scada-OPC通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // 二供WEB-pump通信子服务
                if (Config.configInfo.confSonWebPandaPumpDataService != null && Config.configInfo.confSonWebPandaPumpDataService.IsNeedRun)
                {
                    webPandaPumpService = new WEBPandaPumpService(Config.configInfo.confSonWebPandaPumpDataService);
                    webPandaPumpService.Start(out errMsg);
                    if (webPandaPumpService.IsRuning)
                    {
                        TraceManagerForWeb.AppendInfo("二供WEB通信子服务已经启动");
                    }
                    else
                    {
                        errMsg = "二供WEB通信子服务启动失败:" + errMsg;
                        TraceManagerForWeb.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForWeb.AppendErrMsg("二供WEB通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // WEB-pump-Scada 通信子服务
                if (Config.configInfo.confSonWebPandaPumpScadaDataService != null && Config.configInfo.confSonWebPandaPumpScadaDataService.IsNeedRun)
                {
                    webPandaPumpScadaService = new WEBPandaPumpSCADAService(Config.configInfo.confSonWebPandaPumpScadaDataService);
                    webPandaPumpScadaService.Start(out errMsg);
                    if (webPandaPumpScadaService.IsRuning)
                    {
                        TraceManagerForWeb.AppendInfo("WEB-pandaPump_Scada 通信子服务已经启动");
                    }
                    else
                    {
                        errMsg = "WEB-pandaPump_Scada 通信子服务启动失败:" + errMsg;
                        TraceManagerForWeb.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForWeb.AppendErrMsg("WEB-pandaPump_Scada 通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // SACADA—WEB-监测点通信子服务
                if (Config.configInfo.confSonWebPandaYLDataService != null && Config.configInfo.confSonWebPandaYLDataService.IsNeedRun)
                {
                    webPandaYLScadaService = new WEBPandaYLSacdaService(Config.configInfo.confSonWebPandaYLDataService);
                    webPandaYLScadaService.Start(out errMsg);
                    if (webPandaYLScadaService.IsRuning)
                    {
                        TraceManagerForWeb.AppendInfo("SACADA—WEB-监测点通信子服务已经启动");
                    }
                    else
                    {
                        errMsg = "SACADA—WEB-监测点通信子服务启动失败:" + errMsg;
                        TraceManagerForWeb.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForWeb.AppendErrMsg("SACADA—WEB-监测点通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // SACADA—WEB-综合测点通信子服务
                if (Config.configInfo.confSonWebPandaZHCDDataService != null && Config.configInfo.confSonWebPandaZHCDDataService.IsNeedRun)
                {
                    webPandaZHCDScadaServcice = new WEBPandaZHCDSacdaService(Config.configInfo.confSonWebPandaZHCDDataService);
                    webPandaZHCDScadaServcice.Start(out errMsg);
                    if (webPandaZHCDScadaServcice.IsRuning)
                    {
                        TraceManagerForWeb.AppendInfo("SACADA—WEB-综合测点通信子服务已经启动");
                    }
                    else
                    {
                        errMsg = "SACADA—WEB-综合测点通信子服务启动失败:" + errMsg;
                        TraceManagerForWeb.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForWeb.AppendErrMsg("SACADA—WEB-综合测点通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // 二供报警服务
                if (Config.configInfo.confSonCityIoTPumpAlarm != null && Config.configInfo.confSonCityIoTPumpAlarm.IsNeedRun)
                {
                    pumpAlarmService = new PumpAlarmService(Config.configInfo.confSonCityIoTPumpAlarm);
                    pumpAlarmService.Start(out errMsg);
                    if (pumpAlarmService.IsRuning)
                    {
                        TraceManagerForPumpAlarm.AppendInfo("二供报警服务已经启动");
                    }
                    else
                    {
                        errMsg = "二供报警服务启动失败:" + errMsg;
                        TraceManagerForPumpAlarm.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForPumpAlarm.AppendErrMsg("二供报警服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // 历史抽稀服务
                if (Config.configInfo.confSonHisVacuateService != null && Config.configInfo.confSonHisVacuateService.IsNeedRun)
                {
                    hisVacuate = new HisVacuate(Config.configInfo.confSonHisVacuateService);
                    hisVacuate.Start(out errMsg);
                    if (hisVacuate.IsRuning)
                    {
                        TraceManagerForHisVacuate.AppendInfo("历史抽稀服务已经启动");
                    }
                    else
                    {
                        errMsg = "历史抽稀服务启动失败:" + errMsg;
                        TraceManagerForHisVacuate.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForHisVacuate.AppendErrMsg("历史抽稀服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // 特殊项目子服务
                if (Config.configInfo.confSonProjectDataService != null && Config.configInfo.confSonProjectDataService.IsNeedRun)
                {
                    if (!Config.configInfo.confSonProjectDataService.EnvIsOkay)
                    {
                        TraceManagerForProject.AppendErrMsg("特殊项目动态库环境配置异常:" + Config.configInfo.confSonProjectDataService.ErrMsg);
                    }
                    else
                    {
                        caseManagerInjection = Interface.GetInjection(Config.configInfo.confSonProjectDataService.DllPath);
                        caseManagerInjection.Start(out errMsg);
                        if (caseManagerInjection.IsRuning)
                        {
                            TraceManagerForProject.AppendInfo(Config.configInfo.confSonProjectDataService.ProjectName + "服务已经启动");
                        }
                        else
                        {
                            errMsg = Config.configInfo.confSonProjectDataService.ProjectName + "服务启动失败:" + errMsg;
                            TraceManagerForProject.AppendErrMsg(errMsg);
                        }
                    }
                }
            }
            catch (Exception e) { TraceManagerForProject.AppendErrMsg(Config.configInfo.confSonProjectDataService.ProjectName + "服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            IsRuning = true;
        }
示例#7
0
        public void Stop()
        {
            try
            {
                // 特殊项目子服务
                if (this.caseManagerInjection != null)
                {
                    this.caseManagerInjection.Stop();
                    if (this.caseManagerInjection.IsRuning)
                    {
                        TraceManagerForProject.AppendErrMsg(Config.configInfo.confSonProjectDataService.ProjectName + "服务停止失败");
                    }
                    else
                    {
                        TraceManagerForProject.AppendInfo(Config.configInfo.confSonProjectDataService.ProjectName + "服务已经全部停止");
                    }
                    this.caseManagerInjection = null;
                }
            }
            catch (Exception e) { TraceManagerForProject.AppendErrMsg(Config.configInfo.confSonProjectDataService.ProjectName + "服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                //  历史抽稀服务
                if (this.hisVacuate != null)
                {
                    this.hisVacuate.Stop();
                    if (this.hisVacuate.IsRuning)
                    {
                        TraceManagerForHisVacuate.AppendErrMsg("历史抽稀服务停止失败");
                    }
                    else
                    {
                        TraceManagerForHisVacuate.AppendInfo("历史抽稀服务已经全部停止");
                    }
                    this.hisVacuate = null;
                }
            }
            catch (Exception e) { TraceManagerForHisVacuate.AppendErrMsg("历史抽稀服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                //  二供报警服务
                if (this.pumpAlarmService != null)
                {
                    this.pumpAlarmService.Stop();
                    if (this.pumpAlarmService.IsRuning)
                    {
                        TraceManagerForPumpAlarm.AppendErrMsg("二供报警服务停止失败");
                    }
                    else
                    {
                        TraceManagerForPumpAlarm.AppendInfo("二供报警服务已经全部停止");
                    }
                    this.pumpAlarmService = null;
                }
            }
            catch (Exception e) { TraceManagerForPumpAlarm.AppendErrMsg("二供报警服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                //  SACADA—WEB-综合测点通信子服务
                if (this.webPandaZHCDScadaServcice != null)
                {
                    this.webPandaZHCDScadaServcice.Stop();
                    if (this.webPandaZHCDScadaServcice.IsRuning)
                    {
                        TraceManagerForWeb.AppendErrMsg("SACADA-WEB-综合测点通信子服务停止失败");
                    }
                    else
                    {
                        TraceManagerForPumpAlarm.AppendInfo("SACADA—WEB-综合测点通信子服务已经全部停止");
                    }
                    this.webPandaZHCDScadaServcice = null;
                }
            }
            catch (Exception e) { TraceManagerForWeb.AppendErrMsg("SACADA—WEB-综合测点通信子服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                //  SACADA—WEB-监测点通信子服务
                if (this.webPandaYLScadaService != null)
                {
                    this.webPandaYLScadaService.Stop();
                    if (this.webPandaYLScadaService.IsRuning)
                    {
                        TraceManagerForWeb.AppendErrMsg("SACADA—WEB-监测点通信子服务停止失败");
                    }
                    else
                    {
                        TraceManagerForPumpAlarm.AppendInfo("SACADA—WEB-监测点通信子服务已经全部停止");
                    }
                    this.webPandaYLScadaService = null;
                }
            }
            catch (Exception e) { TraceManagerForWeb.AppendErrMsg("SACADA—WEB-监测点通信子服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                //  WEB-pandaPump_Scada 通信子服务
                if (this.webPandaPumpScadaService != null)
                {
                    this.webPandaPumpScadaService.Stop();
                    if (this.webPandaPumpScadaService.IsRuning)
                    {
                        TraceManagerForWeb.AppendErrMsg("二供WEB通信子服务停止失败");
                    }
                    else
                    {
                        TraceManagerForPumpAlarm.AppendInfo("二供WEB通信子服务已经全部停止");
                    }
                    this.webPandaPumpScadaService = null;
                }
            }
            catch (Exception e) { TraceManagerForWeb.AppendErrMsg("二供WEB通信子服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                //  二供WEB通信子服务
                if (this.webPandaPumpService != null)
                {
                    this.webPandaPumpService.Stop();
                    if (this.webPandaPumpService.IsRuning)
                    {
                        TraceManagerForWeb.AppendErrMsg("二供WEB通信子服务停止失败");
                    }
                    else
                    {
                        TraceManagerForPumpAlarm.AppendInfo("二供WEB通信子服务已经全部停止");
                    }
                    this.webPandaPumpService = null;
                }
            }
            catch (Exception e) { TraceManagerForWeb.AppendErrMsg("二供WEB通信子服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                //  Scada-OPC通信子服务
                if (this.opcScadaService != null)
                {
                    this.opcScadaService.Stop();
                    if (this.opcScadaService.IsRuning)
                    {
                        TraceManagerForOPC.AppendErrMsg("Scada-OPC通信子服务停止失败");
                    }
                    else
                    {
                        TraceManagerForPumpAlarm.AppendInfo("Scada-OPC通信子服务已经全部停止");
                    }
                    this.opcScadaService = null;
                }
            }
            catch (Exception e) { TraceManagerForOPC.AppendErrMsg("Scada-OPC通信子服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // Pump-OPC通信子服务
                if (this.opcPumpService != null)
                {
                    this.opcPumpService.Stop();
                    if (this.opcPumpService.IsRuning)
                    {
                        TraceManagerForOPC.AppendErrMsg("Pump-OPC通信子服务停止失败");
                    }
                    else
                    {
                        TraceManagerForPumpAlarm.AppendInfo("Pump-OPC通信子服务已经全部停止");
                    }
                    this.opcPumpService = null;
                }
            }
            catch (Exception e) { TraceManagerForOPC.AppendErrMsg("Pump-OPC通信子服务停止失败:" + e.Message + "堆栈:" + e.StackTrace); }

            IsRuning = false;
        }
示例#8
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
        }
示例#9
0
        // 实时表是否在线字段实时维护
        private void RunPumpJZOnline()
        {
            PumpJZDataOper.Instance.InitPumpRealData(out string errMsg);
            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                TraceManagerForPumpAlarm.AppendErrMsg(errMsg);
                return;
            }

            // 加载机组表信息
            string    sql = @"select FOnLine,FUpdateDate,TempTime,BASEID from PumpRealData;";
            DataTable dt  = DBUtil.ExecuteDataTable(sql, out errMsg);

            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                TraceManagerForPumpAlarm.AppendErrMsg("加载机组实时表信息失败:" + errMsg);
                return;
            }
            List <PumpJZOnline> jzs = new List <PumpJZOnline>();

            foreach (DataRow dr in dt.Rows)
            {
                PumpJZOnline jZOnline = new PumpJZOnline()
                {
                    _FOnLine     = DataUtil.ToInt(dr["FOnLine"]),
                    _FUpdateDate = DataUtil.ToDateString(dr["FUpdateDate"]).Trim(),
                    _BASEID      = DataUtil.ToString(dr["BASEID"]).Trim()
                };
                jzs.Add(jZOnline);
            }

            // 最后更新时间是否超时
            int    i         = 0;
            string tableSQL  = "";
            bool   isTimeout = false;

            foreach (PumpJZOnline jz in jzs)
            {
                isTimeout = false;// 复位
                if (jz._FOnLine == 0 && !string.IsNullOrWhiteSpace(jz._FUpdateDate))
                {
                    continue;  // 离线状态正常,不要更新到数据库
                }
                if (string.IsNullOrWhiteSpace(jz._FUpdateDate))
                {
                    jz._FOnLine     = 0;
                    jz._FUpdateDate = DataUtil.ToDateString(DateTime.Now);
                    isTimeout       = true;// 需要更新到库
                }
                if (DateTime.Now - DataUtil.ToDateTime(jz._FUpdateDate) > TimeSpan.FromMinutes(this.timeout))
                {
                    jz._FOnLine = 0;
                    isTimeout   = true;// 需要更新到库
                }

                if (jz._FOnLine == 0 && isTimeout == true) // 已超时,拼接SQL
                {
                    string cache = string.Format(@"select {0} FOnLine ,'{1}' FUpdateDate,'{2}' BASEID 
                                                    ",
                                                 jz._FOnLine, jz._FUpdateDate, jz._BASEID);
                    if (i == 0)
                    {
                        tableSQL += cache;
                        i++;
                    }
                    else
                    {
                        tableSQL += " union all " + cache;
                    }
                }
            }
            // 更新状态到数据库
            if (string.IsNullOrWhiteSpace(tableSQL))
            {
                return;
            }
            string mergeSQL = string.Format(@"merge into PumpRealData t
                                            using( {0} ) as s
                                            on t.BASEID=s.BASEID 
                                            when matched then 
                                            update set t.FOnLine=s.FOnLine,t.FUpdateDate=s.FUpdateDate;
                                            ", tableSQL);

            DBUtil.ExecuteNonQuery(mergeSQL, out errMsg);
            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                TraceManagerForPumpAlarm.AppendErrMsg("二供实时表离线状态更新失败:" + errMsg);
                return;
            }
        }