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;
            }
        }
Exemple #2
0
        protected void saveButton_Click(object sender, EventArgs e)
        {
            ProductBLL product = new ProductBLL();

            try
            {
                //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 (productRateTextBox.Text == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Product Rate field is required.";
                }
                //else if (vatPercentageTextBox.Text == "")
                //{
                //    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "VAT field is required.";
                //}
                else if (productGroupDropDownList.SelectedValue == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Product Group field is required.";
                }
                //else if (vendorDropDownList.SelectedValue == "")
                //{
                //    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Product Vendor field is required.";
                //}
                else
                {
                    int isaddanother = 1;

                    Button btn = (Button)sender;

                    if (btn.Text == "Save")
                    {
                        isaddanother = 0;
                    }

                    product.ProductNameOnly = productNameOnlyTextBox.Text.Trim();
                    product.Barcode = ""; //barcodeTextBox.Text.Trim();
                    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.additinalInfo = txtBxAddition.Text.Trim();
                    product.VolumeQuantity = decimal.Parse(volumeQuantityTextBox.Text.Trim());
                    product.Unit = unitTextBox.Text.Trim();
                    product.ProductRate = decimal.Parse(productRateTextBox.Text.Trim());
                    product.ProductName = product.ProductNameOnly.Trim() + " [" + " (" + product.additinalInfo.Trim() + ") " + product.ProductVolume.Trim() + "]";
                    product.VendorId = vendorDropDownList.SelectedValue;
                    product.VATPercentage = float.Parse(vatPercentageTextBox.Text.Trim());
                    product.WareHouseId = warehouseDropDownList.SelectedValue;
                    product.salescenter = "";

                    product.productDesc = txtProductDesc.Text.Trim();

                    //if (!product.CheckDuplicateProductByBarcode(product.Barcode.Trim()))
                    //{
                    if (!product.CheckDuplicateProductByName(product.ProductName.Trim(), product.WareHouseId, product.salescenter))
                    {
                        List<string> mainProductList = new List<string>();

                        if (productTypeDropDownList.SelectedValue == "No")
                        {
                            for (int i = 0; i < mainProductListListBox.Items.Count; i++)
                            {
                                mainProductList.Add(mainProductListListBox.Items[i].Value);
                            }
                        }
                        product.productImageName = "";//saveProductImage(product.Barcode);
                        DataTable dt = product.SaveProduct(mainProductList);

                        if (dt.Rows.Count > 0)
                        {
                            if (isaddanother == 0)
                            {
                                string message =
                                    "Product <span class='actionTopic'>Created</span> Successfully with Product ID: <span class='actionTopic'>" +
                                    dt.Rows[0][0].ToString() + "</span>.";
                                MyAlertBox(
                                    "var callbackOk = function () { MyOverlayStart(); window.location = \"/UI/Product/List.aspx\"; }; SuccessAlert(\"" +
                                    "Process Succeed" + "\", \"" + message + "\", callbackOk);");

                            }
                            else
                            {
                                string message =
                                   "Product <span class='actionTopic'>Created</span> Successfully with Product ID: <span class='actionTopic'>" +
                                   dt.Rows[0][0].ToString() + "</span>.";
                                MyAlertBox(
                                    "var callbackOk = function () { MyOverlayStart(); window.location = \"/UI/Product/Create.aspx\"; }; SuccessAlert(\"" +
                                    "Process Succeed" + "\", \"" + message + "\", callbackOk);");

                            }
                        }
                        else
                        {
                            string message = "<span class='actionTopic'>Failed</span> to Create Product.";
                            MyAlertBox("ErrorAlert(\"" + "Process Failed" + "\", \"" + message + "\");");
                        }
                    }
                    else
                    {
                        string message = "This Product Name <span class='actionTopic'>already exist</span>, try another one.";
                        MyAlertBox("WarningAlert(\"" + "Data Duplicate" + "\", \"" + message + "\");");
                    }
                    //}
                    //else
                    //{
                    //    string message = "This Barcode <span class='actionTopic'>already exist</span>, try another one.";
                    //    MyAlertBox("WarningAlert(\"" + "Data Duplicate" + "\", \"" + message + "\");");
                    //}
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; }
                MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");
            }
            finally
            {
                product = null;
            }
        }