using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using CY.IDAL.Sys;
|
using CY.Model;
|
using System.Data.SqlClient;
|
using System.Data;
|
using System.Transactions;
|
|
namespace CY.SQLDAL
|
{
|
public class LogDAL : ILogDAL
|
{
|
|
private Database _dataBase = null;
|
|
public LogDAL()
|
{
|
_dataBase = new Database();
|
}
|
|
public IEnumerable<Model.Log> SelectModelPage(string startTime, string endTime, Infrastructure.Query.Pagination pagination)
|
{
|
string condition = " 1=1 ";
|
if (!string.IsNullOrEmpty(startTime))
|
{
|
condition += " and CAST(Date AS date)>='" + startTime + "'";
|
}
|
|
if (!string.IsNullOrEmpty(endTime))
|
{
|
condition += " and CAST(Date AS date)<='" + endTime + "'";
|
}
|
|
return _dataBase.SelectModelPage<Log>(pagination, "*", "Log", "Date Desc", "Date Desc", condition);
|
}
|
|
public bool DeleteModel(int id)
|
{
|
bool isSuccess = false;
|
try
|
{
|
string sqlStr = "delete from Log where Id=@Id";
|
SqlParameter[] pars = new SqlParameter[]{
|
new SqlParameter("@Id",SqlDbType.Int,4)
|
};
|
pars[0].Value = id;
|
isSuccess = (_dataBase.ExecuteSql(sqlStr, pars) > 0);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return isSuccess;
|
}
|
|
public bool DeleteModeList(IList<int> idList)
|
{
|
bool isSuccess = true;
|
if (idList != null && idList.Count > 0)
|
{
|
using (TransactionScope scope = new TransactionScope())
|
{
|
foreach (int id in idList)
|
{
|
isSuccess = DeleteModel(id);
|
if (!isSuccess)
|
break;
|
}
|
if (isSuccess)
|
scope.Complete();
|
}
|
}
|
return isSuccess;
|
}
|
|
public Log GetModel(int id)
|
{
|
Log model = null;
|
string condition = " id=" + id;
|
IList<Log> list = _dataBase.SelectModel<Log>("*", "Log",condition);
|
if (list != null && list.Count > 0)
|
{
|
model = list[0];
|
}
|
return model;
|
}
|
}
|
}
|