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;
                }
            }
        }
 protected override void AfterMyWorkStateChanged(object sender, EventArgs e)
 {
     if (myWorkState)
     {
         var ElectricConfig = MysqlMethod.Search_ElectricConfig(GatewayConfig.GatewayIndex);
         foreach (var item in ElectricConfig)
         {
             ElectricTypeEnum electricTypeEnum = (ElectricTypeEnum)item.ElectricTypeEnum;
             switch (electricTypeEnum)
             {
             case ElectricTypeEnum.BAW_4C:
             {
                 BAW_4CProtocol protocol = new BAW_4CProtocol()
                 {
                     ID                 = (byte)item.DeviceID,
                     GatewayIndex       = item.GatewayIndex,
                     DeviceIndex        = item.DeviceIndex,
                     ElectricTypeEnum   = item.ElectricTypeEnum,
                     LoopTypeEnum       = item.LoopTypeEnum,
                     PhaseTypeEnum      = item.PhaseTypeEnum,
                     PhaseAngleTypeEnum = item.PhaseAngleTypeEnum,
                     MysqlMethod        = MysqlMethod
                 };
                 ElectricAbsProtocols.Add(protocol);
             }
             break;
             }
         }
         ComponentThread = new Thread(Analysis);
         ComponentThread.Start();
     }
     else
     {
         if (ComponentThread != null)
         {
             ComponentThread.Abort();
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 通訊錯誤泡泡視窗
 /// </summary>
 public void ComponentFail()
 {
     if (ElectricAbsProtocols.Count > 0)
     {
         var absprotocol = ElectricAbsProtocols.Where(g => g.ConnectFlag == false).ToList();
         if (absprotocol.Count > 0)
         {
             if (ErrorflyoutPanel == null)
             {
                 ErrorflyoutPanel = new FlyoutPanel()
                 {
                     OwnerControl = this,
                     Size         = new Size(1920, 68)
                 };
                 LabelControl label = new LabelControl()
                 {
                     Size = new Size(1920, 63)
                 };
                 label.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
                 label.Appearance.Font      = new Font("微軟正黑體", 30);
                 label.Appearance.ForeColor = Color.White;
                 label.Appearance.BackColor = Color.Red;
                 label.AutoSizeMode         = LabelAutoSizeMode.None;
                 label.Text = "通訊異常 !!";
                 ErrorflyoutPanel.Controls.Add(label);
                 ErrorflyoutPanel.Options.AnchorType = DevExpress.Utils.Win.PopupToolWindowAnchor.Bottom;
                 ErrorflyoutPanel.ShowPopup();
             }
             return;
         }
     }
     if (ErrorflyoutPanel != null)
     {
         ErrorflyoutPanel.HidePopup();
         ErrorflyoutPanel = null;
     }
 }
Esempio n. 4
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;
        }
Esempio n. 5
0
        protected override void AfterMyWorkStateChanged(object sender, EventArgs e)
        {
            if (myWorkState)
            {
                int    Baudate  = Convert.ToInt32(GatewayConfig.Rate.Split(',')[0]);
                int    DataBits = Convert.ToInt32(GatewayConfig.Rate.Split(',')[1]);
                string parity   = GatewayConfig.Rate.Split(',')[2];
                int    stopbits = Convert.ToInt32(GatewayConfig.Rate.Split(',')[3]);

                RS485          = new SerialPort(GatewayConfig.Location);
                RS485.BaudRate = Baudate;
                RS485.DataBits = DataBits;
                switch (parity)
                {
                case "N":
                {
                    RS485.Parity = Parity.None;
                }
                break;

                case "O":
                {
                    RS485.Parity = Parity.Odd;
                }
                break;

                case "E":
                {
                    RS485.Parity = Parity.Even;
                }
                break;
                }
                RS485.StopBits = (StopBits)stopbits;
                var ElectricConfig = MysqlMethod.Search_ElectricConfig(GatewayConfig.GatewayIndex);
                foreach (var item in ElectricConfig)
                {
                    ElectricTypeEnum electricTypeEnum = (ElectricTypeEnum)item.ElectricTypeEnum;
                    switch (electricTypeEnum)
                    {
                    case ElectricTypeEnum.BAW_4C:
                    {
                        BAW_4CProtocol protocol = new BAW_4CProtocol()
                        {
                            ID                 = (byte)item.DeviceID,
                            GatewayIndex       = item.GatewayIndex,
                            DeviceIndex        = item.DeviceIndex,
                            ElectricTypeEnum   = item.ElectricTypeEnum,
                            LoopTypeEnum       = item.LoopTypeEnum,
                            PhaseTypeEnum      = item.PhaseTypeEnum,
                            PhaseAngleTypeEnum = item.PhaseAngleTypeEnum,
                            MysqlMethod        = MysqlMethod
                        };
                        ElectricAbsProtocols.Add(protocol);
                    }
                    break;
                    }
                }
                ComponentThread = new Thread(Analysis);
                ComponentThread.Start();
            }
            else
            {
                if (RS485.IsOpen)
                {
                    RS485.Close();
                }
                if (ComponentThread != null)
                {
                    ComponentThread.Abort();
                }
            }
        }