public async void ReadRealDevice(Scada.Model.IO_SERVER server, Scada.Model.IO_COMMUNICATION communication, Scada.Model.IO_DEVICE device)
        {
            try
            {
                if (InfluxDbManager != null)
                {
                    var result = await InfluxDbManager.DbQuery_Real(server, communication, device);

                    if (result != null && result.Count() > 0)
                    {
                        Serie s = result.Last();
                        if (s != null && s.Values.Count > 0)
                        {
                            for (int i = 0; i < device.IOParas.Count; i++)
                            {
                                device.IOParas[i].IORealData = new Scada.IOStructure.IOData();
                            }
                            var values = s.Values[s.Values.Count - 1];
                            for (int i = 0; i < s.Columns.Count; i++)
                            {
                                if (s.Columns[i].Split('_')[0].ToLower() == "field")
                                {
                                    string paraname          = s.Columns[i].Replace("field_", "").Replace("_value", "").Replace("_datetime", "").Replace("_qualitystamp", "");
                                    Scada.Model.IO_PARA para = device.IOParas.Find(x => x.IO_NAME.Trim().ToLower() == paraname.ToLower());
                                    if (para != null)
                                    {
                                        int length = s.Columns[i].Split('_').Length;
                                        if (s.Columns[i].Split('_')[length - 1].ToLower() == "value")
                                        {
                                            para.IORealData.ParaValue = InfluxDbManager.GetInfluxdbValue(values[i]).ToString();
                                        }
                                        if (s.Columns[i].Split('_')[length - 1].ToLower() == "datetime")
                                        {
                                            para.IORealData.Date = Convert.ToDateTime(InfluxDbManager.GetInfluxdbValue(values[i]).ToString());
                                        }
                                        if (s.Columns[i].Split('_')[length - 1].ToLower() == "qualitystamp")
                                        {
                                            para.IORealData.QualityStamp = (QualityStamp)Enum.Parse(typeof(QualityStamp), InfluxDbManager.GetInfluxdbValue(values[i]).ToString());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception emx)
            {
                AddLog("ERROR=50001" + emx.Message);
            }
        }
        private async void ReadAlarmHistory()
        {
            try
            {
                if (Device == null)
                {
                    return;
                }
                this.listView.Items.Clear();
                IO_DEVICE copyDevice = this.Device.Copy();
                //获取读取历史数据
                InfluxDBHistoryData resultData = await IOCenterManager.QueryFormManager.ReadHistoryAlarmDevice(this.Server, this.Communication, copyDevice, this.search.StartDate, this.search.EndDate, this.search.AlarmType, this.search.AlarmLevel, this.ucPagerControl.PageSize, this.ucPagerControl.PageIndex);

                if (resultData == null || !resultData.ReturnResult)
                {
                    if (resultData != null)
                    {
                        FrmDialog.ShowDialog(this, resultData.Msg);
                    }
                    else
                    {
                        FrmDialog.ShowDialog(this, "查询失败");
                    }

                    return;
                }
                //设置页眉控件参数
                this.ucPagerControl.PageCount   = resultData.PageCount;
                this.ucPagerControl.RecordCount = resultData.RecordCount;
                //删除曲线


                //循环读取每个历史数据
                //首先构造ListColumn



                if (resultData.Seres.Count() > 0)
                {
                    //field_io_alarm_date
                    //field_io_alarm_disposalidea
                    //field_io_alarm_disposaluser
                    //field_io_alarm_level
                    //field_io_alarm_type
                    //field_io_alarm_value
                    //field_io_label
                    //field_io_name
                    Serie s = resultData.Seres.ElementAt(0);
                    //获取首个时间

                    for (int i = 0; i < s.Values.Count; i++)
                    {
                        int    timeindex = s.Columns.IndexOf("time");
                        string time      = UnixDateTimeConvert.ConvertDateTimeInt(Convert.ToDateTime(InfluxDbManager.GetInfluxdbValue(s.Values[i][timeindex]))).ToString();
                        int    dateindex = s.Columns.IndexOf("field_io_alarm_date");

                        string       date          = InfluxDbManager.GetInfluxdbValue(s.Values[i][dateindex]);
                        ListViewItem lvi           = new ListViewItem(time);
                        int          io_name_index = s.Columns.IndexOf("field_io_name");
                        if (io_name_index >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][io_name_index]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }
                        ///
                        int io_name_label = s.Columns.IndexOf("field_io_label");
                        if (io_name_label >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][io_name_label]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }

                        ///
                        int io_alarm_value = s.Columns.IndexOf("field_io_alarm_value");
                        if (io_alarm_value >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][io_alarm_value]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }

                        int io_alarm_date = s.Columns.IndexOf("field_io_alarm_date");
                        if (io_alarm_date >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][io_alarm_date]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }

                        int io_alarm_level = s.Columns.IndexOf("field_io_alarm_level");
                        if (io_alarm_level >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][io_alarm_level]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }

                        int io_alarm_type = s.Columns.IndexOf("field_io_alarm_type");
                        if (io_alarm_type >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][io_alarm_type]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }

                        int io_alarm_disposalidea = s.Columns.IndexOf("field_io_alarm_disposalidea");
                        if (io_alarm_disposalidea >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][io_alarm_disposalidea]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }

                        int io_alarm_disposaluser = s.Columns.IndexOf("field_io_alarm_disposaluser");
                        if (io_alarm_disposaluser >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][io_alarm_disposaluser]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }
                        listView.Items.Add(lvi);
                    }
                }
            }
            catch (Exception ex)
            {
                IOCenterManager.QueryFormManager.DisplyException(ex);
            }
        }
        private async void ReadAlarmConfigHistory()
        {
            try
            {
                if (Device == null)
                {
                    return;
                }
                this.listViewSendCommand.Clear();
                IO_DEVICE copyDevice = this.Device.Copy();
                //获取读取历史数据
                InfluxDBHistoryData resultData = await IOCenterManager.QueryFormManager.ReadHistoryAlarmConfigsDevice(this.Server, this.Communication, copyDevice, this.search.StartDate, this.search.EndDate, this.ucPagerControl.PageSize, this.ucPagerControl.PageIndex);

                if (resultData == null || !resultData.ReturnResult)
                {
                    if (resultData != null)
                    {
                        FrmDialog.ShowDialog(this, resultData.Msg);
                    }
                    else
                    {
                        FrmDialog.ShowDialog(this, "查询失败");
                    }

                    return;
                }
                //设置页眉控件参数
                this.ucPagerControl.PageCount   = resultData.PageCount;
                this.ucPagerControl.RecordCount = resultData.RecordCount;
                //删除曲线


                if (resultData.Seres.Count() > 0)
                {
                    Serie s = resultData.Seres.ElementAt(0);
                    //获取首个时间

                    for (int i = 0; i < s.Values.Count; i++)
                    {
                        int    timeindex         = s.Columns.IndexOf("time");
                        string time              = UnixDateTimeConvert.ConvertDateTimeInt(Convert.ToDateTime(InfluxDbManager.GetInfluxdbValue(s.Values[i][timeindex]))).ToString();
                        int    field_update_date = s.Columns.IndexOf("field_update_date");

                        string       date = InfluxDbManager.GetInfluxdbValue(s.Values[i][field_update_date]);
                        ListViewItem lvi  = new ListViewItem(date);


                        int field_update_result = s.Columns.IndexOf("field_update_result");
                        if (field_update_result >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_update_result]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }

                        int field_update_uid = s.Columns.IndexOf("field_update_uid");
                        if (field_update_uid >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_update_uid]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }


                        int field_io_name = s.Columns.IndexOf("field_io_name");
                        if (field_io_name >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_name]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }
                        ///
                        int field_io_label = s.Columns.IndexOf("field_io_label");
                        if (field_io_label >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_label]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }



                        int field_io_condition = s.Columns.IndexOf("field_io_condition");
                        if (field_io_condition >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_condition]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }



                        int field_io_enable_maxmax = s.Columns.IndexOf("field_io_enable_maxmax");
                        if (field_io_enable_maxmax >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_enable_maxmax]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }
                        int field_io_maxmax_type = s.Columns.IndexOf("field_io_maxmax_type");
                        if (field_io_maxmax_type >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_maxmax_type]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }
                        int field_io_maxmax_value = s.Columns.IndexOf("field_io_maxmax_value");
                        if (field_io_maxmax_value >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_maxmax_value]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }

                        int field_io_enable_max = s.Columns.IndexOf("field_io_enable_max");
                        if (field_io_enable_max >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_enable_max]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }
                        int field_io_max_type = s.Columns.IndexOf("field_io_max_type");
                        if (field_io_max_type >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_max_type]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }
                        int field_io_max_value = s.Columns.IndexOf("field_io_max_value");
                        if (field_io_max_value >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_max_value]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }



                        int field_io_enable_min = s.Columns.IndexOf("field_io_enable_min");
                        if (field_io_enable_min >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_enable_min]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }

                        int field_io_min_type = s.Columns.IndexOf("field_io_min_type");
                        if (field_io_min_type >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_min_type]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }
                        int field_io_min_value = s.Columns.IndexOf("field_io_min_value");
                        if (field_io_min_value >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_min_value]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }



                        int field_io_enable_minmin = s.Columns.IndexOf("field_io_enable_minmin");
                        if (field_io_enable_minmin >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_enable_minmin]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }

                        int field_io_minmin_type = s.Columns.IndexOf("field_io_minmin_type");
                        if (field_io_minmin_type >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_minmin_type]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }
                        int field_io_minmin_value = s.Columns.IndexOf("field_io_minmin_value");
                        if (field_io_minmin_value >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_io_minmin_value]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }



                        this.listViewSendCommand.Items.Add(lvi);
                    }
                }
            }
            catch (Exception ex)
            {
                IOCenterManager.QueryFormManager.DisplyException(ex);
            }
        }
Beispiel #4
0
        private async void ReadBackupHistory()
        {
            this.listView.Items.Clear();
            try
            {
                //获取读取历史数据
                InfluxDBHistoryData resultData = await IOCenterManager.QueryFormManager.ReadBackupHistory(this.ucPagerControl.PageSize, this.ucPagerControl.PageIndex);

                if (resultData == null || !resultData.ReturnResult)
                {
                    if (resultData != null)
                    {
                        FrmDialog.ShowDialog(this, resultData.Msg);
                    }
                    else
                    {
                        FrmDialog.ShowDialog(this, "查询失败");
                    }

                    return;
                }
                //设置页眉控件参数
                this.ucPagerControl.PageCount   = resultData.PageCount;
                this.ucPagerControl.RecordCount = resultData.RecordCount;

                if (resultData.Seres.Count() > 0)
                {
                    Serie s = resultData.Seres.ElementAt(0);
                    //获取首个时间

                    for (int i = 0; i < s.Values.Count; i++)
                    {
                        int    timeindex = s.Columns.IndexOf("time");
                        string time      = UnixDateTimeConvert.ConvertDateTimeInt(Convert.ToDateTime(InfluxDbManager.GetInfluxdbValue(s.Values[i][timeindex]))).ToString();
                        int    dateindex = s.Columns.IndexOf("field_backup_date");

                        string       date = InfluxDbManager.GetInfluxdbValue(s.Values[i][dateindex]);
                        ListViewItem lvi  = new ListViewItem(time);
                        int          field_backup_date = s.Columns.IndexOf("field_backup_date");
                        if (field_backup_date >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_backup_date]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }

                        int field_backup_path = s.Columns.IndexOf("field_backup_path");
                        if (field_backup_path >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_backup_path]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }
                        ///
                        int field_backup_file = s.Columns.IndexOf("field_backup_file");
                        if (field_backup_file >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_backup_file]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }

                        ///
                        int field_backup_result = s.Columns.IndexOf("field_backup_result");
                        if (field_backup_result >= 0)
                        {
                            lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][field_backup_result]));
                        }
                        else
                        {
                            lvi.SubItems.Add("");
                        }


                        listView.Items.Add(lvi);
                    }
                }
            }

            catch (Exception ex)
            {
                IOCenterManager.QueryFormManager.DisplyException(ex);
            }
        }
        private async void ReadHistory()
        {
            try
            {
                if (Device == null)
                {
                    return;
                }
                this.listView.Items.Clear();
                this.listView.Columns.Clear();
                IO_DEVICE copyDevice = this.Device.Copy();
                //构造查询语句
                string selected = "";


                for (int i = 0; i < copyDevice.IOParas.Count; i++)
                {
                    //只能统计模拟量的
                    if (Device.IOParas[i].IO_POINTTYPE == "模拟量")
                    {
                        selected += "," + this.search.MethType + "(field_" + copyDevice.IOParas[i].IO_NAME.ToLower() + "_value) as field_" + copyDevice.IOParas[i].IO_NAME.ToLower() + "_value";
                    }
                }
                if (selected != "")
                {
                    selected = selected.Remove(0, 1);
                }

                //获取读取历史数据
                InfluxDBHistoryData resultData = await IOCenterManager.QueryFormManager.ReadHistoryStaticsDevice(this.Server, this.Communication, copyDevice, this.search.StartDate, this.search.EndDate, this.ucPagerControl.PageSize, this.ucPagerControl.PageIndex, selected, search.TimeType);

                if (resultData == null || !resultData.ReturnResult)
                {
                    if (resultData != null)
                    {
                        FrmDialog.ShowDialog(this, resultData.Msg);
                    }
                    else
                    {
                        FrmDialog.ShowDialog(this, "查询失败");
                    }

                    return;
                }
                //设置页眉控件参数
                this.ucPagerControl.PageCount   = resultData.PageCount;
                this.ucPagerControl.RecordCount = resultData.RecordCount;
                //删除曲线
                InitChart();

                //循环读取每个历史数据
                //首先构造ListColumn

                ColumnHeader listColumn = new ColumnHeader();
                listColumn.Name  = "field_device_date";
                listColumn.Text  = "采集时间";
                listColumn.Width = 200;
                listColumn.Tag   = null;
                this.listView.Columns.Add(listColumn);
                //每个参数都创建一列,-9999表示质量戳是坏的值
                for (int i = 0; i < copyDevice.IOParas.Count; i++)
                {
                    if (Device.IOParas[i].IO_POINTTYPE == "模拟量")
                    {
                        listColumn       = new ColumnHeader();
                        listColumn.Name  = copyDevice.IOParas[i].ToString() + "_value";
                        listColumn.Tag   = copyDevice.IOParas[i];
                        listColumn.Text  = copyDevice.IOParas[i].IO_LABEL;
                        listColumn.Width = 100;
                        this.listView.Columns.Add(listColumn);

                        //创建曲线
                        IOParaSeries series = new IOParaSeries(this.Server, this.Communication, copyDevice, copyDevice.IOParas[i]);
                        IOSeries.Add(series);
                    }
                }
                if (resultData.Seres.Count() > 0)
                {
                    Serie s = resultData.Seres.ElementAt(0);
                    //获取首个时间
                    int dateindex = s.Columns.IndexOf("time");
                    if (dateindex >= 0)
                    {
                        for (int i = 0; i < s.Values.Count; i++)
                        {
                            string date = InfluxDbManager.GetInfluxdbValue(s.Values[i][dateindex]);


                            ListViewItem lvi = new ListViewItem(date);
                            for (int c = 0; c < copyDevice.IOParas.Count; c++)
                            {
                                int paraindex = s.Columns.IndexOf("field_" + copyDevice.IOParas[c].IO_NAME.ToLower() + "_value");
                                if (paraindex >= 0)
                                {
                                    IOParaSeries series = IOSeries.Find(x => x.Name.Trim() == copyDevice.IOParas[c].IO_NAME.Trim());

                                    double yValue = -9999;
                                    double.TryParse(InfluxDbManager.GetInfluxdbValue(s.Values[i][paraindex]), out yValue);
                                    string xValue = date;

                                    lvi.SubItems.Add(InfluxDbManager.GetInfluxdbValue(s.Values[i][paraindex]).ToString());

                                    if (series != null)
                                    {
                                        int pointIndex = series.Points.AddXY(date, new object[1] {
                                            yValue
                                        });
                                        if (xValue != "")
                                        {
                                            if (yValue == -9999)
                                            {
                                                series.Points[pointIndex].IsEmpty = true;
                                                series.Points[pointIndex].ToolTip = "坏数据";
                                            }
                                            else
                                            {
                                                series.Points[pointIndex].ToolTip = "时间=" + date + ",采集值=" + yValue;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    lvi.SubItems.Add("");
                                }
                            }
                            listView.Items.Add(lvi);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                IOCenterManager.QueryFormManager.DisplyException(ex);
            }
        }