Ejemplo n.º 1
0
        private void timer_Tick(object sender, System.EventArgs e)
        {
            count.Text = ++countNumber + "";
            MyDBConnect myDBConnect = new MyDBConnect();

            myDBConnect.Open();
            try
            {
                string          qian45 = DateTime.Now.AddMinutes(-45).ToString("yyyy-MM-dd HH:mm:ss");
                string          qian30 = DateTime.Now.AddMinutes(-30).ToString("yyyy-MM-dd HH:mm:ss");
                string          sql    = "SELECT diaoxian.Project_ID projectId,diaoxian.`max` lasttime,pro.userid userid,wxuser.openid openid,wxuser.nickname FROM `tb_qd_projectinuser` pro LEFT JOIN (SELECT Project_ID,MAX(tb.`Date`) `max` FROM tb_monitordata15 tb WHERE tb.`Date` > '" + qian45 + "' GROUP BY Project_ID HAVING `max` < '" + qian30 + "') diaoxian  ON diaoxian.Project_ID = pro.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON pro.userid = wxuser.userid WHERE diaoxian.Project_ID IS NOT NULL";
                MySqlDataReader reader = myDBConnect.Reader(sql);
                while (reader.NextResult())
                {
                    string text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": projectId=" + reader.GetString("projectId") + " lasttime=" + reader.GetString("lasttime") + " userid=" + reader.GetString("userid") + " openid=" + reader.GetString("openid") + " nickname=" + reader.GetString("nickname");
                    content.Text = content.Text + "\r\n" + text;
                }
            }
            catch (Exception e1)
            {
            }
            finally
            {
                myDBConnect.Close();
            }
        }
Ejemplo n.º 2
0
        private void OnTimedEvent(object sender, ElapsedEventArgs e)
        {
            MyDBConnect myDBConnect = new MyDBConnect();

            myDBConnect.Open();
            try
            {
                string          qian45 = DateTime.Now.AddMinutes(-45).ToString("yyyy-MM-dd HH:mm:ss");
                string          qian30 = DateTime.Now.AddMinutes(-30).ToString("yyyy-MM-dd HH:mm:ss");
                string          sql    = "SELECT diaoxian.Project_ID projectId,diaoxian.`max` lasttime,pro.userid userid,wxuser.openid openid,wxuser.nickname FROM `tb_qd_projectinuser` pro LEFT JOIN (SELECT Project_ID,MAX(tb.`Date`) `max` FROM tb_monitordata15 tb WHERE tb.`Date` > '" + qian45 + "' GROUP BY Project_ID HAVING `max` < '" + qian30 + "') diaoxian  ON diaoxian.Project_ID = pro.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON pro.userid = wxuser.userid WHERE diaoxian.Project_ID IS NOT NULL";
                MySqlDataReader reader = myDBConnect.Reader(sql);
                while (reader.NextResult())
                {
                    string text = " projectId=" + reader.GetString("projectId") + " lasttime=" + reader.GetString("lasttime") + " userid=" + reader.GetString("userid") + " openid=" + reader.GetString("openid") + " nickname=" + reader.GetString("nickname");
                    Console.WriteLine("报警设备的信息:" + text);
                    logger.Info("报警设备的信息:" + text);
                }
            }
            catch (Exception e1)
            {
                logger.Info("报警设备的信息:" + e1.Message);
            }
            finally
            {
                myDBConnect.Close();
            }
        }
Ejemplo n.º 3
0
        public void Check(HashSet <int> diaoxianSet, MyDBConnect myDBConnect, DeviceStatusMonitor deviceStatusMonitor)
        {
            if (diaoxianSet == null || diaoxianSet.Count == 0 || myDBConnect == null || deviceStatusMonitor == null)
            {
                if (diaoxianSet == null)
                {
                    MyLog.log("掉线设备集合引用为空");
                }
                else if (diaoxianSet.Count == 0)
                {
                    MyLog.log("当前没有设备掉线");
                }
                return;
            }
            HashSet <Project> projectSet = new HashSet <Project>();
            string            qian15     = DateTime.Now.AddMinutes(-15).ToString("yyyy-MM-dd HH:mm:ss");
            string            inDiaoxian = "";
            int n = 0;

            foreach (int i in diaoxianSet)
            {
                n++;
                inDiaoxian += i;
                if (n < diaoxianSet.Count)
                {
                    inDiaoxian += ",";
                }
            }

            string sql = "SELECT shangxian.Project_ID projectId, wxuser.openid openid, project.`Project_Name` `name`,project.Project_Address address FROM `tb_qd_projectinuser` prouser LEFT JOIN (SELECT Project_ID FROM tb_monitordata15 tb WHERE tb.`Project_ID` IN (" + inDiaoxian + ") AND tb.`Date` > '" + qian15 + "') shangxian ON shangxian.Project_ID = prouser.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON prouser.userid = wxuser.userid LEFT JOIN `tb_project` project ON prouser.`Project_ID`= project.`Project_ID` WHERE prouser.`Project_ID` IN (" + inDiaoxian + ") AND shangxian.`Project_ID` IS NOT NULL AND wxuser.`openid` IS NOT NULL AND wxuser.`openid` != ''";

            MyLog.log("查询上线的SQL语句:" + sql);
            MySqlDataReader reader = myDBConnect.Reader(sql);

            while (reader.Read())
            {
                Project project = new Project
                {
                    projectId = reader.GetInt32("projectId"),
                    openId    = reader.GetString("openid"),
                    name      = reader.GetString("name"),
                    address   = reader.GetString("address")
                };
                projectSet.Add(project);
            }
            reader.Close();
            foreach (var project in projectSet)
            {
                diaoxianSet.Remove(project.projectId);
                Baojing baojing = new Baojing();
                baojing.text          = project.name + "设备上线";
                baojing.time          = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                baojing.type          = "上线";
                baojing.point         = project.address;
                baojing.BaojingObject = project.name;
                string result = deviceStatusMonitor.SendBaojing(baojing, project.openId);
                MyLog.log("设备上线:" + "openid=" + project.openId + ",name=" + project.name + ",address=" + project.address);
                MyLog.log("上线通知发送结果:" + result);
            }
        }
Ejemplo n.º 4
0
        private void timer_Tick(object sender, System.EventArgs e)
        {
            count.Text = ++countNumber + "";
            MyDBConnect myDBConnect = new MyDBConnect();

            myDBConnect.Open();
            string sql = null;

            try
            {
                string qian45 = DateTime.Now.AddMinutes(-45).ToString("yyyy-MM-dd HH:mm:ss");
                string qian30 = DateTime.Now.AddMinutes(-30).ToString("yyyy-MM-dd HH:mm:ss");
                sql = "SELECT wxuser.openid openid, project.`Project_Name` `name`,project.Project_Address address FROM `tb_qd_projectinuser` prouser LEFT JOIN (SELECT Project_ID,MAX(tb.`Date`) `max` FROM tb_monitordata15 tb WHERE tb.`Date` > '" + qian45 + "' GROUP BY Project_ID HAVING `max` < '" + qian30 + "') diaoxian  ON diaoxian.Project_ID = prouser.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON prouser.userid = wxuser.userid left join `tb_project` project on prouser.`Project_ID`= project.`Project_ID` WHERE diaoxian.Project_ID IS NOT NULL And wxuser.`openid` is not null and wxuser.`openid` != ''";
                MySqlDataReader reader = myDBConnect.Reader(sql);
                if (reader.NextResult())
                {
                    do
                    {
                        Project project = new Project();
                        project.openId  = reader.GetString("openid");
                        project.name    = reader.GetString("name");
                        project.address = reader.GetString("address");
                        string text = "openid=" + project.openId + ";name=" + project.name + ";address=" + project.address;
                        labelContent.Text = labelContent.Text + "\r\n" + text;
                    } while (reader.NextResult());
                }
                else
                {
                    labelContent.Text = labelContent.Text + "\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": 没有掉线设备" + (DateTime.Now.Ticks - startTime);
                }
            }
            catch (Exception e1)
            {
                labelContent.Text = labelContent.Text + "\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": 查询出错";
            }
            finally
            {
                const string filename = "log.txt";
                FileStream   fs       = new FileStream(filename, FileMode.Append);
                byte[]       bytes    = System.Text.Encoding.Default.GetBytes("sql=" + sql);
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();
                myDBConnect.Close();
            }
        }
Ejemplo n.º 5
0
        public void Check(MyDBConnect myDBConnect, DeviceStatusMonitor deviceStatusMonitor)
        {
            HashSet <Project> projectSet = new HashSet <Project>();
            string            qian45     = DateTime.Now.AddMinutes(-45).ToString("yyyy-MM-dd HH:mm:ss");
            string            qian30     = DateTime.Now.AddMinutes(-30).ToString("yyyy-MM-dd HH:mm:ss");
            // string sql = "SELECT diaoxian.Project_ID projectId,diaoxian.`max` lasttime,pro.userid userid,wxuser.openid openid,wxuser.nickname FROM `tb_qd_projectinuser` pro LEFT JOIN (SELECT Project_ID,MAX(tb.`Date`) `max` FROM tb_monitordata15 tb WHERE tb.`Date` > '" + qian45 + "' GROUP BY Project_ID HAVING `max` < '" + qian30 + "') diaoxian  ON diaoxian.Project_ID = pro.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON pro.userid = wxuser.userid WHERE diaoxian.Project_ID IS NOT NULL";
            //可以用的
            string sql = "SELECT diaoxian.Project_ID projectId, wxuser.openid openid, project.`Project_Name` `name`,project.Project_Address address FROM `tb_qd_projectinuser` prouser LEFT JOIN (SELECT Project_ID,MAX(tb.`Date`) `max` FROM tb_monitordata15 tb WHERE tb.`Date` > '" + qian45 + "' GROUP BY Project_ID HAVING `max` < '" + qian30 + "') diaoxian  ON diaoxian.Project_ID = prouser.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON prouser.userid = wxuser.userid left join `tb_project` project on prouser.`Project_ID`= project.`Project_ID` WHERE diaoxian.Project_ID IS NOT NULL And wxuser.`openid` is not null and wxuser.`openid` != ''";

            //测试用的
            //string sql = "SELECT wxuser.openid openid, project.`Project_Name` `name`,project.Project_Address address FROM `tb_qd_projectinuser` prouser LEFT JOIN (SELECT Project_ID,MAX(tb.`Date`) `max` FROM tb_monitordata15 tb WHERE tb.`Date` > '" + qian45 + "' GROUP BY Project_ID) diaoxian  ON diaoxian.Project_ID = prouser.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON prouser.userid = wxuser.userid left join `tb_project` project on prouser.`Project_ID`= project.`Project_ID` WHERE diaoxian.Project_ID IS NOT NULL And wxuser.`openid` is not null and wxuser.`openid` != ''";
            MyLog.log("查询掉线的SQL语句:" + sql);
            MySqlDataReader reader = myDBConnect.Reader(sql);

            while (reader.Read())
            {
                Project project = new Project
                {
                    projectId = reader.GetInt32("projectId"),
                    openId    = reader.GetString("openid"),
                    name      = reader.GetString("name"),
                    address   = reader.GetString("address")
                };
                projectSet.Add(project);
            }
            reader.Close();
            foreach (var project in projectSet)
            {
                Baojing baojing = new Baojing();
                baojing.text          = project.name + "设备掉线";
                baojing.time          = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                baojing.type          = "掉线";
                baojing.point         = project.address;
                baojing.BaojingObject = project.name;
                string result = deviceStatusMonitor.SendBaojing(baojing, project.openId);
                MyLog.log("设备掉线:" + "openid=" + project.openId + ",name=" + project.name + ",address=" + project.address);
                MyLog.log("报警发送结果:" + result);
                diaoxianSet.Add(project.projectId);
            }
        }
Ejemplo n.º 6
0
        private void OnTimedEvent(object sender, ElapsedEventArgs e)
        {
            MyDBConnect myDBConnect = new MyDBConnect();

            myDBConnect.Open();
            try
            {
                string qian45 = DateTime.Now.AddMinutes(-45).ToString("yyyy-MM-dd HH:mm:ss");
                string qian30 = DateTime.Now.AddMinutes(-30).ToString("yyyy-MM-dd HH:mm:ss");
                //string sql = "SELECT diaoxian.Project_ID projectId,diaoxian.`max` lasttime,pro.userid userid,wxuser.openid openid,wxuser.nickname FROM `tb_qd_projectinuser` pro LEFT JOIN (SELECT Project_ID,MAX(tb.`Date`) `max` FROM tb_monitordata15 tb WHERE tb.`Date` > '" + qian45 + "' GROUP BY Project_ID HAVING `max` < '" + qian30 + "') diaoxian  ON diaoxian.Project_ID = pro.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON pro.userid = wxuser.userid WHERE diaoxian.Project_ID IS NOT NULL";
                string          sql    = "SELECT wxuser.openid openid, project.`Project_Name` `name`,project.Project_Address address FROM `tb_qd_projectinuser` prouser LEFT JOIN (SELECT Project_ID,MAX(tb.`Date`) `max` FROM tb_monitordata15 tb WHERE tb.`Date` > '" + qian45 + "' GROUP BY Project_ID HAVING `max` < '" + qian30 + "') diaoxian  ON diaoxian.Project_ID = prouser.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON prouser.userid = wxuser.userid left join `tb_project` project on prouser.`Project_ID`= project.`Project_ID` WHERE diaoxian.Project_ID IS NOT NULL And wxuser.`openid` is not null and wxuser.`openid` != ''";
                MySqlDataReader reader = myDBConnect.Reader(sql);
                while (reader.NextResult())
                {
                    Project project = new Project();
                    project.openId  = reader.GetString("openid");
                    project.name    = reader.GetString("name");
                    project.address = reader.GetString("address");
                    string text = "openid=" + project.openId + ";name=" + project.name + ";address=" + project.address;
                    Console.WriteLine("报警设备的信息:" + text);
                }

                const string filename = "log.txt";
                FileStream   fs       = new FileStream(filename, FileMode.Append);
                byte[]       bytes    = System.Text.Encoding.Default.GetBytes("sql=" + sql);
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();
            }
            catch (Exception e1)
            {
            }
            finally
            {
                myDBConnect.Close();
            }
        }
Ejemplo n.º 7
0
 public void Check(MyDBConnect myDBConnect, DeviceStatusMonitor deviceStatusMonitor)
 {
     try
     {
         Dictionary <int, List <Project> > earlyWarningDic = new Dictionary <int, List <Project> >();
         Dictionary <int, List <Project> > overProofaDic   = new Dictionary <int, List <Project> >();
         Dictionary <int, List <Project> > overProofbDic   = new Dictionary <int, List <Project> >();
         string nowDate = DateTime.Now.ToString("yyyy-MM-dd");
         //检查是否到了该清零的日子
         if (!nowDate.Equals(day))
         {
             day = nowDate;
             overProofaNote.Clear();
             overProofbNote.Clear();
         }
         string qian15 = DateTime.Now.AddMinutes(-15).ToString("yyyy-MM-dd HH:mm:ss");
         string sql    = "SELECT yujing.Project_ID projectId,yujing.`Dust` , yujing.`EarlyWarning` ,yujing.`OverProofa`,yujing.`OverProofaValue`,yujing.`OverProofb`,yujing.`OverProofbValue`,wxuser.openid openid, project.`Project_Name` `name`,project.Project_Address address FROM `tb_qd_projectinuser` prouser LEFT JOIN (SELECT config.Project_ID ,data15.`Dust` , config.`EarlyWarning` ,config.`OverProofa`,config.`OverProofaValue`,config.`OverProofb`,config.`OverProofbValue` FROM tb_projectwarnconfig config LEFT JOIN tb_monitordata15 data15 ON config.`Project_ID` = data15.`Project_ID`WHERE data15.`Date` > '" + qian15 + "' AND ((config.`EarlyWarning` !=0 AND data15.`Dust` >= config.`EarlyWarning`) OR (config.`OverProofa` !=0 AND config.`OverProofaValue` !=0 AND data15.`Dust` >= config.`OverProofaValue`) OR (config.`OverProofb` !=0 AND config.`OverProofbValue` !=0 AND data15.`Dust` >= config.`OverProofbValue`))) yujing ON yujing.Project_ID = prouser.Project_ID LEFT JOIN `tb_qd_weixininuser` wxuser ON prouser.userid = wxuser.userid LEFT JOIN `tb_project` project ON prouser.`Project_ID`= project.`Project_ID` WHERE yujing.Project_ID IS NOT NULL AND wxuser.`openid` IS NOT NULL AND wxuser.`openid` != ''";
         MyLog.log("粉尘检测sql: " + sql);
         myDBConnect.Open();
         MySqlDataReader reader = myDBConnect.Reader(sql);
         while (reader.Read())
         {
             Project project = new Project
             {
                 projectId = reader.GetInt32("projectId"),
                 openId    = reader.GetString("openid"),
                 name      = reader.GetString("name"),
                 address   = reader.GetString("address")
             };
             int    Project_ID      = reader.GetInt32("projectId");
             Double Dust            = reader.GetDouble("Dust");
             Double EarlyWarning    = reader.GetDouble("EarlyWarning");
             int    OverProofa      = reader.GetInt32("OverProofa");
             Double OverProofaValue = reader.GetDouble("OverProofaValue");
             int    OverProofb      = reader.GetInt32("OverProofb");
             Double OverProofbValue = reader.GetDouble("OverProofbValue");
             if (EarlyWarning != 0 && Dust > EarlyWarning)
             {
                 if (!earlyWarningDic.ContainsKey(Project_ID))
                 {
                     earlyWarningDic[Project_ID] = new List <Project>();
                 }
                 earlyWarningDic[Project_ID].Add(project);
             }
             if (OverProofa != 0 && OverProofaValue != 0 && Dust > OverProofaValue)
             {
                 if (!earlyWarningDic.ContainsKey(Project_ID))
                 {
                     overProofaNote[Project_ID] = 0;
                 }
                 overProofaNote[Project_ID]++;
                 if (overProofaNote[Project_ID] >= OverProofa)
                 {
                     overProofaNote[Project_ID] = 0;
                     if (!overProofaDic.ContainsKey(Project_ID))
                     {
                         overProofaDic[Project_ID] = new List <Project>();
                     }
                     overProofaDic[Project_ID].Add(project);
                 }
             }
             if (OverProofb != 0 && OverProofbValue != 0 && Dust > OverProofbValue)
             {
                 try
                 {
                     overProofbNote[Project_ID]++;
                 }
                 catch
                 {
                     overProofbNote[Project_ID] = 1;
                 }
                 if (overProofbNote[Project_ID] >= OverProofb)
                 {
                     overProofbNote[Project_ID] = 0;
                     if (!overProofbDic.ContainsKey(Project_ID))
                     {
                         overProofbDic[Project_ID] = new List <Project>();
                     }
                     overProofbDic[Project_ID].Add(project);
                 }
             }
         }
         reader.Close();
         foreach (var map in earlyWarningDic)
         {
             List <Project> projects = map.Value;
             foreach (var project in projects)
             {
                 MyLog.log("project_id为" + project.projectId + "的设备粉尘超过预警值了");
                 Baojing baojing = new Baojing();
                 baojing.text          = project.name + "设备超出预警";
                 baojing.time          = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 baojing.type          = "预警";
                 baojing.point         = project.address;
                 baojing.BaojingObject = project.name;
                 string result = deviceStatusMonitor.SendBaojing(baojing, project.openId);
                 MyLog.log("报警发送结果:" + result);
             }
         }
         foreach (var map in overProofaDic)
         {
             List <Project> projects = map.Value;
             foreach (var project in projects)
             {
                 MyLog.log("project_id为" + project.projectId + "的设备粉尘超过OverProofaValue值了");
                 Baojing baojing = new Baojing();
                 baojing.text          = project.name + "设备告警";
                 baojing.time          = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 baojing.type          = "告警";
                 baojing.point         = project.address;
                 baojing.BaojingObject = project.name;
                 string result = deviceStatusMonitor.SendBaojing(baojing, project.openId);
                 MyLog.log("报警发送结果:" + result);
             }
         }
         foreach (var map in overProofbDic)
         {
             List <Project> projects = map.Value;
             foreach (var project in projects)
             {
                 MyLog.log("project_id为" + project.projectId + "的设备粉尘超过OverProofbValue值了");
                 Baojing baojing = new Baojing();
                 baojing.text          = project.name + "设备告警";
                 baojing.time          = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 baojing.type          = "告警";
                 baojing.point         = project.address;
                 baojing.BaojingObject = project.name;
                 string result = deviceStatusMonitor.SendBaojing(baojing, project.openId);
                 MyLog.log("报警发送结果:" + result);
             }
         }
     }
     catch (Exception e1)
     {
         MyLog.log("error|代码异常信息:" + e1.ToString());
     }
 }