示例#1
0
        /// <summary>
        /// 首页设备数
        /// </summary>
        /// <returns></returns>
        public APIRst GetEquInfo()
        {
            APIRst rst = new APIRst();

            try
            {
                DataTable dtSource = bll.GetEquCount();
                dtSource.Columns.Add("IsGz", typeof(System.Int32));
                int allCount = dtSource.Rows.Count;
                int mdCount = 0, gzzs = 0, dbgzzs = 0;
                foreach (DataRow dr in dtSource.Rows)
                {
                    string key      = user.CacheKey + CommFunc.ConvertDBNullToInt32(dr["Module_id"]) + "." + CommFunc.ConvertDBNullToString(dr["ModuleAddr"]) + ".Comm";
                    int    isDefine = CommFunc.ConvertDBNullToInt32(dr["IsDefine"]);

                    RstVar var = MemcachedMgr.GetVal <RstVar>(key);
                    int    gz  = (var == null ? 1 : (int)CommFunc.ConvertDBNullToDecimal(var.lpszVal) == 0 ? 0 : 1);
                    gzzs = gzzs + gz;
                    if (isDefine == 100)
                    {
                        mdCount = mdCount + 1;
                        dbgzzs  = dbgzzs + gz;
                    }
                }
                rst.data = new { Count = allCount, MdCount = mdCount, Gzzs = gzzs, Dbgzzs = dbgzzs };
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("获取首页设备数:" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
示例#2
0
文件: MgrBLL.cs 项目: ZQuanLi/Test
        public object GetMgrCtrl(string pk, string moduleName)
        {
            DataTable     dtSource = dal.GetMgrCtrl(moduleName);
            List <object> dd       = new List <object>();

            foreach (DataRow drp in dtSource.Select("Parent_id=0"))
            {
                int           cc = 0, sc = 0;;
                List <object> cp = new List <object>();
                foreach (DataRow dr in dtSource.Select("Parent_id=" + CommFunc.ConvertDBNullToInt32(drp["Module_id"])))
                {
                    string   key       = pk + CommFunc.ConvertDBNullToString(dr["LpszDbVarName"]);
                    string   dataValue = CommFunc.ConvertDBNullToString(dr["DataValue"]);
                    int      status    = CommFunc.ConvertDBNullToInt32(dr["Status"]);
                    DateTime update_dt = CommFunc.ConvertDBNullToDateTime(dr["Update_dt"]);

                    int    i   = 0;
                    RstVar var = null;
                    while (++i <= 2)
                    {
                        var = MemcachedMgr.GetVal <RstVar>(key);
                        if (var != null)
                        {
                            break;
                        }
                        System.Threading.Thread.Sleep(50);
                    }
                    decimal?value      = null;// "未知";
                    int     realStatus = 1;
                    if (var != null)
                    {
                        value = CommFunc.ConvertDBNullToDecimal(var.lpszVal); // == 0 ? "合闸" : "拉闸";
                        sc    = sc + (CommFunc.ConvertDBNullToInt32(var.lpszVal) == 0 ? 1 : 0);
                    }
                    if (!string.IsNullOrEmpty(dataValue))
                    {
                        if (update_dt.AddMinutes(1) > DateTime.Now)
                        {/*在两分钟内重新监测一次,超过两分钟设置全部按缓存值*/
                            decimal realVal = value == null ? -1 : value.Value;
                            if (realVal == CommFunc.ConvertDBNullToDecimal(dataValue))
                            {/*值相等设置成功*/
                                realStatus = 1;
                            }
                            else
                            {
                                realStatus = 0;
                            }
                            value = CommFunc.ConvertDBNullToDecimal(dataValue);
                        }
                    }
                    cp.Add(new { rowId = ++cc, moduleName = CommFunc.ConvertDBNullToString(dr["ModuleName"]), tag = CommFunc.ConvertDBNullToString(dr["LpszDbVarName"]), value = value, status = realStatus });
                }
                dd.Add(new { moduleName = CommFunc.ConvertDBNullToString(drp["ModuleName"]), count = cc, online = sc, list = cp });
            }
            return(dd);
        }
示例#3
0
文件: Helper.cs 项目: ZQuanLi/Test
        private void Process()
        {
            while (true)
            {
                Thread.Sleep(1000);/*每一秒*/
                if (NCSys.IsRun == false)
                {
                    continue;
                }

                try
                {
                    this.GetProcessOfConfig();
                }
                catch (Exception ex)
                {
                    FileLog.Error("读取采集配置数据错误:" + ex.Message + ex.StackTrace);
                }
                try
                {
                    foreach (var s0 in NCSys.Result)
                    {
                        CollectVModel s1 = s0.Value;
                        if (DateTime.Now < s1.UpTime.AddMinutes(Helper.FrMd))
                        {
                            continue;
                        }

                        RstVar rst = s1.RstVar;
                        if (rst == null)
                        {
                            continue;
                        }
                        try
                        {
                            string msg;
                            int    errcode = processBll.DataProcess(s1.Module_id, s1.ModuleAddr, s1.Fun_id, rst.lpszVal, rst.lpszdateTime, out msg);
                            if (errcode < 0)
                            {
                                FileLog.Error("KEY:" + s0.Key + "值:" + rst.lpszVal + "数据处理结果错误:" + msg);
                            }
                            FileLog.Debug("KEY:" + s0.Key + "值:" + rst.lpszVal + "保存成功");
                        }
                        catch (Exception ex)
                        {
                            FileLog.Error("KEY:" + s0.Key + "值:" + rst.lpszVal + "采集时间:" + rst.lpszdateTime.ToString() + "数据处理结果错误:" + ex.Message);
                        }
                        s1.UpTime = DateTime.Now;/*入库时间*/
                    }
                }
                catch (Exception ex)
                {
                    FileLog.Error("数据处理错误:" + ex.Message + ex.StackTrace);
                }
            }
        }
示例#4
0
        private void GetRealVal(DataTable dt, out decimal pTotal, out decimal eTotal, out DateTime UTime)
        {
            pTotal = 0;
            eTotal = 0;
            UTime  = DateTime.MinValue;
            CacheUser user = WebConfig.GetSession();
            string    key  = (user == null || user.Uid == 0) ? "" : user.CacheKey;

            if (string.IsNullOrEmpty(key))
            {
                key = WebConfig.MemcachKey;
            }
            string ccKey = "";

            foreach (DataRow dr in dt.Rows)
            {
                ccKey = key + CommFunc.ConvertDBNullToString(dr["P_Tag"]);
                int    i   = 0;
                RstVar var = null;
                while (++i <= 2)
                {
                    var = MemcachedMgr.GetVal <RstVar>(ccKey);
                    if (var != null)
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(50);
                }
                if (var != null)
                {
                    pTotal += CommFunc.ConvertDBNullToDecimal(var.lpszVal);
                    if (var.lpszdateTime > UTime)
                    {
                        UTime = var.lpszdateTime;
                    }
                }
                //ccKey = key + CommFunc.ConvertDBNullToString(dr["E_Tag"]);
                //i = 0;
                //var = null;
                //while (++i <= 2)
                //{
                //    var = MemcachedMgr.GetVal<RstVar>(ccKey);
                //    if (var != null) break;
                //    System.Threading.Thread.Sleep(50);
                //}
                //if (var != null)
                //{
                //    eTotal += CommFunc.ConvertDBNullToDecimal(var.lpszVal);
                //    if (var.lpszdateTime > UTime) UTime = var.lpszdateTime;
                //}
            }
        }
示例#5
0
        /// <summary>
        /// 批量获取实时数据
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        public APIRst GetBatchRealVal(List <string> tags)
        {
            //List<string> tag = new List<string>();
            //CacheUser user = WebConfig.GetSession();
            string key = (user == null || user.Uid == 0) ? "" : user.CacheKey;

            if (string.IsNullOrEmpty(key))
            {
                key = WebConfig.MemcachKey;
            }
            string        ccKey = "";
            List <object> dd    = new List <object>();

            //foreach (var k in tags.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            foreach (var k in tags)
            {
                ccKey = key + k;
                int    i   = 0;
                RstVar var = null;
                if (k.Equals("2.WD01.Val"))
                {
                    //FileLog.WriteLog(ccKey);
                }
                while (++i <= 2)
                {
                    var = MemcachedMgr.GetVal <RstVar>(ccKey);
                    if (var != null)
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(50);
                }
                if (var == null)
                {
                    dd.Add(new { tag = k, value = "" });
                    //dd.Add(new { tag = k, value = new { lpszVal = (new Random(Guid.NewGuid().GetHashCode()).Next(100,250)).ToString(), lpszdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }});
                }
                else
                {
                    dd.Add(new { tag = k, value = new { lpszVal = var.lpszVal, lpszdateTime = var.lpszdateTime } });
                }
            }
            APIRst rst = new APIRst()
            {
                rst = true, data = dd
            };

            return(rst);
        }
示例#6
0
 /// <summary>
 /// 电气火灾列表
 /// </summary>
 /// <returns></returns>
 public APIRst GetDqhzList()
 {
     APIRst rst = new APIRst();
     try
     {
         List<object> list = new List<object>();
         DataTable dtSource = bll.GetDqhzList();
         var res1 = from s1 in dtSource.AsEnumerable()
                    group s1 by new { Module_id = CommFunc.ConvertDBNullToInt32(s1["Module_id"]) } into g1
                    select new
                    {
                        Module_id = g1.Key.Module_id,
                        ModuleName = CommFunc.ConvertDBNullToString(g1.First()["ModuleName"]),
                        MeterName = CommFunc.ConvertDBNullToString(g1.First()["MeterName"]),
                    };
         foreach (var o1 in res1)
         {
             
             List<object> rv = new List<object>();
             foreach (DataRow dr in dtSource.Select("Module_id=" + o1.Module_id))
             {
                 string lpszDbVarName = CommFunc.ConvertDBNullToString(dr["LpszDbVarName"]);
                 string funType = CommFunc.ConvertDBNullToString(dr["FunType"]);
                 string funName = CommFunc.ConvertDBNullToString(dr["FunName"]);
                 int scale = CommFunc.ConvertDBNullToInt32(dr["Scale"]);
                 RstVar vv = MemcachedMgr.GetVal<RstVar>(user.CacheKey + lpszDbVarName);
                 if (vv != null)
                 {
                     vv.lpszVal = CommFunc.ConvertDBNullToDecimal(vv.lpszVal).ToString("f" + scale);
                     rv.Add(new { FunType = funType, FunName = funName, Data = new { lpszVal = vv.lpszVal, lpszdateTime = vv.lpszdateTime } });
                 }
                 else
                 {
                     rv.Add(new { FunType = funType, FunName = funName, Data = "" });
                 }
             }
             list.Add(new { Module_id = o1.Module_id, MouleName = o1.ModuleName, MeterName = o1.MeterName, List = rv });
         }
         rst.data = list;
     }
     catch (Exception ex)
     {
         rst.rst = false;
         rst.err.code = (int)ResultCodeDefine.Error;
         rst.err.msg = ex.Message;
         FileLog.WriteLog("获取电气火灾列表:" + ex.Message + ex.StackTrace);
     }
     return rst;
 }
示例#7
0
文件: ZpAlarm.cs 项目: ZQuanLi/Test
        public static void DbEventWpf(CommandVModel command, string lpszVal, DateTime lpszdateTime, AlarmType errCode, string errTxt)
        {
            if (lpszVal == null || lpszdateTime.Year < 2000)
            {
                return;
            }
            if (errCode != AlarmType.Sue)
            {
                return;
            }

            DataProcessBLL bll = new DataProcessBLL(command.Ledger, Config.Uid);
            SysPro         pro;

            NCSys.Pro.TryGetValue(command.Ledger, out pro);
            if (pro == null)
            {
                FileLog.Error("CollectAlarm.DbEventWpf 模块没有项目:" + command.Ledger);
                return;
            }
            string        mkey    = pro.ProjectKey + command.LpszDbVarName;
            CollectVModel collect = null;

            if (NCSys.Result.TryGetValue(mkey, out collect) == false)
            {
                return;
            }

            RstVar rst   = collect.RstVar;// MemcachedMgr.GetVal<RstVar>(mkey);
            bool   isAdd = true;

            if (rst != null && !string.IsNullOrEmpty(rst.lpszVal))
            {
                MalignantVModel pp = JsonHelper.Deserialize <MalignantVModel>(rst.lpszVal);
                if (collect.IsDb == false)
                {
                    if (pp.CTime == lpszdateTime)
                    {
                        isAdd = false;
                    }
                }
                collect.IsDb = false;
            }
            if (isAdd == true)
            { /*增加到数据库中*/
                bll.AddAlarmOnCollect(command.Co_id, command.Module_id, command.ModuleAddr, command.FunType, command.Fun_id, lpszVal, (int)errCode, errTxt, lpszdateTime);
            }
        }
示例#8
0
        private RstVar GetRstVar(string key)
        {
            int    i   = 0;
            RstVar var = null;

            while (++i <= 2)
            {
                var = MemcachedMgr.GetVal <RstVar>(key);
                if (var != null)
                {
                    break;
                }
                System.Threading.Thread.Sleep(50);
            }
            return(var);
        }
示例#9
0
文件: MgrBLL.cs 项目: ZQuanLi/Test
        public object GetMgrStatus(string pk)
        {
            DataTable     dtSource = dal.GetMgrStatus();
            List <object> dd       = new List <object>();
            int           sc       = 0;
            int           oc       = 0;
            int           ec       = 0;

            foreach (DataRow drp in dtSource.Rows)
            {
                string key = pk + CommFunc.ConvertDBNullToString(drp["LpszDbVarName"]);
                int    i   = 0;
                RstVar var = null;
                while (++i <= 2)
                {
                    var = MemcachedMgr.GetVal <RstVar>(key);
                    if (var != null)
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(50);
                }
                decimal?status = null;
                if (var != null)
                {
                    status = CommFunc.ConvertDBNullToDecimal(var.lpszVal);
                    //sc = sc + (CommFunc.ConvertDBNullToDecimal(var.lpszVal) == 0 ? 1 : 0);
                    if (status == 0)
                    {
                        sc++;
                    }
                    else
                    {
                        oc++;
                    }
                }
                else
                {
                    ec++;
                }
                dd.Add(new { moduleName = CommFunc.ConvertDBNullToString(drp["CoName"]), status = status });
            }
            return(new { status = new { count = dtSource.Rows.Count, online = sc, offline = oc, errCnt = ec }, list = dd });
        }
示例#10
0
        public APIRst GetRealVal(string tag)
        {
            //CacheUser user = WebConfig.GetSession();
            string key = (user == null || user.Uid == 0) ? "" : user.CacheKey;

            if (string.IsNullOrEmpty(key))
            {
                key = WebConfig.MemcachKey;
            }
            key = key + tag;
            //FileLog.WriteLog("key:" + key);
            int    i   = 0;
            RstVar var = null;

            while (++i <= 2)
            {
                var = MemcachedMgr.GetVal <RstVar>(key);
                if (var != null)
                {
                    break;
                }
                System.Threading.Thread.Sleep(50);
            }
            APIRst rst = new APIRst()
            {
                rst = true
            };

            if (var == null)
            {
                rst.rst  = false;
                rst.data = null;
                rst.err  = new APIErr()
                {
                    code = -1, msg = "无数据"
                };
            }
            else
            {
                rst.data = new { lpszVal = var.lpszVal, lpszdateTime = var.lpszdateTime };
            }
            return(rst);
        }
示例#11
0
文件: MgrHelper.cs 项目: ZQuanLi/Test
        private int GetStatus(string tag, string dataValue, DateTime update_dt)
        {
            string key = user.CacheKey + tag;
            int    i   = 0;
            RstVar var = null;

            while (++i <= 2)
            {
                var = MemcachedMgr.GetVal <RstVar>(key);
                if (var != null)
                {
                    break;
                }
                System.Threading.Thread.Sleep(50);
            }
            decimal?value      = null;// "未知";
            int     realStatus = 1;

            if (var != null)
            {
                value = CommFunc.ConvertDBNullToDecimal(var.lpszVal); // 值
            }
            if (!string.IsNullOrEmpty(dataValue))
            {
                decimal realVal = value == null ? -1 : value.Value;
                if (realVal == CommFunc.ConvertDBNullToDecimal(dataValue))
                {/*值相等设置成功*/
                    realStatus = 1;
                }
                else
                {
                    if (update_dt.AddMinutes(1) > DateTime.Now)
                    {/*正在设置*/
                        realStatus = 0;
                    }
                    else
                    {/*超过两分钟设置全部按缓存值*/
                        realStatus = -1;
                    }
                }
            }
            return(realStatus);
        }
示例#12
0
        private void button3_Click(object sender, EventArgs e)
        {
            string key = this.textBox1.Text.Trim();
            RstVar ss  = new RstVar();

            ss.lpszdateTime = DateTime.Now;
            ss.lpszVal      = this.textBox2.Text.Trim();
            //string ss = this.textBox2.Text.Trim();
            //bool last = MemcachedMgr.SetVal(key, this.textBox2.Text.Trim());
            bool last = MemcachedMgr.SetVal(key, ss);

            if (last == true)
            {
                MessageBox.Show("成功");
            }
            else
            {
                MessageBox.Show("失败");
            }
        }
示例#13
0
        private void button4_Click(object sender, EventArgs e)
        {
            string key = this.textBox1.Text.Trim();
            //object ss1 = MemcachedMgr.GetVal(key);
            //this.textBox2.Text = ss1 == null ? "无值": ss1.ToString();
            //return;
            RstVar ss = MemcachedMgr.GetVal <RstVar>(key);

            if (ss != null)
            {
                this.textBox2.Text = "时间:" + ss.lpszdateTime.ToString();
                this.textBox2.Text = this.textBox2.Text + Environment.NewLine + "值:" + ss.lpszVal;
                //this.textBox2.Text = ss.lpszVal;
            }
            else
            {
                //object obj = MemcachedMgr.GetVal(key);
                //if (obj != null)
                //    this.textBox2.Text = obj.ToString();
                //else
                MessageBox.Show("获取值失败");
            }
        }
示例#14
0
        private RstVar GetRstVar(string tag)
        {
            string key = (user == null || user.Uid == 0) ? "" : user.CacheKey;

            if (string.IsNullOrEmpty(key))
            {
                key = WebConfig.MemcachKey;
            }
            key = key + tag;
            RstVar var = null;
            int    i   = 0;

            while (++i <= 2)
            {
                var = MemcachedMgr.GetVal <RstVar>(key);
                if (var != null)
                {
                    break;
                }
                System.Threading.Thread.Sleep(50);
            }
            return(var);
        }
示例#15
0
        private static void SaveCollectCache(int ledger, string lpszDbVarName, string lpszVal, DateTime lpszdateTime, UInt32 dwUserData)
        {
            SysPro pro = null;

            NCSys.Pro.TryGetValue(ledger, out pro);
            if (pro == null)
            {
                FileLog.Debug("获取账目数据错误");
                return;
            }
            string        mkey    = pro.ProjectKey + lpszDbVarName;
            CollectVModel collect = null;

            if (NCSys.Result.TryGetValue(mkey, out collect) == false)
            {
                //collect = new CollectVModel() { Ledger = ledger, Module_id = 0 };
                //return null;
            }
            if (collect == null || collect.Module_id == 0)
            {/*正常不出现此错误,除非上面数据库或逻辑错误*/
                FileLog.Debug("获取采集数据错误");
                return;
            }
            RstVar rstVar = MemcachedMgr.GetVal <RstVar>(collect.CachedKey);

            if (rstVar == null)
            {
                rstVar = new RstVar()
                {
                    lpszVal = lpszVal, lpszdateTime = lpszdateTime, dwUserData = dwUserData
                };
            }
            /////////////////////////////////////////////////////////////////
            bool isUpCached = true; // 是否更新内存

            if ((collect.FunType.Equals("E")) && pro.Auto == 0)
            {
                decimal curLpszVal = CommFunc.ConvertDBNullToDecimal(lpszVal);
                decimal chdLpszVal = CommFunc.ConvertDBNullToDecimal(rstVar.lpszVal);
                //if (decimal.TryParse(lpszVal, out curLpszVal) == false)
                //{
                //    string[] arr = lpszVal.Split(new char[] { ':', ',' }, StringSplitOptions.RemoveEmptyEntries);
                //    if (arr.Count() < 2)
                //    {
                //        FileLog.Debug("KEY:" + lpszDbVarName + "采集数据" + lpszVal + "格式异常");
                //    }
                //    else
                //    {
                //        curLpszVal = CommFunc.ConvertDBNullToDecimal(arr[1]);
                //    }
                //    if (!string.IsNullOrEmpty(collect.RstVar.lpszVal))
                //    {
                //        arr = collect.RstVar.lpszVal.Split(new char[] { ':', ',' }, StringSplitOptions.RemoveEmptyEntries);
                //        if (arr.Count() < 2)
                //        {
                //            FileLog.Debug("KEY:" + lpszDbVarName + "缓存的数据" + collect.RstVar.lpszVal + "格式异常");
                //        }
                //        else
                //        {
                //            chdLpszVal = CommFunc.ConvertDBNullToDecimal(arr[1]);
                //        }
                //    }
                //}
                if (chdLpszVal > curLpszVal)
                {
                    //collectInfo.errCode = AlarmType.Ez_1;
                    //collectInfo.errTxt = "上期采集值:" + CommFunc.ConvertDBNullToDecimal(collect.RstVar.lpszVal) + "本次采集值:" + CommFunc.ConvertDBNullToDecimal(lpszVal);
                    //collectInfo.isSend = 0;
                    //NCSys.AlarmCollect.Enqueue(collectInfo); /*更新数据库*/
                    isUpCached = false;
                    FileLog.Debug("KEY:" + lpszDbVarName + "采集数据反转" + " 上期采集值:" + chdLpszVal + "本次采集值:" + curLpszVal);
                }
                else
                {
                    if (pro.MaxVal != 0)
                    {
                        decimal useVal    = curLpszVal - chdLpszVal;/*当前使用量*/
                        decimal maxUseVal = (decimal)((lpszdateTime - rstVar.lpszdateTime).TotalMinutes / pro.FrMd) * pro.MaxVal;
                        if (useVal > maxUseVal)
                        {
                            //collectInfo.errCode = AlarmType.Err_OFlow;
                            //collectInfo.errTxt = "上期采集值:" + CommFunc.ConvertDBNullToDecimal(collect.RstVar.lpszVal) + "时间" + collect.RstVar.lpszdateTime.ToString("yyyy-MM-dd HH:mm:ss") + "本次采集值:" + CommFunc.ConvertDBNullToDecimal(lpszVal) + "时间" + lpszdateTime.ToString("yyyy-MM-dd HH:mm:ss");
                            //collectInfo.isSend = 0;
                            //NCSys.AlarmCollect.Enqueue(collectInfo); /*更新数据库*/
                            isUpCached = false;
                            FileLog.Debug("KEY:" + lpszDbVarName + "采集数据越限" + "上期采集值:" + chdLpszVal + "时间" + rstVar.lpszdateTime.ToString("yyyy-MM-dd HH:mm:ss") + "本次采集值:" + curLpszVal + "时间" + lpszdateTime.ToString("yyyy-MM-dd HH:mm:ss"));
                        }
                    }
                }
            }

            if (CommFunc.ConvertDBNullToDateTime(rstVar.lpszdateTime) > lpszdateTime)
            {
                //collectInfo.errCode = AlarmType.Ez_2;
                //collectInfo.errTxt = "上期采集值:" + collect.RstVar.lpszdateTime + "本次采集值:" + lpszVal;
                //collectInfo.isSend = 0;
                //NCSys.AlarmCollect.Enqueue(collectInfo); /*更新数据库*/
                isUpCached = false;
                FileLog.Debug("KEY:" + lpszDbVarName + "值采集时间反转");
            }

            if (isUpCached == true)
            {
                bool isDb = false;
                if (collect.FunType.ToLower().Equals("ssr") && !rstVar.lpszVal.Equals(lpszVal))
                {
                    isDb = true;/*更新存储入库标记*/
                }
                DateTime lastTime = rstVar.lpszdateTime;
                rstVar.lpszVal      = lpszVal;
                rstVar.lpszdateTime = lpszdateTime;
                rstVar.dwUserData   = dwUserData;
                if (collect.Action == 0)
                {                                                               /*事件的数据不缓存*/
                    bool last = MemcachedMgr.SetVal(collect.CachedKey, rstVar); /*加入memcached*/
                    if (last == false)
                    {
                        if (lpszdateTime > lastTime.AddMinutes(15))
                        {/*相隔15分钟入队列*/
                         //collectInfo.errCode = AlarmType.Err_Nd;
                         //collectInfo.errTxt = "更新Memcahed错误";
                         //collectInfo.isSend = 0;
                         //NCSys.AlarmCollect.Enqueue(collectInfo); /*更新数据库*/
                        }
                        /////////////////////////////////////////
                        FileLog.WriteLog("变量" + collect.CachedKey + "更新Memcahed错误");
                    }
                    else
                    {
                        if (isDb == true)
                        {
                            collect.IsDb = true;
                        }
                        FileLog.Debug("KEY:" + collect.CachedKey + " 保存缓存成功值:" + rstVar.lpszVal);
                    }
                }
            }
        }
示例#16
0
        /// <summary>
        /// 获取第二层数据
        /// </summary>
        /// <param name="co_id">层级2的id号</param>
        /// <returns></returns>
        public APIRst GetLayer02(int co_id)
        {
            APIRst rst = new APIRst();

            try
            {
                List <object> dd       = new List <object>();
                DataTable     dtSource = bll.GetLayer02(co_id);
                foreach (DataRow dr in dtSource.Rows)
                {
                    //string keyWD = user.CacheKey + CommFunc.ConvertDBNullToString(dr["TagNameWD"]);
                    //string keySD = user.CacheKey + CommFunc.ConvertDBNullToString(dr["TagNameSD"]);
                    //RstVar var1 = this.GetRstVar(keyWD);
                    //RstVar var2 = this.GetRstVar(keySD);
                    //if (var1 != null)
                    //    dr["TagValWD"] = var1.lpszVal;
                    //if (var2 != null)
                    //    dr["TagValSD"] = var1.lpszVal;
                    List <object> cc   = new List <object>();
                    DataTable     dtR3 = bll.GetLayer02(CommFunc.ConvertDBNullToInt32(dr["Co_id"]));
                    foreach (DataRow dr3 in dtR3.Rows)
                    {
                        string keyWD = user.CacheKey + CommFunc.ConvertDBNullToString(dr["TagNameWD"]);
                        string keySD = user.CacheKey + CommFunc.ConvertDBNullToString(dr["TagNameSD"]);
                        RstVar var1  = this.GetRstVar(keyWD);
                        RstVar var2  = this.GetRstVar(keySD);
                        if (var1 != null)
                        {
                            dr3["TagValWD"] = var1.lpszVal;
                        }
                        if (var2 != null)
                        {
                            dr3["TagValSD"] = var1.lpszVal;
                        }
                        object objC = new
                        {
                            Id       = CommFunc.ConvertDBNullToInt32(dr3["Co_id"]),
                            Name     = CommFunc.ConvertDBNullToString(dr3["CoName"]),
                            Number   = CommFunc.ConvertDBNullToInt32(dr3["Number"]),
                            Addr     = CommFunc.ConvertDBNullToString(dr3["CustAddr"]),
                            WD       = CommFunc.ConvertDBNullToDecimal(dr3["TagValWD"]).ToString("f2"),
                            SD       = CommFunc.ConvertDBNullToDecimal(dr3["TagValSD"]).ToString("f2"),
                            Disabled = CommFunc.ConvertDBNullToInt32(dr3["Disabled"]),
                        };
                        cc.Add(objC);
                    }
                    object obj = new
                    {
                        Id       = CommFunc.ConvertDBNullToInt32(dr["Co_id"]),
                        Name     = CommFunc.ConvertDBNullToString(dr["CoName"]),
                        Number   = CommFunc.ConvertDBNullToInt32(dr["Number"]),
                        Addr     = CommFunc.ConvertDBNullToString(dr["CustAddr"]),
                        WD       = CommFunc.ConvertDBNullToDecimal(dr["TagValWD"]).ToString("f2"),
                        SD       = CommFunc.ConvertDBNullToDecimal(dr["TagValSD"]).ToString("f2"),
                        Disabled = CommFunc.ConvertDBNullToInt32(dr["Disabled"]),
                        nodes    = cc,
                    };
                    dd.Add(obj);
                }
                //var res1 = from s1 in dtSource.AsEnumerable()
                //           select new
                //           {
                //               Id = CommFunc.ConvertDBNullToInt32(s1["Co_id"]),
                //               Name = CommFunc.ConvertDBNullToString(s1["CoName"]),
                //               Number = CommFunc.ConvertDBNullToInt32(s1["Number"]),
                //               Addr = CommFunc.ConvertDBNullToString(s1["CustAddr"]),
                //               WD = CommFunc.ConvertDBNullToDecimal(s1["TagValWD"]).ToString("f2"),
                //               SD = CommFunc.ConvertDBNullToDecimal(s1["TagValSD"]).ToString("f2"),
                //               Disabled = CommFunc.ConvertDBNullToInt32(s1["Disabled"]),
                //           };
                rst.data = dd; // res1.ToList();
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("获取第二层数据错误:" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
示例#17
0
        public DataTable GetMonitorList(string pk, int co_id)
        {
            DataTable dtRst = new DataTable();

            dtRst.Columns.Add("Module_id", typeof(System.Int32));
            dtRst.Columns.Add("ModuleName", typeof(System.String));
            dtRst.Columns.Add("Status", typeof(System.String));
            dtRst.Columns.Add("Ssr_Tag", typeof(System.String));
            dtRst.Columns.Add("E_Tag", typeof(System.String));
            dtRst.Columns.Add("U_Tag", typeof(System.String));
            dtRst.Columns.Add("I_Tag", typeof(System.String));
            dtRst.Columns.Add("P_Tag", typeof(System.String));
            dtRst.Columns.Add("IMax_Tag", typeof(System.String));
            dtRst.Columns.Add("IMin_Tag", typeof(System.String));
            dtRst.Columns.Add("IMax_Val", typeof(System.String));
            dtRst.Columns.Add("IMin_Val", typeof(System.String));
            dtRst.Columns.Add("IMax_Unit", typeof(System.String));
            dtRst.Columns.Add("IMin_Unit", typeof(System.String));
            dtRst.Columns.Add("Ssr_Unit", typeof(System.String));
            dtRst.Columns.Add("E_Unit", typeof(System.String));
            dtRst.Columns.Add("U_Unit", typeof(System.String));
            dtRst.Columns.Add("I_Unit", typeof(System.String));
            dtRst.Columns.Add("P_Unit", typeof(System.String));
            dtRst.Columns.Add("FrMd", typeof(System.Int32));
            dtRst.PrimaryKey = new DataColumn[] { dtRst.Columns["Module_id"] };
            DataTable dtSource = dal.GetMonitorList(co_id);

            foreach (DataRow dr in dtSource.Rows)
            {
                int frMd = CommFunc.ConvertDBNullToInt32(dr["FrMd"]);
                frMd = frMd == 0 ? 15 : frMd;
                DataRow addDr = dtRst.Rows.Find(dr["Module_id"]);
                if (addDr == null)
                {
                    addDr = dtRst.NewRow();
                    addDr["Module_id"]  = dr["Module_id"];
                    addDr["ModuleName"] = dr["ModuleName"];
                    addDr["FrMd"]       = dr["FrMd"];
                    dtRst.Rows.Add(addDr);
                }

                //E,U,I,P,IMax,IMin
                string cloTag  = CommFunc.ConvertDBNullToString(dr["FunType"]) + "_Tag";
                string cloUnit = CommFunc.ConvertDBNullToString(dr["FunType"]) + "_Unit";
                string cloVal  = CommFunc.ConvertDBNullToString(dr["FunType"]) + "_Val";
                if (dtRst.Columns.Contains(cloTag))
                {
                    addDr[cloTag] = CommFunc.ConvertDBNullToString(dr["LpszDbVarName"]);
                }
                if (dtRst.Columns.Contains(cloUnit))
                {
                    addDr[cloUnit] = CommFunc.ConvertDBNullToString(dr["Unit"]);
                }
                if (dtRst.Columns.Contains(cloVal))
                {
                    addDr[cloVal] = CommFunc.ConvertDBNullToString(dr["DataValue"]);
                }

                if (CommFunc.ConvertDBNullToString(dr["FunType"]).Equals("E"))
                {
                    string key = pk + CommFunc.ConvertDBNullToString(dr["LpszDbVarName"]);
                    int    i   = 0;
                    RstVar var = null;
                    while (++i <= 2)
                    {
                        var = MemcachedMgr.GetVal <RstVar>(key);
                        if (var != null)
                        {
                            break;
                        }
                        System.Threading.Thread.Sleep(50);
                    }
                    DateTime lastTime = var == null ? new DateTime(1900, 1, 1) : var.lpszdateTime;
                    if (DateTime.Now > lastTime.AddMinutes(frMd))
                    {
                        addDr["Status"] = "0";
                    }
                    else
                    {
                        addDr["Status"] = "1";
                    }
                    //if (DateTime.Now > lastTime.AddMinutes(frMd))
                    //    addDr["Status"] = "异常";
                    //else
                    //    addDr["Status"] = "在线";
                }
            }
            return(dtRst);
        }
示例#18
0
 private void GetYdStatusOnLine(DataTable dtSource)
 {
     dtSource.Columns.Add("SsrS", typeof(System.String));
     foreach (DataRow dr in dtSource.Rows)
     {
         RstVar var = null;
         //RstVar varSsr = null;
         int frMd = CommFunc.ConvertDBNullToInt32(dr["FrMd"]);
         int mid  = CommFunc.ConvertDBNullToInt32(dr["Module_id"]);
         //int ssr = -1;
         string   memcachKey    = CommFunc.ConvertDBNullToString(dr["MemcachKey"]);
         string   memcachKeySsr = memcachKey.Replace(".E", ".Ssr");
         string   cachComm      = CommFunc.ConvertDBNullToString(dr["CachComm"]);
         DateTime lastTime      = CommFunc.ConvertDBNullToDateTime(dr["LastTime"]);
         frMd         = frMd == 0 ? 15 : frMd;
         dr["OnLine"] = 1;    //因演示需要修改,原来是0
         dr["Ssr"]    = 0;    //原来是-1
         dr["SsrS"]   = "合闸"; //原来是未知
         if (lastTime.AddDays(50) < DateTime.Now)
         {
             continue;
         }
         #region 是否在线
         if (!string.IsNullOrEmpty(cachComm))
         {
             var = null; int i = 0;
             while (var == null && ++i < 2)
             {
                 var = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + cachComm);
                 if (var != null)
                 {
                     break;
                 }
                 System.Threading.Thread.Sleep(2);
             }
             if (var != null)
             {
                 dr["OnLine"] = ((int)CommFunc.ConvertDBNullToDecimal(var.lpszVal) == 0) ? 1 : 0;
             }
         }
         else if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(dr["MemcachKey"])))
         {
             var = null; int i = 0;
             while (var == null && ++i < 2)
             {
                 var = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + memcachKey);
                 if (var != null)
                 {
                     //FileLog.WriteLog("key:" + Common.GetMemcachKey + memcachKey + " Val:" + JsonHelper.Serialize(var));
                     break;
                 }
                 else
                 {
                     //FileLog.WriteLog("空值 key:" + Common.GetMemcachKey + memcachKey);
                     //FileLog.WriteLog("空值 SSr key:" + Common.GetMemcachKey + memcachKeySsr);
                 }
                 System.Threading.Thread.Sleep(2);
             }
             if (var != null)
             {
                 DateTime callTime = var.lpszdateTime;
                 if (callTime >= DateTime.Now.AddMinutes(0 - frMd))
                 {
                     dr["OnLine"] = 1;
                 }
             }
         }
         #endregion
         #region 拉合闸状态
         //if (mid == 228)
         //{
         //    FileLog.WriteLog("电能状态:" + WebConfig.MemcachKey + memcachKey);
         //    FileLog.WriteLog("拉合闸状态:" + WebConfig.MemcachKey + memcachKeySsr);
         //}
         if (!string.IsNullOrEmpty(memcachKeySsr))
         {
             var = null; int i = 0;
             while (var == null && ++i < 2)
             {
                 var = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + memcachKeySsr);
                 if (var != null)
                 {
                     break;
                 }
                 System.Threading.Thread.Sleep(2);
             }
             if (var != null)
             {
                 int ssr = (int)CommFunc.ConvertDBNullToDecimal(var.lpszVal);
                 //ssr = ssr == 0 ? 0 : 1;
                 dr["Ssr"] = ssr;
                 if (ssr == 0)
                 {
                     dr["SsrS"] = "合闸";
                 }
                 else if (ssr == 129)
                 {
                     dr["SsrS"] = "恶性负载跳闸";
                 }
                 else if (ssr == 130)
                 {
                     dr["SsrS"] = "总功率超限跳闸";
                 }
                 else if (ssr == 132)
                 {
                     dr["SsrS"] = "移相器或半波跳闸";
                 }
                 else if (ssr == 136)
                 {
                     dr["SsrS"] = "定时断电拉闸";
                 }
                 else if (ssr == 144)
                 {
                     dr["SsrS"] = "远程拉闸";
                 }
                 else if (ssr == 160)
                 {
                     dr["SsrS"] = "过流超限跳闸";
                 }
                 else if (ssr == 192)
                 {
                     dr["SsrS"] = "单次功率超限跳闸";
                 }
                 else
                 {
                     dr["SsrS"] = "跳闸";
                 }
             }
         }
         #endregion
         //int i = 0;
         //int onLine = -1;
         //if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(dr["MemcachKey"])))
         //{
         //    while (var == null && ++i < 2)
         //    {
         //        var = MemcachedMgr.GetVal<RstVar>(WebConfig.MemcachKey + memcachKey);
         //        varSsr = MemcachedMgr.GetVal<RstVar>(WebConfig.MemcachKey + memcachKeySsr);
         //        if (var != null || varSsr != null)
         //        {
         //            //FileLog.WriteLog("key:" + WebConfig.MemcachKey + memcachKey + " Val:" + JsonHelper.Serialize(var));
         //            break;
         //        }
         //        else
         //        {
         //            //FileLog.WriteLog("空值 key:" + WebConfig.MemcachKey + memcachKey);
         //            //FileLog.WriteLog("空值 SSr key:" + WebConfig.MemcachKey + memcachKeySsr);
         //        }
         //        System.Threading.Thread.Sleep(2);
         //    }
         //}
         //onLine = 0;
         //if (var != null)
         //{
         //    DateTime callTime = var.lpszdateTime;
         //    if (callTime >= DateTime.Now.AddMinutes(0 - frMd))
         //        onLine = 1;
         //}
         //if (varSsr != null)
         //    ssr = CommFunc.ConvertDBNullToInt32(varSsr.lpszVal);
         //dr["OnLine"] = onLine;
         //dr["Ssr"] = ssr;
     }
 }
示例#19
0
        private void DbProcess()
        {
            while (true)
            {
                Thread.Sleep(1000);/*每一秒*/
                if (NCSys.IsRun == false)
                {
                    continue;
                }

                #region 配置信息
                try
                {
                    this.GetProcessOfConfig();
                }
                catch (Exception ex)
                {
                    FileLog.Error("读取采集配置数据错误:" + ex.Message + ex.StackTrace);
                }
                #endregion

                #region 先入库存储
                try
                {
                    bool bIsNext = true;
                    var  enumer  = NCSys.Result.GetEnumerator();
                    while (bIsNext == true)
                    {
                        bIsNext = enumer.MoveNext();
                        if (bIsNext == false)
                        {
                            break;
                        }
                        var           s0  = enumer.Current;
                        CollectVModel s1  = s0.Value;
                        SysPro        pro = null;
                        NCSys.Pro.TryGetValue(s1.Ledger, out pro);
                        if (pro == null)
                        {
                            FileLog.Error("KEY:" + s0.Key + "没有此账目: " + s1.Ledger);
                            continue;
                        }
                        RstVar rst = MemcachedMgr.GetVal <RstVar>(s1.CachedKey);
                        if (rst == null)
                        {
                            //FileLog.Error("KEY:" + s0.Key + "没有缓存值");
                            continue;
                        }
                        if (s1.Module_id == 0 || s1.Action != 0)
                        {
                            continue;
                        }
                        if (s1.IsDb == false)
                        {
                            if (s1.UpTime.AddMinutes(pro.FrMd) > rst.lpszdateTime)
                            {
                                continue;
                            }
                        }
                        try
                        {
                            string         msg;
                            DataProcessBLL bll     = new DataProcessBLL(s1.Ledger, Config.Uid);
                            int            errcode = bll.DataProcess(s1.Module_id, s1.ModuleAddr, s1.Fun_id, rst.lpszVal, rst.lpszdateTime, out msg, 90);
                            if (errcode < 0)
                            {
                                FileLog.Error("KEY:" + s0.Key + "值:" + rst.lpszVal + "数据处理结果错误:" + msg);
                            }
                            else
                            {
                                FileLog.Debug("KEY:" + s0.Key + "值:" + rst.lpszVal + "保存成功");
                            }
                        }
                        catch (Exception ex)
                        {
                            FileLog.Error("KEY:" + s0.Key + "值:" + rst.lpszVal + "采集时间:" + rst.lpszdateTime.ToString() + "数据处理结果错误:" + ex.Message);
                        }
                        s1.UpTime = DateTime.Now; /*入库时间*/
                        s1.IsDb   = false;
                        Thread.Sleep(20);         /*每20毫秒*/
                    }
                }
                catch (Exception ex)
                {
                    FileLog.Error("数据处理错误:" + ex.Message + ex.StackTrace);
                }
                #endregion
            }
        }
示例#20
0
 private void GetYdStatusOnLine(DataTable dtSource)
 {
     foreach (DataRow dr in dtSource.Rows)
     {
         RstVar var = null;
         //RstVar varSsr = null;
         int frMd = CommFunc.ConvertDBNullToInt32(dr["FrMd"]);
         //int ssr = -1;
         string   memcachKey    = CommFunc.ConvertDBNullToString(dr["MemcachKey"]);
         string   memcachKeySsr = memcachKey.Replace(".E", ".Ssr");
         string   cachComm      = CommFunc.ConvertDBNullToString(dr["CachComm"]);
         DateTime lastTime      = CommFunc.ConvertDBNullToDateTime(dr["LastTime"]);
         frMd         = frMd == 0 ? 15 : frMd;
         dr["OnLine"] = 0;
         dr["Ssr"]    = -1;
         if (lastTime.AddDays(1) < DateTime.Now)
         {
             continue;
         }
         #region 是否在线
         if (!string.IsNullOrEmpty(cachComm))
         {
             var = null; int i = 0;
             while (var == null && ++i < 2)
             {
                 var = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + cachComm);
                 if (var != null)
                 {
                     break;
                 }
                 System.Threading.Thread.Sleep(2);
             }
             if (var != null)
             {
                 dr["OnLine"] = ((int)CommFunc.ConvertDBNullToDecimal(var.lpszVal) == 0) ? 1 : 0;
             }
         }
         else if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(dr["MemcachKey"])))
         {
             var = null; int i = 0;
             while (var == null && ++i < 2)
             {
                 var = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + memcachKey);
                 if (var != null)
                 {
                     //FileLog.WriteLog("key:" + Common.GetMemcachKey + memcachKey + " Val:" + JsonHelper.Serialize(var));
                     break;
                 }
                 else
                 {
                     //FileLog.WriteLog("空值 key:" + Common.GetMemcachKey + memcachKey);
                     //FileLog.WriteLog("空值 SSr key:" + Common.GetMemcachKey + memcachKeySsr);
                 }
                 System.Threading.Thread.Sleep(2);
             }
             if (var != null)
             {
                 DateTime callTime = var.lpszdateTime;
                 if (callTime >= DateTime.Now.AddMinutes(0 - frMd))
                 {
                     dr["OnLine"] = 1;
                 }
             }
         }
         #endregion
         #region 拉合闸状态
         if (!string.IsNullOrEmpty(memcachKeySsr))
         {
             var = null; int i = 0;
             while (var == null && ++i < 2)
             {
                 var = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + memcachKeySsr);
                 if (var != null)
                 {
                     break;
                 }
                 System.Threading.Thread.Sleep(2);
             }
             if (var != null)
             {
                 dr["Ssr"] = (int)CommFunc.ConvertDBNullToDecimal(var.lpszVal);
             }
         }
         #endregion
         //int i = 0;
         //int onLine = -1;
         //if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(dr["MemcachKey"])))
         //{
         //    while (var == null && ++i < 2)
         //    {
         //        var = MemcachedMgr.GetVal<RstVar>(WebConfig.MemcachKey + memcachKey);
         //        varSsr = MemcachedMgr.GetVal<RstVar>(WebConfig.MemcachKey + memcachKeySsr);
         //        if (var != null || varSsr != null)
         //        {
         //            //FileLog.WriteLog("key:" + WebConfig.MemcachKey + memcachKey + " Val:" + JsonHelper.Serialize(var));
         //            break;
         //        }
         //        else
         //        {
         //            //FileLog.WriteLog("空值 key:" + WebConfig.MemcachKey + memcachKey);
         //            //FileLog.WriteLog("空值 SSr key:" + WebConfig.MemcachKey + memcachKeySsr);
         //        }
         //        System.Threading.Thread.Sleep(2);
         //    }
         //}
         //onLine = 0;
         //if (var != null)
         //{
         //    DateTime callTime = var.lpszdateTime;
         //    if (callTime >= DateTime.Now.AddMinutes(0 - frMd))
         //        onLine = 1;
         //}
         //if (varSsr != null)
         //    ssr = CommFunc.ConvertDBNullToInt32(varSsr.lpszVal);
         //dr["OnLine"] = onLine;
         //dr["Ssr"] = ssr;
     }
 }
示例#21
0
        /// <summary>
        /// 获取温湿度
        /// </summary>
        public APIRst GetTemperatureAndHumidity(string strcName, string coName)
        {
            APIRst rst = new APIRst();

            try
            {
                DataTable dtSource = bll.GetTemperatureAndHumidity(strcName, coName);
                int       total    = dtSource.Rows.Count;
                foreach (DataRow dr in dtSource.Rows)
                {
                    string lpszDbVar = CommFunc.ConvertDBNullToString(dr["LpszDbVar"]);
                    int    leakScale = CommFunc.ConvertDBNullToInt32(dr["LeakScale"]);
                    int    tempScale = CommFunc.ConvertDBNullToInt32(dr["TempScale"]);
                    RstVar rstVal = null, rstAlarm = null;

                    rstAlarm = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + lpszDbVar + "LeakAlarm");

                    for (int i = 1; i <= 8; i++)
                    {
                        System.Threading.Thread.Sleep(10);
                        rstVal = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + lpszDbVar + "Leak" + i);
                        if (rstVal != null)
                        {
                            dr["Leak" + i] = CommFunc.ConvertDBNullToDecimal(rstVal.lpszVal).ToString("f" + leakScale);
                            if (rstAlarm != null)
                            {
                                if (!string.IsNullOrEmpty(rstAlarm.lpszVal))
                                {
                                    if (rstAlarm.lpszVal.ToString().Substring((i - 1), 1) == "1")
                                    {
                                        dr["Leak" + i] = CommFunc.ConvertDBNullToString(dr["Leak" + i]) + "(告警)";
                                    }
                                }
                            }
                        }
                        if (i <= 2)
                        {
                            rstVal = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + lpszDbVar + "Temp" + i);
                            if (rstVal != null)
                            {
                                dr["Temp" + i] = CommFunc.ConvertDBNullToDecimal(rstVal.lpszVal).ToString("f" + tempScale);
                                if (rstAlarm != null)
                                {
                                    if (!string.IsNullOrEmpty(rstAlarm.lpszVal))
                                    {
                                        if (rstAlarm.lpszVal.ToString().Substring((i + 7), 1) == "1")
                                        {
                                            dr["Temp" + i] = CommFunc.ConvertDBNullToString(dr["Temp" + i]) + "(告警)";
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                var res1 = from s1 in dtSource.AsEnumerable()
                           select new
                {
                    RowId      = dtSource.Rows.IndexOf(s1) + 1,
                    Co_id      = CommFunc.ConvertDBNullToInt32(s1["Co_id"]),
                    Module_id  = CommFunc.ConvertDBNullToInt32(s1["Module_id"]),
                    ModuleAddr = CommFunc.ConvertDBNullToString(s1["ModuleAddr"]),
                    CoName     = CommFunc.ConvertDBNullToString(s1["CoName"]),
                    CoStrcName = CommFunc.ConvertDBNullToString(s1["CoStrcName"]),
                    LeakScale  = CommFunc.ConvertDBNullToInt32(s1["LeakScale"]),
                    TempScale  = CommFunc.ConvertDBNullToInt32(s1["TempScale"]),
                    Leak1      = CommFunc.ConvertDBNullToString(s1["Leak1"]),
                    Leak2      = CommFunc.ConvertDBNullToString(s1["Leak2"]),
                    Leak3      = CommFunc.ConvertDBNullToString(s1["Leak3"]),
                    Leak4      = CommFunc.ConvertDBNullToString(s1["Leak4"]),
                    Leak5      = CommFunc.ConvertDBNullToString(s1["Leak5"]),
                    Leak6      = CommFunc.ConvertDBNullToString(s1["Leak6"]),
                    Leak7      = CommFunc.ConvertDBNullToString(s1["Leak7"]),
                    Leak8      = CommFunc.ConvertDBNullToString(s1["Leak8"]),
                    Temp1      = CommFunc.ConvertDBNullToString(s1["Temp1"]),
                    Temp2      = CommFunc.ConvertDBNullToString(s1["Temp2"]),
                };
                object obj = new { total = total, rows = res1.ToList() };
                rst.data = obj;
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("获取数据错误(GetTemperatureAndHumidity):" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
示例#22
0
        /// <summary>
        /// 获取采集点实时数据错误
        /// </summary>
        /// <param name="tag">采集点号</param>
        /// <returns></returns>
        public APIRst GetRealTime(string tag)
        {
            //保留两种状态,正常和异常。通讯异常的,暂无数据的,都显示为异常
            APIRst rst = new APIRst();

            try
            {
                string key = (user == null || user.Uid == 0) ? "" : user.CacheKey + tag;
                //if (string.IsNullOrEmpty(key))
                //    key = WebConfig.MemcachKey;
                string[] arr    = key.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                string   ns     = string.Join(".", arr, 0, arr.Length - 1);
                string   status = "正常";

                RstVar var = this.GetStatus(key);

                RstVar Ua = this.GetStatus(ns + ".Ua");
                if (Ua == null)
                {
                    RstVar com = this.GetStatus(ns + ".Comm");
                    if (com == null)
                    {
                        status = "异常";
                        //FileLog.WriteLog("key:" + tag + " 无状态信息");
                    }
                    else
                    {
                        if (CommFunc.ConvertDBNullToDecimal(com.lpszVal) > 0)
                        {
                            status = "异常";
                            //FileLog.WriteLog("key:" + tag + " Com: " + JsonHelper.Serialize(com));
                        }
                    }

                    if (tag.Contains("R2B1.2.3"))
                    {
                        //FileLog.WriteLog("key:" + ns + ".Comm " + " com: " + JsonHelper.Serialize(com));
                    }
                }
                else
                {
                    if (CommFunc.ConvertDBNullToDecimal(Ua.lpszVal) == 0)
                    {
                        status = "异常";
                        // FileLog.WriteLog("key:" + tag + "Ua: " + JsonHelper.Serialize(Ua));
                    }
                    else
                    {
                        //if (CommFunc.ConvertDBNullToDecimal(Ua.errCode) == -1)
                        //    status = "异常";
                    }
                }


                if (tag.Contains("R2B1.2.3"))
                {
                    //FileLog.WriteLog("key:" + tag +  "  tag: " + JsonHelper.Serialize(var));
                    //FileLog.WriteLog("key:" + ns + ".Ua " + "  Ua: " + JsonHelper.Serialize(Ua));
                }

                if (!user.CacheKey.Contains("EngShBen"))
                {
                    status = "正常";
                    if (var == null)
                    {
                        status = "异常";
                    }
                    else
                    {
                        if (DateTime.Now > var.lpszdateTime.AddMinutes(1))
                        {
                            status = "异常";
                        }
                    }
                }
                //FileLog.WriteLog("key:" + key + "  值: " + JsonHelper.Serialize(var));
                if (var != null)
                {
                    rst.data = new { LpszVal = var.lpszVal, LpszdateTime = var.lpszdateTime.ToString("yyyy-MM-dd HH:mm:ss"), Status = status }
                }
                ;
                else
                {
                    rst.data = new { LpszVal = "", LpszdateTime = "", Status = status }
                };

                //RstVar var = null;
                //int i = 0;
                //while (++i <= 3)
                //{
                //    var = MemcachedMgr.GetVal<RstVar>(key);
                //    if (var != null) break;
                //    System.Threading.Thread.Sleep(50);
                //}
                //if (var == null)
                //{
                //    rst.rst = true;
                //    rst.data = new { LpszVal = "", LpszdateTime = "", Status = "异常" };
                //}
                //else
                //{
                //    string ss = "异常";
                //    if (CommFunc.ConvertDBNullToDecimal(var.lpszVal) == 0)
                //    {
                //        ss = "断线";
                //    }
                //    else
                //    {
                //        if (var.lpszdateTime.AddMinutes(15) > DateTime.Now)
                //        {
                //            ss = "正常";
                //        }
                //    }
                //    rst.data = new { LpszVal = var.lpszVal, LpszdateTime = var.lpszdateTime.ToString("yyyy-MM-dd HH:mm:ss"), Status = ss };
                //}
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("获取采集点实时数据错误:" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
示例#23
0
文件: ZpAlarm.cs 项目: ZQuanLi/Test
        internal bool GetAlarm()
        {
            DataTable dtSource      = null;
            DataTable dtAlarmConfig = null;

            try
            {
                dtAlarmConfig = bll.GetAlarmConfig();
                int     cnt       = dtAlarmConfig.Rows.Count;
                decimal alarmVal1 = cnt == 0 ? 0 : CommFunc.ConvertDBNullToDecimal(dtAlarmConfig.Rows[0]["CfValue"]);
                string  unit      = cnt == 0 ? "" : CommFunc.ConvertDBNullToString(dtAlarmConfig.Rows[0]["Unit"]);
                dtSource = bll.GetAlarmData(alarmVal1, unit);
            }
            catch (Exception ex)
            {
                FileLog.WriteLog("获取告警数据错误:" + ex.Message + ex.StackTrace);
            }
            //
            if (dtSource == null)
            {
                return(false);
            }
            Thread.Sleep(100);
            int co_idPrev = -9999;

            foreach (DataRow dr in dtSource.Rows)
            {
                int      co_id = CommFunc.ConvertDBNullToInt32(dr["Co_id"]);
                string   coName = CommFunc.ConvertDBNullToString(dr["CoName"]);
                int      chrgType = CommFunc.ConvertDBNullToInt32(dr["ChrgType"]); /*<=1 房间 >1电表*/
                int      isAlarm = CommFunc.ConvertDBNullToInt32(dr["IsAlarm"]);   /*<=1 房间 >1电表*/
                DateTime lastTime = CommFunc.ConvertDBNullToDateTime(dr["LastTime"]);
                int      transferType = CommFunc.ConvertDBNullToInt32(dr["TransferType"]);
                decimal  rdVal = CommFunc.ConvertDBNullToDecimal(dr["RdVal"]);
                decimal  price = CommFunc.ConvertDBNullToDecimal(dr["Price"]);
                decimal  rdAmt = CommFunc.ConvertDBNullToDecimal(dr["RdAmt"]);
                int      module_id = CommFunc.ConvertDBNullToInt32(dr["Module_id"]);
                string   moduleAddr = CommFunc.ConvertDBNullToString(dr["ModuleAddr"]);
                string   moduleName = CommFunc.ConvertDBNullToString(dr["ModuleName"]);
                string   cfKey = "", cfUnit = "";
                decimal  cfValue = 0;
                decimal  cfRule  = 1;
                bool     isRun   = true;
                if (chrgType <= 1 && co_idPrev == co_id)
                {
                    isRun = false;
                }
                co_idPrev = co_id;
                if (isRun == false)
                {
                    continue;
                }
                int ccc = dtAlarmConfig.Rows.Count;
                int crn = 0;
                foreach (DataRow drC in dtAlarmConfig.Rows)
                {/*从大到小排列*/
                    cfKey   = CommFunc.ConvertDBNullToString(drC["CfKey"]);
                    cfValue = CommFunc.ConvertDBNullToDecimal(drC["CfValue"]);
                    cfRule  = CommFunc.ConvertDBNullToDecimal(drC["Rule"]);
                    cfUnit  = CommFunc.ConvertDBNullToString(drC["Unit"]).ToLower();
                    if (pro.Project.Equals("YdXip") && cfKey.Equals("AlarmValOd"))
                    {/*西安培华的拉闸电量*/
                        cfValue = CommFunc.ConvertDBNullToDecimal(dr["OdValue"]);
                    }
                    //if (!cfKey.ToLower().Equals("AlarmValOd".ToLower()))
                    //    cfRule = cfRule == 0 ? 1 : cfRule;
                    decimal comVal  = string.IsNullOrEmpty(cfUnit) || cfUnit.Equals("kWh".ToLower()) ? rdVal : rdAmt;
                    decimal toValue = cfValue;
                    if (crn < ccc - 1)
                    {
                        toValue = CommFunc.ConvertDBNullToDecimal(dtAlarmConfig.Rows[crn + 1]["CfValue"]);
                    }
                    if (cfValue >= comVal && comVal > toValue)
                    {
                        break;
                    }
                    crn = crn + 1;
                }
                //FileLog.WriteLog("电表ID:" + module_id + "地址:" + moduleAddr + "房间:" + coName + "剩余电量:" + rdVal + "告警类型:" + cfKey + "规则:" + cfRule + "告警值:" + cfValue);
                bool sendAlarm = true;
                if (cfKey.ToLower().Equals("AlarmValOd".ToLower()) && isAlarm == 1)
                {     /*拉合闸*/
                    if (CommFunc.ConvertDBNullToInt32(cfRule) == 1)
                    { /*发送拉合闸命令*/
                        sendAlarm = false;
                        try
                        {
                            string key    = pro.ProjectKey + CommFunc.ConvertDBNullToString(dr["LpszSsr"]);
                            RstVar rstVar = MemcachedMgr.GetVal <RstVar>(key);
                            bool   isPass = false;
                            if (rstVar != null && CommFunc.ConvertDBNullToDecimal(rstVar.lpszVal) == 0)
                            {
                                isPass = true;
                            }

                            if (isPass == true)
                            {
                                this.CtorlSsr1(module_id);
                            }
                        }
                        catch (Exception ex)
                        {
                            FileLog.Error("透支电量发送拉合闸命令错误:" + ex.Message + ex.StackTrace);
                        }
                    }
                }
                if (sendAlarm == true)
                {/*发送告警*/
                    cfRule = cfRule == 0 ? 1 : cfRule;
                    v2_alarm_logVModel alarmInfo = this.AlarmInfo(dr, cfValue, cfRule);
                    if (isAlarm == 1)
                    {
                        if (!string.IsNullOrEmpty(EmailUtilities.EmConfig.MailFrom) && !string.IsNullOrEmpty(EmailUtilities.EmConfig.MailSmtpHost) &&
                            !string.IsNullOrEmpty(EmailUtilities.EmConfig.MailSmtpUser) && !string.IsNullOrEmpty(EmailUtilities.EmConfig.MailSmtpPassword)
                            )
                        {/*邮件告警*/
                            this.AlarmEmail(alarmInfo.Log_id, co_id, coName, lastTime, rdVal);
                        }
                        if (!string.IsNullOrEmpty(pro.Sms.ComSmsConfig.ComSms) ||
                            (!string.IsNullOrEmpty(SmsFun.AliSmsConfig.AliAppKey) && !string.IsNullOrEmpty(SmsFun.AliSmsConfig.AliAppSecret) && !string.IsNullOrEmpty(SmsFun.AliSmsConfig.AliSignName))
                            )
                        {/*短信告警*/
                            this.AlarmSms(alarmInfo.Log_id, co_id, moduleName, coName, lastTime, rdVal, rdAmt);
                        }
                        if (!string.IsNullOrEmpty(pro.Wx.WxConfig.WxAPPID))
                        {/*微信告警*/
                         //this.AlarmWx(alarmInfo.Log_id, co_id, coName, lastTime, rdVal);
                        }
                    }
                }
            }
            return(true);
        }
示例#24
0
        /// <summary>
        /// 更新缓存信息
        /// </summary>
        /// <param name="command"></param>
        /// <param name="errCode"></param>
        /// <param name="errTxt"></param>
        private static void RefreshCached(CommandVModel command, string lpszVal, AlarmType errCode)
        {
            if (errCode != AlarmType.Sue)
            {
                return;                          /*不成功则返回;成功则继续往下操作*/
            }
            if (command.Action == 1 && command.Fun_id != 0)
            {/*记录写的值*/
                new DataProcessBLL(command.Ledger, Config.Uid).UpdataMap(command.Module_id, command.Fun_id, lpszVal);
            }
            SysPro pro = null;

            NCSys.Pro.TryGetValue(command.Ledger, out pro);
            if (pro == null)
            {
                return;
            }
            string ss1 = pro.ProjectKey + command.Module_id.ToString() + "." + command.ModuleAddr + ".";

            if (command.FunType.Equals(V0Fun.Ssr.ToString()) && !string.IsNullOrEmpty(command.DataValue))
            { // 立刻更新拉合闸
                string key = ss1 + V0Fun.Ssr.ToString();
                RstVar rst = MemcachedMgr.GetVal <RstVar>(key);
                if (rst == null)
                {
                    return;
                }
                rst.lpszVal      = command.DataValue;
                rst.lpszdateTime = command.CollectTime.Value;
                rst.dwUserData   = 0;
                ///////////////
                CollectVModel collect = null;
                if (NCSys.Result.TryGetValue(key, out collect) == true)
                {
                    //collect.RstVar = rst;
                    //collect.IsDb = true;
                    //collect.IsRn = command.IsRn;
                }
                ///////////////
                MemcachedMgr.SetVal(key, rst);
            }
            if (command.FunType.Equals(V0Fun.Pay.ToString()) || command.FunType.Equals(V0Fun.Refund.ToString()))
            { // 充值;退费
                string key = ss1 + V0Fun.RdVal.ToString();
                RstVar rst = MemcachedMgr.GetVal <RstVar>(key);
                if (rst == null)
                {
                    return;
                }
                decimal lpszPay = CommFunc.ConvertDBNullToDecimal(rst.lpszVal);
                if (command.FunType.Equals(V0Fun.Pay.ToString()))
                {
                    lpszPay = lpszPay + CommFunc.ConvertDBNullToDecimal(command.DataValue);
                }
                else if (command.FunType.Equals(V0Fun.Refund.ToString()))
                {
                    lpszPay = lpszPay - CommFunc.ConvertDBNullToDecimal(command.DataValue);
                }
                rst.lpszVal      = lpszPay.ToString();
                rst.lpszdateTime = command.CollectTime.Value;
                rst.dwUserData   = 0;
                ///////////////
                CollectVModel collect = null;
                if (NCSys.Result.TryGetValue(key, out collect) == true)
                {
                    //collect.RstVar = rst;
                    //collect.IsDb = true;
                }
                ///////////////
                MemcachedMgr.SetVal(key, rst);
                #region 2018.07.02
                //if (command.ModuleType.Equals("YD-ZB20-4PL2-SB"))
                //{
                //    key = ss1 + V0Fun.E.ToString();
                //    collect = null;
                //    if (NCSys.Result.TryGetValue(key, out collect) == true)
                //        collect.IsDb = true;
                //}
                #endregion
            }
        }
示例#25
0
        public void Run()
        {
            DateTime? dtRun = null, dtTab = null;
            DataTable dtSi = null;

            while (true)
            {
                Thread.Sleep(1000);/*每一秒*/
                if (NCSys.IsRun == false)
                {
                    dtSi = null; dtTab = null;
                    continue;
                }
                DateTime Now = DateTime.Now;
                if (dtRun != null)
                { /*以分钟为一个单位执行*/
                    if (dtRun.Value.Minute == Now.Minute)
                    {
                        continue;
                    }
                }
                dtRun = DateTime.Now;
                //
                try
                {
                    if (NCSys.ResetSiTime == false || dtSi == null || dtTab == null || dtTab.Value.AddHours(1) < DateTime.Now)
                    {
                        dtSi              = bll.GetV1_si_ssr();
                        dtTab             = DateTime.Now;
                        NCSys.ResetSiTime = true;
                    }
                    foreach (DataRow dr in dtSi.Rows)
                    {
                        int    ledger     = CommFunc.ConvertDBNullToInt32(dr["Ledger"]);
                        int    si_id      = CommFunc.ConvertDBNullToInt32(dr["Si_id"]);
                        int    co_id      = CommFunc.ConvertDBNullToInt32(dr["Co_id"]);
                        int    module_id  = CommFunc.ConvertDBNullToInt32(dr["Module_id"]);
                        string moduleAddr = CommFunc.ConvertDBNullToString(dr["ModuleAddr"]);
                        string moduleType = CommFunc.ConvertDBNullToString(dr["ModuleType"]);
                        //
                        int    meter_id  = CommFunc.ConvertDBNullToInt32(dr["Meter_id"]);
                        string meterAddr = CommFunc.ConvertDBNullToString(dr["MeterAddr"]);
                        int    ssr       = IsRunSi(Now, dr);
                        //
                        if (ssr == 0)
                        {
                            continue;
                        }
                        bool isQf = false;

                        //if (moduleType.Equals("YD-ZB20-4PL2-SB"))
                        //{/*这款用于河北工业大学的SB设备,特殊定制化*/
                        //    isQf = bll.GetMeterQianFei(ledger,co_id, meter_id, meterAddr);/*是否欠费*/
                        //}
                        //else
                        //{
                        isQf = bll.GetModuleQianFei(ledger, co_id, module_id, moduleAddr);   /*是否欠费*/
                        //}


                        V0Fun  fun      = V0Fun.Ssr;
                        int    fun_id   = CommFunc.ConvertDBNullToInt32(dr["Fun_id"]);
                        string funName  = "定时合闸";
                        int    nowSsr   = 0;
                        string descr    = "定时合闸";
                        string dataVale = "0";
                        if (ssr == 3355)
                        {
                            fun      = V0Fun.Ssr;
                            fun_id   = 0;
                            funName  = "定时拉闸";
                            nowSsr   = 1;
                            dataVale = "1";
                            descr    = "定时拉闸";
                        }
                        //////////////
                        SysPro pro;
                        NCSys.Pro.TryGetValue(ledger, out pro);
                        if (pro == null)
                        {
                            continue;
                        }
                        string key    = pro.ProjectKey + CommFunc.ConvertDBNullToString(dr["LpszDbVarName"]);
                        RstVar rstVar = MemcachedMgr.GetVal <RstVar>(key);
                        int    curSsr = -1;
                        if (rstVar != null)
                        {
                            curSsr = CommFunc.ConvertDBNullToInt32(rstVar.lpszVal);
                        }
                        //if (nowSsr == curSsr) continue;
                        ///////////////////////////////////////////////////////////////////////////////////////////
                        if (ssr == 9966)
                        {/*合闸*/
                            if (isQf == true)
                            {
                                continue;              /*欠费不合闸*/
                            }
                        }
                        if (nowSsr != curSsr)
                        {/*不一致执行命令*/
                            //CommandVModel cmd = bll.GetSsrInfo(ledger, module_id, dataVale);
                            CommandVModel cmd          = null;
                            int           transferType = bll.GetTransferType(ledger, module_id);
                            if (transferType == 4)
                            {
                                cmd = bll.GetSsrInfo(ledger, module_id, V0Fun.Ssr.ToString() + dataVale, dataVale);
                            }
                            else
                            {
                                cmd = bll.GetSsrInfo(ledger, module_id, V0Fun.Ssr.ToString(), dataVale);
                            }
                            if (cmd == null)
                            {
                                FileLog.Error("定时操作没有数据");
                                continue;
                            }
                            cmd.Fun_id    = fun_id;
                            cmd.FunType   = fun.ToString();
                            cmd.FunName   = funName;
                            cmd.DataValue = dataVale;
                            cmd.Descr     = descr;
                            cmd.IsUI      = true;
                            cmd.IsNDb     = true;
                            cmd.Create_by = Config.Uid;
                            if (cmd.TransferType == 4)
                            {
                                //string fs = cmd.FunType + cmd.DataValue;
                                //string tagName = "", dataValue = "";
                                //tagName = bll.GetSSrIOService(ledger, module_id, fs, out dataValue);
                                //if (!string.IsNullOrEmpty(tagName) && !string.IsNullOrEmpty(dataVale))
                                //{
                                //    cmd.LpszDbVarName = tagName;
                                //    cmd.DataValue = dataVale;
                                //}
                                DataProcess.IOService.Collection.CollectionHelper.WriteVar(cmd);
                            }
                            else
                            {
                                DataProcess.YdDrive.Collection.CollectionHelper.Instance(cmd);
                            }
                            FileLog.Debug("电表ID:" + cmd.Module_id + "地址:" + cmd.ModuleAddr + "动作:" + cmd.Descr);
                        }
                    }
                }
                catch (Exception ex)
                {
                    FileLog.Error("拉合闸策略错误:" + ex.Message + ex.StackTrace);
                }
            }
        }