예제 #1
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
 }
예제 #2
0
        public Form1()
        {
            #region Serilog initial
            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初始化
            #endregion

            #region Loading initial
            FluentSplashScreenOptions op = new FluentSplashScreenOptions();
            op.Title                = "太陽能資料蒐集系統";//太陽能資料蒐集系統  帆宣自動化抄表系統
            op.Subtitle             = "Automatic Meter Reading System";
            op.LeftFooter           = "Copyright © 2021 SIN MAO Energy CO., LTD." + Environment.NewLine + "All Rights reserved.";
            op.LoadingIndicatorType = FluentLoadingIndicatorType.Dots;
            op.OpacityColor         = Color.FromArgb(62, 91, 135);
            op.Opacity              = 130;
            SplashScreenManager.ShowFluentSplashScreen(
                op,
                parentForm: this,
                useFadeIn: true,
                useFadeOut: true
                );
            #endregion

            #region  入資料庫JSON
            op.RightFooter = $"載入資料庫資訊";
            SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op);
            SystemSetting = InitialMethod.SystemLoad();
            Thread.Sleep(1000);
            #endregion

            #region  入按鈕JSON
            op.RightFooter = $"載入按鈕資訊";
            SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op);
            ButtonSetting = InitialMethod.InitialButtonLoad();
            Thread.Sleep(1000);
            #endregion

            #region  入匯出報表JSON
            op.RightFooter = $"載入匯出報表資訊";
            SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op);
            XtraReportSetting = InitialMethod.InitialXtraReportLoad();

            Thread.Sleep(1000);
            #endregion

            #region JSON錯誤資訊檢查
            if (SystemSetting == null && ButtonSetting == null && XtraReportSetting == null)
            {
                ErrorStr = "資料庫與按鈕Json錯誤";
            }
            else if (SystemSetting != null && ButtonSetting == null && XtraReportSetting != null)
            {
                ErrorStr = "按鈕Json錯誤";
            }
            else if (SystemSetting == null && ButtonSetting != null && XtraReportSetting != null)
            {
                ErrorStr = "資料庫Json錯誤";
            }
            else if (SystemSetting != null && ButtonSetting != null && XtraReportSetting == null)
            {
                ErrorStr = "匯出報表Json錯誤";
            }
            if (ErrorStr == "")
            {
                op.RightFooter = $"載入完成";
                SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op);
                Thread.Sleep(1000);
                SplashScreenManager.CloseForm();
            }
            else
            {
                op.RightFooter = $"{ErrorStr}";
                SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op);
                Thread.Sleep(5000);
                SplashScreenManager.CloseForm();
            }
            #endregion

            InitializeComponent();
            if (ErrorStr == "")
            {
                Change_Logo();                                                                   //載入Logo
                SettingbarButtonItem.ImageOptions.Image = imageCollection1.Images["technology"]; //設定按鈕圖
                #region 建立資料庫物件
                MysqlMethod = new MysqlMethod(SystemSetting);
                if (SystemSetting != null)
                {
                    GatewayConfigs = MysqlMethod.Search_GatewayConfig();
                }
                #endregion

                #region 建立通訊
                if (GatewayConfigs != null)
                {
                    foreach (var item in GatewayConfigs)
                    {
                        GatewayTypeEnum gatewayType = (GatewayTypeEnum)item.GatewayTypeEnum;
                        switch (gatewayType)
                        {
                        case GatewayTypeEnum.ModbusRTU:
                        {
                            SerialportMasterComponent serialport = new SerialportMasterComponent(item, MysqlMethod)
                            {
                                MysqlMethod = MysqlMethod
                            };
                            serialport.MyWorkState = true;
                            Field4Components.Add(serialport);
                        }
                        break;

                        case GatewayTypeEnum.ModbusTCP:
                        {
                            TCPMasterComponent TCP = new TCPMasterComponent(item, MysqlMethod)
                            {
                                MysqlMethod = MysqlMethod
                            };
                            TCP.MyWorkState = true;
                            Field4Components.Add(TCP);
                        }
                        break;
                        }
                    }
                }
                #endregion

                #region 建立按鈕物件
                NavigationFrame = new NavigationFrame()
                {
                    Dock = DockStyle.Fill
                };
                NavigationFrame.Parent = ViewpanelControl;
                ButtonMethod           = new ButtonMethod()
                {
                    Form1 = this, navigationFrame = NavigationFrame
                };
                ButtonMethod.AccordionLoad(accordionControl1, ButtonSetting);
                #endregion

                #region 建立畫面
                foreach (var Componentitem in Field4Components)
                {
                    foreach (var Absprotocolitem in Componentitem.ElectricAbsProtocols)
                    {
                        ElectricAbsProtocols.Add(Absprotocolitem);
                    }
                }
                #region 主畫面
                MainUserControl main = new MainUserControl(MysqlMethod, ElectricAbsProtocols)
                {
                    Dock = DockStyle.Fill
                };
                NavigationFrame.AddPage(main);
                Field4UserControls.Add(main);
                #endregion
                #region 報表畫面
                ChartUserControl chart = new ChartUserControl(MysqlMethod)
                {
                    Dock = DockStyle.Fill
                };
                NavigationFrame.AddPage(chart);
                Field4UserControls.Add(chart);
                #endregion
                #region 月報表畫面
                xtraReportUserControl = new XtraReportUserControl(MysqlMethod)
                {
                    Dock = DockStyle.Fill
                };
                NavigationFrame.AddPage(xtraReportUserControl);
                #endregion
                #endregion
            }
            timer1.Interval = 1000;
            timer1.Enabled  = true;
        }