// GET: Console/ExportOrders public ActionResult ExportOrders(string date) { IViewerFactory <OrderView> factory = new OrderViewFactory(); DateTime menuDate; List <OrderView> list; if (!string.IsNullOrEmpty(date) && DateTime.TryParse(date, out menuDate)) { list = factory.Query(new Criteria(new { MenuDate = menuDate })); } else { // 为避免数据量过大,只显示7天内的订餐记录 list = factory.Query(new Criteria { WhereClause = "MenuDate >= DATEADD(DAY,-7,GETDATE())", PagingSize = 0 }); list.Sort((x1, x2) => x2.Menu.MenuDate.CompareTo(x1.Menu.MenuDate)); } if (list != null && list.Count > 0) { var mapper = OrderDto.ConfigMapper().CreateMapper(); var orders = mapper.Map <IEnumerable <OrderDto> >(list.AsEnumerable()).ToList(); var book = ExcelManager.BuildOrderWorkbook(orders); byte[] file; using (var ms = new MemoryStream()) { book.Write(ms); file = ms.GetBuffer(); } var timestamp = !string.IsNullOrEmpty(date) ? Convert.ToDateTime(date).ToString("yyyyMMdd") : string.Empty; return(File(file, "application/vnd.ms-excel", $@"订餐记录表-{timestamp}.xls")); //return File(file, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", // $@"订餐记录表-{timestamp}.xlsx"); } return(RedirectToAction("OrderManagement", "Console", new { date })); }
// GET: Console/OrderManagementCanteen public ActionResult OrderManagementCanteen() { var model = new ConsoleModels.OrderManagementDto(); IViewerFactory <OrderView> factory = new OrderViewFactory(); var list = factory.Query(new Criteria(new { MenuDate = DateTime.Today, MenuType = (int)MenuDto.GetMenuLunchOrSupper(0, false) })); if (list != null && list.Count > 0) { var mapper = OrderDto.ConfigMapper().CreateMapper(); model.Orders = mapper.Map <IEnumerable <OrderDto> >(list.AsEnumerable()).ToList(); // 查找今日的菜单,判断是否大班长确认过 var currentMenus = Entities.Menu.Cache.MenuListActiveToday.FindAll(x => x.MenuType.Equals(MenuDto.GetMenuLunchOrSupper(0, false))); model.IsMenuApproved = currentMenus.Exists(x => x.IsApproved); model.ApproverInfo = model.IsMenuApproved ? currentMenus[0].Remark : string.Empty; } model.DeliveryZones = Delivery.Cache.DeliveryZoneList; return(View(model)); }
private OrderDto GetMyCurrentOrder(int[] ids) { if (MenuDto.GetMenuLunchOrSupper() != MenuTypeEnum.None) { // 获得预订了对应的套餐 var factory = new OrderViewFactory(); var critria = new Criteria { WhereClause = $"UserGuid = '{_authorizedUser.ID}'", OrderClause = "PlaceTime DESC", PagingSize = 0 }; var order = factory.Query(critria).Find(x => ids.Any(id => id == x.Menu.ID)); if (order != null) { var mapper = OrderDto.ConfigMapper().CreateMapper(); return(mapper.Map <OrderDto>(order)); } } return(null); }
// GET: Reservation/ExportOrders public ActionResult ExportOrders() { IViewerFactory <OrderView> factory = new OrderViewFactory(); var list = factory.Query(new Criteria(new { MenuDate = DateTime.Today, MenuType = (int)MenuDto.GetMenuLunchOrSupper(0, false) })); if (list != null && list.Count > 0) { var mapper = OrderDto.ConfigMapper().CreateMapper(); var orders = mapper.Map <IEnumerable <OrderDto> >(list.AsEnumerable()).ToList(); var book = ExcelManager.BuildOrderWorkbook(orders); byte[] file; using (var ms = new MemoryStream()) { book.Write(ms); file = ms.GetBuffer(); } return(File(file, "application/vnd.ms-excel", $@"今日订餐记录表-{DateTime.Today.ToString("yyyyMMdd")}.xls")); //return File(file, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", // $"今日订餐记录表-{DateTime.Today.ToString("yyyyMMdd")}.xlsx"); } return(RedirectToAction("TodayOrders", "Reservation")); }
// GET: Console/OrderManagement public ActionResult OrderManagement(string date) { var model = new ConsoleModels.OrderManagementDto(); IViewerFactory <OrderView> factory = new OrderViewFactory(); DateTime menuDate; List <OrderView> list; if (!string.IsNullOrEmpty(date) && DateTime.TryParse(date, out menuDate)) { list = factory.Query(new Criteria(new { MenuDate = menuDate })); model.MenuDate = menuDate; // 查找今日的菜单,判断是否大班长确认过 var currentMenus = Entities.Menu.Cache.MenuListActive.FindAll(x => x.MenuDate.Equals(menuDate) && x.MenuType.Equals(MenuDto.GetMenuLunchOrSupper(0, false))); model.ApproverInfo = currentMenus.Exists(x => x.IsApproved) ? currentMenus[0].Remark : string.Empty; } else { // 为避免数据量过大,只显示7天内的订餐记录 list = factory.Query(new Criteria { WhereClause = "MenuDate >= DATEADD(DAY,-7,GETDATE())", PagingSize = 0 }); list.Sort((x1, x2) => x2.Menu.MenuDate.CompareTo(x1.Menu.MenuDate)); } if (list != null && list.Count > 0) { var mapper = OrderDto.ConfigMapper().CreateMapper(); model.Orders = mapper.Map <IEnumerable <OrderDto> >(list.AsEnumerable()).ToList(); } model.DeliveryZones = Delivery.Cache.DeliveryZoneList; return(View(model)); }
// GET: Reservation/History public ActionResult History() { var model = new ReservationModels.HistoryDto { MenuDate = DateTime.Today, // 设置当前是否在订餐时间内,不判断是否有菜单 CanReserveNow = MenuDto.GetMenuLunchOrSupper() != MenuTypeEnum.None }; // 获取所有历史订单 (7天内) IViewerFactory <OrderView> factory = new OrderViewFactory(); var criteria = new Criteria { WhereClause = $@"(PlaceTime >= '{DateTime.Today.AddDays(-7)}') AND UserGuid = '{_authorizedUser.ID}'", PagingSize = 0 }; var query = factory.Query(criteria); if (query.Any()) { var mapper = OrderDto.ConfigMapper().CreateMapper(); model.MyHistroyOrders = mapper.Map <IEnumerable <OrderDto> >(query.AsEnumerable()).ToList(); // 今天的午餐订单 model.MyOrderLunch = model.MyHistroyOrders.Find(x => x.MenuDate == model.MenuDate && x.MenuType == MenuTypeEnum.Lunch); // 设置可取消 if (model.MyOrderLunch != null && CanCancelNow(model.MyOrderLunch.MenuID)) { model.MyOrderLunch.CanCancelNow = true; } // 今天的夜宵订单 model.MyOrderSupper = model.MyHistroyOrders.Find(x => x.MenuDate == model.MenuDate && x.MenuType == MenuTypeEnum.Supper); // 设置可取消 if (model.MyOrderSupper != null && CanCancelNow(model.MyOrderSupper.MenuID)) { model.MyOrderSupper.CanCancelNow = true; } } return(View(model)); }
public void Test_Query_Pager_Viewer() { var factory = new OrderViewFactory(); var criteria = new Criteria { PagingSize = 20, WhereClause = "StapleFood = 2 AND ExtraFood = 1", OrderClause = "CreateTime DESC" }; Assert.IsFalse(criteria.TotalCount > 0); var query = factory.Query(criteria); Assert.IsNotNull(query); Assert.IsInstanceOfType(query, typeof(List <OrderView>)); Assert.IsTrue(query.Any()); Assert.IsTrue(criteria.TotalCount > 0); //Assert.AreEqual(criteria.PagingSize.ToString(), query.Count.ToString()); }
public void Test_Query_Viewer() { IViewerFactory <OrderView> factory = new OrderViewFactory(); var criteria = new Criteria { WhereClause = $"(PlaceTime < '{DateTime.Now}')", PagingSize = 0 }; var query = factory.Query(criteria); Assert.IsNotNull(query); Assert.IsInstanceOfType(query, typeof(List <OrderView>)); Assert.IsTrue(query.Any()); var instance = query.First(); Assert.IsNotNull(instance); Assert.IsInstanceOfType(instance, typeof(OrderView)); Assert.IsNotNull(instance.User); Assert.IsNotNull(instance.Menu); Assert.IsNotNull(instance.Delivery); }