private void SelectDesk(Protocol.SelectDesk e, IUserAgent agent, ISiqiServer server) { IDesk desk = Desks.FirstOrDefault(o => o.ID == e.Desk); Protocol.SelectDeskResponse response = new Protocol.SelectDeskResponse(); response.Success = true; response.Seat = e.Seat; response.Desk = e.Desk; if (desk != null) { response.Message = desk.In(agent, e.Seat); response.Success = string.IsNullOrEmpty(response.Message); } else { response.Success = false; response.Message = "桌子编号错误!"; } server.Send(response, agent); }
/// <summary> /// 重新加载内存数据 /// </summary> /// <returns></returns> public async Task ReloadAsync() { using (var scope = DataBase.BeginLifetimeScope()) { var service = scope.Resolve <IUtilService>(); var orderService = scope.Resolve <IOrderService>(); Types.Clear(); Products.Clear(); DeskTypes.Clear(); Desks.Clear(); // 产品列表 (await service.GetProductTypeAsync())?.ForEach(a => { Types.Add(a); a.Products?.ForEach(b => Products.Add(b)); }); // 产品库存 (await service.GetProductStocksAsync())?.ForEach(a => { var product = Products.FirstOrDefault(b => b.Id == a.ProductId); if (product == null) { return; } product.Stock = a.Stock; }); // 桌台 (await service.GetDeskTypesAsync())?.ForEach(a => { DeskTypes.Add(a); a.Desks?.ForEach(b => Desks.Add(b)); }); // 未完成订单 orderService.GetUnfinishOrder()?.ForEach(order => { var desk = Desks.FirstOrDefault(a => a.Id == order.DeskId); if (desk == null) { return; } desk.Order = order; }); service.PubSubscribe("SystemMessage", "ResetDeskStatus"); var clientPrinters = await service.GetAllAsync <ClientPrinter>(); // 将删除的打印机关闭 var delPrinter = new List <Printer>(); Printers.ForEach(a => { var printer = clientPrinters?.FirstOrDefault(b => a.Device.Id == b.Id); if (printer != null) { return; } a.Close(); delPrinter.Add(a); }); delPrinter.ForEach(a => Printers.Remove(a)); clientPrinters?.ForEach(item => { var printer = Printers.FirstOrDefault(a => a.Device.Id == item.Id); if (printer == null) { printer = new Printer { Device = item }; Printers.Add(printer); } else { printer.Device = item; } if (printer.Device.State == 1) { printer.Open(); } else { printer.Close(); } }); } }