using MESClassLibrary.BLL.Log; using MESClassLibrary.Model; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Reflection; using System.Text; namespace MESClassLibrary.DAL.Log { public class LogErrDAL { public static string TableName = "LogErr"; public string GetTableName() { return TableName; } /// /// 查询全部错误信息 /// /// public DataTable Search_Info() { try { string sql = @"select * from " + TableName + " order by ErrTime desc"; return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0]; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public DataTable Search_InfoByTime(DateTime stime, DateTime etime) { try { string sql = @"select * from " + TableName + @" where ErrTime>=@stime and ErrTime<=@etime order by ErrTime desc"; SqlParameter[] param = new SqlParameter[2]; param[0] = new SqlParameter("@stime", SqlDbType.DateTime); param[0].Value = stime; param[1] = new SqlParameter("@etime", SqlDbType.DateTime); param[1].Value = etime; return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0]; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } /// /// 添加错误信息 /// /// /// public bool Add_Info(LogErrModel mod) { try { #region 添加数据 string sql = ""; SqlParameter[] param = null; sql = "INSERT INTO " + TableName + " (ID,ErrContent,ErrSource"; sql += ") VALUES ("; sql += "@ID,"; sql += "@ErrContent,"; sql += "@ErrSource)"; #region 添加参数 param = new SqlParameter[3]; param[0] = new SqlParameter("@ID", SqlDbType.VarChar); param[0].Value = mod.ID; param[1] = new SqlParameter("@ErrContent", SqlDbType.VarChar); param[1].Value = mod.ErrContent; param[2] = new SqlParameter("@ErrSource", SqlDbType.VarChar); param[2].Value = mod.ErrSource; #endregion SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param); #endregion return true; } catch (Exception ex) { return false; } } } }