Пример #1
0
        //数据持久化
        internal static void  SaveToDb(PoliticsInfo pPoliticsInfo, Politics pPolitics, bool pIsNew)
        {
            pPolitics.PoliticsId   = pPoliticsInfo.politicsId;
            pPolitics.PoliticsName = pPoliticsInfo.politicsName;
            pPolitics.IsNew        = pIsNew;
            string UserName = SubsonicHelper.GetUserName();

            try
            {
                pPolitics.Save(UserName);
            }
            catch (Exception ex)
            {
                LogManager.getInstance().getLogger(typeof(PoliticsInfo)).Error(ex);
                if (ex.Message.Contains("插入重复键"))               //违反了唯一键
                {
                    throw new AppException("此对象已经存在");          //此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示
                }
                throw new AppException("保存失败");
            }
            pPoliticsInfo.politicsId = pPolitics.PoliticsId;
            //如果缓存存在,更新缓存
            if (CachedEntityCommander.IsTypeRegistered(typeof(PoliticsInfo)))
            {
                ResetCache();
            }
        }
Пример #2
0
        /// <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 <PoliticsInfo> GetPagedList(int pPageIndex, int pPageSize, SortDirection pOrderBy, string pSortExpression, out int pRecordCount)
        {
            if (pPageIndex <= 1)
            {
                pPageIndex = 1;
            }
            List <PoliticsInfo> list = new List <PoliticsInfo>();

            Query q = Politics.CreateQuery();

            q.PageIndex = pPageIndex;
            q.PageSize  = pPageSize;
            q.ORDER_BY(pSortExpression, pOrderBy.ToString());
            PoliticsCollection collection = new  PoliticsCollection();

            collection.LoadAndCloseReader(q.ExecuteReader());

            foreach (Politics politics  in collection)
            {
                PoliticsInfo politicsInfo = new PoliticsInfo();
                LoadFromDAL(politicsInfo, politics);
                list.Add(politicsInfo);
            }
            pRecordCount = q.GetRecordCount();

            return(list);
        }
Пример #3
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// <returns></returns>
        public static List <PoliticsInfo> GetList()
        {
            string cacheKey = GetCacheKey();

            //本实体已经注册成缓存实体,并且缓存存在的时候,直接从缓存取
            if (CachedEntityCommander.IsTypeRegistered(typeof(PoliticsInfo)) && CachedEntityCommander.GetCache(cacheKey) != null)
            {
                return(CachedEntityCommander.GetCache(cacheKey) as List <PoliticsInfo>);
            }
            else
            {
                List <PoliticsInfo> list       = new List <PoliticsInfo>();
                PoliticsCollection  collection = new  PoliticsCollection();
                Query qry = new Query(Politics.Schema);
                collection.LoadAndCloseReader(qry.ExecuteReader());
                foreach (Politics politics in collection)
                {
                    PoliticsInfo politicsInfo = new PoliticsInfo();
                    LoadFromDAL(politicsInfo, politics);
                    list.Add(politicsInfo);
                }
                //生成缓存
                if (CachedEntityCommander.IsTypeRegistered(typeof(PoliticsInfo)))
                {
                    CachedEntityCommander.SetCache(cacheKey, list);
                }
                return(list);
            }
        }
Пример #4
0
 /// <summary>
 /// 批量装载
 /// </summary>
 internal static void LoadFromDALPatch(List <PoliticsInfo> pList, PoliticsCollection pCollection)
 {
     foreach (Politics politics in pCollection)
     {
         PoliticsInfo politicsInfo = new PoliticsInfo();
         LoadFromDAL(politicsInfo, politics);
         pList.Add(politicsInfo);
     }
 }
Пример #5
0
        public PoliticsInfo GetPoliticsInfoById(int PoliticsId)
        {
            PoliticsInfo politicsInfo = null;             //

            try
            {
                politicsInfo = new PoliticsInfo(PoliticsId);
            }
            catch (AppException)
            {
                return(null);
            }

            return(politicsInfo);
        }
Пример #6
0
        public PoliticsInfo GetPoliticsInfoById(int PoliticsId)
        {
            PoliticsInfo politicsInfo  = null;//
            try
            {
                 politicsInfo = new PoliticsInfo(PoliticsId);

            }
            catch (AppException)
            {
                return null;
            }

            return  politicsInfo;
        }
Пример #7
0
 private void LoadFromId(int politicsId)
 {
     if (CachedEntityCommander.IsTypeRegistered(typeof(PoliticsInfo)))
     {
         PoliticsInfo politicsInfo = Find(GetList(), politicsId);
         if (politicsInfo == null)
         {
             throw new AppException("未能在缓存中找到相应的键值对象");
         }
         Copy(politicsInfo, this);
     }
     else
     {
         Politics politics = new Politics(politicsId);
         if (politics.IsNew)
         {
             throw new AppException("尚未初始化");
         }
         LoadFromDAL(this, politics);
     }
 }
Пример #8
0
        /// <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<PoliticsInfo> GetPagedList(int pPageIndex,int pPageSize,SortDirection pOrderBy,string pSortExpression,out int pRecordCount)
        {
            if(pPageIndex<=1)
            pPageIndex=1;
            List< PoliticsInfo> list = new List< PoliticsInfo>();

            Query q = Politics .CreateQuery();
            q.PageIndex = pPageIndex;
            q.PageSize = pPageSize;
            q.ORDER_BY(pSortExpression,pOrderBy.ToString());
            PoliticsCollection  collection=new  PoliticsCollection();
             	collection.LoadAndCloseReader(q.ExecuteReader());

            foreach (Politics  politics  in collection)
            {
                PoliticsInfo politicsInfo = new PoliticsInfo();
                LoadFromDAL(politicsInfo,   politics);
                list.Add(politicsInfo);
            }
            pRecordCount=q.GetRecordCount();

            return list;
        }
Пример #9
0
        public void DeleteById(PoliticsInfo pPoliticsInfo)
        {
            PoliticsInfo politicsInfo = new PoliticsInfo(pPoliticsInfo.PoliticsId);

            politicsInfo.Delete();
        }
Пример #10
0
 public object SavePoliticsInfo(PoliticsInfo politicsInfo)
 {
     politicsInfo.Save();
     return politicsInfo . PoliticsId;
 }
Пример #11
0
 public List <PoliticsInfo> GetPoliticsInfoList()
 {
     return(PoliticsInfo.GetList());
 }
Пример #12
0
 //从后台获取数据
 internal static void  LoadFromDAL(PoliticsInfo pPoliticsInfo, Politics pPolitics)
 {
     pPoliticsInfo.politicsId   = pPolitics.PoliticsId;
     pPoliticsInfo.politicsName = pPolitics.PoliticsName;
     pPoliticsInfo.Loaded       = true;
 }
Пример #13
0
 //数据持久化
 internal static void SaveToDb(PoliticsInfo pPoliticsInfo, Politics  pPolitics,bool pIsNew)
 {
     pPolitics.PoliticsId = pPoliticsInfo.politicsId;
      		pPolitics.PoliticsName = pPoliticsInfo.politicsName;
     pPolitics.IsNew=pIsNew;
     string UserName = SubsonicHelper.GetUserName();
     try
     {
         pPolitics.Save(UserName);
     }
     catch(Exception ex)
     {
         LogManager.getInstance().getLogger(typeof(PoliticsInfo)).Error(ex);
         if(ex.Message.Contains("插入重复键"))//违反了唯一键
         {
             throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示
         }
         throw new AppException("保存失败");
     }
     pPoliticsInfo.politicsId = pPolitics.PoliticsId;
     //如果缓存存在,更新缓存
     if (CachedEntityCommander.IsTypeRegistered(typeof(PoliticsInfo)))
     {
         ResetCache();
     }
 }
Пример #14
0
 /// <summary>
 /// 复制一个对象,采用硬编码的方式,避免反射的低效
 /// </summary>
 /// <param name="pIndustryTypeInfoFrom"></param>
 /// <param name="pIndustryTypeInfoTo"></param>
 public static void Copy(PoliticsInfo pPoliticsInfoFrom, PoliticsInfo pPoliticsInfoTo)
 {
     pPoliticsInfoTo.PoliticsId   = pPoliticsInfoFrom.politicsId;
     pPoliticsInfoTo.PoliticsName = pPoliticsInfoFrom.politicsName;
     pPoliticsInfoTo.Loaded       = pPoliticsInfoFrom.Loaded;
 }
Пример #15
0
 //从后台获取数据
 internal static void LoadFromDAL(PoliticsInfo pPoliticsInfo, Politics  pPolitics)
 {
     pPoliticsInfo.politicsId = pPolitics.PoliticsId;
      		pPoliticsInfo.politicsName = pPolitics.PoliticsName;
     pPoliticsInfo.Loaded=true;
 }
Пример #16
0
 /// <summary>
 /// 批量装载
 /// </summary>
 internal static void LoadFromDALPatch(List< PoliticsInfo> pList, PoliticsCollection pCollection)
 {
     foreach (Politics politics in pCollection)
     {
         PoliticsInfo politicsInfo = new PoliticsInfo();
         LoadFromDAL(politicsInfo, politics );
         pList.Add(politicsInfo);
     }
 }
Пример #17
0
 public List <PoliticsInfo> GetPagedList(int pPageIndex, int pPageSize, SortDirection pOrderBy, string pSortExpression, out int pRecordCount)
 {
     return(PoliticsInfo.GetPagedList(pPageIndex, pPageSize, pOrderBy, pSortExpression, out pRecordCount));
 }
Пример #18
0
 /// <summary>
 /// 复制为另一个对象
 /// </summary>
 /// <param name="pIndustryTypeInfoTo"></param>
 public void CopyTo(PoliticsInfo pPoliticsInfoTo)
 {
     Copy(this, pPoliticsInfoTo);
 }
Пример #19
0
 /// <summary>
 /// 获得数据列表
 /// </summary>
 /// <returns></returns>
 public static List<PoliticsInfo> GetList()
 {
     string cacheKey = GetCacheKey();
     //本实体已经注册成缓存实体,并且缓存存在的时候,直接从缓存取
     if (CachedEntityCommander.IsTypeRegistered(typeof(PoliticsInfo)) && CachedEntityCommander.GetCache(cacheKey) != null)
     {
         return CachedEntityCommander.GetCache(cacheKey) as List< PoliticsInfo>;
     }
     else
     {
         List< PoliticsInfo>  list =new List< PoliticsInfo>();
         PoliticsCollection  collection=new  PoliticsCollection();
         Query qry = new Query(Politics.Schema);
         collection.LoadAndCloseReader(qry.ExecuteReader());
         foreach(Politics politics in collection)
         {
             PoliticsInfo politicsInfo= new PoliticsInfo();
             LoadFromDAL(politicsInfo,politics);
             list.Add(politicsInfo);
         }
       	//生成缓存
         if (CachedEntityCommander.IsTypeRegistered(typeof(PoliticsInfo)))
         {
             CachedEntityCommander.SetCache(cacheKey, list);
         }
         return list;
     }
 }
Пример #20
0
 /// <summary>
 /// 复制一个对象,采用硬编码的方式,避免反射的低效
 /// </summary>
 /// <param name="pIndustryTypeInfoFrom"></param>
 /// <param name="pIndustryTypeInfoTo"></param>
 public static void Copy(PoliticsInfo pPoliticsInfoFrom, PoliticsInfo pPoliticsInfoTo)
 {
     pPoliticsInfoTo.PoliticsId = pPoliticsInfoFrom.politicsId;
      		pPoliticsInfoTo.PoliticsName = pPoliticsInfoFrom.politicsName;
     pPoliticsInfoTo.Loaded=pPoliticsInfoFrom.Loaded;
 }
Пример #21
0
 public object  SavePoliticsInfo(PoliticsInfo politicsInfo)
 {
     politicsInfo.Save();
     return(politicsInfo.PoliticsId);
 }
Пример #22
0
 /// <summary>
 /// 复制为另一个对象
 /// </summary>
 /// <param name="pIndustryTypeInfoTo"></param>
 public void CopyTo(PoliticsInfo pPoliticsInfoTo)
 {
     Copy(this,  pPoliticsInfoTo);
 }
Пример #23
0
 public void DeleteById(PoliticsInfo pPoliticsInfo)
 {
     PoliticsInfo politicsInfo = new PoliticsInfo(pPoliticsInfo.PoliticsId);
     politicsInfo.Delete();
 }