Exemple #1
0
        //每隔30秒采集一次数据
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                DateTime LastDate = new DateTime();
                //便利datatable中的所有行
                if (dt.Rows.Count > 0)
                {
                    //for(int j=0;j<dt.Rows.Count;j++)
                    //{

                    //}
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string temp = HttpRequest.SendGet(dt.Rows[i][3].ToString() + "?count=1").Replace("\"data\":", "").Replace(",\"success\":\"true\"", "");
                        if (temp.Length > 10)
                        {
                            temp = temp.Substring(1, temp.Length - 2);
                            List <WanWuYunData> entityList = JsonHelper.JonsToList <WanWuYunData>(temp);
                            foreach (WanWuYunData entity in entityList)
                            {
                                if (WanWuYunDataList[i] == entity.TIME)
                                {
                                    this.richTextBox1.Text += DateTime.Now.ToString() + " 设备:" + dt.Rows[i][1].ToString() + "数据与上次相同,请查看设备状态" + "\n";
                                    TXTLogHelper.LogBackup(DateTime.Now.ToString() + " 设备:" + dt.Rows[i][1].ToString() + "数据与上次相同,请查看设备状态" + "\r\n");
                                    break;
                                }
                                entity.ID = CommonHelper.GetGuid;
                                WanWuYunData.Insert(entity);
                                this.richTextBox1.Text += DateTime.Now.ToString() + " 设备:" + dt.Rows[i][1].ToString() + "数据已更新" + "\n";
                                TXTLogHelper.LogBackup(DateTime.Now.ToString() + " 设备:" + dt.Rows[i][1].ToString() + "数据已更新" + "\r\n");
                                WanWuYunDataList[i] = Convert.ToDateTime(entity.TIME);
                            }
                        }
                        else
                        {
                            this.richTextBox1.Text += DateTime.Now.ToString() + " 设备:" + dt.Rows[i][1].ToString() + "数据未获取到" + "\n";
                            TXTLogHelper.LogBackup(DateTime.Now.ToString() + " 设备:" + dt.Rows[i][1].ToString() + "数据未获取到" + "\r\n");
                        }
                    }
                }
                //避免richTextBox1数据过大,占用内存过大,定期清除
                if (this.richTextBox1.Text.Length > 500)
                {
                    this.richTextBox1.Text = "";
                }
            }
            catch (Exception ex)
            {
                TXTLogHelper.LogBackup(DateTime.Now.ToString() + "发生异常:" + ex.Message + "\r\n");
            }
            //string testData = "[{\"DEV_ID\":\"C8:93:46:72:E7:59\",\"G\":\"0.0\",\"GX\":\"0.0\",\"GY\":\"0.0\",\"GZ\":\"0.0\",\"H\":\"56\",\"HCHO\":\"0.053\",\"LIGHT\":\"0\",\"PM25\":\"61\",\"T\":\"28\",\"TIME\":\"2018-09-07 17:42:40\",\"VERSION\":\"V4.0\"},{\"DEV_ID\":\"C8:93:46:72:E7:59\",\"G\":\"0.0\",\"GX\":\"0.0\",\"GY\":\"0.0\",\"GZ\":\"0.0\",\"H\":\"57\",\"HCHO\":\"0.054\",\"LIGHT\":\"0\",\"PM25\":\"53\",\"T\":\"28\",\"TIME\":\"2018-09-07 17:42:10\",\"VERSION\":\"V4.0\"},{\"DEV_ID\":\"C8:93:46:72:E7:59\",\"G\":\"0.0\",\"GX\":\"0.0\",\"GY\":\"0.0\",\"GZ\":\"0.0\",\"H\":\"56\",\"HCHO\":\"0.054\",\"LIGHT\":\"0\",\"PM25\":\"50\",\"T\":\"28\",\"TIME\":\"2018-09-07 17:41:40\",\"VERSION\":\"V4.0\"},{\"DEV_ID\":\"C8:93:46:72:E7:59\",\"G\":\"0.0\",\"GX\":\"0.0\",\"GY\":\"0.0\",\"GZ\":\"0.0\",\"H\":\"56\",\"HCHO\":\"0.054\",\"LIGHT\":\"0\",\"PM25\":\"54\",\"T\":\"28\",\"TIME\":\"2018-09-07 17:41:10\",\"VERSION\":\"V4.0\"},{\"DEV_ID\":\"C8:93:46:72:E7:59\",\"G\":\"0.0\",\"GX\":\"0.0\",\"GY\":\"0.0\",\"GZ\":\"0.0\",\"H\":\"55\",\"HCHO\":\"0.051\",\"LIGHT\":\"0\",\"PM25\":\"53\",\"T\":\"28\",\"TIME\":\"2018-09-07 17:40:40\",\"VERSION\":\"V4.0\"},{\"DEV_ID\":\"C8:93:46:72:E7:59\",\"G\":\"0.0\",\"GX\":\"0.0\",\"GY\":\"0.0\",\"GZ\":\"0.0\",\"H\":\"55\",\"HCHO\":\"0.053\",\"LIGHT\":\"0\",\"PM25\":\"53\",\"T\":\"28\",\"TIME\":\"2018-09-07 17:40:10\",\"VERSION\":\"V4.0\"},{\"DEV_ID\":\"C8:93:46:72:E7:59\",\"G\":\"0.0\",\"GX\":\"0.0\",\"GY\":\"0.0\",\"GZ\":\"0.0\",\"H\":\"55\",\"HCHO\":\"0.053\",\"LIGHT\":\"0\",\"PM25\":\"52\",\"T\":\"28\",\"TIME\":\"2018-09-07 17:39:39\",\"VERSION\":\"V4.0\"},{\"DEV_ID\":\"C8:93:46:72:E7:59\",\"G\":\"0.0\",\"GX\":\"0.0\",\"GY\":\"0.0\",\"GZ\":\"0.0\",\"H\":\"54\",\"HCHO\":\"0.046\",\"LIGHT\":\"0\",\"PM25\":\"57\",\"T\":\"28\",\"TIME\":\"2018-09-07 17:39:09\",\"VERSION\":\"V4.0\"},{\"DEV_ID\":\"C8:93:46:72:E7:59\",\"G\":\"0.0\",\"GX\":\"0.0\",\"GY\":\"0.0\",\"GZ\":\"0.0\",\"H\":\"53\",\"HCHO\":\"0.042\",\"LIGHT\":\"0\",\"PM25\":\"55\",\"T\":\"28\",\"TIME\":\"2018-09-07 17:38:39\",\"VERSION\":\"V4.0\"},{\"DEV_ID\":\"C8:93:46:72:E7:59\",\"G\":\"0.0\",\"GX\":\"0.0\",\"GY\":\"0.0\",\"GZ\":\"0.0\",\"H\":\"53\",\"HCHO\":\"0.044\",\"LIGHT\":\"0\",\"PM25\":\"52\",\"T\":\"28\",\"TIME\":\"2018-09-07 17:38:09\",\"VERSION\":\"V4.0\"}]";
            //List<WanWuYunData> entityListtemp= JsonHelper.JonsToList<WanWuYunData>(testData);
        }
Exemple #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         string sql = " select * from t_statistic where 1=1 and UPDATE_TIME is not null  ";
         if (MaxRecord != "")
         {
             sql = sql + " and UPDATE_TIME>'{0}' ";
         }
         sql = string.Format(sql, MaxRecord);
         DataTable dt = MySqlHelper.Query(sql).Tables[0];
         SqlBulkCopyInsert(ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString, "t_statistic", dt, out string message);
         this.label1.Text = DateTime.Now.ToString() + message;
         TXTLogHelper.LogBackup(DateTime.Now.ToString() + "手动同步" + message);
     }
     catch (Exception ex)
     {
         TXTLogHelper.LogBackup(DateTime.Now.ToString() + "手动同步出错" + ex.Message);
     }
 }
Exemple #3
0
        //调用html模板发送邮件通知
        private void SendMail(string email, string name, string date, string table1, string table2, string level, string qianzhui)
        {
            string mailFrom      = MailHelper.MailServerFrom;
            string mailTo        = string.Empty;
            string mailSubject   = string.Empty;
            string mailBody      = string.Empty;
            string mailAttch     = string.Empty;
            string mailCode      = MailHelper.MailPassword;
            string mailPriority  = string.Empty;
            string mailCC        = string.Empty;
            string resultMessage = "";

            if (!string.IsNullOrEmpty(email))
            {
                mailTo      = email;
                mailSubject = "GP12遏制产品待处理信息通知";
                try
                {
                    string templetpath        = System.Environment.CurrentDirectory + "/MailTemplate/test.html";
                    NameValueCollection myCol = new NameValueCollection();
                    myCol.Add("ename", name);
                    myCol.Add("date", date);
                    myCol.Add("table1", table1);
                    myCol.Add("table2", table2);
                    myCol.Add("level", level);
                    myCol.Add("qianzhui", qianzhui);
                    //ConfigurationManager.ConnectionStrings["S1"].ToString()
                    //myCol.Add("link", System.Configuration.ConfigurationManager.AppSettings["rootUrl"]);
                    mailBody = TemplateHelper.BulidByFile(templetpath, myCol);
                    MailHelper.SendNetMail(mailFrom, mailTo, mailSubject, mailBody, mailAttch, mailCode, mailPriority, mailCC, out resultMessage);
                    TXTLogHelper.LogBackup(resultMessage);
                }
                catch (Exception ex)
                {
                }
            }
        }