private void SavesimpleButton_Click(object sender, EventArgs e)
 {
     if (Form1.ConnectionFlag)
     {
         if (SqlMethod.Updata_ElectricConfig(NewDeviceNametextEdit.Text, GatewayIndex, DeviceIndex))
         {
             ElectricConfigs = SqlMethod.Search_Electricconfig();
             Form1.billingSheetUserControl.Create_CheckedListBoxItem(ElectricConfigs);
             Form1.dataReportUserControl.DeviceItemRefresh(ElectricConfigs);
         }
     }
     else
     {
         foreach (var item in ElectricConfigs)
         {
             if (item.DeviceID == Convert.ToInt32(DeviceIDlabelControl.Text))
             {
                 item.DeviceName = NewDeviceNametextEdit.Text;
                 break;
             }
         }
         Form1.billingSheetUserControl.Create_CheckedListBoxItem(ElectricConfigs);
         Form1.dataReportUserControl.DeviceItemRefresh(ElectricConfigs);
     }
     /*復原GIA切換畫面旗標*/
     Form1.LockFlag   = Form1.AfterLockFlag;
     Form1.FlyoutFlag = false;
     Form1.flyout.Close();
 }
Example #2
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     #region 自動登出
     PageIndex = NavigationFrame.SelectedPageIndex;
     TimeSpan timeSpan = DateTime.Now.Subtract(UserTime);
     if (timeSpan.TotalSeconds > 600 && AdministraturFlag)
     {
         UserbarButtonItem_ItemClick(null, null);
     }
     #endregion
     if (ConnectionFlag)
     {
         ElectricConfigs = SqlMethod.Search_Electricconfig();//電表設備資訊
         AbsProtocols    = new List <AbsProtocol>();
         foreach (var item in ModbusComponents)
         {
             foreach (var dataitem in item.AbsProtocols)
             {
                 AbsProtocols.Add(dataitem);
             }
         }
         if (SqlComponent != null)
         {
             SqlComponent.AbsProtocols = AbsProtocols;
         }
     }
     if (field4UserControls.Count > NavigationFrame.SelectedPageIndex)
     {
         field4UserControls[NavigationFrame.SelectedPageIndex].AbsProtocols    = AbsProtocols;
         field4UserControls[NavigationFrame.SelectedPageIndex].ElectricConfigs = ElectricConfigs;
         field4UserControls[NavigationFrame.SelectedPageIndex].TextChange();
     }
     ComponentFail();
 }
 public ChargingPileUserControl(List <ElectricConfig> electricConfigs, SqlMethod sqlMethod, Form1 form1, List <GatewayConfig> gatewayConfigs)
 {
     InitializeComponent();
     Form1 = form1;
     foreach (var item in electricConfigs)
     {
         if (!item.TotalMeterFlag)//子電表
         {
             if (Form1.ConnectionFlag)
             {
                 SubMeterUserControl subMeter = new SubMeterUserControl(item, sqlMethod, form1, gatewayConfigs)
                 {
                     SqlMethod = sqlMethod, Location = new Point(5 + 340 * (SubMeterIndex % 5), 2 + 225 * (SubMeterIndex / 5))
                 }; SubMeterIndex++;
                 SubMeters.Add(subMeter);
                 xtraScrollableControl1.Controls.Add(subMeter);
             }
             else
             {
                 SubMeterUserControl subMeter = new SubMeterUserControl(item, sqlMethod, form1, gatewayConfigs)
                 {
                     SqlMethod = sqlMethod, Location = new Point(5 + 340 * (SubMeterIndex % 5), 2 + 225 * (SubMeterIndex / 5)), ElectricConfigs = electricConfigs
                 }; SubMeterIndex++;
                 SubMeters.Add(subMeter);
                 xtraScrollableControl1.Controls.Add(subMeter);
             }
         }
     }
 }
Example #4
0
        public void InsertMethod()
        {
            var contact = new SqlMethod();
            var db      = new AccessNorthwind("C:/Northwind.mdb");

            db.SqlMethods.InsertOnSubmit(contact);
            db.SubmitChanges();
            Assert.AreEqual(NorthwindDatabase.SqlMethodAction.InsertContact, db.SqlAction);
        }
 public ChargingPileView(List <ElectricConfig> electricConfigs, SqlMethod sqlMethod, Form1 form1, List <GatewayConfig> gatewayConfigs)
 {
     InitializeComponent();
     Form1 = form1;
     if (electricConfigs != null)
     {
         foreach (var item in electricConfigs)
         {
             if (item.TotalMeterFlag)//總電表
             {
                 if (Form1.ConnectionFlag)
                 {
                     MasterMeterUserControl masterMeter = new MasterMeterUserControl(item, sqlMethod, form1, gatewayConfigs)
                     {
                         SqlMethod = sqlMethod
                     };
                     MasterMeters.Add(masterMeter);
                     MasterMetenavigationFrame.AddPage(masterMeter);
                 }
                 else
                 {
                     MasterMeterUserControl masterMeter = new MasterMeterUserControl(item, sqlMethod, form1, gatewayConfigs)
                     {
                         SqlMethod = sqlMethod, ElectricConfigs = electricConfigs
                     };
                     MasterMeters.Add(masterMeter);
                     MasterMetenavigationFrame.AddPage(masterMeter);
                 }
             }
         }
         ChargingPileUserControl = new ChargingPileUserControl(electricConfigs, sqlMethod, form1, gatewayConfigs)
         {
             SqlMethod = sqlMethod, GatewayConfigs = GatewayConfigs
         };
         ChargingPilepanelControl.Controls.Add(ChargingPileUserControl);
         ChangeViewTime = DateTime.Now;
     }
     else
     {
         Log.Error("無電表資訊,請檢查資料");
     }
 }
Example #6
0
 public SubMeterUserControl(ElectricConfig electricConfig, SqlMethod sqlMethod, Form1 form1, List <GatewayConfig> gatewayConfigs)
 {
     InitializeComponent();
     GatewayConfigs = gatewayConfigs;
     Form1          = form1;
     groupControl.CustomHeaderButtons[0].Properties.Image = imageCollection1.Images["aligncenter"];
     ValueFont = NowkWlabelControl.Font;//即時用電、本日累積用電、昨日累積用電、總累積用電 字型大小一樣
     if (electricConfig != null && Form1.ConnectionFlag)
     {
         groupControl.Text = $"{electricConfig.DeviceName}";                                                             //電表名稱
         var NowkWh   = sqlMethod.Search_ElectricTotalPrice(0, electricConfig.GatewayIndex, electricConfig.DeviceIndex); //本日累積用電度
         var AfterkWh = sqlMethod.Search_ElectricTotalPrice(1, electricConfig.GatewayIndex, electricConfig.DeviceIndex); //昨日累積用電度
         var TotalkWh = sqlMethod.Search_ElectricTotalPrice(3, electricConfig.GatewayIndex, electricConfig.DeviceIndex); //總累積用電度
         if (NowkWh.Count > 0)
         {
             NowkWhlabelControl.Text = NowkWh[0].KwhTotal.ToString("F1");
         }
         if (AfterkWh.Count > 0)
         {
             AfterkWhlabelControl.Text = AfterkWh[0].KwhTotal.ToString("F1");
         }
         if (TotalkWh.Count > 0)
         {
             TotalkWhlabelControl.Appearance.Font = CalculateFontSize(TotalkWh[0].KwhTotal.ToString("F1"), TotalkWhlabelControl);
             TotalkWhlabelControl.Text            = TotalkWh[0].KwhTotal.ToString("F1");
         }
     }
     else if (!Form1.ConnectionFlag)
     {
         groupControl.Text = $"{electricConfig.DeviceName}"; //電表名稱
         var NowkWh   = rnd.Next(100, 300);                  //本日累積用電度
         var AfterkWh = rnd.Next(100, 300);                  //昨日累積用電度
         var TotalkWh = rnd.Next(10000, 30000);              //總累積用電度
         NowkWhlabelControl.Text   = NowkWh.ToString();
         AfterkWhlabelControl.Text = AfterkWh.ToString();
         TotalkWhlabelControl.Text = TotalkWh.ToString();
     }
     groupControl.CustomHeaderButtons[0].Properties.Enabled = false;
 }
Example #7
0
 public MasterMeterUserControl(ElectricConfig electricConfig, SqlMethod sqlMethod, Form1 form1, List <GatewayConfig> gatewayConfigs)
 {
     InitializeComponent();
     GatewayConfigs = gatewayConfigs;
     Form1          = form1;
     groupControl.CustomHeaderButtons[0].Properties.Image = imageCollection1.Images["aligncenter"];
     ValueFont = DaykWhlabelControl.Font;                                                                                //本日累積用電、本月累積用電 字型大小一樣
     if (electricConfig != null && Form1.ConnectionFlag)                                                                 //通訊
     {
         groupControl.Text = $"總表 - {electricConfig.DeviceName}";                                                        //電表名稱
         var NowkWh   = sqlMethod.Search_ElectricTotalPrice(0, electricConfig.GatewayIndex, electricConfig.DeviceIndex); //本日累積用電度
         var MonthkWh = sqlMethod.Search_ElectricTotalPrice(2, electricConfig.GatewayIndex, electricConfig.DeviceIndex); //本月累積用電度
         if (NowkWh.Count > 0)
         {
             DaykWhlabelControl.Appearance.Font = CalculateFontSize(NowkWh[0].KwhTotal.ToString("F1") + " kWh", DaykWhlabelControl);
             DaykWhlabelControl.Text            = NowkWh[0].KwhTotal.ToString("F1") + " kWh";
         }
         if (MonthkWh.Count > 0)
         {
             MonthkWhlabelControl.Appearance.Font = CalculateFontSize(MonthkWh[0].KwhTotal.ToString("F1") + " kWh", MonthkWhlabelControl);
             MonthkWhlabelControl.Text            = MonthkWh[0].KwhTotal.ToString("F1") + " kWh";
         }
     }
     else if (!Form1.ConnectionFlag)                             //Demo
     {
         groupControl.Text = $"總表 -{electricConfig.DeviceName}"; //電表名稱
         var NowkWh   = rnd.Next(100, 300);                      //本日累積用電度
         var MonthkWh = rnd.Next(3000, 5000);                    //本月累積用電度
         DaykWhlabelControl.Text   = NowkWh.ToString() + " kWh";
         MonthkWhlabelControl.Text = MonthkWh.ToString() + " kWh";
     }
     #region 曲線圖
     LinechartControl.Legend.Direction  = LegendDirection.TopToBottom;                                          //線條說明的排序
     LinechartControl.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;                                //線條說明顯示
     LinechartControl.CrosshairOptions.CrosshairLabelMode          = CrosshairLabelMode.ShowCommonForAllSeries; //顯示全部線條內容
     LinechartControl.CrosshairOptions.LinesMode                   = CrosshairLinesMode.Auto;                   //自動獲取點上面的數值
     LinechartControl.CrosshairOptions.GroupHeaderTextOptions.Font = new System.Drawing.Font("微軟正黑體", 12);
     LinechartControl.CrosshairOptions.ShowArgumentLabels          = true;                                      //是否顯示Y軸垂直線
     LinechartControl.SideBySideEqualBarWidth = false;                                                          //線條是否需要相等寬度
     TotalMeterSeries = new Series("總表累積量", ViewType.Line);
     if (sqlMethod != null && Form1.ConnectionFlag)
     {
         var SQLline = sqlMethod.Search_ThreePhaseElectricMeter_Log(DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("yyyyMMdd"), electricConfig.GatewayIndex, electricConfig.DeviceIndex);
         TotalMeterSeries.DataSource         = SQLline;
         TotalMeterSeries.ArgumentDataMember = "ttimen";
         TotalMeterSeries.ValueDataMembers.AddRange(new string[] { "kw" });
     }
     else
     {
         var SQLline = Create_Line();
         TotalMeterSeries.DataSource         = SQLline;
         TotalMeterSeries.ArgumentDataMember = "Argument";
         TotalMeterSeries.ValueDataMembers.AddRange(new string[] { "Value" });
     }
     TotalMeterSeries.CrosshairLabelPattern = "{S} \r時間 : {A:yyyy-MM-dd HH:mm}\r{V:0.##} kW";
     //TotalMeterSeries.LabelsVisibility = DefaultBoolean.False;
     if (LinechartControl != null)
     {
         if (LinechartControl.Series.Count == 0)
         {
             LinechartControl.Series.Add(TotalMeterSeries);
         }
     }
     if (TotalMeterSeries.DataSource != null && LinechartControl.Series.Count > 0)
     {
         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.Angle                    = 90;
             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 = false;//是否顯示Y軸垂直線
     }
     LineTime = DateTime.Now;
     groupControl.CustomHeaderButtons[0].Properties.Enabled = false;
     #endregion
 }
Example #8
0
        public override void TextChange()
        {
            if (ElectricConfig != null && Form1.ConnectionFlag)
            {
                groupControl.CustomHeaderButtons[0].Properties.Enabled = Form1.AdministraturFlag;//更改名稱按鈕
                ElectricEnumType = (ElectricEnumType)ElectricConfig.ElectricEnumType;
                PhaseEnumType    = (PhaseEnumType)ElectricConfig.PhaseEnumType;
                #region 電表名稱
                if (groupControl.Text != $"總表 - {ElectricConfig.DeviceName}")
                {
                    groupControl.Text = $"總表 - {ElectricConfig.DeviceName}";
                }
                #endregion
                #region 電表數值
                var Data = AbsProtocols.Where(g => g.GatewayIndex == ElectricConfig.GatewayIndex & g.DeviceIndex == ElectricConfig.DeviceIndex).ToList();
                if (Data.Count > 0)
                {
                    switch (ElectricEnumType)
                    {
                    case ElectricEnumType.PA310:
                    {
                        PA310Protocol protocol = (PA310Protocol)Data[0];
                        RSvlabelControl.Text = protocol.RSv.ToString("F2");
                        STvlabelControl.Text = protocol.STv.ToString("F2");
                        TRvlabelControl.Text = protocol.TRv.ToString("F2");
                        RalabelControl.Text  = protocol.RA.ToString("F2");
                        SalabelControl.Text  = protocol.SA.ToString("F2");
                        TalabelControl.Text  = protocol.TA.ToString("F2");
                        PFlabelControl.Text  = protocol.PF.ToString("F2");
                        kWlabelControl.Text  = protocol.kW.ToString("F2");
                        kWhlabelControl.Text = protocol.kWh.ToString("F2");
                    }
                    break;

                    case ElectricEnumType.HC660:
                    {
                        HC6600Protocol protocol = (HC6600Protocol)Data[0];
                        RSvlabelControl.Text = protocol.RSv.ToString("F2");
                        STvlabelControl.Text = protocol.STv.ToString("F2");
                        TRvlabelControl.Text = protocol.TRv.ToString("F2");
                        RalabelControl.Text  = protocol.RA.ToString("F2");
                        SalabelControl.Text  = protocol.SA.ToString("F2");
                        TalabelControl.Text  = protocol.TA.ToString("F2");
                        PFlabelControl.Text  = protocol.PF.ToString("F2");
                        kWlabelControl.Text  = protocol.kW.ToString("F2");
                        kWhlabelControl.Text = protocol.kWh.ToString("F2");
                    }
                    break;

                    case ElectricEnumType.CPM6:
                    {
                        CPM6Protocol protocol = (CPM6Protocol)Data[0];
                        RSvlabelControl.Text = protocol.RSv.ToString("F2");
                        STvlabelControl.Text = protocol.STv.ToString("F2");
                        TRvlabelControl.Text = protocol.TRv.ToString("F2");
                        RalabelControl.Text  = protocol.RA.ToString("F2");
                        SalabelControl.Text  = protocol.SA.ToString("F2");
                        TalabelControl.Text  = protocol.TA.ToString("F2");
                        PFlabelControl.Text  = protocol.PF.ToString("F2");
                        kWlabelControl.Text  = protocol.kW.ToString("F2");
                        kWhlabelControl.Text = protocol.kWh.ToString("F2");
                    }
                    break;

                    case ElectricEnumType.PA60:
                    {
                        PA60Protocol protocol = (PA60Protocol)Data[0];
                        RSvlabelControl.Text = protocol.RSv[ElectricConfig.LoopEnumType].ToString("F2");
                        STvlabelControl.Text = protocol.STv[ElectricConfig.LoopEnumType].ToString("F2");
                        TRvlabelControl.Text = protocol.TRv[ElectricConfig.LoopEnumType].ToString("F2");
                        RalabelControl.Text  = protocol.RA[ElectricConfig.LoopEnumType].ToString("F2");
                        SalabelControl.Text  = protocol.SA[ElectricConfig.LoopEnumType].ToString("F2");
                        TalabelControl.Text  = protocol.TA[ElectricConfig.LoopEnumType].ToString("F2");
                        PFlabelControl.Text  = protocol.PF[ElectricConfig.LoopEnumType].ToString("F2");
                        kWlabelControl.Text  = protocol.kW[ElectricConfig.LoopEnumType].ToString("F2");
                        kWhlabelControl.Text = protocol.kWh[ElectricConfig.LoopEnumType].ToString("F2");
                    }
                    break;

                    case ElectricEnumType.ABBM2M:
                    {
                        ABBM2MProtocol protocol = (ABBM2MProtocol)Data[0];
                        RSvlabelControl.Text = protocol.RSv.ToString("F2");
                        STvlabelControl.Text = protocol.STv.ToString("F2");
                        TRvlabelControl.Text = protocol.TRv.ToString("F2");
                        RalabelControl.Text  = protocol.RA.ToString("F2");
                        SalabelControl.Text  = protocol.SA.ToString("F2");
                        TalabelControl.Text  = protocol.TA.ToString("F2");
                        PFlabelControl.Text  = protocol.PF.ToString("F2");
                        kWlabelControl.Text  = protocol.kW.ToString("F2");
                        kWhlabelControl.Text = protocol.kWh.ToString("F2");
                    }
                    break;

                    case ElectricEnumType.PM200:
                    {
                        PM200Protocol protocol = (PM200Protocol)Data[0];
                        RSvlabelControl.Text = protocol.RSv.ToString("F2");
                        STvlabelControl.Text = protocol.STv.ToString("F2");
                        TRvlabelControl.Text = protocol.TRv.ToString("F2");
                        RalabelControl.Text  = protocol.RA.ToString("F2");
                        SalabelControl.Text  = protocol.SA.ToString("F2");
                        TalabelControl.Text  = protocol.TA.ToString("F2");
                        PFlabelControl.Text  = protocol.PF.ToString("F2");
                        kWlabelControl.Text  = protocol.kW.ToString("F2");
                        kWhlabelControl.Text = protocol.kWh.ToString("F2");
                    }
                    break;

                    case ElectricEnumType.TWCPM4:
                    {
                        TWCPM4Protocol protocol = (TWCPM4Protocol)Data[0];
                        RSvlabelControl.Text = protocol.RSv.ToString("F2");
                        STvlabelControl.Text = protocol.STv.ToString("F2");
                        TRvlabelControl.Text = protocol.TRv.ToString("F2");
                        RalabelControl.Text  = protocol.RA.ToString("F2");
                        SalabelControl.Text  = protocol.SA.ToString("F2");
                        TalabelControl.Text  = protocol.TA.ToString("F2");
                        PFlabelControl.Text  = protocol.PF.ToString("F2");
                        kWlabelControl.Text  = protocol.kW.ToString("F2");
                        kWhlabelControl.Text = protocol.kWh.ToString("F2");
                    }
                    break;
                    }
                }
                #endregion

                var NowkWh   = SqlMethod.Search_ElectricTotalPrice(0, ElectricConfig.GatewayIndex, ElectricConfig.DeviceIndex); //本日累積用電度
                var MonthkWh = SqlMethod.Search_ElectricTotalPrice(2, ElectricConfig.GatewayIndex, ElectricConfig.DeviceIndex); //本月累積用電度
                if (NowkWh.Count > 0)
                {
                    DaykWhlabelControl.Appearance.Font = CalculateFontSize(NowkWh[0].KwhTotal.ToString("F1") + " kWh", DaykWhlabelControl);
                    DaykWhlabelControl.Text            = NowkWh[0].KwhTotal.ToString("F1") + " kWh";
                }
                if (MonthkWh.Count > 0)
                {
                    MonthkWhlabelControl.Appearance.Font = CalculateFontSize(MonthkWh[0].KwhTotal.ToString("F1") + " kWh", MonthkWhlabelControl);
                    MonthkWhlabelControl.Text            = MonthkWh[0].KwhTotal.ToString("F1") + " kWh";
                }
                #region 曲線圖
                TimeSpan timeSpan = DateTime.Now.Subtract(LineTime);
                if (timeSpan.TotalSeconds > 20)
                {
                    if (SqlMethod != null)
                    {
                        var SQLline = SqlMethod.Search_ThreePhaseElectricMeter_Log(DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("yyyyMMdd"), ElectricConfig.GatewayIndex, ElectricConfig.DeviceIndex);
                        TotalMeterSeries.DataSource = SQLline;
                    }
                    LinechartControl.Refresh();
                    LineTime = DateTime.Now;
                }
                #endregion
            }
            else if (!Form1.ConnectionFlag)
            {
                groupControl.CustomHeaderButtons[0].Properties.Enabled = Form1.AdministraturFlag;//更改名稱按鈕
                #region 電表名稱
                if (groupControl.Text != $"總表 - {ElectricConfig.DeviceName}")
                {
                    groupControl.Text = $"總表 - {ElectricConfig.DeviceName}";
                }
                #endregion
                RSvlabelControl.Text = (Convert.ToDouble(rnd.Next(2100, 2200)) / 10).ToString("F1");
                STvlabelControl.Text = (Convert.ToDouble(rnd.Next(2100, 2200)) / 10).ToString("F1");
                TRvlabelControl.Text = (Convert.ToDouble(rnd.Next(2100, 2200)) / 10).ToString("F1");
                RalabelControl.Text  = (Convert.ToDouble(rnd.Next(1100, 2200)) / 100).ToString("F2");
                SalabelControl.Text  = (Convert.ToDouble(rnd.Next(1100, 2200)) / 100).ToString("F2");
                TalabelControl.Text  = (Convert.ToDouble(rnd.Next(1100, 2200)) / 100).ToString("F2");
                PFlabelControl.Text  = (Convert.ToDouble(rnd.Next(9800, 10000)) / 100).ToString("F2");
                kWlabelControl.Text  = (Convert.ToDouble(rnd.Next(2000, 3000)) / 100).ToString("F2");
                kWhlabelControl.Text = (Convert.ToDouble(rnd.Next(21000, 22000)) / 100).ToString("F2");
            }
        }
Example #9
0
        public void SqlRecord()
        {
            while (myWorkState)
            {
                TimeSpan timeSpan = DateTime.Now.Subtract(ReadTime);
                if (timeSpan.TotalSeconds >= 30)
                {
                    try
                    {
                        if (AbsProtocols.Count > 0)
                        {
                            foreach (var item in AbsProtocols)
                            {
                                if (item.ConnectFlag)
                                {
                                    if (item.ElectricEnumType != -1)
                                    {
                                        ElectricEnumType = (Enums.ElectricEnumType)item.ElectricEnumType;
                                        switch (ElectricEnumType)
                                        {
                                        case Enums.ElectricEnumType.PA310:
                                        {
                                            PA310Protocol protocol      = (PA310Protocol)item;
                                            PhaseEnumType PhaseEnumType = (PhaseEnumType)item.PhaseEnumType;
                                            switch (PhaseEnumType)
                                            {
                                            case Enums.PhaseEnumType.ThreePhase:
                                                SqlMethod.Insert_ThreePhaseElectricMeter(protocol);
                                                break;

                                            case Enums.PhaseEnumType.SinglePhase:
                                                SqlMethod.Insert_SinglePhaseElectricMeter(protocol);
                                                break;
                                            }
                                        }
                                        break;

                                        case Enums.ElectricEnumType.HC660:
                                        {
                                            HC6600Protocol protocol      = (HC6600Protocol)item;
                                            PhaseEnumType  PhaseEnumType = (PhaseEnumType)item.PhaseEnumType;
                                            switch (PhaseEnumType)
                                            {
                                            case Enums.PhaseEnumType.ThreePhase:
                                                SqlMethod.Insert_ThreePhaseElectricMeter(protocol);
                                                break;

                                            case Enums.PhaseEnumType.SinglePhase:
                                                SqlMethod.Insert_SinglePhaseElectricMeter(protocol);
                                                break;
                                            }
                                        }
                                        break;

                                        case Enums.ElectricEnumType.CPM6:
                                        {
                                            CPM6Protocol  protocol      = (CPM6Protocol)item;
                                            PhaseEnumType PhaseEnumType = (PhaseEnumType)item.PhaseEnumType;
                                            switch (PhaseEnumType)
                                            {
                                            case Enums.PhaseEnumType.ThreePhase:
                                                SqlMethod.Insert_ThreePhaseElectricMeter(protocol);
                                                break;

                                            case Enums.PhaseEnumType.SinglePhase:
                                                SqlMethod.Insert_SinglePhaseElectricMeter(protocol);
                                                break;
                                            }
                                        }
                                        break;

                                        case Enums.ElectricEnumType.PA60:
                                        {
                                            PA60Protocol  protocol      = (PA60Protocol)item;
                                            PhaseEnumType PhaseEnumType = (PhaseEnumType)item.PhaseEnumType;
                                            switch (PhaseEnumType)
                                            {
                                            case Enums.PhaseEnumType.ThreePhase:
                                                SqlMethod.Insert_ThreePhaseElectricMeter(protocol);
                                                break;

                                            case Enums.PhaseEnumType.SinglePhase:
                                                SqlMethod.Insert_SinglePhaseElectricMeter(protocol);
                                                break;
                                            }
                                        }
                                        break;

                                        case Enums.ElectricEnumType.ABBM2M:
                                        {
                                            ABBM2MProtocol protocol      = (ABBM2MProtocol)item;
                                            PhaseEnumType  PhaseEnumType = (PhaseEnumType)item.PhaseEnumType;
                                            switch (PhaseEnumType)
                                            {
                                            case Enums.PhaseEnumType.ThreePhase:
                                                SqlMethod.Insert_ThreePhaseElectricMeter(protocol);
                                                break;

                                            case Enums.PhaseEnumType.SinglePhase:
                                                SqlMethod.Insert_SinglePhaseElectricMeter(protocol);
                                                break;
                                            }
                                        }
                                        break;

                                        case Enums.ElectricEnumType.PM200:
                                        {
                                            PM200Protocol protocol = (PM200Protocol)item;
                                            SqlMethod.Insert_ThreePhaseElectricMeter(protocol);
                                        }
                                        break;

                                        case Enums.ElectricEnumType.TWCPM4:
                                        {
                                            TWCPM4Protocol protocol      = (TWCPM4Protocol)item;
                                            PhaseEnumType  PhaseEnumType = (PhaseEnumType)item.PhaseEnumType;
                                            switch (PhaseEnumType)
                                            {
                                            case Enums.PhaseEnumType.ThreePhase:
                                                SqlMethod.Insert_ThreePhaseElectricMeter(protocol);
                                                break;

                                            case Enums.PhaseEnumType.SinglePhase:
                                                SqlMethod.Insert_SinglePhaseElectricMeter(protocol);
                                                break;
                                            }
                                        }
                                        break;
                                        }
                                    }
                                }
                            }
                            ComponentFlag = false;
                            ReadTime      = DateTime.Now;
                        }
                    }
                    catch (ThreadAbortException) { }
                    catch (Exception ex) { ComponentFlag = true; ErrorString = "資料庫連結失敗!"; Log.Error(ex, "資料庫紀錄失敗"); }
                }
                else
                {
                    Thread.Sleep(80);
                }
            }
        }
Example #10
0
        public override void TextChange()
        {
            if (ElectricConfig != null && Form1.ConnectionFlag)
            {
                groupControl.CustomHeaderButtons[0].Properties.Enabled = Form1.AdministraturFlag;//更改名稱按鈕
                #region 電表名稱
                if (groupControl.Text != $"{ElectricConfig.DeviceName}")
                {
                    groupControl.Text = $"{ElectricConfig.DeviceName}";
                }
                #endregion
                #region 電表數值
                var Data = AbsProtocols.Where(g => g.GatewayIndex == ElectricConfig.GatewayIndex & g.DeviceIndex == ElectricConfig.DeviceIndex).ToList();
                if (Data.Count > 0)
                {
                    ElectricEnumType = (ElectricEnumType)Data[0].ElectricEnumType;
                    switch (ElectricEnumType)
                    {
                    case ElectricEnumType.PA310:
                    {
                        PA310Protocol protocol = (PA310Protocol)Data[0];
                        NowkWlabelControl.Text = protocol.kW.ToString("F2");
                    }
                    break;

                    case ElectricEnumType.HC660:
                    {
                        {
                            HC6600Protocol protocol = (HC6600Protocol)Data[0];
                            NowkWlabelControl.Text = protocol.kW.ToString("F2");
                        }
                    }
                    break;

                    case ElectricEnumType.CPM6:
                    {
                        {
                            CPM6Protocol protocol = (CPM6Protocol)Data[0];
                            NowkWlabelControl.Text = protocol.kW.ToString("F2");
                        }
                    }
                    break;

                    case ElectricEnumType.PA60:
                    {
                        {
                            PA60Protocol protocol = (PA60Protocol)Data[0];
                            NowkWlabelControl.Text = protocol.kW[ElectricConfig.LoopEnumType].ToString("F2");
                        }
                    }
                    break;

                    case ElectricEnumType.ABBM2M:
                    {
                        {
                            ABBM2MProtocol protocol = (ABBM2MProtocol)Data[0];
                            NowkWlabelControl.Text = protocol.kW.ToString("F2");
                        }
                    }
                    break;

                    case ElectricEnumType.PM200:
                    {
                        {
                            PM200Protocol protocol = (PM200Protocol)Data[0];
                            NowkWlabelControl.Text = protocol.kW.ToString("F2");
                        }
                    }
                    break;

                    case ElectricEnumType.TWCPM4:
                    {
                        {
                            TWCPM4Protocol protocol = (TWCPM4Protocol)Data[0];
                            NowkWlabelControl.Text = protocol.kW.ToString("F2");
                        }
                    }
                    break;
                    }
                }
                #endregion
            }
            else if (!Form1.ConnectionFlag)
            {
                groupControl.CustomHeaderButtons[0].Properties.Enabled = Form1.AdministraturFlag;//更改名稱按鈕
                #region 電表名稱
                if (groupControl.Text != $"{ElectricConfig.DeviceName}")
                {
                    groupControl.Text = $"{ElectricConfig.DeviceName}";
                }
                #endregion
                NowkWlabelControl.Text = rnd.Next(100, 300).ToString();
            }
            if (Form1.ConnectionFlag)
            {
                var NowkWh   = SqlMethod.Search_ElectricTotalPrice(0, ElectricConfig.GatewayIndex, ElectricConfig.DeviceIndex); //本日累積用電度
                var AfterkWh = SqlMethod.Search_ElectricTotalPrice(1, ElectricConfig.GatewayIndex, ElectricConfig.DeviceIndex); //昨日累積用電度
                var TotalkWh = SqlMethod.Search_ElectricTotalPrice(3, ElectricConfig.GatewayIndex, ElectricConfig.DeviceIndex); //總累積用電度
                if (NowkWh.Count > 0)
                {
                    NowkWhlabelControl.Text = NowkWh[0].KwhTotal.ToString("F1");
                }
                if (AfterkWh.Count > 0)
                {
                    AfterkWhlabelControl.Text = AfterkWh[0].KwhTotal.ToString("F1");
                }
                if (TotalkWh.Count > 0)
                {
                    TotalkWhlabelControl.Appearance.Font = CalculateFontSize(TotalkWh[0].KwhTotal.ToString("F1"), TotalkWhlabelControl);
                    TotalkWhlabelControl.Text            = TotalkWh[0].KwhTotal.ToString("F1");
                }
            }
        }
Example #11
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;
            }
        }
Example #12
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;
        }
Example #13
0
        private void SearchsimpleButton_Click(object sender, EventArgs e)
        {
            string                    AfterStartTime;
            string                    AfterEndTime;
            string                    NowStartTime;
            string                    NowEndTime;
            int                       RoomCheck     = 0;                   //勾選數量
            bool                      OddEvenFlag   = false;               //奇偶數
            List <string>             RoomName      = new List <string>(); //勾選住戶名
            List <ElectricTotalPrice> NowbillData   = new List <ElectricTotalPrice>();
            List <ElectricTotalPrice> AfterbillData = new List <ElectricTotalPrice>();

            if (Convert.ToDateTime(StartdateEdit.EditValue).Month == 1)
            {
                AfterStartTime = $"{Convert.ToDateTime(StartdateEdit.EditValue).AddYears(-1).Year}1201";
                AfterEndTime   = $"{Convert.ToDateTime(StartdateEdit.EditValue).AddYears(-1).Year}1231";
            }
            else
            {
                AfterStartTime = $"{Convert.ToDateTime(StartdateEdit.EditValue).Year}{Convert.ToDateTime(StartdateEdit.EditValue).AddMonths(-1).Month}01";
                AfterEndTime   = $"{Convert.ToDateTime(StartdateEdit.EditValue).Year}{Convert.ToDateTime(StartdateEdit.EditValue).AddMonths(-1).Month}{DateTime.DaysInMonth(Convert.ToDateTime(StartdateEdit.EditValue).Year, Convert.ToDateTime(StartdateEdit.EditValue).AddMonths(-1).Month)}";
            }
            NowStartTime = Convert.ToDateTime(StartdateEdit.EditValue).ToString("yyyyMM01");
            NowEndTime   = Convert.ToDateTime(StartdateEdit.EditValue).ToString("yyyyMM") + DateTime.DaysInMonth(Convert.ToDateTime(StartdateEdit.EditValue).Year, Convert.ToDateTime(StartdateEdit.EditValue).Month);
            #region 塞入勾選房間房號
            foreach (var item in boxItems)
            {
                if (item.CheckState == CheckState.Checked)
                {
                    ElectricConfig electric = (ElectricConfig)item.Tag;
                    RoomName.Add(electric.DeviceName);
                    if (Form1.ConnectionFlag)
                    {
                        var nowbilldata = SqlMethod.Search_ElectricTotalPrice_Billing(NowStartTime, NowEndTime, electric.GatewayIndex, electric.DeviceIndex);
                        NowbillData.Add(nowbilldata);
                        var afterbilldata = SqlMethod.Search_ElectricTotalPrice_Billing(AfterStartTime, AfterEndTime, electric.GatewayIndex, electric.DeviceIndex);
                        AfterbillData.Add(afterbilldata);
                    }
                    else
                    {
                        var nowbilldata = new ElectricTotalPrice()
                        {
                            Price = rnd.Next(500, 1000), KwhTotal = rnd.Next(100, 200)
                        };
                        NowbillData.Add(nowbilldata);
                        var afterbilldata = new ElectricTotalPrice()
                        {
                            Price = rnd.Next(500, 1000), KwhTotal = rnd.Next(100, 200)
                        };
                        AfterbillData.Add(afterbilldata);
                    }
                    RoomCheck++;
                }
            }
            #endregion
            #region 判斷奇數偶數
            if (RoomCheck % 2 == 0)
            {
                OddEvenFlag = true;//偶數
            }
            else
            {
                OddEvenFlag = false;//奇數
            }
            #endregion
            BillingSheetXtraReport[] billingSheets = new BillingSheetXtraReport[RoomCheck / 2 + RoomCheck % 2]; //計費單數量
            XtraReport xtraReport = new XtraReport();
            if (OddEvenFlag)                                                                                    //偶數
            {
                for (int i = 0; i < billingSheets.Length; i++)
                {
                    billingSheets[i] = new BillingSheetXtraReport()
                    {
                        bankAccount = BankaccountSetting
                    };
                    billingSheets[i].Create_BillingSheet(Convert.ToDateTime(StartdateEdit.EditValue), true, RoomName[i + i], NowbillData[i + i], AfterbillData[i + i], RoomName[i + i + 1], NowbillData[i + i + 1], AfterbillData[i + 1]);
                    billingSheets[i].CreateDocument();
                    xtraReport.Pages.AddRange(billingSheets[i].Pages);
                }
                documentViewer1.DocumentSource = xtraReport;
            }
            else//奇數
            {
                for (int i = 0; i < billingSheets.Length; i++)
                {
                    billingSheets[i] = new BillingSheetXtraReport()
                    {
                        bankAccount = BankaccountSetting
                    };
                    if (i != billingSheets.Length - 1)
                    {
                        billingSheets[i].Create_BillingSheet(Convert.ToDateTime(StartdateEdit.EditValue), true, RoomName[i + i], NowbillData[i + i], AfterbillData[i + i], RoomName[i + i + 1], NowbillData[i + i + 1], AfterbillData[i + 1]);
                    }
                    else
                    {
                        billingSheets[i].Create_BillingSheet(Convert.ToDateTime(StartdateEdit.EditValue), false, RoomName[i + i], NowbillData[i + i], AfterbillData[i + i]);
                    }
                    billingSheets[i].CreateDocument();
                    xtraReport.Pages.AddRange(billingSheets[i].Pages);
                }
                documentViewer1.DocumentSource = xtraReport;
            }
        }