public ElectricUserControl(ElectricConfig config, MysqlMethod mysql, List <AbsProtocol> electricAbsprocotols)
        {
            InitializeComponent();
            MysqlMethod                  = mysql;
            ElectricConfig               = config;
            ElectricAbsProtocols         = electricAbsprocotols;
            ElectricgroupControl.Text    = ElectricConfig.DeviceName;
            ThreePhaseElectricMeter_Logs = MysqlMethod.Search_ThreePhaseElectricMeter_Log($"{TTime:yyyyMMdd000000}", $"{TTime:yyyyMMdd235959}", ElectricConfig.GatewayIndex, ElectricConfig.DeviceIndex);
            LinechartControl.DataSource  = ThreePhaseElectricMeter_Logs;
            Series series = new Series($"{config.DeviceName}", viewType: ViewType.Line);

            series.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:HH:mm:ss} " + "\n" + "瞬間用電:{V:0.00}kW";
            series.LegendTextPattern     = "{A}";
            series.ArgumentDataMember    = "ttimen";
            series.ValueDataMembers.AddRange(new string[] { "kw" });
            series.LabelsVisibility = DefaultBoolean.False;
            LinechartControl.Series.Add(series);
            XYDiagram diagram = (XYDiagram)LinechartControl.Diagram;

            if (diagram != null)
            {
                diagram.EnableAxisXZooming   = true;                                             //放大縮小
                diagram.EnableAxisXScrolling = true;                                             //拖曳
                diagram.AxisX.DateTimeScaleOptions.MeasureUnit   = DateTimeMeasureUnit.Minute;   // 顯示設定
                diagram.AxisX.DateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Minute; // 刻度設定
                diagram.AxisX.Label.TextPattern              = "{A:HH:mm}";                      //X軸顯示
                diagram.AxisX.WholeRange.SideMarginsValue    = 0;                                //不需要邊寬
                diagram.AxisY.WholeRange.AlwaysShowZeroLevel = false;
            }
            LinechartControl.CrosshairOptions.ShowArgumentLabels  = false; //是否顯示Y軸垂直線
            LinechartControl.CrosshairOptions.ShowArgumentLine    = false; //是否顯示Y軸垂直線
            LinechartControl.CrosshairOptions.ShowCrosshairLabels = true;  //是否顯示Y軸垂直線
        }
        public override void TextChange()
        {
            TTime = DateTime.Now;
            ThreePhaseElectricMeter_Logs = MysqlMethod.Search_ThreePhaseElectricMeter_Log($"{TTime:yyyyMMdd000000}", $"{TTime:yyyyMMdd235959}", ElectricConfig.GatewayIndex, ElectricConfig.DeviceIndex);
            LinechartControl.DataSource  = ThreePhaseElectricMeter_Logs;
            LinechartControl.Refresh();
            var data = ElectricAbsProtocols.Single(g => g.GatewayIndex == ElectricConfig.GatewayIndex & g.DeviceIndex == ElectricConfig.DeviceIndex);

            if (data.ConnectFlag)
            {
                ElectricTypeEnum electricTypeEnum = (ElectricTypeEnum)data.ElectricTypeEnum;
                switch (electricTypeEnum)
                {
                case ElectricTypeEnum.BAW_4C:
                {
                    ThreePhaseElectricMeterData threePhaseElectric = (ThreePhaseElectricMeterData)data;
                    rsvlabelControl.Text   = threePhaseElectric.rsv.ToString("F2");
                    stvlabelControl.Text   = threePhaseElectric.stv.ToString("F2");
                    trvlabelControl.Text   = threePhaseElectric.trv.ToString("F2");
                    ralabelControl.Text    = threePhaseElectric.ra.ToString("F2");
                    salabelControl.Text    = threePhaseElectric.sa.ToString("F2");
                    talabelControl.Text    = threePhaseElectric.ta.ToString("F2");
                    pfelabelControl.Text   = threePhaseElectric.pfe.ToString("F3");
                    hzlabelControl.Text    = threePhaseElectric.hz.ToString("F2");
                    kwlabelControl.Text    = threePhaseElectric.kw.ToString("F2");
                    kwhlabelControl.Text   = threePhaseElectric.kwh.ToString("F2");
                    kvarlabelControl.Text  = threePhaseElectric.kvar.ToString("F2");
                    kvarhlabelControl.Text = threePhaseElectric.kvarh.ToString("F2");
                }
                break;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 查詢按鈕
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ShearsimpleButton_Click(object sender, EventArgs e)
        {
            if (DeviceCheckedcomboBoxEdit.Text != "" && ValuecomboBoxEdit.Text != "" && StartdateEdit.Text != "" && EnddateEdit.Text != null && Convert.ToDateTime(StartdateEdit.EditValue) <= Convert.ToDateTime(EnddateEdit.EditValue))
            {
                if (LinechartControl.Series.Count >= 0)
                {
                    LinechartControl.Series.Clear();
                }
                if (gridView1.Columns.Count > 0)
                {
                    gridView1.Columns.Clear();
                }
                string        starttime  = ((DateTime)StartdateEdit.EditValue).ToString("yyyyMMdd000000"); //起始時間
                string        endtime    = ((DateTime)EnddateEdit.EditValue).ToString("yyyyMMdd235959");   //結束時間
                string        Tstarttime = ((DateTime)StartdateEdit.EditValue).ToString("yyyyMMdd");       //起始時間
                string        Tendtime   = ((DateTime)EnddateEdit.EditValue).ToString("yyyyMMdd");         //結束時間
                List <Series> Lineseries = new List <Series>();                                            //曲線圖用
                ThreePhaseElectricMeter_Logs = new List <ThreePhaseElectricMeter_Log>();                   //報表用
                ElectricTotals = new List <ElectricTotal>();
                ElectricSearchTypeEnum electricSearchTypeEnum = (ElectricSearchTypeEnum)ValuecomboBoxEdit.SelectedIndex;
                for (int i = 0; i < DeviceCheckedcomboBoxEdit.Properties.Items.Count; i++)
                {
                    if (DeviceCheckedcomboBoxEdit.Properties.Items[i].CheckState == CheckState.Checked)
                    {
                        ElectricConfig = (ElectricConfig)DeviceCheckedcomboBoxEdit.Properties.Items[i].Tag;
                        var data = MysqlMethod.Search_ThreePhaseElectricMeter_Log(starttime, endtime, ElectricConfig.GatewayIndex, ElectricConfig.DeviceIndex);
                        var ElectricTotaldata = MysqlMethod.Search_ElectricTotal(Tstarttime, Tendtime, ElectricConfig.GatewayIndex, ElectricConfig.DeviceIndex);
                        #region 報表資料整理
                        ThreePhaseElectricMeter_Logs.AddRange(data);
                        ElectricTotals.AddRange(ElectricTotaldata);
                        #endregion
                        #region 曲線圖資料整理
                        switch (electricSearchTypeEnum)
                        {
                        case ElectricSearchTypeEnum.Voltage:
                        {
                            Series series1 = new Series($"{ElectricConfig.DeviceName} - R相電壓", viewType: ViewType.Line);
                            series1.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:yyyy-MM-dd HH:mm:ss} " + "\n" + "數值:{V:0.00}V";
                            series1.LegendTextPattern     = "{A}";
                            series1.ArgumentDataMember    = "ttimen";
                            series1.LabelsVisibility      = DefaultBoolean.False;
                            series1.ValueDataMembers.AddRange(new string[] { "rsv" });
                            Lineseries.Add(series1);
                            Series series2 = new Series($"{ElectricConfig.DeviceName} - S相電壓", viewType: ViewType.Line);
                            series2.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:yyyy-MM-dd HH:mm:ss} " + "\n" + "數值:{V:0.00}V";
                            series2.LegendTextPattern     = "{A}";
                            series2.ArgumentDataMember    = "ttimen";
                            series2.LabelsVisibility      = DefaultBoolean.False;
                            series2.ValueDataMembers.AddRange(new string[] { "stv" });
                            Lineseries.Add(series2);
                            Series series3 = new Series($"{ElectricConfig.DeviceName} - T相電壓", viewType: ViewType.Line);
                            series3.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:yyyy-MM-dd HH:mm:ss} " + "\n" + "數值:{V:0.00}V";
                            series3.LegendTextPattern     = "{A}";
                            series3.ArgumentDataMember    = "ttimen";
                            series3.LabelsVisibility      = DefaultBoolean.False;
                            series3.ValueDataMembers.AddRange(new string[] { "trv" });
                            Lineseries.Add(series3);
                        }
                        break;

                        case ElectricSearchTypeEnum.Current:
                        {
                            Series series1 = new Series($"{ElectricConfig.DeviceName}- R相電流", viewType: ViewType.Line);
                            series1.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:yyyy-MM-dd HH:mm:ss} " + "\n" + "數值:{V:0.00}A";
                            series1.LegendTextPattern     = "{A}";
                            series1.ArgumentDataMember    = "ttimen";
                            series1.LabelsVisibility      = DefaultBoolean.False;
                            series1.ValueDataMembers.AddRange(new string[] { "ra" });
                            Lineseries.Add(series1);
                            Series series2 = new Series($"{ElectricConfig.DeviceName} - S相電流", viewType: ViewType.Line);
                            series2.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:yyyy-MM-dd HH:mm:ss} " + "\n" + "數值:{V:0.00}A";
                            series2.LegendTextPattern     = "{A}";
                            series2.ArgumentDataMember    = "ttimen";
                            series2.LabelsVisibility      = DefaultBoolean.False;
                            series2.ValueDataMembers.AddRange(new string[] { "sa" });
                            Lineseries.Add(series2);
                            Series series3 = new Series($"{ElectricConfig.DeviceName} - T相電流", viewType: ViewType.Line);
                            series3.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:yyyy-MM-dd HH:mm:ss} " + "\n" + "數值:{V:0.00}A";
                            series3.LegendTextPattern     = "{A}";
                            series3.ArgumentDataMember    = "ttimen";
                            series3.LabelsVisibility      = DefaultBoolean.False;
                            series3.ValueDataMembers.AddRange(new string[] { "ta" });
                            Lineseries.Add(series3);
                        }
                        break;

                        case ElectricSearchTypeEnum.kW:
                        {
                            Series series1 = new Series($"{ElectricConfig.DeviceName} - 瞬間功率", viewType: ViewType.Line);
                            series1.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:yyyy-MM-dd HH:mm:ss} " + "\n" + "數值:{V:0.00}kW";
                            series1.LegendTextPattern     = "{A}";
                            series1.ArgumentDataMember    = "ttimen";
                            series1.LabelsVisibility      = DefaultBoolean.False;
                            series1.ValueDataMembers.AddRange(new string[] { "kw" });
                            Lineseries.Add(series1);
                        }
                        break;

                        case ElectricSearchTypeEnum.kVAR:
                        {
                            Series series1 = new Series($"{ElectricConfig.DeviceName} - 瞬間虛功率", viewType: ViewType.Line);
                            series1.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:yyyy-MM-dd HH:mm:ss} " + "\n" + "數值:{V:0.00}kVAR";
                            series1.LegendTextPattern     = "{A}";
                            series1.ArgumentDataMember    = "ttimen";
                            series1.LabelsVisibility      = DefaultBoolean.False;
                            series1.ValueDataMembers.AddRange(new string[] { "kvar" });
                            Lineseries.Add(series1);
                        }
                        break;

                        case ElectricSearchTypeEnum.PF:
                        {
                            Series series1 = new Series($"{ElectricConfig.DeviceName} - 功率因數", viewType: ViewType.Line);
                            series1.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:yyyy-MM-dd HH:mm:ss} " + "\n" + "數值:{V:0.00}";
                            series1.LegendTextPattern     = "{A}";
                            series1.ArgumentDataMember    = "ttimen";
                            series1.LabelsVisibility      = DefaultBoolean.False;
                            series1.ValueDataMembers.AddRange(new string[] { "pfe" });
                            Lineseries.Add(series1);
                        }
                        break;

                        case ElectricSearchTypeEnum.HZ:
                        {
                            Series series1 = new Series($"{ElectricConfig.DeviceName} - 頻率", viewType: ViewType.Line);
                            series1.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:yyyy-MM-dd HH:mm:ss} " + "\n" + "數值:{V:0.00}HZ";
                            series1.LegendTextPattern     = "{A}";
                            series1.ArgumentDataMember    = "ttimen";
                            series1.LabelsVisibility      = DefaultBoolean.False;
                            series1.ValueDataMembers.AddRange(new string[] { "hz" });
                            Lineseries.Add(series1);
                        }
                        break;

                        case ElectricSearchTypeEnum.kWh:
                        {
                            Series series1 = new Series($"{ElectricConfig.DeviceName} - 累積電量", viewType: ViewType.Bar);
                            series1.DataSource            = ElectricTotaldata;
                            series1.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:yyyy-MM-dd} " + "\n" + "數值:{V:0.00}kWh";
                            series1.LegendTextPattern     = "{A}";
                            series1.ArgumentDataMember    = "ttimen";
                            series1.LabelsVisibility      = DefaultBoolean.False;
                            series1.ValueDataMembers.AddRange(new string[] { "KwhTotal" });
                            Lineseries.Add(series1);
                        }
                        break;
                        }
                        #endregion
                    }
                }
                switch (electricSearchTypeEnum)
                {
                case ElectricSearchTypeEnum.Voltage:
                case ElectricSearchTypeEnum.Current:
                case ElectricSearchTypeEnum.kW:
                case ElectricSearchTypeEnum.kVAR:
                case ElectricSearchTypeEnum.PF:
                case ElectricSearchTypeEnum.HZ:
                {
                    gridControl1.DataSource     = ThreePhaseElectricMeter_Logs;
                    LinechartControl.DataSource = ThreePhaseElectricMeter_Logs;
                }
                break;

                case ElectricSearchTypeEnum.kWh:
                {
                    gridControl1.DataSource = ElectricTotals;
                    //LinechartControl.DataSource = ElectricTotals;
                }
                break;
                }

                #region 報表
                for (int i = 0; i < gridView1.Columns.Count; i++)
                {
                    gridView1.Columns[i].Visible = false;
                }
                gridView1.OptionsBehavior.Editable    = false;
                gridView1.OptionsView.ColumnAutoWidth = false;
                gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
                switch (electricSearchTypeEnum)
                {
                case ElectricSearchTypeEnum.Voltage:
                {
                    gridView1.Columns["trv"].Visible = true;
                    gridView1.Columns["trv"].Caption = "T相電壓";
                    gridView1.Columns["trv"].BestFit();
                    gridView1.Columns["stv"].Visible = true;
                    gridView1.Columns["stv"].Caption = "S相電壓";
                    gridView1.Columns["stv"].BestFit();
                    gridView1.Columns["rsv"].Visible = true;
                    gridView1.Columns["rsv"].Caption = "R相電壓";
                    gridView1.Columns["rsv"].BestFit();
                }
                break;

                case ElectricSearchTypeEnum.Current:
                {
                    gridView1.Columns["ta"].Visible = true;
                    gridView1.Columns["ta"].Caption = "T相電流";
                    gridView1.Columns["ta"].BestFit();
                    gridView1.Columns["sa"].Visible = true;
                    gridView1.Columns["sa"].Caption = "S相電流";
                    gridView1.Columns["sa"].BestFit();
                    gridView1.Columns["ra"].Visible = true;
                    gridView1.Columns["ra"].Caption = "R相電流";
                    gridView1.Columns["ta"].BestFit();
                }
                break;

                case ElectricSearchTypeEnum.kW:
                {
                    gridView1.Columns["kw"].Visible = true;
                    gridView1.Columns["kw"].Caption = "瞬間功率";
                    gridView1.Columns["kw"].BestFit();
                }
                break;

                case ElectricSearchTypeEnum.kVAR:
                {
                    gridView1.Columns["kvar"].Visible = true;
                    gridView1.Columns["kvar"].Caption = "瞬間虛功率";
                    gridView1.Columns["kvar"].BestFit();
                }
                break;

                case ElectricSearchTypeEnum.PF:
                {
                    gridView1.Columns["pfe"].Visible = true;
                    gridView1.Columns["pfe"].Caption = "功率因數";
                    gridView1.Columns["pfe"].BestFit();
                }
                break;

                case ElectricSearchTypeEnum.HZ:
                {
                    gridView1.Columns["hz"].Visible = true;
                    gridView1.Columns["hz"].Caption = "頻率";
                    gridView1.Columns["hz"].BestFit();
                }
                break;

                case ElectricSearchTypeEnum.kWh:
                {
                    gridView1.Columns["KwhTotal"].Visible = true;
                    gridView1.Columns["KwhTotal"].Caption = "累積電量";
                    gridView1.Columns["KwhTotal"].BestFit();
                }
                break;
                }
                gridView1.Columns["ttimen"].Visible = true;
                gridView1.Columns["ttimen"].Caption = "時間";

                switch (electricSearchTypeEnum)
                {
                case ElectricSearchTypeEnum.Voltage:
                case ElectricSearchTypeEnum.Current:
                case ElectricSearchTypeEnum.kW:
                case ElectricSearchTypeEnum.kVAR:
                case ElectricSearchTypeEnum.PF:
                case ElectricSearchTypeEnum.HZ:
                {
                    gridView1.Columns["ttimen"].DisplayFormat.FormatString = "yyyy/MM/dd HH:mm:ss";
                }
                break;

                case ElectricSearchTypeEnum.kWh:
                {
                    gridView1.Columns["ttimen"].DisplayFormat.FormatString = "yyyy/MM/dd";
                }
                break;
                }
                gridView1.Columns["ttimen"].BestFit();
                gridView1.Columns["GatewayIndex"].Caption = "閘道器";
                gridView1.Columns["DeviceIndex"].Caption  = "設備";
                gridView1.CustomColumnDisplayText        += (s, ex) =>
                {
                    ColumnView view = s as ColumnView;
                    if (ex.Column.FieldName == "DeviceIndex" && ex.ListSourceRowIndex != DevExpress.XtraGrid.GridControl.InvalidRowHandle)
                    {
                        int val = (int)ex.Value;
                        for (int i = 0; i < ElectricConfigs.Count; i++)
                        {
                            int data = (int)view.GetListSourceRowCellValue(ex.ListSourceRowIndex, "GatewayIndex");
                            if (data == ElectricConfigs[i].GatewayIndex)
                            {
                                if (ElectricConfigs[i].DeviceIndex == val)
                                {
                                    ex.DisplayText = ElectricConfigs[i].DeviceName;
                                    break;
                                }
                            }
                        }
                    }
                    else if (ex.Column.FieldName == "GatewayIndex" && ex.ListSourceRowIndex != DevExpress.XtraGrid.GridControl.InvalidRowHandle)
                    {
                        int val = (int)ex.Value;
                        for (int i = 0; i < GatewayConfigs.Count; i++)
                        {
                            ex.DisplayText = GatewayConfigs[i].GatewayName;
                        }
                    }
                };
                gridView1.Columns["GatewayIndex"].Group();
                gridView1.Columns["DeviceIndex"].Group();
                #endregion
                #region 曲線圖
                LinechartControl.Legend.Direction = LegendDirection.TopToBottom;                                           //曲線圖線條說明的排序
                LinechartControl.CrosshairOptions.CrosshairLabelMode          = CrosshairLabelMode.ShowCommonForAllSeries; //顯示全部線條內容
                LinechartControl.CrosshairOptions.LinesMode                   = CrosshairLinesMode.Auto;                   //自動獲取點上面的數值
                LinechartControl.CrosshairOptions.GroupHeaderTextOptions.Font = new Font("微軟正黑體", 12);
                LinechartControl.CrosshairOptions.ShowArgumentLabels          = true;                                      //是否顯示Y軸垂直線
                LinechartControl.SideBySideEqualBarWidth = false;                                                          //線條是否需要相等寬度
                foreach (var item in Lineseries)
                {
                    LinechartControl.Series.AddRange(item);
                }
                #region 最後曲線圖顯示刻度
                if (LinechartControl.DataSource != null)
                {
                    XYDiagram diagram = (XYDiagram)LinechartControl.Diagram;
                    if (diagram != null)
                    {
                        diagram.EnableAxisXZooming   = true; //放大縮小
                        diagram.EnableAxisXScrolling = true; //拖曳
                        switch (electricSearchTypeEnum)
                        {
                        case ElectricSearchTypeEnum.Voltage:
                        case ElectricSearchTypeEnum.Current:
                        case ElectricSearchTypeEnum.kW:
                        case ElectricSearchTypeEnum.kVAR:
                        case ElectricSearchTypeEnum.PF:
                        case ElectricSearchTypeEnum.HZ:
                        {
                            diagram.AxisX.DateTimeScaleOptions.MeasureUnit   = DateTimeMeasureUnit.Minute;   // 顯示設定
                            diagram.AxisX.DateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Minute; // 刻度設定
                            diagram.AxisX.WholeRange.SideMarginsValue        = 0;                            //不需要邊寬
                            diagram.AxisY.WholeRange.AlwaysShowZeroLevel     = false;
                            diagram.AxisX.Label.TextPattern = "{A:yyyy-MM-dd HH:mm}";                        //X軸顯示
                        }
                        break;

                        case ElectricSearchTypeEnum.kWh:
                        {
                            diagram.AxisX.DateTimeScaleOptions.MeasureUnit   = DateTimeMeasureUnit.Day;   // 顯示設定
                            diagram.AxisX.DateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Day; // 刻度設定
                            diagram.AxisX.WholeRange.SideMarginsValue        = 1;                         //不需要邊寬
                            diagram.AxisX.Label.TextPattern = "{A:yyyy-MM-dd}";                           //X軸顯示
                        }
                        break;
                        }
                    }
                }
                #endregion
                #endregion
            }
            else
            {
                FlyoutAction action = new FlyoutAction();
                action.Caption     = "電表資訊-查詢報表錯誤";
                action.Description = "請選擇正確條件再進行查詢";
                action.Commands.Add(FlyoutCommand.OK);
                FlyoutDialog.Show(FindForm(), action);
            }
        }