コード例 #1
0
ファイル: Helper.cs プロジェクト: ZQuanLi/Test
        /// <summary>
        /// 保存采集项数据
        /// </summary>
        /// <param name="lpszDbVarName"></param>
        /// <param name="lpszVal"></param>
        /// <param name="lpszdateTime"></param>
        internal static void SaveCollectCache(string lpszDbVarName, string lpszVal, DateTime lpszdateTime)
        {
            string        mkey    = Helper.ProjectKey + lpszDbVarName;
            CollectVModel collect = null;

            if (NCSys.Result.TryGetValue(mkey, out collect) == false)
            {
                try
                {
                    collect = new CollectVModel();
                    System.Data.DataTable dtSource = processBll.GetMapInfo(lpszDbVarName);
                    if (dtSource.Rows.Count != 1)
                    {
                        FileLog.Debug("KEY:" + lpszDbVarName + "值信息不存在数据库中");
                        return;
                    }
                    collect.RstVar = new RstVar()
                    {
                        dwUserData = 0
                    };
                    foreach (DataRow dr in dtSource.Rows)
                    {
                        collect.Module_id           = CommFunc.ConvertDBNullToInt32(dr["Module_id"]);
                        collect.ModuleAddr          = CommFunc.ConvertDBNullToString(dr["ModuleAddr"]);
                        collect.Fun_id              = CommFunc.ConvertDBNullToInt32(dr["Fun_id"]);
                        collect.UpTime              = CommFunc.ConvertDBNullToDateTime(dr["LastTime"]);
                        collect.RstVar.lpszVal      = dr["LastVal"] == DBNull.Value ? "" : CommFunc.ConvertDBNullToDecimal(dr["LastVal"]).ToString();
                        collect.RstVar.lpszdateTime = collect.UpTime;
                    }
                    NCSys.Result.TryAdd(mkey, collect);
                }
                catch (Exception ex)
                {
                    FileLog.Debug("获取DB数据错误:" + ex.Message + ex.StackTrace);
                    return;/*采集值反转*/
                }
            }
            if (CommFunc.ConvertDBNullToDateTime(collect.RstVar.lpszdateTime) > lpszdateTime)
            {
                FileLog.Debug("KEY:" + lpszDbVarName + "值采集时间反转");
                return;/*时间反转*/
            }
            if (CommFunc.ConvertDBNullToDecimal(collect.RstVar.lpszVal) > CommFunc.ConvertDBNullToDecimal(lpszVal))
            {
                FileLog.Debug("KEY:" + lpszDbVarName + "值采集数据反转");
                return;/*采集值反转*/
            }
            collect.RstVar.lpszVal      = lpszVal;
            collect.RstVar.lpszdateTime = lpszdateTime;
            collect.RstVar.dwUserData   = 0;
        }
コード例 #2
0
ファイル: ZpAlarm.cs プロジェクト: ZQuanLi/Test
        /// <summary>
        /// 增加告警到数据库
        /// </summary>
        /// <param name="lpszDbVarName"></param>
        /// <param name="lpszVal"></param>
        /// <param name="lpszdateTime"></param>
        /// <param name="errCode"></param>
        /// <param name="errTxt"></param>
        public static void DbAddAlarm(CommandVModel command, string lpszVal, DateTime lpszdateTime, AlarmType errCode, string errTxt, bool isSend)
        {
            DataProcessBLL bll        = new DataProcessBLL(command.Ledger, Config.Uid);
            StringBuilder  strContent = new StringBuilder();
            DataTable      dtSource   = bll.GetMapInfo(command.LpszDbVarName);
            int            ccc        = dtSource.Rows.Count;

            if (ccc == 0)
            {
                FileLog.WriteLog("告警模块变量:" + command.LpszDbVarName + "不存在映射表中");
                return;
            }
            if (ccc > 1)
            {
                FileLog.WriteLog("告警模块变量:" + command.LpszDbVarName + "在映射表中存在多个");
                return;
            }

            int    module_id  = CommFunc.ConvertDBNullToInt32(dtSource.Rows[0]["Module_id"]);
            int    co_id      = CommFunc.ConvertDBNullToInt32(dtSource.Rows[0]["Co_id"]);
            int    fun_id     = CommFunc.ConvertDBNullToInt32(dtSource.Rows[0]["Fun_id"]);
            string moduleAddr = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["ModuleAddr"]);
            string funType    = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["FunType"]);

            if (funType.Equals(V0Fun.LeakAlarm.ToString()))
            {
                if (lpszVal.Substring(0, 12).Contains("1"))
                {
                    int cnt = 0;
                    foreach (char c in lpszVal.Substring(0, 12).ToCharArray())
                    {
                        string content = "";
                        ++cnt;
                        if (c.ToString().Equals("1"))
                        {
                            if (cnt <= 8)
                            {
                                content = "漏电流" + cnt + "发生告警";
                            }
                            else
                            {
                                content = "温度" + (cnt - 8) + "发生告警";
                            }
                        }
                        if (!string.IsNullOrEmpty(content))
                        {
                            if (!string.IsNullOrEmpty(strContent.ToString()))
                            {
                                strContent.Append(";");
                            }
                            strContent.Append(content);
                        }
                    }
                }
            }
            else
            {
                string content = "";
                System.Reflection.FieldInfo info = typeof(V0Fun).GetField(funType);
                if (info != null)
                {
                    var obj = info.GetCustomAttributes(typeof(DisplayAttribute), false);
                    if (obj != null)
                    {
                        foreach (DisplayAttribute md in obj)
                        {
                            content = md.Name;
                        }
                    }
                }
                strContent.Append(content);
            }
            long log_id = bll.AddAlarm(co_id, module_id, moduleAddr, errCode.ToString(), fun_id, strContent.ToString(), lpszVal, lpszdateTime, (int)errCode, errTxt);

            if (isSend == true)
            {/*发送告警*/
                SendHd(command.Ledger, log_id, errCode, HdType.AL_Sms, errTxt, module_id);
                SendHd(command.Ledger, log_id, errCode, HdType.AL_Email, errTxt, module_id);
            }
        }