/// <summary>
        /// AI即時資訊比較
        /// </summary>
        /// <param name="setting"> AI設定資訊</param>
        /// <returns></returns>
        public bool AI64Load(ReceiveSetting setting)
        {
            bool Flag = false;

            try
            {
                using (var Conn = new MySqlConnection(Webscsb.ConnectionString))
                {
                    string sql   = "SELECT TIMESTAMPDIFF(MINUTE,(SELECT ttimen FROM Ai64 Where CaseNo = @CaseNo AND ReceiveNo = @ReceiveNo),@Datetime)";
                    var    value = Conn.QuerySingle <int?>(sql, new { CaseNo = setting.CaseNo, ReceiveNo = setting.ReceiveNo, Datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") });
                    if (value != null)
                    {
                        if (value >= setting.MTimeoutSpan)
                        {
                            Flag = true;
                        }
                        else
                        {
                            Flag = false;
                        }
                    }
                    else
                    {
                        Flag = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "AI即時資訊比較" + "錯誤(ChungHsin)");
            }
            return(Flag);
        }
        private void SavesimpleButton_Click(object sender, EventArgs e)
        {
            ReceiveSetting receiveSetting = new ReceiveSetting()
            {
                CaseNo         = CaseNotextEdit.Text,
                DeviceTypeEnum = DeviceTypeEnumcomboBoxEdit.SelectedIndex,
                ReceiveNo      = Convert.ToInt32(ReceiveNotextEdit.Text),
                ReceiveName    = ReceiveNametextEdit.Text,
                NotifyFlag     = NotifyFlagtoggleSwitch.IsOn,
                HTimeoutSpan   = Convert.ToInt32(TimeoutSpantextEdit.Text),
                MTimeoutSpan   = Convert.ToInt32(MTimeoutSpantextEdit.Text)
            };

            ChungHsin_MySqlMethod.Insert_ReceiveSettig(receiveSetting);
            var aiconfig    = ChungHsin_MySqlMethod.AiConfigLoad(receiveSetting.DeviceTypeEnum);
            var stateconfig = ChungHsin_MySqlMethod.StateConfigLoad(receiveSetting.DeviceTypeEnum);
            List <AiSetting>    aiSettings    = new List <AiSetting>();
            List <StateSetting> stateSettings = new List <StateSetting>();

            if (aiconfig != null)
            {
                foreach (var item in aiconfig)
                {
                    AiSetting setting = new AiSetting()
                    {
                        CaseNo    = receiveSetting.CaseNo,
                        ReceiveNo = receiveSetting.ReceiveNo,
                        AINo      = item.AINo,
                    };
                    aiSettings.Add(setting);
                }
                ChungHsin_MySqlMethod.Insert_AiSetting(aiSettings);
            }
            if (stateconfig != null)
            {
                foreach (var item in stateconfig)
                {
                    StateSetting setting = new StateSetting()
                    {
                        CaseNo    = receiveSetting.CaseNo,
                        ReceiveNo = receiveSetting.ReceiveNo,
                        StateNo   = item.StateNo
                    };
                    stateSettings.Add(setting);
                }
                ChungHsin_MySqlMethod.Insert_StateSetting(stateSettings);
            }
            caseUserControl.Search_Setting();
            caseUserControl.FlyoutFlag = false;
            caseUserControl.flyout.Close();
        }
 /// <summary>
 /// Receive新增
 /// </summary>
 /// <param name="setting"></param>
 public void Insert_ReceiveSettig(ReceiveSetting setting)
 {
     try
     {
         using (var Conn = new MySqlConnection(scsb.ConnectionString))
         {
             string sql = "INSERT IGNORE INTO ReceiveSetting (DeviceTypeEnum,CaseNo,ReceiveNo,ReceiveName,NotifyFlag,HTimeoutSpan,MTimeoutSpan)" +
                          " VALUES(@DeviceTypeEnum,@CaseNo,@ReceiveNo,@ReceiveName,@NotifyFlag,@HTimeoutSpan,@MTimeoutSpan) ";
             Conn.Execute(sql, setting);
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex, "Receive新增" + "錯誤(ChungHsin)");
     }
 }
Exemplo n.º 4
0
        private void ChangesimpleButton_Click(object sender, EventArgs e)
        {
            ReceiveSetting receiveSetting = new ReceiveSetting()
            {
                CaseNo         = CaseNotextEdit.Text,
                DeviceTypeEnum = Convert.ToInt32(DeviceTypeEnumcomboBoxEdit.SelectedIndex),
                ReceiveNo      = Convert.ToInt32(ReceiveNotextEdit.Text),
                ReceiveName    = ReceiveNametextEdit.Text,
                NotifyFlag     = NotifyFlagtoggleSwitch.IsOn,
                HTimeoutSpan   = Convert.ToInt32(TimeoutSpantextEdit.Text),
                MTimeoutSpan   = Convert.ToInt32(MTimeoutSpantextEdit.Text)
            };

            ChungHsin_MySqlMethod.Updata_ReceiveSetting(receiveSetting);
            Search_Setting();
        }
 /// <summary>
 /// 查詢AI點位上傳時間
 /// </summary>
 /// <param name="setting"></param>
 /// <returns></returns>
 public DateTime?AI_LastTime(ReceiveSetting setting)
 {
     try
     {
         using (var Conn = new MySqlConnection(Webscsb.ConnectionString))
         {
             string sql   = "SELECT ttimen FROM Ai64 Where CaseNo = @CaseNo AND ReceiveNo = @ReceiveNo";
             var    value = Conn.QuerySingle <DateTime>(sql, new { CaseNo = setting.CaseNo, ReceiveNo = setting.ReceiveNo });
             return(value);
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex, "更新AI點位最後上傳時間" + "錯誤(ChungHsin)");
         return(null);
     }
 }
        /// <summary>
        /// Receive上傳間隔時間
        /// </summary>
        /// <returns></returns>
        public int?Receive_Time(ReceiveSetting setting)
        {
            int?value = null;

            try
            {
                using (var Conn = new MySqlConnection(scsb.ConnectionString))
                {
                    string sql = "SELECT TIMESTAMPDIFF(HOUR,(SELECT SendTime FROM ReceiveSetting Where CaseNo = @CaseNo AND ReceiveNo = @ReceiveNo),@Datetime)";
                    value = Conn.QuerySingle <int?>(sql, new { CaseNo = setting.CaseNo, ReceiveNo = setting.ReceiveNo, Datetime = DateTime.Now });
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Receive上傳間隔時間" + "錯誤(ChungHsin)");
            }
            return(value);
        }
 /// <summary>
 /// Receive更新
 /// </summary>
 /// <param name="setting"></param>
 public void Updata_ReceiveSetting(ReceiveSetting setting)
 {
     try
     {
         using (var Conn = new MySqlConnection(scsb.ConnectionString))
         {
             string sql = "UPDATE ReceiveSetting SET " +
                          "DeviceTypeEnum  = @DeviceTypeEnum," +
                          "ReceiveName = @ReceiveName," +
                          "NotifyFlag = @NotifyFlag," +
                          "HTimeoutSpan = @HTimeoutSpan," +
                          "MTimeoutSpan = @MTimeoutSpan" +
                          " WHERE CaseNo = @CaseNo AND ReceiveNo = @ReceiveNo";
             Conn.Execute(sql, setting);
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex, "Receive更新" + "錯誤(ChungHsin)");
     }
 }
 /// <summary>
 /// 更新Receive點位最後上傳時間
 /// </summary>
 /// <param name="setting"></param>
 public void UpdataReceive_Time(ReceiveSetting setting, bool TimeFlag)
 {
     try
     {
         using (var Conn = new MySqlConnection(scsb.ConnectionString))
         {
             string sql = "UPDATE ReceiveSetting SET SendTime = @SendTime WHERE CaseNo = @CaseNo AND ReceiveNo = @ReceiveNo";
             if (TimeFlag)
             {
                 var value = Conn.Execute(sql, new { SendTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), CaseNo = setting.CaseNo, ReceiveNo = setting.ReceiveNo });
             }
             else
             {
                 var value = Conn.Execute(sql, new { SendTime = DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss"), CaseNo = setting.CaseNo, ReceiveNo = setting.ReceiveNo });
             }
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex, "更新Receive最後上傳時間" + "錯誤(ChungHsin)");
     }
 }