public static T GetCastValue <T>(this BaseDAL dal, object obj) { if (obj is DBNull) { return(default(T)); } return((T)obj); }
public static Guid?GetNulableGuid(this BaseDAL dal, object obj) { if (obj is DBNull) { return(null); } return((Guid)obj); }
public static string GetString(this BaseDAL dal, object obj) { if (obj is DBNull) { return(string.Empty); } return(Convert.ToString(obj)); }
public void FinishCheck(DbContext db, SystemStatus systemStatus, StocktakingLogHd hd, List <ProfitAndLossLog> plLogList, List <InventoryLossLog> lossLogList, List <UnlistedGoodsLog> ugLogList, List <InventoryLog> stockLogList) { using (TransactionScope ts = new TransactionScope()) { // 让使用typeof(T).Name标签的所有缓存过期 QueryCacheManager.ExpireTag(nameof(SystemStatus)); QueryCacheManager.ExpireTag(nameof(StocktakingLogHd)); QueryCacheManager.ExpireTag(nameof(ProfitAndLoss)); QueryCacheManager.ExpireTag(nameof(VProfitAndLossLog)); QueryCacheManager.ExpireTag(nameof(InventoryLoss)); QueryCacheManager.ExpireTag(nameof(VInventoryLossLog)); QueryCacheManager.ExpireTag(nameof(UnlistedGoods)); QueryCacheManager.ExpireTag(nameof(VUnlistedGoodsLog)); QueryCacheManager.ExpireTag(nameof(Inventory)); QueryCacheManager.ExpireTag(nameof(VInventoryLog)); db.Configuration.ValidateOnSaveEnabled = false; BaseDAL baseDAL = DALFty.Create <BaseDAL>(); // 更新状态表 db.Entry(systemStatus).State = EntityState.Modified; db.SaveChanges(); // 添加盘点日志 db.Set <StocktakingLogHd>().Add(hd); db.SaveChanges(); // 保存盘点差异日志表 if (plLogList.Count > 0) { baseDAL.AddByBulkCopy <ProfitAndLossLog>(db, plLogList); } // 保存损耗确认单日志表 if (lossLogList.Count > 0) { baseDAL.AddByBulkCopy <InventoryLossLog>(db, lossLogList); } // 保存未上架商品确认单日志表 if (ugLogList.Count > 0) { baseDAL.AddByBulkCopy <UnlistedGoodsLog>(db, ugLogList); } // 保存账面库存日志表 if (stockLogList.Count > 0) { baseDAL.AddByBulkCopy <InventoryLog>(db, stockLogList); } // 删除盘点差异表 db.Set <ProfitAndLoss>().DeleteFromQuery(); // 删除损耗确认单 db.Set <InventoryLoss>().DeleteFromQuery(); // 删除未上架商品确认单 db.Set <UnlistedGoods>().DeleteFromQuery(); // 删除账面库存表 db.Set <Inventory>().DeleteFromQuery(); db.Configuration.ValidateOnSaveEnabled = true; ts.Complete(); } }
public List <StudentDTO> getStudentBySchoolId(long schoolId) { using (MyDbContext ctx = new MyDbContext()) { BaseDAL <Student> bs = new BaseDAL <Student>(ctx); var persons = bs.getAll().Include(s => s.Teachers).Where(s => s.schoolId == schoolId); List <StudentDTO> students = new List <StudentDTO>(); foreach (var person in persons) { StudentDTO studentdto = getDTO(person); students.Add(studentdto); //studentdto.teacherId = person.Teachers.; //studentdto.schoolId = person.schoolId; } return(students); } }
public StudentDTO[] getStudentByID(long teacherId) { using (MyDbContext ctx = new MyDbContext()) { BaseDAL <Teacher> bs = new BaseDAL <Teacher>(ctx); var entities = bs.getAll().Include(e => e.students) .Include(e => e.school).Where(e => e.Id == teacherId) .SingleOrDefault().students; List <StudentDTO> list = new List <StudentDTO>(); foreach (Student s in entities) { StudentDTO sto = new StudentDTO(); sto.Adress = s.Adress; sto.Age = s.Age; sto.BirthDateTime = s.BirthDateTime; sto.departments = s.departments; sto.EmailAdress = s.EmailAdress; sto.EnrollmentYear = s.EnrollmentYear; sto.firstLoginTime = s.firstLoginTime; sto.Gender = s.Gender; sto.Id = s.Id; sto.IDnumber = s.IDnumber; sto.is_delete = s.is_delete; sto.lastLoginIp = s.lastLoginIp; sto.lastloginTime = s.lastloginTime; sto.major = s.major; sto.Name = s.Name; sto.Password = s.Password; sto.passwordSalty = s.passwordSalty; sto.PhoneNum = s.PhoneNum; sto.schoolId = s.schoolId; sto.schoolName = s.School.Name; sto.stuId = s.stuId; sto.teacherIds = s.Teachers.Select(t => t.Id).ToArray(); list.Add(sto); } return(list.ToArray()); } }
public void SaveProfitAndLoss(DbContext db, SystemStatus systemStatus, StocktakingLogHd hd, List <StocktakingLogDtl> dtlList, List <ProfitAndLoss> insertList, List <ProfitAndLoss> updateList) { using (TransactionScope ts = new TransactionScope()) { // 让使用typeof(T).Name标签的所有缓存过期 QueryCacheManager.ExpireTag(nameof(StocktakingLogHd)); QueryCacheManager.ExpireTag(nameof(StocktakingLogDtl)); QueryCacheManager.ExpireTag(nameof(ProfitAndLoss)); QueryCacheManager.ExpireTag(nameof(Stocktaking)); db.Configuration.ValidateOnSaveEnabled = false; BaseDAL baseDAL = DALFty.Create <BaseDAL>(); // 更新状态表 db.Entry(systemStatus).State = EntityState.Modified; db.SaveChanges(); // 添加盘点日志 db.Set <StocktakingLogHd>().Add(hd); db.SaveChanges(); if (dtlList.Count > 0) { baseDAL.AddByBulkCopy <StocktakingLogDtl>(db, dtlList); } // 保存盘点差异表 if (insertList.Count > 0) { baseDAL.AddByBulkCopy <ProfitAndLoss>(db, insertList); } if (updateList.Count > 0) { db.Set <ProfitAndLoss>().BulkUpdate(updateList); } // 删除盘点导入表 db.Set <Stocktaking>().DeleteFromQuery(); db.SaveChanges(); db.Configuration.ValidateOnSaveEnabled = true; ts.Complete(); } }
public void Insert(WmsContext db, UsersInfo obj, List <Permission> pList, List <ButtonPermission> btnList) { using (TransactionScope ts = new TransactionScope()) { // 让使用typeof(T).Name标签的所有缓存过期 QueryCacheManager.ExpireTag(nameof(UsersInfo)); QueryCacheManager.ExpireTag(nameof(Permission)); QueryCacheManager.ExpireTag(nameof(ButtonPermission)); db.Configuration.ValidateOnSaveEnabled = false; BaseDAL baseDAL = DALFty.Create <BaseDAL>(); db.Set <UsersInfo>().Add(obj); db.SaveChanges(); if (pList.Count > 0) { baseDAL.AddByBulkCopy <Permission>(db, pList); } if (btnList.Count > 0) { baseDAL.AddByBulkCopy <ButtonPermission>(db, btnList); } db.Configuration.ValidateOnSaveEnabled = true; ts.Complete(); } }