Exemple #1
0
        private void CtorlSsr1(int module_id)
        {/*先下发命令*/
         //YDS6000.BLL.CmdService.ProcessBLL gwBll = new YDS6000.BLL.CmdService.ProcessBLL(Config.Ledger, Config.Uid);
         //int fun_id = gwBll.GetYdToFun_id(module_id, V0Fun.Ssr);
         //long log_id = gwBll.YdToGwOfAddCmd(module_id, fun_id, V0Fun.Ssr.ToString(), "1");
         //CommandVModel cmd = gwBll.GetYdToGwOfSendCmd(log_id);
            CommandVModel cmd = bll.GetSsr1(module_id);  //ModelHandler<CommandVModel>.FillModel(dtSsr.Rows[0]);

            if (cmd == null)
            {
                FileLog.Error("CtorlSsr1没有数据");
                return;
            }
            cmd.DataValue = "1";
            cmd.IsNDb     = true;
            cmd.Create_by = Config.Uid;
            cmd.IsRn      = 1;
            if (cmd.TransferType == 4)
            {/*IOService通信*/
                string fs = cmd.FunType + cmd.DataValue;
                string tagName = "", dataValue = "";
                tagName = bll.GetSSrIOService(module_id, fs, out dataValue);
                if (!string.IsNullOrEmpty(tagName) && !string.IsNullOrEmpty(dataValue))
                {
                    cmd.LpszDbVarName = tagName;
                    cmd.DataValue     = dataValue;
                }
                DataProcess.IOService.Collection.CollectionHelper.WriteVar(cmd);
                //DataProcess.IOService.Collection.CollectionHelper.WriteVar(cmd.Ledger, cmd.HandledBY, cmd.LpszDbVarName, cmd.DataValue);
            }
            else
            {
                DataProcess.YdDrive.Collection.CollectionHelper.Instance(cmd);
            }
            //DataProcess.YdDrive.Collection.CollectionHelper.Instance(cmd);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //处理未捕获的异常
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            //处理UI线程异常
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            new Config();/*初始化配置*/
            //for (int i = 0; i < args.Length; i++)
            //{
            //    if (i == 0 && !string.IsNullOrEmpty(args[i]))
            //        Config.Project = args[i].Trim();
            //};
            //
            string argStr = string.IsNullOrEmpty(Config.Systems) ? "test" : Config.Systems;

            mutex = new System.Threading.Mutex(true, argStr);
            if (!mutex.WaitOne(0, false))
            {
                return;
            }

            bool   isStart = false;
            string AppCode = ConfigHelper.GetComputerSn();
            string sn      = ConfigHelper.GetAppSettings("sn");
            bool   isVrc   = GetVrc();

            if (string.IsNullOrEmpty(sn) || !sn.Trim().Equals(ConfigHelper.Encrypt(AppCode.Trim())) || isVrc == false)
            {
                FormAKey form = new FormAKey();
                if (form.ShowDialog() == DialogResult.OK)
                {
                    FormSetConnInfo form0 = new FormSetConnInfo();
                    if (form0.ShowDialog() == DialogResult.OK)
                    {
                        isStart = true;
                    }
                }
            }
            else
            {
                FormSetConnInfo form0 = new FormSetConnInfo();
                if (form0.ShowDialog() == DialogResult.OK)
                {
                    isStart = true;
                }
            }

            if (isStart == false)
            {
                return;
            }

            new DataProcess.Services.ListenSocket().Start(); /*开启监听服务*/
            DataProcess.YdProcess.Helper.Start();            // 启动服务

            FileLog.WriteLog("启动成功");

            MainForm mainForm = new MainForm();

            mainForm.Text = mainForm.Text + " -- 项目名称:" + Config.SystemName;
            Application.Run(mainForm);
        }
Exemple #3
0
        private void AlarmSms(long log_id, int co_id, string coName, string moduleName, DateTime lastTime, decimal rdVal, decimal rdAmt)
        {
            List <string> listReceipts = new List <string>();
            string        crmName = "", content = "";
            int           aid = 0, errCode = 0;
            string        errTxt = "";
            string        msg    = "";

            try
            {
                DataTable dtSource = bll.GetAlarm_log_hand(log_id, HdType.AL_Sms.ToString());
                if (dtSource.Rows.Count > 0)
                {
                    aid     = CommFunc.ConvertDBNullToInt32(dtSource.Rows[0]["Aid"]);
                    errCode = CommFunc.ConvertDBNullToInt32(dtSource.Rows[0]["ErrCode"]);
                }
                if (errCode == 1)
                {
                    return;
                }

                DataTable dtCrm = bll.GetCrmOfCo(co_id);
                foreach (DataRow drCrm in dtCrm.Rows)
                {
                    if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(drCrm["MPhone"])))
                    {
                        listReceipts.Add(CommFunc.ConvertDBNullToString(drCrm["MPhone"]));
                    }
                    //if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(drCrm["MPhone"])))
                    //    mphone.Add(CommFunc.ConvertDBNullToString(drCrm["MPhone"]));
                    //if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(drCrm["Email"])))
                    //    listReceipts.Add(CommFunc.ConvertDBNullToString(drCrm["Email"]));
                    crmName = CommFunc.ConvertDBNullToString(drCrm["CrmName"]);
                }
                //object obj = new
                //{
                //    CrmName = crmName,
                //    DateTime = lastTime.ToString("yyyy-MM-dd"),
                //    CoName = coName,
                //    SyAmt = rdAmt.ToString("f2"),
                //    SyVal = rdVal.ToString("f2") + "kWh"
                //};
                object obj = new
                {
                    moduleName = moduleName,
                    rdAmt      = rdAmt.ToString("f2") + "元",
                };
                content = JsonHelper.Serialize(obj);
            }
            catch (Exception ex)
            {
                FileLog.Error("获取告警数据错误:" + ex.Message + ex.StackTrace);
                errTxt = "获取告警用户邮件手机号码错误";
            }
            ////////////////
            bool sue = false;

            if (listReceipts.Count != 0)
            {
                //【电费通知】尊敬的【房间名】用户,您好,您已欠费【具体金额】,请及时缴费。
                if (!string.IsNullOrEmpty(pro.Sms.ComSmsConfig.ComSms))
                {
                    if (rdAmt < 0)
                    {
                        content = "【电费通知】尊敬的【" + coName + "】用户,您好,您已欠费【" + Math.Abs(rdAmt).ToString("f2") + "元】,请及时缴费。";
                    }
                    else
                    {
                        content = "【电费通知】尊敬的【" + coName + "】用户,您好,您已剩余【" + Math.Abs(rdAmt).ToString("f2") + "元】,请及时缴费。";
                    }
                    //content = "你好当前设备:" + moduleName + "余额:" + rdAmt.ToString("f2");
                }
                sue = this.SendSms(listReceipts, content, out msg);
            }
            else
            {
                msg = "无手机号码";
            }
            errTxt  = msg;
            errCode = (sue == true ? 1 : -1);
            bll.AddAV2_alarm_log_hand(log_id, aid, HdType.AL_Sms.ToString(), "", "", errCode, errTxt);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        private void AutoARM()//DataTable dtSource
        {
            DateTime? dtStart    = null;
            DateTime? dtIsWrDate = null;
            DataTable dtSource   = null;

            while (true)
            {
                Thread.Sleep(1000);
                ////////////
                if (NCSys.IsRun == false)
                {
                    break;                                                                                      /*网关未启动*/
                }
                bool running = (dtStart == null || DateTime.Now > dtStart.Value.AddMinutes(60)) ? true : false; /*15分钟没有运行过立刻再运行一次*/

                if (NCSys.BackgroundCount > 0 && running == false)
                {
                    continue;                                                /*没有后台命令时才循环再发 /*防止过多的命令,导致内存不足*/
                }
                if (NCSys.UIResult.Count >= 15000)
                {                                 /*没有后台命令时才循环再发 /*防止过多的命令,导致内存不足*/
                    Thread.Sleep(1000 * 60 * 10); /*等10分钟*/
                }
                if (NCSys.UIResult.Count >= 5000)
                {/*没有后台命令时才循环再发 /*防止过多的命令,导致内存不足*/
                    continue;
                }
                try
                {
                    int frMd = 0;
                    if (dtSource != null)
                    {
                        foreach (DataRow dr in dtSource.Rows)
                        {
                            frMd = CommFunc.ConvertDBNullToInt32(dr["FrMd"]);
                            CommandVModel cmd = ModelHandler <CommandVModel> .FillModel(dr);

                            this.AddCmd(cmd);
                        }
                    }
                    frMd = frMd == 0 ? 15 : frMd;

                    #region 获取读写的数据
                    int  r1    = dtIsWrDate == null ? 0 : CommFunc.ConvertDBNullToInt32(dtIsWrDate.Value.ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo));
                    int  r2    = CommFunc.ConvertDBNullToInt32(DateTime.Now.ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo));
                    bool isRun = (dtIsWrDate == null) ? true : false;
                    if (isRun == false)
                    {
                        if (DateTime.Now.Hour <= 4)
                        {
                            isRun = (r1 != r2) ? true : false;
                        }
                    }
                    //if (isRun == true && DateTime.Now.Hour <= 4)
                    if (isRun == true && 1 == 2)
                    {
                        DataTable dtWr = bll.GetWrData();
                        foreach (DataRow dr in dtWr.Rows)
                        {
                            CommandVModel cmd = ModelHandler <CommandVModel> .FillModel(dr);

                            this.AddCmd(cmd);
                        }
                        dtIsWrDate = DateTime.Now;
                    }
                    #endregion
                    #region 更新抄表数据
                    if (DateTime.Now >= dtUpARM.AddMinutes(frMd))
                    {
                        dtSource = bll.GetArmData();
                        dtUpARM  = DateTime.Now;
                    }
                    #endregion
                    dtStart = DateTime.Now;
                }
                catch (Exception ex)
                {
                    FileLog.Error("自动抄表命令错误" + ex.Message + ex.StackTrace);
                }
                Thread.Sleep(1000 * 15);
            }
        }
Exemple #6
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);
                }
            }
        }