FIC_Solar/solarApp/Service/procArchiveLog.cs
jay.chang e647e6196b [solarApp]修正/優化歸檔邏輯,跑報表新增區間跑報表
[solarPower]逆便器分析因應資料搬遷修改語法。電站分析優化發電量圖表及歷史資料語法。
2025-11-14 14:48:15 +08:00

55 lines
2.2 KiB
C#

using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
namespace solarApp.Service
{
public class procArchiveLog
{
/// <summary>
/// insert Log
/// </summary>
/// <param name="action_name">動作名稱</param>
/// <param name="duration_sec">運行時間</param>
/// <param name="src_table">來源Table</param>
/// <param name="dest_table">目的地table</param>
/// <param name="errMessage">異常資訊</param>
/// <param name="myCon">連線資訊</param>
/// <param name="cmd">command物件</param>
public void insert_log(string power_stationID, string action_name, double duration_sec, string src_table, string dest_table, string procResult, string errMessage, string note, MySqlConnection myCon , MySqlCommand cmd = null) {
MySqlCommand _cmd = new MySqlCommand();
if (cmd == null) {
_cmd.Connection = myCon;
_cmd.CommandTimeout = 720;
}
else _cmd = cmd;
if (myCon.State != ConnectionState.Open)
myCon.Open();
string errMsg = string.Empty;
if (!string.IsNullOrEmpty(errMessage))
{
errMsg = errMessage.Replace("'", "''");
}
string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//string procResult = (string.IsNullOrEmpty(errMessage)) ? "0" : "1";
if (procResult == "err")
{
procResult = "1"; // 1: error
}
string sql = @"INSERT INTO `solar_master`.`log_archive`(power_stationID, `action_name`, `action_time`, `duration_sec`, `src_table`, `dest_table`, `result`, `err_txt`, `note`)
VALUES ("+ power_stationID + ", '" + action_name + "', '" + nowTime + "', " + duration_sec + ", '" + // action_time, duration_sec
src_table + "', '"+ dest_table + "', b'"+ procResult + "', '" + // src_table, dest_table, result
errMsg + "', '"+ note +"');"; // err_txt
_cmd.CommandText = sql;
_cmd.ExecuteNonQuery();
}
}
}