Esempio n. 1
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("失败");
            }
        }
Esempio n. 2
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
            }
        }
Esempio n. 3
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);
                    }
                }
            }
        }