Example #1
0
        public string GetDetailsCSV(List <TicketDetail> details)
        {
            var results = TicketDetail.GetTitlesCSV();

            foreach (var detail in details)
            {
                results += detail.ToCSV();
            }
            return(results);
        }
Example #2
0
        private void SubmitOrder(bool isQuickSale)
        {
            try
            {
                var shouldContinue = true;

                if (!isQuickSale)
                {
                    if (string.IsNullOrEmpty(txtName.Text.Trim()) && string.IsNullOrEmpty(comboName.Text.Trim()))
                    {
                        MessageBox.Show("Valid name required");
                        shouldContinue = false;
                    }
                    else if ((comboDates.SelectedItem == null || comboTimes.SelectedItem == null) &&
                             _programState == ProgramState.Presale)
                    {
                        MessageBox.Show("Valid date and time required");
                        shouldContinue = false;
                    }
                    else if (string.IsNullOrEmpty(txtTicket.Text) && _programState == ProgramState.EventDay &&
                             !chkToGo.IsChecked.Value)
                    {
                        MessageBox.Show("Enter valid table number");
                        shouldContinue = false;
                    }
                    else if (_orderTotal <= 0)
                    {
                        MessageBox.Show("Invalid total price");
                        shouldContinue = false;
                    }
                }
                if (shouldContinue)
                {
                    if (_savedTotal > 0 && Math.Abs(_savedTotal - FloatSafeParse(txtTotal.Text)) > 0)
                    {
                        MessageBox.Show("Total price must be " + _savedTotal.ToString("C"));
                        shouldContinue = false;
                    }
                }

                if (shouldContinue)
                {
                    if (_programState == ProgramState.EventDay && _savedTotal > 0)
                    {
                        //_orderNumber
                        using (var context = new SalesEntities())
                        {
                            var detailsToDelete = context.TicketDetails.Where(x => x.OrderGuid == _orderGuid);
                            if (detailsToDelete.Any())
                            {
                                context.TicketDetails.RemoveRange(detailsToDelete);
                            }

                            foreach (var item in _totalList)
                            {
                                var ticketDetails = new TicketDetail();
                                ticketDetails.ItemName  = item.Name;
                                ticketDetails.ItemPrice = item.Price;
                                ticketDetails.OrderGuid = _orderGuid;
                                context.TicketDetails.Add(ticketDetails);
                            }
                            context.SaveChanges();
                        }
                    }

                    _savedTotal = 0;
                    var eventDate   = GetEventDate();
                    var isToGo      = chkToGo.IsChecked ?? false;
                    var isFulfilled = false;
                    var isWalkUp    = false;
                    var tableNumber = txtTicket.Text ?? "";

                    if (_programState == ProgramState.Presale)
                    {
                        eventDate = (DateTime)comboTimes.SelectedItem;
                    }
                    else
                    {
                        isFulfilled = true;
                    }

                    if (_programState == ProgramState.EventDay && string.IsNullOrEmpty(_orderNumber))
                    {
                        isWalkUp = true;
                    }

                    var isNewOrder = false;

                    if (isWalkUp)
                    {
                        isNewOrder = true;
                    }
                    else if (_programState == ProgramState.Presale)
                    {
                        isNewOrder = true;
                    }

                    if (isNewOrder)
                    {
                        var paymentWindow = new PaymentWindow();
                        paymentWindow.ShowDialog();

                        var paymentType = paymentWindow.PaymentType;
                        if (string.IsNullOrEmpty(paymentType))
                        {
                            return;
                        }

                        var ticketSale = new TicketSale();
                        var guid       = Guid.NewGuid().ToString();

                        ticketSale.Name = txtName.Text.Trim().ToUpper();
                        if (isQuickSale)
                        {
                            ticketSale.Name = "OTHER";
                        }
                        else if (_programState == ProgramState.EventDay)
                        {
                            ticketSale.Name = comboName.Text.ToUpper();
                        }
                        if (!string.IsNullOrEmpty(txtNotes.Text))
                        {
                            ticketSale.Notes = txtNotes.Text;
                        }
                        ticketSale.PaymentType = paymentType;
                        ticketSale.EventDate   = eventDate;
                        ticketSale.OrderGuid   = guid;
                        ticketSale.IsFulfilled = isFulfilled;
                        ticketSale.IsToGo      = isToGo;
                        ticketSale.IsWalkUp    = isWalkUp;
                        ticketSale.IsValid     = true;
                        ticketSale.CreateDate  = DateTime.Now;
                        ticketSale.OrderNumber = string.Format("{0}-{1}", DateTime.Now.Year,
                                                               Math.Round((DateTime.Now - new DateTime(DateTime.Now.Year, 1, 1)).TotalMilliseconds));

                        using (var context = new SalesEntities())
                        {
                            context.TicketSales.Add(ticketSale);
                            foreach (var item in _totalList)
                            {
                                var ticketDetails = new TicketDetail();
                                ticketDetails.ItemName  = item.Name;
                                ticketDetails.ItemPrice = item.Price;
                                ticketDetails.OrderGuid = guid;
                                context.TicketDetails.Add(ticketDetails);
                            }
                            context.SaveChanges();

                            var printerLogic = new PrinterLogic();
                            if (!isQuickSale)
                            {
                                if (_programState == ProgramState.Presale)
                                {
                                    printerLogic.PrintPreSaleReceipt(_totalList, ticketSale.Name, ticketSale.EventDate,
                                                                     ticketSale.OrderNumber, string.Empty, "Men's Fellowship Copy");
                                    printerLogic.PrintPreSaleReceipt(_totalList, ticketSale.Name, ticketSale.EventDate,
                                                                     ticketSale.OrderNumber, string.Empty, "Customer Copy");
                                }
                                else
                                {
                                    printerLogic.PrintEventDaySaleReceipt(_totalList, ticketSale.Name,
                                                                          ticketSale.EventDate,
                                                                          ticketSale.OrderNumber, tableNumber, isToGo, ticketSale.Notes,
                                                                          "Men's Fellowship Copy");
                                    printerLogic.PrintEventDaySaleReceipt(_totalList, ticketSale.Name,
                                                                          ticketSale.EventDate,
                                                                          ticketSale.OrderNumber, tableNumber, isToGo, ticketSale.Notes, "Customer Copy");
                                    printerLogic.PrintKitchenReceipt(_totalList, ticketSale.Name, ticketSale.EventDate,
                                                                     ticketSale.OrderNumber, tableNumber, isToGo, isWalkUp, ticketSale.Notes);
                                }
                            }
                            var backup = new Backup()
                            {
                                EventDates    = context.EventDates.ToList(),
                                SaleItems     = context.SaleItems.ToList(),
                                TicketDetails = context.TicketDetails.ToList(),
                                TicketSales   = context.TicketSales.ToList()
                            };
                            BackupData(backup);
                        }
                    }
                    else
                    {
                        using (var context = new SalesEntities())
                        {
                            var sale = context.TicketSales.FirstOrDefault(x => x.OrderNumber == _orderNumber);
                            if (sale != null)
                            {
                                sale.IsFulfilled = true;
                                sale.IsToGo      = chkToGo.IsChecked ?? false;
                                if (!string.IsNullOrEmpty(txtNotes.Text))
                                {
                                    sale.Notes = txtNotes.Text;
                                }
                                context.SaveChanges();

                                var printerLogic = new PrinterLogic();
                                printerLogic.PrintEventDaySaleReceipt(_totalList, comboName.Text, DateTime.Now, _orderNumber, tableNumber, isToGo, txtNotes.Text, "Men's Fellowship Copy");
                                printerLogic.PrintKitchenReceipt(_totalList, comboName.Text, DateTime.Now, _orderNumber, tableNumber, isToGo, isWalkUp, sale.Notes);
                            }
                        }
                    }

                    if (_programState == ProgramState.EventDay && _totalList.Any(x => x.Name == "Drink" || x.Name == "Raffle"))
                    {
                        var totalDrinks = _totalList.Count(x => x.Name == "Drink");
                        var totalRaffle = _totalList.Count(x => x.Name == "Raffle");
                        if (totalDrinks > 0)
                        {
                            MessageBox.Show("Has customer received " + totalDrinks + " drink tickets?", "Drink Tickets",
                                            MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
                        }

                        if (isNewOrder && totalRaffle > 0)
                        {
                            MessageBox.Show("Has customer received " + totalRaffle + " raffle tickets?", "Raffle Tickets",
                                            MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
                        }
                    }

                    MessageBox.Show("Order Completed");
                    ResetScreen();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }