Ejemplo n.º 1
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //获取所选行的id
            string id      = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            int    adminId = Convert.ToInt32(id);

            //MessageBox.Show(id);

            AdminUserDal dal = new AdminUserDal();
            DataTable    dt  = dal.GetById(adminId);
            DataRow      row = dt.Rows[0];

            txtName.Text = row["name"].ToString();
            txtPwd.Text  = row["pwd"].ToString();
            int typeid = Convert.ToInt32(row["typeId"]);

            if (typeid == 1)
            {
                comboBox2.SelectedIndex = 0;
            }
            else if (typeid == 2)
            {
                comboBox2.SelectedIndex = 1;
            }
        }
Ejemplo n.º 2
0
        //修改
        private void button2_Click(object sender, EventArgs e)
        {
            string id      = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            int    adminId = Convert.ToInt32(id);
            string name    = txtName.Text;
            string pwd     = txtPwd.Text;
            string type    = comboBox2.SelectedItem.ToString();
            int    typeId  = 0;

            typeId = type == "管理员" ? 1 : 2;

            AdminUserDal dal = new AdminUserDal();
            int          n   = dal.UpdateById(adminId, name, pwd, typeId);

            if (n <= 0)
            {
                MessageBox.Show("修改失败");
            }
            else
            {
                MessageBox.Show("修改成功");
                comboBox1.SelectedIndex = 0;
                comboBox1.SelectedIndex = 1;
            }
        }
Ejemplo n.º 3
0
        private void Main_Load(object sender, EventArgs e)
        {
            // menuStrip1.Hide();
            Login login = new Login();

            login.ShowDialog();
            //判断用户是否登入成功,不成功则直接退出系统
            if (!login.isOk)
            {
                Application.Exit();
            }
            //获取用户类型
            type   = login.type;
            userId = login.id;
            //判断用户类型,如果是收费员则限定某些功能不能使用

            AdminUserDal dal = new AdminUserDal();
            DataTable    dt  = dal.GetById(userId);
            DataRow      row = dt.Rows[0];

            userId = Convert.ToInt32(row["typeid"]);

            if (type == "收费员")
            {
                //menuStrip1.Hide();
                menuStrip1.Enabled            = false;
                proGetStardand.Enabled        = false;
                proGetMoneyManager.Enabled    = false;
                proCarPositionManager.Enabled = false;
            }
        }
Ejemplo n.º 4
0
 //登入
 private void btnLogin_Click(object sender, EventArgs e)
 {
     try
     {
         //获取用户的密码,姓名,类型
         string       name = txtName.Text;
         string       pwd  = txtPwd.Text;
         string       type = cmbList.SelectedItem.ToString();
         AdminUserDal dal  = new AdminUserDal();
         int          n    = dal.CheckLogin(name, pwd, type);
         DataTable    dt   = dal.GetUserId(name, pwd, type);
         DataRow      row  = dt.Rows[0];
         if (n > 0)
         {
             MessageBox.Show("登入成功");
             this.type = type;
             this.isOk = true;
             this.id   = Convert.ToInt32(row["id"].ToString());
             this.Close();
         }
         else
         {
             MessageBox.Show("登入失败");
             return;
         }
     }
     catch
     {
         MessageBox.Show("登入失败");
         return;
     }
 }
Ejemplo n.º 5
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            NCPEP.Dal.AdminUserDal dal = new AdminUserDal();
            dynamic adminUser          = null;
            string  username           = this.username.Value.Trim();
            string  password           = this.password.Value.Trim();
            string  randid             = this.randid.Value;
            string  CheckCode          = Session["CheckCode"] as string;

            if (randid.ToUpper().Equals(CheckCode.ToUpper()))
            {
                if (dal.CheckUserName(username))
                {
                    adminUser = dal.AdminUserLogin(username, password);
                    if (!string.IsNullOrEmpty(adminUser.AdminLogPass))
                    {
                        if (0 != adminUser.AdminState)
                        {
                            Session.Add("SuperAdminUserSession", adminUser);
                            dal.NumberLogin(adminUser.Id);
                            SysLogBll.Create("登陆页面", "登陆成功", adminUser.AdminName);
                            Response.Redirect("main.aspx");
                            //AddCookie(context, adminUser.Id.ToString());
                        }
                        else
                        {
                            //SysLogBll.Create("登陆页面", "账户禁用", adminUser.AdminName);
                            MessageBox.Show(this, "用于登录后台管理的账户已经被禁用");
                            return;
                        }
                    }
                    else
                    {
                        //SysLogBll.Create("登陆页面", "密码错误", adminUser.AdminName);

                        MessageBox.Show(this, "密码不正确请重新输入密码!");
                        return;
                    }
                }
                else
                {
                    //SysLogBll.Create("登陆页面", "用户名错误", adminUser.AdminName);

                    MessageBox.Show(this, "用户名不存在请联系上级单位!");
                    return;
                }
            }
            else
            {
                //SysLogBll.Create("登陆页面", "验证码错误", adminUser.AdminName);
                MessageBox.Show(this, "验证码错误请重新输入!");
                return;
            }
        }
Ejemplo n.º 6
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //获取用户选择的用户类型
            string  adminUserType = comboBox1.SelectedItem.ToString();
            TypeDal types         = new TypeDal();
            int     typeId        = types.GetTypeIdByName(adminUserType);
            //MessageBox.Show(typeId.ToString());
            //MessageBox.Show(comboBox1.SelectedValue.ToString());
            AdminUserDal admins = new AdminUserDal();
            DataTable    dt     = admins.GetByTypeId(typeId);

            if (dt.Rows.Count <= 0)
            {
                //MessageBox.Show("没有此类型的用户.....");
                return;
            }
            dataGridView1.DataSource = dt;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 查看用户是否有某个权限
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="controller">控制器</param>
        /// <param name="action">方法</param>
        /// <returns></returns>
        public bool IsValid(int userId, string controller, string action)
        {
            try
            {
                var model = AdminUserDal.GetModels(x => x.Id == userId).FirstOrDefault();
                if (model != null)
                {
                    var cache = CacheHelper.GetCache("SysOp" + model.Id);
                    List <T_SysOperations> list = new List <T_SysOperations>();
                    if (cache == null)
                    {
                        foreach (var role in model.T_UserRoles)
                        {
                            var tempList = BtnPermissionDal.GetSysOperationsByRoleId(role.Id);
                            list.AddRange(tempList);
                        }
                        CacheHelper.SetCache("SysOp" + model.Id, list);
                    }
                    else
                    {
                        list = (List <T_SysOperations>)cache;
                    }

                    if (list.Any(x => x.ContronllerName == controller & x.ActionName == action))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                log.Fatal(new LogContent("查询用户角色权限失败:", ex.Message));
                return(false);
            }
        }
Ejemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            string name   = txtName.Text;
            string pwd    = txtPwd.Text;
            int    typeId = comboBox2.SelectedIndex + 1;

            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(pwd))
            {
                MessageBox.Show("填入的信息不能为空哦~~~");
                return;
            }
            AdminUserDal dal    = new AdminUserDal();
            int          result = dal.Add(name, pwd, typeId);

            if (result > 0)
            {
                MessageBox.Show("添加成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("添加失败");
            }
        }
Ejemplo n.º 9
0
 //
 public AdminUserLogin()
 {
     type = new AdminTypeDal();
     dal  = new AdminUserDal();
 }
Ejemplo n.º 10
0
        public MsgResult InitData(List <T_SysOperations> list)
        {
            MsgResult result = new MsgResult();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //1 , 清除数据,先删关系表

                    int count = 0;

                    count = AdminUserDal.Clear(typeof(T_UserRoles).Name);
                    count = AdminUserDal.Clear(typeof(T_RolePermissions).Name);
                    count = AdminUserDal.Clear(typeof(T_OperatePermissions).Name);
                    count = AdminUserDal.Clear(typeof(T_MenuPermissions).Name);

                    count = AdminUserDal.Clear(typeof(T_AdminUsers).Name);
                    count = AdminUserDal.Clear(typeof(T_SysRoles).Name);
                    count = AdminUserDal.Clear(typeof(T_SysPermissions).Name);
                    count = AdminUserDal.Clear(typeof(T_SysOperations).Name);
                    //count = AdminUserDal.Clear(typeof(T_SysMenus).Name);



                    //2 , 初始化数据

                    //用户
                    T_AdminUsers adminUser = new T_AdminUsers();
                    adminUser.Phone      = "17512039375";
                    adminUser.CreateTime = DateTime.Now;
                    adminUser.CreateUser = 1;
                    adminUser.Salt       = "123456";
                    adminUser.PwdHush    = EncryptHelper.GetMd5("n5187698" + adminUser.Salt);
                    adminUser.Guid       = Guid.NewGuid().ToString("N");
                    var addUser = AdminUserDal.Add(adminUser);
                    AdminUserDal.SaveChanges();

                    //角色
                    T_SysRoles role = new T_SysRoles();
                    role.Guid        = Guid.NewGuid().ToString("N");
                    role.Name        = "超级管理员";
                    role.Description = "拥有所有的权限";
                    role.CreateUser  = adminUser.Id;
                    role.CreateTime  = DateTime.Now;

                    //操作权限
                    T_SysPermissions permission = new T_SysPermissions();
                    permission.Guid        = Guid.NewGuid().ToString("N");
                    permission.Type        = 1;
                    permission.Description = "操作权限";
                    permission.CreateUser  = adminUser.Id;
                    permission.CreateTime  = DateTime.Now;

                    //菜单权限
                    T_SysPermissions permissionNew = new T_SysPermissions();
                    permissionNew.Guid        = Guid.NewGuid().ToString("N");
                    permissionNew.Type        = 2;
                    permissionNew.Description = "菜单权限";
                    permissionNew.CreateUser  = adminUser.Id;
                    permissionNew.CreateTime  = DateTime.Now;



                    var addRole          = SysRoleDal.Add(role);
                    var addPermission    = SysPermissionDal.Add(permission);
                    var addPermissionNew = SysPermissionDal.Add(permissionNew);

                    //操作权限
                    SysOperationDal.BatchInsert(list);

                    var newList = SysOperationDal.GetModels(x => x.Id >= 0).ToList();
                    AdminUserDal.SaveChanges();


                    // 3 , 初始化关系
                    T_UserRoles userRole = new T_UserRoles();
                    userRole.UserId = addUser.Id;
                    userRole.RoleId = addRole.Id;


                    //用户角色
                    adminUser.T_UserRoles.Add(userRole);
                    AdminUserDal.SaveChanges();

                    //操作权限
                    T_RolePermissions permissions = new T_RolePermissions();
                    permissions.RoleId       = addRole.Id;
                    permissions.PermissionId = addPermission.Id;

                    //菜单权限
                    T_RolePermissions permissionsNew = new T_RolePermissions();
                    permissionsNew.RoleId       = addRole.Id;
                    permissionsNew.PermissionId = addPermissionNew.Id;


                    //角色权限
                    role.T_RolePermissions.Add(permissions);
                    role.T_RolePermissions.Add(permissionsNew);



                    List <T_OperatePermissions> addOperatelist = new List <T_OperatePermissions>();
                    for (int i = 0; i < newList.Count; i++)
                    {
                        T_OperatePermissions operate = new T_OperatePermissions();
                        operate.PermissionId = addPermission.Id;
                        operate.OperationId  = newList[i].Id;
                        addOperatelist.Add(operate);
                    }

                    //权限操作
                    permission.T_OperatePermissions = addOperatelist;


                    List <T_MenuPermissions> addMenuOperate = new List <T_MenuPermissions>();
                    List <T_SysMenus>        menuList       = new List <T_SysMenus>();
                    menuList = SysMenuDal.GetModels(X => X.Id >= 0).ToList();
                    for (int i = 0; i < menuList.Count; i++)
                    {
                        T_MenuPermissions menuPermission = new T_MenuPermissions();
                        menuPermission.MenuId       = menuList[i].Id;
                        menuPermission.PermissionId = addPermissionNew.Id;
                        addMenuOperate.Add(menuPermission);
                    }

                    permission.T_MenuPermissions = addMenuOperate;
                    AdminUserDal.SaveChanges();

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(null);
        }