//private void BindTextGroupCode(string TextGroupCode, DropDownList dd_TextGroupCode)
    //{
    //    try
    //    {
    //        List<ProductCat> list = ProductCat.ListTextGroupCode();
    //        if (list != null && list.Count > 0)
    //        {
    //            dd_TextGroupCode.DataSource = list;
    //            dd_TextGroupCode.DataTextField = "Code";
    //            dd_TextGroupCode.DataValueField = "Code";
    //            dd_TextGroupCode.DataBind();
    //            dd_TextGroupCode.Items.Insert(0, new ListItem("-Select-", "0"));
    //        }
    //        else
    //        {
    //            dd_TextGroupCode.DataSource = null;
    //            dd_TextGroupCode.DataBind();
    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        l_Error.Text = ex.Message;
    //        l_Error.Visible = true;
    //    }
    //}

    public void btn_Update(object sender, EventArgs e)
    {
        try
        {
            Boolean flag = false;
            if (drpNoseries.SelectedIndex == 0)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please select sales order no series.');", true);
            }
            else if (drpStructure.SelectedIndex == 0)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please select structure.');", true);
            }
            else if (drpProductCode.SelectedIndex == 0)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please select Product code.');", true);
            }
            else if (txtDestination.Text == "")
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please enter Destination.');", true);
            }
            else if (drplocationcode.SelectedIndex == 0)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please select Location code.');", true);
            }
            else
            {
                NetworkCredential NetCredentials = new NetworkCredential();
                NetCredentials.UserName = ConfigurationManager.AppSettings["UserName"];
                NetCredentials.Password = ConfigurationManager.AppSettings["Password"];

                foreach (RepeaterItem item in rpt_FinalCart.Items)
                {
                    HiddenField  ItemNo                   = (HiddenField)item.FindControl("hf_ItemNo");
                    HiddenField  LineNo                   = (HiddenField)item.FindControl("hf_LineNo");
                    TextBox      Qty_to_Ship              = (TextBox)item.FindControl("Qty_to_Ship");
                    TextBox      tb_Discount              = (TextBox)item.FindControl("tb_discount");
                    Label        lbl_QTY                  = (Label)item.FindControl("lbl_QTY");
                    DropDownList dd_TaxAreaCode           = (DropDownList)item.FindControl("dd_TaxAreaCode");
                    TextBox      dd_TaxGroupCode          = (TextBox)item.FindControl("dd_TaxGroupCode");
                    DropDownList dd_Excise_PostingGrpCode = (DropDownList)item.FindControl("dd_Excise_PostingGrpCode");

                    Label lbl_SalesOrderNo = (Label)item.FindControl("lbl_SalesOrderNo");
                    Label lbl_home_logo    = (Label)item.FindControl("lbl_home_logo");

                    if (Qty_to_Ship.Text == "")
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Quantity to Ship should not be allowed blank.');", true);
                        flag = true;
                    }
                    else if (Convert.ToDecimal(Qty_to_Ship.Text) == 0)
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Quantity to Ship should not be allowed zero.');", true);
                        Qty_to_Ship.Focus();
                        flag = true;
                    }
                    else if (Convert.ToDecimal(Qty_to_Ship.Text) > Convert.ToDecimal(lbl_QTY.Text))
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Quantity to Ship should not be greater than Order Quantity.');", true);
                        Qty_to_Ship.Focus();
                        flag = true;
                    }
                    else if (Convert.ToString(tb_Discount.Text) == "")
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Discount should not be allowed blank.');", true);
                        tb_Discount.Focus();
                        tb_Discount.Text = Convert.ToString(0);
                        flag             = true;
                    }
                    //else if (dd_TaxGroupCode.SelectedIndex == 0)
                    //{
                    //    ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please select Tax Group Code.');", true);
                    //    flag = true;
                    //}
                    else if (dd_Excise_PostingGrpCode.SelectedIndex == 0)
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please select Excise Group Code.');", true);
                        flag = true;
                    }
                    else
                    {
                        string str = string.Empty;
                        if (drpFormCode.SelectedIndex == 0)
                        {
                            str = "";
                        }
                        else
                        {
                            str = Convert.ToString(drpFormCode.SelectedValue);
                        }
                        // Update Values of Blanket Sales  Order by Codeunit Function.
                        Web_Order_Mail objser1 = new Web_Order_Mail();
                        objser1.UseDefaultCredentials = true;
                        objser1.Credentials           = NetCredentials;
                        objser1.UpdateBlanketOrder(Convert.ToString(Request.QueryString["OrderNo"]), string.Empty, drpProductCode.SelectedItem.Value, drpStructure.SelectedItem.Value, txtTransporterName.Text, drpNoseries.SelectedItem.Value, txtDestination.Text, Convert.ToString(str), drplocationcode.SelectedValue);
                        objser1 = null;

                        // Update Quantity to ship in  Sales  Order by Codeunit Function.
                        Web_Order_Mail objser = new Web_Order_Mail();
                        objser.UseDefaultCredentials = true;
                        objser.Credentials           = NetCredentials;
                        objser.UpdateQtyToShip(Convert.ToString(Request.QueryString["OrderNo"]), Convert.ToInt32(LineNo.Value), Convert.ToDecimal(Qty_to_Ship.Text), Convert.ToDecimal(tb_Discount.Text), string.Empty, Convert.ToString(dd_TaxGroupCode.Text), Convert.ToString(dd_Excise_PostingGrpCode.SelectedItem.Value));
                        objser = null;
                    }
                }
                if (flag == true)
                {
                }
                else
                {
                    // Release Blanket Sales  Order by Codeunit Function.
                    Web_Order_Mail objservice = new Web_Order_Mail();
                    objservice.UseDefaultCredentials = true;
                    objservice.Credentials           = NetCredentials;
                    objservice.ReleaseBlanketOrder(Convert.ToString(Request.QueryString["OrderNo"]));
                    objservice = null;

                    // Make Order By Codeunit Function Return with OrderNo.
                    Web_Order_Mail objser2 = new Web_Order_Mail();
                    objser2.UseDefaultCredentials = true;
                    objser2.Credentials           = NetCredentials;
                    string MakeOrderNo = objser2.MakeOrder(4, Convert.ToString(Request.QueryString["OrderNo"]));
                    objser2 = null;

                    //lb_Update.Visible = false;
                    //lb_Satistic.Visible = true;
                    //lbl_home_logo.Visible = false;

                    lb_Update.Visible   = false;
                    lb_Satistic.Visible = true;

                    // lbl_home_logo.Visible = false;

                    lbl_SalesOrderNo.Visible = true;
                    lblOrderNo.Visible       = false;
                    blanketOrder_tr.Visible  = true;

                    lbl_blk_No.Text         = Convert.ToString(Request.QueryString["OrderNo"]);
                    ViewState["SalesOrder"] = Convert.ToString(MakeOrderNo);
                    lbl_SalesOrderNo.Text   = Convert.ToString(MakeOrderNo);
                    var message = new JavaScriptSerializer().Serialize("Order has been successfully updated and Sales Order generated - Sales Order No. " + MakeOrderNo.ToString() + "");
                    var script  = string.Format("alert({0});", message);
                    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", script, true);
                }
            }
        }
        catch (Exception ex)
        {
            string            IsSalesOrderExist = string.Empty;
            NetworkCredential NetCredentials    = new NetworkCredential();
            NetCredentials.UserName = ConfigurationManager.AppSettings["UserName"];
            NetCredentials.Password = ConfigurationManager.AppSettings["Password"];

            Web_Order_Mail objservice = new Web_Order_Mail();
            objservice.UseDefaultCredentials = true;
            objservice.Credentials           = NetCredentials;

            IsSalesOrderExist = objservice.IsOrderExistfromBlanketOrder(Convert.ToString(Request.QueryString["OrderNo"]));
            if (IsSalesOrderExist != "")
            {
                lb_Update.Visible       = false;
                lb_Satistic.Visible     = true;
                ViewState["SalesOrder"] = Convert.ToString(IsSalesOrderExist);
                objservice.ReleaseBlanketOrder(Convert.ToString(Request.QueryString["OrderNo"]));
                objservice = null;

                var message = new JavaScriptSerializer().Serialize("Order has been successfully updated and Sales Order generated - Sales Order No. " + IsSalesOrderExist.ToString() + "");
                var script  = string.Format("alert({0});", message);
                ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", script, true);
            }
            else
            {
                objservice.ReOpenOrder(Convert.ToString(Request.QueryString["OrderNo"]));
                objservice          = null;
                lb_Update.Visible   = true;
                lb_Satistic.Visible = false;

                var message = new JavaScriptSerializer().Serialize(ex.Message.ToString());
                var script  = string.Format("alert({0});", message);
                ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", script, true);
            }
            //var message = new JavaScriptSerializer().Serialize(ex.Message.ToString());
            //var script = string.Format("alert({0});", message);
            //ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", script, true);
        }
    }