using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using System.Data; using System.Text; namespace solarApp.Service { public class procArchiveLog { /// /// insert Log /// /// 動作名稱 /// 運行時間 /// 來源Table /// 目的地table /// 異常資訊 /// 連線資訊 /// command物件 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(); } } }