public ActionResult Add_ShopTempletDetail(string ShopTempletID, string[] ids)
 {
     if (ids != null && ids.Length > 0)
     {
         ShopTemplet shopTemplet           = this.ShopTempletRepo.GetByDatabaseID(Convert.ToInt32(ShopTempletID));
         var         listShopTempletDetail = this.ShopTempletDetailsRepo.GetAll()
                                             .Where(it => it._ShopTemplet == shopTemplet);
         foreach (var ShopTempletDetail in listShopTempletDetail)
         {
             this.ShopTempletDetailsRepo.Delete(ShopTempletDetail);
         }
         for (int i = 0; i < ids.Length; i++)
         {
             ShopTempletDetails gd = new ShopTempletDetails()
             {
                 _ShopTemplet = shopTemplet,
                 _ShopGroup   = this.ShopGroupRepo.GetByDatabaseID(Convert.ToInt32(ids[i])),
                 UpdateTime   = DateTime.Now
             };
             this.ShopTempletDetailsRepo.Save(gd);
         }
         return(Json(new { state = true, message = "添加或修改成功, 请刷新显示" }));
     }
     else
     {
         return(Json(new { state = false, message = "请选择班组" }));
     }
 }
Esempio n. 2
0
        //(4)进行系统排班,清空PBDateTemplet,PersonShopPBs,PersonPBs之前的记录。插入PBDateTemplet,PersonShopPBs,PersonPBs自动插入。
        //(5)手工调整PBDateTemplet和值班人员,调整时PersonShopPBs,PersonPBs自动更新。
        public void PaiBan(DateTime localStartDate, DateTime localEndDate, Kf_DepartMent kf_DepartMent)
        {
            WorkDateRepository    workDateRepo     = new WorkDateRepository();
            List <UserWorkDate>   listUserWorkDate = workDateRepo.PaiBan(localStartDate, localEndDate);
            ShopTempletRepository shopTempletRepo  = new ShopTempletRepository();

            //把PBDateTemplet中的记录删除掉,再重新
            List <PBDateTemplet> listPBDateTemplet = this.GetAll()
                                                     .Where(it => it._UserWorkDate.WorkDate.Date <= localEndDate.Date)
                                                     .Where(it => it._UserWorkDate.WorkDate.Date >= localStartDate.Date)
                                                     .WhereIf(it => it._ShopTemplet._Kf_DepartMent == kf_DepartMent, kf_DepartMent.ID != 1)
                                                     .ToList();

            //删除,重新排
            if (listPBDateTemplet != null && listPBDateTemplet.Count != 0)
            {
                foreach (var pb in listPBDateTemplet)
                {
                    this.Delete(pb);
                }
            }

            List <ShopTemplet> listShopTemplet = shopTempletRepo.GetAll()
                                                 .Where(it => it.isExpire == isExpire.未过期)
                                                 .Where(it => it.isValid == isValid.效)
                                                 .WhereIf(it => it._Kf_DepartMent == kf_DepartMent, kf_DepartMent.ID != 1)
                                                 .ToList();

            for (DateTime Date = localStartDate; Date <= localEndDate; Date = Date.AddDays(1))
            {
                UserWorkDate workDate = listUserWorkDate.Where(it => it.WorkDate == Date).FirstOrDefault();

                //循环
                ShopTemplet shopTempletOrdinary    = listShopTemplet.Where(it => it.ShopTempletTypeID == _ShopTempletType.平时).ToList().FirstOrDefault();
                ShopTemplet shopTempletWeekEnd     = listShopTemplet.Where(it => it.ShopTempletTypeID == _ShopTempletType.周末).ToList().FirstOrDefault();
                ShopTemplet shopTempletHoliday     = listShopTemplet.Where(it => it.ShopTempletTypeID == _ShopTempletType.假期).ToList().FirstOrDefault();
                ShopTemplet shopTempletSpecailDate = listShopTemplet.Where(it => it.ShopTempletTypeID == _ShopTempletType.特定日期).ToList().FirstOrDefault();

                PBDateTemplet pbDateTemplet = new PBDateTemplet();
                if ((Date.DayOfWeek == DayOfWeek.Saturday || Date.DayOfWeek == DayOfWeek.Sunday) && shopTempletWeekEnd != null)
                {
                    pbDateTemplet._ShopTemplet = shopTempletWeekEnd;
                }
                else if (shopTempletSpecailDate != null && Date.Date == shopTempletSpecailDate.SpecialDate.Date)
                {
                    pbDateTemplet._ShopTemplet = shopTempletSpecailDate;
                }
                else if (false)//假期还没完善上去。
                {
                }
                else
                {
                    pbDateTemplet._ShopTemplet = shopTempletOrdinary;
                }
                pbDateTemplet._UserWorkDate = workDate;
                pbDateTemplet.UpdateTime    = System.DateTime.Now.Date;
                this.Save(pbDateTemplet);
            }
        }
        //如果是手工排班需要不需要检查里面有无排班,如果有排班的数据,那么就不重新全部删除,而是保留一部分原来的排班的数据
        public void PaiBanHandChange(PBDateTemplet PbDateTempletOld, ShopTemplet shopTempletNew, Kf_DepartMent kf_DepartMent)
        {
            ShopTempletDetailsRepository shopTempletDetailsRepo = new ShopTempletDetailsRepository();
            PBDateTempletRepository      pbDateTempletRepo      = new PBDateTempletRepository();


            List <ShopTempletDetails> listShopTempletDetailsOld = shopTempletDetailsRepo.GetAll()
                                                                  .Where(it => it._ShopTemplet == PbDateTempletOld._ShopTemplet)
                                                                  .WhereIf(it => it._ShopGroup._Kf_DepartMent == kf_DepartMent, kf_DepartMent.ID != 1)
                                                                  .ToList();

            List <ShopTempletDetails> listShopTempletDetailsNew = shopTempletDetailsRepo.GetAll()
                                                                  .Where(it => it._ShopTemplet == shopTempletNew)
                                                                  .WhereIf(it => it._ShopGroup._Kf_DepartMent == kf_DepartMent, kf_DepartMent.ID != 1)
                                                                  .ToList();

            //在老的里面有,新的里面也有的,不动。
            List <PersonShopGroupPBs> listPersonShopGroupPBs = this.GetAll()
                                                               .Where(it => it.UserWorkDate == PbDateTempletOld._UserWorkDate)
                                                               .WhereIf(it => it._ShopGroups._Kf_DepartMent == kf_DepartMent, kf_DepartMent.ID != 1)
                                                               .ToList();

            //在老的里面有,新的里面没有的,删除掉。
            foreach (var PersonShopGroupPB in listPersonShopGroupPBs)
            {
                if (listShopTempletDetailsNew.Where(it => it._ShopGroup == PersonShopGroupPB._ShopGroups).Count() == 0)
                {
                    this.Delete(PersonShopGroupPB);
                }
            }
            //在老的里面没有,新的里面有的,插入进去。
            //都是哪些人可以做这个班组的客服
            PersonShopGroupRepository PersonShopGroupRepo = new PersonShopGroupRepository();
            List <PersonShopGroup>    listPersonShopGroup = PersonShopGroupRepo.GetAll().ToList();

            foreach (var shopGroupDetail in listShopTempletDetailsNew)
            {
                if (listPersonShopGroupPBs.Where(it => it._ShopGroups == shopGroupDetail._ShopGroup).Count() == 0)
                {
                    //根据排班来插入店铺
                    this.ShopGroupPB(shopGroupDetail._ShopGroup, PbDateTempletOld._UserWorkDate, kf_DepartMent);
                }
            }
        }
        public ActionResult AddShopTemplet(int?id)
        {
            Kf_DepartMentRepository      kf_DepartRepo  = new Kf_DepartMentRepository();
            IEnumerable <SelectListItem> listDepartMent = kf_DepartRepo.GetData(this.Users().DepartMent.ID)
                                                          .Select(p => new SelectListItem
            {
                Text  = p.DepartMentName,
                Value = p.ID.ToString().Trim(),
            });

            ViewData["listDepartMent"] = listDepartMent;
            if (id != null)
            {
                ShopTemplet shopTemplet = this.ShopTempletRepo.GetByDatabaseID(id.Value);
                ViewBag.Edit = "1";
                return(View(shopTemplet));
            }
            return(View());
        }
        public ActionResult AddShopTemplet(string ShopTempletName, string _Kf_DepartMent, string ShopTempletTypeID, string SpecialDate, string isExpire, int?id)
        {
            if (ShopTempletName.IsNullOrEmpty())
            {
                return(Json(new { state = false, message = "请填写模板名称!" }));
            }
            if (_Kf_DepartMent.IsNullOrEmpty())
            {
                return(Json(new { state = false, message = "请选择部门!" }));
            }
            if (ShopTempletTypeID.IsNullOrEmpty())
            {
                return(Json(new { state = false, message = "请选择模板类型!" }));
            }
            if (ShopTempletTypeID == "4" && SpecialDate.IsNullOrEmpty())
            {
                return(Json(new { state = false, message = "模板为特定日期时请选择日期!" }));
            }
            if (isExpire.IsNullOrEmpty())
            {
                return(Json(new { state = false, message = "请选择是否过期!" }));
            }
            ShopTemplet shopTemplet = new ShopTemplet();

            try
            {
                if (id != null && id.Value > 0)
                {
                    shopTemplet = this.ShopTempletRepo.GetByDatabaseID(id.Value);
                }
                shopTemplet.ShopTempletName = ShopTempletName;
                shopTemplet._Kf_DepartMent  = new Kf_DepartMent {
                    ID = _Kf_DepartMent.ToInt()
                };
                shopTemplet.ShopTempletTypeID = ShopTempletTypeID.ToEnum <_ShopTempletType>();
                shopTemplet.isExpire          = isExpire.ToEnum <isExpire>();
                shopTemplet.UpdateTime        = System.DateTime.Today;
                if (SpecialDate.IsNotNullAndEmpty())
                {
                    shopTemplet.SpecialDate = SpecialDate.ToDateTime();
                }
                else
                {
                    shopTemplet.SpecialDate = System.DateTime.Today;
                }

                if (id != null && id.Value > 0)
                {
                    ShopTempletRepo.Update(shopTemplet);
                }
                else
                {
                    shopTemplet.UpdateTime = System.DateTime.Today;
                    ShopTempletRepo.Save(shopTemplet);
                }
                return(Json(new { state = true, message = "操作成功!" }));
            }
            catch (RuleException ex)
            {
                throw new RuleException(ex.Message, ex);
            }
        }