protected void GetProductPriceListByProductGroup(string productGroupId)
        {
            ProductPriceBLL productPrice = new ProductPriceBLL();

            try
            {
                DataTable dt = productPrice.GetProductPriceListByProductGroup(productGroupId);

                productPriceListGridView.DataSource = dt;
                productPriceListGridView.DataBind();

                for (int i = 0; i < productPriceListGridView.Rows.Count; i++)
                {
                    TextBox newPriceTextBox = (TextBox)productPriceListGridView.Rows[i].Cells[5].FindControl("newPriceTextBox");
                    TextBox newVATPercentageTextBox = (TextBox)productPriceListGridView.Rows[i].Cells[7].FindControl("newVATPercentageTextBox");

                    newPriceTextBox.Text = dt.Rows[i]["RatePerUnit"].ToString();
                    newVATPercentageTextBox.Text = dt.Rows[i]["VATPercentage"].ToString();
                }

                if (productPriceListGridView.Rows.Count > 0)
                {
                    productPriceListGridView.UseAccessibleHeader = true;
                    productPriceListGridView.HeaderRow.TableSection = TableRowSection.TableHeader;
                    updateButton.Visible = true;
                }
                else
                {
                    updateButton.Visible = false;
                    msgbox.Visible = true; msgTitleLabel.Text = "No price list is found for the selected product group."; msgDetailLabel.Text = "";
                    msgbox.Attributes.Add("class", "alert alert-warning");
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; }
                MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");
            }
            finally
            {
                productPrice = null;
                MyAlertBox("MyOverlayStop();");
            }
        }
        protected void GetOverallVATPercentage()
        {
            ProductPriceBLL productPrice = new ProductPriceBLL();

            try
            {
                DataTable dt = productPrice.GetOverallProductVAT();

                vatTextBox.Text = dt.Rows[0][0].ToString();
                vatTextBox.ReadOnly = true;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; }
                MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");
            }
            finally
            {
                productPrice = null;
                MyAlertBox("MyOverlayStop();");
            }
        }
        protected void updateAVGvatButton_Click(object sender, EventArgs e)
        {
            ProductPriceBLL productPrice = new ProductPriceBLL();

            try
            {
                if (overallVATTextBox.Text.Trim() == "")
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Validation!!!"; msgDetailLabel.Text = "Overall VAT(%) field is required.";
                }
                else
                {
                    productPrice.UpdateOverallProductVAT(overallVATTextBox.Text.Trim());

                    string message = "Overall VAT(%) <span class='actionTopic'>Updated</span> Successfully.";
                    MyAlertBox("SuccessAlert(\"" + "Process Succeed" + "\", \"" + message + "\", \"\");");
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; }
                MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");
            }
            finally
            {
                productPrice = null;
                MyAlertBox("MyOverlayStop();");
            }
        }
        protected void updateButton_Click(object sender, EventArgs e)
        {
            string msg = string.Empty;
            List<ProductPriceBLL> productPrices = new List<ProductPriceBLL>();
            ProductPriceBLL productPrice;
            decimal newRate = 0;
            decimal newUnitPrice = 0;
            float newVAT = 0;
            CheckBox selectCheckBox;
            TextBox newPriceTextBox;
            TextBox newUnitPriceTextBox;
            TextBox newVATPercentageTextBox;
            int i = 0;

            try
            {
                for (i = 0; i < productPriceListGridView.Rows.Count; i++)
                {
                    selectCheckBox = (CheckBox)productPriceListGridView.Rows[i].Cells[7].FindControl("selectCheckBox");
                    newUnitPriceTextBox = (TextBox)productPriceListGridView.Rows[i].Cells[4].FindControl("lastUnitTextBox");
                    newPriceTextBox = (TextBox)productPriceListGridView.Rows[i].Cells[5].FindControl("newPriceTextBox");
                    newVATPercentageTextBox = (TextBox)productPriceListGridView.Rows[i].Cells[6].FindControl("newVATPercentageTextBox");

                    if (selectCheckBox.Checked && string.IsNullOrEmpty(newPriceTextBox.Text.Trim()))
                    {
                        msg = "Product ID [" + productPriceListGridView.Rows[i].Cells[0].Text.ToString() + "] has no price to update new price.";
                        msgbox.Visible = true; msgTitleLabel.Text = "Warning!!!"; msgDetailLabel.Text = msg;
                        return;
                    }
                    else if (selectCheckBox.Checked && string.IsNullOrEmpty(newVATPercentageTextBox.Text.Trim()))
                    {
                        msg = "Product ID [" + productPriceListGridView.Rows[i].Cells[0].Text.ToString() + "] has no Discount(%) to update Discount VAT(%).";
                        msgbox.Visible = true; msgTitleLabel.Text = "Warning!!!"; msgDetailLabel.Text = msg;
                        return;
                    }
                    else if (selectCheckBox.Checked)
                    {
                        newUnitPrice = decimal.Parse(newUnitPriceTextBox.Text.Trim());
                        newRate = decimal.Parse(newPriceTextBox.Text.Trim());
                        newVAT = float.Parse(newVATPercentageTextBox.Text.Trim());

                        productPrice = new ProductPriceBLL();
                        productPrice.ProductId = productPriceListGridView.Rows[i].Cells[0].Text.ToString();
                        productPrice.RatePerUnit = newRate;
                        productPrice.VATPercentage = newVAT;
                        productPrice.NewUnitPrice = newUnitPrice;

                        productPrices.Add(productPrice);
                    }
                }

                if (productPrices.Count > 0)
                {
                    productPrice = new ProductPriceBLL();
                    productPrice.UpdateProductPriceList(productPrices);

                    string message = "Product Price(s) & Discount(%) <span class='actionTopic'>Updated</span> Successfully.";
                    MyAlertBox("var callbackOk = function () { $('#allProductListButton').click(); }; SuccessAlert(\"" + "Process Succeed" + "\", \"" + message + "\", callbackOk);");
                }
                else if (string.IsNullOrEmpty(msg))
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "Warning!!!"; msgDetailLabel.Text = "No Product is selected to update product price.";
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "Input string was not in a correct format.")
                {
                    msg = "Product ID [" + productPriceListGridView.Rows[i].Cells[0].Text.ToString() + "] has no valid price or VAT(%) to update new price.";
                    msgbox.Visible = true; msgTitleLabel.Text = "Exception!!!"; msgDetailLabel.Text = msg;
                }
                else
                {
                    string message = ex.Message;
                    if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; }
                    MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");
                }
            }
            finally
            {
                productPrice = null;
                MyAlertBox("MyOverlayStop();");
            }
        }