Exemple #1
0
        protected void updateButton_Click(object sender, EventArgs e)
        {
            ProductBLL product = new ProductBLL();

            try
            {
                if (productIdForUpdateHiddenField.Value.Trim() == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = "Product not found to update.";
                }
                //else if (barcodeTextBox.Text == "")
                //{
                //    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Barcode Name field is required.";
                //}
                else if (productNameOnlyTextBox.Text == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Product Name field is required.";
                }
                else if (productVolumeTextBox.Text == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Product Volume field is required.";
                }
                //else if (volumeQuantityTextBox.Text == "")
                //{
                //    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Volume Quantity field is required.";
                //}
                else if (unitTextBox.Text == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Unit field is required.";
                }
                //else if (vendorDropDownList.SelectedValue == "")
                //{
                //    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Product Vendor field is required.";
                //}
                else if (productGroupDropDownList.SelectedValue == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Product Group field is required.";
                }
                else
                {
                    product.ProductId = productIdForUpdateHiddenField.Value.Trim();
                    product.ProductNameOnly = productNameOnlyTextBox.Text.Trim();
                    product.Barcode = "";
                    product.ProductGroupId = productGroupDropDownList.SelectedValue.Trim();
                    product.SecondaryUnit = "";//secondaryUnitTextBox.Text.Trim();
                    product.ProductType = productTypeDropDownList.SelectedValue.Trim();
                    product.SubProduct = subProductDropDownList.SelectedValue.Trim();
                    product.ProductVolume = productVolumeTextBox.Text.Trim();
                    product.VolumeQuantity = decimal.Parse(volumeQuantityTextBox.Text.Trim());
                    product.Unit = unitTextBox.Text.Trim();
                    product.additinalInfo = txtBxAddition.Text;
                    if (productTypeDropDownList.SelectedValue == "Yes")
                    {
                        product.VendorId = vendorDropDownList.SelectedValue;
                    }
                    else
                    {
                        product.VendorId = "";
                    }
                    product.ProductName = product.ProductNameOnly.Trim() + "[" + " (" + product.additinalInfo.Trim() + ") " + product.ProductVolume.Trim() + "]";
                    product.salescenter = ""; //salescenterDropDownList.SelectedValue;
                    product.WareHouseId = warehouseDropDownList.SelectedValue;
                    product.productImageName = "";
                    product.productDesc = txtProductDesc.Text;

                    string updateCondition = "";

                    //if (barcodeForUpdateHiddenField.Value != product.Barcode.Trim())
                    //{
                    //    if (!product.CheckDuplicateProductByBarcode(product.Barcode.Trim()))
                    //    {
                    //        updateCondition += "Brc";
                    //    }
                    //    else
                    //    {
                    //        string message1 = "This Barcode <span class='actionTopic'>already exist</span>, try another one.";
                    //        MyAlertBox("WarningAlert(\"" + "Data Duplicate" + "\", \"" + message1 + "\");");
                    //        return;
                    //    }
                    //}

                    if (productNameForUpdateHiddenField.Value != product.ProductName.Trim())
                    {
                        if (!product.CheckDuplicateProductByName(product.ProductName.Trim(), product.WareHouseId, product.salescenter))
                        {
                            updateCondition += "Prdn";
                        }
                        else
                        {
                            string message2 = "This Product Name <span class='actionTopic'>already exist</span>, try another one.";
                            MyAlertBox("WarningAlert(\"" + "Data Duplicate" + "\", \"" + message2 + "\");");
                            return;
                        }
                    }
                    //string iamgeName = saveProductImage(product.Barcode.Trim());
                    //if (iamgeName == "")
                    //{
                    //    product.productImageName = ImageNameHiddenField.Value;
                    //}
                    //else
                    //{
                    //    product.productImageName = iamgeName;
                    //}
                    List<string> mainProductList = new List<string>();

                    for (int i = 0; i < mainProductListListBox.Items.Count; i++)
                    {
                        mainProductList.Add(mainProductListListBox.Items[i].Value);
                    }
                    product.UpdateProduct(mainProductList, updateCondition);
                    productNameForUpdateHiddenField.Value = "";
                    productIdForUpdateHiddenField.Value = "";
                    barcodeForUpdateHiddenField.Value = "";

                    string message = "Product <span class='actionTopic'>Updated</span> Successfully.";
                    MyAlertBox("var callbackOk = function () { MyOverlayStart(); window.location = \"/UI/Product/List.aspx\"; }; SuccessAlert(\"" + "Process Succeed" + "\", \"" + message + "\", callbackOk);");
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; }
                MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");
            }
            finally
            {
                product = null;
            }
        }