protected void btnSave_Click(object sender, EventArgs e) { _productManager = new ProductManager(this); product = new Product(); if (Page.ViewState["ProductId"] != null) { originalProduct = _productManager.GetProduct(Convert.ToInt32(Page.ViewState["ProductId"])); } else if (_productManager.CheckIfProductCodeExists(Company.CompanyId, txtProductCode.Text)) { ShowError(Exception.DuplicateCode); return; } if (originalProduct == null) originalProduct = _productManager.GetTempProduct(Convert.ToInt32(Page.ViewState["ProductId"]), Company.CompanyId); if (originalProduct != null) product.CopyPropertiesFrom(originalProduct); product.CompanyId = (Int32)Company.MatrixId; if (!String.IsNullOrEmpty(cboCategories.SelectedValue)) product.CategoryId = Convert.ToInt32(cboCategories.SelectedValue); product.Name = txtProduct.Name; InsertManufacturer(product); product.ProductCode = txtProductCode.Text; product.BarCode = txtBarCode.Text; product.IdentificationOrPlaca = txtIdentificationOrPlaca.Text; product.PatrimonioOrRenavam = txtPatrimonioOrRenavam.Text; product.SerialNumberOrChassi = txtSerialNumberOrChassi.Text; product.IPI = ucCurrFieldIPI.CurrencyValue; product.ICMS = ucCurrFieldICMS.CurrencyValue; product.FiscalClass = txtFiscalClass.Text; product.WarrantyDays = ucCurrFieldWarrantyDays.IntValue; product.Description = DescriptionTextBox.Value; product.IsActive = ChkIsActive.Checked; product.DropCompositeInStock = Convert.ToBoolean(chkDropCompositeInStock.Checked); product.AddCustomerEquipmentInSale = Convert.ToBoolean(chkAddCustomerEquipment.Checked); product.AllowNegativeStock = Convert.ToBoolean(chkAllowNegativeStock.Checked); product.AllowSaleBelowCost = Convert.ToBoolean(chkAllowSaleBelowCost.Checked); product.ModifiedDate = DateTime.Now; product.RequiresAuthorization = chkRequiresAuthorization.Checked; #region Optional Fields /* * Add fields here that may not be used or only used in some companies(_companies) * Here is made a verification if there's value in the control to not assign a value * to the DataBank from a null control and prevent exceptions */ if (!String.IsNullOrEmpty(cboBarCodeType.SelectedValue)) product.BarCodeTypeId = Convert.ToInt32(cboBarCodeType.SelectedValue); if (txtUnit != null) product.Unit = txtUnit.Text; if (txtKeyWord != null) product.Keywords = txtKeyWord.Text; if (txtPackage != null) product.Package = txtPackage.Text; if (chkIsEmphasizeInHome != null) product.EmphasizeInHome = chkIsEmphasizeInHome.Checked; if (chkIsCasting != null) product.IsCasting = chkIsCasting.Checked; if (ucCurrFieldWheight != null) product.Weight = ucCurrFieldWheight.CurrencyValue; #endregion if (!String.IsNullOrEmpty(Request["IsTemp"])) product.IsTemp = true; string redirectUrl = ""; if (originalProduct == null) { product.CreatedByUser = User.Identity.UserName; _productManager.Insert(product); } else { product.ModifiedByUser = User.Identity.UserName; _productManager.Update(originalProduct, product); redirectUrl = "parent."; } if (((WebControl)sender).ID == "btnSaveAndNew") redirectUrl += "location='Product_General.aspx';"; else { if (product.IsTemp == true) redirectUrl += "location='../Purchasing/PurchaseRequests.aspx';"; else redirectUrl += "location='Product.aspx?ProductId=" + product.ProductId + "'"; } Page.ClientScript.RegisterClientScriptBlock(GetType(), "", redirectUrl, true); }