/// <summary> /// 查詢電表點位上傳時間 /// </summary> /// <param name="setting"></param> /// <returns></returns> public DateTime?ElectricMeter_LastTime(ElectricSetting setting) { try { using (var Conn = new MySqlConnection(Webscsb.ConnectionString)) { string sql = string.Empty; ElectricPhaseTypeEnum phaseTypeEnum = (ElectricPhaseTypeEnum)setting.PhaseTypeEnum; switch (phaseTypeEnum) { case ElectricPhaseTypeEnum.Three: { sql = "SELECT ttimen FROM ThreePhaseElectricMeter Where CaseNo = @CaseNo AND ElectricNo = @ElectricNo"; } break; case ElectricPhaseTypeEnum.Single: { sql = "SELECT ttimen FROM SinglePhaseElectricMeter Where CaseNo = @CaseNo AND ElectricNo = @ElectricNo"; } break; } var value = Conn.QuerySingle <DateTime>(sql, new { CaseNo = setting.CaseNo, ElectricNo = setting.ElectricNo }); return(value); } } catch (Exception ex) { Log.Error(ex, "查詢電表點位上傳時間" + "錯誤(Ewatch)"); return(null); } }
/// <summary> /// 電表上傳間隔時間 /// </summary> /// <returns></returns> public int?ElectricMeter_Time(ElectricSetting setting) { int?value = null; using (var Conn = new MySqlConnection(scsb.ConnectionString)) { string sql = "SELECT TIMESTAMPDIFF(HOUR,(SELECT SendTime FROM ElectricSetting Where CaseNo = @CaseNo AND ElectricNo = @ElectricNo),@Datetime)"; value = Conn.QuerySingle <int?>(sql, new { CaseNo = setting.CaseNo, ElectricNo = setting.ElectricNo, Datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }); } return(value); }
private void ChangesimpleButton_Click(object sender, EventArgs e) { ElectricSetting electricSetting = new ElectricSetting() { CaseNo = CaseNotextEdit.Text, ElectricNo = Convert.ToInt32(ElectricNotextEdit.Text), ElectricName = ElectricNametextEdit.Text, NotifyFlag = NotifyFlagtoggleSwitch.IsOn, TimeoutSpan = Convert.ToInt32(TimeoutSpantextEdit.Text), MTimeoutSpan = Convert.ToInt32(MTimeoutSpantextEdit.Text) }; Ewatch_MySqlMethod.Update_ElectricSetting(electricSetting); Search_Setting(); }
/// <summary> /// 更新電表點位最後上傳時間 /// </summary> /// <param name="setting"></param> public void UpdataElectricMeter_Time(ElectricSetting setting, bool TimeFlag) { using (var Conn = new MySqlConnection(scsb.ConnectionString)) { string sql = "UPDATE ElectricSetting SET SendTime = @SendTime Where CaseNo = @CaseNo AND ElectricNo = @ElectricNo"; if (TimeFlag) { var value = Conn.Execute(sql, new { SendTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), CaseNo = setting.CaseNo, ElectricNo = setting.ElectricNo }); } else { var value = Conn.Execute(sql, new { SendTime = DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss"), CaseNo = setting.CaseNo, ElectricNo = setting.ElectricNo }); } } }
/// <summary> /// 電表新增 /// </summary> /// <param name="setting"></param> public void Insert_ElectricSetting(ElectricSetting setting) { try { using (var Conn = new MySqlConnection(scsb.ConnectionString)) { string sql = "INSERT IGNORE INTO ElectricSetting (CaseNo,ElectricNo,ElectricName,PhaseTypeEnum,NotifyFlag,TimeoutSpan,MTimeoutSpan)" + " VALUES(@CaseNo,@ElectricNo,@ElectricName,@PhaseTypeEnum,@NotifyFlag,@TimeoutSpan,@MTimeoutSpan) "; Conn.Execute(sql, setting); } } catch (Exception ex) { Log.Error(ex, "電表新增" + "錯誤(Ewatch)"); } }
private void SavesimpleButton_Click(object sender, EventArgs e) { ElectricSetting electricSetting = new ElectricSetting() { CaseNo = CaseNotextEdit.Text, ElectricNo = Convert.ToInt32(ElectricNotextEdit.Text), ElectricName = ElectricNametextEdit.Text, NotifyFlag = NotifyFlagtoggleSwitch.IsOn, TimeoutSpan = Convert.ToInt32(TimeoutSpantextEdit.Text), MTimeoutSpan = Convert.ToInt32(MTimeoutSpantextEdit.Text) }; Ewatch_MySqlMethod.Insert_ElectricSetting(electricSetting); caseUserControl.Search_Setting(); caseUserControl.FlyoutFlag = false; caseUserControl.flyout.Close(); }
/// <summary> /// 電表即時資訊比較 /// </summary> /// <param name="setting">電表設定資訊</param> /// <returns></returns> public bool ElectricMeterLoad(ElectricSetting setting) { bool Flag = false; try { using (var Conn = new MySqlConnection(Webscsb.ConnectionString)) { string sql = string.Empty; ElectricPhaseTypeEnum phaseTypeEnum = (ElectricPhaseTypeEnum)setting.PhaseTypeEnum; switch (phaseTypeEnum) { case ElectricPhaseTypeEnum.Three: { sql = "SELECT TIMESTAMPDIFF(MINUTE,(SELECT ttimen FROM ThreePhaseElectricMeter Where CaseNo = @CaseNo AND ElectricNo = @ElectricNo),@Datetime)"; } break; case ElectricPhaseTypeEnum.Single: { sql = "SELECT TIMESTAMPDIFF(MINUTE,(SELECT ttimen FROM SinglePhaseElectricMeter Where CaseNo = @CaseNo AND ElectricNo = @ElectricNo),@Datetime)"; } break; } var value = Conn.QuerySingle <int?>(sql, new { CaseNo = setting.CaseNo, ElectricNo = setting.ElectricNo, Datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }); if (value != null) { if (value >= setting.MTimeoutSpan) { Flag = true; } else { Flag = false; } } } } catch (Exception ex) { Log.Error(ex, "電表即時資訊比較" + "錯誤(Ewatch)"); } return(Flag); }
/// <summary> /// 電表更新 /// </summary> /// <param name="electricSetting"></param> public void Update_ElectricSetting(ElectricSetting setting) { try { using (var Conn = new MySqlConnection(scsb.ConnectionString)) { string sql = "UPDATE ElectricSetting SET " + "ElectricName = @ElectricName," + "PhaseTypeEnum = @PhaseTypeEnum," + "NotifyFlag = @NotifyFlag," + "TimeoutSpan = @TimeoutSpan," + "MTimeoutSpan = @MTimeoutSpan" + " WHERE CaseNo = @CaseNo AND ElectricNo = @ElectricNo"; Conn.Execute(sql, setting); } } catch (Exception ex) { Log.Error(ex, "電表更新" + "錯誤(Ewatch)"); } }