private void BindDetails()
    {
        BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();
        Entity.CompanyInfo oCompanyInfo = new Entity.CompanyInfo();
        if (Request.QueryString["qid"] != null)
        {
            oCompanyInfo = oCompanyManager.GetQuestionsForHealthCoachFromUserByQuestionId(Convert.ToInt32(Request.QueryString["qid"]));
            if (oCompanyInfo != null)
            {
                lblCategory.Text = oCompanyInfo.StrCategoryName + " - " + oCompanyInfo.StrCategoryLevel;
                lblQuestion.Text = oCompanyInfo.StrQuestion;
                lblSubject.Text = oCompanyInfo.StrSubject;
                lblComments.Text = oCompanyInfo.StrComments;

                lblQuestionType.Text= oCompanyInfo.StrQuestionType;

                GVAnswer.DataSource = oCompanyManager.GetAnswerofPrivateQuestionByQuestionId(Convert.ToInt32(Request.QueryString["qid"]));
                GVAnswer.DataBind();
                if (GVAnswer.Rows.Count > 0)
                    trAnswer.Visible = true;
                else
                    trAnswer.Visible = false;
                //
            }
        }

        oCompanyInfo = null;
        oCompanyManager = null;
    }
 /// Function Header*******************************************************
 /// Function Name: GVUsers_RowCommand
 /// Function Type: Event
 /// Functionality: Fired on when the user click on the linkbtns of grid
 /// wizard
 /// Input: 
 /// Output: 
 /// Return Value:
 /// Note: 
 protected void GVUsers_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName.ToLower().Equals("statuschanged"))
     {
         oCompanyManager = new BLL.CompanyManager();
         oCompanyManager.UpdateCompanyActiveStatus(Convert.ToInt32(e.CommandArgument), DateTime.Now);
         lblMsg.Text = "Status has been updated successfully.";
         BindCompanies('Y');
     }
 }
    /// Function Header*******************************************************
    /// Function Name: BindEvents
    /// Function Type: Function
    /// Functionality: used to get bind the events
    /// Input: 
    /// Output: 
    /// Return Value:
    /// Note: 
    /// *********************************************************************
    private void BindQuestions()
    {
        Entity.CompanyInfo oCompanyInfo = new Entity.CompanyInfo();
        oCompanyInfo.StrCategoryName = "x";
        oCompanyInfo.ChrIsAnsweredGiven = 'x';
        oCompanyInfo.StrQuestionType = "x";
        BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();
        GVQuestion.DataSource = oCompanyManager.GetQuestionsForHealthCoachFromUser(oCompanyInfo);

        GVQuestion.DataBind();
        oCompanyManager = null;
        oCompanyInfo = null;
    }
    /*Sub Header***********************************************************
    Function Name: BindAllUsers
    Functionality: This function is used to bind the dropdown from the users
    Input: dropdownlist and the strInitialText
    Output:
    Note:
    *********************************************************************/
    public static void BindAllUsers(DropDownList ddList, string strInitialText)
    {
        BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();
        ddList.DataSource = oCompanyManager.GetAllUsers();
        ddList.DataTextField = "StrEmpEmail";
        ddList.DataValueField = "StrEmpEmail";
        ddList.DataBind();

        ListItem lstInitialItem;
        if (strInitialText.Trim() != "")
        {
            lstInitialItem = new ListItem(strInitialText, "0");
            ddList.Items.Insert(0, lstInitialItem);
        }
        lstInitialItem = null;

        oCompanyManager = null;
    }
 protected void ddlCompany_SelectedIndexChanged(object sender, EventArgs e)
 {
     trCompany.Visible = true;
     if (!ddlCompany.SelectedValue.Equals("0"))
     {
         if (Convert.ToInt32(ddlToEmails.SelectedValue).Equals(4))
         {
             trUsers.Visible = true;
             BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();
             ddlUsers.DataSource = oCompanyManager.GetUsersByCompanyId(Convert.ToInt32(ddlCompany.SelectedValue));
             ddlUsers.DataTextField = "StrEmpEmail";
             ddlUsers.DataValueField = "StrEmpEmail";
             ddlUsers.DataBind();
             if (ddlUsers.Items.Count.Equals(0))
                 ddlUsers.Items.Add(new ListItem("No User Exist", "0"));
         }
         else
             trUsers.Visible = false;
     }
     else
         trUsers.Visible = false;
 }
    /// Function Header*******************************************************
    /// Function Name: BindDetails
    /// Function Type: Function
    /// Functionality: Function used to bind the details of question
    /// Input: 
    /// Output: 
    /// Return Value:
    /// Note: 
    /// ********************************************************************
    private void BindDetails()
    {
        BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();
        Entity.CompanyInfo oCompanyInfo = new Entity.CompanyInfo();
        if (Request.QueryString["qid"] != null)
        {
            oCompanyInfo = oCompanyManager.GetQuestionsForHealthCoachFromUserByQuestionId(Convert.ToInt32(Request.QueryString["qid"]));
            if (oCompanyInfo != null)
            {
                lblCategory.Text = oCompanyInfo.StrCategoryName + " - " + oCompanyInfo.StrCategoryLevel;
                lblQuestion.Text = oCompanyInfo.StrQuestion;
                lblSubject.Text = oCompanyInfo.StrSubject;
                lblComments.Text = oCompanyInfo.StrComments;
                lblUserId.Text = oCompanyInfo.StrUserName;

                rdoQuestionType.SelectedValue = oCompanyInfo.StrQuestionType;
                lblUserEmail.Text = oCompanyInfo.StrUserName;
                lblUserEmail.Text = oCompanyManager.GetUserDetailsByUsername(lblUserEmail.Text).StrUserFullName + "(" + oCompanyInfo.StrUserName + ")";
                GVAnswer.DataSource = oCompanyManager.GetAnswerofPrivateQuestionByQuestionId(Convert.ToInt32(Request.QueryString["qid"]));
                GVAnswer.DataBind();

                List<Entity.CompanyInfo> Info = oCompanyManager.GetAnswerofPrivateQuestionByQuestionId(Convert.ToInt32(Request.QueryString["qid"]));
                if (Info.Count > 0)
                {
                    txtAnswer.Text = oCompanyManager.GetAnswerofPrivateQuestionByQuestionId(Convert.ToInt32(Request.QueryString["qid"])).ElementAt(0).StrAnswer;

                }

                if (GVAnswer.Rows.Count > 0)
                    trAnswer.Visible = true;
                else
                    trAnswer.Visible = false;
                //
            }
        }

        oCompanyInfo = null;
        oCompanyManager = null;
    }
    protected void lnkBtnDisapprove_Click(object sender, EventArgs e)
    {
        List<Entity.CompanyInfo> _objListCompanyInfo = new List<Entity.CompanyInfo>();
        foreach (GridViewRow gvRows in GVCompany.Rows)
        {
            CheckBox chkSelect = (CheckBox)gvRows.FindControl("chkSelect");
            if (chkSelect.Checked)
            {
                lblMsg.Text = string.Empty;
                Label lblCompanyId = (Label)gvRows.FindControl("lblCompanyId");
                if (lblCompanyId != null)
                {
                    oCompanyInfo = new Entity.CompanyInfo();
                    oCompanyInfo.IntCompanyId = Convert.ToInt32(lblCompanyId.Text);
                    oCompanyInfo.ChrIsApproved = 'N';
                    _objListCompanyInfo.Add(oCompanyInfo);
                    oCompanyInfo = null;
                }
            }

        }

        if (_objListCompanyInfo.Count > 0)
        {
            oCompanyManager = new BLL.CompanyManager();
            oCompanyManager.UpdateCompanyApprovedStatus(_objListCompanyInfo);
            oCompanyManager = null;

            lblMsg.Text = "Company(ies) has been disapproved successfully.";
            BindCompanies('Y');
        }
        else
        {
            lblMsg.Text = "Please select atleast one company for disapprove.";
        }
        //BindCompanies('Y');
    }
    /************************************************************
    Function Name: BindCompanies
    Functionality: This function is used to bind the company grid
    *********************************************************************/
    private void BindCompanies(char isSearch)
    {
        oCompanyManager = new BLL.CompanyManager();
        oCompanyInfo = new Entity.CompanyInfo();
        oCompanyInfo.StrCompanyEmail = txtEmail.Text.Trim();
        oCompanyInfo.StrCompanyName = txtCompanyName.Text.Trim();
        oCompanyInfo.ChrIsActive = 'X';
        if (!ddlStatus.SelectedValue.Equals("0"))
            oCompanyInfo.ChrIsActive = Convert.ToChar(ddlStatus.SelectedValue);

        GVCompany.DataSource = oCompanyManager.SearchCompanies(oCompanyInfo);
        GVCompany.DataBind();
        if (isSearch.Equals('Y'))
            lblResultMsg.Text = GVCompany.Rows.Count.ToString() + " Record(s) found.";

        if (GVCompany.Rows.Count > 0)
            lnkBtnDisapprove.Visible = true;
        else
            lnkBtnDisapprove.Visible = false;
    }
    protected void lnkBtnSendRequest_Click(object sender, EventArgs e)
    {
        string strEmailContentForCompany = string.Empty;
        strEmailContentForCompany = "<table>";
        string strContent = string.Empty;
        BLL.TemplateLib oTemplateLib = new BLL.TemplateLib();

        strContent = oTemplateLib.GetTemplateDetailsByTemplateTemplateName("RegistrationRequestForUserEmail").TextAreaHTML;

        List<Entity.CompanyInfo> _objListCompanyInfo = new List<Entity.CompanyInfo>();
        foreach (GridViewRow gvRows in GVUsers.Rows)
        {
            CheckBox chkSelect = (CheckBox)gvRows.FindControl("chkSelect");
            if (chkSelect.Checked)
            {
                lblMsg.Text = string.Empty;
                Label lblCompanyRequestedUsersListId = (Label)gvRows.FindControl("lblCompanyRequestedUsersListId");
                Label lblEmail = (Label)gvRows.FindControl("lblEmail");
                Label lblName = (Label)gvRows.FindControl("lblName");

                if (lblCompanyRequestedUsersListId != null)
                {
                    string strRegistrationLink = AppConfig.GetBaseSiteUrl() + "UserRegistration.aspx?iid=" + lblCompanyRequestedUsersListId.Text;
                    strEmailContentForCompany = strEmailContentForCompany + "<tr><td>" + lblName.Text + "(" + lblEmail.Text + ")</td></tr>";

                    strContent = strContent.Replace("[FullName]", lblName.Text);
                    strContent = strContent.Replace("[SiteUrl]", AppConfig.GetBaseSiteUrl());
                    strContent = strContent.Replace("[RegistrationLink]", strRegistrationLink);
                    strContent = strContent.Replace("[SiteName]", AppConfig.GetSiteName());

                    //AppLib.SendMailToUser(lblEmail.Text, "Registration Request By TLW", strContent, AppConfig.GetAdminEmail());

                       string fname = "~/Upload/" + lblName.Text + ".html";
                       StreamWriter _testData = new StreamWriter(Server.MapPath(fname));
                        _testData.WriteLine(strContent); // Write the file.
                        _testData.Flush();
                        _testData.Close(); // Close the instance of StreamWriter.
                        _testData.Dispose(); // Dispose from memory.

                    oCompanyInfo = new Entity.CompanyInfo();
                    oCompanyInfo.IntCompanyRequestedUsersListId = Convert.ToInt32(lblCompanyRequestedUsersListId.Text);
                    oCompanyInfo.ChrStatus = 'S';
                    oCompanyInfo.DtModifiedDate = DateTime.Now;
                    _objListCompanyInfo.Add(oCompanyInfo);
                    oCompanyInfo = null;
                }
            }
        }

        if (_objListCompanyInfo.Count > 0)
        {
            strEmailContentForCompany = strEmailContentForCompany + "</table>";
            strContent = oTemplateLib.GetTemplateDetailsByTemplateTemplateName("EmailToCompanyForRegistrationofUser").TextAreaHTML;
            strContent = strContent.Replace("[CompanyName]", ddlCompany.SelectedItem.Text);
            strContent = strContent.Replace("[Name]", strEmailContentForCompany);

            oCompanyInfo = new Entity.CompanyInfo();
            oCompanyManager = new BLL.CompanyManager();
            oCompanyInfo = oCompanyManager.GetCompanyDetailsById(Convert.ToInt32(ddlCompany.SelectedValue));
            if (oCompanyInfo != null)
            {
                AppLib.SendMailToUser(oCompanyInfo.StrCompanyEmail, "Registration Request Status of User", strContent, AppConfig.GetAdminEmail());
            }

            oCompanyManager.UpdateRequestUserStatus(_objListCompanyInfo);
            oCompanyManager = null;
            oCompanyInfo = null;

            lblMsg.Text = "Registration Request has been sent successfully.";
            BindCompanies('Y');
        }
        else
        {
            lblMsg.Text = "Please select atleast one record.";
        }
        //BindCompanies('Y');

        oTemplateLib = null;
    }
    /// Function Header*******************************************************
    /// Function Name: SaveDetails
    /// Function Type: Function
    /// Functionality: Function used to save the details of questions with answer provided by admin
    /// Input: 
    /// Output: 
    /// Return Value:
    /// Note: 
    /// ********************************************************************
    private void SaveDetails()
    {
        string strContent = string.Empty;

        BLL.TemplateLib oTemplateLib = new BLL.TemplateLib();

        Entity.CompanyInfo oCompanyInfo = new Entity.CompanyInfo();
        oCompanyInfo.StrUserName = AppLib.GetLoggedInUserName();
        oCompanyInfo.IntQuestionId = Convert.ToInt32(Request.QueryString["qid"]);
        oCompanyInfo.StrAnswer = txtAnswer.Text.Trim();
        oCompanyInfo.DtAnsweredOn = DateTime.Now;
        oCompanyInfo.StrQuestionType = rdoQuestionType.SelectedValue;
        oCompanyInfo.StrAnsweredBy = AppLib.GetLoggedInUserName();
        oCompanyInfo.StrQuestion = lblQuestion.Text;
        oCompanyInfo.StrUserId = lblUserId.Text;
        BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();
        oCompanyManager.SaveAnswerFromHealthCoach(oCompanyInfo);

        strContent = oTemplateLib.GetTemplateDetailsByTemplateTemplateName("HealthCoachSubmitQuestionEmail").TextAreaHTML;

        try
        {

           // strContent = strContent.Replace("[Name]", oCompanyManager.GetUserDetailsByUsername(lblUserEmail.Text).StrUserFullName);
            strContent = strContent.Replace("[Name]", oCompanyManager.GetUserDetailsByUsername(oCompanyInfo.StrUserId).StrUserFullName);

            strContent = strContent.Replace("[Category]", lblCategory.Text);
            strContent = strContent.Replace("[Question]", lblQuestion.Text);
            strContent = strContent.Replace("[Subject]", lblSubject.Text);
            strContent = strContent.Replace("[Comments]", lblComments.Text);
            strContent = strContent.Replace("[QuestionType]", rdoQuestionType.SelectedValue);
            strContent = strContent.Replace("[Answer]", txtAnswer.Text);
            strContent = strContent.Replace("[SiteUrl]", AppConfig.GetBaseSiteUrl());
            strContent = strContent.Replace("[SiteName]", AppConfig.GetSiteName());
            strContent = strContent.Replace("[SitePhone]", AppConfig.GetSITEPHONE());
           // AppLib.SendMailToUser(lblUserEmail.Text, lblSubject.Text, strContent, AppConfig.GetAdminEmail());
           AppLib.SendMailToUser(oCompanyInfo.StrUserId, lblSubject.Text, strContent, AppConfig.GetAdminEmail());
            //AppLib.SendMailToUser(oCompanyInfo.StrUserId, lblSubject.Text, strContent, "*****@*****.**");

            //AppLib.SendMailToUser(AppConfig.GetAdminEmail(), lblSubject.Text, "Dear Admin, Following are the contents that were sent to the user. <br />" + strContent, lblUserEmail.Text);
        }
        catch { }
        finally
        {
            oTemplateLib = null;
            oCompanyManager = null;
            oCompanyInfo = null;
        }

        Response.Redirect(AppConfig.GetBaseSiteUrl() + "BackOffice/UserUtilities/ManageQuestionforHealthCoach.aspx?msg=up", true);
    }
    /************************************************************
    Function Name: BindCompanies
    Functionality: This function is used to bind the company grid
    *********************************************************************/
    private void BindCompanies(char isSearch)
    {
        oCompanyManager = new BLL.CompanyManager();

        GVUsers.DataSource = oCompanyManager.SearchRequestedUsersForCompanies(Convert.ToInt32(ddlCompany.SelectedValue), 'I');
        GVUsers.DataBind();
        if (isSearch.Equals('Y'))
            lblResultMsg.Text = GVUsers.Rows.Count.ToString() + " Record(s) found.";

        if (GVUsers.Rows.Count > 0)
            lnkBtnSendRequest.Visible = true;
        else
            lnkBtnSendRequest.Visible = false;

        oCompanyManager = null;
    }
    private void BindCompanyDetails()
    {
        try
        {
            BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();
            Entity.CompanyInfo oCompanyInfo = new Entity.CompanyInfo();
            int intCompanyId = Convert.ToInt32(Request.QueryString["cid"].ToString());
            int intCompanyRequestedUserId = Convert.ToInt32(Request.QueryString["id"].ToString());

            oCompanyInfo = oCompanyManager.GetCompanyDetailsByCompanyandRequestedUserId(intCompanyId, intCompanyRequestedUserId);
            if (oCompanyInfo != null)
            {
                TextBox txtOrganization = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtOrganization");
                if (txtOrganization != null)
                {
                    txtOrganization.Text = oCompanyInfo.StrCompanyName;
                    TextBox txtEmail = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Email");

                    TextBox txtUserName = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");
                    if (txtEmail != null && txtUserName != null)
                    {
                        txtEmail.Text = oCompanyInfo.StrEmpEmail;
                        txtUserName.Text = oCompanyInfo.StrEmpEmail;
                        txtEmail.Enabled = false;
                        txtUserName.Enabled = false;
                    }}
            }

            oCompanyInfo = null;
            oCompanyManager = null;
        }
        catch (Exception ex) { string strTemp = ex.Message; }
    }
    protected void btnSaveRecord_Click(object sender, EventArgs e)
    {
        List<Entity.CompanyInfo> oListCompanyInfo = new List<Entity.CompanyInfo>();
        Entity.CompanyInfo oCompanyInfo;

        string[] strEmailArray = new string[gvRequestedUser.Rows.Count];
        int i = 0;
        foreach (GridViewRow gvr in gvRequestedUser.Rows)
        {
            Label lblEmpEmail = (Label)gvr.FindControl("lblEmpEmail");
            if (lblEmpEmail != null && lblEmpEmail.Text != string.Empty)
            {
                strEmailArray[i] = lblEmpEmail.Text;
                i = i + 1;
            }
        }

        oCompanyManager = new BLL.CompanyManager();
        if (!oCompanyManager.IsEmailIdExists(strEmailArray))
        {
            oCompanyManager = null;
            lblMsg.Text = "<br /><br/>Please check the email addresses.  Multiple entries are not allowed.";
            ReadXML();
            return;
        }

        oCompanyManager = null;
        try
        {
            foreach (GridViewRow gvr in gvRequestedUser.Rows)
            {
                Label lblEmpfName = (Label)gvr.FindControl("lblEmpfName");
                Label lblEmpLName = (Label)gvr.FindControl("lblEmpLName");
                Label lblEmpEmail = (Label)gvr.FindControl("lblEmpEmail");

                oCompanyInfo = new Entity.CompanyInfo();
                oCompanyInfo.IntCompanyId = AppLib.GetLoggedInUserId();
                oCompanyInfo.StrEmployeeAddress = "";

                oCompanyInfo.StrEmpCode = "";
                oCompanyInfo.StrEmpFirstName = lblEmpfName.Text.Trim();
                oCompanyInfo.StrEmpLastName = lblEmpLName.Text.Trim();
                oCompanyInfo.StrEmpMiddleName = "";
                oCompanyInfo.StrEmpEmail = lblEmpEmail.Text.Trim();
                oCompanyInfo.ChrStatus = 'I';
                oCompanyInfo.DtCreatedDate = DateTime.Now;

                oListCompanyInfo.Add(oCompanyInfo);
                oCompanyInfo = null;
            }
        }
        catch { }

        try
        {
            if (oListCompanyInfo.Count > 0)
            {
                oCompanyManager = new BLL.CompanyManager();
                oCompanyManager.SaveRequestCompanyForUserRegistration(oListCompanyInfo);
                oCompanyManager = null;
                SendUserRegistrationEmailtoAdmin();
                lblMsg.Text = "<br /><br />Thank you.  Check back for status of your employees.<br /><br /><br />";
            }
        }
        catch(Exception ex) {

            lblMsg.Text = "<br /><br />There was an error with your request.  Please contact TLW directly.<br /><br /><br />";
        }
        oCompanyInfo = null;

        oListCompanyInfo = null;
    }
    protected void OnLoggedIn(object sender, EventArgs e)
    {
        TextBox UserName = (TextBox)Login1.FindControl("UserName");
        TextBox Password = (TextBox)Login1.FindControl("Password");

        try
        {
            HttpContext.Current.Session["strUserName"] = UserName.Text.ToString().Trim();
            sendOutConfirmationEmail(UserName.Text.ToString().Trim());

            BLL.UserLib oUserLib = new BLL.UserLib();

            Session["strUserType"] = oUserLib.GetRoleNameByUserName(UserName.Text.ToString().Trim());

            Session["ChrUserType"] = oUserLib.GetUserTypeByUser(UserName.Text.ToString().Trim());

            #region Insert visited log details

            AppLib.InsertVisitedSectionDetails("Logged In");

            #endregion

            oUserLib = null;

            BLL.CompanyManager oCompanyManager;
            Entity.CompanyInfo oCompanyInfo;

            oCompanyManager = new BLL.CompanyManager();
            oCompanyInfo = new Entity.CompanyInfo();

            oCompanyInfo = oCompanyManager.GetCompanyDetailsByEmailId(AppLib.GetLoggedInUserName());
            if (oCompanyInfo != null)
                Session["intLoggedUserId"] = oCompanyInfo.IntCompanyId.ToString();

            oCompanyInfo = null;
            oCompanyManager = null;

            CheckBox cbRememberMe = (CheckBox)Login1.FindControl("cbRememberMe");

            if (cbRememberMe.Checked)
            {
                Response.Cookies.Remove("RememberMe");
                HttpCookie myCookie = new HttpCookie("RememberMe");

                myCookie.Values.Add("Email", UserName.Text.ToString().Trim());

                myCookie.Expires = DateTime.Now.AddDays(200); //you can add years and months too here
                Response.Cookies.Add(myCookie);
            }
            else
            {
                HttpCookie cookie = Request.Cookies["RememberMe"];
                if (cookie != null)
                {
                    cookie.Expires = DateTime.Now.AddDays(-1);
                    Response.Cookies.Add(cookie);
                }
            }
        }
        catch (Exception ex)
        {
        }

        //string sUsername = AppLib.GetLoggedInUserName();
        string sUsername = Membership.GetUser(UserName.Text.Trim()).UserName;

        try
        {
            if (objBackofficeClass.Mem_GET_UserInfo(sUsername).Tables[0].Rows[0]["REGISTRATION_FLG"].ToString() == "0")
            {//they have not gone through their personal registration yet

                FormsAuthentication.SignOut();// LOG USER OUT PROGRAMMATICALLY
                //Response.Redirect("/Main/UserUtilities/EditUser.aspx?username="******"Main/UserUtilities/EditUser.aspx?username="******"Password"))
            {
                //Response.Redirect("/Anonymous/ResetPassword/ResetPassword.aspx");/*Commented by Netsmartz*/

                Response.Redirect(AppConfig.GetBaseSiteUrl() + "Anonymous/ResetPassword/ResetPassword.aspx");
            }
            else if (Roles.IsUserInRole(sUsername, "Company"))
            {
                //Response.Redirect("/Anonymous/ResetPassword/ResetPassword.aspx");/*Commented by Netsmartz*/

                Response.Redirect(AppConfig.GetBaseSiteUrl() + "Company/UploadUsersForRegistration.aspx");
            }
        }
        catch (Exception ex)
        {
        }

        /*---------------------VISITLOG---------------------*/
         //   UC_Visitlog_Visitlog1.addEntry(1, 0, 0, 0, "", "", "");

        Response.Redirect(AppConfig.GetBaseSiteUrl() + "login/login_success.aspx");
    }
    private void BindCompanyDetails()
    {
        oCompanyInfo = new Entity.CompanyInfo();
        oCompanyManager = new BLL.CompanyManager();
        oCompanyInfo = oCompanyManager.GetCompanyDetailsById(Convert.ToInt32(Request.QueryString["id"]));
        if (oCompanyInfo != null)
        {
            rblStatus.SelectedValue = oCompanyInfo.ChrIsActive.ToString();
            txtAddress.Text = oCompanyInfo.StrCompanyAddress.Trim();
            txtCity.Text = oCompanyInfo.StrCity.Trim();
            lblEmailId.Text = oCompanyInfo.StrCompanyEmail.Trim();
            txtCompanyName.Text = oCompanyInfo.StrCompanyName.Trim();
            txtFax.Text = oCompanyInfo.StrCompanyFax.Trim();
            txtPhone.Text = oCompanyInfo.StrCompanyPhone.Trim();

            ddlCountry.SelectedIndex = ddlCountry.Items.IndexOf(ddlCountry.Items.FindByValue(oCompanyInfo.IntCountryId.ToString()));
            ddlState.SelectedIndex = ddlState.Items.IndexOf(ddlState.Items.FindByValue(oCompanyInfo.IntStateId.ToString()));
            txtStateText.Text = oCompanyInfo.StrStateName;
            fillState();
            // ddlState.SelectedIndex = ddlState.Items.IndexOf(ddlState.Items.FindByValue(oCompanyInfo.IntStateId.ToString()));
            rblApproved.SelectedValue = oCompanyInfo.ChrIsApproved.ToString();
        }

        oCompanyInfo = null;
        oCompanyManager = null;
    }
    private void SendUserRegistrationEmailtoAdmin()
    {
        try
        {
            Entity.CompanyInfo oCompanyInfo = new Entity.CompanyInfo();
            oCompanyManager = new BLL.CompanyManager();
            oCompanyInfo = oCompanyManager.GetCompanyDetailsById(intLoggedUserId);
            if (oCompanyInfo != null)
            {
                string strContent = string.Empty;
                BLL.TemplateLib oTemplateLib = new BLL.TemplateLib();
                strContent = oTemplateLib.GetTemplateDetailsByTemplateTemplateName("UserRegistrationRequestByCompany").TextAreaHTML;
                strContent = strContent.Replace("[CompanyName]", oCompanyInfo.StrCompanyName.Trim());
                strContent = strContent.Replace("[SiteUrl]", AppConfig.GetBaseSiteUrl());
                strContent = strContent.Replace("[SiteName]", AppConfig.GetSiteName());

                AppLib.SendMailToUser(AppConfig.GetAdminEmail(), "User Registration Request from Company", strContent, AppConfig.GetAdminEmail());
                oTemplateLib = null;
            }

            oCompanyInfo = null;

            oCompanyManager = null;
        }
        catch { }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        fillNames();
        if (!AppLib.IsLoggedinSessionExists())
            Response.Redirect(AppConfig.GetBaseSiteUrl() + "Welcome/Main_Frame.aspx", true);
        MembershipUser currentUser = Membership.GetUser();
        Roles.GetRolesForUser(HttpContext.Current.User.Identity.Name);
        //string strScript = "<script type='text/javascript'>function load(sUrl) { document.getElementById(iframeName).src = '" + AppConfig.GetBaseSiteUrl() + "' + sUrl; } </script>";
        //this.Page.RegisterClientScriptBlock("abc", strScript);
        objBackofficeClass = new BackofficeClass(objSqlConnClass.OpenConnection());
        objForumClass = new ForumClass(objSqlConnClass.sqlConnection);

        BackofficeClass objBackOfficeClass;
        objBackOfficeClass = new BackofficeClass(objSqlConnClass.OpenConnection());
        DataSet DS = objBackOfficeClass.Mem_GET_Admin(currentUser.UserName);
        if (DS != null)
        {
            if (DS.Tables[0].Rows.Count > 0)
            {
                if (DS.Tables[0].Rows[0]["ROLENAME"].ToString().Equals("Administrator"))
                {
                    if (Session["popup"] != null)
                    {
                        bool pop = (bool)Session["popup"];

                        if (pop)
                        {
                            BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();
                            int no = oCompanyManager.GetQuestion();
                            // string Script = "jConfirm('You have " + no + " unanswered HealthCoach Message !  Click Ok to answer them', 'HealthCoach Message',function(r) {alert(r);});";

                            if (no != 0)
                            {

                                string Script = "jConfirm('You have " + no + " unanswered HealthCoach Message !  Click Ok to see them', 'HealthCoach Message',function(r) { if(r) {window.location.href = '../Backoffice/UserUtilities/ManageQuestionforHealthCoach.aspx';}});";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseWindow", Script, true);
                                Session["popup"] = false;
                                Response.Redirect("../Backoffice/UserUtilities/ManageQuestionforHealthCoach.aspx");
                            }
                        }
                        else
                        {
                            Session.Remove(Session["popup"].ToString());
                        }
                    }
                    else
                    {

                    }
                }

                else
                {
                    if (Session["popup"] != null)
                    {
                        bool pop = (bool)Session["popup"];

                        if (pop)
                        {
                            BLL.CompanyManager oCompanyManagers = new BLL.CompanyManager();
                            int no = oCompanyManagers.GetAnswers(currentUser.UserName);
                            if (no != 0)
                            {
                                string Script = "jConfirm('You have " + no + " answered HealthCoach Message !  Click Ok to see them', 'HealthCoach Message',function(r) { if(r) {window.location.href = '../Users/MyAskedQuestions.aspx';}});";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseWindow", Script, true);
                                Session["popup"] = false;
                            }
                        }
                        else
                        {
                            Session.Remove(Session["popup"].ToString());
                        }
                    }
                    else
                    {

                    }
                }
            }
        }

        //if (Request.QueryString["register"] != null)
        //{
        //    IFRAME_CONTENT.Attributes.Remove("src");
        //    IFRAME_CONTENT.Attributes.Add("src", "UserUtilities/CreateUser.aspx");
        //}

        //if (!IsPostBack)
        {
            fillOutForm();
        }

        //if (HttpContext.Current.User.IsInRole("Administrator"))
        //{

        //    if (Session["popup"] != null)
        //    {
        //        bool pop = (bool)Session["popup"];

        //        if (pop)
        //        {
        //            BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();
        //            int no = oCompanyManager.GetQuestion();
        //            string Script = "jConfirm('You have " + no + " unanswered HealthCoach Message !  Click Ok to answer them', 'HealthCoach Message',function(r) { if(r) {window.location.href = '../Backoffice/UserUtilities/ManageQuestionforHealthCoach.aspx';}});";
        //            ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseWindow", Script, true);
        //            Session["popup"] = false;
        //        }
        //        else
        //        {
        //            Session.Remove(Session["popup"].ToString());
        //        }
        //    }
        //    else
        //    {

        //    }
        //}
        //else
        //{

        //}
    }
    private void BindCompanyDetails()
    {
        BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();
        Entity.CompanyInfo oCompanyInfo = new Entity.CompanyInfo();

        try
        {
            int intCompanyId = Convert.ToInt32(AppLib.Decrypt(Request.QueryString["cid"].ToString()));
            DropDownList ddlCompany = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ddlCompany");
            ddlCompany.SelectedIndex = ddlCompany.Items.IndexOf(ddlCompany.Items.FindByValue(intCompanyId.ToString()));
            ddlCompany.Enabled = false;
            /*
          int intCompanyRequestedUserId = Convert.ToInt32(AppLib.Decrypt(Request.QueryString["id"].ToString()));
          oCompanyInfo = oCompanyManager.GetCompanyDetailsByCompanyandRequestedUserId(intCompanyId, intCompanyRequestedUserId);
          if (oCompanyInfo != null)
          {
              //TextBox txtOrganization = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtOrganization");
              DropDownList ddlCompany = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ddlCompany");
              ddlCompany.SelectedIndex = ddlCompany.Items.IndexOf(ddlCompany.Items.FindByValue(intCompanyId.ToString()));
              /*

              if (txtOrganization != null)
                  txtOrganization.Text = oCompanyInfo.StrCompanyName;
          }*/
        }
        catch (Exception ex) { string strTemp = ex.Message; }
        finally
        {
            oCompanyInfo = null;
            oCompanyManager = null;
        }
    }
    /*Sub Header***********************************************************
    Function Name: BindCompanyStatusDropdown
    Functionality: This function is used to bind the company statuses with the predefined array

    Input: dropdownlist and the strInitialText
    Output:
    Note:
    *********************************************************************/
    public static void BindCompanyCheckBoxList(CheckBoxList ddList, string strInitialText)
    {
        BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();

        ddList.DataSource = oCompanyManager.GetCompanyAllCompanies();
        ddList.DataTextField = "strCompanyName";
        ddList.DataValueField = "intCompanyId";
        ddList.DataBind();

        ListItem lstInitialItem;
        if (strInitialText.Trim() != "")
        {
            lstInitialItem = new ListItem(strInitialText, "0");
            ddList.Items.Insert(0, lstInitialItem);
        }
        lstInitialItem = null;
        oCompanyManager = null;
    }
    private void SendContactUsEmail()
    {
        string strContent = string.Empty;

        BLL.TemplateLib oTemplateLib = new BLL.TemplateLib();

        strContent = oTemplateLib.GetTemplateDetailsByTemplateTemplateName("HealthCoachSubmitQuestionEmail").TextAreaHTML;

        Entity.CompanyInfo oCompanyInfo = new Entity.CompanyInfo();
        oCompanyInfo.StrCategoryLevel = ddlLevel.SelectedItem.Text;
        oCompanyInfo.StrUserName = AppLib.GetLoggedInUserName();
        oCompanyInfo.StrCategoryName = ddlCategory.SelectedItem.Text;
        oCompanyInfo.StrQuestion = txtQuestion.Text.Trim();
        oCompanyInfo.StrSubject = txtsubject.Text.Trim();
        oCompanyInfo.StrComments = txtComments.Text.Trim();
        oCompanyInfo.StrQuestionType = rdoQuestionType.SelectedItem.Text;
        oCompanyInfo.StrAnswer = string.Empty;
        oCompanyInfo.DtCreatedOn = DateTime.Now;
        oCompanyInfo.ChrIsAnsweredGiven = 'N';
        oCompanyInfo.ChrIsDeleted = 'N';

        BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();
        oCompanyManager.SaveQuestionToHealthCoachFromUser(oCompanyInfo);

        lblMsg.Text = "Your question has been successfully sent to health coach. Health Coach will approach you soon";
        strContent = strContent.Replace("[Name]", oCompanyManager.GetUserDetailsByUsername(AppLib.GetLoggedInUserName()).StrUserFullName);
        strContent = strContent.Replace("[Email]", AppLib.GetLoggedInUserName());
        strContent = strContent.Replace("[Category]", ddlCategory.SelectedItem.Text + " - " + ddlLevel.SelectedItem.Text);
        strContent = strContent.Replace("[Question]", txtQuestion.Text.Trim());

        strContent = strContent.Replace("[Subject]", txtsubject.Text);
        strContent = strContent.Replace("[Comments]", txtComments.Text);
        strContent = strContent.Replace("[QuestionType]", rdoQuestionType.SelectedItem.Text);

        strContent = strContent.Replace("[SiteUrl]", AppConfig.GetBaseSiteUrl());
        strContent = strContent.Replace("[SiteName]", AppConfig.GetSiteName());
        strContent = strContent.Replace("[SitePhone]", AppConfig.GetSITEPHONE());

        ///Code for Forum

        if (rdoQuestionType.SelectedValue == "Public")
        {

            string msg = txtQuestion.Text;
            msg = msg.Trim();
            msg = msg.Replace("<", "&lt;").Replace(">", "&gt;");
            msg = aspnetforum.Utils.Formatting.FilterBadWords(msg);

            bool isModer = false;

            if (msg == "") return;

            string catgory = ddlCategory.SelectedItem.Text;
            string lvl = ddlLevel.SelectedValue;
            string totalvalue = catgory + " - " + lvl;
            providerFactory = aspnetforum.Utils.DB.CreateDBProviderFactory();
            cn = aspnetforum.Utils.DB.CreateConnection();
            cmd = providerFactory.CreateCommand();
            cmd.Connection = cn;
            this.cn.Open();
            this.cmd.CommandText = "SELECT ForumID FROM Forums WHERE Title='" + totalvalue + "'";

            object _forumID = this.cmd.ExecuteScalar();

            if (_addTopic || _changeTopic) //creating a new topic or editing topic title
            {
                string subj = txtsubject.Text;
                subj = subj.Trim();
                if (subj == "") return;
                subj = aspnetforum.Utils.Formatting.FilterBadWords(subj);

                if (_addTopic)
                {
                    string CurrentUserID = Membership.GetUser().ProviderUserKey.ToString();
                    this.cmd.Parameters.Clear();
                    this.cmd.CommandText = "INSERT INTO ForumTopics (ForumID, UserID, Subject, Visible) " +
                        "VALUES (?, convert(uniqueidentifier, ?), ?, ?)";
                    aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, _forumID, CurrentUserID, subj, !_premoderated);
                    this.cmd.ExecuteNonQuery();
                    this.cmd.Parameters.Clear();

                    this.cmd.CommandText = "SELECT MAX(TopicID) FROM ForumTopics WHERE Subject=?";
                    aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, subj);
                    _topicID = Convert.ToInt32(this.cmd.ExecuteScalar());
                    this.cmd.Parameters.Clear();

                    //CREATE A POLL (if specified)
                    string pollQuestion = "";//tbPollQuestion.Text.Trim();
                    if (pollQuestion.Length > 0)
                    {
                        //add a poll
                        this.cmd.Parameters.Clear();
                        this.cmd.CommandText = "INSERT INTO ForumPolls (TopicID, Question) " +
                            "VALUES (?, ?)";
                        aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, _topicID, pollQuestion);
                        this.cmd.ExecuteNonQuery();
                        this.cmd.Parameters.Clear();

                        //now get the ID of the poll we just created
                        this.cmd.CommandText = "SELECT MAX(PollID) FROM ForumPolls WHERE TopicID=?";
                        aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, _topicID);
                        int pollID = Convert.ToInt32(this.cmd.ExecuteScalar());
                        this.cmd.Parameters.Clear();

                        int i = 0;
                        while (Request.Form["PollOption" + i] != null && Request.Form["PollOption" + i].Trim().Length > 0)
                        {
                            //add option
                            this.cmd.CommandText = "INSERT INTO ForumPollOptions (PollID, OptionText) " +
                            "VALUES (?, ?)";
                            aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, pollID, Request.Form["PollOption" + i]);
                            this.cmd.ExecuteNonQuery();
                            this.cmd.Parameters.Clear();
                            i++;
                        }
                    }
                }
                else if (_changeTopic) //edit topic subj
                {
                    this.cmd.Parameters.Clear();
                    this.cmd.CommandText = "UPDATE ForumTopics SET Subject = ? WHERE TopicID = ?";
                    aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, subj, _topicID);
                    this.cmd.ExecuteNonQuery();
                    this.cmd.Parameters.Clear();
                }
            }

            // Inserting or updating?
            if (_isEditing)
            {
                //if moderatro, admin or message author
                //if (bmoderator || _messageAuthorID == CurrentUserID)
                //{
                //    // Record last editor and date at the end of the message.
                //    msg += "\r\n<em>edited by " + Session["aspnetforumUserName"] +
                //            " on " + aspnetforum.Utils.GetCurrTime().ToShortDateString() + "</em>";

                //    this.cmd.CommandText = "UPDATE ForumMessages SET Body=?, Visible=? " +
                //        "WHERE MessageID=" + _messageId;
                //    aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, msg, !_premoderated);
                //    this.cmd.ExecuteNonQuery();
                //    this.cmd.Parameters.Clear();

                //    SaveAttachments(_messageId);
                //}
            }
            else //inserting
            {
                this.cmd.CommandText = "INSERT INTO ForumMessages (TopicID, UserID, Body, CreationDate, Visible) " +
                    "VALUES (?, convert(uniqueidentifier, ?), ?, ?, ?)";
                aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, _topicID, CurrentUserID, msg, aspnetforum.Utils.GetCurrTime(), !_premoderated);
                this.cmd.ExecuteNonQuery();
                this.cmd.Parameters.Clear();

                //incrementing repliescount (well... actually - re-calculating it)
                this.cmd.CommandText = "SELECT Count(MessageID) FROM ForumMessages WHERE TopicID=" + _topicID;
                object res = this.cmd.ExecuteScalar();
                this.cmd.CommandText = "UPDATE ForumTopics SET RepliesCount=" + res.ToString() + " WHERE TopicID=" + _topicID;
                this.cmd.ExecuteNonQuery();

                //incrementing PostsCount in Users table only for new messages, not edits.
                //only for registered users (if guestmode is on)
                if (CurrentUserID != "")
                {
                    this.cmd.CommandText = "UPDATE ForumUsers SET PostsCount=PostsCount+1 WHERE UserID='" + CurrentUserID + "'";
                    this.cmd.ExecuteNonQuery();
                }

                //get last message's ID
                this.cmd.CommandText = "SELECT MAX(MessageID) FROM ForumMessages WHERE TopicID=" + _topicID + " AND UserID='" + CurrentUserID + "'";
                aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, true);
                res = this.cmd.ExecuteScalar();
                int lastmsgid = (res == null || res == DBNull.Value) ? 0 : Convert.ToInt32(res);

                //updating LastMessageID in Topics table
                this.cmd.CommandText = "UPDATE ForumTopics SET LastMessageID=" + lastmsgid + " WHERE TopicID=" + _topicID;
                this.cmd.ExecuteNonQuery();

                SaveAttachments(lastmsgid);
            }

            //saving notifications settings
            if (_mailNotificationsEnabled)
            {
                this.cmd.CommandText = "DELETE FROM ForumSubscriptions WHERE UserID='" + CurrentUserID + "' AND TopicID=" + _topicID;
                this.cmd.ExecuteNonQuery();
                //if(this.cbSubscribe.Checked)
                //{
                this.cmd.CommandText = "INSERT INTO ForumSubscriptions (UserID, TopicID) VALUES ('" + CurrentUserID + "', " + _topicID + ")";
                this.cmd.ExecuteNonQuery();
                //}
            }

            //sending notifications
            if (_mailNotificationsEnabled)
            {
                string url = Request.Url.ToString().ToLower();
                url = url.Substring(0, url.IndexOf("addpost.aspx"));

                if (_addTopic)
                {
                    if (_forumID != null)
                    {
                        aspnetforum.SendNotifications.SendNewTopicNotificationEmails(Convert.ToInt32(_forumID), CurrentUserID, url);
                    }

                }
                else
                {
                    aspnetforum.SendNotifications.SendNewMsgNotificationEmails(_topicID, CurrentUserID, url);
                }
            }

        }

        try
        {
            AppLib.SendMailToUser(AppLib.GetLoggedInUserName(), txtsubject.Text, strContent, AppConfig.GetAdminEmail());

            AppLib.SendMailToUser(AppConfig.GetAdminEmail(), txtsubject.Text, "Dear Admin, Following are the contents that were sent to the user. <br />" + strContent, AppLib.GetLoggedInUserName());
        }
        catch { }

        oTemplateLib = null;
        oCompanyManager = null;
        oCompanyInfo = null;

        txtQuestion.Text = string.Empty;
        txtsubject.Text = string.Empty;
        txtComments.Text = string.Empty; ;
        rdoQuestionType.SelectedIndex = 0;
    }
    protected void lnkBtnUpdate_Click(object sender, EventArgs e)
    {
        BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();
        List<Entity.CompanyInfo> oListCompanyInfo = new List<Entity.CompanyInfo>();
        Entity.CompanyInfo oCompanyInfo = new Entity.CompanyInfo();
        switch (ddlToEmails.SelectedValue)
        {
            case "0":/*send email to all the users*/
                {
                    oListCompanyInfo = oCompanyManager.GetAllUsers();
                    if (oListCompanyInfo.Count > 0)
                    {
                        foreach (var item in oListCompanyInfo)
                        {
                            AppLib.SendMailToUser(item.StrEmpEmail, txtSubject.Text, reContent.Content, txtFromEmail.Text);
                        }
                    }
                    oCompanyManager = null;
                    oListCompanyInfo = null;
                    break;
                }
            case "1":/*send email to all companies*/
                {
                    oListCompanyInfo = oCompanyManager.GetCompanyAllCompanies();
                    if (oListCompanyInfo.Count > 0)
                    {
                        foreach (var item in oListCompanyInfo)
                        {
                            AppLib.SendMailToUser(item.StrEmpEmail, txtSubject.Text, reContent.Content, txtFromEmail.Text);
                        }
                    }
                    break;
                }
            case "2":/* send email to single companies*/
                {
                    oCompanyInfo = oCompanyManager.GetCompanyDetailsById(Convert.ToInt32(ddlCompany.SelectedValue));
                    if (oCompanyInfo != null)
                    {
                        AppLib.SendMailToUser(oCompanyInfo.StrCompanyEmail, txtSubject.Text, reContent.Content,txtFromEmail.Text);
                    }
                    break;
                }
            case "3":/*send email to all the users of the company*/
                {
                    oListCompanyInfo = oCompanyManager.GetUsersByCompanyId(Convert.ToInt32(ddlCompany.SelectedValue));
                    foreach (var item in oListCompanyInfo)
                    {
                        AppLib.SendMailToUser(item.StrEmpEmail, txtSubject.Text, reContent.Content, txtFromEmail.Text);
                    }

                    break;
                }
            case "4":/*send email to single user of the compan*/
                {
                    AppLib.SendMailToUser(ddlUsers.SelectedItem.Text, txtSubject.Text, reContent.Content, txtFromEmail.Text);
                    break;
                }
            default:
                {
                    break;
                }
        }

        lblMsg.Text = "Email(s) has been successfully sent. ";
        txtSubject.Text = string.Empty;
        reContent.Content = string.Empty;
        oCompanyManager = null;
        oCompanyInfo = null;
        oListCompanyInfo = null;
    }
    private void fillName()
    {
        lblName.Text = "Guest";
        BLL.CompanyManager oCompanyManager;
        Entity.CompanyInfo oCompanyInfo;
        string sUsername = AppLib.GetLoggedInUserName();
        oCompanyManager = new BLL.CompanyManager();
        oCompanyInfo = new Entity.CompanyInfo();
        oCompanyInfo = oCompanyManager.CheckEmailIDExistsInCompany(sUsername);
        if (oCompanyInfo != null)
        {
            lblName.Text = oCompanyInfo.StrCompanyName;
            // rmMenu.Items[7].Items[2].Visible = false;
            //  IFRAME_CONTENT.Attributes.Remove("src");
            // IFRAME_CONTENT.Attributes.Add("src", AppConfig.GetBaseSiteUrl() + "Company/UploadUsersForRegistration.aspx");
            //rmMenu.Items[7].Items[1].Visible = true;
            //rmMenu.Items[7].Items[0].Visible = true;
        }
        else
        {
            //rmMenu.Items[7].Items[2].Visible = true;
            // rmMenu.Items[7].Items[1].Visible = false;
            //rmMenu.Items[7].Items[0].Visible = false;
            //rmMenu.Items[7].Visible = false;
        }

        oCompanyInfo = null;
        oCompanyManager = null;
        lblLogout.Text = " ";
        lblLogout.Text = "<a class='small' href='" + AppConfig.GetBaseSiteUrl() + "login/logout.aspx'>Log Out</a> ";
        //lblEdit.Text = " ";
        if (Membership.GetUser() != null)
        {
            //string sUsername = Membership.GetUser().UserName;
            DS = objBackofficeClass.Mem_GET_UserInfo(sUsername);
            try
            {
                // lblEdit.Text = "<a class='small' href=\"javascript:load('" + AppConfig.GetBaseSiteUrl() + "Main/UserUtilities/EditUser.aspx');\">My Account</a> <span style=font-weight:normal;>|</span> ";
                lblLogout.Text = "<a class='small' href='/login/logout.aspx'>Log Out</a> ";/*Commented by Netsmartz*/
                lblLogout.Text = "<a class='small' href='" + AppConfig.GetBaseSiteUrl() + "login/logout.aspx'>Log Out</a> ";

                if (AppLib.GetLoggedInUserType().ToLower().ToString().Equals("a"))
                {
                   // lblAdminArea.Text = "<a target='_top' class='small' href='" + AppConfig.GetBaseSiteUrl() + "Backoffice/Main_FRAME.aspx'>Admin Area</a>";//  <span style='color:#DAA520'>|</span> ";
                }
                if (AppLib.GetCurrentUserType().ToLower().ToString().Equals("c"))
                {
                    //lblEdit.Text = "<a class='small' href=\"javascript:load('" + AppConfig.GetBaseSiteUrl() + "Company/EditCompanyDetails.aspx?id=" + AppLib.GetLoggedInUserId() + "');\">My Account</a> <span style=font-weight:normal;>|</span> ";
                }

                lblName.Text = DS.Tables[0].Rows[0]["FNAME"].ToString() + " " + DS.Tables[0].Rows[0]["LNAME"].ToString();
            }
            catch (Exception ex)
            {
            }
        }
    }
    private void sendOutConfirmationEmail(int intCompanyId)
    {
        try
        {
            oCompanyInfo = new Entity.CompanyInfo();
            oCompanyManager = new BLL.CompanyManager();
            oCompanyInfo = oCompanyManager.GetCompanyDetailsById(intCompanyId);
            if (oCompanyInfo != null)
            {
                string strContent = string.Empty;
                BLL.TemplateLib oTemplateLib = new BLL.TemplateLib();

                strContent = oTemplateLib.GetTemplateDetailsByTemplateTemplateName("CompanyStatusChangedEmail").TextAreaHTML;

                string strToEmail = oCompanyInfo.StrCompanyEmail;
                strContent = strContent.Replace("[CompanyName]", oCompanyInfo.StrCompanyName);
                strContent = strContent.Replace("[UI_USERNAME]", oCompanyInfo.StrCompanyEmail);
                strContent = strContent.Replace("[WC_EMAIL_PROJECT_NAME]", AppConfig.GetSiteName());
                strContent = strContent.Replace("[SiteUrl]", AppConfig.GetBaseSiteUrl());
                strContent = strContent.Replace("[SiteName]", AppConfig.GetSiteName());
                strContent = strContent.Replace("[SitePhone]", AppConfig.GetSITEPHONE());
                strContent = strContent.Replace("[Status]", oCompanyInfo.ChrIsActive.Equals('Y') ? "Active" : "Deactive");

                AppLib.SendMailToUser(strToEmail, "Registration Request Status Changed From Tri Living Well", strContent, AppConfig.GetAdminEmail());
                oTemplateLib = null;
                oCompanyInfo = null;
                oCompanyManager = null;
            }
        }
        catch { }
    }
    /// Function Header*******************************************************
    /// Function Name: BindQuestions
    /// Function Type: Function
    /// Functionality: used to get bind the questions which were asked by user(s)
    /// Input: 
    /// Output: 
    /// Return Value:
    /// Note: 
    /// *********************************************************************
    private void BindQuestions()
    {
        Entity.CompanyInfo oCompanyInfo = new Entity.CompanyInfo();
        oCompanyInfo.StrCategoryName = ddlCategory.SelectedValue;
        oCompanyInfo.ChrIsAnsweredGiven = Convert.ToChar(ddlAnsweredGiven.SelectedValue);
        oCompanyInfo.StrQuestionType = ddlQuestionType.SelectedValue;
        BLL.CompanyManager oCompanyManager = new BLL.CompanyManager();
        GVQuestion.DataSource = oCompanyManager.GetQuestionsForHealthCoachFromUser(oCompanyInfo);

        GVQuestion.DataBind();
        oCompanyManager = null;
        oCompanyInfo = null;
    }
    protected void lnkBtnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            oCompanyInfo = new Entity.CompanyInfo();
            oCompanyInfo.StrCompanyEmail = txtCompanyEmail.Text.Trim();
            oCompanyInfo.StrPassword = txtPassword.Text.Trim();
            oCompanyInfo.StrCompanyName = txtCompanyName.Text.Trim();
            oCompanyInfo.StrCompanyPhone = txtPhone.Text.Trim();
            oCompanyInfo.StrCompanyFax = txtFax.Text.Trim();
        //DKB 04/09/12
        //Remove country from company reg page. I am adding in a hidden field for usa so the stored procs don't have to change
        //for country.
            oCompanyInfo.IntCountryId = Convert.ToInt32(hiddenCountry.Value);

        /*
        David K Bowers 04/09/12
        USA only so only display states
        for country.
            if (ddlCountry.SelectedValue == "1" || ddlCountry.SelectedValue == "2")//USA || Canada
            {
                oCompanyInfo.IntStateId = Convert.ToInt32(ddlState.SelectedValue);
                oCompanyInfo.StrStateName = ddlState.SelectedItem.Text;
            }
            else
            {
                oCompanyInfo.IntStateId = 0;
                oCompanyInfo.StrStateName = txtStateText.Text.Trim();
            }
        */

            oCompanyInfo.IntStateId = Convert.ToInt32(ddlState.SelectedValue);
            oCompanyInfo.StrStateName = ddlState.SelectedItem.Text;

        // David K. Bowers 04/10/12 added in zip code
            oCompanyInfo.StrZipCode = txtZipCode.Text.Trim();

            oCompanyInfo.StrCity = txtCity.Text.Trim();
            oCompanyInfo.StrCompanyAddress = txtAddress.Text.Trim();
        // David K. Bowers 04/10/12 changed default values of ChrIsPaid and ChrIsApproved from Y to N
            oCompanyInfo.ChrIsPaid = 'N';
            oCompanyInfo.ChrIsActive = 'N';
            oCompanyInfo.ChrIsApproved = 'Y';

            oCompanyInfo.DtCreatedDate = DateTime.Now;
            oCompanyInfo.DtModifiedDate = oCompanyInfo.DtCreatedDate;
            oCompanyInfo.ChrIsDeleted = 'N';
            oCompanyInfo.ChrCreatedBy = 'C';

            oCompanyManager = new BLL.CompanyManager();

            MembershipUser objUser = Membership.CreateUser(oCompanyInfo.StrCompanyEmail, oCompanyInfo.StrPassword, oCompanyInfo.StrCompanyEmail);
            int intRetVal = oCompanyManager.SaveCompanyDetails(oCompanyInfo);
            if (intRetVal > 0)
            {
                sendOutConfirmationEmail();
                string strpath = Request.PhysicalApplicationPath + AppConfig.GetCompanyRequestExcelUploadPath() + intRetVal.ToString();
                DirectoryInfo drInfo = new DirectoryInfo(strpath);
                if (!drInfo.Exists)
                {
                    drInfo.Create();
                }

                oCompanyManager = null;
                oCompanyInfo = null;
                if (Request.QueryString["src"] == null)
                {
                    lblError.Text = "<br /><br /><br /><br />Thanks for your information, TLW will contact you soon.<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />";
                    trControls.Visible = false;
                    ClearControls();
                }
                else
                {
                    Response.Redirect(AppConfig.GetBaseSiteUrl() + "BackOffice/ManageCompany/ManageCompanies.aspx?m=ins", true);
                }
            }
            else
            {
                trControls.Visible = true;
                lblError.Text = "Company Email Id already exists.";
                return;
            }
        }
        catch
        {

            lblError.Text = "Company Email Id already exists.";
            // return;
        }

        oCompanyManager = null;
        oCompanyInfo = null;
    }
    protected void lnkBtnSubmit_Click(object sender, EventArgs e)
    {
        oCompanyInfo = new Entity.CompanyInfo();
        oCompanyInfo.IntCompanyId = Convert.ToInt32(Request.QueryString["id"]);
        oCompanyInfo.StrCompanyName = txtCompanyName.Text.Trim();
        oCompanyInfo.StrCompanyPhone = txtPhone.Text.Trim();
        oCompanyInfo.StrCompanyFax = txtFax.Text.Trim();
        oCompanyInfo.IntCountryId = Convert.ToInt32(ddlCountry.SelectedValue);
        oCompanyInfo.StrStateName = txtStateText.Text.Trim();

        if (ddlCountry.SelectedValue == "1" || ddlCountry.SelectedValue == "2")//USA || Canada
        {

            oCompanyInfo.IntStateId = Convert.ToInt32(ddlState.SelectedValue);
            oCompanyInfo.StrStateName = ddlState.SelectedItem.Text;
        }
        else
        {
            oCompanyInfo.IntStateId = 0;
            oCompanyInfo.StrStateName = txtStateText.Text.Trim();
        }

        oCompanyInfo.StrCity = txtCity.Text.Trim();
        oCompanyInfo.StrCompanyAddress = txtAddress.Text.Trim();

        oCompanyInfo.ChrIsActive = Convert.ToChar(rblStatus.SelectedValue);
        oCompanyInfo.ChrIsApproved = Convert.ToChar(rblApproved.SelectedValue);
        oCompanyInfo.DtModifiedDate = DateTime.Now;

        oCompanyManager = new BLL.CompanyManager();
        if (oCompanyManager.UpdateCompanyDetails(oCompanyInfo) > 0)
        {
            oCompanyInfo = null;
            oCompanyManager = null;

            if (AppLib.GetCurrentUserType().ToLower().ToString().Equals("c"))
            {
                lblError.Text = "Information has been updated successfully.";
            }
            else
            {
                Response.Redirect(AppConfig.GetBaseSiteUrl() + "BackOffice/ManageCompany/ManageCompanies.aspx?m=up", true);
            }
        }
        else
        {
            lblError.Text = "Company Email already exists.";

            return;
        }
    }
 /************************************************************
 Function Name: BindCompanies
 Functionality: This function is used to bind the company grid
 *********************************************************************/
 private void BindCompanies()
 {
     oCompanyManager = new BLL.CompanyManager();
     GVUsers.DataSource = oCompanyManager.SearchRequestedUsersForCompanies(Convert.ToInt32(AppLib.GetLoggedInUserId()), Convert.ToChar(ddlStatus.SelectedValue));
     GVUsers.DataBind();
 }