Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine(@"Hello World!");
            Console.ReadLine();

            try
            {
                string dateTimeStr   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                string deviceTypeStr = "004";
                string sareaIdStr    = "145";
                string spotIdStr     = "001";
                string deviceIdStr   = "002";
                float  alarmValue    = 11.2F;
                string alarmMsgStr   = "凤城服务区 服务大厅 温度异常(低于下限)";
                //string insertStr = @"INSERT INTO " + "temperature_alarm_record"
                //					+ @"(date_time, sarea_id, spot_id, device_type, device_id, alarm_message, value_01"
                //					+ @") VALUES('" + dateTimeStr + @"'," + "888" + @", " + "123" + @", '"
                //					+ @"004" + @"', '" + @"001" + @"', '" + @"中文字符串" + @"', " + "17" + @")";

                string insertStr = @"INSERT INTO " + "temperature_alarm_record"
                                   + @"(date_time, sarea_id, spot_id, device_type, device_id, alarm_message, value_01"
                                   + @") VALUES('" + dateTimeStr + @"','" + sareaIdStr + @"', '" + spotIdStr + @"', '"
                                   + deviceTypeStr + @"', '" + deviceIdStr + @"', '" + alarmMsgStr + @"', " + alarmValue.ToString() + @")";

                DBConnectMySQL mysql_object = new DBConnectMySQL();
                mysql_object.ExecuteMySqlCommand(insertStr);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.WriteLine(@"End!");
            Console.ReadLine();

            return;

            string requestStr = @"http://10.62.72.116/nvc-cgi/admin/vca.cgi?action=list&group=VCA.Ch0.Ct0.count";
            int    idx        = requestStr.LastIndexOf("=");

            if (-1 == idx)
            {
                return;
            }
            string findKey   = requestStr.Substring(idx + 1).Trim() + "=";
            string rdStr     = "";
            string reportStr = "";

            HttpWebRequest hwreq     = null;
            WebResponse    hwrsp     = null;
            Stream         rspStream = null;
            StreamReader   sr        = null;

            try
            {
                hwreq     = (HttpWebRequest)WebRequest.Create(requestStr);
                hwrsp     = hwreq.GetResponse();
                rspStream = hwrsp.GetResponseStream();
                sr        = new StreamReader(rspStream);
                while (null != (rdStr = sr.ReadLine()))
                {
                    // Console.WriteLine(rdStr);
                    if (-1 != (idx = rdStr.IndexOf(findKey)))
                    {
                        string subStr = rdStr.Substring(idx + findKey.Length).Trim();
                        int    value;
                        if (int.TryParse(subStr, out value))
                        {
                            reportStr = ", " + subStr;
                            Console.WriteLine("reportStr = \"" + reportStr + "\"");
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                if (null != hwrsp)
                {
                    hwrsp.Close();
                }
                if (null != rspStream)
                {
                    rspStream.Close();
                }
                if (null != sr)
                {
                    sr.Close();
                }
            }
            //string resultStr = GetReportString(outStr, requestStr);
            //Console.WriteLine(resultStr);

            Console.ReadLine();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine(@"Hello World!");
            Console.ReadLine();

            try
            {
                string dateTimeStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                string deviceTypeStr = "004";
                string sareaIdStr = "145";
                string spotIdStr = "001";
                string deviceIdStr = "002";
                float alarmValue = 11.2F;
                string alarmMsgStr = "凤城服务区 服务大厅 温度异常(低于下限)";
                //string insertStr = @"INSERT INTO " + "temperature_alarm_record"
                //					+ @"(date_time, sarea_id, spot_id, device_type, device_id, alarm_message, value_01"
                //					+ @") VALUES('" + dateTimeStr + @"'," + "888" + @", " + "123" + @", '"
                //					+ @"004" + @"', '" + @"001" + @"', '" + @"中文字符串" + @"', " + "17" + @")";

                string insertStr = @"INSERT INTO " + "temperature_alarm_record"
                                + @"(date_time, sarea_id, spot_id, device_type, device_id, alarm_message, value_01"
                                + @") VALUES('" + dateTimeStr + @"','" + sareaIdStr + @"', '" + spotIdStr + @"', '"
                                + deviceTypeStr + @"', '" + deviceIdStr + @"', '" + alarmMsgStr + @"', " + alarmValue.ToString() + @")";

                DBConnectMySQL mysql_object = new DBConnectMySQL();
                mysql_object.ExecuteMySqlCommand(insertStr);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.WriteLine(@"End!");
            Console.ReadLine();

            return;
            string requestStr = @"http://10.62.72.116/nvc-cgi/admin/vca.cgi?action=list&group=VCA.Ch0.Ct0.count";
            int idx = requestStr.LastIndexOf("=");
            if (-1 == idx)
            {
                return;
            }
            string findKey = requestStr.Substring(idx + 1).Trim() + "=";
            string rdStr = "";
            string reportStr = "";

            HttpWebRequest hwreq = null;
            WebResponse hwrsp = null;
            Stream rspStream = null;
            StreamReader sr = null;
            try
            {
                hwreq = (HttpWebRequest)WebRequest.Create(requestStr);
                hwrsp = hwreq.GetResponse();
                rspStream = hwrsp.GetResponseStream();
                sr = new StreamReader(rspStream);
                while ( null != (rdStr = sr.ReadLine()) )
                {
                    // Console.WriteLine(rdStr);
                    if ( -1 != (idx = rdStr.IndexOf(findKey)) )
                    {
                        string subStr = rdStr.Substring(idx + findKey.Length).Trim();
                        int value;
                        if (int.TryParse(subStr, out value))
                        {
                            reportStr = ", " + subStr;
                            Console.WriteLine("reportStr = \"" + reportStr + "\"");
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                if (null != hwrsp)
                {
                    hwrsp.Close();
                }
                if (null != rspStream)
                {
                    rspStream.Close();
                }
                if (null != sr)
                {
                    sr.Close();
                }
            }
            //string resultStr = GetReportString(outStr, requestStr);
            //Console.WriteLine(resultStr);

            Console.ReadLine();
        }