コード例 #1
0
ファイル: CategoryProduct.cs プロジェクト: 2644783865/Infoztc
        public List <CategoryProductInfo> GetList()
        {
            string cmdText = @"select ProductId,CategoryId 
			                from CategoryProduct
							order by ProductId "                            ;

            List <CategoryProductInfo> list = new List <CategoryProductInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        CategoryProductInfo model = new CategoryProductInfo();
                        model.ProductId  = reader.GetGuid(0);
                        model.CategoryId = reader.GetGuid(1);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
コード例 #2
0
ファイル: CategoryProduct.cs プロジェクト: 2644783865/Infoztc
        public List <CategoryProductInfo> GetList(int pageIndex, int pageSize, string sqlWhere, params SqlParameter[] cmdParms)
        {
            int startIndex = (pageIndex - 1) * pageSize + 1;
            int endIndex   = pageIndex * pageSize;

            string cmdText = @"select * from(select row_number() over(order by ProductId) as RowNumber,
			                 ProductId,CategoryId
							 from CategoryProduct"                            ;

            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += " where 1=1 " + sqlWhere;
            }
            cmdText += ")as objTable where RowNumber between " + startIndex + " and " + endIndex + " ";

            List <CategoryProductInfo> list = new List <CategoryProductInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        CategoryProductInfo model = new CategoryProductInfo();
                        model.ProductId  = reader.GetGuid(1);
                        model.CategoryId = reader.GetGuid(2);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
コード例 #3
0
ファイル: CategoryProduct.cs プロジェクト: 2644783865/Infoztc
        public List <CategoryProductInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms)
        {
            string cmdText = @"select ProductId,CategoryId
                              from CategoryProduct";

            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += " where 1=1 " + sqlWhere;
            }

            List <CategoryProductInfo> list = new List <CategoryProductInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        CategoryProductInfo model = new CategoryProductInfo();
                        model.ProductId  = reader.GetGuid(0);
                        model.CategoryId = reader.GetGuid(1);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
コード例 #4
0
ファイル: CategoryProduct.cs プロジェクト: 2644783865/Infoztc
        public CategoryProductInfo GetModel(object ProductId)
        {
            CategoryProductInfo model = null;

            string       cmdText = @"select top 1 ProductId,CategoryId 
			                   from CategoryProduct
							   where ProductId = @ProductId "                            ;
            SqlParameter parm    = new SqlParameter("@ProductId", SqlDbType.UniqueIdentifier);

            parm.Value = Guid.Parse(ProductId.ToString());

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, parm))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        model            = new CategoryProductInfo();
                        model.ProductId  = reader.GetGuid(0);
                        model.CategoryId = reader.GetGuid(1);
                    }
                }
            }

            return(model);
        }
コード例 #5
0
ファイル: CategoryProduct.cs プロジェクト: 2644783865/Infoztc
        public int Update(CategoryProductInfo model)
        {
            string cmdText = @"update CategoryProduct set CategoryId = @CategoryId 
			                 where ProductId = @ProductId"            ;

            SqlParameter[] parms =
            {
                new SqlParameter("@ProductId",  SqlDbType.UniqueIdentifier),
                new SqlParameter("@CategoryId", SqlDbType.UniqueIdentifier)
            };
            parms[0].Value = model.ProductId;
            parms[1].Value = model.CategoryId;

            return(SqlHelper.ExecuteNonQuery(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, parms));
        }
コード例 #6
0
ファイル: CategoryProduct.cs プロジェクト: 2644783865/Infoztc
        public int Insert(CategoryProductInfo model)
        {
            string cmdText = @"insert into CategoryProduct (CategoryId,ProductId)
			                 values
							 (@CategoryId,@ProductId)
			                 "            ;

            SqlParameter[] parms =
            {
                new SqlParameter("@CategoryId", SqlDbType.UniqueIdentifier),
                new SqlParameter("@ProductId",  SqlDbType.UniqueIdentifier)
            };
            parms[0].Value = model.CategoryId;
            parms[1].Value = model.ProductId;

            return(SqlHelper.ExecuteNonQuery(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, parms));
        }
コード例 #7
0
        private void SaveProduct(HttpContext context)
        {
            string  Id             = context.Request.Form["ctl00$cphMain$hId"].Trim();
            string  sProductName   = context.Request.Form["ctl00$cphMain$txtProductName"].Trim();
            string  sSubTitle      = context.Request.Form["ctl00$cphMain$txtSubTitle"].Trim();
            decimal dOriginalPrice = 0;
            decimal dProductPrice  = 0;
            float   discount       = 0;

            decimal.TryParse(context.Request.Form["ctl00$cphMain$txtOriginalPrice"].Trim(), out dOriginalPrice);
            decimal.TryParse(context.Request.Form["ctl00$cphMain$txtProductPrice"].Trim(), out dProductPrice);
            float.TryParse(context.Request.Form["ctl00$cphMain$txtDiscount"].Trim(), out discount);
            string sDiscountDescri = context.Request.Form["ctl00$cphMain$txtDiscountDescri"].Trim();
            int    stockNum        = 0;

            int.TryParse(context.Request.Form["ctl00$cphMain$txtStockNum"].Trim(), out stockNum);
            string sProductPictureId = context.Request.Form["productPictureId"].Trim();
            Guid   productPictureId  = Guid.Empty;

            Guid.TryParse(sProductPictureId, out productPictureId);
            string sCategoryId = context.Request.Form["categoryId"].Trim();
            Guid   categoryId  = Guid.Empty;

            Guid.TryParse(sCategoryId, out categoryId);
            string sBrandId = context.Request.Form["brandId"].Trim();
            Guid   brandId  = Guid.Empty;

            Guid.TryParse(sBrandId, out brandId);
            Guid customMenuId = Guid.Empty;

            Guid.TryParse(context.Request.Form["customMenuId"].Trim(), out customMenuId);
            string sOtherPicture = context.Request.Form["otherPic"].Trim();
            string sSizeItem     = context.Request.Form["sizeItem"].Trim();
            string sSizePicture  = context.Request.Form["sizePicture"].Trim();
            string sPayOption    = "";

            string content = context.Request.Form["txtContent"].Trim();

            content = HttpUtility.HtmlDecode(content);
            Guid gId = Guid.Empty;

            if (Id != "")
            {
                Guid.TryParse(Id, out gId);
            }

            ProductInfo model = new ProductInfo();

            model.Id               = gId;
            model.UserId           = WebCommon.GetUserId();
            model.LastUpdatedDate  = DateTime.Now;
            model.ProductName      = sProductName;
            model.SubTitle         = sSubTitle;
            model.OriginalPrice    = dOriginalPrice;
            model.ProductPrice     = dProductPrice;
            model.Discount         = discount;
            model.DiscountDescri   = sDiscountDescri;
            model.ProductPictureId = productPictureId;
            model.StockNum         = stockNum;
            model.CustomMenuId     = customMenuId;

            Product         bll   = new Product();
            ProductItem     piBll = new ProductItem();
            CategoryProduct cpBll = new CategoryProduct();
            BrandProduct    bpBll = new BrandProduct();

            ProductItemInfo piModel = new ProductItemInfo();

            piModel.OtherPicture = sOtherPicture;
            piModel.SizeItem     = sSizeItem;
            piModel.SizePicture  = sSizePicture;
            piModel.PayOption    = sPayOption;
            piModel.CustomAttr   = string.Empty;
            piModel.Descr        = content;
            piModel.ProductId    = gId;

            int effect = -1;

            if (!gId.Equals(Guid.Empty))
            {
                bll.Update(model);
                piBll.Update(piModel);

                CategoryProductInfo cpModel = cpBll.GetModel(gId);
                BrandProductInfo    bpModel = bpBll.GetModel(gId);

                #region 所属分类

                if (!categoryId.Equals(Guid.Empty))
                {
                    if (cpModel == null)
                    {
                        cpModel            = new CategoryProductInfo();
                        cpModel.ProductId  = gId;
                        cpModel.CategoryId = categoryId;
                        cpBll.Insert(cpModel);
                    }
                    else
                    {
                        if (!cpModel.CategoryId.Equals(categoryId))
                        {
                            cpModel.CategoryId = categoryId;
                            cpBll.Update(cpModel);
                        }
                    }
                }
                else
                {
                    if (cpModel != null)
                    {
                        cpBll.Delete(gId, cpModel.CategoryId);
                    }
                }

                #endregion
                #region 所属品牌

                if (!brandId.Equals(Guid.Empty))
                {
                    if (bpModel == null)
                    {
                        bpModel           = new BrandProductInfo();
                        bpModel.ProductId = gId;
                        bpModel.BrandId   = brandId;
                        bpBll.Insert(bpModel);
                    }
                    else
                    {
                        if (!bpModel.BrandId.Equals(brandId))
                        {
                            bpModel.BrandId = brandId;
                            bpBll.Update(bpModel);
                        }
                    }
                }
                else
                {
                    if (bpModel != null)
                    {
                        bpBll.Delete(gId, bpModel.BrandId);
                    }
                }

                #endregion

                effect = 1;
            }
            else
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    Guid productId = bll.Insert(model);
                    piModel.ProductId = productId;
                    piBll.Insert(piModel);
                    if (!categoryId.Equals(Guid.Empty))
                    {
                        CategoryProductInfo cpModel = new CategoryProductInfo();
                        cpModel.CategoryId = categoryId;
                        cpModel.ProductId  = productId;
                        cpBll.Insert(cpModel);
                    }
                    if (!brandId.Equals(Guid.Empty))
                    {
                        BrandProductInfo bpModel = new BrandProductInfo();
                        bpModel.BrandId   = brandId;
                        bpModel.ProductId = productId;
                        bpBll.Insert(bpModel);
                    }

                    effect = 1;

                    scope.Complete();
                }
            }

            if (effect != 1)
            {
                context.Response.Write("{\"success\": false,\"message\": \"操作失败,请正确输入\"}");
                return;
            }

            context.Response.Write("{\"success\": true,\"message\": \"操作成功\"}");
        }
コード例 #8
0
 /// <summary>
 /// 修改数据
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Update(CategoryProductInfo model)
 {
     return(dal.Update(model));
 }
コード例 #9
0
 /// <summary>
 /// 添加数据到数据库
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Insert(CategoryProductInfo model)
 {
     return(dal.Insert(model));
 }