private void CreateRM()
        {
            if (Validation())
            {
                AdvisorStaffBo advisorStaffBo = new AdvisorStaffBo();
                RMVo           rmVo           = new RMVo();
                Random         id             = new Random();
                AdvisorBo      advisorBo      = new AdvisorBo();
                advisorVo = (AdvisorVo)Session["advisorVo"];
                int    branchId;
                string password = id.Next(10000, 99999).ToString();

                rmUserVo.UserType   = "Advisor";
                rmUserVo.Password   = Encryption.Encrypt(password);
                rmUserVo.MiddleName = txtMiddleName.Text.ToString();
                //rmUserVo.LoginId = txtEmail.Text.ToString();
                rmUserVo.LastName  = txtLastName.Text.ToString();
                rmUserVo.FirstName = txtFirstName.Text.ToString();

                rmUserVo.Email = txtEmail.Text.ToString();

                rmVo.Email = txtEmail.Text.ToString();
                if (txtFaxNumber.Text == "")
                {
                    rmVo.Fax = 0;
                }
                else
                {
                    rmVo.Fax = int.Parse(txtFaxNumber.Text.ToString());
                }
                if (txtFaxISD.Text == "")
                {
                    rmVo.FaxIsd = 0;
                }
                else
                {
                    rmVo.FaxIsd = int.Parse(txtFaxISD.Text.ToString());
                }
                if (txtFaxSTD.Text == "")
                {
                    rmVo.FaxStd = 0;
                }
                else
                {
                    rmVo.FaxStd = int.Parse(txtExtSTD.Text.ToString());
                }

                rmVo.FirstName  = txtFirstName.Text.ToString();
                rmVo.LastName   = txtLastName.Text.ToString();
                rmVo.MiddleName = txtMiddleName.Text.ToString();
                rmVo.StaffCode  = txtStaffCode.Text.ToString();
                if (txtMobileNumber.Text.ToString() != "")
                {
                    rmVo.Mobile = Convert.ToInt64(txtMobileNumber.Text.ToString());
                }
                if (!string.IsNullOrEmpty(txtPhDirectISD.Text.ToString()))
                {
                    rmVo.OfficePhoneDirectIsd = int.Parse(txtPhDirectISD.Text.ToString());
                }
                if (!string.IsNullOrEmpty(txtPhDirectPhoneNumber.Text.ToString()))
                {
                    rmVo.OfficePhoneDirectNumber = int.Parse(txtPhDirectPhoneNumber.Text.ToString());
                }

                if (txtPhExtISD.Text == "")
                {
                    rmVo.OfficePhoneExtIsd = 0;
                }
                else
                {
                    rmVo.OfficePhoneExtIsd = int.Parse(txtPhExtISD.Text.ToString());
                }
                if (txtPhExtPhoneNumber.Text == "")
                {
                    rmVo.OfficePhoneExtNumber = 0;
                }
                else
                {
                    rmVo.OfficePhoneExtNumber = int.Parse(txtPhExtPhoneNumber.Text.ToString());
                }
                if (txtExtSTD.Text == "")
                {
                    rmVo.OfficePhoneExtStd = 0;
                }
                else
                {
                    rmVo.OfficePhoneExtStd = int.Parse(txtExtSTD.Text.ToString());
                }
                if (txtPhResiISD.Text == "")
                {
                    rmVo.ResPhoneIsd = 0;
                }
                else
                {
                    rmVo.ResPhoneIsd = int.Parse(txtPhResiISD.Text.ToString());
                }
                if (txtPhResiPhoneNumber.Text == "")
                {
                    rmVo.ResPhoneNumber = 0;
                }
                else
                {
                    rmVo.ResPhoneNumber = int.Parse(txtPhResiPhoneNumber.Text.ToString());
                }
                if (txtResiSTD.Text == "")
                {
                    rmVo.ResPhoneStd = 0;
                }
                else
                {
                    rmVo.ResPhoneStd = int.Parse(txtResiSTD.Text.ToString());
                }
                if (txtPhDirectSTD.Text == "")
                {
                    rmVo.OfficePhoneDirectStd = 0;
                }
                else
                {
                    rmVo.OfficePhoneDirectStd = int.Parse(txtPhDirectSTD.Text.ToString());
                }
                if (ChklistRMBM.Items[0].Selected == true)
                {
                    rmVo.RMRole = "RM";
                }
                else
                {
                    rmVo.RMRole = "BM";
                }
                //rmVo.RMRole = ddlRMRole.SelectedValue.ToString();

                rmVo.AdviserId = advisorVo.advisorId;

                if (txtCTCMonthly.Text != "")
                {
                    rmVo.CTC = Double.Parse(txtCTCMonthly.Text);
                }

                if (chkExternalStaff.Checked)
                {
                    rmVo.IsExternal = 1;
                }
                else
                {
                    rmVo.IsExternal = 0;
                }

                rmIds = advisorStaffBo.CreateCompleteRM(rmUserVo, rmVo, userVo.UserId);

                rmVo.UserId         = rmIds[0];
                Session["rmId"]     = rmIds[1];
                Session["rmUserVo"] = userBo.GetUserDetails(rmVo.UserId);
                Session["userId"]   = rmVo.UserId;
                if (chkMailSend.Checked == true)
                {
                    SendMail();
                }


                //if (rmVo.RMRole == "RM")
                //{
                //    // Create Association for RM
                //    userBo.CreateRoleAssociation(rmVo.UserId, 1001);
                //    // 1001 - RM
                //    // 1000 - Adviser
                //    // 1003 - Customer
                //}
                //else
                //{
                //    // Create Association if BM
                //    userBo.CreateRoleAssociation(rmVo.UserId, 1002);
                //    // 1002 - BM
                //    if (chkRM.Checked)
                //    {
                //        // Create Association for RM
                //        userBo.CreateRoleAssociation(rmVo.UserId, 1001);
                //    }
                //}

                foreach (ListItem Items in ChklistRMBM.Items)
                {
                    if (Items.Selected)
                    {
                        if (Items.Text == "RM")
                        {
                            // Create Association for RM
                            userBo.CreateRoleAssociation(rmVo.UserId, Int16.Parse(Items.Value.ToString()));
                        }
                        else if (Items.Text == "BM")
                        {
                            // Create Association for RM
                            userBo.CreateRoleAssociation(rmVo.UserId, Int16.Parse(Items.Value.ToString()));
                        }
                    }
                }

                string hdnSelectedString = hdnSelectedBranches.Value.ToString();

                if (!string.IsNullOrEmpty(hdnSelectedString))
                {
                    string[] selectedBranchesList = hdnSelectedString.Split(',');

                    foreach (string str in selectedBranchesList)
                    {
                        if (str != "")
                        {
                            advisorBranchBo.CreateRMBranchAssociation(rmIds[1], int.Parse(str), advisorVo.advisorId, advisorVo.advisorId);
                        }
                    }
                }

                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "loadcontrol('ViewRM','none');", true);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (Validation())
                {
                    AdvisorStaffBo advisorStaffBo = new AdvisorStaffBo();
                    RMVo           rmVo           = new RMVo();
                    Random         id             = new Random();
                    AdvisorBo      advisorBo      = new AdvisorBo();

                    string password = id.Next(10000, 99999).ToString();

                    //rmUserVo.UserType = ddlRMRole.SelectedItem.Text.ToString().Trim();
                    rmUserVo.Password   = password;
                    rmUserVo.MiddleName = txtMiddleName.Text.ToString();
                    rmUserVo.LoginId    = txtEmail.Text.ToString();
                    rmUserVo.LastName   = txtLastName.Text.ToString();
                    rmUserVo.FirstName  = txtFirstName.Text.ToString();
                    rmUserVo.Email      = txtEmail.Text.ToString();

                    rmVo.Email = txtEmail.Text.ToString();
                    if (txtFaxNumber.Text == "")
                    {
                        rmVo.Fax = 0;
                    }
                    else
                    {
                        rmVo.Fax = int.Parse(txtFaxNumber.Text.ToString());
                    }
                    if (txtFaxISD.Text == "")
                    {
                        rmVo.FaxIsd = 0;
                    }
                    else
                    {
                        rmVo.FaxIsd = int.Parse(txtFaxISD.Text.ToString());
                    }
                    if (txtFaxSTD.Text == "")
                    {
                        rmVo.FaxStd = 0;
                    }
                    else
                    {
                        rmVo.FaxStd = int.Parse(txtExtSTD.Text.ToString());
                    }

                    rmVo.FirstName               = txtFirstName.Text.ToString();
                    rmVo.LastName                = txtLastName.Text.ToString();
                    rmVo.MiddleName              = txtMiddleName.Text.ToString();
                    rmVo.Mobile                  = Convert.ToInt64(txtMobileNumber.Text.ToString());
                    rmVo.OfficePhoneDirectIsd    = int.Parse(txtPhDirectISD.Text.ToString());
                    rmVo.OfficePhoneDirectNumber = int.Parse(txtPhDirectPhoneNumber.Text.ToString());

                    if (txtPhExtISD.Text == "")
                    {
                        rmVo.OfficePhoneExtIsd = 0;
                    }
                    else
                    {
                        rmVo.OfficePhoneExtIsd = int.Parse(txtPhExtISD.Text.ToString());
                    }
                    if (txtPhExtPhoneNumber.Text == "")
                    {
                        rmVo.OfficePhoneExtNumber = 0;
                    }
                    else
                    {
                        rmVo.OfficePhoneExtNumber = int.Parse(txtPhExtPhoneNumber.Text.ToString());
                    }
                    if (txtExtSTD.Text == "")
                    {
                        rmVo.OfficePhoneExtStd = 0;
                    }
                    else
                    {
                        rmVo.OfficePhoneExtStd = int.Parse(txtExtSTD.Text.ToString());
                    }
                    if (txtPhResiISD.Text == "")
                    {
                        rmVo.ResPhoneIsd = 0;
                    }
                    else
                    {
                        rmVo.ResPhoneIsd = int.Parse(txtPhResiISD.Text.ToString());
                    }
                    if (txtPhResiPhoneNumber.Text == "")
                    {
                        rmVo.ResPhoneNumber = 0;
                    }
                    else
                    {
                        rmVo.ResPhoneNumber = int.Parse(txtPhResiPhoneNumber.Text.ToString());
                    }
                    if (txtResiSTD.Text == "")
                    {
                        rmVo.ResPhoneStd = 0;
                    }
                    else
                    {
                        rmVo.ResPhoneStd = int.Parse(txtResiSTD.Text.ToString());
                    }
                    if (txtPhDirectSTD.Text == "")
                    {
                        rmVo.OfficePhoneDirectStd = 0;
                    }
                    else
                    {
                        rmVo.OfficePhoneDirectStd = int.Parse(txtPhDirectSTD.Text.ToString());
                    }

                    //rmVo.RMRole = ddlRMRole.SelectedValue.ToString();

                    rmVo.AdviserId = advisorVo.advisorId;

                    if (chkExternalStaff.Checked)
                    {
                        rmVo.IsExternal = 1;
                        rmVo.CTC        = Double.Parse(txtCTCMonthly.Text);
                    }
                    else
                    {
                        rmVo.IsExternal = 0;
                    }

                    rmIds = advisorStaffBo.CreateCompleteRM(rmUserVo, rmVo, userVo.UserId);

                    rmVo.UserId         = rmIds[0];
                    Session["rmId"]     = rmIds[1];
                    Session["rmUserVo"] = userBo.GetUserDetails(rmVo.UserId);
                    Session["userId"]   = rmVo.UserId;

                    //if (rmVo.RMRole == "RM")
                    //{
                    //    // Create Association for RM
                    //    userBo.CreateRoleAssociation(rmVo.UserId, 1001);
                    //    // 1001 - RM
                    //    // 1000 - Adviser
                    //    // 1003 - Customer
                    //}
                    //else
                    //{
                    //    // Create Association if BM
                    //    userBo.CreateRoleAssociation(rmVo.UserId, 1002);
                    //    // 1002 - BM
                    //    if (chkRM.Checked)
                    //    {
                    //        // Create Association for RM
                    //        userBo.CreateRoleAssociation(rmVo.UserId, 1001);
                    //    }
                    //}
                    //if (chkRM.Checked)
                    //{
                    //    // Create Association for RM
                    //     userBo.CreateRoleAssociation(rmVo.UserId, 1001);

                    //}
                    //if (chkBM.Checked)
                    //{
                    //    // Create Association if BM
                    //   userBo.CreateRoleAssociation(rmVo.UserId, 1002);

                    //}
                }
            }
            catch (BaseApplicationException Ex)
            {
                throw Ex;
            }
            catch (Exception Ex)
            {
                BaseApplicationException exBase       = new BaseApplicationException(Ex.Message, Ex);
                NameValueCollection      FunctionInfo = new NameValueCollection();
                FunctionInfo.Add("Method", "AddRM.ascx:btnSave_Click()");
                object[] objects = new object[5];
                objects[0]   = advisorVo;
                objects[1]   = userVo;
                objects[2]   = rmUserVo;
                objects[3]   = userId;
                objects[4]   = rmVo;
                FunctionInfo = exBase.AddObject(FunctionInfo, objects);
                exBase.AdditionalInformation = FunctionInfo;
                ExceptionManager.Publish(exBase);
                throw exBase;
            }
        }