public ProductTypeInfo GetProductTypeInfoById(int ProductTypeId) { ProductTypeInfo productTypeInfo = null;// try { productTypeInfo = new ProductTypeInfo(ProductTypeId); } catch (AppException) { return null; } return productTypeInfo; }
private void LoadFromId(int productTypeId) { if (CachedEntityCommander.IsTypeRegistered(typeof(ProductTypeInfo))) { ProductTypeInfo productTypeInfo = Find(GetList(), productTypeId); if (productTypeInfo == null) { throw new AppException("未能在缓存中找到相应的键值对象"); } Copy(productTypeInfo, this); } else { ProductType productType = new ProductType(productTypeId); if (productType.IsNew) { throw new AppException("尚未初始化"); } LoadFromDAL(this, productType); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (isPValid()) { try { int OpId = Convert.ToInt32(Request["OfferPriceId"].ToString()); ProductTypeInfo product = new ProductTypeInfo(); product.OfferPriceId = OpId; product.ProductName = txtName.Text.ToString(); product.Model = txtModel.Text.ToString(); product.Num = txtNum.Text.ToString(); product.Price = txtPrice.Text.ToString(); product.Unit = ddlPUnit.SelectedItem.Text; float fNum = float.Parse(txtNum.Text.ToString()); float fPrice = float.Parse(txtPrice.Text.ToString()); float fSum = fNum * fPrice; product.Sums = fSum.ToString(); product.Save(); gvProductBind(); string str = OfferPriceInfo.GetProductMoneySum(OpId); if (str == "") { lblMoneySum.Text = "0Ԫ"; } else { lblMoneySum.Text = OfferPriceInfo.GetProductMoneySum(OpId) + "Ԫ"; } Clear(); } catch (Exception Ex) { ClientScript.RegisterStartupScript(this.GetType(), "Save", "alert('����ʧ�ܣ�" + Ex.Message + "');", true); } } }
public List <ProductTypeInfo> GetProductTypeInfoList() { return(ProductTypeInfo.GetList()); }
public void DeleteById(ProductTypeInfo pProductTypeInfo) { ProductTypeInfo productTypeInfo = new ProductTypeInfo(pProductTypeInfo.ProductTypeId); productTypeInfo.Delete(); }
//数据持久化 internal static void SaveToDb(ProductTypeInfo pProductTypeInfo, ProductType pProductType,bool pIsNew) { pProductType.ProductTypeId = pProductTypeInfo.productTypeId; pProductType.ProductName = pProductTypeInfo.productName; pProductType.OfferPriceId = pProductTypeInfo.offerPriceId; pProductType.Model = pProductTypeInfo.model; pProductType.Unit = pProductTypeInfo.unit; pProductType.Num = pProductTypeInfo.num; pProductType.Price = pProductTypeInfo.price; pProductType.Sums = pProductTypeInfo.sums; pProductType.IsNew=pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pProductType.Save(UserName); } catch(Exception ex) { LogManager.getInstance().getLogger(typeof(ProductTypeInfo)).Error(ex); if(ex.Message.Contains("插入重复键"))//违反了唯一键 { throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pProductTypeInfo.productTypeId = pProductType.ProductTypeId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(ProductTypeInfo))) { ResetCache(); } }
/// <summary> /// 批量装载 /// </summary> internal static void LoadFromDALPatch(List< ProductTypeInfo> pList, ProductTypeCollection pCollection) { foreach (ProductType productType in pCollection) { ProductTypeInfo productTypeInfo = new ProductTypeInfo(); LoadFromDAL(productTypeInfo, productType ); pList.Add(productTypeInfo); } }
//从后台获取数据 internal static void LoadFromDAL(ProductTypeInfo pProductTypeInfo, ProductType pProductType) { pProductTypeInfo.productTypeId = pProductType.ProductTypeId; pProductTypeInfo.productName = pProductType.ProductName; pProductTypeInfo.offerPriceId = pProductType.OfferPriceId; pProductTypeInfo.model = pProductType.Model; pProductTypeInfo.unit = pProductType.Unit; pProductTypeInfo.num = pProductType.Num; pProductTypeInfo.price = pProductType.Price; pProductTypeInfo.sums = pProductType.Sums; pProductTypeInfo.Loaded=true; }
/// <summary> /// 复制为另一个对象 /// </summary> /// <param name="pIndustryTypeInfoTo"></param> public void CopyTo(ProductTypeInfo pProductTypeInfoTo) { Copy(this, pProductTypeInfoTo); }
/// <summary> /// 获得数据列表 /// </summary> /// <returns></returns> public static List<ProductTypeInfo> GetList() { string cacheKey = GetCacheKey(); //本实体已经注册成缓存实体,并且缓存存在的时候,直接从缓存取 if (CachedEntityCommander.IsTypeRegistered(typeof(ProductTypeInfo)) && CachedEntityCommander.GetCache(cacheKey) != null) { return CachedEntityCommander.GetCache(cacheKey) as List< ProductTypeInfo>; } else { List< ProductTypeInfo> list =new List< ProductTypeInfo>(); ProductTypeCollection collection=new ProductTypeCollection(); Query qry = new Query(ProductType.Schema); collection.LoadAndCloseReader(qry.ExecuteReader()); foreach(ProductType productType in collection) { ProductTypeInfo productTypeInfo= new ProductTypeInfo(); LoadFromDAL(productTypeInfo,productType); list.Add(productTypeInfo); } //生成缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(ProductTypeInfo))) { CachedEntityCommander.SetCache(cacheKey, list); } return list; } }
/// <summary> /// 复制一个对象,采用硬编码的方式,避免反射的低效 /// </summary> /// <param name="pIndustryTypeInfoFrom"></param> /// <param name="pIndustryTypeInfoTo"></param> public static void Copy(ProductTypeInfo pProductTypeInfoFrom, ProductTypeInfo pProductTypeInfoTo) { pProductTypeInfoTo.ProductTypeId = pProductTypeInfoFrom.productTypeId; pProductTypeInfoTo.ProductName = pProductTypeInfoFrom.productName; pProductTypeInfoTo.OfferPriceId = pProductTypeInfoFrom.offerPriceId; pProductTypeInfoTo.Model = pProductTypeInfoFrom.model; pProductTypeInfoTo.Unit = pProductTypeInfoFrom.unit; pProductTypeInfoTo.Num = pProductTypeInfoFrom.num; pProductTypeInfoTo.Price = pProductTypeInfoFrom.price; pProductTypeInfoTo.Sums = pProductTypeInfoFrom.sums; pProductTypeInfoTo.Loaded=pProductTypeInfoFrom.Loaded; }
public object SaveProductTypeInfo(ProductTypeInfo productTypeInfo) { productTypeInfo.Save(); return productTypeInfo . ProductTypeId; }
public List <ProductTypeInfo> GetPagedList(int pPageIndex, int pPageSize, SortDirection pOrderBy, string pSortExpression, out int pRecordCount) { return(ProductTypeInfo.GetPagedList(pPageIndex, pPageSize, pOrderBy, pSortExpression, out pRecordCount)); }
/// <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<ProductTypeInfo> GetPagedList(int pPageIndex,int pPageSize,SortDirection pOrderBy,string pSortExpression,out int pRecordCount) { if(pPageIndex<=1) pPageIndex=1; List< ProductTypeInfo> list = new List< ProductTypeInfo>(); Query q = ProductType .CreateQuery(); q.PageIndex = pPageIndex; q.PageSize = pPageSize; q.ORDER_BY(pSortExpression,pOrderBy.ToString()); ProductTypeCollection collection=new ProductTypeCollection(); collection.LoadAndCloseReader(q.ExecuteReader()); foreach (ProductType productType in collection) { ProductTypeInfo productTypeInfo = new ProductTypeInfo(); LoadFromDAL(productTypeInfo, productType); list.Add(productTypeInfo); } pRecordCount=q.GetRecordCount(); return list; }
public object SaveProductTypeInfo(ProductTypeInfo productTypeInfo) { productTypeInfo.Save(); return(productTypeInfo.ProductTypeId); }