|
|
|
|
using System;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using DSWeb.Models;
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
using WebSqlHelper;
|
|
|
|
|
|
|
|
|
|
namespace DSWeb.EntityDA
|
|
|
|
|
{
|
|
|
|
|
public class LogDA
|
|
|
|
|
{
|
|
|
|
|
private const string PARM_LOGGER_GID = "@gid";
|
|
|
|
|
private const string PARM_LOGGER_NAME = "@name";
|
|
|
|
|
private const string PARM_LOGGER_LOGTYPE = "@log_type";
|
|
|
|
|
private const string PARM_LOGGER_LOGTIME = "@log_time";
|
|
|
|
|
private const string PARM_LOGGER_LOGCONTENT = "@log_content";
|
|
|
|
|
private const string PARM_LOGGER_CREATEUSER = "@create_user";
|
|
|
|
|
private const string PARM_LOGGER_BEGIN_TIME = "@begin_time";
|
|
|
|
|
private const string PARM_LOGGER_END_TIME = "@end_time";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private const string SQL_SELECT_LOG_ALL = "SELECT GID, NAME, LOGTYPE, LOGTIME, LOGCONTENT, CREATEUSER FROM sys_log";
|
|
|
|
|
|
|
|
|
|
private const string SQL_SELECT_LOG_BY_TIME = "SELECT GID, NAME, LOGTYPE, LOGTIME, LOGCONTENT, CREATEUSER FROM sys_log WHERE LOGTIME > @begin_time AND LOGTIME < @end_time";
|
|
|
|
|
private const string SQL_INSERT_LOG = "INSERT INTO sys_log( GID, NAME, LOGTYPE, LOGTIME, LOGCONTENT, CREATEUSER ) VALUES ( @gid,@name,@log_type,GETDATE(),@log_content,@create_user) ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 插入日志记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="LogEntity">日志实体类</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int InsertLog(LogEntity logEntity)
|
|
|
|
|
{
|
|
|
|
|
int iResult = 0;
|
|
|
|
|
SqlParameter[] parms = GetInsertParms();
|
|
|
|
|
|
|
|
|
|
parms[0].Value = logEntity.GID;
|
|
|
|
|
parms[1].Value = logEntity.Name;
|
|
|
|
|
parms[2].Value = logEntity.LogType;
|
|
|
|
|
parms[3].Value = logEntity.LogContent;
|
|
|
|
|
parms[4].Value = logEntity.CreateUserID;
|
|
|
|
|
|
|
|
|
|
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
|
|
{
|
|
|
|
|
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_INSERT_LOG, parms);
|
|
|
|
|
if (existVal > 0)
|
|
|
|
|
{
|
|
|
|
|
iResult = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
iResult = -1;//执行异常
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return iResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化INSERT参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private SqlParameter[] GetInsertParms()
|
|
|
|
|
{
|
|
|
|
|
SqlParameter[] parms = new SqlParameter[] {
|
|
|
|
|
new SqlParameter("@gid",SqlDbType.VarChar,36),
|
|
|
|
|
new SqlParameter("@name",SqlDbType.VarChar,50),
|
|
|
|
|
new SqlParameter("@log_type",SqlDbType.VarChar,15),
|
|
|
|
|
new SqlParameter("@log_content",SqlDbType.VarChar,300),
|
|
|
|
|
new SqlParameter("@create_user",SqlDbType.VarChar,36)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return parms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据SQL语句查询日志记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="strSql"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataSet GetExcuteSql(string strSql)
|
|
|
|
|
{
|
|
|
|
|
DataSet userSet = new DataSet();
|
|
|
|
|
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
|
|
|
|
|
return userSet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取日志记录总页数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="strSql">sql查询语句</param>
|
|
|
|
|
/// <returns>返回int型日志记录总数</returns>
|
|
|
|
|
public int GetPageTotal(string strSql)
|
|
|
|
|
{
|
|
|
|
|
int iResult = 0;
|
|
|
|
|
|
|
|
|
|
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql, null))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
while (sqlRead.Read())
|
|
|
|
|
{
|
|
|
|
|
iResult = sqlRead.GetInt32(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception error)
|
|
|
|
|
{
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return iResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|