Beispiel #1
0
        /// <summary>
        /// Suppression del'article
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickDeleteItem(object sender, RoutedEventArgs e)
        {
            // the sender is a button

            try
            {
                var item = (ItemModel)((ListViewItem)lv_items.ContainerFromElement((Button)sender)).Content;
                var it   = db.ITEM.FirstOrDefault(i => i.id_item == item.Id);
                db.ITEM.Remove(it);
                db.SaveChanges();
                try
                {
                    var liste = (CategoryModel)lv_itemsCategory.SelectedItem;
                    if (liste != null)
                    {
                        lv_items.ItemsSource = mg.GetItemsByCat(liste.Id);
                    }
                }
                catch
                {
                }
            }
            catch (Exception ex)
            {
                DialogHost.Show(new Message()
                {
                    message_tb = { Text = "Supression impossible, vérifiez les affectations" }
                }, "RootDialog");
            }
        }
Beispiel #2
0
        private void OnCLickAddNewCat(object sender, RoutedEventArgs e)
        {
            try
            {
                if (IDSource == 2)
                {
                    CATEGORY_INGREDIENT ci = new CATEGORY_INGREDIENT();
                    if (!string.IsNullOrEmpty(tb_nameCat.Text))
                    {
                        ci.category_ingredient_title = tb_nameCat.Text.ToString();
                        db.CATEGORY_INGREDIENT.Add(ci);
                        db.SaveChanges();
                    }
                }
                if (IDSource == 1)
                {
                    CATEGORY c = new CATEGORY();
                    if (!string.IsNullOrEmpty(tb_nameCat.Text))
                    {
                        c.category_title       = tb_nameCat.Text.ToString();
                        c.category_description = "";

                        c.category_button_color = "#9b59b6";
                        db.CATEGORY.Add(c);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #3
0
        private void OnCLickAddNewItem(object sender, RoutedEventArgs e)
        {
            if (lv_items.SelectedItem != null)
            {
                ITEM item = lv_items.SelectedItem  as ITEM;
                MENU menu = new MENU();

                menu.menu_title = tb_MenuName.Text;
                menu.menu_price = Decimal.Parse(tb_MenuPrice.Text);
                menu.actif      = true;
                menu.id_item    = item.id_item;

                var idOptionChoixMenu = lv_options.SelectedItems;
                int count             = idOptionChoixMenu.Count;
                for (int i = 0; i < count; i++)
                {
                    var result = (OPTION_CHOIX_MENU)idOptionChoixMenu[i];
                    menu.OPTION_CHOIX_MENU.Add(result);
                }
                db.MENU.Add(menu);
                db.SaveChanges();
            }
            else
            {
                MessageBox.Show("Selectionnez un article");
            }
        }
Beispiel #4
0
        private void OnCLickAddMenuOption(object sender, RoutedEventArgs e)
        {
            OPTION_CHOIX_MENU ocm = new OPTION_CHOIX_MENU();
            var idItem            = (lv_items.SelectedItems);
            int count             = idItem.Count;

            ocm.option_choix_menu_title = tb_nameMenuOption.Text;
            db.OPTION_CHOIX_MENU.Add(ocm);
            for (int i = 0; i < count; i++)
            {
                var item = (ITEM)idItem[i];

                ITEM_OPTION_MENU iom = new ITEM_OPTION_MENU();
                iom.id_option_choix_menu = ocm.id_option_choix_menu;
                iom.id_item = item.id_item;
                iom.item_option_menu_quantity = 1;

                db.ITEM_OPTION_MENU.Add(iom);
            }
            db.SaveChanges();
        }
Beispiel #5
0
        private void OnClickAffect(object sender, RoutedEventArgs e)
        {
            int count = 0;
            //  var idCat = ((ItemsCategoryModel)lv_ingredientCategoryList.SelectedItem).Id;
            var idCatList = (lv_ingredientCategoryList.SelectedItems);

            count = idCatList.Count;
            using (var db = new ModelCezar())
            {
                try
                {
                    ITEM item = new ITEM {
                        id_item = IdItem
                    };
                    db.ITEM.Add(item);
                    db.ITEM.Attach(item);
                    for (int i = 0; i < count; i++)
                    {
                        var result = (ItemsCategoryModel)idCatList[i];

                        CATEGORY_INGREDIENT catIng = new CATEGORY_INGREDIENT {
                            id_category_ingredient = result.Id
                        };
                        db.CATEGORY_INGREDIENT.Add(catIng);
                        db.CATEGORY_INGREDIENT.Attach(catIng);

                        item.CATEGORY_INGREDIENT.Add(catIng);
                        db.SaveChanges();
                        rvm.Result        = true;
                        rvm.Resultmessage = "Validé";
                    }
                }
                catch (Exception ex)
                {
                    rvm.Resultmessage = "Erreur " + ex.InnerException;
                    rvm.Result        = false;
                }
            }
        }
Beispiel #6
0
        // Suppression d'une option
        private void OnClickDeleteOption(object sender, RoutedEventArgs e)
        {
            try
            {
                mg = new ManagementModel();
                ModelCezar db                 = new ModelCezar();
                var        itm                = (ItemModel)lv_items.SelectedItem;
                var        selectedOption     = (ItemsCategoryModel)((ListViewItem)lv_itemsOptions.ContainerFromElement((Button)sender)).Content;
                var        item               = db.ITEM.FirstOrDefault(it => it.id_item == idItem);
                var        categoryIngredient = db.CATEGORY_INGREDIENT.FirstOrDefault(c => c.id_category_ingredient == selectedOption.Id);

                item.CATEGORY_INGREDIENT.Remove(categoryIngredient);
                db.SaveChanges();

                lv_itemsOptions.ItemsSource = mg.GetItemsOptionsByItem(itm.Id);
            }
            catch (Exception ex)
            {
                DialogHost.Show(new Message()
                {
                    message_tb = { Text = "Suppression impossible" }
                }, "RootDialog");
            }
        }
Beispiel #7
0
        //Ajout/Modification d'un article
        private async void OnCLickAddNewItem(object sender, RoutedEventArgs e)
        {
            // A chaque "Click" sur le bouton ajouter, j'initialise les message
            tb_messageItem.Text = "";
            string message     = ""; // Message de resultat
            string infoMessage = "";

            if (IDSource == 1) //  Produit
            {
                try
                {
                    ITEM item = new ITEM();
                    // If update
                    if (IDItem > 0)
                    {
                        infoMessage = "modification";
                        ITEM itm = (from it in db.ITEM where it.id_item == IDItem select it).Single();

                        itm.item_title      = tb_name.Text;
                        itm.item_decription = tb_description.Text;

                        if (!string.IsNullOrEmpty(tb_price.Text))
                        {
                            itm.item_price = Decimal.Parse(tb_price.Text);
                        }
                        if (!string.IsNullOrEmpty(tb_pricePromo.Text))
                        {
                            itm.item_promotion_price = Decimal.Parse(tb_pricePromo.Text);
                        }
                        if (color != null)
                        {
                            itm.item_button_color = color.ToString();
                        }
                        itm.actif  = (bool)tg_actif.IsChecked;
                        itm.cooked = (bool)tg_cooked.IsChecked;
                        db.SaveChanges();


                        message    = "Le produit a été ajouté avec succès ";
                        rvm.Result = true;

                        _errors = new Errors();
                        gridForms.DataContext = _errors;

                        tb_messageItem.Visibility   = Visibility.Visible;
                        icon_messageItem.Visibility = Visibility.Visible;
                        tb_messageItem.Text         = message;
                        tb_messageItem.Foreground   = Brushes.DarkGreen;
                        icon_messageItem.Kind       = PackIconKind.CheckCircleOutline;
                        icon_messageItem.Foreground = Brushes.DarkGreen;
                    }
                    else// If add
                    {
                        infoMessage = "ajout";
                        if (!string.IsNullOrEmpty(tb_name.Text)) // Obligatoire
                        {
                            item.item_title = tb_name.Text;
                        }
                        else
                        {
                            return;
                        }
                        if (!string.IsNullOrEmpty(tb_description.Text))
                        {
                            item.item_decription = tb_description.Text;
                        }
                        if (!string.IsNullOrEmpty(tb_price.Text))// Obligatoire
                        {
                            item.item_price = Decimal.Parse(tb_price.Text);
                        }
                        else
                        {
                            return;
                        }
                        if (!string.IsNullOrEmpty(tb_pricePromo.Text))
                        {
                            item.item_promotion_price = Decimal.Parse(tb_pricePromo.Text);
                        }
                        if (color != null)
                        {
                            item.item_button_color = color.ToString();
                        }
                        if (color == null)
                        {
                            item.item_button_color = "#9b59b6";
                        }
                        item.actif       = (bool)tg_actif.IsChecked;
                        item.cooked      = (bool)tg_cooked.IsChecked;
                        item.id_category = IDCat;
                        db.ITEM.Add(item);
                        db.SaveChanges();


                        _errors = new Errors();
                        gridForms.DataContext = _errors;

                        tb_messageItem.Visibility   = Visibility.Visible;
                        icon_messageItem.Visibility = Visibility.Visible;
                        tb_messageItem.Text         = message;
                        tb_messageItem.Foreground   = Brushes.DarkGreen;
                        icon_messageItem.Kind       = PackIconKind.CheckCircleOutline;
                        icon_messageItem.Foreground = Brushes.DarkGreen;

                        message    = "Le produit a été ajouté avec succès ";
                        rvm.Result = true;
                    }
                }
                catch (Exception ex)
                {
                    tb_messageItem.Visibility   = Visibility.Visible;
                    icon_messageItem.Visibility = Visibility.Visible;
                    tb_messageItem.Text         = "Echec " + infoMessage + " de l'article " + ex.Message;
                    tb_messageItem.Foreground   = Brushes.DarkRed;
                    icon_messageItem.Kind       = PackIconKind.AlertCircleOutline;
                    icon_messageItem.Foreground = Brushes.DarkRed;
                    rvm.Result = false;
                }
            }
            if (IDSource == 2) // INGREDIENT
            {
                try
                {
                    INGREDIENT item = new INGREDIENT();
                    // If update
                    if (IDItem > 0)
                    {
                        infoMessage = "modification";
                        INGREDIENT itm = (from it in db.INGREDIENT where it.id_ingredient == IDItem select it).Single();

                        itm.ingredient_title       = tb_name.Text;
                        itm.ingredient_description = tb_description.Text;
                        if (!string.IsNullOrEmpty(tb_price.Text))
                        {
                            itm.ingredient_price = Decimal.Parse(tb_price.Text);
                        }

                        itm.actif = (bool)tg_actif.IsChecked;
                        db.SaveChanges();
                        message    = "l'ingrédient a été modifié avec succès ";
                        rvm.Result = true;
                    }
                    else// If add
                    {
                        infoMessage = "ajout";
                        if (!string.IsNullOrEmpty(tb_name.Text)) // Obligatoire
                        {
                            item.ingredient_title = tb_name.Text;
                        }
                        else
                        {
                            return;
                        }
                        if (!string.IsNullOrEmpty(tb_description.Text))
                        {
                            item.ingredient_description = tb_description.Text;
                        }
                        if (!string.IsNullOrEmpty(tb_price.Text))// Obligatoire
                        {
                            item.ingredient_price = Decimal.Parse(tb_price.Text);
                        }
                        else
                        {
                            return;
                        }

                        item.actif = (bool)tg_actif.IsChecked;
                        item.id_category_ingredient = IDCat;
                        db.INGREDIENT.Add(item);
                        db.SaveChanges();


                        _errors = new Errors();
                        gridForms.DataContext = _errors;

                        tb_messageItem.Visibility   = Visibility.Visible;
                        icon_messageItem.Visibility = Visibility.Visible;
                        tb_messageItem.Text         = message;
                        tb_messageItem.Foreground   = Brushes.DarkGreen;
                        icon_messageItem.Kind       = PackIconKind.CheckCircleOutline;
                        icon_messageItem.Foreground = Brushes.DarkGreen;

                        message    = "L'ingrédient a été ajouté avec succès ";
                        rvm.Result = true;
                    }
                }
                catch (Exception ex)
                {
                    tb_messageItem.Visibility   = Visibility.Visible;
                    icon_messageItem.Visibility = Visibility.Visible;
                    tb_messageItem.Text         = "Echec " + infoMessage + " de l'article " + ex.Message;
                    tb_messageItem.Foreground   = Brushes.DarkRed;
                    icon_messageItem.Kind       = PackIconKind.AlertCircleOutline;
                    icon_messageItem.Foreground = Brushes.DarkRed;
                    rvm.Result = false;
                }
            }

            //try
            //{
            //    // If update
            //    if (IDItem > 0)
            //    {
            //        infoMessage = "modification";
            //        ITEM itm = (from it in db.ITEM where it.id_item == IDItem select it).Single();

            //        itm.item_title = tb_name.Text;
            //        itm.item_decription = tb_description.Text;
            //        if (!string.IsNullOrEmpty(tb_price.Text))
            //        {
            //            itm.item_price = Decimal.Parse(tb_price.Text);
            //        }
            //        if (!string.IsNullOrEmpty(tb_pricePromo.Text))
            //        {
            //            itm.item_promotion_price = Decimal.Parse(tb_pricePromo.Text);
            //        }
            //        itm.item_button_color = color.ToString();
            //        itm.actif = (bool)tg_actif.IsChecked;
            //        db.SaveChanges();
            //        message = "l'article a été modifié avec succès ";
            //        rvm.Result = true;
            //    } // If add
            //    else
            //    {

            //    }

            //    // OK => Init UI
            //    _errors = new Errors();
            //    gridForms.DataContext = _errors;

            //    tb_messageItem.Visibility = Visibility.Visible;
            //    icon_messageItem.Visibility = Visibility.Visible;
            //    tb_messageItem.Text = message;
            //    tb_messageItem.Foreground = Brushes.DarkGreen;
            //    icon_messageItem.Kind = PackIconKind.CheckCircleOutline;
            //    icon_messageItem.Foreground = Brushes.DarkGreen;
            //}
            //catch (Exception ex)
            //{
            //    tb_messageItem.Visibility = Visibility.Visible;
            //    icon_messageItem.Visibility = Visibility.Visible;
            //    tb_messageItem.Text = "Echec " + infoMessage + " de l'article " + ex.Message;
            //    tb_messageItem.Foreground = Brushes.DarkRed;
            //    icon_messageItem.Kind = PackIconKind.AlertCircleOutline;
            //    icon_messageItem.Foreground = Brushes.DarkRed;
            //    rvm.Result = false;
            //}

            await Task.Run(() =>
            {
                Thread.Sleep(2000);
            });


            icon_messageItem.Visibility = Visibility.Collapsed;
            tb_messageItem.Text         = "Ajouter " + TitleCat;
            tb_messageItem.Foreground   = Brushes.DarkGreen;
            icon_messageItem.Kind       = PackIconKind.AccessPoint;
            icon_messageItem.Foreground = Brushes.DarkGreen;
        }
Beispiel #8
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();
        }