示例#1
0
        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                // First lets save the product
                SimpleProductInfo SimpleProduct = null;
                bool isNew = false;

                if (ProductId >= 0)
                {
                    SimpleProduct = Controller.GetSimpleProductByProductId(PortalId, ProductId);
                }
                else
                {
                    isNew = true;
                }

                if (SimpleProduct != null)
                {
                    SimpleProduct.Image                = BBStoreHelper.GetRelativeFilePath(ImageSelector.Url);
                    SimpleProduct.ItemNo               = txtItemNo.Text.Trim();
                    SimpleProduct.UnitCost             = taxUnitCost.NetPrice;
                    SimpleProduct.OriginalUnitCost     = taxOriginalUnitCost.NetPrice;
                    SimpleProduct.TaxPercent           = Convert.ToDecimal(txtTaxPercent.Text.Trim());
                    SimpleProduct.LastModifiedByUserId = UserId;
                    SimpleProduct.LastModifiedOnDate   = DateTime.Now;
                    SimpleProduct.Disabled             = chkDisabled.Checked;
                    SimpleProduct.HideCost             = chkHideCost.Checked;
                    SimpleProduct.NoCart               = chkNoCart.Checked;
                    SimpleProduct.SupplierId           = String.IsNullOrEmpty(cboSupplier.SelectedValue) ? -1 : Convert.ToInt32(cboSupplier.SelectedValue);
                    SimpleProduct.UnitId               = String.IsNullOrEmpty(ddlUnit.SelectedValue) ? -1 : Convert.ToInt32(ddlUnit.SelectedValue);
                    SimpleProduct.Weight               = Convert.ToDecimal(txtWeight.Text.Trim());
                    Controller.UpdateSimpleProduct(SimpleProduct);
                }
                else
                {
                    SimpleProduct                      = new SimpleProductInfo();
                    SimpleProduct.PortalId             = PortalId;
                    SimpleProduct.Image                = BBStoreHelper.GetRelativeFilePath(ImageSelector.Url);
                    SimpleProduct.ItemNo               = txtItemNo.Text.Trim();
                    SimpleProduct.UnitCost             = taxUnitCost.NetPrice;
                    SimpleProduct.OriginalUnitCost     = taxOriginalUnitCost.NetPrice;
                    SimpleProduct.TaxPercent           = Convert.ToDecimal(txtTaxPercent.Text.Trim());
                    SimpleProduct.CreatedOnDate        = DateTime.Now;
                    SimpleProduct.LastModifiedOnDate   = DateTime.Now;
                    SimpleProduct.CreatedByUserId      = UserId;
                    SimpleProduct.LastModifiedByUserId = UserId;
                    SimpleProduct.Disabled             = chkDisabled.Checked;
                    SimpleProduct.HideCost             = chkHideCost.Checked;
                    SimpleProduct.NoCart               = chkNoCart.Checked;
                    SimpleProduct.SupplierId           = String.IsNullOrEmpty(cboSupplier.SelectedValue) ? -1 : Convert.ToInt32(cboSupplier.SelectedValue);
                    SimpleProduct.UnitId               = String.IsNullOrEmpty(ddlUnit.SelectedValue) ? -1 : Convert.ToInt32(ddlUnit.SelectedValue);
                    SimpleProduct.Weight               = Convert.ToDecimal(txtWeight.Text.Trim());
                    ProductId = Controller.NewSimpleProduct(SimpleProduct);
                }

                // Lets update the ShippingModel
                Controller.DeleteProductShippingModelByProduct(ProductId);
                int shippingModelId = -1;
                if (cboShippingModel.SelectedValue != null && Int32.TryParse(cboShippingModel.SelectedValue, out shippingModelId))
                {
                    Controller.InsertProductShippingModel(new ProductShippingModelInfo()
                    {
                        ShippingModelId = shippingModelId, SimpleProductId = ProductId
                    });
                }


                // Now lets update Language information
                lngSimpleProducts.UpdateLangs();
                Controller.DeleteSimpleProductLangs(ProductId);
                foreach (SimpleProductLangInfo si in lngSimpleProducts.Langs)
                {
                    si.SimpleProductId = ProductId;
                    Controller.NewSimpleProductLang(si);
                }

                // Lets handle the Product Groups
                int redirProductGroupId = 0;
                if (HasProductGroupModule)
                {
                    if (Request.QueryString["productgroup"] != null)
                    {
                        redirProductGroupId = Convert.ToInt32(Request.QueryString["productgroup"]);
                    }


                    Controller.DeleteProductInGroups(ProductId);
                    foreach (TreeNode node in treeProductGroup.CheckedNodes)
                    {
                        int ProductGroupId = Convert.ToInt32(node.Value.Substring(1));
                        Controller.NewProductInGroup(ProductId, ProductGroupId);
                        if (redirProductGroupId == 0)
                        {
                            redirProductGroupId = ProductGroupId;
                        }
                    }
                }

                // If we created a new product, we bound this as a fixed product to the module
                if (isNew && this.Parent.NamingContainer.ID != "ViewAdmin")
                {
                    ModuleController module = new ModuleController();
                    module.UpdateModuleSetting(ModuleId, "ProductId", ProductId.ToString());
                }
                FeatureGrid.SaveFeatures();

                List <string> addParams = new List <string>();

                if (Request["adminmode"] != null)
                {
                    addParams.Add("adminmode=productlist");
                }
                if (redirProductGroupId > 0)
                {
                    addParams.Add("productgroup=" + redirProductGroupId.ToString());
                }
                addParams.Add("productId=" + ProductId.ToString());

                Response.Redirect(Globals.NavigateURL(TabId, "", addParams.ToArray()), true);
            }
            catch (Exception exc)
            {
                //Module failed to load
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }