protected void SubmitLinkButton2_Click(object sender, EventArgs e)
        {
            string street = StreetTextBox.Text;
            string city = CityTextBox.Text;
            string postal = PostalCodeTextBox.Text;
            string phone = MobilePhoneTextBox.Text;
            string email = PrimaryEmailTextBox.Text;
            UserBL userBL = new UserBL();
            bool emailaddress = userBL.IsEmailExists(PrimaryEmailTextBox.Text);
            Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
            Match match = regex.Match(email);
            Regex sregex = new Regex(@"^[a-zA-Z0-9\s\(\)\/,\:\;\.-]+$");
            Match smatch = sregex.Match(street);
            Regex cregex = new Regex(@"^[a-zA-Z''-'.\s]{1,200}$");
            Match cmatch = cregex.Match(city);
            Regex pregex = new Regex(@"^\d{4}$");
            Match pmatch = pregex.Match(postal);
            Regex mregex = new Regex(@"^(\+?(88)?)((02)|(0?1))((\d{9})|(\d{7}))$");
            Match mmatch = mregex.Match(phone);

            if (street != "" && city != "" && postal != "" && phone != "" && email !="" && emailaddress == false)
            {
                if (!smatch.Success)
                {
                    Literal1.Text = "Error";
                    Label1.Text = "Street Field is not valid ";
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                    return;
                }
                if (!cmatch.Success)
                {
                    Literal1.Text = "Error";
                    Label1.Text = "City Name is not valid ";
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                    return;
                }
                if (!pmatch.Success)
                {
                    Literal1.Text = "Error";
                    Label1.Text = "Postal code is not valid ";
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                    return;
                }
                if (!mmatch.Success)
                {
                    Literal1.Text = "Error";
                    Label1.Text = "Phone number is not valid ";
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                    return;
                }
                if (!match.Success)
                {
                    Literal1.Text = "Error";
                    Label1.Text = "This Email Address is not valid. Please give valid Email Address.";
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                    return;
                }
                if (smatch.Success && cmatch.Success && pmatch.Success && mmatch.Success && match.Success)
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "GoToSlide(2);", true);
                }

            }

            if (street == "")
            {
                Literal1.Text = "Error";
                Label1.Text = "Street Field cannot be empty";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                return;
            }
            if (city == "")
            {
                Literal1.Text = "Error";
                Label1.Text = "City field cannot be empty";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                return;
            }
            if (postal == "")
            {
                Literal1.Text = "Error";
                Label1.Text = "Postal Code Field cannot be empty";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                return;
            }
            if (phone == "")
            {
                Literal1.Text = "Error";
                Label1.Text = "Phone field cannot be empty";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                return;
            }
            if (email == "")
            {
                Literal1.Text = "Error";
                Label1.Text = "Email Address cannot be empty";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                return;
            }
            if (emailaddress == true)
            {
                Literal1.Text = "Error";
                Label1.Text = "This Email Address alreday exists. Please try another one.";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                return;
            }
        }
        protected void submit_Click(object sender, EventArgs e)
        {
            try
                {
                    string companyname = "";
                    companyname = CompanyTextBox.Text;
                    int countryid = Convert.ToInt32(countryDropDownList.SelectedValue);
                    string rolename = "Administrator";
                    UserBL userBL = new UserBL();
                    ACLRoleBL aclroleBL = new ACLRoleBL();

                    bool existcompany = false;
                    bool emailaddress = false;

                    existcompany = userBL.IsCompanyExists(companyname);
                    emailaddress = userBL.IsEmailExists(PrimaryEmailTextBox.Text);

                    if (
                        existcompany == false && emailaddress == false && companyname != "" && FirstNameTextBox.Text != ""
                        && LastNameTextBox.Text != "" && TitleTextBox.Text != "" && StreetTextBox.Text != ""
                        && CityTextBox.Text != "" && PostalCodeTextBox.Text != ""
                        && MobilePhoneTextBox.Text != "" && PrimaryEmailTextBox.Text != ""
                     )
                    {
                        Int32 companyID = userBL.GetCompanyID(companyname, countryid);
                        Int32 roleID = userBL.GetRoleID(rolename, companyID);
                        string password = userBL.GenerateRandomPassword();
                        string m = aclroleBL.InsertCompanyModules(companyID);
                        aclroleBL.InsertACLAction(roleID, companyID);
                        object[] objp;
                        int i = 0;

                        objp = new object[12];

                        objp.SetValue(FirstNameTextBox.Text, i++);
                        objp.SetValue(LastNameTextBox.Text, i++);
                        objp.SetValue(TitleTextBox.Text, i++);
                        objp.SetValue(StreetTextBox.Text, i++);
                        objp.SetValue(CityTextBox.Text, i++);
                        //objp.SetValue(StateTextBox.Text, i++);
                        objp.SetValue(PostalCodeTextBox.Text, i++);
                        objp.SetValue(countryDropDownList.SelectedValue, i++);
                        objp.SetValue(MobilePhoneTextBox.Text, i++);
                        objp.SetValue(PrimaryEmailTextBox.Text, i++);
                        objp.SetValue(companyID, i++);
                        objp.SetValue(roleID, i++);
                        objp.SetValue(password, i++);

                        long id = userBL.RegisterUser(objp);

                        /// Code done by Pavel to Activate Registered User
                        /// Start

                        string emailID = PrimaryEmailTextBox.Text;
                       // String mailbody = null;
                        Guid? activationID = userBL.GetActivationID(emailID);

                        ListDictionary templateValues = new ListDictionary();
                        templateValues.Add("<%=PrimaryEmail%>", emailID);
                        templateValues.Add("<%=ActivationID%>", activationID);
                        templateValues.Add("<%=Password%>", password);

                        Session["CompanyID"] = companyID;
                        Session["UserID"] = id;

                        C3App.App_Code.Notification.Notify("User", id, 1, emailID, 1, templateValues);

                        Session.Clear();
                        Session.Abandon();

                        Literal1.Text = "Registration Successfull";
                        Label1.Text = "To activate your account please check your email.<br>";
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                        CloseHyperLink.NavigateUrl = "~/UserLogin.aspx";
                        // ClientScript.RegisterClientScriptBlock(Page.GetType(), "validation", "<script language='javascript'>ShowAlertModal();</script>");
                    }
                    else
                    {
                        Literal1.Text = "Registration Error";
                        Label1.Text = "Registration is not completed.Please try again";
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                        CloseHyperLink.NavigateUrl = "~/UserRegister.aspx";
                        //ClientScript.RegisterClientScriptBlock(Page.GetType(), "validation", "<script language='javascript'>ShowAlertModal();</script>");
                    }

                }

                catch (Exception ex)
                {
                    throw ex;
                }
        }
        protected void UsersDetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            TextBox pe = (TextBox)UsersDetailsView.FindControl("txtPrimaryEmail");
            string pemail = pe.Text;
            UserBL userBL = new UserBL();
            bool emailaddress = false;
            emailaddress = userBL.IsEmailExists(pemail);

            int companyid = Convert.ToInt32(HttpContext.Current.Session["CompanyID"]);
            Int64 userid = Convert.ToInt32(HttpContext.Current.Session["UserID"]);

            e.Values["TeamID"] = teamDropDownList.SelectedValue;

            Int64 teamid = Convert.ToInt64(teamDropDownList.SelectedValue);
            e.Values["TeamSetID"] = userBL.GetTeamSetID(teamid);

            e.Values["CreatedBy"] = userid;
            e.Values["ModifiedBy"] = userid;
            e.Values["ModifiedTime"] = DateTime.Now;
            e.Values["CreatedTime"] = DateTime.Now;
            e.Values["ActivationID"] = Guid.NewGuid();
            e.Values["CompanyID"] = companyid;

            if (Convert.ToInt32(roleDropDownList.SelectedValue) == 0) { e.Values["RoleID"] = null; e.Values["IsAdmin"] = null; }
            else
            {
                e.Values["RoleID"] = roleDropDownList.SelectedValue;
                int roleid = Convert.ToInt32(roleDropDownList.SelectedValue);
                string rolename = userBL.GetRoleName(roleid);
                if (rolename == "Administrator" || rolename == "Admin")
                {
                    e.Values["IsAdmin"] = true;
                }
                else
                {
                    e.Values["IsAdmin"] = false;
                }

            }
            e.Values["IsActive"] = true;
            e.Values["IsEmployee"] = true;
            e.Values["CountryID"] = countryDropDownList.SelectedValue;
            e.Values["PrimaryEmail"] = pe.Text;
        }
        protected void UsersDetailsView_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
        {
            TextBox pe = (TextBox)UsersDetailsView.FindControl("txtPrimaryEmail");
            string pemail = pe.Text;
            UserBL userBL = new UserBL();
            bool emailaddress = true;
            emailaddress = userBL.IsEmailExists(pemail);

            long id = 0;
            string value = Convert.ToString(Session["NewUser"]);
            if (value != "")
            id = int.Parse(value);

            if (id > 0)
            {
                Label3.Text = "Success !</br> <p>User information has been saved successfully</p>";
                UpdatePanel3.Update();
            }
            else
            {
                if (emailaddress == false)
                {

                    Label3.Text = "Error !</br> <p>User information did not save.</p>";
                    UpdatePanel3.Update();

                }
                else
                {
                    Label3.Text = "Error !</br> <p>This Primary Email Address Already Exists.Please try another one.</p>";
                    UpdatePanel3.Update();

                }

            }
        }
        protected void UsersDetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            TextBox pe = (TextBox)UsersDetailsView.FindControl("txtPrimaryEmail");
            string pemail = pe.Text;

            TextBox pa = (TextBox)UsersDetailsView.FindControl("CreatePasswordTextBox");
            string password = pa.Text;

            UserBL userBL = new UserBL();
            bool emailaddress = false;
            emailaddress = userBL.IsEmailExists(pemail);

            int companyid = Convert.ToInt32(HttpContext.Current.Session["CompanyID"]);
            Int64 userid = Convert.ToInt32(HttpContext.Current.Session["UserID"]);

                e.Values["Gender"] = genderDropDownList.SelectedValue;
                e.Values["IsActive"] = isActiveDropDownList.SelectedValue;
                //e.Values["MaritalStatus"] = maritalStatusDropDownList.SelectedValue;
                e.Values["MessengerType"] = messengerTypeDropDownList.SelectedValue;
               // e.Values["SecurityQuestion"] = securityQuestionDropDownList.SelectedValue;
                e.Values["TeamID"] = teamDropDownList.SelectedValue;

                Int64 teamid = Convert.ToInt64(teamDropDownList.SelectedValue);
                e.Values["TeamSetID"] = userBL.GetTeamSetID(teamid);

                e.Values["CreatedBy"] = userid;
                e.Values["ModifiedBy"] = userid;
                e.Values["ModifiedTime"] = DateTime.Now;
                e.Values["CreatedTime"] = DateTime.Now;
                e.Values["ActivationID"] = Guid.NewGuid();
                e.Values["Password"] = password;
                e.Values["CompanyID"] = companyid;

                if (Convert.ToInt32(countryDropDownList.SelectedValue) == 0) { e.Values["CountryID"] = null; }
                else { e.Values["CountryID"] = countryDropDownList.SelectedValue; }

                if (Convert.ToInt32(roleDropDownList.SelectedValue) == 0) { e.Values["RoleID"] = null; e.Values["IsAdmin"] = null; }
                else
                {
                    e.Values["RoleID"] = roleDropDownList.SelectedValue;
                    int roleid = Convert.ToInt32(roleDropDownList.SelectedValue);
                    string rolename = userBL.GetRoleName(roleid);
                    if (rolename == "Administrator" || rolename == "Admin")
                    {
                        e.Values["IsAdmin"] = true;
                    }
                    else
                    {
                        e.Values["IsAdmin"] = false;
                    }

                }

                if (Convert.ToInt32(reportsToDropDownList.SelectedValue) == 0) { e.Values["ReportsTo"] = null; }
                else { e.Values["ReportsTo"] = reportsToDropDownList.SelectedValue; }
                e.Values["PrimaryEmail"] = pe.Text;
        }
        protected void UsersDetailsView_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
        {
            this.UsersGridView.DataBind();
            this.MiniUserFormView.DataBind();
            this.MiniUserDetailsView.DataBind();
            upListView.Update();
            miniDetails.Update();

            TextBox pe = (TextBox)UsersDetailsView.FindControl("txtPrimaryEmail");
            string pemail = pe.Text;
            UserBL userBL = new UserBL();
            bool emailaddress = false;
            emailaddress = userBL.IsEmailExists(pemail);

            Int64 id = 0;
            string value = Convert.ToString(Session["NewUser"]);
            if(value !="")
            id = int.Parse(value);

                if (id > 0)
                {
                    //Literal1.Text = "Success";
                    //Label6.Text = "User information has been saved successfully.";
                    Literal1.Text = "Success !</br></br> <p>User information has been saved successfully</p>";
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                    Session["EditUserID"] = 0;
                    UsersDetailsView.DataBind();

                }
                else
                {
                    if (emailaddress == true)
                    {
                        //Literal1.Text = "Error";
                        //Label6.Text = "User information did not save.";
                        Literal1.Text = "Error !</br></br> <p>User information did not save.</p>";
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$('#myModal').reveal();", true);
                        Session["EditUserID"] = 0;
                        UsersDetailsView.DataBind();

                    }

                }
        }