Exemple #1
0
        /// <summary>
        ///     查看销售任务
        /// </summary>
        /// <param name="taskNumber">任务编号</param>
        /// <returns></returns>
        public SaleTask GetSaleTask(string taskNumber)
        {
            var taskService = new TaskService();
            var taskEmployeeService = new TaskEmployeeService();
            var pigTypeService = new PigTypeService();

            task task = taskService.FindByTaskNumber(taskNumber);

            if (task == null)
            {
                return null;
            }

            var customerService = new CustomerService();
            var checkTask = new SaleTask
                                {
                                    TaskNumber = task.TaskNumber,
                                    StartTime = task.StartTime,
                                    EndTime = task.EndTime,
                                    EmployeeName = taskEmployeeService.GetEmployeeNames(task.Id),
                                    EmployeeNumber = taskEmployeeService.GetEmployeeNumbers(task.Id),
                                    Customer = customerService.Find(task.CustomerId).Name,
                                    Status = task.task_status_type.Name,
                                    Memo = task.Memo
                                };

            List<SaleDetail> saleDetailList = task.sale_task_quality.Select(item => new SaleDetail
                                                                                        {
                                                                                            PigType =
                                                                                                pigTypeService.Find(
                                                                                                    item.PigTypeId).Name,
                                                                                            Price = item.Price,
                                                                                            Quantity = item.Quality
                                                                                        }).ToList();

            if (saleDetailList.Count != 0)
            {
                checkTask.SaleDetailList = saleDetailList;
            }
            return checkTask;
        }
        /// <summary>
        ///     根据类型id查找关联它的表是否为0
        /// </summary>
        /// <param name="typeid">类型id</param>
        /// <param name="typename">类型名字</param>
        /// <returns></returns>
        public string GetRelationtById(long typeid, string typename)
        {
            var cureTypeService = new CureTypeService();
            var medicineService = new MedicineService();
            var unitService = new UnitService();
            var fodderTypeService = new FodderTypeService();
            var excetionTypeService = new ExceptionTypeService();
            var pigTypeService = new PigTypeService();
            var pigHouseTypeService = new PigHouseTypeService();
            var taskStatusTypeService = new TaskStatusTypeService();
            var taskTypeService = new TaskTypeService();
            var roleTypeService = new RoleTypeService();
            var preventionTypeService = new PreventionTypeService();
            var roleAuthorityService = new RoleAuthorityService();
            var customerService = new CustomerService();
            if (typeid == 0)
            {
                return "不存在于数据库,可以删除";
            }
            try
            {
                if (typename == "治疗")
                {
                    cureTypeService.Delete(cureTypeService.Find(typeid));
                }
                if (typename == "单位")
                {
                    unitService.Delete(unitService.Find(typeid));
                }
                if (typename == "药物")
                {
                    medicineService.Delete(medicineService.Find(typeid));
                }
                if (typename == "异常")
                {
                    excetionTypeService.Delete(excetionTypeService.Find(typeid));
                }
                if (typename == "饲料")
                {
                    fodderTypeService.Delete(fodderTypeService.Find(typeid));
                }
                if (typename == "生猪")
                {
                    if (pigTypeService.Find(typeid).Name == "母猪" || pigTypeService.Find(typeid).Name == "公猪")
                    {
                        return "不可删除";
                    }
                    pigTypeService.Delete(pigTypeService.Find(typeid));
                }
                if (typename == "防疫")
                {
                    preventionTypeService.Delete(preventionTypeService.Find(typeid));
                }
                if (typename == "猪舍")
                {
                    pigHouseTypeService.Delete(pigHouseTypeService.Find(typeid));
                }
                if (typename == "任务状态")
                {
                    if (taskStatusTypeService.Find(typeid).Name == "未完成" ||
                        taskStatusTypeService.Find(typeid).Name == "已完成" ||
                        taskStatusTypeService.Find(typeid).Name == "正在进行")
                    {
                        return "不可删除";
                    }
                    taskStatusTypeService.Delete(taskStatusTypeService.Find(typeid));
                }
                if (typename == "任务类型")
                {
                    if (taskTypeService.Find(typeid).Name == "喂饲" || taskTypeService.Find(typeid).Name == "防疫" ||
                        taskTypeService.Find(typeid).Name == "巡查" || taskTypeService.Find(typeid).Name == "治疗" ||
                        taskTypeService.Find(typeid).Name == "销售" || taskTypeService.Find(typeid).Name == "转栏" ||
                        taskTypeService.Find(typeid).Name == "添加生猪")
                    {
                        return "不可删除";
                    }
                    taskTypeService.Delete(taskTypeService.Find(typeid));
                }
                if (typename == "角色")
                {
                    foreach (role_authority c in roleAuthorityService.FindByRoleTypeId(typeid))
                        roleAuthorityService.Delete(roleAuthorityService.Find(c.Id));
                    roleTypeService.Delete(roleTypeService.Find(typeid));
                }
                if (typename == "客户名称")
                {
                    customerService.Delete(customerService.Find(typeid));
                }
            }
            catch (Exception)
            {
                return "不可删除";
            }

            return "";
        }
        //猪栏内的猪类型
        public JsonResult getPigstyTypes(string pigstys,string pigHouseId)
        {
            HashSet<SelectListItem>pigStyType=new HashSet<SelectListItem>();
             TransferService transferService= new TransferService();
            var pigstyService = new PigstyService();
            var  pigTypeService=new PigTypeService();
            pigStyType.Add(new SelectListItem(){
                     Text="全部猪",Value="0",Selected=true
                    });
            foreach(var str in pigstys.Split(',')){
            var pigSty=pigstyService.GetPigsty(int.Parse(str),long.Parse(pigHouseId));
              var   pigTypeIdList =transferService.FindByPigStyByPigType(pigSty.Id);
                foreach(var id in pigTypeIdList){
                    var name=pigTypeService.Find(id).Name;
                    pigStyType.Add(new SelectListItem(){
                     Text=name,Value=id+""
                    });
                }
            }

            return Json(pigStyType, JsonRequestBehavior.AllowGet);
        }
Exemple #4
0
 public void PigTypeSaveChanges(BasicInfoModel model)
 {
     var typeService = new PigTypeService();
     List<pig_type> types = typeService.FindAll();
     foreach (pig_type type in types)
     {
         int idFlag = 0;
         int nameFlag = 0;
         string newname = "";
         foreach (NameModel name in model.Names)
         {
             if (type.Id == name.Id)
             {
                 idFlag = 1;
                 if (type.Name.Equals(name.Name))
                 {
                     nameFlag = 1;
                 }
                 else
                 {
                     newname = name.Name;
                 }
             }
         }
         //若存在此Id,但是name变化了的,则需要修改数据库
         if (idFlag == 1)
         {
             if (nameFlag == 0)
             {
                 if (newname == "")
                 {
                     throw new Exception();
                 }
                 pig_type modifyCure = typeService.Find(type.Id);
                 modifyCure.Name = newname;
                 typeService.Update(modifyCure);
             }
         }
     }
     //如果model里的Id为0,说明是新建的类型
     foreach (NameModel name in model.Names)
     {
         if (name.Id == 0 && typeService.FindByName(name.Name) == null)
         {
             var newType = new pig_type {Name = name.Name};
             typeService.Insert(newType);
         }
     }
 }