private void FormSetConnInfo_Load(object sender, EventArgs e) { this.txtSource.Text = IniHepler.GetConfig(Config.lpFileName, "Db", "DbHost"); this.txtUid.Text = IniHepler.GetConfig(Config.lpFileName, "Db", "DbUid"); this.txtPasswd.Text = ConfigHelper.Decrypt(IniHepler.GetConfig(Config.lpFileName, "Db", "DBPwd")); this.txtDbName.Text = IniHepler.GetConfig(Config.lpFileName, "Db", "DbName"); }
private void Start() { try { if (string.IsNullOrEmpty(WebConfig.LpFileName)) { //string lpFileName = HttpContext.Current.Request.PhysicalApplicationPath + "web.ini"; string lpFileName = AppDomain.CurrentDomain.BaseDirectory + "web.ini"; string project = IniHepler.GetConfig(lpFileName, "Automatic", "Project"); WebConfig.Ledger = CommFunc.ConvertDBNullToInt32(IniHepler.GetConfig(lpFileName, "Automatic", "Ledger")); WebConfig.Port = CommFunc.ConvertDBNullToInt32(IniHepler.GetConfig(lpFileName, "Automatic", "Port")); WebConfig.MemcachKey = project + "->" + WebConfig.Ledger + "->"; string connect = ConfigHelper.GetConnectionStrings("DefaultConnection"); string dbHost = IniHepler.GetConfig(lpFileName, "Db", "DbHost"); string dbName = IniHepler.GetConfig(lpFileName, "Db", "DbName"); string dbUid = IniHepler.GetConfig(lpFileName, "Db", "DbUid"); string dbPwd = IniHepler.GetConfig(lpFileName, "Db", "DBPwd"); dbPwd = ConfigHelper.Decrypt(dbPwd); // connect = string.Format(connect, dbHost, dbName, dbUid, dbPwd); YDS6000.BLL.WholeBLL.ConnectionString(connect); WebConfig.LpFileName = lpFileName; Automatic.Start(); FileLog.WriteLog("启动成功:" + project); } } catch (Exception ex) { FileLog.WriteLog("启动错误:" + ex.Message + ex.StackTrace); } }
private void FormCfg_Load(object sender, EventArgs e) { this.bind(); int isAlarm = CommFunc.ConvertDBNullToInt32(IniHepler.GetConfig(Config.lpFileName, "Alarm", "isAlarm")); this.IsAlarm.Checked = isAlarm == 1 ? true : false; this.txtHour.Value = CommFunc.ConvertDBNullToInt32(IniHepler.GetConfig(Config.lpFileName, "Alarm", "hour")); this.txtPortName.Value = CommFunc.ConvertDBNullToInt32(IniHepler.GetConfig(Config.lpFileName, "Alarm", "portName")); this.cbBaudRate.Text = IniHepler.GetConfig(Config.lpFileName, "Alarm", "baudRate"); this.cbDataBits.Text = IniHepler.GetConfig(Config.lpFileName, "Alarm", "databits"); this.cbStopBits.Text = IniHepler.GetConfig(Config.lpFileName, "Alarm", "stopBits"); this.cbParity.SelectedValue = CommFunc.ConvertDBNullToInt32(IniHepler.GetConfig(Config.lpFileName, "Alarm", "parity")); }
private void buttonOK_Click(object sender, EventArgs e) { string HOST = this.txtSource.Text.Trim(); string DBUID = this.txtUid.Text.Trim(); string DBPWD = this.txtPasswd.Text.Trim(); string DBNAME = this.txtDbName.Text.Trim(); if (string.IsNullOrEmpty(HOST)) { MessageBox.Show("请输入数据源", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.txtSource.Focus(); return; } if (string.IsNullOrEmpty(DBUID)) { MessageBox.Show("请输入用户名", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.txtUid.Focus(); return; } if (string.IsNullOrEmpty(DBPWD)) { MessageBox.Show("请输入密码", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.txtPasswd.Focus(); return; } if (string.IsNullOrEmpty(DBNAME)) { MessageBox.Show("请输入数据库实例", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.txtDbName.Focus(); return; } // try { string connect = ConfigHelper.GetConnectionStrings("DefaultConnection"); IniHepler.SetConfig("Db", "DbHost", HOST, Config.lpFileName); IniHepler.SetConfig("Db", "DbName", DBNAME, Config.lpFileName); IniHepler.SetConfig("Db", "DbUid", DBUID, Config.lpFileName); IniHepler.SetConfig("Db", "DbPwd", ConfigHelper.Encrypt(DBPWD), Config.lpFileName); connect = string.Format(connect, HOST, DBNAME, DBUID, DBPWD); YDS6000.BLL.WholeBLL.ConnectionString(connect); } catch (Exception ex) { MessageBox.Show("更新错误" + ex.Message); return; } this.DialogResult = System.Windows.Forms.DialogResult.OK; }
/// <summary> /// 发送采集数据 /// </summary> /// <param name="vm"></param> /// <param name="msg"></param> /// <returns></returns> public static bool SendCollectVal(ListenVModel vm, out string msg) { bool rst = false; msg = ""; try { if (start == false) { //string ps1 = IniHepler.GetConfig(WebConfig.LpFileName, "Automatic", "Ip"); //string[] ar = ps1.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); //if (ar.Count() != 2) //{ // msg = "IP地址格式错误"; // return false; //} //ip = CommFunc.ConvertDBNullToString(ar[0]); //port = CommFunc.ConvertDBNullToInt32(ar[1]); string ps1 = IniHepler.GetConfig(WebConfig.LpFileName, "Automatic", "Port"); port = CommFunc.ConvertDBNullToInt32(ps1); start = true; } ///////////////////////////////////////// string data = JsonHelper.Serialize(vm); IPAddress host = IPAddress.Parse(ip); Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); clientSocket.ReceiveTimeout = 1000; clientSocket.SendTimeout = 1000; byte[] dd = System.Text.Encoding.Default.GetBytes(data); lock (CacheMgr.staticLocker) { clientSocket.Connect(host, port); clientSocket.Send(dd); if (clientSocket.Connected) { clientSocket.Shutdown(SocketShutdown.Both); } clientSocket.Close(); } rst = true; } catch (Exception ex) { FileLog.WriteLog("网络发送数据错误:" + ex.Message + ex.StackTrace); msg = ex.Message; } return(rst); }
public void Run() { DateTime dtAlarm = DateTime.Now.AddDays(-9999); while (true) { Thread.Sleep(1000); try { int scan = CommFunc.ConvertDBNullToInt32(IniHepler.GetConfig(Config.lpFileName, "Alarm", "Scan")); scan = scan == 0 ? (60 * 24) : scan; // //if (SmsTime == null || SmsTime.Value.AddMinutes(15) > DateTime.Now) SmsFun.StopSerice();/*停止端口,让出端口给其他应用使用*/ // if (DateTime.Now.Minute != 0 && DateTime.Now.Minute % 15 != 0 && DateTime.Now.Minute % 30 != 0) { continue; } if (dtAlarm.AddMinutes(scan) > DateTime.Now) { continue; } int hour = DateTime.Now.Hour; int hh = CommFunc.ConvertDBNullToInt32(IniHepler.GetConfig(Config.lpFileName, "Alarm", "Hour")); int isAlarm = CommFunc.ConvertDBNullToInt32(IniHepler.GetConfig(Config.lpFileName, "Alarm", "IsAlarm")); if (isAlarm == 0) { continue; /*总开关*/ } if (hour < hh) { continue; } foreach (var s1 in NCSys.Pro) { //new ZpAlarm(s1.Key, s1.Value).GetAlarm(); } dtAlarm = DateTime.Now; } catch (Exception ex) { FileLog.Error("告警处理模块错误:" + ex.Message + ex.StackTrace); } } }
static Config() { if (string.IsNullOrEmpty(Config.lpFileName)) { string path = AppDomain.CurrentDomain.BaseDirectory; string[] aa = path.Split(new Char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); string tt = aa[aa.Length - 1]; if (tt.ToLower().Equals("Automatic".ToLower())) { Config.lpFileName = path.Substring(0, path.Length - (tt.Length + 1)) + "Web.ini"; } else { Config.lpFileName = path + "Web.ini"; } } string port = IniHepler.GetConfig(lpFileName, "Automatic", "Port"); if (!string.IsNullOrEmpty(port)) { Config.ListenPort = CommFunc.ConvertDBNullToInt32(port); } Config.Systems = IniHepler.GetConfig(lpFileName, "Automatic", "Systems"); Config.Uid = CommFunc.ConvertDBNullToInt32(IniHepler.GetConfig(lpFileName, "Automatic", "Uid")); //Config.Project = IniHepler.GetConfig(lpFileName, "Automatic", "Project"); Config.SystemName = IniHepler.GetConfig(lpFileName, "Automatic", "SystemName"); Config.Log_levenl = CommFunc.ConvertDBNullToInt32(IniHepler.GetConfig(lpFileName, "Automatic", "Log_levenl")); string rdcIp = CommFunc.ConvertDBNullToString(IniHepler.GetConfig(lpFileName, "Rdc", "Ip")); int rdcPort = CommFunc.ConvertDBNullToInt32(IniHepler.GetConfig(lpFileName, "Rdc", "DataPort")); if (!string.IsNullOrEmpty(rdcIp)) { Config.IOHandledBY = rdcIp + ":" + rdcPort; } // string connect = ConfigHelper.GetConnectionStrings("DefaultConnection"); string dbHost = IniHepler.GetConfig(lpFileName, "Db", "DbHost"); string dbName = IniHepler.GetConfig(lpFileName, "Db", "DbName"); string dbUid = IniHepler.GetConfig(lpFileName, "Db", "DbUid"); string dbPwd = IniHepler.GetConfig(lpFileName, "Db", "DBPwd"); dbPwd = ConfigHelper.Decrypt(dbPwd); // connect = string.Format(connect, dbHost, dbName, dbUid, dbPwd); YDS6000.BLL.WholeBLL.ConnectionString(connect); }
private void button1_Click(object sender, EventArgs e) { if (MessageBox.Show("确定更改保存吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes) { return; } int isAlarm = this.IsAlarm.Checked == true ? 1 : 0; int hour = CommFunc.ConvertDBNullToInt32(this.txtHour.Value); int portName = CommFunc.ConvertDBNullToInt32(this.txtPortName.Value); int baudRate = CommFunc.ConvertDBNullToInt32(this.cbBaudRate.Text); int databits = CommFunc.ConvertDBNullToInt32(this.cbDataBits.Text); int stopBits = CommFunc.ConvertDBNullToInt32(this.cbStopBits.Text); int parity = CommFunc.ConvertDBNullToInt32(this.cbParity.SelectedValue); IniHepler.SetConfig("Alarm", "isAlarm", isAlarm.ToString(), Config.lpFileName); IniHepler.SetConfig("Alarm", "hour", hour.ToString(), Config.lpFileName); IniHepler.SetConfig("Alarm", "portName", portName.ToString(), Config.lpFileName); IniHepler.SetConfig("Alarm", "baudRate", baudRate.ToString(), Config.lpFileName); IniHepler.SetConfig("Alarm", "databits", databits.ToString(), Config.lpFileName); IniHepler.SetConfig("Alarm", "stopBits", stopBits.ToString(), Config.lpFileName); IniHepler.SetConfig("Alarm", "parity", parity.ToString(), Config.lpFileName); this.DialogResult = System.Windows.Forms.DialogResult.OK; }
private static void SendHd(int ledger, long log_id, AlarmType alarmType, HdType hdType, string content, int module_id) { SysPro pro; NCSys.Pro.TryGetValue(ledger, out pro); if (pro == null) { return; } DataProcessBLL bll = new DataProcessBLL(ledger, Config.Uid); v2_alarm_logHandVModel hand = bll.GetAlarmHand(log_id, hdType.ToString()); hand.Content = content; if (hand.ErrCode == 1) { int sendSpan = CommFunc.ConvertDBNullToInt32(IniHepler.GetConfig(Config.lpFileName, "Alarm", "SendSpan")); if (hand.HdTime.AddMinutes(sendSpan) > DateTime.Now) { return; } else { hand.Aid = 0;/*新增一条记录*/ } } DataTable dtSource = bll.GetSendInfo(module_id); List <string> mpReceipts = new List <string>(); List <string> emReceipts = new List <string>(); string coName = "", moduleName = ""; foreach (DataRow drCrm in dtSource.Rows) { if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(drCrm["MPhone"]))) { mpReceipts.Add(CommFunc.ConvertDBNullToString(drCrm["MPhone"])); } if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(drCrm["Email"]))) { emReceipts.Add(CommFunc.ConvertDBNullToString(drCrm["Email"])); } coName = CommFunc.ConvertDBNullToString(drCrm["CoName"]); moduleName = CommFunc.ConvertDBNullToString(drCrm["ModuleName"]); } bool sue = false; string msg = ""; try { if (hdType == HdType.AL_Sms) { if (mpReceipts.Count > 0) { if (alarmType == AlarmType.Al_Use) {/*感知万物演示用*/ string ccc = JsonHelper.Serialize(new { moduleName = moduleName }); if (!string.IsNullOrEmpty(pro.Sms.ComSmsConfig.ComSms)) { sue = pro.Sms.SendMessage(mpReceipts, ccc, out msg); } else if (!string.IsNullOrEmpty(SmsFun.AliSmsConfig.AliAppKey)) { sue = pro.Sms.SmsMessage(mpReceipts, ccc, out msg, "SMS_137657141"); } else { msg = "没有发现短信接口"; } } else { msg = "感知演示,暂不开放"; } } else { msg = "无手机号码"; } } else if (hdType == HdType.AL_Email) { if (mpReceipts.Count > 0) { StringBuilder mailcont1 = new StringBuilder(); mailcont1.Append("你好:" + coName); mailcont1.Append("<br>"); mailcont1.Append("告警内容:" + hand.Content); mailcont1.Append("<br>"); mailcont1.Append("告警时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo)); pro.Email.SendMail("告警通知", mailcont1.ToString(), "", emReceipts, null, null); sue = true; } else { msg = "无邮箱地址"; } } hand.ErrCode = sue == true ? 1 : -1; } catch (Exception ex) { hand.ErrCode = -1; msg = ex.Message; } hand.ErrTxt = msg; bll.UpAlarmHand(hand); }