Пример #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            decimal retailPrice = 0;

            if (!string.IsNullOrEmpty(txtRetailPrice.Text))
            {
                decimal.TryParse(txtRetailPrice.Text, out retailPrice);
            }
            decimal salePrice = 0;

            decimal.TryParse(txtSalePrice.Text, out salePrice);
            decimal vipPrice = 0;

            decimal.TryParse(txtVipPrice.Text, out vipPrice);

            HttpPostedFile imageFile = null;

            if (radImgNew.Checked && fupFile.PostedFile != null &&
                fupFile.PostedFile.ContentLength != 0)
            {
                imageFile = fupFile.PostedFile;
            }

            HttpPostedFile image2File = null;

            if (fup2.PostedFile != null && fup2.PostedFile.ContentLength != 0)
            {
                image2File = fup2.PostedFile;
            }

            HttpPostedFile image3File = null;

            if (fup3.PostedFile != null && fup3.PostedFile.ContentLength != 0)
            {
                image3File = fup3.PostedFile;
            }

            HttpPostedFile image4File = null;

            if (fup4.PostedFile != null && fup4.PostedFile.ContentLength != 0)
            {
                image4File = fup4.PostedFile;
            }

            List <int> colorIDs = new List <int>();

            foreach (ListItem item in chkColors.Items)
            {
                if (item.Selected)
                {
                    colorIDs.Add(int.Parse(item.Value));
                }
            }

            int animeID = 0;

            int.TryParse(ddlAnimes.SelectedValue, out animeID);

            if (_product == null)
            {
                _product = new StoreProduct();
            }
            _product.AnimeID     = animeID;
            _product.ProductCode = txtCode.Text;
            _product.Name        = txtName.Text;
            _product.Description = txtDescription.Text;
            _product.Title       = txtShortDescription.Text;
            _product.PageName    = txtUrl.Text;
            _product.IsActive    = chkApproved.Checked;
            _product.IsFeatured  = chkFeatured.Checked;
            if (imageFile != null)
            {
                string path = Server.MapPath("~/images/");
                imageFile.SaveAs(string.Format("{0}{1}", path, imageFile.FileName));
                _product.ImageFile = imageFile.FileName;
            }
            if (image2File != null)
            {
                _product.ImageFile2 = image2File.FileName;
            }
            if (image3File != null)
            {
                _product.ImageFile3 = image3File.FileName;
            }
            if (image4File != null)
            {
                _product.ImageFile4 = image4File.FileName;
            }
            if (retailPrice > 0)
            {
                _product.RetailPrice = retailPrice;
            }
            if (salePrice > 0)
            {
                _product.SalePrice = salePrice;
            }
            if (vipPrice > 0)
            {
                _product.VIPPrice = vipPrice;
            }

            storeProductRep.SaveProduct(_product);
        }
Пример #2
0
        protected void btn_continue_Click(object sender, EventArgs e)
        {
            if (!this.ProductYes.Checked && !this.ProductNo.Checked)
            {
                MyCommon.Alert("请选择产品属性.");
                return;
            }
            if (this.ProductYes.Checked)
            {
                int Variant1 = MyCommon.ToInt(this.ddl_Vaiant1.SelectedValue);
                int Variant2 = MyCommon.ToInt(this.ddl_Vaiant2.SelectedValue);

                if (Variant1 == 0 && Variant2 == 0)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>alert('请选择属性.');</script>");
                    return;
                }
                if (_StoreProduct.GetProductByID(MyCommon.ToLong(this.HiddenField_proId.Value)).Variant1TypeID == Variant1 &&
                    _StoreProduct.GetProductByID(MyCommon.ToLong(this.HiddenField_proId.Value)).Variant2TypeID == Variant2)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>alert('选择的属性与现有属性相同,请重新选择.');</script>");
                    return;
                }
                if (Variant1 == Variant2)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>alert('选择的两种属性相同,请重新选择.');</script>");
                    return;
                }
                if (Variant1 > 0)
                {
                    if (_StoreVariantTypeOptions.GetStoreVariantTypeOptionByVariantTypeID(Variant1).Count == 0)
                    {
                        string name = _StoreVariantTypes.GetStoreVariantTypeByID(Variant1).GroupName;
                        ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>alert('属性1[" + name + "]中无数据,请添加.');</script>");
                        VaiantNo.Style.Value   = "display: none;";
                        VaiantYes.Style.Value  = "display: block;";
                        div_detail.Style.Value = "display: block;";
                        return;
                    }
                }
                if (Variant2 > 0)
                {
                    if (_StoreVariantTypeOptions.GetStoreVariantTypeOptionByVariantTypeID(Variant2).Count == 0)
                    {
                        string name = _StoreVariantTypes.GetStoreVariantTypeByID(Variant2).GroupName;
                        ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>alert('属性2[" + name + "]中无数据,请添加.');</script>");
                        VaiantNo.Style.Value   = "display: none;";
                        VaiantYes.Style.Value  = "display: block;";
                        div_detail.Style.Value = "display: block;";
                        return;
                    }
                }
            }

            StoreProductInventory inv = new StoreProductInventory();

            inv.ProductID = MyCommon.ToLong(this.HiddenField_proId.Value);
            inv.QtyAvail  = 0;
            inv.QtySold   = 0;
            inv.QtyOnHold = 0;
            inv.SortOrder = 0;

            if (this.ProductNo.Checked)
            {
                _StoreProductInventoy.DelProductInventoryByProduct(MyCommon.ToLong(this.HiddenField_proId.Value));

                inv.QtyAvail = MyCommon.ToInt(this.ProductNum.Text);
                _StoreProductInventoy.SaveProductInventory(inv);

                StoreProduct product = _StoreProduct.GetProductByID(MyCommon.ToLong(this.HiddenField_proId.Value));
                product.Variant1TypeID = null;
                product.Variant2TypeID = null;
                _StoreProduct.SaveProduct(product);
                MyCommon.Alert("保存库存数量成功.", "ProductList.aspx");
            }

            if (this.ProductYes.Checked)
            {
                int Variant1 = MyCommon.ToInt(this.ddl_Vaiant1.SelectedValue);
                int Variant2 = MyCommon.ToInt(this.ddl_Vaiant2.SelectedValue);

                //当修改一个属性,清空库存
                if (_StoreProduct.GetProductByID(MyCommon.ToLong(this.HiddenField_proId.Value)).Variant1TypeID != Variant1 ||
                    _StoreProduct.GetProductByID(MyCommon.ToLong(this.HiddenField_proId.Value)).Variant2TypeID != Variant2)
                {
                    _StoreProductInventoy.DelProductInventoryByProduct(MyCommon.ToLong(this.HiddenField_proId.Value));
                }
                _StoreProductInventoy.SaveProductInventory(inv);

                StoreProduct product = _StoreProduct.GetProductByID(MyCommon.ToLong(this.HiddenField_proId.Value));
                if (Variant1 == 0)
                {
                    product.Variant1TypeID = null;
                }
                else
                {
                    product.Variant1TypeID = Variant1;
                }
                if (Variant2 == 0)
                {
                    product.Variant2TypeID = null;
                }
                else
                {
                    product.Variant2TypeID = Variant2;
                }
                _StoreProduct.SaveProduct(product);

                ShowVariant(Variant1, Variant2);
                BindRepeater(MyCommon.ToInt(this.HiddenField_proId.Value));

                VaiantNo.Style.Value  = "display: none;";
                VaiantYes.Style.Value = "display: block;";
                ProductNum.Text       = "0";
            }
        }