Beispiel #1
0
        private void eatin(object sender, RoutedEventArgs e)
        {
            ORDERS         orderModel    = new ORDERS();
            item_selection itemSelection = new item_selection();
            var            testValue     = db.ORDERS.OrderByDescending(p => p.orders_number).Where(p => p.id_orders_type == 1).Select(q => q.orders_number).FirstOrDefault();


            orderModel.orders_number     = Service.GetNextCode("SPL", testValue);
            orderModel.id_orders_status  = 1;
            orderModel.id_orders_type    = Convert.ToInt32(((Button)sender).Tag);
            orderModel.orders_date       = DateTime.Today;
            orderModel.orders_delay_date = null;
            orderModel.orders_price      = (decimal)totalPrice;     // total commande
            orderModel.orders_leftToPay  = (decimal)totalRestPrice; // reste à payer

            db.ORDERS.Add(orderModel);
            db.SaveChanges();

            int idOrder = orderModel.id_orders;

            foreach (var item in cartList)
            {
                itemSelection = new item_selection();



                if (item.SelectedIngredients != null && item.SelectedIngredients.Count > 0)
                {
                    foreach (var subItem in item.SelectedIngredients)
                    {
                        itemSelection.id_item                 = item.ItemId;
                        itemSelection.id_orders               = idOrder;
                        itemSelection.id_ingredient           = subItem.IdIngredient;
                        itemSelection.item_selection_quantity = item.ItemQuantity;
                        db.item_selection.Add(itemSelection);
                        db.SaveChanges();
                    }
                }
                else
                {
                    itemSelection.id_item   = item.ItemId;
                    itemSelection.id_orders = idOrder;
                    itemSelection.item_selection_quantity = item.ItemQuantity;
                    db.item_selection.Add(itemSelection);
                    db.SaveChanges();
                }
            }


            cvm.Payement  = new ObservableCollection <Payement>();
            cvm.TotalCart = null;
            cvm.TotalRest = null;
            new Commandes();
            #region PRINT
            // Show Print Dialog
            PrintDialog printDialog = new PrintDialog();

            FlowDocument document = new FlowDocument();
            System.Windows.Documents.Paragraph par = new System.Windows.Documents.Paragraph();
            par.FontFamily = new System.Windows.Media.FontFamily("Times");
            System.Windows.Documents.Paragraph subPar = new System.Windows.Documents.Paragraph();
            document.ColumnWidth = printDialog.PrintableAreaWidth;
            document.PagePadding = new Thickness(25);
            Span s = new Span();
            s = new Span(new Run("Le Cezar food"));
            s.Inlines.Add(new LineBreak()); //Line break is used for next line.
            par.Inlines.Add(s);             // Add the span content into paragraph.


            par.Inlines.Add(new Span(new Run("Ticket fabrication")));
            par.Inlines.Add(new LineBreak()); //Line break is used for next line.
            par.Inlines.Add(new Span(new Run("Sur place")));
            par.Inlines.Add(new LineBreak()); //Line break is used for next line.
            par.Inlines.Add(new Span(new Run("Commande n° " + orderModel.orders_number)));
            par.Inlines.Add(new LineBreak()); //Line break is used for next line.
            par.Inlines.Add(new Span(new Run("-------------------------------------")));
            document.Blocks.Add(par);

            foreach (var item in cartList.Where(c => c.Cooked == true))
            {
                par               = new System.Windows.Documents.Paragraph(new Run(item.ItemQuantity.ToString() + " x " + item.ItemTitle.ToString()));
                par.FontSize      = 14;
                par.TextAlignment = TextAlignment.Left;
                document.Blocks.Add(par);
                if (item.SelectedIngredients != null)
                {
                    subPar = new System.Windows.Documents.Paragraph();
                    foreach (var subItem in item.SelectedIngredients)
                    {
                        subPar.Inlines.Add(new Span(new Run(subItem.Ingredient_quantity + " x " + subItem.Ingredient_title.ToString())));
                        subPar.Inlines.Add(new Span(new Run("   ")));
                        subPar.FontSize      = 12;
                        subPar.TextAlignment = TextAlignment.Center;
                        document.Blocks.Add(subPar);
                    }
                }
            }
            System.Windows.Documents.Paragraph par1 = new System.Windows.Documents.Paragraph();

            par1.Inlines.Add(new LineBreak());//Line break is used for next line.
            par1.Inlines.Add(new Span(new Run("-------------------------------------")));

            document.Blocks.Add(par1);
            foreach (var item in cartList.Where(c => c.Cooked == false))
            {
                par1               = new System.Windows.Documents.Paragraph(new Run(item.ItemQuantity.ToString() + " x " + item.ItemTitle.ToString()));
                par1.FontSize      = 14;
                par1.TextAlignment = TextAlignment.Left;
                document.Blocks.Add(par1);
            }


            //Config printer
            //var query = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");
            //var printers = query.Get();
            //string printerName = Properties.Settings.Default.printerName;

            //foreach (ManagementObject p in printers)
            //{
            //    if (p["name"].ToString() == printerName.ToString())
            //    {
            //        p.InvokeMethod("SetDefaultPrinter", null, null);
            //    }
            //}


            //document.Blocks.Add(par);
            //  fdViewer.Document = document;



            IDocumentPaginatorSource idpSource = document;
            printDialog.PrintDocument(idpSource.DocumentPaginator, "Receipt");
            //Give style and formatting to paragraph content.
            //par.FontSize = 14;
            //par.FontStyle = FontStyles.Normal;
            //par.TextAlignment = TextAlignment.Left;
            //document.Blocks.Add(par);
            //  DoThePrint(document);

            #endregion
            //ExportDataTableToPdf(cartList, @"C:\Users\Wave\Documents\Visual Studio 2015\Projects\Le cezar food caisse\CezarCaisse_v.0.1\Ecom\Resources\test.pdf", "Friend List");
            cartList.Clear();
        }
Beispiel #2
0
 public OrderViewModel()
 {
     orders        = new ORDERS();
     itemSelection = new item_selection();
 }