/// <summary> /// 显示结果 /// </summary> private void ShowResult() { DateTime errTime = DateTime.Now; while (true) { Thread.Sleep(1000); try { this.UpdateAllStatus(); int uiCnt = NCSys.UIResult.Count; for (int i = 0; i < uiCnt; i++) { if (i % 200 == 0) { Thread.Sleep(200); } else { Thread.Sleep(80); } CmdResult command = null; if (NCSys.UIResult.TryDequeue(out command) == false) { continue; } if (command == null) { continue; } if (NCSys.IsRun == true) { this.Invoke(new ShowUI(UpdateList), command); } } } catch (Exception ex) { FileLog.WriteLog("错误信息:" + ex.Message + ex.StackTrace); } } }
private bool SendWx(string opendid, string crmName, string coName, DateTime lastTime, decimal SyVal, out string msg) { msg = ""; StringBuilder mailcont1 = new StringBuilder(); if (SyVal > 0) { mailcont1.Append("您好" + crmName + "当前剩余电量:" + SyVal.ToString("f2") + "kWh"); } else { mailcont1.Append("您好" + crmName + "当前透支电量:" + Math.Abs(SyVal).ToString("f2") + "kWh"); } mailcont1.Append("<br>"); mailcont1.Append("统计时间:" + lastTime.ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo)); if (string.IsNullOrEmpty(opendid)) { msg = "openid为空,微信用户未认证"; return(false); } bool rst = false; try { rst = pro.Wx.PushAlarm(opendid, "告警通知", mailcont1.ToString(), "", out msg); if (rst == true) { msg = "发送成功"; } else { msg = "发送失败"; } } catch (Exception ex) { msg = ex.Message; FileLog.WriteLog("发送微信错误" + ex.Message); } return(rst); }
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); }
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); }