public bool SaveOrder() { logger.Debug($"SaveOrder {Order.Id}"); var addRes = true; try { if (Order.OrderCustomer == null) { logger.Debug($"Order.OrderCustomer== null {Order?.Id}"); addRes = false; UI.UIModify.ShowAlert("Нельзя сохранить заказ без указания клиента"); logger.Debug($"Order.OrderCustomer== null end {Order.Id}"); } Order.DishPackages = OrderDishez.ToList(); Order.IsSHSent = true; bool addToBaseRes = false; logger.Debug($"Before addRes"); if (addRes) { /* * if (Order.Id == 0) * { * addToBaseRes = ToGoOrdersModelSingleton.Instance.AddOrder(Order, OrderDishez.ToList()); * } * else * { * addToBaseRes = ToGoOrdersModelSingleton.Instance.UpdateOrder(Order); * } */ addToBaseRes = DataCatalogsSingleton.Instance.OrdersToGoData.EndEdit(Order).Succeess; logger.Debug($"After addRes addToBaseRes: {addToBaseRes}"); try { if (Order.DishPackages == null) { logger.Debug($"Before Print: Order.DishPackages==null"); } else { logger.Debug($"Before Print: Non print count: {Order.DishPackages.Where(a => !a.Printed).Count()}"); } if (Order.DishPackages != null && Order.DishPackages.Any(a => !a.Printed)) { //Печатаем List <string> outErr = new List <string>(); if (!PrintRecieps.PrintOnWinPrinter.PrintOrderToGoToKitchen(Order, out outErr)) { foreach (string s in outErr) { UI.UIModify.ShowAlert(s); } } else { foreach (var d in Order.DishPackages) { d.Printed = true; } } } } catch (Exception e) { logger.Error("Error save print " + e.Message); } } logger.Debug($"Before addToBaseRes"); if (addToBaseRes) { //SH.SHWrapper.CreateSalesInvoice(Order); if (Order.OrderStatus != OrderStatus.InWork) { var CreateSHres = SH.SHWrapper.CreateSalesInvoiceSync(Order, out string err); if (!CreateSHres) { UI.UIModify.ShowAlert($"{err + Environment.NewLine} Накладная будет создана при появлении связи со StoreHouse"); Models.ToGoOrdersModelSingleton.Instance.UpdateOrder(Order); } } return(true); } return(false); } catch (Exception e) { logger.Error($"SaveOrder Error {Order.Id} Mess: {e.Message}"); return(false); } finally { } }
private void EventsInit() { OrderDishez.CollectionChanged += ((sender, e) => { Order.DishPackages = OrderDishez.ToList(); OrderChanged?.Invoke(); }); //OrderDishez_CollectionChanged; OrderDishez.ItemPropertyChanged += ((sender, e) => { OrderChanged?.Invoke(); }); Order.PropertyChanged += ((sender, e) => { OrderChanged?.Invoke(); }); }
public bool SaveOrder() { logger.Debug($"SaveOrder {Order.Id}"); bool NewOrder = (Order.Id == 0); try { if (Order.OrderCustomer == null) { logger.Debug($"Order.OrderCustomer== null {Order?.Id}"); UI.UIModify.ShowAlert("Нельзя сохранить заказ без указания клиента"); logger.Debug($"Order.OrderCustomer== null end {Order.Id}"); return(false); } List <long> oldItms = OrderDishez.Where(a => a.Printed).Select(a => a.Id).ToList(); Order.DishPackages = OrderDishez.ToList(); Order.IsSHSent = true; var sRes = DataCatalogsSingleton.Instance.OrdersToGoData.EndEdit(Order); if (!sRes.Succeess) { UI.UIModify.ShowAlert($"Ошибка при сохранении заказа {sRes.ErrorMessage}"); return(false); } try { foreach (var dp in sRes.UpdatedItem.DishPackages) { dp.Printed = oldItms.Contains(dp.Id); } if (sRes.UpdatedItem.DishPackages != null && sRes.UpdatedItem.DishPackages.Any(a => !a.Printed)) { //Печатаем List <string> outErr = new List <string>(); if (!PrintRecieps.PrintOnWinPrinter.PrintOrderToGoToKitchen(sRes.UpdatedItem, out outErr)) { foreach (string s in outErr) { UI.UIModify.ShowAlert(s); } } else { foreach (var d in sRes.UpdatedItem.DishPackages) { d.Printed = true; } } } } catch (Exception e) { logger.Error("Error save print " + e.Message); } if (Order.OrderStatus != OrderStatus.InWork) { var CreateSHres = SH.SHWrapper.CreateSalesInvoiceSync(Order, out string err); if (!CreateSHres) { UI.UIModify.ShowAlert($"{err + Environment.NewLine} Накладная будет создана при появлении связи со StoreHouse"); Models.ToGoOrdersModelSingleton.Instance.UpdateOrder(Order); } } if (NewOrder) { MainClass.AfterSaveNewToGoOrder(); } return(true); } catch (Exception e) { logger.Error($"SaveOrder Error {Order.Id} Mess: {e.Message}"); return(false); } finally { } }