Files
T-DAS/Epost.DAL/ErrorLogDAL.cs

136 lines
4.0 KiB
C#
Raw Normal View History

2023-01-13 15:30:20 +08:00
using Epost.Common;
using Epost.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Epost.DAL.Enum.SqlLogType;
namespace Epost.DAL
{
2024-01-04 15:30:23 +08:00
public class ErrorLogDAL
2023-01-13 15:30:20 +08:00
{
2024-01-04 15:30:23 +08:00
DataBaseOpration.OprationSqlDAL db = DB_DLL.GetInstance();
2023-01-13 15:30:20 +08:00
#region
public bool InsertErrorLog(ErrorLogModel model)
{
try
{
2024-01-04 15:30:23 +08:00
string sql = string.Format("insert into errorlog(username,ErrorDate,Type,title,Remark) values('{0}','{1}','{2}','{3}','{4}')",
2023-01-13 15:30:20 +08:00
model.UserName,
2024-01-04 15:30:23 +08:00
2023-01-13 15:30:20 +08:00
DateTime.Now.ToString(),
model.Type,
2024-01-04 15:30:23 +08:00
model.Title,
2023-01-13 15:30:20 +08:00
model.Remark);
int x = db.InsertSql(sql);
if (x > 0)
return true;
return false;
}
catch (Exception ex)
{
LogHelper.WriteLogInfo("添加错误日志异常:" + ex.Message);
return false;
}
}
#endregion
#region
public DataTable ErrorLogList(sqlLogType type)
{
try
{
string sql = string.Format("select * from errorlog where type='{0}' ",
type
);
DataTable dt = db.GetsqlForDT(sql);
return dt;
}
catch (Exception ex)
{
LogHelper.WriteLogInfo("查询错误日志异常:" + ex.Message);
return null;
}
}
#endregion
#region
public List<ErrorLogModel> GetLog4NetDetailListByPage(string strWhere, string orderby, int startIndex, int endIndex, out int recordCount)
{
try
{
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT * FROM ( ");
strSql.Append(" SELECT ROW_NUMBER() OVER (");
if (!string.IsNullOrEmpty(orderby.Trim()))
{
strSql.Append("order by T." + orderby);
}
else
{
2024-01-04 15:30:23 +08:00
strSql.Append("order by Id desc");
2023-01-13 15:30:20 +08:00
}
strSql.Append(")AS Row, T.* from ErrorLog T WITH(NOLOCK) ");
if (!string.IsNullOrEmpty(strWhere.Trim()))
{
strSql.Append(" WHERE 1=1 " + strWhere);
}
strSql.Append(" ) TT");
strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
List<ErrorLogModel> list = ModelConvertHelper<ErrorLogModel>.ConvertToList(db.GetsqlForDT(strSql.ToString()));
strSql.Remove(0, strSql.Length);
strSql.Append("SELECT COUNT(*) FROM ErrorLog AS T ");
if (!string.IsNullOrEmpty(strWhere.Trim()))
{
strSql.AppendFormat(" WHERE 1=1 {0}", strWhere);
}
object obj = db.GetsqlForDT(strSql.ToString()).Rows[0][0];
if (obj != null)
recordCount = Convert.ToInt32(obj);
else
recordCount = 0;
return list;
}
catch (Exception ex)
{
LogHelper.WriteLog(GetType(), ex.Message);
recordCount = 0;
2024-01-04 15:30:23 +08:00
return new List<ErrorLogModel>();
2023-01-13 15:30:20 +08:00
}
}
#endregion
2024-01-04 15:30:23 +08:00
public long DeleteLog(string type)
{
string strwhere = string.Empty;
if (!string.IsNullOrEmpty(type))
{
strwhere = " and type ='" + type + "'";
}
string sql = string.Format("delete from errorlog where 1=1 " + strwhere + "");
return db.DeleteSql(sql);
}
2023-01-13 15:30:20 +08:00
}
}