private void DisplayTickets() { if (ShowTickets && Customer.Order.Seats.Count < 10) { Application.Current.Dispatcher.Invoke((Action) delegate { foreach (Seat seat in Customer.Order.Seats) { MemoryStream ms = GetTicketImage(Customer.Order.Id, seat.Id, 1); if (ms != null) { Spot spot = SelectedSpots.FirstOrDefault(x => x.Id == seat.Id); if (spot != null) { BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); spot.TicketImage = bi; } } } }); } }
/// <summary> /// Handles PurchaseOrder button on OrderWindow /// </summary> private void OnPurchaseOrder() { PaymentTypeBox ptb = new PaymentTypeBox(); bool? result = ptb.ShowDialog(); if (result ?? false) { BlankStatus = String.Empty; Customer.Order.Seats = new List <Seat>(); foreach (Ticket t in Tickets) { Seat seat = new Seat() { Id = t.Id }; Customer.Order.Seats.Add(seat); } Customer.Order.PaymentType = (PaymentType)Enum.Parse(typeof(PaymentType), SelectedPaymentType.Key.ToString(), true); Customer.Order = Customer.Order = Access.ConfirmPayment(Customer.Order); ReloadOrder(); if (Customer.Order != null && Customer.Order.Status == ItemStatus.Sold) { if (ShowTickets && Customer.Order.Seats.Count < 10) { Application.Current.Dispatcher.Invoke((Action) delegate { foreach (Seat seat in Customer.Order.Seats) { MemoryStream ms = GetTicketImage(Customer.Order.Id, seat.Id, 1); if (ms != null) { Spot spot = SelectedSpots.FirstOrDefault(x => x.Id == seat.Id); if (spot != null) { BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms; bi.EndInit(); spot.TicketImage = bi; } } } }); } } else { Customer.Order = new Order(); // Just not to be null OperationResult = String.Format("Произошла ошибка. Заказ № {0} не оплачен", Customer.Order.Id); } } }
/// <summary> /// Keeps SelectedSpots updated /// </summary> private void PersistSelectedSpots(List <Seat> seats) { foreach (Seat seat in seats) { Spot spot = SelectedSpots.FirstOrDefault(x => x.Id == seat.Id); if (spot != null) { spot.Status = seat.Status; spot.Result = seat.Result; spot.ReserveDate = seat.ReserveDate; } } }
/// <summary> /// Handles PayOrder button event and open PrintView in wizard /// </summary> private void OnPayOrder() { BlankStatus = String.Empty; // if View called from orders if (Customer.Order.Seats == null) { Customer.Order.Seats = new List <Seat>(); foreach (Ticket t in Tickets) { Seat seat = new Seat() { Id = t.Id }; Customer.Order.Seats.Add(seat); } } Customer.Order.PaymentType = (PaymentType)Enum.Parse(typeof(PaymentType), SelectedPaymentType.Key.ToString(), true); _worker = new BackgroundWorker(); _worker.DoWork += delegate { WizardProgressVisibility = Visibility.Visible; Customer.Order = Access.ConfirmPayment(Customer.Order); if (Customer.Order != null && Customer.Order.Status == ItemStatus.Sold) { Blank[] blanks = Access.GetBlanks(0, Customer.Order.ItemsCount, ItemStatus.OnSale); if (blanks != null) { if (blanks.Length != Customer.Order.ItemsCount) { BlankStatus = "Количество бланков недостаточно для печати заказа"; } } else { BlankStatus = "У вас отсутствуют бланки"; } for (int i = 0; i < Customer.Order.Seats.Count; i++) { Seat seat = Customer.Order.Seats[i]; Spot spot = SelectedSpots.FirstOrDefault(x => x.Id == seat.Id); if (spot != null) { spot.Status = seat.Status; //spot.Result = seat.Result; spot.ReserveDate = seat.ReserveDate; if (blanks != null && blanks.Length > i) { spot.Blank = blanks[i]; } } } //PersistSelectedSpots(Customer.Order.Seats); StatusText = OperationResult = String.Format("Заказ № {0} оплачен. Сумма заказа: {1}", Customer.Order.Id, OrderPrice.ToString("C")); if (_wizardWindow != null) { WizardTitle = "Печать заказа"; ContentWindow = new PrintViewModel(Instance); } _wisardStep = WisardStep.OrderPaid; DisplayTickets(); } else { Customer.Order = new Order(); // Just not to be null StatusText = OperationResult = String.Format("Произошла ошибка. Заказ № {0} не оплачен", Customer.Order.Id); } }; _worker.RunWorkerCompleted += delegate { WizardProgressVisibility = Visibility.Collapsed; }; _worker.RunWorkerAsync(); }