Beispiel #1
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");
            }
        }
Beispiel #2
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");
                }
            }
        }
Beispiel #3
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);
                }
            }
        }
Beispiel #4
0
        protected override void AfterMyWorkStateChanged(object sender, EventArgs e)
        {
            if (myWorkState)
            {
                foreach (var item in ElectricConfigs)
                {
                    ElectricEnumType = (ElectricEnumType)item.ElectricEnumType;
                    switch (ElectricEnumType)
                    {
                    case ElectricEnumType.PA310:
                    {
                        PA310Protocol protocol = new PA310Protocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;

                    case ElectricEnumType.HC660:
                    {
                        HC6600Protocol protocol = new HC6600Protocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;

                    case ElectricEnumType.CPM6:
                    {
                        CPM6Protocol protocol = new CPM6Protocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;

                    case ElectricEnumType.PA60:
                    {
                        PA60Protocol protocol = new PA60Protocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;

                    case ElectricEnumType.ABBM2M:
                    {
                        ABBM2MProtocol protocol = new ABBM2MProtocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;

                    case ElectricEnumType.PM200:
                    {
                        PM200Protocol protocol = new PM200Protocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;

                    case ElectricEnumType.TWCPM4:
                    {
                        TWCPM4Protocol protocol = new TWCPM4Protocol()
                        {
                            GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ID = (byte)item.DeviceID, LoopEnumType = item.LoopEnumType, PhaseAngleEnumType = item.PhaseAngleEnumType, PhaseEnumType = item.PhaseEnumType, ElectricEnumType = item.ElectricEnumType
                        };
                        AbsProtocols.Add(protocol);
                    }
                    break;
                    }
                }
                ReadThread = new Thread(Analysis);
                ReadThread.Start();
            }
            else
            {
                if (ReadThread != null)
                {
                    ReadThread.Abort();
                }
            }
        }