//protected void btnClear_Click(object sender, EventArgs e)
 //{
 //    txtName.Text = string.Empty;
 //    txtPassword.Text = string.Empty;
 //    LogActivity("Clear User Detail", "User detail has been cleared", string.Empty);
 //}
 //protected void btnSave_Click(object sender, EventArgs e)
 //{
 //    LoginBLL bll = new LoginBLL();
 //    if (bll.IsValidPasword(txtPassword.Text))
 //    {
 //        DAL.Login model = new DAL.Login();
 //        model.CreatedDate = DateTime.Now;
 //        model.FailedAttempts = 0;
 //        model.IsLocked = false;
 //        model.LastPasswordReset = DateTime.Now;
 //        model.Name = txtName.Text;
 //        model.Password = txtPassword.Text;
 //        model.Role = AppConstants.Roles.Normal.ToString();
 //        model.Status = 1;
 //        model.Email = txtCreatUserEmail.Text;
 //        model = bll.NewAccount(model);
 //        lblError.Visible = false;
 //        if (model == null)
 //        {
 //            ShowMessage("Error", "User with the same name already exist");
 //            return;
 //        }
 //        BindAccounts();
 //        LogActivity("User Created", "New user has been created", string.Empty);
 //    }
 //    else
 //    {
 //        lblError.Visible = true;
 //        lblError.Text = "Password must be 8 to 15 characters long which contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character";
 //    }
 //}
 //protected void btnSaveEmail_Click(object sender, EventArgs e)
 //{
 //    EmailGroup model = new EmailGroup();
 //    if (!string.IsNullOrEmpty(hfEmailGroupId.Value))
 //    {
 //        model.ID = Convert.ToInt32(hfEmailGroupId.Value);
 //        LogActivity("Email Updated", "Email has been updated", string.Empty);
 //    }
 //    else
 //    {
 //        LogActivity("Email Created", "Email has been created", string.Empty);
 //    }
 //    model.GroupName = ddlGroups.SelectedItem.Text;
 //    model.Name = txtEmail.Text;
 //    EmailGroupsBL bl = new EmailGroupsBL();
 //    bl.Save(model);
 //    BindEmails();
 //    hfEmailGroupId.Value = string.Empty;
 //}
 //protected void grdEmail_RowCommand(object sender, GridViewCommandEventArgs e)
 //{
 //    EmailGroupsBL bll = new EmailGroupsBL();
 //    if (e.CommandName == "Remove")
 //    {
 //        int id = Convert.ToInt32(e.CommandArgument);
 //        bll.Delete(id);
 //        BindEmails();
 //        LogActivity("Email Removed", "Email has been removed", string.Empty);
 //    }
 //    else if (e.CommandName == "EditRow")
 //    {
 //        int id = Convert.ToInt32(e.CommandArgument);
 //        EmailGroup model = bll.GetById(id);
 //        txtEmail.Text = model.Name;
 //        ddlGroups.ClearSelection();
 //        ddlGroups.FindItemByText(model.GroupName).Selected = true;
 //        hfEmailGroupId.Value = model.ID.ToString();
 //    }
 //    else if (e.CommandName == "SendEmail")
 //    {
 //        ReportHelper.GenerateAndSendPDFReport(e.CommandArgument.ToString());
 //        ShowMessage("Message", "Emails has been set to all the addresses in the group(" + e.CommandArgument.ToString() + ")");
 //    }
 //}
 //protected void btnClearEmail_Click(object sender, EventArgs e)
 //{
 //    txtEmail.Text = string.Empty;
 //    hfEmailGroupId.Value = string.Empty;
 //}
 protected void ddlGroupReceiver_SelectedIndexChanged(object sender, EventArgs e)
 {
     GroupBL bl = new GroupBL();
     bl.SetEmailReceiver(Convert.ToInt32(ddlGroupReceiver.SelectedValue));
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //txtIdleTime.Text = "15" ;

                var configuration = WebConfigurationManager.OpenWebConfiguration("~");
                var section = (SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState");

                double timeout = 0;
                if (section != null)
                    timeout = section.Timeout.TotalMinutes;
                txtIdleTime.InnerText = timeout.ToString();
                //    section.Timeout = new TimeSpan(0,Convert.ToInt16( txtIdleTime.Text),0);
                /// Only administrator can view this page
                ///

                string urlWithSessionID = Response.ApplyAppPathModifier(Request.Url.PathAndQuery);
                RadTab tab = RadTabStrip1.FindTabByUrl(urlWithSessionID);
                if (tab != null)
                {
                    tab.SelectParents();
                    tab.PageView.Selected = true;
                }

                Sorting();

                //on 08-01
                BindCurrentYear();

                if (Session["LogedInUser"] != null && (Session["LogedInUser"] as DAL.Login) != null)
                {
                    // Show the Admin tab only to Administrator role
                    if ((Session["LogedInUser"] as DAL.Login).Role == AppConstants.Roles.Admin.ToString())
                    {
                        BindAccounts();
                        BindEmails(); BindRegions();
                        BindCounterParties(); BindBorrowers();
                        BindCountry(); BindCurrencies(); BindCreditRatings(); BindCreditAgencies(); BindAgencyDropDown();
                        GroupBL bl = new GroupBL();
                        List<Group> groups = bl.GetAll(); ;
                        ddlGroups.DataSource = groups;
                        ddlGroups.DataTextField = "Name";
                        ddlGroups.DataValueField = "ID";
                        ddlGroups.DataBind();

                        ddlGroupReceiver.DataSource = groups;
                        ddlGroupReceiver.DataTextField = "Name";
                        ddlGroupReceiver.DataValueField = "ID";
                        ddlGroupReceiver.DataBind();
                        Group receiver = groups.FirstOrDefault(c => c.IsEmailReceiver);
                        if (receiver != null)
                        {
                            //     DropDownListItem item = ddlGroupReceiver.FindItemByText(receiver.Name);
                            ListItem item = ddlGroupReceiver.Items.FindByText(receiver.Name);

                            if (item != null)
                            {
                                item.Selected = true;
                            }
                        }
                        BindDuplicateLoansTab();
                    }
                    else
                    {
                        // Move back to the login page
                        Response.Redirect("~/Default.aspx");
                    }
                }
                else
                {
                    // Move back to the login page
                    Response.Redirect("~/Banner.aspx");
                }
            }
        }