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軸垂直線
        }
Пример #2
0
    public void SavePlayer()
    {
        Serialization();
        MysqlMethod mysql = new MysqlMethod();

        mysql.SaveAccountPlayer(mAccountId);
    }
Пример #3
0
 public void InsertSql()
 {
     if (ConnectFlag)
     {
         MysqlMethod.Insert_ThreePhaseElectricMeter_Log(this);
     }
 }
        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;
                }
            }
        }
Пример #5
0
 /// <summary>
 /// 月累積量公式
 /// </summary>
 private void Month_ElectricTotal()
 {
     TTime = DateTime.Now;
     ElectricTotals.Clear();
     foreach (var ElectricConfigitem in ElectricConfigs)
     {
         var ElectricTotal = MysqlMethod.Search_ElectricTotal($"{TTime:yyyyMM01}", $"{TTime:yyyyMM31}", ElectricConfigitem.GatewayIndex, ElectricConfigitem.DeviceIndex);
         for (int i = 0; i < DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); i++)
         {
             foreach (var item in ElectricTotal)
             {
                 if (i >= 9)
                 {
                     if (item.ttime == DateTime.Now.ToString("yyyyMM") + $"{i + 1}")
                     {
                         ElectricTotals.Add(item);
                     }
                     else
                     {
                         ElectricTotal electricTotal = new ElectricTotal()
                         {
                             ttimen       = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/") + $"{i + 1}" + " 00:00:00"),
                             GatewayIndex = ElectricConfigitem.GatewayIndex,
                             DeviceIndex  = ElectricConfigitem.DeviceIndex,
                             KwhTotal     = 0
                         };
                         ElectricTotals.Add(electricTotal);
                     }
                 }
                 else
                 {
                     if (item.ttime == DateTime.Now.ToString("yyyyMM") + $"0{i + 1}")
                     {
                         ElectricTotals.Add(item);
                     }
                     else
                     {
                         ElectricTotal electricTotal = new ElectricTotal()
                         {
                             ttimen       = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/") + $"0{i + 1}" + " 00:00:00"),
                             GatewayIndex = ElectricConfigitem.GatewayIndex,
                             DeviceIndex  = ElectricConfigitem.DeviceIndex,
                             KwhTotal     = 0
                         };
                         ElectricTotals.Add(electricTotal);
                     }
                 }
             }
         }
     }
 }
Пример #6
0
    void LoginGame()
    {
        var str = input.text;

        if (str == "")
        {
            return;
        }
        MysqlMethod mysqlMethod = new MysqlMethod();

        mysqlMethod.GetAccountPlayer(str);
        loginButton.enabled = false;
        Debug.Log("login success");
        SceneManager.LoadScene("gameTest_SK");
    }
Пример #7
0
 public ExportElectricSettingUserControl(ReportConfig reportConfig, ElectricConfig electricConfig, MysqlMethod mysql)
 {
     InitializeComponent();
     MysqlMethod                                = mysql;
     ReportConfig                               = reportConfig;
     groupControl1.Text                         = electricConfig.DeviceName;
     ElectricNotextEdit.Text                    = ReportConfig.ElectricNo;
     ElectricitySalePeriodtextEdit.Text         = ReportConfig.ElectricitySalePeriod.ToString();
     StartingDatetimeEdit.EditValue             = ReportConfig.StartingDate.ToString("yyyy/MM/dd");
     OfficialPricingStartDatetimeEdit.EditValue = ReportConfig.OfficialPricingStartDate.ToString("yyyy/MM/dd");
     PricStartTimetimeEdit.EditValue            = ReportConfig.PricStartTime.ToString("yyyy/MM/dd");
     PricEndTimetimeEdit.EditValue              = ReportConfig.PricEndTime.ToString("yyyy/MM/dd");
     ElectricityPurchaseRatetextEdit.Text       = ReportConfig.ElectricityPurchaseRate.ToString("#.####");
     DeviceCapacitytextEdit.Text                = ReportConfig.DeviceCapacity.ToString("#.###");
     PurchaseAndSaleCapacitytextEdit.Text       = ReportConfig.PurchaseAndSaleCapacity.ToString("#.###");
     RatetextEdit.Text                          = ReportConfig.Ratio.ToString();
 }
Пример #8
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;
 }
Пример #9
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++;
            }
        }
Пример #10
0
 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();
         }
     }
 }
Пример #11
0
 public XtraReportUserControl(MysqlMethod mysql)
 {
     InitializeComponent();
     StartdateEdit.Properties.ContextImageOptions.Image = imageCollection1.Images["calendar"];
     MysqlMethod = mysql;
 }
Пример #12
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);
            }
        }
Пример #13
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();
                }
            }
        }
Пример #14
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
 }
Пример #15
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
            }
        }
Пример #16
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;
        }
Пример #17
0
 public TCPMasterComponent(GatewayConfig gateway, MysqlMethod mysql)
 {
     InitializeComponent();
     GatewayConfig = gateway;
     MysqlMethod   = mysql;
 }
Пример #18
0
 private void Analysis()
 {
     while (myWorkState)
     {
         TimeSpan timeSpan = DateTime.Now.Subtract(ComponentTime);
         if (timeSpan.TotalMilliseconds >= 1000)
         {
             try
             {
                 #region Rs485通訊功能初始化
                 try
                 {
                     if (!RS485.IsOpen)
                     {
                         RS485.Open();
                     }
                 }
                 catch (ArgumentException)
                 {
                     Log.Error("通訊埠設定有誤");
                 }
                 catch (InvalidOperationException)
                 {
                     Log.Error("通訊埠被占用");
                 }
                 catch (IOException)
                 {
                     //Log.Error("通訊埠無效");
                 }
                 catch (Exception ex)
                 {
                     Log.Error(ex, "通訊埠發生不可預期的錯誤。");
                 }
                 #endregion
             }
             catch (Exception ex)
             {
                 Log.Error(ex, $"Connect Comport error.");
                 throw;
             }
             try
             {
                 master = ModbusFactoryExtensions.CreateRtuMaster(Factory, RS485);//建立RTU通訊
                 master.Transport.ReadTimeout = 500;
                 master.Transport.Retries     = 1;
                 int Index         = 0;
                 var ReportConfigs = MysqlMethod.Search_ReportConfig();
                 foreach (var item in ElectricAbsProtocols)
                 {
                     item.ReportConfig = ReportConfigs[Index];
                     item.ReadData(master);
                     Index++;
                     Thread.Sleep(10);
                 }
             }
             catch (ThreadAbortException) { }
             catch (Exception ex)
             {
                 Log.Error(ex, $"Connect to device({GatewayConfig.Location}) failed.");
                 foreach (var item in ElectricAbsProtocols)
                 {
                     item.ConnectFlag = false;
                 }
             }
             ComponentTime = DateTime.Now;
         }
         else
         {
             Thread.Sleep(80);
         }
     }
 }