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.
244 lines
7.0 KiB
244 lines
7.0 KiB
3 months ago
|
using MESClassLibrary.BLL.Log;
|
||
|
using MESClassLibrary.DAL;
|
||
|
using MESClassLibrary.DAL.Log;
|
||
|
using MESClassLibrary.EFModel;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.ComponentModel.DataAnnotations;
|
||
|
using System.Linq;
|
||
|
using System.Linq.Expressions;
|
||
|
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 UpdateInfo(T md)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
return db.Modify(md) > 0;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// 删除信息
|
||
|
public bool DelInfo(T md)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
|
||
|
if (db.Del(md) > 0)
|
||
|
{
|
||
|
#region 删除日志
|
||
|
try
|
||
|
{
|
||
|
PropertyInfo[] proList = md.GetType().GetProperties();
|
||
|
|
||
|
tb_DelData_Log delmd = new tb_DelData_Log();
|
||
|
delmd.ID = Guid.NewGuid().ToString();
|
||
|
delmd.TableName = md.GetType().Name;
|
||
|
|
||
|
|
||
|
PropertyInfo pkProp = proList.Where(p => p.GetCustomAttributes(typeof(KeyAttribute), false).Length > 0).FirstOrDefault();
|
||
|
if (pkProp != null && pkProp.GetValue(md, null) != null)
|
||
|
{
|
||
|
delmd.KeyId = pkProp.GetValue(md, null).ToString();
|
||
|
}
|
||
|
|
||
|
PropertyInfo userProp = proList.Where(p => p.Name == "UserID").FirstOrDefault();
|
||
|
if (userProp != null && userProp.GetValue(md, null) != null)
|
||
|
{
|
||
|
delmd.UserID = userProp.GetValue(md, null).ToString();
|
||
|
}
|
||
|
delmd.CreateTime = DateTime.Now;
|
||
|
|
||
|
LogDelDAL.Add_Info(delmd);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
#endregion
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
public List<T> Search<TKey>(Expression<Func<T, bool>> whereLambda)
|
||
|
{
|
||
|
return db.GetListBy(whereLambda);
|
||
|
}
|
||
|
|
||
|
public List<T> Search<TKey>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, TKey>> orderLambda)
|
||
|
{
|
||
|
return db.GetListBy(whereLambda, orderLambda);
|
||
|
}
|
||
|
|
||
|
public int GetCount(Expression<Func<T, bool>> whereLambda)
|
||
|
{
|
||
|
return db.GetCount(whereLambda);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|