You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
178 lines
4.7 KiB
178 lines
4.7 KiB
using MESClassLibrary.BLL.Log;
|
|
using MESClassLibrary.DAL;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MESClassLibrary.BLL
|
|
{
|
|
public class BasicBLL<T> where T : class, new()
|
|
{
|
|
BaseDAL<T> db = new BaseDAL<T>();
|
|
/// 新增信息
|
|
public bool AddInfo(T md)
|
|
{
|
|
try
|
|
{
|
|
if (db.Add(md) > 0)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
return false;
|
|
}
|
|
|
|
}
|
|
/// 修改信息
|
|
public bool UpdateInfo(T md, params string[] proNames)
|
|
{
|
|
try
|
|
{
|
|
//T u = new T() { uId = 1, uLoginName = "asdfasdf" };
|
|
if (db.Modify(md, proNames) > 0)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
return false;
|
|
}
|
|
|
|
}
|
|
/// 删除信息
|
|
public bool DelInfo(T md)
|
|
{
|
|
try
|
|
{
|
|
if (db.Del(md) > 0)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
return false;
|
|
}
|
|
|
|
}
|
|
public List<T> SearchInfo(int page, int pagesize, out int total)
|
|
{
|
|
try
|
|
{
|
|
var list = db.GetListBy(LambdaHelper.CreateEqual<T>("IsUseing", 1)).ToList();
|
|
total = list.Count;
|
|
int Skipcount = (page - 1) * pagesize;
|
|
return list.Skip(Skipcount).Take(pagesize).ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
total = 0;
|
|
//LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
return null;
|
|
}
|
|
|
|
}
|
|
public List<T> SearchInfoByKey(string keyname, object keyvalue)
|
|
{
|
|
try
|
|
{
|
|
var list = db.GetListBy(LambdaHelper.CreateEqual<T>(keyname, keyvalue)).ToList();
|
|
return list;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return new List<T>();
|
|
//return null;
|
|
}
|
|
|
|
}
|
|
|
|
public List<T> SearchInfoContains(string keyname, string keyvalue)
|
|
{
|
|
try
|
|
{
|
|
var list = db.GetListBy(LambdaHelper.GetContains<T>(keyname, keyvalue)).ToList();
|
|
return list;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return new List<T>();
|
|
//return null;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<T> SearchInfoAll(int page, int pagesize, out int total)
|
|
{
|
|
try
|
|
{
|
|
var list = db.GetListBy(LambdaHelper.True<T>()).ToList();
|
|
total = list.Count;
|
|
int Skipcount = (page - 1) * pagesize;
|
|
return list.Skip(Skipcount).Take(pagesize).ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
total = 0;
|
|
//LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
return null;
|
|
}
|
|
|
|
}
|
|
public T SearchInfoByID(string ID)
|
|
{
|
|
try
|
|
{
|
|
var list = db.Find(ID);
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
}
|
|
public List<T> SearchAllInfo()
|
|
{
|
|
try
|
|
{
|
|
return db.GetListBy(LambdaHelper.True<T>()).ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
return null;
|
|
}
|
|
|
|
}
|
|
public List<T> SearchInfoByTime(string cname, DateTime stime, DateTime etime)
|
|
{
|
|
try
|
|
{
|
|
IQueryable<T> list = db.GetListBy(LambdaHelper.CreateCompareToLater<T>(cname, stime)).AsQueryable();
|
|
list = list.Where(LambdaHelper.CreateCompareToEarlier<T>(cname, etime));
|
|
return list.ToList();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return new List<T>();
|
|
//return null;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|