private void Connection_Mysql()
        {
            while (myWorkState)
            {
                TimeSpan timeSpan = DateTime.Now.Subtract(ConnectionTime);
                if (timeSpan.TotalMilliseconds > 1000)
                {
                    CaseSettings = MySqlMethod.CaseLoad();
                    var Alarmdata = MySqlMethod.AiConfig_Compare_Load();
                    foreach (var item in Alarmdata)
                    {
                        var caseSetting = CaseSettings.Where(g => g.CaseNo == item.CaseNo).ToList()[0];
                        var value       = MySqlMethod.Ai64web(item);
                        var nowdata     = MySqlMethod.Alarm_Procedure(item, value);

                        var Adata = AiConfigs.Where(g => g.PK == item.PK).ToList();
                        if (Adata.Count > 0)
                        {
                            if (item.CompareType != Adata[0].CompareType)
                            {
                                switch (item.CompareType)
                                {
                                case 0:     //上限
                                {
                                    LineNotifyClass lineNotifyClass = new LineNotifyClass();
                                    lineNotifyClass.LineNotifyFunction(caseSetting.NotifyToken, $"\r案場名稱: {caseSetting.TitleName}\r點位名稱: {item.AiName}\r超過上限值: {item.AiMax}\r目前數值為 {nowdata}");
                                }
                                break;

                                case 1:     //正常
                                {
                                    LineNotifyClass lineNotifyClass = new LineNotifyClass();
                                    lineNotifyClass.LineNotifyFunction(caseSetting.NotifyToken, $"\r案場名稱: {caseSetting.TitleName}\r點位名稱: {item.AiName}\r上限值: {item.AiMax}\r下限值: {item.AiMin}\r恢復正常,目前數值為 {nowdata}");
                                }
                                break;

                                case 2:     //下限
                                {
                                    LineNotifyClass lineNotifyClass = new LineNotifyClass();
                                    lineNotifyClass.LineNotifyFunction(caseSetting.NotifyToken, $"\r案場名稱: {caseSetting.TitleName}\r點位名稱: {item.AiName}\r低於下限值: {item.AiMin}\r目前數值為 {nowdata}");
                                }
                                break;
                                }
                            }
                        }
                    }
                    AiConfigs      = Alarmdata;
                    ConnectionTime = DateTime.Now;
                }
                else
                {
                    Thread.Sleep(80);
                }
            }
        }
Пример #2
0
        private void Connection_Mysql()
        {
            while (myWorkState)
            {
                TimeSpan timeSpan = DateTime.Now.Subtract(ConnectionTime);
                if (timeSpan.TotalMilliseconds > 5000)
                {
                    CaseSettings = Ewatch_MySqlMethod.CaseLoad();
                    #region AI上下限
                    var Alarmdata = Ewatch_MySqlMethod.AiConfig_Compare_Load();
                    foreach (var item in Alarmdata)
                    {
                        var caseSetting = CaseSettings.Where(g => g.CaseNo == item.CaseNo).ToList()[0];
                        var value       = Ewatch_MySqlMethod.Ai64web(item);
                        if (value != null)
                        {
                            var nowdata = Ewatch_MySqlMethod.Alarm_Procedure(item, value);

                            var Adata = AiConfigs.Where(g => g.PK == item.PK).ToList();
                            if (Adata.Count > 0)
                            {
                                if (item.CompareType != Adata[0].CompareType)
                                {
                                    NotifyTypeEnum notifyTypeEnum = (NotifyTypeEnum)caseSetting.NotifyTypeEnum;
                                    switch (notifyTypeEnum)
                                    {
                                    case NotifyTypeEnum.None:
                                        break;

                                    case NotifyTypeEnum.Line:
                                    {
                                        switch (item.CompareType)
                                        {
                                        case 0:             //上限
                                        {
                                            LineNotifyClass lineNotifyClass = new LineNotifyClass();
                                            lineNotifyClass.LineNotifyFunction(caseSetting.NotifyToken, $"\r案場名稱: {caseSetting.TitleName}\r點位名稱: {item.AiName}\r超過上限值: {item.AiMax}\r目前數值為 {nowdata}");
                                        }
                                        break;

                                        case 1:             //正常
                                        {
                                            LineNotifyClass lineNotifyClass = new LineNotifyClass();
                                            lineNotifyClass.LineNotifyFunction(caseSetting.NotifyToken, $"\r案場名稱: {caseSetting.TitleName}\r點位名稱: {item.AiName}\r上限值: {item.AiMax}\r下限值: {item.AiMin}\r恢復正常,目前數值為 {nowdata}");
                                        }
                                        break;

                                        case 2:             //下限
                                        {
                                            LineNotifyClass lineNotifyClass = new LineNotifyClass();
                                            lineNotifyClass.LineNotifyFunction(caseSetting.NotifyToken, $"\r案場名稱: {caseSetting.TitleName}\r點位名稱: {item.AiName}\r低於下限值: {item.AiMin}\r目前數值為 {nowdata}");
                                        }
                                        break;
                                        }
                                    }
                                    break;

                                    case NotifyTypeEnum.Telegram:
                                    {
                                        switch (item.CompareType)
                                        {
                                        case 0:             //上限
                                        {
                                            TelegramBotClass telegramBotClass = new TelegramBotClass(caseSetting.NotifyApi)
                                            {
                                                Chat_ID = caseSetting.NotifyToken
                                            };
                                            telegramBotClass.Send_Message_Group($"\r案場名稱: {caseSetting.TitleName}\r點位名稱: {item.AiName}\r超過上限值: {item.AiMax}\r目前數值為 {nowdata}");
                                        }
                                        break;

                                        case 1:             //正常
                                        {
                                            TelegramBotClass telegramBotClass = new TelegramBotClass(caseSetting.NotifyApi)
                                            {
                                                Chat_ID = caseSetting.NotifyToken
                                            };
                                            telegramBotClass.Send_Message_Group($"\r案場名稱: {caseSetting.TitleName}\r點位名稱: {item.AiName}\r上限值: {item.AiMax}\r下限值: {item.AiMin}\r恢復正常,目前數值為 {nowdata}");
                                        }
                                        break;

                                        case 2:             //下限
                                        {
                                            TelegramBotClass telegramBotClass = new TelegramBotClass(caseSetting.NotifyApi)
                                            {
                                                Chat_ID = caseSetting.NotifyToken
                                            };
                                            telegramBotClass.Send_Message_Group($"\r案場名稱: {caseSetting.TitleName}\r點位名稱: {item.AiName}\r低於下限值: {item.AiMin}\r目前數值為 {nowdata}");
                                        }
                                        break;
                                        }
                                    }
                                    break;
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                    AiConfigs      = Alarmdata;
                    ConnectionTime = DateTime.Now;
                }
                else
                {
                    Thread.Sleep(80);
                }
            }
        }
Пример #3
0
        protected void Connection_Mysql()
        {
            while (myWorkState)
            {
                TimeSpan timeSpan = DateTime.Now.Subtract(ConnectionTime);
                if (timeSpan.TotalMilliseconds > 1000) //每一秒查詢動作
                {
                    var casevalue = MySqlMethod.CaseLoad();
                    foreach (var caseitem in casevalue)
                    {
                        if (caseitem.NotifyTypeEnum != 0)// 檢查是否使用發報功能 0 =不使用
                        {
                            var aivalue = MySqlMethod.AiLoad(caseitem);
                            foreach (var aiitem in aivalue)
                            {
                                if (aiitem.NotifyFlag)                               //AI點位需要發報
                                {
                                    if (MySqlMethod.AI64Load(aiitem))                //檢查即時數值是否超過時間
                                    {
                                        var TimeValue = MySqlMethod.Ai_Time(aiitem); //檢查發報數值是否達到
                                        if (TimeValue == null || TimeValue >= aiitem.TimeoutSpan)
                                        {
                                            NotifyTypeEnum notifyTypeEnum = (NotifyTypeEnum)caseitem.NotifyTypeEnum;
                                            switch (notifyTypeEnum)
                                            {
                                            case NotifyTypeEnum.None:
                                                break;

                                            case NotifyTypeEnum.Line:
                                            {
                                                LineNotifyClass lineNotifyClass = new LineNotifyClass();
                                                lineNotifyClass.LineNotifyFunction(caseitem.NotifyToken, $"設備名稱:{aiitem.AiName} \r最後上傳時間 : {MySqlMethod.AI_LastTime(aiitem)}\r上傳逾時請檢查");
                                            }
                                            break;

                                            case NotifyTypeEnum.Telegram:
                                            {
                                                TelegramBotClass telegramBotClass = new TelegramBotClass(caseitem.NotifyApi)
                                                {
                                                    Chat_ID = caseitem.NotifyToken
                                                };
                                                telegramBotClass.Send_Message_Group($"設備名稱:{aiitem.AiName} \r最後上傳時間 : {MySqlMethod.AI_LastTime(aiitem)}\r上傳逾時請檢查");
                                            }
                                            break;
                                            }
                                            MySqlMethod.UpdataAi_Time(aiitem, true);
                                        }
                                    }
                                    else
                                    {
                                        MySqlMethod.UpdataAi_Time(aiitem, false);
                                    }
                                }
                            }
                            var electricvalue = MySqlMethod.ElectricLoad(caseitem);
                            foreach (var electricitem in electricvalue)
                            {
                                if (electricitem.NotifyFlag)//電表點位需要發報
                                {
                                    if (MySqlMethod.ElectricMeterLoad(electricitem))
                                    {
                                        var TimeValue = MySqlMethod.ElectricMeter_Time(electricitem);
                                        if (TimeValue == null || TimeValue >= electricitem.TimeoutSpan)
                                        {
                                            NotifyTypeEnum notifyTypeEnum = (NotifyTypeEnum)caseitem.NotifyTypeEnum;
                                            switch (notifyTypeEnum)
                                            {
                                            case NotifyTypeEnum.None:
                                                break;

                                            case NotifyTypeEnum.Line:
                                            {
                                                LineNotifyClass lineNotifyClass = new LineNotifyClass();
                                                lineNotifyClass.LineNotifyFunction(caseitem.NotifyToken, $"設備名稱:{electricitem.ElectricName} \r最後上傳時間 : {MySqlMethod.ElectricMeter_LastTime(electricitem)}\r上傳逾時請檢查");
                                            }
                                            break;

                                            case NotifyTypeEnum.Telegram:
                                            {
                                                TelegramBotClass telegramBotClass = new TelegramBotClass(caseitem.NotifyApi)
                                                {
                                                    Chat_ID = caseitem.NotifyToken
                                                };
                                                telegramBotClass.Send_Message_Group($"設備名稱:{electricitem.ElectricName} \r最後上傳時間 : {MySqlMethod.ElectricMeter_LastTime(electricitem)}\r上傳逾時請檢查");
                                            }
                                            break;
                                            }
                                            MySqlMethod.UpdataElectricMeter_Time(electricitem, true);
                                        }
                                    }
                                    else
                                    {
                                        MySqlMethod.UpdataElectricMeter_Time(electricitem, false);
                                    }
                                }
                            }
                        }
                    }
                    ConnectionTime = DateTime.Now;
                }
                else
                {
                    Thread.Sleep(80);
                }
            }
        }
        private void Connection_Mysql()
        {
            while (myWorkState)
            {
                TimeSpan timeSpan = DateTime.Now.Subtract(ConnectionTime);
                if (timeSpan.TotalMilliseconds > 5000)
                {
                    var NewCaseSettings    = ChungHsin_MySqlMethod.CaseLoad();
                    var NewReceiveSettings = ChungHsin_MySqlMethod.ReceiveLoad();
                    var NewDeviceConfigs   = ChungHsin_MySqlMethod.DevicesLoad();
                    foreach (var Caseitem in NewCaseSettings)
                    {
                        #region 接收
                        var ReceiveValue = ChungHsin_MySqlMethod.ReceiveLoad(Caseitem);
                        foreach (var Receiveitem in ReceiveValue)
                        {
                            if (Receiveitem.NotifyFlag)
                            {
                                if (ChungHsin_MySqlMethod.AI64Load(Receiveitem))
                                {
                                    var TimeValue = ChungHsin_MySqlMethod.Receive_Time(Receiveitem);
                                    if (TimeValue == null || TimeValue >= Receiveitem.HTimeoutSpan)
                                    {
                                        if (NewReceiveSettings.SingleOrDefault(g => g.PK == Receiveitem.PK) != null)
                                        {
                                            NewReceiveSettings.Single(g => g.PK == Receiveitem.PK).ConnectionFlag = "斷線";
                                            NotifyTypeEnum notifyTypeEnum = (NotifyTypeEnum)Caseitem.NotifyTypeEnum;
                                            switch (notifyTypeEnum)
                                            {
                                            case NotifyTypeEnum.None:
                                                break;

                                            case NotifyTypeEnum.Line:
                                            {
                                                LineNotifyClass lineNotifyClass = new LineNotifyClass();
                                                lineNotifyClass.LineNotifyFunction(Caseitem.NotifyToken, $"設備名稱:{Receiveitem.ReceiveName} \r最後上傳時間 : {ChungHsin_MySqlMethod.AI_LastTime(Receiveitem)}\r上傳逾時請檢查");
                                            }
                                            break;

                                            case NotifyTypeEnum.Telegram:
                                            {
                                                TelegramBotClass telegramBotClass = new TelegramBotClass(Caseitem.NotifyApi)
                                                {
                                                    Chat_ID = Caseitem.NotifyToken
                                                };
                                                telegramBotClass.Send_Message_Group($"設備名稱:{Receiveitem.ReceiveName} \r最後上傳時間 : {ChungHsin_MySqlMethod.AI_LastTime(Receiveitem)}\r上傳逾時請檢查");
                                            }
                                            break;
                                            }
                                            ChungHsin_MySqlMethod.UpdataReceive_Time(Receiveitem, true);
                                        }
                                    }
                                    else
                                    {
                                        NewReceiveSettings.Single(g => g.PK == Receiveitem.PK).ConnectionFlag = "斷線";
                                    }
                                }
                                else
                                {
                                    if (NewReceiveSettings.SingleOrDefault(g => g.PK == Receiveitem.PK) != null)
                                    {
                                        NewReceiveSettings.Single(g => g.PK == Receiveitem.PK).ConnectionFlag = "連線";
                                        ChungHsin_MySqlMethod.UpdataReceive_Time(Receiveitem, false);
                                    }
                                }
                            }
                            else
                            {
                                if (ChungHsin_MySqlMethod.AI64Load(Receiveitem))
                                {
                                    if (NewReceiveSettings.SingleOrDefault(g => g.PK == Receiveitem.PK) != null)
                                    {
                                        NewReceiveSettings.Single(g => g.PK == Receiveitem.PK).ConnectionFlag = "斷線";
                                        //ChungHsin_MySqlMethod.UpdataReceive_Time(Receiveitem, true);
                                    }
                                }
                                else
                                {
                                    if (NewReceiveSettings.SingleOrDefault(g => g.PK == Receiveitem.PK) != null)
                                    {
                                        NewReceiveSettings.Single(g => g.PK == Receiveitem.PK).ConnectionFlag = "連線";
                                        ChungHsin_MySqlMethod.UpdataReceive_Time(Receiveitem, false);
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    CaseSettings    = NewCaseSettings;
                    ReceiveSettings = NewReceiveSettings;
                    DeviceConfigs   = NewDeviceConfigs;
                    ConnectionTime  = DateTime.Now;
                }
                else
                {
                    Thread.Sleep(80);
                }
            }
        }
        private void Connection_Mysql()
        {
            while (myWorkState)
            {
                TimeSpan timeSpan = DateTime.Now.Subtract(ConnectionTime);
                if (timeSpan.TotalMilliseconds > 5000) //每一秒查詢動作
                {
                    var NewCaseSettings     = Ewatch_MySqlMethod.CaseLoad();
                    var NewAiSettings       = Ewatch_MySqlMethod.AiLoad();
                    var NewElectricSettings = Ewatch_MySqlMethod.ElectricLoad();
                    var casevalue           = Ewatch_MySqlMethod.CaseLoad();
                    foreach (var caseitem in casevalue)
                    {
                        #region AI接收
                        var aivalue = Ewatch_MySqlMethod.AiLoad(caseitem);
                        foreach (var aiitem in aivalue)
                        {
                            if (aiitem.NotifyFlag)                                      //AI點位需要發報
                            {
                                if (Ewatch_MySqlMethod.AI64Load(aiitem))                //檢查即時數值是否超過時間
                                {
                                    var TimeValue = Ewatch_MySqlMethod.Ai_Time(aiitem); //檢查發報數值是否達到
                                    if (TimeValue == null || TimeValue >= aiitem.TimeoutSpan)
                                    {
                                        if (NewAiSettings.SingleOrDefault(g => g.PK == aiitem.PK) != null)
                                        {
                                            NewAiSettings.Single(g => g.PK == aiitem.PK).ConnectionFlag = "斷線";
                                            NotifyTypeEnum notifyTypeEnum = (NotifyTypeEnum)caseitem.NotifyTypeEnum;
                                            switch (notifyTypeEnum)
                                            {
                                            case NotifyTypeEnum.None:
                                                break;

                                            case NotifyTypeEnum.Line:
                                            {
                                                LineNotifyClass lineNotifyClass = new LineNotifyClass();
                                                lineNotifyClass.LineNotifyFunction(caseitem.NotifyToken, $"設備名稱:{aiitem.AiName} \r最後上傳時間 : {Ewatch_MySqlMethod.AI_LastTime(aiitem)}\r上傳逾時請檢查");
                                            }
                                            break;

                                            case NotifyTypeEnum.Telegram:
                                            {
                                                TelegramBotClass telegramBotClass = new TelegramBotClass(caseitem.NotifyApi)
                                                {
                                                    Chat_ID = caseitem.NotifyToken
                                                };
                                                telegramBotClass.Send_Message_Group($"設備名稱:{aiitem.AiName} \r最後上傳時間 : {Ewatch_MySqlMethod.AI_LastTime(aiitem)}\r上傳逾時請檢查");
                                            }
                                            break;
                                            }
                                            Ewatch_MySqlMethod.UpdataAi_Time(aiitem, true);
                                        }
                                    }
                                    else
                                    {
                                        NewAiSettings.Single(g => g.PK == aiitem.PK).ConnectionFlag = "斷線";
                                    }
                                }
                                else
                                {
                                    if (NewAiSettings.SingleOrDefault(g => g.PK == aiitem.PK) != null)
                                    {
                                        NewAiSettings.Single(g => g.PK == aiitem.PK).ConnectionFlag = "連線";
                                        Ewatch_MySqlMethod.UpdataAi_Time(aiitem, false);
                                    }
                                }
                            }
                            else
                            {
                                //AiSettings.Single(g => g.PK == aiitem.PK).ConnectionFlag = "不使用";
                                if (Ewatch_MySqlMethod.AI64Load(aiitem))//檢查即時數值是否超過時間
                                {
                                    if (NewAiSettings.SingleOrDefault(g => g.PK == aiitem.PK) != null)
                                    {
                                        NewAiSettings.Single(g => g.PK == aiitem.PK).ConnectionFlag = "斷線";
                                        //Ewatch_MySqlMethod.UpdataAi_Time(aiitem, true);
                                    }
                                }
                                else
                                {
                                    if (NewAiSettings.SingleOrDefault(g => g.PK == aiitem.PK) != null)
                                    {
                                        NewAiSettings.Single(g => g.PK == aiitem.PK).ConnectionFlag = "連線";
                                        Ewatch_MySqlMethod.UpdataAi_Time(aiitem, false);
                                    }
                                }
                            }
                        }
                        #endregion

                        #region 電表接收
                        var electricvalue = Ewatch_MySqlMethod.ElectricLoad(caseitem);
                        foreach (var electricitem in electricvalue)
                        {
                            if (electricitem.NotifyFlag)//電表點位需要發報
                            {
                                if (Ewatch_MySqlMethod.ElectricMeterLoad(electricitem))
                                {
                                    var TimeValue = Ewatch_MySqlMethod.ElectricMeter_Time(electricitem);
                                    if (TimeValue == null || TimeValue >= electricitem.TimeoutSpan)
                                    {
                                        if (NewElectricSettings.SingleOrDefault(g => g.PK == electricitem.PK) != null)
                                        {
                                            NewElectricSettings.Single(g => g.PK == electricitem.PK).ConnectionFlag = "斷線";
                                            NotifyTypeEnum notifyTypeEnum = (NotifyTypeEnum)caseitem.NotifyTypeEnum;
                                            switch (notifyTypeEnum)
                                            {
                                            case NotifyTypeEnum.None:
                                                break;

                                            case NotifyTypeEnum.Line:
                                            {
                                                LineNotifyClass lineNotifyClass = new LineNotifyClass();
                                                lineNotifyClass.LineNotifyFunction(caseitem.NotifyToken, $"設備名稱:{electricitem.ElectricName} \r最後上傳時間 : {Ewatch_MySqlMethod.ElectricMeter_LastTime(electricitem)}\r上傳逾時請檢查");
                                            }
                                            break;

                                            case NotifyTypeEnum.Telegram:
                                            {
                                                TelegramBotClass telegramBotClass = new TelegramBotClass(caseitem.NotifyApi)
                                                {
                                                    Chat_ID = caseitem.NotifyToken
                                                };
                                                telegramBotClass.Send_Message_Group($"設備名稱:{electricitem.ElectricName} \r最後上傳時間 : {Ewatch_MySqlMethod.ElectricMeter_LastTime(electricitem)}\r上傳逾時請檢查");
                                            }
                                            break;
                                            }
                                            Ewatch_MySqlMethod.UpdataElectricMeter_Time(electricitem, true);
                                        }
                                    }
                                    else
                                    {
                                        NewElectricSettings.Single(g => g.PK == electricitem.PK).ConnectionFlag = "斷線";
                                    }
                                }
                                else
                                {
                                    if (NewElectricSettings.SingleOrDefault(g => g.PK == electricitem.PK) != null)
                                    {
                                        NewElectricSettings.Single(g => g.PK == electricitem.PK).ConnectionFlag = "連線";
                                        Ewatch_MySqlMethod.UpdataElectricMeter_Time(electricitem, false);
                                    }
                                }
                            }
                            else
                            {
                                //ElectricSettings.Single(g => g.PK == electricitem.PK).ConnectionFlag = "不使用";
                                var TimeValue = Ewatch_MySqlMethod.ElectricMeter_Time(electricitem);
                                if (TimeValue == null || TimeValue >= electricitem.TimeoutSpan)
                                {
                                    if (NewElectricSettings.SingleOrDefault(g => g.PK == electricitem.PK) != null)
                                    {
                                        NewElectricSettings.Single(g => g.PK == electricitem.PK).ConnectionFlag = "斷線";
                                    }
                                }
                                else
                                {
                                    if (NewElectricSettings.SingleOrDefault(g => g.PK == electricitem.PK) != null)
                                    {
                                        NewElectricSettings.Single(g => g.PK == electricitem.PK).ConnectionFlag = "連線";
                                        Ewatch_MySqlMethod.UpdataElectricMeter_Time(electricitem, false);
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    CaseSettings     = NewCaseSettings;
                    AiSettings       = NewAiSettings;
                    ElectricSettings = NewElectricSettings;
                    ConnectionTime   = DateTime.Now;
                }
                else
                {
                    Thread.Sleep(80);
                }
            }
        }