コード例 #1
0
        private bool Btns_OnSave()
        {
            if (string.IsNullOrWhiteSpace(this.txtName.Text.Trim()) || string.IsNullOrWhiteSpace(this.txtUserName.Text.Trim()))
            {
                MessageBox.Show("未输入或输入无效", "提示");
                return(false);
            }
            Entity.Admin admin = null;
            string       temp  = new Random().Next(100000, 999999).ToString();

            if (this.btns.IsAdd)
            {
                var r = this._service.Add(admin = new Entity.Admin
                {
                    Name     = this.txtName.Text,
                    UserName = this.txtUserName.Text,
                    Password = temp
                });
                if (!r.Success)
                {
                    MessageBox.Show(r.Message);
                    return(false);
                }
                MessageBox.Show($"已新增管理员\r\n登录名:{admin.UserName}\r\n密码:{temp}");
            }
            else
            {
                this._service.Update(this.btns.DataID, new { Name = this.txtName.Text });
            }
            this.InitListView();
            return(true);
        }
コード例 #2
0
        public ActionResult Check(Entity.Admin admin)
        {
            var cres = svc.Check(admin.Name, admin.Pwd);

            if (cres.Code == 0)
            {
                Session["LoginInfo"] = cres.ExtData;
            }
            return(Json(cres));
        }
コード例 #3
0
        public ActionResult Login()
        {
            Ocean.Entity.Admin admin         = new Entity.Admin();
            string             adminName     = Request["username"];
            string             adminPassword = Request["password"];
            AdminLogger        adminLogger   = new AdminLogger();

            adminLogger.AdminName  = adminName;
            adminLogger.CreateDate = DateTime.Now;
            adminLogger.FromIP     = IpHelper.UserHostAddress;
            adminLogger.Module     = (int)AdminLoggerModuleEnum.Admin;

            if (adminName.Length == 0)
            {
                return(JsonMessage(false, "账号不能为空"));
            }

            if (adminPassword.Length == 0)
            {
                return(JsonMessage(false, "密码不能为空"));
            }

            admin = _adminService.GetAdminByName(adminName);

            if (admin == null)
            {
                adminLogger.Description = string.Format("账号不存在,登录失败");
                _adminLoggerService.Insert(adminLogger);
                return(JsonMessage(false, "账号不存在"));
            }

            if (admin.Password != Hash.MD5Encrypt(Hash.MD5Encrypt(adminPassword)))
            {
                adminLogger.Description = string.Format("密码错误,登录失败");
                _adminLoggerService.Insert(adminLogger);
                return(JsonMessage(false, "密码错误"));
            }
            else if (admin.State == 2)
            {
                adminLogger.Description = string.Format("账号已被冻结,登录失败");
                _adminLoggerService.Insert(adminLogger);
                return(JsonMessage(false, "账号已被冻结,请与管理员取得联系"));
            }
            else
            {
                adminLogger.Description = string.Format("成功登录后台管理系统");
                _adminLoggerService.Insert(adminLogger);
                AdminLogin.Instance.CreateAdminCookie(admin.Id, admin.Password, admin.PasswordKey, GlobalConfig.GetConfig()["SafeCode"]);
                admin.LastLoginDate = DateTime.Now;
                admin.LoginCount    = admin.LoginCount + 1;
                admin.LastLoginIP   = IpHelper.UserHostAddress;
                _adminService.Update(admin);
                return(JsonMessage(true, "登录成功"));
            }
        }
コード例 #4
0
ファイル: AdminList.cs プロジェクト: mndarren/Pizza
        private Admin MapEntityToAdmin(Entity.Admin tempAdmin)
        {
            var Admin = new Admin();

            if (null != tempAdmin)
            {
                Admin.ID            = tempAdmin.ID;
                Admin.Name          = tempAdmin.Name;
                Admin.StreetAddress = tempAdmin.StreetAddress;
                Admin.City          = tempAdmin.City;
                Admin.State         = tempAdmin.State;
                Admin.ZipCode       = tempAdmin.ZipCode;
            }

            return(Admin);
        }
コード例 #5
0
ファイル: AdminList.cs プロジェクト: mndarren/Pizza
        private Entity.Admin MapAdminToEntity(Admin admin)
        {
            var tempAdmin = new Entity.Admin();

            if (null != admin)
            {
                tempAdmin.ID            = admin.ID;
                tempAdmin.Name          = admin.Name;
                tempAdmin.StreetAddress = admin.StreetAddress;
                tempAdmin.City          = admin.City;
                tempAdmin.State         = admin.State;
                tempAdmin.ZipCode       = admin.ZipCode;
            }

            return(tempAdmin);
        }
コード例 #6
0
ファイル: AdminController.cs プロジェクト: dongguarrr/LvDu
        public ActionResult GetAdminList()
        {
            DboUtils db  = new DboUtils();
            String   sql = "select * from admin";
            DataSet  ds  = db.query(sql);

            List <Entity.Admin> list = new List <Entity.Admin>();

            foreach (DataRow mDr in ds.Tables[0].Rows)
            {
                Entity.Admin ad = new Entity.Admin();
                ad.username = mDr["username"].ToString();
                ad.pwd      = mDr["pwd"].ToString();
                list.Add(ad);
            }
            ViewBag.adminList = list;
            return(View());
        }
コード例 #7
0
ファイル: AdminController.cs プロジェクト: dongguarrr/LvDu
        private List <LvDu.Entity.Admin> getAdminListByName(String username)
        {
            DboUtils            db   = new DboUtils();
            String              sql  = "select * from admin where username='******'";
            DataSet             ds   = db.query(sql);
            List <Entity.Admin> list = new List <Entity.Admin>();

            foreach (DataRow mDr in ds.Tables[0].Rows)
            {
                Entity.Admin ad = new Entity.Admin()
                {
                    username = mDr["username"].ToString(),
                    pwd      = mDr["pwd"].ToString()
                };
                list.Add(ad);
            }
            return(list);
        }
コード例 #8
0
 public ActionResult LogOut(Entity.Admin admin)
 {
     Session["LoginInfo"] = null;
     return(RedirectToAction("Index"));
 }
コード例 #9
0
        private void CommandNewClick()
        {
            if (userNameText.Text.Trim() == "")
            {
                MessageBox.Show("Заповніть нікнейм користувача");
                return;
            }

            if (userFullNameText.Text.Trim() == "")
            {
                MessageBox.Show("Заповніть повне ім'я користувача");
                return;
            }

            if (rolesBox.SelectedValue.ToString() == "")
            {
                MessageBox.Show("Оберіть роль користувача");
                return;
            }
            string[] tempFullName = userFullNameText.Text.Trim().Split(' ');
            if (tempFullName.Count() < 2)
            {
                MessageBox.Show("Повне ім'я користувача повинне складатись що найменше з двох слів");
                return;
            }

            userPassword = "******";
            userName     = userNameText.Text.Trim();
            userFullName = userFullNameText.Text.Trim();

            string tempRole = rolesBox.SelectedValue.ToString();

            try{
                role = (from r in ceqacc.Role where r.role_name == tempRole select r.role_id).First().ToString();
            }
            catch
            {
                MessageBox.Show("Сталась системна помилка");
                return;
            }


            if ((from u in ceqacc.Login where u.name == userName select u.uid).Count() > 0)
            {
                MessageBox.Show("Користувач з таким ім'ям вже існує");
                return;
            }

            try
            {
                int newuID = (from u in ceqacc.Login select u.uid).ToArray().Max() + 1;

                if (Convert.ToInt32(role) == 0 || Convert.ToInt32(role) == 1)
                {
                    int          newID = (from u in ceqacc.Admin select u.admin_id).ToArray().Max() + 1;
                    Entity.Admin ad    = new Entity.Admin
                    {
                        admin_id  = newID,
                        full_name = userFullName
                    };


                    ceqacc.Admin.Add(ad);


                    Entity.Login lgg = new Entity.Login
                    {
                        uid      = newuID,
                        id       = newID,
                        password = userPassword,
                        role_id  = Convert.ToInt16(role),
                        name     = userName
                    };

                    ceqacc.Login.Add(lgg);
                    ceqacc.SaveChanges();

                    MessageBox.Show("Користувача успішно додано!");
                    this.Hide();
                }

                //else if(Convert.ToInt32(role) == 2)
                //{
                // int newID = (from u in ceqacc.Driver select u.id_driver).ToArray().Max() + 1;
                //   userBirthDate = new DateTime(2001, 1, 1);

                //Entity.Driver ads = new Entity.Driver
                //{
                // id_driver = newID,
                //last_name = userFullName,
                //};
                //      ceqacc.Driver.Add(ads);

                //Entity.Login lgs = new Entity.Login
                // {
                //        uid = newuID,
                //        id = newID,
                //        password = userPassword,
                //    role_id = Convert.ToInt16(role),
                //    name = userName
                //};


                //  ceqacc.Login.Add(lgs);
                //   ceqacc.SaveChanges();

                //   MessageBox.Show("Користувача успішно додано!");
                //   this.Hide();
                //}
            }
            catch
            {
                MessageBox.Show("Системна помилка при додаванні користувача");
            }
        }
コード例 #10
0
        public ActionResult AdminEditProvide()
        {
            if (string.IsNullOrWhiteSpace(RQuery["AdminId"]))
            {
                if (!base.HasPermission("admin", PermissionOperate.add))
                {
                    return(JsonMessage(false, "你没有添加管理员的权限"));
                }
            }
            else
            {
                if (!base.HasPermission("admin", PermissionOperate.edit))
                {
                    return(JsonMessage(false, "你没有编辑管理员的权限"));
                }
            }

            Ocean.Entity.Admin admin       = new Entity.Admin();
            string             oldPassword = string.Empty;

            if (!string.IsNullOrWhiteSpace(RQuery["AdminId"]))
            {
                admin       = _adminService.GetById(new Guid(RQuery["AdminId"]));
                oldPassword = admin.Password;
            }

            UpdateModel <Ocean.Entity.Admin>(admin);

            if (!string.IsNullOrWhiteSpace(RQuery["Password"]))
            {
                //判断密码有效性
                if (!StringValidate.IsNumCHA20(admin.Password))
                {
                    return(JsonMessage(false, "添加管理员失败,密码必须由6-20字母、数字组成"));
                }
            }

            if (RQuery["Password"] != RQuery["PasswordConfirm"])
            {
                return(JsonMessage(false, "两次输入密码不匹配"));
            }

            if (admin.PermissionOrganizationId == Guid.Empty || admin.PermissionOrganizationId == null)
            {
                return(JsonMessage(false, "请选择所属部门"));
            }

            if (admin.PermissionRoleId == Guid.Empty || admin.PermissionRoleId == null)
            {
                return(JsonMessage(false, "请选择所属角色"));
            }

            if (string.IsNullOrWhiteSpace(RQuery["AdminId"]))
            {
                admin.Password    = Hash.MD5Encrypt(Hash.MD5Encrypt(admin.Password));
                admin.PasswordKey = Guid.NewGuid().ToString().Substring(0, 8);
                admin.State       = 1;
                _adminService.Insert(admin);
                base.AddLog(string.Format("添加管理员[{0}]成功", admin.Name), AdminLoggerModuleEnum.Admin);
                return(JsonMessage(true, "添加管理员成功"));
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(RQuery["Password"]))
                {
                    admin.Password    = Hash.MD5Encrypt(Hash.MD5Encrypt(admin.Password));
                    admin.PasswordKey = Guid.NewGuid().ToString().Substring(0, 8);
                }
                else
                {
                    admin.Password = oldPassword;
                }

                _adminService.Update(admin);
                base.AddLog(string.Format("修改管理员[{0}]成功", admin.Name), AdminLoggerModuleEnum.Admin);
                return(JsonMessage(true, "修改管理员成功"));
            }
        }