コード例 #1
0
 private void Save(object sender, EventArgs e)
 {
     if (!CheckGood())
     {
         MessageBox.Show("You didn't write right", "TRY AGAIN", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
         All_White();
     }
     else
     {
         CategoryProduct categoryProduct = FormToCategoryProduct();
         if (categoryProduct.ID == 0)
         {
             CategoryProductArr oldCategoryProductArr = new CategoryProductArr();
             oldCategoryProductArr.Fill();
             if (!oldCategoryProductArr.IsContains(categoryProduct))
             {
                 if (categoryProduct.Insert())
                 {
                     MessageBox.Show("CategoryProduct Details Saved");
                     Clean_Form();
                     CategoryProductArr categoryProductArr = new CategoryProductArr();
                     categoryProductArr.Fill();
                     categoryProduct = categoryProductArr.GetCategoryRoonWithMaxId();
                     CategoryProductArrToForm(categoryProduct);
                     Close();
                 }
                 else
                 {
                     MessageBox.Show("Cannot Save CategoryProduct Details");
                 }
             }
             else
             {
                 MessageBox.Show("CategoryProduct already existing");
             }
         }
         else
         {
             if (categoryProduct.Update())
             {
                 MessageBox.Show("CategoryProduct Details UPDATED");
                 Clean_Form();
                 CategoryProductArrToForm(null);
             }
             else
             {
                 MessageBox.Show("Cannot UPDATE CategoryProduct Details");
             }
         }
     }
 }
コード例 #2
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\": \"操作成功\"}");
        }