public ActionResult AddNewEmployeeManage(EmployeeModel model)
 {
     if (ModelState.IsValid)
     {
         if (EmployeeModel.SaveNewEmployee(model))
         {
             ViewBag.Title = "添加成功";
             return View("SuccessEmployee");
         }
         Response.Write("<script language='JavaScript'>alert('添加新人员失败.');history.go(-1);</script>");
     }
     var listService = new ListService();
     //性别
     ViewData["Sex"] = listService.GetSexTypeList();
     //角色类型
     ViewData["Role"] = listService.GetRoleTypeList();
     ViewBag.Title = "添加新人员的信息";
     return View(model);
 }
        public ActionResult AddNewEmployeeManage()
        {
            if (Session["CheckFeed"] == null || !(bool) Session["AddSystemManage"] ||
                !(bool) Session["CheckSystemManage"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            //性别
            ViewData["Sex"] = ListService.GetSexTypeList();
            //角色类型
            ViewData["Role"] = ListService.GetRoleTypeList();
            var employeeModel = new EmployeeModel();
            var roleType = new List<long>();
            const long rolefirst = 0;
            roleType.Add(rolefirst);
            employeeModel.RoleTypeId = roleType;
            ViewBag.Title = "添加新人员的信息";
            return View(employeeModel);
        }
Exemplo n.º 3
0
 public EmployeeModel FindEmployeeById(long id)
 {
     var employeeService = new EmployeeService();
     var roleService = new RoleService();
     try
     {
         List<role> roles = roleService.FindByEmployeeId(id);
         employee employee = employeeService.Find(id);
         var employeeModel = new EmployeeModel
                                 {
                                     EmployeeId = employee.Id,
                                     EmployeeNumber = employee.Number,
                                     EmployeeName = employee.Name,
                                     Rfid = employee.RFID,
                                     Sex = employee.Sex,
                                     ConfirmPassWd = employee.Password,
                                     PassWd = employee.Password,
                                     Logon = employee.LogOn,
                                     state=employee.State,
                                     Birthday = Convert.ToDateTime(employee.Birthday),
                                     Memo = employee.Memo
                                 };
         List<long> roleType = roles.Select(role => role.role_type.Id).ToList();
         employeeModel.RoleTypeId = roleType;
         return employeeModel;
     }
     catch (Exception)
     {
         return null;
     }
 }
Exemplo n.º 4
0
        public bool SaveNewEmployee(EmployeeModel model)
        {
            var employeeService = new EmployeeService();
            var roleService = new RoleService();
            try
            {
                //SHA412加密
                string result = "";
                SHA512 sha512 = new SHA512Managed();
                byte[] s = sha512.ComputeHash(Encoding.UTF8.GetBytes("123456"));
                for (int i = 0; i < s.Length; i++)
                {
                    result += s[i].ToString("X2");
                }
                sha512.Clear();

                //添加人员信息
                var newemployee = new employee
                                      {
                                          Name = model.EmployeeName,
                                          Number = model.EmployeeNumber,
                                          RFID = model.Rfid,
                                          Sex = model.Sex,
                                          Password = result.ToLower(),
                                          LogOn = true,
                                          Birthday = Convert.ToDateTime(model.Birthday),
                                          Memo = model.Memo,
                                          State = true
                                      };
                employeeService.Insert(newemployee);

                var roleFlag = new List<long>(); //用来存储角色id,并判断角色id是否重复
                //添加角色信息
                foreach (long t in model.RoleTypeId)
                {
                    //用来判断model中的roleid是否跟roleFlag中的重复
                    int flag = 0;
                    foreach (long l in roleFlag)
                    {
                        if (l == t)
                        {
                            flag = 1;
                        }
                    }
                    //model中的roleid跟roleFlag中的不重复
                    if (flag == 0)
                    {
                        roleFlag.Add(t);
                        var role = new role
                                       {
                                           EmployeeId = employeeService.FindByRfid(model.Rfid).Id,
                                           RoleId = t
                                       };
                        roleService.Insert(role);
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
Exemplo n.º 5
0
        public bool SaveModifyEmployee(EmployeeModel model)
        {
            var employeeService = new EmployeeService();
            var roleService = new RoleService();
            string result = "";
            try
            {
                //SHA512加密
                if (model.ConfirmPassWd != null)
                {
                    SHA512 sha512 = new SHA512Managed();
                    byte[] s = sha512.ComputeHash(Encoding.UTF8.GetBytes(model.ConfirmPassWd));
                    for (int i = 0; i < s.Length; i++)
                    {
                        result += s[i].ToString("X2");
                    }
                    sha512.Clear();
                }

                //修改人员信息
                employee newemployee = employeeService.Find(model.EmployeeId);
                newemployee.Name = model.EmployeeName;
                newemployee.Number = model.EmployeeNumber;
                newemployee.RFID = model.Rfid;
                newemployee.LogOn = model.Logon;
                newemployee.Sex = model.Sex;
                newemployee.State = model.state;
                newemployee.Birthday = Convert.ToDateTime(model.Birthday);
                newemployee.Memo = model.Memo;
                if (model.ConfirmPassWd != null)
                {
                    newemployee.Password = result.ToLower();
                }
                employeeService.Update(newemployee);

                //修改角色信息
                //如果增加的角色类型数据库中没有,则插入该角色
                foreach (long t in model.RoleTypeId)
                {
                    List<role> roles = roleService.FindByEmployeeId(model.EmployeeId);
                    int flag = 1;
                    foreach (role role in roles)
                    {
                        if (t == role.RoleId)
                        {
                            flag = 0;
                        }
                    }
                    if (flag == 1)
                    {
                        var role = new role
                                       {
                                           EmployeeId = model.EmployeeId,
                                           RoleId = t
                                       };
                        roleService.Insert(role);
                    }
                }

                //   如果删除了一个角色类型,则在数据库删除对应的角色类型
                List<role> anotherroles = roleService.FindByEmployeeId(model.EmployeeId);
                foreach (role anotherrole in anotherroles)
                {
                    int flag = 1;
                    long delete = anotherrole.RoleId;
                    for (int j = 0; j < model.RoleTypeId.Count; j++)
                    {
                        if (anotherrole.RoleId == model.RoleTypeId[j])
                        {
                            flag = 0;
                        }
                    }
                    if (flag == 1)
                    {
                        roleService = new RoleService();
                        roleService.Delete(
                            roleService.Find(roleService.FindByEmployeeIdAndRoleId(model.EmployeeId, delete).Id));
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
Exemplo n.º 6
0
 public PagedList<EmployeeModel> GetEmployeePagedList(int pageIndex, int pageSize)
 {
     var employeeService = new EmployeeService();
     IOrderedEnumerable<employee> employees = employeeService.FindAll().OrderBy(m => m.Name);
     var employeeModels = new List<EmployeeModel>();
     foreach (employee employee in employees)
     {
         var employeeModel = new EmployeeModel
                                 {
                                     EmployeeId = employee.Id,
                                     EmployeeNumber = employee.Number,
                                     EmployeeName = employee.Name,
                                     Rfid = employee.RFID,
                                     Sex = employee.Sex,
                                     Birthday = Convert.ToDateTime(employee.Birthday),
                                     Memo = employee.Memo
                                 };
         employeeModels.Add(employeeModel);
     }
     int count = (pageIndex - 1)*pageSize;
     return new PagedList<EmployeeModel>(employeeModels.Skip(count).Take(pageSize), pageIndex, pageSize,
                                         employeeModels.Count());
 }
        public ActionResult CheckEmployeeManage(long id)
        {
            if (Session["CheckFeed"] == null || !(bool) Session["CheckSystemManage"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            var employeeService = new EmployeeService();
            var roleService = new RoleService();
            var listService = new ListService();
            List<role> roles = roleService.FindByEmployeeId(id);
            employee employee = employeeService.Find(id);
            var employeeModel = new EmployeeModel
                                    {
                                        EmployeeId = employee.Id,
                                        EmployeeNumber = employee.Number,
                                        EmployeeName = employee.Name,
                                        Rfid = employee.RFID,
                                        Sex = employee.Sex,
                                        ConfirmPassWd = employee.Password,
                                        PassWd = employee.Password,
                                        Logon = employee.LogOn,
                                        Birthday = Convert.ToDateTime(employee.Birthday),
                                        Memo = employee.Memo
                                    };
            List<long> roleType = roles.Select(role => role.role_type.Id).ToList();
            employeeModel.RoleTypeId = roleType;
            ViewData["Role"] = listService.GetRoleTypeList();
            ViewData["Sex"] = listService.GetSexTypeList();
            ViewBag.Title = "查看人员信息";
            return View("AddNewEmployeeManage", employeeModel);
        }
 public ActionResult ModifyEmployeeManage(EmployeeModel model)
 {
     if (!Request.IsAjaxRequest())
     {
         return null;
     }
     if (EmployeeModel.SaveModifyEmployee(model))
     {
         ViewBag.Title = "修改成功";
         return PartialView("SuccessEmployee");
     }
     ViewBag.Title = "修改失败";
     return PartialView("SuccessEmployee");
 }
        public ActionResult EmployeeManage(int pageIndex = 1)
        {
            if (Session["CheckFeed"] == null || !(bool) Session["CheckSystemManage"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            const int pageSize = 25;
            var employeeModel = new EmployeeModel();
            PagedList<EmployeeModel> infoPagerList = employeeModel.GetEmployeePagedList(pageIndex, pageSize);

            if (Request.IsAjaxRequest())
            {
                return PartialView("UCJqEmployeeList", infoPagerList);
            }

            return View(infoPagerList);
        }