/// <summary>
        ///     更新任务的人员
        /// </summary>
        /// <param name="task">任务类</param>
        /// <param name="numbers">员工名字的字符串数组</param>
        public void UpdateByNumber(task task, string[] numbers)
        {
            int oldLen = task.task_employee.Count;
            int newLen = numbers.Length;
            int leastLength = oldLen < newLen ? oldLen : newLen;

            var employeeService = new EmployeeService();
            var taskEmployeeService = new TaskEmployeeService();

            for (int i = 0; i < leastLength; i++)
            {
                task_employee updateitem = taskEmployeeService.FindByTaskId(task.Id)[i];
                updateitem.EmployeeId = employeeService.FindByNumber(numbers[i]).Id;
                taskEmployeeService.Update(updateitem);
            }

            for (int i = leastLength; i < oldLen; i++)
            {
                taskEmployeeService.Delete(taskEmployeeService.Find(task.task_employee.ElementAt(i).Id));
            }

            for (int i = leastLength; i < newLen; i++)
            {
                taskEmployeeService.Insert(new task_employee
                                               {
                                                   TaskId = task.Id,
                                                   EmployeeId = employeeService.FindByNumber(numbers[i]).Id
                                               });
            }
        }
        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);
        }
예제 #3
0
        /// <summary>
        ///     查看喂食信息
        /// </summary>
        /// <param name="employeename">选中喂食信息的喂食人员</param>
        /// <param name="taskNumber">喂食任务编号</param>
        /// <param name="time">喂食时间</param>
        /// <returns></returns>
        public FeedInfo CheckFeedInfo(string employeename, string taskNumber, DateTime time)
        {
            var checkFeedInfo = new FeedInfo();
            var feedService = new FeedService();
            var fodderTakeService = new FodderTakeService();
            var employeeService = new EmployeeService();
            //var taskService = new TaskService();
            checkFeedInfo.TaskNumber = taskNumber;
            checkFeedInfo.EmployeeName = employeename;
            checkFeedInfo.TakeDetail = new List<FodderTakeDetail>();
            checkFeedInfo.FeedPig = new List<FeedInfoDetail>();
            employee firstOrDefault = employeeService.FindByName(employeename).FirstOrDefault();
            if (firstOrDefault != null)
                foreach (fodder_take fodderTake in fodderTakeService.FindByEmployeeId(firstOrDefault.Id))
                    //task firstOrDefault = taskService.FindByTaskNumber(taskNumber);
                    //if (firstOrDefault != null)
                    //foreach (fodder_take fodderTake in fodderTakeService.FindByTaskId(firstOrDefault.Id))
                {
                    string num = fodderTake.task.TaskNumber;
                    if (!time.Date.Equals(fodderTake.Time.Date) && num != taskNumber) continue;
                    checkFeedInfo.TakeDetail.Add(new FodderTakeDetail
                                                     {
                                                         FodderType = fodderTake.fodder_type.Name,
                                                         Quantity = fodderTake.Quantity,
                                                         Unit = fodderTake.unit.Name,
                                                         TakeTime = fodderTake.Time
                                                     });
                }

            employee orDefault = employeeService.FindByName(employeename).FirstOrDefault();
            if (orDefault != null)
                foreach (feed feedItem in feedService.FindByEmployeeId(orDefault.Id))
                {
                    string num = feedItem.task.TaskNumber;
                    if (!time.Date.Equals(feedItem.Time.Date) && num != taskNumber) continue;
                    checkFeedInfo.FeedPig.Add(new FeedInfoDetail
                                                  {
                                                      DetailTime = feedItem.Time,
                                                      PigHouse =
                                                          feedItem.pigsty.pig_house.pig_house_type.Name +
                                                          feedItem.pigsty.pig_house.Number,
                                                      Pigsty = feedItem.pigsty.Number + string.Empty
                                                      //FodderType = feedItem.fodder_type.Name,
                                                      //Quantity = feedItem.Quality,
                                                      //Unit = feedItem.unit.Name
                                                  });
                    checkFeedInfo.Meno = feedItem.Memo;
                }
            return checkFeedInfo;
        }
예제 #4
0
 /// <summary>
 /// 删除对应的喂食信息
 /// </summary>
 /// <param name="employeename">喂食人员姓名</param>
 /// <param name="taskNumber">任务编号</param>
 /// <param name="time">喂食时间</param>
 /// <returns></returns>
 public bool DelFeed(string employeename, string taskNumber, DateTime time)
 {
     var feedService = new FeedService();
     var employeeService = new EmployeeService();
     employee orDefault = employeeService.FindByName(employeename).FirstOrDefault();
     if (orDefault != null)
         foreach (feed feedItem in feedService.FindByEmployeeId(orDefault.Id))
         {
             string num = feedItem.task.TaskNumber;
             if (!time.Date.Equals(feedItem.Time.Date) && num == taskNumber) continue;
             feedService.Delete(feedService.Find(feedItem.Id));
         }
     else
         return false;
     return true;
 }
예제 #5
0
 /// <summary>
 ///     删除饲料领取信息
 /// </summary>
 /// <param name="employeename">领取人员</param>
 /// <param name="taskNumber">任务编号</param>
 /// <param name="time">领取时间</param>
 /// <returns></returns>
 public bool DelFodderTake(string employeename, string taskNumber, DateTime time)
 {
     var fodderTakeService = new FodderTakeService();
     var employeeService = new EmployeeService();
     // var taskService = new TaskService();
     employee firstOrDefault = employeeService.FindByName(employeename).FirstOrDefault();
     //var firstOrDefault = taskService.FindByTaskNumber(taskNumber);
     if (firstOrDefault == null)
     {
         return false;
     }
     for (int i = 0; i < fodderTakeService.FindByEmployeeId(firstOrDefault.Id).Count; i++)
     {
         fodder_take fodderTake = fodderTakeService.FindByEmployeeId(firstOrDefault.Id)[i];
         string num = fodderTake.task.TaskNumber;
         if (!time.Date.Equals(fodderTake.Time.Date) && num == taskNumber) continue;
         fodderTakeService = new FodderTakeService();
         fodderTakeService.Delete(fodderTakeService.Find(fodderTake.Id));
     }
     return true;
 }
예제 #6
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;
     }
 }
예제 #7
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;
        }
예제 #8
0
        /// <summary>
        ///     新建喂食信息
        /// </summary>
        /// <param name="newFeedInfo"></param>
        /// y
        /// <returns></returns>
        public bool CreateFeedInfo(FeedInfo newFeedInfo)
        {
            var employeeService = new EmployeeService();
            var feedService = new FeedService();
            var fodderTakeService = new FodderTakeService();
            var taskService = new TaskService();
            var fodderTypeService = new FodderTypeService();
            var unitService = new UnitService();
            var taskStatusTypeService = new TaskStatusTypeService();
            long taskId = long.Parse(TaskNumber);
            foreach (FodderTakeDetail takedetail in newFeedInfo.TakeDetail)
            {
                employee firstOrDefault = employeeService.Find(long.Parse(newFeedInfo.EmployeeName));
                if (firstOrDefault != null)
                {
                    var take = new fodder_take
                                   {
                                       TaskId = taskId,
                                       EmployeeId = firstOrDefault.Id,
                                       //FodderTypeId = fodderTypeService.Find(long.Parse(takedetail.FodderType)).Id,
                                       //Quantity = takedetail.Quantity,
                                       //UnitId = unitService.Find(long.Parse(takedetail.Unit)).Id,
                                       Time = takedetail.TakeTime
                                   };
                    fodderTakeService.Insert(take);
                }
            }

            foreach (FeedInfoDetail feedPigDetail in FeedPig)
            {
                var feedinfo = new feed {TaskId = taskId};
                employee firstOrDefault = employeeService.Find(long.Parse(newFeedInfo.EmployeeName));
                if (firstOrDefault != null)
                    feedinfo.EmployeeId = firstOrDefault.Id;
                feedinfo.PigstyId = long.Parse(feedPigDetail.Pigsty);
                //feedinfo.FodderTypeId = long.Parse(feedPigDetail.FodderType);
                //feedinfo.Quality = feedPigDetail.Quantity;
                //feedinfo.UnitId = long.Parse(feedPigDetail.Unit);
                feedinfo.Memo = newFeedInfo.Meno;
                feedinfo.Time = feedPigDetail.DetailTime;
                feedService.Insert(feedinfo);
            }
            task_status_type taskStatusType = taskStatusTypeService.FindByName("正在进行");
            task task = taskService.Find(long.Parse(newFeedInfo.TaskNumber));
            if (taskStatusType != null && task != null)
            {
                task.TaskStatusId = taskStatusType.Id;
                taskService.Update(task);
            }

            return true;
        }
예제 #9
0
        /// <summary>
        ///     喂食信息管理列表
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Info> GetFeedInfoList()
        {
            var feedService = new FeedService();
            var taskService = new TaskService();
            var employeeService = new EmployeeService();
            string taskNumber = "";
            task task = null;
            var feedInfoList = new List<Info>();
            var employeeIds = new HashSet<long>();
            foreach (feed employeeId in feedService.FindAll())
            {
                employeeIds.Add(employeeId.EmployeeId);
            }

            foreach (long employeeId in employeeIds)
            {
                feed item = feedService.FindByEmployeeId(employeeId).OrderByDescending(m => m.Time).FirstOrDefault();
                if (item != null) task = taskService.Find(item.TaskId);
                taskNumber = task != null ? task.TaskNumber : "";

                if (item != null)
                {
                    feedInfoList.Add(new Info
                                         {
                                             TaskNumber = taskNumber,
                                             EmployeeName =
                                                 employeeService.Find(
                                                     item.
                                                         EmployeeId).Name,
                                             Time = item.Time,
                                             Meno = item.Memo
                                         });
                    foreach (
                        feed feedInfoitem in feedService.FindByEmployeeId(employeeId).OrderByDescending(m => m.Time))
                    {
                        task = taskService.Find(feedInfoitem.TaskId);
                        taskNumber = task != null ? task.TaskNumber : "";

                        if (item.Time.Date.Equals(feedInfoitem.Time.Date) && item.TaskId == feedInfoitem.TaskId)
                            continue;
                        feedInfoList.Add(new Info
                                             {
                                                 TaskNumber = taskNumber,
                                                 EmployeeName =
                                                     employeeService.Find(
                                                         feedInfoitem.
                                                             EmployeeId).Name,
                                                 Time = feedInfoitem.Time,
                                                 Meno = feedInfoitem.Memo
                                             });
                        item = feedInfoitem;
                    }
                }
            }

            return feedInfoList.OrderByDescending(m => m.Time);
        }
예제 #10
0
        public bool NewInspectTask(InspectTask newTask, long taskTypeId, string createEmployee)
        {
            var employeeService = new EmployeeService();

            var task = new task
                           {
                               TaskNumber = newTask.TaskNumber,
                               StartTime = newTask.StartTime,
                               EndTime = newTask.EndTime,
                               CreateTime = DateTime.Now,
                               CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id,
                               TaskStatusId = 1,
                               TaskTypeId = taskTypeId,
                               Memo = newTask.Memo
                           };

            foreach (string employeeNumber in newTask.EmployeeNumber.Split(','))
            {
                task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id});
            }

            foreach (string pigHouse in newTask.PigHouseId.Split(','))
            {
                task.task_pighouse.Add(new task_pighouse
                                           {
                                               PigHouseId = long.Parse(pigHouse)
                                           });
            }

            foreach (
                task_interval_cycle taskIntervalCycle in
                    newTask.InspectTaskCycle.Select(taskcycle => new task_interval_cycle
                                                                     {
                                                                         FirstExecuteDate = taskcycle.FirstExecuteDate,
                                                                         CycleDays = taskcycle.CycleDays
                                                                     }))
            {
                task.task_interval_cycle.Add(taskIntervalCycle);
            }
            var taskService = new TaskService();
            taskService.Insert(task);

            return true;
        }
예제 #11
0
        public string GetEmployeeByRole(int id)
        {
            string role;
            switch (id)
            {
                case 1:
                    role = "饲养员";
                    break;
                case 2:
                    role = "防疫员";
                    break;
                case 3:
                    role = "转栏员";
                    break;
                case 4:
                    role = "巡查员";
                    break;
                case 5:
                    role = "兽医";
                    break;
                case 6:
                    role = "销售员";
                    break;
                case 7:
                    role = "添加生猪员工";
                    break;
                case 8:
                    role = "淘汰生猪负责员";
                    break;
                case 9:
                    role = "死亡生猪处理员";
                    break;
                default:
                    role = "";
                    break;
            }
            var employeeService = new EmployeeService();

            try
            {
                return employeeService.GetEmployeeNumAndName(new RoleTypeService().FindByName(role).Id);
            }
            catch (Exception)
            {
                return null;
            }
        }
예제 #12
0
 //员工RFID
 public bool EmployeeRfidCompare(string rfid)
 {
     var employeeService = new EmployeeService();
     if (employeeService.FindByRfid(rfid) != null)
     {
         return false;
     }
     return true;
 }
예제 #13
0
        public ActionResult Catalog()
        {
            //若未登录,则不初始化左边的菜单栏
            if (!User.Identity.IsAuthenticated)
            {
                return null;
            }
            //若session已有记录,则不再重复获得各个权限的session
            if (Session["CheckFeed"] != null)
            {
                return PartialView();
            }
            employee employee = new EmployeeService().FindByNumber(User.Identity.Name.Split('|')[0]);
            if (employee == null)
            {
                return null;
            }
            List<role> roleList = new RoleService().FindByEmployeeId(employee.Id);

            var roleAuthorityService = new RoleAuthorityService();
            List<List<role_authority>> list =
                roleList.Select(role => roleAuthorityService.FindByRoleTypeId(role.RoleId)).ToList();

            //增加权限
            Session["AddFeed"] = roleAuthorityService.GetAddAuthority(list, "Feed");
            Session["AddPreventionDisease"] = roleAuthorityService.GetAddAuthority(list,
                                                                                   "PreventionDisease");
            Session["AddTransferPigsty"] = roleAuthorityService.GetAddAuthority(list, "TransferPigsty");
            Session["AddInspect"] = roleAuthorityService.GetAddAuthority(list, "Inspect");
            Session["AddCure"] = roleAuthorityService.GetAddAuthority(list, "Cure");
            Session["AddSale"] = roleAuthorityService.GetAddAuthority(list, "Sale");
            Session["AddAddPig"] = roleAuthorityService.GetAddAuthority(list, "AddPig");
            Session["AddDataImport"] = roleAuthorityService.GetAddAuthority(list, "DataImport");
            Session["AddAddNewPig"] = roleAuthorityService.GetAddAuthority(list, "AddNewPig");
            Session["AddPigData"] = roleAuthorityService.GetAddAuthority(list, "PigData");
            Session["AddFeedInfo"] = roleAuthorityService.GetAddAuthority(list, "FeedInfo");
            Session["AddPreventionDiseaseInfo"] = roleAuthorityService.GetAddAuthority(list,
                                                                                       "PreventionDiseaseInfo");
            Session["AddTransferPigstyInfo"] = roleAuthorityService.GetAddAuthority(list,
                                                                                    "TransferPigstyInfo");
            Session["AddInspectInfo"] = roleAuthorityService.GetAddAuthority(list, "InspectInfo");
            Session["AddCureInfo"] = roleAuthorityService.GetAddAuthority(list, "CureInfo");
            Session["AddSalesInfo"] = roleAuthorityService.GetAddAuthority(list, "SalesInfo");
            Session["AddFodderTake"] = roleAuthorityService.GetAddAuthority(list, "FodderTake");
            Session["AddMedicineTake"] = roleAuthorityService.GetAddAuthority(list, "MedicineTake");
            Session["AddSystemManage"] = roleAuthorityService.GetAddAuthority(list, "SystemManage");
            Session["AddEliminateTask"] = roleAuthorityService.GetAddAuthority(list, "EliminateTask");
            Session["AddDeadTask"] = roleAuthorityService.GetAddAuthority(list, "DeadTask");
            Session["AddEliminateInfo"] = roleAuthorityService.GetAddAuthority(list, "EliminateInfo");
            Session["AddDeadInfo"] = roleAuthorityService.GetAddAuthority(list, "DeadInfo");

            //删除权限
            Session["DelFeed"] = roleAuthorityService.GetDelAuthority(list, "Feed");
            Session["DelPreventionDisease"] = roleAuthorityService.GetDelAuthority(list,
                                                                                   "PreventionDisease");
            Session["DelTransferPigsty"] = roleAuthorityService.GetDelAuthority(list, "TransferPigsty");
            Session["DelInspect"] = roleAuthorityService.GetDelAuthority(list, "Inspect");
            Session["DelCure"] = roleAuthorityService.GetDelAuthority(list, "Cure");
            Session["DelSale"] = roleAuthorityService.GetDelAuthority(list, "Sale");
            Session["DelAddPig"] = roleAuthorityService.GetDelAuthority(list, "AddPig");
            Session["DelDataImport"] = roleAuthorityService.GetDelAuthority(list, "DataImport");
            Session["DelAddNewPig"] = roleAuthorityService.GetDelAuthority(list, "AddNewPig");
            Session["DelPigData"] = roleAuthorityService.GetDelAuthority(list, "PigData");
            Session["DelFeedInfo"] = roleAuthorityService.GetDelAuthority(list, "FeedInfo");
            Session["DelPreventionDiseaseInfo"] = roleAuthorityService.GetDelAuthority(list,
                                                                                       "PreventionDiseaseInfo");
            Session["DelTransferPigstyInfo"] = roleAuthorityService.GetDelAuthority(list,
                                                                                    "TransferPigstyInfo");
            Session["DelInspectInfo"] = roleAuthorityService.GetDelAuthority(list, "InspectInfo");
            Session["DelCureInfo"] = roleAuthorityService.GetDelAuthority(list, "CureInfo");
            Session["DelSalesInfo"] = roleAuthorityService.GetDelAuthority(list, "SalesInfo");
            Session["DelFodderTake"] = roleAuthorityService.GetDelAuthority(list, "FodderTake");
            Session["DelMedicineTake"] = roleAuthorityService.GetDelAuthority(list, "MedicineTake");
            Session["DelSystemManage"] = roleAuthorityService.GetDelAuthority(list, "SystemManage");
            Session["DelEliminateTask"] = roleAuthorityService.GetDelAuthority(list, "EliminateTask");
            Session["DelDeadTask"] = roleAuthorityService.GetDelAuthority(list, "DeadTask");
            Session["DelEliminateInfo"] = roleAuthorityService.GetDelAuthority(list, "EliminateInfo");
            Session["DelDeadInfo"] = roleAuthorityService.GetDelAuthority(list, "DeadInfo");

            //查看权限,若无查看权限,则默认增删查改权限都没有
            Session["CheckFeed"] = roleAuthorityService.GetCheckAuthority(list, "Feed");
            Session["CheckPreventionDisease"] = roleAuthorityService.GetCheckAuthority(list,
                                                                                       "PreventionDisease");
            Session["CheckTransferPigsty"] = roleAuthorityService.GetCheckAuthority(list, "TransferPigsty");
            Session["CheckInspect"] = roleAuthorityService.GetCheckAuthority(list, "Inspect");
            Session["CheckCure"] = roleAuthorityService.GetCheckAuthority(list, "Cure");
            Session["CheckSale"] = roleAuthorityService.GetCheckAuthority(list, "Sale");
            Session["CheckAddPig"] = roleAuthorityService.GetCheckAuthority(list, "AddPig");
            Session["CheckDataImport"] = roleAuthorityService.GetCheckAuthority(list, "DataImport");
            Session["CheckAddNewPig"] = roleAuthorityService.GetCheckAuthority(list, "AddNewPig");
            Session["CheckPigData"] = roleAuthorityService.GetCheckAuthority(list, "PigData");
            Session["CheckFeedInfo"] = roleAuthorityService.GetCheckAuthority(list, "FeedInfo");
            Session["CheckPreventionDiseaseInfo"] = roleAuthorityService.GetCheckAuthority(list,
                                                                                           "PreventionDiseaseInfo");
            Session["CheckTransferPigstyInfo"] = roleAuthorityService.GetCheckAuthority(list,
                                                                                        "TransferPigstyInfo");
            Session["CheckInspectInfo"] = roleAuthorityService.GetCheckAuthority(list, "InspectInfo");
            Session["CheckCureInfo"] = roleAuthorityService.GetCheckAuthority(list, "CureInfo");
            Session["CheckSalesInfo"] = roleAuthorityService.GetCheckAuthority(list, "SalesInfo");
            Session["CheckFodderTake"] = roleAuthorityService.GetCheckAuthority(list, "FodderTake");
            Session["CheckMedicineTake"] = roleAuthorityService.GetCheckAuthority(list, "MedicineTake");
            Session["CheckSystemManage"] = roleAuthorityService.GetCheckAuthority(list, "SystemManage");
            Session["CheckEliminateTask"] = roleAuthorityService.GetCheckAuthority(list, "EliminateTask");
            Session["CheckDeadTask"] = roleAuthorityService.GetCheckAuthority(list, "DeadTask");
            Session["CheckEliminateInfo"] = roleAuthorityService.GetCheckAuthority(list, "EliminateInfo");
            Session["CheckDeadInfo"] = roleAuthorityService.GetCheckAuthority(list, "DeadInfo");

            //编辑权限
            Session["EditFeed"] = roleAuthorityService.GetEditAuthority(list, "Feed");
            Session["EditPreventionDisease"] = roleAuthorityService.GetEditAuthority(list,
                                                                                     "PreventionDisease");
            Session["EditTransferPigsty"] = roleAuthorityService.GetEditAuthority(list, "TransferPigsty");
            Session["EditInspect"] = roleAuthorityService.GetEditAuthority(list, "Inspect");
            Session["EditCure"] = roleAuthorityService.GetEditAuthority(list, "Cure");
            Session["EditSale"] = roleAuthorityService.GetEditAuthority(list, "Sale");
            Session["EditAddPig"] = roleAuthorityService.GetEditAuthority(list, "AddPig");
            Session["EditDataImport"] = roleAuthorityService.GetEditAuthority(list, "DataImport");
            Session["EditAddNewPig"] = roleAuthorityService.GetEditAuthority(list, "AddNewPig");
            Session["EditPigData"] = roleAuthorityService.GetEditAuthority(list, "PigData");
            Session["EditFeedInfo"] = roleAuthorityService.GetEditAuthority(list, "FeedInfo");
            Session["EditPreventionDiseaseInfo"] = roleAuthorityService.GetEditAuthority(list,
                                                                                         "PreventionDiseaseInfo");
            Session["EditTransferPigstyInfo"] = roleAuthorityService.GetEditAuthority(list,
                                                                                      "TransferPigstyInfo");
            Session["EditInspectInfo"] = roleAuthorityService.GetEditAuthority(list, "InspectInfo");
            Session["EditCureInfo"] = roleAuthorityService.GetEditAuthority(list, "CureInfo");
            Session["EditSalesInfo"] = roleAuthorityService.GetEditAuthority(list, "SalesInfo");
            Session["EditFodderTake"] = roleAuthorityService.GetEditAuthority(list, "FodderTake");
            Session["EditMedicineTake"] = roleAuthorityService.GetEditAuthority(list, "MedicineTake");
            Session["EditSystemManage"] = roleAuthorityService.GetEditAuthority(list, "SystemManage");
            Session["EditEliminateTask"] = roleAuthorityService.GetEditAuthority(list, "EliminateTask");
            Session["EditDeadTask"] = roleAuthorityService.GetEditAuthority(list, "DeadTask");
            Session["EditEliminateInfo"] = roleAuthorityService.GetEditAuthority(list, "EliminateInfo");
            Session["EditDeadInfo"] = roleAuthorityService.GetEditAuthority(list, "DeadInfo");
            return PartialView();
        }
예제 #14
0
        /// <summary>
        ///     新建喂食任务
        /// </summary>
        /// <param name="newTask"></param>
        /// <param name="taskTypeId"></param>
        /// <param name="createEmployee">发布任务的员工工号</param>
        /// <returns></returns>
        public bool NewFeedTask(FeedTask newTask, long taskTypeId, string createEmployee)
        {
            if (createEmployee == null) throw new ArgumentNullException("createEmployee");
            var employeeService = new EmployeeService();

            var task = new task
                           {
                               TaskNumber = newTask.TaskNumber,
                               StartTime = newTask.StartTime,
                               EndTime = newTask.EndTime,
                               CreateTime = DateTime.Now,
                               CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id,
                               TaskStatusId = 1,
                               TaskTypeId = taskTypeId,
                               Memo = newTask.Memo
                           };

            //根据工号找到对应的id
            foreach (string employeeNumber in newTask.EmployeeNumber.Split(','))
            {
                task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id});
            }

            var pigstyService = new PigstyService();
            var fodderService = new FodderTypeService();
            foreach (FeedTaskDetail detail in newTask.Feeddetails)
            {
                string[] pigstyNum = detail.Pigsty.Split(',');
                long pighouseid = long.Parse(detail.PigHouse);
                string[] fodders = detail.Fodder.Split(',');
                List<long> fodderIds = fodders.Select(fodder => fodderService.FindByName(fodder).Id).ToList();

                foreach (string pigstydetail in pigstyNum)
                {
                    var taskPigsty = new task_pigsty();
                    int number = int.Parse(pigstydetail);
                    taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id;

                    foreach (long fodder in fodderIds)
                    {
                        taskPigsty.feed_task_quality.Add(new feed_task_quality {FodderTypeId = fodder});
                    }
                    task.task_pigsty.Add(taskPigsty);
                }
            }

            foreach (
                task_interval_cycle taskIntervalCycle in
                    newTask.FeedTaskCycle.Select(taskcycle => new task_interval_cycle
                                                                  {
                                                                      FirstExecuteDate = taskcycle.FirstExecuteDate,
                                                                      CycleDays = taskcycle.CycleDays
                                                                  }))
            {
                task.task_interval_cycle.Add(taskIntervalCycle);
            }
            var taskService = new TaskService();
            taskService.Insert(task);

            return true;
        }
        public ActionResult DelEmployeeManage(long id)
        {
            if (Session["CheckFeed"] == null || !(bool) Session["DelSystemManage"] ||
                !(bool) Session["CheckSystemManage"])
            {
                Response.Write("<script>history.go(0);</script>");
                return View("Error");
            }

            var employeeService = new EmployeeService();
            var roleService = new RoleService();
            employee employee = employeeService.Find(id);
            List<role> roles = roleService.FindByEmployeeId(id);
            //如果该员工有生产信息与之关联,则无法删除
            if (employee.cure_pig.Count != 0 || employee.feed.Count != 0 || employee.fodder_take.Count != 0 ||
                employee.inspection.Count != 0 || employee.prevention.Count != 0 || employee.sale.Count != 0 ||
                employee.task.Count != 0 || employee.task_employee.Count != 0)
            {
                Response.Write("<script language='JavaScript'>alert('该员工有生产信息与之关联,无法删除.');history.go(-1);</script>");
                return Content("nothing");
            }
            foreach (role role in roles)
            {
                roleService.Delete(role);
            }
            employeeService.Delete(employee);

            return RedirectToAction("EmployeeManage");
        }
        public bool DelEmp(long id)
        {
            var employeeService = new EmployeeService();
            var roleService = new RoleService();
            employee employee = employeeService.Find(id);
            List<role> roles = roleService.FindByEmployeeId(id);
            //如果该员工有生产信息与之关联,则无法删除
            if (employee.cure_pig.Count != 0 || employee.feed.Count != 0 || employee.fodder_take.Count != 0 ||
                employee.inspection.Count != 0 || employee.prevention.Count != 0 || employee.sale.Count != 0 ||
                employee.task.Count != 0 || employee.task_employee.Count != 0)
            {
                return false;
            }
            foreach (role role in roles)
            {
                roleService.Delete(role);
            }
            employeeService.Delete(employee);

            return true;
        }
예제 #17
0
        /// <summary>
        ///     修改喂食信息
        /// </summary>
        /// <param name="feedInfo">已修改的喂食信息页面类</param>
        /// <param name="time">原时间</param>
        /// <param name="employeeName">原喂食人员名字</param>
        /// <returns></returns>
        public bool UpdateFeedInfo(FeedInfo feedInfo, DateTime time, string employeeName)
        {
            var feedService = new FeedService();
            var fodderTakeService = new FodderTakeService();
            var employeeService = new EmployeeService();
            var taskService = new TaskService();
            int i = 0, j = 0;
            employee firstOrDefault = employeeService.FindByName(employeeName).FirstOrDefault();
            //var firstOrDefault = taskService.FindByTaskNumber(feedInfo.TaskNumber);
            if (firstOrDefault != null)
            {
                foreach (fodder_take fodderTake in fodderTakeService.FindByEmployeeId(firstOrDefault.Id))
                {
                    string num = fodderTake.task.TaskNumber;
                    if (!time.Date.Equals(fodderTake.Time.Date) && num != feedInfo.TaskNumber) continue;
                    if (i < feedInfo.TakeDetail.Count)
                    {
                        fodderTake.EmployeeId = long.Parse(feedInfo.EmployeeName);
                        fodderTake.FodderTypeId = long.Parse(feedInfo.TakeDetail[i].FodderType);
                        fodderTake.Quantity = feedInfo.TakeDetail[i].Quantity;
                        fodderTake.UnitId = long.Parse(feedInfo.TakeDetail[i].Unit);
                        fodderTake.Time = feedInfo.TakeDetail[i].TakeTime;
                        fodderTakeService.Update(fodderTake);
                        i++;
                    }
                    else
                    {
                        fodderTakeService = new FodderTakeService();
                        fodderTakeService.Delete(fodderTakeService.Find(fodderTake.Id));
                    }
                }
                for (; i < feedInfo.TakeDetail.Count; i++)
                {
                    string num = feedInfo.TaskNumber ?? null;
                    long id = taskService.FindByTaskNumber(num).Id;

                    fodderTakeService.Insert(new fodder_take
                                                 {
                                                     TaskId = id,
                                                     EmployeeId = long.Parse(feedInfo.EmployeeName),
                                                     FodderTypeId = long.Parse(feedInfo.TakeDetail[i].FodderType),
                                                     Quantity = feedInfo.TakeDetail[i].Quantity,
                                                     UnitId = long.Parse(feedInfo.TakeDetail[i].Unit),
                                                     Time = feedInfo.TakeDetail[i].TakeTime
                                                 });
                }
                employee orDefault = employeeService.Find(long.Parse(feedInfo.EmployeeName));
                if (orDefault != null)
                    foreach (feed feedItem in feedService.FindByEmployeeId(orDefault.Id))
                    {
                        string num = feedItem.task.TaskNumber;
                        if (!time.Date.Equals(feedItem.Time.Date) && num != feedInfo.TaskNumber) continue;
                        if (j < feedInfo.FeedPig.Count)
                        {
                            feedItem.EmployeeId = long.Parse(feedInfo.EmployeeName);
                            //feedItem.FodderTypeId = long.Parse(feedInfo.FeedPig[j].FodderType);
                            //feedItem.Quality = feedInfo.FeedPig[j].Quantity;
                            //feedItem.UnitId = long.Parse(feedInfo.FeedPig[j].Unit);
                            feedItem.PigstyId = long.Parse(feedInfo.FeedPig[j].Pigsty);
                            feedItem.Time = feedInfo.FeedPig[j].DetailTime;
                            feedItem.Memo = feedInfo.Meno;
                            feedService.Update(feedItem);
                            j++;
                        }
                        else
                        {
                            feedService = new FeedService();
                            feedService.Delete(feedService.Find(feedItem.Id));
                        }
                    }
                for (; j < feedInfo.FeedPig.Count; j++)
                {
                    string num = feedInfo.TaskNumber ?? null;
                    long id = taskService.FindByTaskNumber(num).Id;
                    feedService.Insert(new feed
                                           {
                                               TaskId = id,
                                               EmployeeId = long.Parse(feedInfo.EmployeeName),
                                               PigstyId = long.Parse(feedInfo.FeedPig[j].Pigsty),
                                               //FodderTypeId = long.Parse(feedInfo.FeedPig[j].FodderType),
                                               //Quality = feedInfo.FeedPig[j].Quantity,
                                               //UnitId = long.Parse(feedInfo.FeedPig[j].Unit),
                                               Time = feedInfo.FeedPig[j].DetailTime,
                                               Memo = feedInfo.Meno
                                           });
                }
            }
            else
            {
                return false;
            }
            return true;
        }
예제 #18
0
 //员工姓名
 public bool EmployeeNameCompare(string name)
 {
     var employeeService = new EmployeeService();
     if (employeeService.FindByName(name).Count == 0)
     {
         return true;
     }
     return false;
 }
예제 #19
0
        public bool NewCureTask(CureTask newTask, long taskTypeId, string createEmployee)
        {
            var employeeService = new EmployeeService();

            var task = new task
                           {
                               TaskNumber = newTask.TaskNumber,
                               StartTime = newTask.StartTime,
                               EndTime = newTask.EndTime,
                               CreateTime = DateTime.Now,
                               CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id,
                               TaskStatusId = 1,
                               TaskTypeId = taskTypeId,
                               Memo = newTask.Memo
                           };

            foreach (string employeeNumber in newTask.EmployeeNumber.Split(','))
            {
                task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id});
            }

            var pigService = new PigService();

            foreach (string pigNumber in newTask.CureDetail.SelectMany(taskDetail => taskDetail.Pig.Split(',')))
            {
                task.task_pig.Add(new task_pig
                                      {
                                          PigId = pigService.FindByNumber(pigNumber).Id
                                      });
            }

            foreach (CureCourse cureCourse in newTask.CureCourse)
            {
                var cureMethodList = new Collection<cure_task_method>();
                foreach (CureMethod cureMethod in cureCourse.CureMethod)
                {
                    var medicineList = new Collection<cure_task_medicine>();
                    foreach (Medicine medicine in cureMethod.CureMedicine.Where(medicine => !(medicine.Quality <= 0)))
                    {
                        medicineList.Add(new cure_task_medicine
                                             {
                                                 MedicineId = long.Parse(medicine.MedicineName),
                                                 Quality = medicine.Quality,
                                                 UnitId = long.Parse(medicine.Unit)
                                             });
                    }
                    cureMethodList.Add(new cure_task_method
                                           {
                                               CureTypeId = long.Parse(cureMethod.CureType),
                                               cure_task_medicine = medicineList
                                           });
                }
                task.cure_task_course.Add(new cure_task_course
                                              {
                                                  Order = cureCourse.CureOrder + 1,
                                                  Time = cureCourse.CureTime,
                                                  cure_task_method = cureMethodList
                                              });
            }

            var taskService = new TaskService();
            taskService.Insert(task);

            return true;
        }
예제 #20
0
 //员工编号
 public bool EmployeeNumberCompare(string number)
 {
     var employeeService = new EmployeeService();
     if (employeeService.FindByNumber(number) != null)
     {
         return false;
     }
     return true;
 }
예제 #21
0
        /// <summary>
        ///     新建销售任务
        /// </summary>
        /// <param name="newTask">销售任务</param>
        /// <param name="taskTypeId">任务类型id</param>
        /// <param name="createEmployee">发布任务的员工工号</param>
        /// <returns>返回新建任务是否成功</returns>
        public bool NewAddPigTask(AddPigTask newTask, long taskTypeId, string createEmployee)
        {
            var employeeService = new EmployeeService();

            var task = new task
                           {
                               TaskNumber = newTask.TaskNumber,
                               StartTime = newTask.StartTime,
                               EndTime = newTask.EndTime,
                               CreateTime = DateTime.Now,
                               CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id,
                               TaskStatusId = 1,
                               TaskTypeId = taskTypeId,
                               Memo = newTask.Memo
                           };

            foreach (string employeeNumber in newTask.EmployeeNumber.Split(','))
            {
                task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id});
            }

            var pigstyService = new PigstyService();
            foreach (TaskDetail detail in newTask.TaskDetails)
            {
                string[] pigstyNum = detail.Pigsty.Split(new[] {','});
                long pighouseid = long.Parse(detail.PigHouse);
                foreach (string pigstydetail in pigstyNum)
                {
                    var taskPigsty = new task_pigsty();
                    int number = int.Parse(pigstydetail);
                    taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id;
                    task.task_pigsty.Add(taskPigsty);
                }
            }

            var taskService = new TaskService();
            taskService.Insert(task);

            return true;
        }
예제 #22
0
        public string GetEmployee()
        {
            var employeeService = new EmployeeService();

            return employeeService.GetEmployeeNumAndName();
        }
예제 #23
0
        /// <summary>
        ///     新建转栏任务
        /// </summary>
        /// <param name="newTask">转栏任务</param>
        /// <param name="taskTypeId">任务类型id</param>
        /// <param name="createEmployee">发布任务的员工工号</param>
        /// <returns>返回新建任务是否成功</returns>
        public bool NewTransferTask(TransferTask newTask, long taskTypeId, string createEmployee)
        {
            var employeeService = new EmployeeService();

            var task = new task
                           {
                               TaskNumber = newTask.TaskNumber,
                               StartTime = newTask.StartTime,
                               EndTime = newTask.EndTime,
                               CreateTime = DateTime.Now,
                               CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id,
                               TaskStatusId = 1,
                               TaskTypeId = taskTypeId,
                               Memo = newTask.Memo
                           };

            foreach (string employeeNumber in newTask.EmployeeNumber.Split(','))
            {
                task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id});
            }

            var pigService = new PigService();

            foreach (string pigNumber in newTask.TransferFrom.SelectMany(taskDetail => taskDetail.Pig.Split(',')))
            {
                task.task_pig.Add(new task_pig
                                      {
                                          PigId = pigService.FindByNumber(pigNumber).Id
                                      });
            }

            var pigstyService = new PigstyService();

            foreach (TaskDetail taskDetail in TransferTo)
            {
                string pigHouse = taskDetail.PigHouse;

                foreach (string pigstyNumber in taskDetail.Pigsty.Split(','))
                {
                    task.task_pigsty.Add(new task_pigsty
                                             {
                                                 PigstyId =
                                                     pigstyService.GetPigsty(int.Parse(pigstyNumber),
                                                                             long.Parse(pigHouse)).Id
                                             });
                }
            }

            var taskService = new TaskService();
            taskService.Insert(task);

            return true;
        }
예제 #24
0
 /// <summary>
 ///     人员下拉列表
 /// </summary>
 /// <returns></returns>
 public IEnumerable<SelectListItem> GetEmployeeList()
 {
     var employeeService = new EmployeeService();
     IEnumerable<SelectListItem> employeeSelect =
         employeeService.FindAll().Select(takeEmployee => new SelectListItem
                                                              {
                                                                  Text = takeEmployee.Name,
                                                                  Value = takeEmployee.Id + "",
                                                              }).OrderBy(m => m.Text);
     return employeeSelect;
 }
예제 #25
0
        /// <summary>
        ///     新建销售任务
        /// </summary>
        /// <param name="newTask">销售任务</param>
        /// <param name="taskTypeId">任务类型id</param>
        /// <param name="createEmployee">发布任务的员工工号</param>
        /// <returns>返回新建任务是否成功</returns>
        public bool NewSaleTask(SaleTask newTask, long taskTypeId, string createEmployee)
        {
            var employeeService = new EmployeeService();
            var task = new task
                           {
                               TaskNumber = newTask.TaskNumber,
                               StartTime = newTask.StartTime,
                               EndTime = newTask.EndTime,
                               CreateTime = DateTime.Now,
                               CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id,
                               TaskStatusId = 1,
                               TaskTypeId = taskTypeId,
                               Memo = newTask.Memo
                           };

            foreach (string employeeNumber in newTask.EmployeeNumber.Split(','))
            {
                task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id});
            }

            var customerService = new CustomerService();
            customer customer = customerService.FindByName(newTask.Customer) ?? customerService.Insert(new customer
                                                                                                           {
                                                                                                               Name =
                                                                                                                   newTask
                                                                                                                   .
                                                                                                                   Customer
                                                                                                           });
            task.CustomerId = customer.Id;

            foreach (SaleDetail detail in newTask.SaleDetailList)
            {
                task.sale_task_quality.Add(new sale_task_quality
                                               {
                                                   PigTypeId = long.Parse(detail.PigType),
                                                   Price = detail.Price,
                                                   Quality = detail.Quantity
                                               });
            }

            var taskService = new TaskService();
            taskService.Insert(task);

            return true;
        }
예제 #26
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());
 }
예제 #27
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;
        }
예제 #28
0
        /// <summary>
        /// 新建淘汰任务
        /// </summary>
        /// <param name="newTask"></param>
        /// <param name="taskTypeId"></param>
        /// <param name="createEmployee"></param>
        /// <returns></returns>
        public bool NewEliminateTask(EliminateTask newTask, long taskTypeId, string createEmployee)
        {
            var employeeService = new EmployeeService();
            var task = new task
            {
                TaskNumber = newTask.TaskNumber,
                StartTime = newTask.StartTime,
                EndTime = newTask.EndTime,
                CreateTime = DateTime.Now,
                CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id,
                TaskStatusId = 1,
                TaskTypeId = taskTypeId,
                Memo = newTask.Memo
            };

            foreach (string employeeNumber in newTask.EmployeeNumber.Split(','))
            {
                task.task_employee.Add(new task_employee { EmployeeId = employeeService.FindByNumber(employeeNumber).Id });
            }

            var pigService = new PigService();

            foreach (var  detail in newTask.EliminateTaskDetail)
            {
                if (detail.Pig != null)
                {
                    var detailPigs = detail.Pig.Split(',');
                    foreach (var str in detailPigs)
                        task.task_pig.Add(new task_pig
                        {
                            PigId = pigService.FindByRfid(str).Id
                        });
                }
                else
                {
                    task.task_pigsty.Add(new task_pigsty
                    {
                        PigstyId = long.Parse(detail.Pigsty)
                    });
                }
            }

            var taskService = new TaskService();
            taskService.Insert(task);

            return true;
        }
        public bool NewPreventionDiseaseTask(PreventionDiseaseTask newTask, long taskTypeId, string createEmployee)
        {
            var employeeService = new EmployeeService();

            var task = new task
                           {
                               TaskNumber = newTask.TaskNumber,
                               StartTime = newTask.StartTime,
                               EndTime = newTask.EndTime,
                               CreateTime = DateTime.Now,
                               CreateEmployeeId = employeeService.FindByNumber(createEmployee).Id,
                               TaskStatusId = 1,
                               TaskTypeId = taskTypeId,
                               Memo = newTask.Memo,
                           };

            foreach (string employeeNumber in newTask.EmployeeNumber.Split(','))
            {
                task.task_employee.Add(new task_employee {EmployeeId = employeeService.FindByNumber(employeeNumber).Id});
            }

            var pigstyService = new PigstyService();
            var transferService = new TransferService();
            foreach (TaskDetail detail in newTask.Taskdetails)
            {
                string[] pigstyNum = detail.Pigsty.Split(new[] {','});
                long pighouseid = long.Parse(detail.PigHouse);
                foreach (string pigstydetail in pigstyNum)
                {
                    var taskPigsty = new task_pigsty();
                    int number = int.Parse(pigstydetail);
                    if (detail.Pig == "2") {
                        taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id;
                       var  munPigList=transferService.FindByMunPig(taskPigsty.PigstyId);

                       foreach (var munPig in munPigList)
                           task.task_pig.Add(new task_pig() {
                               PigId = munPig.PigId
                             });
                    }
                    else
                    {
                        taskPigsty.PigstyId = pigstyService.GetPigsty(number, pighouseid).Id;
                        task.task_pigsty.Add(taskPigsty);
                    }
                }
            }

            task.task_prevention.Add(new task_prevention
                                         {
                                             PreventionTypeId = long.Parse(newTask.DiseaseName)
                                         });

            var taskService = new TaskService();
            taskService.Insert(task);

            return true;
        }