/// <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 <MainOfferPriceInfo> GetPagedList(int pPageIndex, int pPageSize, SortDirection pOrderBy, string pSortExpression, out int pRecordCount) { if (pPageIndex <= 1) { pPageIndex = 1; } List <MainOfferPriceInfo> list = new List <MainOfferPriceInfo>(); Query q = MainOfferPrice.CreateQuery(); q.PageIndex = pPageIndex; q.PageSize = pPageSize; q.ORDER_BY(pSortExpression, pOrderBy.ToString()); MainOfferPriceCollection collection = new MainOfferPriceCollection(); collection.LoadAndCloseReader(q.ExecuteReader()); foreach (MainOfferPrice mainOfferPrice in collection) { MainOfferPriceInfo mainOfferPriceInfo = new MainOfferPriceInfo(); LoadFromDAL(mainOfferPriceInfo, mainOfferPrice); list.Add(mainOfferPriceInfo); } pRecordCount = q.GetRecordCount(); return(list); }
//数据持久化 internal static void SaveToDb(MainOfferPriceInfo pMainOfferPriceInfo, MainOfferPrice pMainOfferPrice, bool pIsNew) { pMainOfferPrice.MainOfferPriceId = pMainOfferPriceInfo.mainOfferPriceId; pMainOfferPrice.MainOfferPriceName = pMainOfferPriceInfo.mainOfferPriceName; pMainOfferPrice.IsNew = pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pMainOfferPrice.Save(UserName); } catch (Exception ex) { LogManager.getInstance().getLogger(typeof(MainOfferPriceInfo)).Error(ex); if (ex.Message.Contains("插入重复键")) //违反了唯一键 { throw new AppException("此对象已经存在"); //此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pMainOfferPriceInfo.mainOfferPriceId = pMainOfferPrice.MainOfferPriceId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(MainOfferPriceInfo))) { ResetCache(); } }
/// <summary> /// 保存 /// </summary> public override void Save() { if (!m_Loaded) //新增 { MainOfferPrice mainOfferPrice = new MainOfferPrice(); SaveToDb(this, mainOfferPrice, true); } else //修改 { MainOfferPrice mainOfferPrice = new MainOfferPrice(mainOfferPriceId); if (mainOfferPrice.IsNew) { throw new AppException("该数据已经不存在了"); } SaveToDb(this, mainOfferPrice, false); } }
/// <summary> /// 删除 /// </summary> /// <returns>是否成功</returns> public override void Delete() { if (!m_Loaded) { throw new AppException("尚未初始化"); } bool result = (MainOfferPrice.Delete(MainOfferPriceId) == 1); //更新缓存 if (result && CachedEntityCommander.IsTypeRegistered(typeof(MainOfferPriceInfo))) { ResetCache(); } if (!result) { throw new AppException("删除失败,数据可能被删除"); } }
private void LoadFromId(int mainOfferPriceId) { if (CachedEntityCommander.IsTypeRegistered(typeof(MainOfferPriceInfo))) { MainOfferPriceInfo mainOfferPriceInfo = Find(GetList(), mainOfferPriceId); if (mainOfferPriceInfo == null) { throw new AppException("未能在缓存中找到相应的键值对象"); } Copy(mainOfferPriceInfo, this); } else { MainOfferPrice mainOfferPrice = new MainOfferPrice(mainOfferPriceId); if (mainOfferPrice.IsNew) { throw new AppException("尚未初始化"); } LoadFromDAL(this, mainOfferPrice); } }
private void LoadFromId(int mainOfferPriceId) { if (CachedEntityCommander.IsTypeRegistered(typeof(MainOfferPriceInfo))) { MainOfferPriceInfo mainOfferPriceInfo=Find(GetList(), mainOfferPriceId); if(mainOfferPriceInfo==null) throw new AppException("未能在缓存中找到相应的键值对象"); Copy(mainOfferPriceInfo, this); } else { MainOfferPrice mainOfferPrice=new MainOfferPrice( mainOfferPriceId); if(mainOfferPrice.IsNew) throw new AppException("尚未初始化"); LoadFromDAL(this, mainOfferPrice); } }
//数据持久化 internal static void SaveToDb(MainOfferPriceInfo pMainOfferPriceInfo, MainOfferPrice pMainOfferPrice,bool pIsNew) { pMainOfferPrice.MainOfferPriceId = pMainOfferPriceInfo.mainOfferPriceId; pMainOfferPrice.MainOfferPriceName = pMainOfferPriceInfo.mainOfferPriceName; pMainOfferPrice.IsNew=pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pMainOfferPrice.Save(UserName); } catch(Exception ex) { LogManager.getInstance().getLogger(typeof(MainOfferPriceInfo)).Error(ex); if(ex.Message.Contains("插入重复键"))//违反了唯一键 { throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pMainOfferPriceInfo.mainOfferPriceId = pMainOfferPrice.MainOfferPriceId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(MainOfferPriceInfo))) { ResetCache(); } }
//从后台获取数据 internal static void LoadFromDAL(MainOfferPriceInfo pMainOfferPriceInfo, MainOfferPrice pMainOfferPrice) { pMainOfferPriceInfo.mainOfferPriceId = pMainOfferPrice.MainOfferPriceId; pMainOfferPriceInfo.mainOfferPriceName = pMainOfferPrice.MainOfferPriceName; pMainOfferPriceInfo.Loaded=true; }
/// <summary> /// 保存 /// </summary> public override void Save() { if(!m_Loaded)//新增 { MainOfferPrice mainOfferPrice=new MainOfferPrice(); SaveToDb(this, mainOfferPrice,true); } else//修改 { MainOfferPrice mainOfferPrice=new MainOfferPrice(mainOfferPriceId); if(mainOfferPrice.IsNew) throw new AppException("该数据已经不存在了"); SaveToDb(this, mainOfferPrice,false); } }
//从后台获取数据 internal static void LoadFromDAL(MainOfferPriceInfo pMainOfferPriceInfo, MainOfferPrice pMainOfferPrice) { pMainOfferPriceInfo.mainOfferPriceId = pMainOfferPrice.MainOfferPriceId; pMainOfferPriceInfo.mainOfferPriceName = pMainOfferPrice.MainOfferPriceName; pMainOfferPriceInfo.Loaded = true; }