Ejemplo n.º 1
0
        void GetListS()
        {
            // < sensor model = "MXN820" uid = "81817F01E524226D" nodeid = "1"  portid = "0" comment = "状态包" />
            string dateTime   = DateTime.Now.AddDays(-60).ToString("yyyy-MM-dd HH:mm");
            string dataSource = ConfigurationManager.AppSettings["dbPath"];

            foreach (SensorModel model in ConfigData.SensorModelRoot.SensorModels)
            {
                string sql = string.Format("SELECT distinct uid,nodeid,port FROM {0}_result WHERE time > '{1}'", model.Sname, dateTime);
                try
                {
                    DataTable dt = SqlLiteHelper.ExecuteReader(dataSource, sql);
                    foreach (DataRow row in dt.Rows)
                    {
                        Sensor ss = new Sensor();
                        ss.Comment  = "";
                        ss.ModelKey = model.Name;
                        ss.NodeId   = row["nodeid"].ToString();
                        ss.PortId   = row["port"].ToString();
                        ss.Uid      = row["uid"].ToString();
                        if (ConfigData.allSensors.Exists(sensor => sensor.Uid == ss.Uid && sensor.NodeId == ss.NodeId && sensor.PortId == ss.PortId))
                        {
                            continue;
                        }
                        listS.Add(ss);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        void SelectData(Sensor sensor)
        {
            //DataTable dt= SqlLiteHelper.ExecuteReader("SELECT * FROM SCity_MX8100_result");
            string sql = string.Format("SELECT {0} FROM {1}_result WHERE time < '{2}' and time >'{3}' and nodeid = {4} ", sensor.HisColumnStr, sensor.Model.Sname, dateTimePickerRetrieveEnd.Value.ToString("yyyy-MM-dd HH:mm"), dateTimePickerRetrieveBegin.Value.ToString("yyyy-MM-dd HH:mm"), sensor.NodeId);

            try
            {
                DataTable dt = SqlLiteHelper.ExecuteReader(ConfigurationManager.AppSettings["dbPath"], sql);
                var       c1 = dt.Columns.Add("传感器类型");
                var       c2 = dt.Columns.Add("传感器位置");
                var       c3 = dt.Columns.Add("备注");
                foreach (DataRow row in dt.Rows)
                {
                    row[c1] = sensor.Model.Title;
                    row[c2] = sensor.GroupName;
                    row[c3] = sensor.Comment;
                }
                customDataView1.DataSource = dt;
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2147467259)
                {
                    MessageBox.Show(string.Format("{0}({1})暂无数据", sensor.Model.Title, sensor.Comment), "提醒", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    MessageBox.Show(ex.Message, "提醒", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
        }
Ejemplo n.º 3
0
        private void 最近三天ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            cdv3.DataSource = null;
            //string timeStrS = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string timeStrE = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd HH:mm:ss");

            dt3             = SqlLiteHelper.ExecuteReader(db, string.Format("SELECT * FROM record where time > '{0}'", timeStrE));
            cdv3.DataSource = dt3;
            cdv3.Columns["time"].HeaderText      = "时间";
            cdv3.Columns["field"].HeaderText     = "监测项";
            cdv3.Columns["groupname"].HeaderText = "位置";
            cdv3.Columns["comment"].HeaderText   = "备注";
            cdv3.Columns["state"].HeaderText     = "状态";
            cdv3.BringToFront();
        }
Ejemplo n.º 4
0
        public void Init()
        {
            db = Path.Combine(Utils.GetUserPath(), "alarm.db");
            string sql = "SELECT COUNT(*) FROM sqlite_master where type = 'table' and name = 'record'";
            object obj = SqlLiteHelper.ExecuteScalar(db, sql);

            if (Convert.ToInt32(obj) == 0)
            {
                string createSql = "CREATE TABLE record(time varchar(50),field varchar(50),groupname varchar(50),comment varchar(50),state varchar(50))";
                int    res       = SqlLiteHelper.ExecuteNonQuery(db, createSql);
            }

            foreach (Field field in ConfigData.allFields)
            {
                field.StateChanged += Field_StateChanged;
            }

            cdv3 = new CustomDataView();
            cdv3.ContextMenuStrip = contextMenuStrip1;
            cdv3.Font             = new Font("微软雅黑", 15);
            cdv3.Parent           = this;
            cdv3.Dock             = DockStyle.Fill;
            cdv3.CellFormatting  += Cdv_CellFormatting;

            cdv = new CustomDataView();
            cdv.ContextMenuStrip = contextMenuStrip1;
            cdv.Font             = new Font("微软雅黑", 15);
            cdv.Parent           = this;
            cdv.Dock             = DockStyle.Fill;
            dt             = SqlLiteHelper.ExecuteReader(db, "SELECT * FROM record");
            cdv.DataSource = dt;
            cdv.Columns["time"].HeaderText      = "时间";
            cdv.Columns["field"].HeaderText     = "监测项";
            cdv.Columns["groupname"].HeaderText = "位置";
            cdv.Columns["comment"].HeaderText   = "备注";
            cdv.Columns["state"].HeaderText     = "状态";
            cdv.CellFormatting += Cdv_CellFormatting;
            cdv.BringToFront();
        }