using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; namespace foda { public class BasicBLL where T : class, new() { BaseDAL db = new BaseDAL(); /// 新增信息 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 SearchInfo(int page, int pagesize, out int total) { total = 0; try { var list = db.GetListBy(LambdaHelper.CreateEqual("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 SearchInfoByKey(string keyname, object keyvalue) { try { var list = db.GetListBy(LambdaHelper.CreateEqual(keyname, keyvalue)).ToList(); return list; } catch (Exception) { return new List(); //return null; } } public List SearchInfoContains(string keyname, string keyvalue) { try { var list = db.GetListBy(LambdaHelper.GetContains(keyname, keyvalue)).ToList(); return list; } catch (Exception) { return new List(); //return null; } } public List SearchInfoAll(int page, int pagesize, out int total) { total = 0; try { var list = db.GetListBy(LambdaHelper.True()).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 SearchAllInfo() { try { return db.GetListBy(LambdaHelper.True()).ToList(); } catch (Exception ex) { //LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public List SearchInfoByTime(string cname, DateTime stime, DateTime etime) { try { IQueryable list = db.GetListBy(LambdaHelper.CreateCompareToLater(cname, stime)).AsQueryable(); list = list.Where(LambdaHelper.CreateCompareToEarlier(cname, etime)); return list.ToList(); } catch (Exception) { return new List(); //return null; } } } }