protected void Page_Load(object sender, EventArgs e)
        {
            VBFunctions.ADFunctions obj = new VBFunctions.ADFunctions();
            string userID = obj.GetUserName();

            // string dirEntry = obj.GetDirectoryEntry();
            memberships = obj.VerifyGroupMemberships("LDAP://192.168.100.3/ou=Cooper Network Users,dc=coopersurgical1,dc=com", "webapps", "Yankees#1", userID);

            if (!Page.IsPostBack)

            {
                if (memberships == 1 || memberships == 2 || memberships == 3)
                {
                    BusinessUnitReportingChild li = new BusinessUnitReportingChild();

                    DataTable table = new DataTable();

                    ddlBusinessUnitName.DataSource    = li.BusinessUnitNameist().Tables[0];
                    ddlBusinessUnitName.DataTextField = "BusinessUnitName";
                    ddlBusinessUnitName.DataBind();

                    ddlCompanyName.DataSource    = li.CompanyNameList().Tables[0];
                    ddlCompanyName.DataTextField = "CompanyName";
                    ddlCompanyName.DataBind();

                    ddlBusinessUnitManagerName.DataSource    = li.BusinessUnitManagerNameList().Tables[0];
                    ddlBusinessUnitManagerName.DataTextField = "BusinessUnitManagerName";
                    ddlBusinessUnitManagerName.DataBind();

                    newCompanyName.DataSource    = li.CompanyEffectiveNameList().Tables[0];
                    newCompanyName.DataTextField = "CompanyName";
                    newCompanyName.DataBind();

                    newBusinessUnitManagerName.DataSource    = li.BusinessUnitManagerNameList().Tables[0];
                    newBusinessUnitManagerName.DataTextField = "BusinessUnitManagerName";
                    newBusinessUnitManagerName.DataBind();

                    BindGridView();
                }
                else
                {
                    string display = "You must be a member of 'Consolidated Sales Reporting – Admin' or 'Consolidated Sales Reporting – Finance' or 'Consolidated Sales Reporting – Commission' groups to View the page.";
                    ClientScript.RegisterStartupScript(this.GetType(), "yourMessage", "alert('" + display + "');", true);
                }
            }
        }
        protected void BusinessUnit_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow && BusinessUnitGridView.EditIndex == e.Row.RowIndex)
            {
                BusinessUnitReportingChild li = new BusinessUnitReportingChild();

                //Find the DropDownList in the Row
                DropDownList ddlBusinessUnitManagerNameList = (e.Row.FindControl("BusinessUnitManagerName") as DropDownList);
                ddlBusinessUnitManagerNameList.DataSource     = li.BusinessUnitManagerNameList().Tables[0];
                ddlBusinessUnitManagerNameList.DataTextField  = "BusinessUnitManagerName";
                ddlBusinessUnitManagerNameList.DataValueField = "BusinessUnitManagerName";
                ddlBusinessUnitManagerNameList.DataBind();

                //Add Default Item in the DropDownList
                ddlBusinessUnitManagerNameList.Items.Insert(0, new ListItem("Select One"));

                //Select the Country of Customer in DropDownList
                string   businessUnitManagerNames = (e.Row.FindControl("lblBusinessUnitManagerName") as Label).Text;
                ListItem item = ddlBusinessUnitManagerNameList.Items.FindByValue(businessUnitManagerNames);
                if (item != null)
                {
                    ddlBusinessUnitManagerNameList.SelectedValue = businessUnitManagerNames;
                }

                //Find the DropDownList in the Row
                DropDownList ddlCompanyNameList = (e.Row.FindControl("CompanyName") as DropDownList);
                ddlCompanyNameList.DataSource     = li.CompanyNameList().Tables[0];
                ddlCompanyNameList.DataTextField  = "CompanyName";
                ddlCompanyNameList.DataValueField = "CompanyName";
                ddlCompanyNameList.DataBind();

                //Add Default Item in the DropDownList
                ddlCompanyNameList.Items.Insert(0, new ListItem("Select One"));

                //Select the Country of Customer in DropDownList
                string companyNames = (e.Row.FindControl("lblCompanyName") as Label).Text;
                ddlCompanyNameList.Items.FindByValue(companyNames).Selected = true;
            }
        }
        protected void btnSaveNewBusinessUnit_Click(object sender, EventArgs e)
        {
            bool   isFormFilled            = true;
            string display                 = "";
            BusinessUnitReportingChild li  = new BusinessUnitReportingChild();
            string businessUnitCode        = newBusinessUnitCode.Text;
            string businessUnitName        = newBusinessUnitName.Text;
            string businessUnitManagerName = newBusinessUnitManagerName.SelectedValue.ToString();
            string companyName             = newCompanyName.SelectedValue.ToString();
            string effectiveDate           = Request.Form[newEffectiveDate.UniqueID];


            if (String.IsNullOrEmpty(effectiveDate) || String.IsNullOrEmpty(businessUnitCode) ||
                String.IsNullOrEmpty(businessUnitName) || String.IsNullOrEmpty(businessUnitManagerName) || companyName.Equals("Select One"))
            {
                display = "Please select all the mandatory fields ";
                ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('" + display + "');", true);
                isFormFilled = false;
            }


            if (isFormFilled)
            {
                if (memberships == 1 || memberships == 2)
                {
                    DataSet result = li.AddNewBusinessUnit(businessUnitCode, businessUnitName, businessUnitManagerName, companyName, effectiveDate);

                    string res = Convert.ToString(result.Tables[0].Rows[0].ItemArray[0]);
                    if (res.Contains("Effective Date should be after"))
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('" + res + "');", true);
                        isFormFilled = false;
                        ModalPopupExtender1.Show();
                    }
                    else if (res.Equals("Duplicate BusinessUnitCode"))
                    {
                        display = "Business Unit Code already exists in the database";
                        ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('" + display + "');", true);
                        isFormFilled = false;
                    }
                    else if (res.Equals("Duplicate BusinessUnitName"))
                    {
                        display = "Business Unit Name already exists in the database";
                        ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('" + display + "');", true);
                        isFormFilled = false;
                    }
                    else if (res.Equals("Success"))
                    {
                        display = "A new Business Unit is successfully added in the database";
                        ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('" + display + "');", true);
                        isFormFilled = true;
                    }
                    if (isFormFilled)
                    {
                        newBusinessUnitCode.Text = "";
                        newBusinessUnitName.Text = "";
                        ddlBusinessUnitManagerName.DataSource    = li.BusinessUnitManagerNameList().Tables[0];
                        ddlBusinessUnitManagerName.DataTextField = "BusinessUnitManagerName";
                        ddlBusinessUnitManagerName.DataBind();

                        ddlCompanyName.DataSource    = li.CompanyNameList().Tables[0];
                        ddlCompanyName.DataTextField = "CompanyName";
                        ddlCompanyName.DataBind();
                        BindGridView();
                    }
                }

                else
                {
                    display = "You must be a member of Consolidated Sales Reporting – Admin or Consolidated Sales Reporting – Finance  groups to Add New Business Units.";
                    ClientScript.RegisterStartupScript(this.GetType(), "yourMessage", "alert('" + display + "');", true);
                }
            }
        }