protected void GetVendorOpeningBal()
        {
            CustomProfile   profile = CustomProfile.GetProfile();
            iCustomerClient ServiceAccountMaster = new iCustomerClient();

            try
            {
                tOpeningBalance objTOpeningBal = new tOpeningBalance();
                objTOpeningBal          = ServiceAccountMaster.GetTOpeningBalanceDtls(Convert.ToInt64(HdnAccountId.Value), "Client", profile.DBConnection._constr);
                txt_OpeningBalance.Text = objTOpeningBal.OpeningBalance.ToString();
                if (objTOpeningBal.FinancialYear != null)
                {
                    ddl_FinancialYr.SelectedValue = objTOpeningBal.FinancialYear.ToString();
                }
                if (objTOpeningBal.DrCr != null)
                {
                    ddl_DrCr.SelectedValue = objTOpeningBal.DrCr.ToString();
                }
                HdnOpeningBalId.Value = objTOpeningBal.ID.ToString();
            }
            catch (Exception ex)
            {
                Login.Profile.ErrorHandling(ex, this, "Client Master", "GetVendorOpeningBal");
            }
            finally
            {
                ServiceAccountMaster.Close();
            }
        }
        public void GetClientDetailByClientID()
        {
            CustomProfile   profile = CustomProfile.GetProfile();
            iCustomerClient ServiceAccountMaster = new iCustomerClient();

            try
            {
                mClient client = new mClient();

                client = ServiceAccountMaster.GetClientDetailByClientID(Convert.ToInt64(HdnAccountId.Value), profile.DBConnection._constr);
                FillCompany();
                if (client.CompanyID != null)
                {
                    ddlcompany.SelectedIndex = ddlcompany.Items.IndexOf(ddlcompany.Items.FindByValue(client.CompanyID.ToString()));
                }
                hdnCompanyid.Value = client.CompanyID.ToString();
                getCustomer(long.Parse(client.CompanyID.ToString()));
                if (client.CustomerID != null)
                {
                    ddlcustomer.SelectedIndex = ddlcustomer.Items.IndexOf(ddlcustomer.Items.FindByValue(client.CustomerID.ToString()));
                }
                hdncustomerid.Value           = client.CustomerID.ToString();
                txt_custname.Text             = client.Name.ToString();
                txt_custcode.Text             = client.Code.ToString();
                txt_turnOver.Text             = client.TurnOver.ToString();
                TxtWebsite.Text               = client.Website.ToString();
                txt_CreditDays.Text           = client.Creditdays.ToString();
                Ddl_CompanyType.SelectedValue = null;
                if (client.CompType != null)
                {
                    Ddl_CompanyType.SelectedValue = (client.CompType).ToString();
                }
                Ddl_Sector.SelectedValue = (client.Sector).ToString();
                if (client.Active == "Y")
                {
                    rbtnYes.Checked = true;
                }
                else
                {
                    rbtnNo.Checked = true;
                }
            }
            catch (Exception ex)
            {
                Login.Profile.ErrorHandling(ex, this, "Client Master", "GetClientDetailByClientID");
            }
            finally
            {
                ServiceAccountMaster.Close();
            }
        }
        protected void pageSave(Object sender, ToolbarService.iUCToolbarClient e)
        {
            iCustomerClient ServiceAccountMaster = new iCustomerClient();

            try
            {
                CustomProfile   profile        = CustomProfile.GetProfile();
                tCustomerHead   objCutomerHead = new tCustomerHead();
                tOpeningBalance objOpeningBal  = new tOpeningBalance();
                mClient         ObjClient      = new mClient();
                int             result;
                long            Result1;
                if (checkDuplicate() == "")
                {
                    if (HdnAccountId.Value != "" && HdnAccountId.Value != "0")
                    {
                        //objCutomerHead = ServiceAccountMaster.GetCustomerHeadDetailByCustomerID(Convert.ToInt64(HdnAccountId.Value), profile.DBConnection._constr);
                        ObjClient     = ServiceAccountMaster.GetClientDetailByClientID(Convert.ToInt64(HdnAccountId.Value), profile.DBConnection._constr);
                        objOpeningBal = ServiceAccountMaster.GetTOpeningBalanceDtls(Convert.ToInt64(HdnAccountId.Value), "Client", profile.DBConnection._constr);
                        //objCutomerHead.LastModifiedBy = profile.Personal.UserID.ToString();
                        //objCutomerHead.LastModifiedDate = DateTime.Now;
                    }
                    else
                    {
                        // objCutomerHead.CreatedBy = profile.Personal.UserID.ToString();
                        // objCutomerHead.CreationDate = DateTime.Now;
                    }

                    ObjClient.Name       = txt_custname.Text;
                    ObjClient.CompanyID  = long.Parse(ddlcompany.SelectedItem.Value);
                    ObjClient.Code       = txt_custcode.Text;
                    ObjClient.Sector     = Convert.ToInt64(Ddl_Sector.SelectedItem.Value);
                    ObjClient.Creditdays = Convert.ToInt64(txt_CreditDays.Text);
                    ObjClient.TurnOver   = decimal.Parse(txt_turnOver.Text);
                    ObjClient.CompType   = Convert.ToInt64(Ddl_CompanyType.SelectedItem.Value);
                    if (rbtnYes.Checked == true)
                    {
                        ObjClient.Active = "Y";
                    }
                    if (rbtnNo.Checked == true)
                    {
                        ObjClient.Active = "N";
                    }
                    ObjClient.CustomerID  = long.Parse(hdncustomerid.Value);
                    ObjClient.Website     = TxtWebsite.Text;
                    ObjClient.AccountType = "Client";



                    /* if (Ddl_CompanyType.SelectedIndex > 0) objCutomerHead.CustomerTypeID = Convert.ToInt64(Ddl_CompanyType.SelectedItem.Value);
                     *
                     * objCutomerHead.CustomerCode = null;
                     * if (txt_custcode.Text.ToString().Trim() != "") objCutomerHead.CustomerCode = (txt_custcode.Text).ToString();
                     *
                     * if (Ddl_Sector.SelectedIndex > 0) objCutomerHead.SectorID = Convert.ToInt64(Ddl_Sector.SelectedItem.Value);
                     *
                     * objCutomerHead.Name = null;
                     * if (txt_custname.Text.ToString().Trim() != "") objCutomerHead.Name = (txt_custname.Text).ToString();
                     *
                     * objCutomerHead.WebSite = null;
                     * if (TxtWebsite.Text.ToString().Trim() != "") objCutomerHead.WebSite = (TxtWebsite.Text).ToString();
                     *
                     * objCutomerHead.TurnOver = null;
                     * if (txt_turnOver.Text.ToString().Trim() != "") objCutomerHead.TurnOver = (txt_turnOver.Text).ToString();
                     *
                     * objCutomerHead.CreditDays = null;
                     * if (txt_CreditDays.Text.ToString().Trim() != "") objCutomerHead.CreditDays = Convert.ToInt32(txt_CreditDays.Text);
                     *
                     * if (rbtnYes.Checked == true) objCutomerHead.Active = "Y";
                     * if (rbtnNo.Checked == true) objCutomerHead.Active = "N";
                     *
                     * objCutomerHead.BillingAddressID = Convert.ToInt64(UCAddress1.BillingSeq);
                     * objCutomerHead.ShippingAddressID = Convert.ToInt64(UCAddress1.ShippingSeq);
                     *
                     * objCutomerHead.ConperID = UCContactPerson1.ContactPersonIDs; */

                    objOpeningBal.FinancialYear = null;
                    if (ddl_FinancialYr.SelectedIndex > 0)
                    {
                        objOpeningBal.FinancialYear = ddl_FinancialYr.SelectedValue;
                    }

                    objOpeningBal.ObjectName = "Client";

                    objOpeningBal.OpeningBalance = null;
                    if (txt_OpeningBalance.Text.ToString().Trim() != "")
                    {
                        objOpeningBal.OpeningBalance = Convert.ToDecimal((txt_OpeningBalance.Text).ToString());
                    }

                    objOpeningBal.DrCr = null;
                    if (ddl_DrCr.SelectedIndex > 0)
                    {
                        objOpeningBal.DrCr = ddl_DrCr.SelectedValue;
                    }

                    //objOpeningBal.ID = Convert.ToInt64(HdnOpeningBalId.Value.ToString());

                    if (HdnAccountId.Value == string.Empty)
                    {
                        //objCutomerHead.CreatedBy = profile.Personal.UserID.ToString();
                        //objCutomerHead.CreationDate = DateTime.Now;
                        //objCutomerHead.CompanyID = profile.Personal.CompanyID;

                        ObjClient.CreatedBy    = profile.Personal.UserID.ToString();
                        ObjClient.CreationDate = DateTime.Now;
                        //result = ServiceAccountMaster.SaveCustomerDetails(objCutomerHead, "AddNew", profile.DBConnection._constr);
                        result = ServiceAccountMaster.SaveClientDetails(ObjClient, "AddNew", profile.DBConnection._constr);
                    }
                    else
                    {
                        //objCutomerHead.LastModifiedBy = profile.Personal.UserID.ToString();
                        //objCutomerHead.LastModifiedDate = DateTime.Now;
                        ObjClient.LastModifiedBy   = profile.Personal.UserID.ToString();
                        ObjClient.LastModifiedDate = DateTime.Now;
                        result = ServiceAccountMaster.SaveClientDetails(ObjClient, "Edit", profile.DBConnection._constr);

                        // result = ServiceAccountMaster.SaveCustomerDetails(objCutomerHead, "Edit", profile.DBConnection._constr);
                    }

                    objOpeningBal.ReferenceID = result;
                    HdnAccountId.Value        = result.ToString();
                    if (HdnOpeningBalId.Value == "0" || HdnOpeningBalId.Value == "")
                    {
                        objOpeningBal.CreatedBy   = profile.Personal.UserID.ToString();
                        objOpeningBal.CreatedDate = DateTime.Now;
                        //Result1 = ServiceAccountMaster.SaveOpeningBalance(objOpeningBal, "AddNew", profile.DBConnection._constr);
                        Result1 = ServiceAccountMaster.SaveAccountOpeningBal(objOpeningBal, profile.DBConnection._constr);
                    }
                    else
                    {
                        objOpeningBal.LastModifiedBy   = profile.Personal.UserID.ToString();
                        objOpeningBal.LastModifiedDate = DateTime.Now;
                        //Result1 = ServiceAccountMaster.SaveOpeningBalance(objOpeningBal, "Edit", profile.DBConnection._constr);
                        Result1 = ServiceAccountMaster.SaveAccountOpeningBal(objOpeningBal, profile.DBConnection._constr);
                    }
                    HdnOpeningBalId.Value = Result1.ToString();
                    UCAddress1.FinalSaveAddress(Address.ReferenceObjectName.Client, result);
                    UCContactPerson1.FinalSaveContactPerson("Client", result);
                    UC_AttachDocument1.FinalSaveDocument(result);
                    /*   UC_StatutoryDetails1.FinalSaveToStatutoryDetails(Convert.ToInt64(result), "Customer", profile.Personal.CompanyID);*/
                    if (result != 0)
                    {
                        WebMsgBox.MsgBox.Show("Record saved successfully");
                    }
                    clr();
                    MainClientGridBind();
                    // FillUserControl(result);
                    ActiveTab("Load");
                }
            }
            catch (System.Exception ex)
            {
                Login.Profile.ErrorHandling(ex, this, "Client Master", "pageSave");
            }
            finally
            {
                ServiceAccountMaster.Close();
            }
        }