Esempio n. 1
0
        private void Search()
        {
            try
            {
                int companyCode = int.Parse(GetCompany());

                List <MembershipUser> listUser = new List <MembershipUser>();


                List <UserPermission> listAllPermisson = UserPermission.GetAll();

                foreach (MembershipUser m in Membership.GetAllUsers())
                {
                    if (Common.isAdminAccount(m.UserName))
                    {
                        continue;
                    }
                    UserPermission findUser = listAllPermisson.FirstOrDefault(p => p.Username == m.UserName);
                    if (findUser == null || findUser.CompanyId == companyCode)
                    {
                        listUser.Add(m);
                    }
                }
                listUser = listUser.Where(l => (l.UserName.Contains(txtUserName.Text))).ToList();
                List <MembershipUser> onlineUser = new List <MembershipUser>();
                foreach (MembershipUser u in listUser)
                {
                    if (u.IsOnline)
                    {
                        onlineUser.Add(u);
                    }
                }

                if (cbxOnlineUser.Checked)
                {
                    if (onlineUser.Count == 0)
                    {
                        lblNoRecord.Visible = true;
                        DataTable dt = new DataTable();
                        dt.Columns.Add("UserName");
                        dt.Columns.Add("Email");
                        dt.Columns.Add("IsApproved");
                        DataRow r = dt.NewRow();
                        r["UserName"]   = string.Empty;
                        r["Email"]      = string.Empty;
                        r["IsApproved"] = true;
                        dt.Rows.Add(r);
                        grvUser.DataSource = dt;
                        grvUser.DataBind();
                        grvUser.Rows[0].Visible = false;
                    }
                    else
                    {
                        lblNoRecord.Visible = false;
                        grvUser.DataSource  = onlineUser;
                        grvUser.DataBind();
                    }
                }
                else
                {
                    if (listUser.Count == 0)
                    {
                        lblNoRecord.Visible = true;
                        DataTable dt = new DataTable();
                        dt.Columns.Add("UserName");
                        dt.Columns.Add("Email");
                        dt.Columns.Add("IsApproved");
                        DataRow r = dt.NewRow();
                        r["UserName"]   = string.Empty;
                        r["Email"]      = string.Empty;
                        r["IsApproved"] = true;
                        dt.Rows.Add(r);

                        grvUser.DataSource = dt;
                        grvUser.DataBind();
                        grvUser.Rows[0].Visible = false;
                    }
                    else
                    {
                        lblNoRecord.Visible = false;
                        grvUser.DataSource  = listUser;
                        grvUser.DataBind();
                    }
                }


                LinkButton lBtn          = new LinkButton();
                LinkButton lBtnResetPass = new LinkButton();
                foreach (GridViewRow r in grvUser.Rows)
                {
                    lBtn          = (LinkButton)r.Cells[3].FindControl("lBtnLockUnLock");
                    lBtnResetPass = (LinkButton)r.Cells[4].FindControl("lBtnResetPassword");

                    if (r.Cells[2].Text == "False")
                    {
                        r.Cells[2].Text = string.Empty;
                        lBtn.Text       = GetResource("Approve");
                    }
                    else
                    {
                        r.Cells[2].Text = "√";
                        lBtn.Text       = GetResource("Disapprove");
                    }
                    if (r.Cells[0].Text == this.User.Identity.Name)
                    {
                        lBtn.Visible = false;
                    }

                    lBtnResetPass.Text = GetResource("ResetPassword");

                    lBtn.Attributes["onclick"]          = "javascript:return confirm('" + string.Format(GetResource("msDisapproveAccount"), lBtn.Text, Common.GetRowString(r.Cells[0].Text)) + "');";
                    lBtnResetPass.Attributes["onclick"] = "javascript:return confirm('" + string.Format(GetResource("msResetPassword"), Common.GetRowString(r.Cells[0].Text)) + "');";


                    UserPermission user = UserPermission.GetUserPermission(r.Cells[0].Text);
                    if (user != null)
                    {
                        DropDownList cbx = (DropDownList)r.Cells[5].FindControl("cbxPermission");
                        if (!string.IsNullOrEmpty(user.WebPermission))
                        {
                            cbx.SelectedValue = user.WebPermission;
                        }
                        else
                        {
                            cbx.SelectedIndex = 0;
                        }

                        CheckBox chkApp = (CheckBox)r.Cells[6].FindControl("cboAppPermission");
                        chkApp.Checked = user.AppPermission;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error Search", ex);
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert(\"" + GetJSMessage(GetResource("Title_Error"), ex.Message) + "\");", true);
            }
        }