/// <summary> /// 获得分页列表,无论是否是缓存实体都从数据库直接拿取数据 /// </summary> /// <param name="pPageIndex">页数</param> /// <param name="pPageSize">每页列表</param> /// <param name="pOrderBy">排序</param> /// <param name="pSortExpression">排序字段</param> /// <param name="pRecordCount">列表行数</param> /// <returns>数据分页</returns> public static List <SpecialExpInfo> GetPagedList(int pPageIndex, int pPageSize, SortDirection pOrderBy, string pSortExpression, out int pRecordCount) { if (pPageIndex <= 1) { pPageIndex = 1; } List <SpecialExpInfo> list = new List <SpecialExpInfo>(); Query q = SpecialExp.CreateQuery(); q.PageIndex = pPageIndex; q.PageSize = pPageSize; q.ORDER_BY(pSortExpression, pOrderBy.ToString()); SpecialExpCollection collection = new SpecialExpCollection(); collection.LoadAndCloseReader(q.ExecuteReader()); foreach (SpecialExp specialExp in collection) { SpecialExpInfo specialExpInfo = new SpecialExpInfo(); LoadFromDAL(specialExpInfo, specialExp); list.Add(specialExpInfo); } pRecordCount = q.GetRecordCount(); return(list); }
/// <summary> /// 保存 /// </summary> public override void Save() { if (!m_Loaded) //新增 { SpecialExp specialExp = new SpecialExp(); SaveToDb(this, specialExp, true); } else //修改 { SpecialExp specialExp = new SpecialExp(specialExpId); if (specialExp.IsNew) { throw new AppException("该数据已经不存在了"); } SaveToDb(this, specialExp, false); } }
/// <summary> /// 删除 /// </summary> /// <returns>是否成功</returns> public override void Delete() { if (!m_Loaded) { throw new AppException("尚未初始化"); } bool result = (SpecialExp.Delete(SpecialExpId) == 1); //更新缓存 if (result && CachedEntityCommander.IsTypeRegistered(typeof(SpecialExpInfo))) { ResetCache(); } if (!result) { throw new AppException("删除失败,数据可能被删除"); } }
//从后台获取数据 internal static void LoadFromDAL(SpecialExpInfo pSpecialExpInfo, SpecialExp pSpecialExp) { pSpecialExpInfo.specialExpId = pSpecialExp.SpecialExpId; pSpecialExpInfo.mainSpecialExpId = pSpecialExp.MainSpecialExpId; pSpecialExpInfo.projectStepId = pSpecialExp.ProjectStepId; pSpecialExpInfo.mainProjectCreateId = pSpecialExp.MainProjectCreateId; pSpecialExpInfo.sheetNum = pSpecialExp.SheetNum; pSpecialExpInfo.applyPeople = pSpecialExp.ApplyPeople; pSpecialExpInfo.applyDate = pSpecialExp.ApplyDate; pSpecialExpInfo.applyReason = pSpecialExp.ApplyReason; pSpecialExpInfo.preIsApply = pSpecialExp.PreIsApply; pSpecialExpInfo.isApprove = pSpecialExp.IsApprove; pSpecialExpInfo.isApply = pSpecialExp.IsApply; pSpecialExpInfo.isApply1 = pSpecialExp.IsApply1; pSpecialExpInfo.isApply2 = pSpecialExp.IsApply2; pSpecialExpInfo.preIsOver = pSpecialExp.PreIsOver; pSpecialExpInfo.isOver1 = pSpecialExp.IsOver1; pSpecialExpInfo.isOver2 = pSpecialExp.IsOver2; pSpecialExpInfo.preApplyTime = pSpecialExp.PreApplyTime; pSpecialExpInfo.approveTime = pSpecialExp.ApproveTime; pSpecialExpInfo.applyTime = pSpecialExp.ApplyTime; pSpecialExpInfo.apply1Time = pSpecialExp.Apply1Time; pSpecialExpInfo.apply2Time = pSpecialExp.Apply2Time; pSpecialExpInfo.preEmployeeId = pSpecialExp.PreEmployeeId; pSpecialExpInfo.sendEmployeeId = pSpecialExp.SendEmployeeId; pSpecialExpInfo.recvEmployeeId = pSpecialExp.RecvEmployeeId; pSpecialExpInfo.recv1EmployeeId = pSpecialExp.Recv1EmployeeId; pSpecialExpInfo.recv2EmployeeId = pSpecialExp.Recv2EmployeeId; pSpecialExpInfo.preEmployeeName = pSpecialExp.PreEmployeeName; pSpecialExpInfo.sendEmployeeName = pSpecialExp.SendEmployeeName; pSpecialExpInfo.recvEmployeeName = pSpecialExp.RecvEmployeeName; pSpecialExpInfo.recv1EmployeeName = pSpecialExp.Recv1EmployeeName; pSpecialExpInfo.recv2EmployeeName = pSpecialExp.Recv2EmployeeName; pSpecialExpInfo.isNewCreate = pSpecialExp.IsNewCreate; pSpecialExpInfo.isMain = pSpecialExp.IsMain; pSpecialExpInfo.isMain1 = pSpecialExp.IsMain1; pSpecialExpInfo.isMain2 = pSpecialExp.IsMain2; pSpecialExpInfo.isMain3 = pSpecialExp.IsMain3; pSpecialExpInfo.applyMoney = pSpecialExp.ApplyMoney; pSpecialExpInfo.today = pSpecialExp.Today; pSpecialExpInfo.signName = pSpecialExp.SignName; pSpecialExpInfo.Loaded = true; }
private void LoadFromId(int specialExpId) { if (CachedEntityCommander.IsTypeRegistered(typeof(SpecialExpInfo))) { SpecialExpInfo specialExpInfo = Find(GetList(), specialExpId); if (specialExpInfo == null) { throw new AppException("未能在缓存中找到相应的键值对象"); } Copy(specialExpInfo, this); } else { SpecialExp specialExp = new SpecialExp(specialExpId); if (specialExp.IsNew) { throw new AppException("尚未初始化"); } LoadFromDAL(this, specialExp); } }
private void LoadFromId(int specialExpId) { if (CachedEntityCommander.IsTypeRegistered(typeof(SpecialExpInfo))) { SpecialExpInfo specialExpInfo=Find(GetList(), specialExpId); if(specialExpInfo==null) throw new AppException("未能在缓存中找到相应的键值对象"); Copy(specialExpInfo, this); } else { SpecialExp specialExp=new SpecialExp( specialExpId); if(specialExp.IsNew) throw new AppException("尚未初始化"); LoadFromDAL(this, specialExp); } }
//数据持久化 internal static void SaveToDb(SpecialExpInfo pSpecialExpInfo, SpecialExp pSpecialExp,bool pIsNew) { pSpecialExp.SpecialExpId = pSpecialExpInfo.specialExpId; pSpecialExp.MainSpecialExpId = pSpecialExpInfo.mainSpecialExpId; pSpecialExp.ProjectStepId = pSpecialExpInfo.projectStepId; pSpecialExp.MainProjectCreateId = pSpecialExpInfo.mainProjectCreateId; pSpecialExp.SheetNum = pSpecialExpInfo.sheetNum; pSpecialExp.ApplyPeople = pSpecialExpInfo.applyPeople; pSpecialExp.ApplyDate = pSpecialExpInfo.applyDate; pSpecialExp.ApplyReason = pSpecialExpInfo.applyReason; pSpecialExp.PreIsApply = pSpecialExpInfo.preIsApply; pSpecialExp.IsApprove = pSpecialExpInfo.isApprove; pSpecialExp.IsApply = pSpecialExpInfo.isApply; pSpecialExp.IsApply1 = pSpecialExpInfo.isApply1; pSpecialExp.IsApply2 = pSpecialExpInfo.isApply2; pSpecialExp.PreIsOver = pSpecialExpInfo.preIsOver; pSpecialExp.IsOver1 = pSpecialExpInfo.isOver1; pSpecialExp.IsOver2 = pSpecialExpInfo.isOver2; pSpecialExp.PreApplyTime = pSpecialExpInfo.preApplyTime; pSpecialExp.ApproveTime = pSpecialExpInfo.approveTime; pSpecialExp.ApplyTime = pSpecialExpInfo.applyTime; pSpecialExp.Apply1Time = pSpecialExpInfo.apply1Time; pSpecialExp.Apply2Time = pSpecialExpInfo.apply2Time; pSpecialExp.PreEmployeeId = pSpecialExpInfo.preEmployeeId; pSpecialExp.SendEmployeeId = pSpecialExpInfo.sendEmployeeId; pSpecialExp.RecvEmployeeId = pSpecialExpInfo.recvEmployeeId; pSpecialExp.Recv1EmployeeId = pSpecialExpInfo.recv1EmployeeId; pSpecialExp.Recv2EmployeeId = pSpecialExpInfo.recv2EmployeeId; pSpecialExp.PreEmployeeName = pSpecialExpInfo.preEmployeeName; pSpecialExp.SendEmployeeName = pSpecialExpInfo.sendEmployeeName; pSpecialExp.RecvEmployeeName = pSpecialExpInfo.recvEmployeeName; pSpecialExp.Recv1EmployeeName = pSpecialExpInfo.recv1EmployeeName; pSpecialExp.Recv2EmployeeName = pSpecialExpInfo.recv2EmployeeName; pSpecialExp.IsNewCreate = pSpecialExpInfo.isNewCreate; pSpecialExp.IsMain = pSpecialExpInfo.isMain; pSpecialExp.IsMain1 = pSpecialExpInfo.isMain1; pSpecialExp.IsMain2 = pSpecialExpInfo.isMain2; pSpecialExp.IsMain3 = pSpecialExpInfo.isMain3; pSpecialExp.ApplyMoney = pSpecialExpInfo.applyMoney; pSpecialExp.Today = pSpecialExpInfo.today; pSpecialExp.SignName = pSpecialExpInfo.signName; pSpecialExp.IsNew=pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pSpecialExp.Save(UserName); } catch(Exception ex) { LogManager.getInstance().getLogger(typeof(SpecialExpInfo)).Error(ex); if(ex.Message.Contains("插入重复键"))//违反了唯一键 { throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pSpecialExpInfo.specialExpId = pSpecialExp.SpecialExpId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(SpecialExpInfo))) { ResetCache(); } }
//从后台获取数据 internal static void LoadFromDAL(SpecialExpInfo pSpecialExpInfo, SpecialExp pSpecialExp) { pSpecialExpInfo.specialExpId = pSpecialExp.SpecialExpId; pSpecialExpInfo.mainSpecialExpId = pSpecialExp.MainSpecialExpId; pSpecialExpInfo.projectStepId = pSpecialExp.ProjectStepId; pSpecialExpInfo.mainProjectCreateId = pSpecialExp.MainProjectCreateId; pSpecialExpInfo.sheetNum = pSpecialExp.SheetNum; pSpecialExpInfo.applyPeople = pSpecialExp.ApplyPeople; pSpecialExpInfo.applyDate = pSpecialExp.ApplyDate; pSpecialExpInfo.applyReason = pSpecialExp.ApplyReason; pSpecialExpInfo.preIsApply = pSpecialExp.PreIsApply; pSpecialExpInfo.isApprove = pSpecialExp.IsApprove; pSpecialExpInfo.isApply = pSpecialExp.IsApply; pSpecialExpInfo.isApply1 = pSpecialExp.IsApply1; pSpecialExpInfo.isApply2 = pSpecialExp.IsApply2; pSpecialExpInfo.preIsOver = pSpecialExp.PreIsOver; pSpecialExpInfo.isOver1 = pSpecialExp.IsOver1; pSpecialExpInfo.isOver2 = pSpecialExp.IsOver2; pSpecialExpInfo.preApplyTime = pSpecialExp.PreApplyTime; pSpecialExpInfo.approveTime = pSpecialExp.ApproveTime; pSpecialExpInfo.applyTime = pSpecialExp.ApplyTime; pSpecialExpInfo.apply1Time = pSpecialExp.Apply1Time; pSpecialExpInfo.apply2Time = pSpecialExp.Apply2Time; pSpecialExpInfo.preEmployeeId = pSpecialExp.PreEmployeeId; pSpecialExpInfo.sendEmployeeId = pSpecialExp.SendEmployeeId; pSpecialExpInfo.recvEmployeeId = pSpecialExp.RecvEmployeeId; pSpecialExpInfo.recv1EmployeeId = pSpecialExp.Recv1EmployeeId; pSpecialExpInfo.recv2EmployeeId = pSpecialExp.Recv2EmployeeId; pSpecialExpInfo.preEmployeeName = pSpecialExp.PreEmployeeName; pSpecialExpInfo.sendEmployeeName = pSpecialExp.SendEmployeeName; pSpecialExpInfo.recvEmployeeName = pSpecialExp.RecvEmployeeName; pSpecialExpInfo.recv1EmployeeName = pSpecialExp.Recv1EmployeeName; pSpecialExpInfo.recv2EmployeeName = pSpecialExp.Recv2EmployeeName; pSpecialExpInfo.isNewCreate = pSpecialExp.IsNewCreate; pSpecialExpInfo.isMain = pSpecialExp.IsMain; pSpecialExpInfo.isMain1 = pSpecialExp.IsMain1; pSpecialExpInfo.isMain2 = pSpecialExp.IsMain2; pSpecialExpInfo.isMain3 = pSpecialExp.IsMain3; pSpecialExpInfo.applyMoney = pSpecialExp.ApplyMoney; pSpecialExpInfo.today = pSpecialExp.Today; pSpecialExpInfo.signName = pSpecialExp.SignName; pSpecialExpInfo.Loaded=true; }
/// <summary> /// 保存 /// </summary> public override void Save() { if(!m_Loaded)//新增 { SpecialExp specialExp=new SpecialExp(); SaveToDb(this, specialExp,true); } else//修改 { SpecialExp specialExp=new SpecialExp(specialExpId); if(specialExp.IsNew) throw new AppException("该数据已经不存在了"); SaveToDb(this, specialExp,false); } }
//数据持久化 internal static void SaveToDb(SpecialExpInfo pSpecialExpInfo, SpecialExp pSpecialExp, bool pIsNew) { pSpecialExp.SpecialExpId = pSpecialExpInfo.specialExpId; pSpecialExp.MainSpecialExpId = pSpecialExpInfo.mainSpecialExpId; pSpecialExp.ProjectStepId = pSpecialExpInfo.projectStepId; pSpecialExp.MainProjectCreateId = pSpecialExpInfo.mainProjectCreateId; pSpecialExp.SheetNum = pSpecialExpInfo.sheetNum; pSpecialExp.ApplyPeople = pSpecialExpInfo.applyPeople; pSpecialExp.ApplyDate = pSpecialExpInfo.applyDate; pSpecialExp.ApplyReason = pSpecialExpInfo.applyReason; pSpecialExp.PreIsApply = pSpecialExpInfo.preIsApply; pSpecialExp.IsApprove = pSpecialExpInfo.isApprove; pSpecialExp.IsApply = pSpecialExpInfo.isApply; pSpecialExp.IsApply1 = pSpecialExpInfo.isApply1; pSpecialExp.IsApply2 = pSpecialExpInfo.isApply2; pSpecialExp.PreIsOver = pSpecialExpInfo.preIsOver; pSpecialExp.IsOver1 = pSpecialExpInfo.isOver1; pSpecialExp.IsOver2 = pSpecialExpInfo.isOver2; pSpecialExp.PreApplyTime = pSpecialExpInfo.preApplyTime; pSpecialExp.ApproveTime = pSpecialExpInfo.approveTime; pSpecialExp.ApplyTime = pSpecialExpInfo.applyTime; pSpecialExp.Apply1Time = pSpecialExpInfo.apply1Time; pSpecialExp.Apply2Time = pSpecialExpInfo.apply2Time; pSpecialExp.PreEmployeeId = pSpecialExpInfo.preEmployeeId; pSpecialExp.SendEmployeeId = pSpecialExpInfo.sendEmployeeId; pSpecialExp.RecvEmployeeId = pSpecialExpInfo.recvEmployeeId; pSpecialExp.Recv1EmployeeId = pSpecialExpInfo.recv1EmployeeId; pSpecialExp.Recv2EmployeeId = pSpecialExpInfo.recv2EmployeeId; pSpecialExp.PreEmployeeName = pSpecialExpInfo.preEmployeeName; pSpecialExp.SendEmployeeName = pSpecialExpInfo.sendEmployeeName; pSpecialExp.RecvEmployeeName = pSpecialExpInfo.recvEmployeeName; pSpecialExp.Recv1EmployeeName = pSpecialExpInfo.recv1EmployeeName; pSpecialExp.Recv2EmployeeName = pSpecialExpInfo.recv2EmployeeName; pSpecialExp.IsNewCreate = pSpecialExpInfo.isNewCreate; pSpecialExp.IsMain = pSpecialExpInfo.isMain; pSpecialExp.IsMain1 = pSpecialExpInfo.isMain1; pSpecialExp.IsMain2 = pSpecialExpInfo.isMain2; pSpecialExp.IsMain3 = pSpecialExpInfo.isMain3; pSpecialExp.ApplyMoney = pSpecialExpInfo.applyMoney; pSpecialExp.Today = pSpecialExpInfo.today; pSpecialExp.SignName = pSpecialExpInfo.signName; pSpecialExp.IsNew = pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pSpecialExp.Save(UserName); } catch (Exception ex) { LogManager.getInstance().getLogger(typeof(SpecialExpInfo)).Error(ex); if (ex.Message.Contains("插入重复键")) //违反了唯一键 { throw new AppException("此对象已经存在"); //此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pSpecialExpInfo.specialExpId = pSpecialExp.SpecialExpId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(SpecialExpInfo))) { ResetCache(); } }