Ejemplo n.º 1
0
        public SettingUserControl(MysqlMethod mysql, Form1 form1)
        {
            InitializeComponent();
            XtraReportSetting = InitialMethod.InitialXtraReportLoad();
            Form1             = form1;
            MysqlMethod       = mysql;
            GatewayConfigs    = MysqlMethod.Search_GatewayConfig();
            foreach (var Gatewayitem in GatewayConfigs)
            {
                var configs = MysqlMethod.Search_ElectricConfig(Gatewayitem.GatewayIndex);
                foreach (var Configitem in configs)
                {
                    ElectricConfigs.Add(Configitem);
                }
            }
            ReportConfigs = MysqlMethod.Search_ReportConfig();
            ReportTitleSetting reportTitle = InitialMethod.InitialReportTitleSetting();

            ContractNoTextEdit.Text = reportTitle.ContractNo;
            ElectNoTextEdit.Text    = reportTitle.ElectNo;
            FileFormatSetting fileFormat = InitialMethod.InitialFileFormatSetting();

            OutputFormatComboBoxEdit.SelectedIndex = fileFormat.FileFormat;
            AutotoggleSwitch.IsOn = XtraReportSetting.AutoExport;       //自動匯出開關
            PathtextEdit.Text     = XtraReportSetting.Path;             //儲存路徑
            DaycomboBoxEdit.Text  = XtraReportSetting.Day.ToString();   //匯出時間

            int Index = 0;

            foreach (var ReportConfigitem in ReportConfigs)
            {
                var electricconfig = ElectricConfigs.Where(g => g.GatewayIndex == ReportConfigitem.GatewayIndex & g.DeviceIndex == ReportConfigitem.DeviceIndex).ToList()[0];
                ExportElectricSettingUserControl control = new ExportElectricSettingUserControl(ReportConfigitem, electricconfig, MysqlMethod)
                {
                    Location = new Point(5 + 420 * Index, 5)
                };
                ReportviewpanelControl.Controls.Add(control);
                exportElectricSettingUserControls.Add(control);
                Index++;
            }
        }
Ejemplo n.º 2
0
 public ChartUserControl(MysqlMethod mysql)
 {
     InitializeComponent();
     StartdateEdit.Properties.ContextImageOptions.Image = imageCollection1.Images["calendar"];
     EnddateEdit.Properties.ContextImageOptions.Image   = imageCollection1.Images["calendar"];
     MysqlMethod    = mysql;
     GatewayConfigs = MysqlMethod.Search_GatewayConfig();
     foreach (var Gatewayitem in GatewayConfigs)
     {
         var configs = MysqlMethod.Search_ElectricConfig(Gatewayitem.GatewayIndex);
         foreach (var Configitem in configs)
         {
             ElectricConfigs.Add(Configitem);
         }
     }
     foreach (var ElectricConfigitem in ElectricConfigs)
     {
         CheckedListBoxItem item = new CheckedListBoxItem(ElectricConfigitem.DeviceName, false);
         item.Tag = ElectricConfigitem;
         DeviceCheckedcomboBoxEdit.Properties.Items.Add(item);
     }
     DeviceCheckedcomboBoxEdit.Popup += (s, e) =>
     {
         var f       = (s as IPopupControl).PopupWindow as CheckedPopupContainerForm;
         var listBox = f.ActiveControl as CheckedListBoxControl;
         if (listBox != null)
         {
             listBox.ItemChecking += listBox_ItemChecking;
         }
     };
     DeviceCheckedcomboBoxEdit.CloseUp += (s, e) =>
     {
         var f       = (s as IPopupControl).PopupWindow as CheckedPopupContainerForm;
         var listBox = f.ActiveControl as CheckedListBoxControl;
         if (listBox != null)
         {
             listBox.ItemChecking -= listBox_ItemChecking;
         }
     };
     DeviceCheckedcomboBoxEdit.Properties.SelectAllItemVisible = false;
 }
 public override void TextChange()
 {
     if (ElectricConfigs != null)
     {
         var electricconfigs = ElectricConfigs.Where(g => g.TotalMeterFlag == false).ToList();
         if (electricconfigs.Count == SubMeterIndex)
         {
             SubMeterIndex = 0;
             foreach (var item in ElectricConfigs)
             {
                 if (!item.TotalMeterFlag)
                 {
                     SubMeters[SubMeterIndex].AbsProtocols   = AbsProtocols;
                     SubMeters[SubMeterIndex].ElectricConfig = item;
                     SubMeters[SubMeterIndex].TextChange();
                     SubMeterIndex++;
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
        private void SearchsimpleButton_Click(object sender, EventArgs e)
        {
            if (gridView1.Columns.Count > 0)
            {
                gridView1.Columns.Clear();
            }
            if (chartControl.Series.Count > 0)
            {
                chartControl.Series.Clear();
            }

            ReportSearchEnumType = (ReportSearchEnumType)SearchTypecomboBoxEdit.SelectedIndex;
            switch (ReportSearchEnumType)
            {
            case ReportSearchEnumType.kW:
            {
                if (Form1.ConnectionFlag)
                {
                    if (ElectricConfigs.Count > 0)
                    {
                        var ElectricConfig = ElectricConfigs.Where(g => g.DeviceName == SearchDevicecomboBoxEdit.Text).Single();
                        var data           = SqlMethod.Search_ThreePhaseElectricMeter_Log(Convert.ToDateTime(StartdateEdit.EditValue).ToString("yyyyMMdd"), Convert.ToDateTime(EnddateEdit.EditValue).ToString("yyyyMMdd"), ElectricConfig.GatewayIndex, ElectricConfig.DeviceIndex);
                        if (data != null)
                        {
                            gridControl.DataSource  = data;
                            chartControl.DataSource = data;
                            #region 報表
                            for (int i = 0; i < gridView1.Columns.Count; i++)
                            {
                                if (gridView1.Columns[i].FieldName == "ttimen")
                                {
                                    gridView1.Columns[i].Caption = "時間";
                                    gridView1.Columns[i].DisplayFormat.FormatString = "yyyy/MM/dd HH:mm";
                                    gridView1.Columns[i].BestFit();
                                }
                                else if (gridView1.Columns[i].FieldName == "kw")
                                {
                                    gridView1.Columns[i].Caption = "即時用電";
                                    gridView1.Columns[i].BestFit();
                                }
                                else
                                {
                                    gridView1.Columns[i].Visible = false;
                                }
                            }
                            #endregion
                            #region 圖表
                            Series series = new Series($"{SearchDevicecomboBoxEdit.Text}", ViewType.Line);
                            series.ArgumentDataMember = "ttimen";
                            series.ValueDataMembers.AddRange(new string[] { "kw" });
                            series.CrosshairLabelPattern = "{S} \r時間 : {A:yyyy-MM-dd HH:mm}\r{V:0.##} kW";
                            series.LabelsVisibility      = DevExpress.Utils.DefaultBoolean.False;
                            chartControl.Series.Add(series);
                            if (chartControl.DataSource != null && chartControl.Series.Count > 0)
                            {
                                XYDiagram diagram = (XYDiagram)chartControl.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.Angle                 = 90;
                                    diagram.AxisX.Label.TextPattern           = "{A:yyyy-MM-dd HH:mm}";              //X軸顯示
                                    diagram.AxisX.WholeRange.SideMarginsValue = 0;                                   //不需要邊寬
                                }
                                chartControl.CrosshairOptions.ShowArgumentLabels = false;                            //是否顯示Y軸垂直線
                                chartControl.CrosshairOptions.ShowArgumentLine   = false;                            //是否顯示Y軸垂直線
                                                                                                                     //chartControl.CrosshairOptions.ShowCrosshairLabels = false;//是否顯示Y軸垂直線
                            }
                            #endregion
                        }
                    }
                }
                else
                {
                    TimeSpan          timeSpan = Convert.ToDateTime(EnddateEdit.EditValue).Subtract(Convert.ToDateTime(StartdateEdit.EditValue));
                    List <LineModule> Data     = new List <LineModule>();
                    for (int day = 0; day < timeSpan.TotalDays + 1; day++)
                    {
                        var data = Create_Line(Convert.ToDateTime(StartdateEdit.EditValue).AddDays(day));
                        Data.AddRange(data);
                    }
                    gridControl.DataSource  = Data;
                    chartControl.DataSource = Data;
                    #region 報表
                    for (int i = 0; i < gridView1.Columns.Count; i++)
                    {
                        if (gridView1.Columns[i].FieldName == "Argument")
                        {
                            gridView1.Columns[i].Caption = "時間";
                            gridView1.Columns[i].DisplayFormat.FormatString = "yyyy/MM/dd HH:mm";
                            gridView1.Columns[i].BestFit();
                        }
                        else if (gridView1.Columns[i].FieldName == "Value")
                        {
                            gridView1.Columns[i].Caption = "即時用電";
                            gridView1.Columns[i].BestFit();
                        }
                        else
                        {
                            gridView1.Columns[i].Visible = false;
                        }
                    }
                    #endregion
                    #region 圖表
                    Series series = new Series($"{SearchDevicecomboBoxEdit.Text}", ViewType.Line);
                    series.ArgumentDataMember = "Argument";
                    series.ValueDataMembers.AddRange(new string[] { "Value" });
                    series.CrosshairLabelPattern = "{S} \r時間 : {A:yyyy-MM-dd HH:mm}\r{V:0.##} kW";
                    series.LabelsVisibility      = DevExpress.Utils.DefaultBoolean.False;
                    chartControl.Series.Add(series);
                    if (chartControl.DataSource != null && chartControl.Series.Count > 0)
                    {
                        XYDiagram diagram = (XYDiagram)chartControl.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.Angle                 = 90;
                            diagram.AxisX.Label.TextPattern           = "{A:yyyy-MM-dd HH:mm}";              //X軸顯示
                            diagram.AxisX.WholeRange.SideMarginsValue = 0;                                   //不需要邊寬
                        }
                        chartControl.CrosshairOptions.ShowArgumentLabels = false;                            //是否顯示Y軸垂直線
                        chartControl.CrosshairOptions.ShowArgumentLine   = false;                            //是否顯示Y軸垂直線
                                                                                                             //chartControl.CrosshairOptions.ShowCrosshairLabels = false;//是否顯示Y軸垂直線
                    }
                    #endregion
                }
            }
            break;

            case ReportSearchEnumType.kWh:
            {
                if (Form1.ConnectionFlag)
                {
                    if (ElectricConfigs.Count > 0)
                    {
                        var ElectricConfig = ElectricConfigs.Where(g => g.DeviceName == SearchDevicecomboBoxEdit.Text).Single();
                        var data           = SqlMethod.Search_ElectricTotalPrice(Convert.ToDateTime(StartdateEdit.EditValue).ToString("yyyyMMdd"), Convert.ToDateTime(EnddateEdit.EditValue).ToString("yyyyMMdd"), ElectricConfig.GatewayIndex, ElectricConfig.DeviceIndex);
                        if (data != null)
                        {
                            gridControl.DataSource  = data;
                            chartControl.DataSource = data;
                            #region 報表
                            for (int i = 0; i < gridView1.Columns.Count; i++)
                            {
                                if (gridView1.Columns[i].FieldName == "ttimen")
                                {
                                    gridView1.Columns[i].Caption = "時間";
                                    gridView1.Columns[i].DisplayFormat.FormatString = "yyyy/MM/dd";
                                    gridView1.Columns[i].BestFit();
                                }
                                else if (gridView1.Columns[i].FieldName == "KwhTotal")
                                {
                                    gridView1.Columns[i].Caption = "累積用電";
                                    gridView1.Columns[i].BestFit();
                                }
                                else
                                {
                                    gridView1.Columns[i].Visible = false;
                                }
                            }
                            #endregion
                            #region 圖表
                            Series series = new Series($"{SearchDevicecomboBoxEdit.Text}", ViewType.Bar);
                            series.ArgumentDataMember = "ttimen";
                            series.ValueDataMembers.AddRange(new string[] { "KwhTotal" });
                            series.CrosshairLabelPattern = "{S} \r時間 : {A:yyyy-MM-dd HH:mm}\r{V:0.##} kWh";
                            series.LabelsVisibility      = DevExpress.Utils.DefaultBoolean.False;
                            chartControl.Series.Add(series);
                            if (chartControl.DataSource != null && chartControl.Series.Count > 0)
                            {
                                XYDiagram diagram = (XYDiagram)chartControl.Diagram;
                                if (diagram != null)
                                {
                                    diagram.AxisX.DateTimeScaleOptions.MeasureUnit   = DateTimeMeasureUnit.Day;   // 顯示設定
                                    diagram.AxisX.DateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Day; // 刻度設定
                                    diagram.AxisX.Label.Angle                 = 90;
                                    diagram.AxisX.Label.TextPattern           = "{A:yyyy-MM-dd}";                 //X軸顯示
                                    diagram.AxisX.WholeRange.SideMarginsValue = 0;                                //不需要邊寬
                                }
                                chartControl.CrosshairOptions.ShowArgumentLabels = false;                         //是否顯示Y軸垂直線
                                chartControl.CrosshairOptions.ShowArgumentLine   = false;                         //是否顯示Y軸垂直線
                                                                                                                  //chartControl.CrosshairOptions.ShowCrosshairLabels = false;//是否顯示Y軸垂直線
                            }
                            #endregion
                        }
                    }
                }
                else
                {
                    TimeSpan          timeSpan = Convert.ToDateTime(EnddateEdit.EditValue).Subtract(Convert.ToDateTime(StartdateEdit.EditValue));
                    List <LineModule> Data     = new List <LineModule>();
                    for (int day = 0; day < timeSpan.TotalDays + 1; day++)
                    {
                        var data = new LineModule()
                        {
                            Argument = Convert.ToDateTime($"{Convert.ToDateTime(StartdateEdit.EditValue).AddDays(day):yyyy-MM-dd} 00:00:00"),
                            Value    = rnd.Next(200, 400)
                        };;
                        Data.Add(data);
                    }
                    gridControl.DataSource  = Data;
                    chartControl.DataSource = Data;
                    #region 報表
                    for (int i = 0; i < gridView1.Columns.Count; i++)
                    {
                        if (gridView1.Columns[i].FieldName == "Argument")
                        {
                            gridView1.Columns[i].Caption = "時間";
                            gridView1.Columns[i].DisplayFormat.FormatString = "yyyy/MM/dd";
                            gridView1.Columns[i].BestFit();
                        }
                        else if (gridView1.Columns[i].FieldName == "Value")
                        {
                            gridView1.Columns[i].Caption = "累積用電";
                            gridView1.Columns[i].BestFit();
                        }
                        else
                        {
                            gridView1.Columns[i].Visible = false;
                        }
                    }
                    #endregion
                    #region 圖表
                    Series series = new Series($"{SearchDevicecomboBoxEdit.Text}", ViewType.Bar);
                    series.ArgumentDataMember = "Argument";
                    series.ValueDataMembers.AddRange(new string[] { "Value" });
                    series.CrosshairLabelPattern = "{S} \r時間 : {A:yyyy-MM-dd HH:mm}\r{V:0.##} kWh";
                    series.LabelsVisibility      = DevExpress.Utils.DefaultBoolean.False;
                    chartControl.Series.Add(series);
                    if (chartControl.DataSource != null && chartControl.Series.Count > 0)
                    {
                        XYDiagram diagram = (XYDiagram)chartControl.Diagram;
                        if (diagram != null)
                        {
                            diagram.AxisX.DateTimeScaleOptions.MeasureUnit   = DateTimeMeasureUnit.Day;   // 顯示設定
                            diagram.AxisX.DateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Day; // 刻度設定
                            diagram.AxisX.Label.Angle                 = 90;
                            diagram.AxisX.Label.TextPattern           = "{A:yyyy-MM-dd}";                 //X軸顯示
                            diagram.AxisX.WholeRange.SideMarginsValue = 0;                                //不需要邊寬
                        }
                        chartControl.CrosshairOptions.ShowArgumentLabels = false;                         //是否顯示Y軸垂直線
                        chartControl.CrosshairOptions.ShowArgumentLine   = false;                         //是否顯示Y軸垂直線
                                                                                                          //chartControl.CrosshairOptions.ShowCrosshairLabels = false;//是否顯示Y軸垂直線
                    }
                    #endregion
                }
            }
            break;
            }
        }
Ejemplo n.º 5
0
        public Form1()
        {
            InitializeComponent();
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         .WriteTo.File($"{AppDomain.CurrentDomain.BaseDirectory}\\log\\log-.txt",
                                       rollingInterval: RollingInterval.Day,
                                       outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
                         .CreateLogger(); //宣告Serilog初始化

            UserbarButtonItem.ImageOptions.Image    = imageCollection16x16.Images["UserDisconnected"];
            SettingbarButtonItem.ImageOptions.Image = imageCollection16x16.Images["Setting"];
            SettingbarButtonItem.Visibility         = BarItemVisibility.Never;
            #region  Json載入
            ButtonSetting      = InitialMethod.ButtonLoad();
            LogoSetting        = InitialMethod.LogoLoad();
            SqlDBSetting       = InitialMethod.SqlDBLoad();
            BankAccountSetting = InitialMethod.BankAccountLoad();
            DemoSetting        = InitialMethod.DemoLoad();
            #endregion
            ConnectionFlag = DemoSetting.ConnectionFlag;

            #region  入Logo圖片
            if (LogoSetting != null)
            {
                if (File.Exists(LogoSetting.LogoPath))
                {
                    LogopictureEdit.Image = Image.FromFile(LogoSetting.LogoPath);
                }
                else
                {
                    LogopictureEdit.Image = LogoimageCollection.Images["ewatch_logo"];
                }
            }
            else
            {
                LogopictureEdit.Image = LogoimageCollection.Images["ewatch_logo"];
            }
            #endregion

            #region  鈕載入
            NavigationFrame = new NavigationFrame()
            {
                Dock = DockStyle.Fill
            };
            NavigationFrame.Parent = DisplaypanelControl;
            ButtonControl          = new ButtonControl()
            {
                Form1 = this, navigationFrame = NavigationFrame
            };
            ButtonControl.AccordionLoad(accordionControl1, ButtonSetting);
            #endregion

            #region 資料庫方法載入
            if (SqlDBSetting != null && ConnectionFlag)
            {
                SqlMethod = new SqlMethod()
                {
                    setting = SqlDBSetting, BankAccountSetting = BankAccountSetting
                };
                SqlMethod.SQLConnect();
                if (SqlMethod.Search_DataBase())
                {
                    SQLDataBaseFlag = true;
                    GatewayConfigs  = SqlMethod.Search_GatewayConfig();  //通道資訊
                    ElectricConfigs = SqlMethod.Search_Electricconfig(); //電表設備資訊
                    SqlComponent    = new SqlComponent()
                    {
                        SqlMethod = SqlMethod, BankAccountSetting = BankAccountSetting
                    };
                    SqlComponent.MyWorkState = ConnectionFlag;
                }
                else
                {
                    SQLDataBaseFlag = false;
                }
            }
            else if (!ConnectionFlag)
            {
                SQLDataBaseFlag = true;
                GatewayConfig gateway = new GatewayConfig()
                {
                    GatewayIndex = 0, GatewayName = "通道1"
                };
                GatewayConfigs.Add(gateway);
                for (int i = 0; i < 20; i++)
                {
                    if (i == 0)
                    {
                        ElectricConfig electric = new ElectricConfig()
                        {
                            TotalMeterFlag = true, DeviceName = $"電表{i + 1}", GatewayIndex = 0, DeviceIndex = i, DeviceID = i + 1
                        };
                        ElectricConfigs.Add(electric);
                    }
                    else
                    {
                        ElectricConfig electric = new ElectricConfig()
                        {
                            TotalMeterFlag = false, DeviceName = $"電表{i + 1}", GatewayIndex = 0, DeviceIndex = i, DeviceID = i + 1
                        };
                        ElectricConfigs.Add(electric);
                    }
                }
            }
            #endregion

            #region 通訊
            if (ConnectionFlag && GatewayConfigs != null && ElectricConfigs != null)
            {
                foreach (var item in GatewayConfigs)
                {
                    GatewayEnumType = (GatewayEnumType)item.GatewayEnumType;
                    var electricconfigs = ElectricConfigs.Where(g => g.GatewayIndex == item.GatewayIndex).ToList();
                    switch (GatewayEnumType)
                    {
                    case GatewayEnumType.ModbusRTU:
                    {
                        SerialportComponent component = new SerialportComponent()
                        {
                            BankAccountSetting = BankAccountSetting, Gatewayconfig = item, ElectricConfigs = electricconfigs
                        };
                        component.MyWorkState = ConnectionFlag;
                        ModbusComponents.Add(component);
                    }
                    break;

                    case GatewayEnumType.ModbusTCP:
                    {
                        TcpComponent component = new TcpComponent()
                        {
                            BankAccountSetting = BankAccountSetting, Gatewayconfig = item, ElectricConfigs = electricconfigs
                        };
                        component.MyWorkState = ConnectionFlag;
                        ModbusComponents.Add(component);
                    }
                    break;
                    }
                }
            }
            #endregion

            #region 畫面
            foreach (var item in ButtonSetting.ButtonGroupSettings)
            {
                foreach (var Buttonitem in item.ButtonItemSettings)
                {
                    ButtonItemEnumType = (ButtonItemEnumType)Buttonitem.ButtonItemEnumType;
                    switch (ButtonItemEnumType)
                    {
                    case ButtonItemEnumType.Home:
                    {
                        ChargingPileView chargingPileView = new ChargingPileView(ElectricConfigs, SqlMethod, this, GatewayConfigs)
                        {
                            SqlMethod = SqlMethod, Dock = DockStyle.Fill
                        };
                        field4UserControls.Add(chargingPileView);
                        NavigationFrame.AddPage(chargingPileView);
                    }
                    break;

                    case ButtonItemEnumType.Report:
                    {
                        dataReportUserControl = new DataReportUserControl(ElectricConfigs)
                        {
                            SqlMethod = SqlMethod, Dock = DockStyle.Fill, Form1 = this
                        };
                        NavigationFrame.AddPage(dataReportUserControl);
                    }
                    break;

                    case ButtonItemEnumType.BillingSheet:
                    {
                        billingSheetUserControl = new BillingSheetUserControl(ElectricConfigs)
                        {
                            BankaccountSetting = BankAccountSetting, SqlMethod = SqlMethod, Dock = DockStyle.Fill, Form1 = this
                        };
                        NavigationFrame.AddPage(billingSheetUserControl);
                    }
                    break;
                    }
                }
            }
            User_ButtonItem_Visible();
            #endregion
            timer1.Interval = 1000;
            timer1.Enabled  = true;
        }
Ejemplo n.º 6
0
 public MainUserControl(MysqlMethod mysql, List <AbsProtocol> electricAbsprotocols)
 {
     InitializeComponent();
     MysqlMethod          = mysql;
     ElectricAbsProtocols = electricAbsprotocols;
     GatewayConfigs       = MysqlMethod.Search_GatewayConfig();
     foreach (var Gatewayitem in GatewayConfigs)
     {
         var configs = MysqlMethod.Search_ElectricConfig(Gatewayitem.GatewayIndex);
         foreach (var Configitem in configs)
         {
             ElectricConfigs.Add(Configitem);
         }
     }
     #region 月累積量
     Month_ElectricTotal();
     foreach (var ElectricConfigitem in ElectricConfigs)
     {
         Series series = new Series($"{ElectricConfigitem.DeviceName}", viewType: ViewType.Bar);
         series.DataSource            = ElectricTotals.Where(g => g.GatewayIndex == ElectricConfigitem.GatewayIndex & g.DeviceIndex == ElectricConfigitem.DeviceIndex).ToList();
         series.CrosshairLabelPattern = "{S}" + "\n" + "時間:{A:yyyy-MM-dd} " + "\n" + "用電量:{V:0.00}kWh";
         series.LegendTextPattern     = "{A}";
         series.ArgumentDataMember    = "ttimen";
         series.ValueDataMembers.AddRange(new string[] { "KwhTotal" });
         series.CheckedInLegend = true;
         ((BarSeriesLabel)series.Label).ShowForZeroValues = true;
         MonthchartControl.Series.Add(series);
     }
     MonthchartControl.LegendItemChecked += (s, e) => //曲線圖 Series勾選功能
     {
         Series checkedSeries = e.CheckedElement as Series;
         if (checkedSeries == null || Series.IndexOf(checkedSeries) != othersSeriesIndex)
         {
             return;
         }
         for (int i = 0; i < Series.Count; i++)
         {
             if (i < othersSeriesIndex)
             {
                 Series[i].Visible = e.NewCheckState;
             }
         }
     };
     MonthchartControl.Legend.MarkerMode                   = LegendMarkerMode.CheckBox;
     MonthchartControl.Legend.Border.Visibility            = DefaultBoolean.False;
     MonthchartControl.Legend.BackColor                    = Color.Transparent;
     MonthchartControl.Legend.Direction                    = LegendDirection.BottomToTop;
     MonthchartControl.CrosshairOptions.CrosshairLabelMode = CrosshairLabelMode.ShowCommonForAllSeries;
     MonthchartControl.CrosshairOptions.LinesMode          = CrosshairLinesMode.Auto;
     MonthchartControl.CrosshairOptions.ShowArgumentLabels = true;
     XYDiagram diagram = (XYDiagram)MonthchartControl.Diagram;
     diagram.AxisX.DateTimeScaleOptions.MeasureUnit   = DateTimeMeasureUnit.Day;   // 顯示設定
     diagram.AxisX.DateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Day; // 刻度設定
     diagram.AxisX.WholeRange.SideMarginsValue        = 1;                         //不需要邊寬
     #endregion
     #region 分電表顯示
     int ElectricInt = 0;
     foreach (var ElectricConfigitem in ElectricConfigs)
     {
         ElectricUserControl electric = new ElectricUserControl(ElectricConfigitem, mysql, ElectricAbsProtocols)
         {
             Location = new Point(5 + (ElectricInt * 855), 5)
         };
         ElectricpanelControl.Controls.Add(electric);
         Field4UserControls.Add(electric);
         ElectricInt++;
     }
     #endregion
 }
Ejemplo n.º 7
0
        public void create_XtraReport(MysqlMethod mysql, string TTime, ReportTitleSetting reportTitle)
        {
            MysqlMethod          = mysql;
            ContractNoLabel.Text = reportTitle.ContractNo;              //契約編號
            ElectNoLabel.Text    = reportTitle.ElectNo;                 //電號
            var TaiwanDate = new System.Globalization.TaiwanCalendar(); //民國轉換

            XtraReportSetting = InitialMethod.InitialXtraReportLoad();
            DateTime dateTime = Convert.ToDateTime(TTime);
            DateTime nowtime  = DateTime.Now;

            ReportConfigs  = MysqlMethod.Search_ReportConfig();//報表資訊
            GatewayConfigs = MysqlMethod.Search_GatewayConfig();
            foreach (var item in GatewayConfigs)
            {
                var configs = MysqlMethod.Search_ElectricConfig(item.GatewayIndex);
                ElectricConfigs.AddRange(configs);
            }
            string startime = startime = dateTime.AddMonths(-1).ToString("yyyyMMdd");
            string endtime  = dateTime.AddDays(-1).ToString("yyyyMMdd");

            foreach (var item in ElectricConfigs)
            {
                var data = MysqlMethod.Search_ElectricSumTotal(startime, endtime, item.GatewayIndex, item.DeviceIndex);
                TotalkWh.Add(data);
            }

            var SumTotalkWh = TotalkWh[0] + TotalkWh[1];

            StartDatexrLabel1.Text = $"{TaiwanDate.GetYear(dateTime.AddMonths(-1))}";
            StartDatexrLabel2.Text = $"{dateTime.AddMonths(-1).ToString("MM")}";
            if (XtraReportSetting.Day.ToString().Length == 2)
            {
                StartDatexrLabel3.Text = $"{XtraReportSetting.Day}";
                //StartDatexrLabel1.Text = $"{TaiwanDate.GetYear(dateTime.AddMonths(-1))}年{dateTime.AddMonths(-1).ToString("MM")}月{ XtraReportSetting.Day}日";
            }
            else
            {
                StartDatexrLabel3.Text = $"0{XtraReportSetting.Day}";
                //StartDatexrLabel1.Text = $"{TaiwanDate.GetYear(dateTime.AddMonths(-1))}年{dateTime.AddMonths(-1).ToString("MM")}月0{ XtraReportSetting.Day}日";
            }

            EndDatexrLabel1.Text = $"{TaiwanDate.GetYear(dateTime.AddDays(-1))}";
            EndDatexrLabel2.Text = $"{dateTime.AddDays(-1).ToString("MM")}";
            EndDatexrLabel3.Text = $"{dateTime.AddDays(-1).ToString("dd")}";
            //EndDatexrLabel1.Text = $"{TaiwanDate.GetYear(dateTime.AddDays(-1))}年{dateTime.AddDays(-1).ToString("MM月dd日")}";
            CurrentMeterReadingDayxrLabel1.Text = $"{TaiwanDate.GetYear(nowtime)}";
            CurrentMeterReadingDayxrLabel2.Text = $"{nowtime.ToString("MM")}";
            CurrentMeterReadingDayxrLabel3.Text = $"{nowtime.ToString("dd")}";
            //CurrentMeterReadingDayxrLabel1.Text = $"{TaiwanDate.GetYear(nowtime)}年{nowtime.ToString("MM")}月{nowtime.ToString("dd")}日";//本期抄表日
            DateOfReportingxrLabel1.Text = $"{TaiwanDate.GetYear(nowtime)}";
            DateOfReportingxrLabel2.Text = $"{nowtime.ToString("MM")}";
            DateOfReportingxrLabel3.Text = $"{nowtime.ToString("dd")}";
            //DateOfReportingxrLabel1.Text = $"{TaiwanDate.GetYear(nowtime)}年{nowtime.ToString("MM")}月{nowtime.ToString("dd")}日";//填報日期
            if (ReportConfigs.Count > 0)
            {
                #region 第一顆電表
                xrTableCell7.Text  = ReportConfigs[0].ElectricNo;
                xrTableCell12.Text = ReportConfigs[0].ElectricitySalePeriod.ToString();                                                                                                                                                                                                              //售電期限
                xrTableCell17.Text = $"{TaiwanDate.GetYear(ReportConfigs[0].StartingDate)}.{ReportConfigs[0].StartingDate.Month}.{ReportConfigs[0].StartingDate.Day}";                                                                                                                               //計價起始日
                xrTableCell22.Text = $"{TaiwanDate.GetYear(ReportConfigs[0].OfficialPricingStartDate)}.{ReportConfigs[0].OfficialPricingStartDate.Month}.{ReportConfigs[0].OfficialPricingStartDate.Day}";                                                                                           //正是購售電能日
                xrTableCell52.Text = $"{TaiwanDate.GetYear(ReportConfigs[0].PricStartTime)}.{ReportConfigs[0].PricStartTime.Month}.{ReportConfigs[0].PricStartTime.Day}-{TaiwanDate.GetYear(ReportConfigs[0].PricEndTime)}.{ReportConfigs[0].PricEndTime.Month}.{ReportConfigs[0].PricEndTime.Day}"; //計價起迄期間
                xrTableCell27.Text = ReportConfigs[0].ElectricityPurchaseRate.ToString("0.####");                                                                                                                                                                                                    //購電費率
                xrTableCell32.Text = ReportConfigs[0].DeviceCapacity.ToString("0.###");                                                                                                                                                                                                              //裝置容量
                xrTableCell37.Text = ReportConfigs[0].PurchaseAndSaleCapacity.ToString("0.###");                                                                                                                                                                                                     //購售電容量
                xrTableCell42.Text = TotalkWh[0].ToString("0.##");                                                                                                                                                                                                                                   //生產電度量
                if (TotalkWh[0] != 0)
                {
                    xrTableCell47.Text = $"{Convert.ToInt32((TotalkWh[0] / SumTotalkWh) * 100)}%";
                }
                #endregion

                #region 第二顆電表
                xrTableCell8.Text  = ReportConfigs[1].ElectricNo;
                xrTableCell13.Text = ReportConfigs[1].ElectricitySalePeriod.ToString();                                                                                                                                                                                                              //售電期限
                xrTableCell18.Text = $"{TaiwanDate.GetYear(ReportConfigs[1].StartingDate)}.{ReportConfigs[1].StartingDate.Month}.{ReportConfigs[1].StartingDate.Day}";                                                                                                                               //計價起始日
                xrTableCell23.Text = $"{TaiwanDate.GetYear(ReportConfigs[1].OfficialPricingStartDate)}.{ReportConfigs[1].OfficialPricingStartDate.Month}.{ReportConfigs[1].OfficialPricingStartDate.Day}";                                                                                           //正是購售電能日
                xrTableCell53.Text = $"{TaiwanDate.GetYear(ReportConfigs[1].PricStartTime)}.{ReportConfigs[1].PricStartTime.Month}.{ReportConfigs[1].PricStartTime.Day}-{TaiwanDate.GetYear(ReportConfigs[1].PricEndTime)}.{ReportConfigs[1].PricEndTime.Month}.{ReportConfigs[1].PricEndTime.Day}"; //計價起迄期間
                xrTableCell28.Text = ReportConfigs[1].ElectricityPurchaseRate.ToString("#.####");                                                                                                                                                                                                    //購電費率
                xrTableCell33.Text = ReportConfigs[1].DeviceCapacity.ToString("#.###");                                                                                                                                                                                                              //裝置容量
                xrTableCell38.Text = ReportConfigs[1].PurchaseAndSaleCapacity.ToString("#.###");                                                                                                                                                                                                     //購售電容量
                xrTableCell43.Text = TotalkWh[1].ToString("#.##");                                                                                                                                                                                                                                   //生產電度量
                if (TotalkWh[1] != 0)
                {
                    xrTableCell48.Text = $"{Convert.ToInt32((TotalkWh[1] / SumTotalkWh) * 100)}%";
                }
                #endregion

                #region 合計
                xrTableCell35.Text = $"{(ReportConfigs[0].DeviceCapacity + ReportConfigs[1].DeviceCapacity).ToString("#.###")}";                    //裝置容量
                xrTableCell40.Text = $"{ (ReportConfigs[0].PurchaseAndSaleCapacity + ReportConfigs[1].PurchaseAndSaleCapacity).ToString("#.###")}"; //購售電容量
                xrTableCell45.Text = $"{SumTotalkWh.ToString("#.##")}";
                #endregion
            }
        }