Пример #1
0
        private void b_addFoodDialogAccept_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tb_newFoodTextBox.Text))
            {
                lb_searchResults.ItemsSource = null;
                return;
            }

            var newFood = new Model.Food();

            newFood.name = tb_newFoodTextBox.Text;
            newFood.nutritionValuesString = temporaryNutritionValuesString;

            if (temporaryFood != null)
            {
                newFood.calories = APIRootObjectToNutritionValuesStringConverter.extractCaloriesFromAPIRootObject(temporaryFood);
            }
            else
            {
                newFood.calories = 0;
            }

            App._vmData.foodList.Add(newFood);

            temporaryNutritionValuesString = "";
            temporaryFood = null;

            FoodCalculation.calculateFood();
        }
Пример #2
0
        public static void UpdateFood(Model.Food food)
        {
            string query =
                "BEGIN " +
                "food_pkg.update_food(" + food.Id + ", '" + food.Name + "', " + food.Price + ", '" + food.Description + "', " + food.Type_Id + ", " + food.Discount_Rate + ", '" + food.Availability + "', " + food.Other_Charges + ", '" + food.Picture + "'); " +
                "END;";

            DB_Handler.ExecuteQuery(query);
        }
        private void BtnUpdate_Click(object sender, RoutedEventArgs e)
        {
            Model.Food foodNew = new Model.Food();
            if (id.Text == "")
            {
                MessageBox.Show("Vui lòng chọn món ăn trước khi cập nhật!!!");
                return;
            }
            foodNew.id          = id.Text;
            foodNew.name        = NameFood.Text;
            foodNew.price       = Price.Text;
            foodNew.ingredients = Ingredients.Text;
            foodNew.note        = Note.Text;

            if (TypeFood.SelectedIndex == 0)
            {
                foodNew.type = "appetizer";
            }
            else if (TypeFood.SelectedIndex == 1)
            {
                foodNew.type = "dish";
            }
            else
            {
                foodNew.type = "dessert";
            }
            foreach (var item in Foods)
            {
                if (item.name == NameFood.Text && item.id != id.Text)
                {
                    MessageBox.Show("Tên món ăn đã có!!!\n Bạn vui lòng chọn tên khác!");
                    return;
                }
            }
            ;

            string  result = API.UpdateFood(id.Text, foodNew);
            dynamic stuff  = JsonConvert.DeserializeObject(result);

            if (result == "")
            {
                return;
            }

            if (stuff.message == "Food updated successfully!")
            {
                MessageBox.Show("Cập nhật thông tin món ăn thành công!!!");
                Foods.Clear();
                Load();
                LoadEmpty();
            }
            else
            {
                MessageBox.Show("Có lỗi sảy ra trong quá trình cập nhật, vui lòng thử lại!!!");
            }
        }
Пример #4
0
 public static Model.Food RowToEntity(DataRow row)
 {
     Model.Food food = new Model.Food
     {
         Id            = Int32.Parse(row["Id"].ToString()),
         Name          = row["Name"].ToString(),
         Price         = Int32.Parse(row["Price"].ToString()),
         Description   = row["Description"].ToString(),
         Type_Id       = Int32.Parse(row["Type_Id"].ToString()),
         Discount_Rate = Int32.Parse(row["Discount_Rate"].ToString()),
         Availability  = row["Availability"].ToString(),
         Other_Charges = Int32.Parse(row["Other_Charges"].ToString()),
         Picture       = row["Picture"].ToString(),
         Stock_Count   = Int32.Parse(row["Stock_Count"].ToString())
     };
     return(food);
 }
        private async void DecreaseFood_Click(object sender, RoutedEventArgs e)
        {
            string selectedFoodName = ((TextBlock)((Grid)((Button)sender).Parent).Children[0]).Text;

            foreach (Order order in Orders)
            {
                if (order.name == selectedFoodName)
                {
                    if (order.amount > 0)
                    {
                        order.amount--;
                    }
                    else
                    {
                        Orders.Remove(order);
                    }

                    lvListBill.Items.Refresh();
                    break;
                }
            }

            foreach (Food item in AllFoods)
            {
                if (item.name == selectedFoodName)
                {
                    foodSelected = item;
                    break;
                }
            }
            await Task.Run(() =>
            {
                string result = API.DecreaseAmountFood(tableSelected.number, foodSelected);
                if (result == "")
                {
                    return;
                }
                dynamic stuff = JsonConvert.DeserializeObject(result);

                this.Dispatcher.Invoke(() =>
                {
                    UpdateBillLayout();
                });
            });
        }
        private void ListViewFood_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (((ListView)sender).SelectedIndex == -1)
            {
                return;
            }

            if (((ListView)sender).ItemContainerGenerator.ContainerFromIndex(((ListView)sender).SelectedIndex) is ListViewItem lvi)
            {
                var bc = new BrushConverter();

                for (int j = 0; j < Foods.Count; j++)
                {
                    ListViewItem lvi1 = ListViewFood.ItemContainerGenerator.ContainerFromIndex(j) as ListViewItem;
                    var          cp1  = VisualTreeHelperExtensions.FindVisualChild <ContentPresenter>(lvi1);

                    var dt1 = cp1.ContentTemplate as DataTemplate;
                    var rt1 = (Rectangle)dt1.FindName("BackGround", cp1);
                    var tb1 = (TextBlock)dt1.FindName("NameFood", cp1);
                    rt1.Fill = Brushes.White;
                }

                var cp = VisualTreeHelperExtensions.FindVisualChild <ContentPresenter>(lvi);

                var        dt           = cp.ContentTemplate as DataTemplate;
                var        rt           = (Rectangle)dt.FindName("BackGround", cp);
                var        tb           = (TextBlock)dt.FindName("NameFood", cp);
                Model.Food foodSelected = new Model.Food();

                foreach (var item in Foods)
                {
                    if (item.name == tb.Text)
                    {
                        foodSelected = item;
                        break;
                    }
                }
                ;

                NameFood.Text    = foodSelected.name;
                Price.Text       = foodSelected.price;
                Ingredients.Text = foodSelected.ingredients;
                Note.Text        = foodSelected.note;

                if (foodSelected.type == "appetizer")
                {
                    TypeFood.SelectedIndex = 0;
                }
                else if (foodSelected.type == "dish")
                {
                    TypeFood.SelectedIndex = 1;
                }
                else
                {
                    TypeFood.SelectedIndex = 2;
                }

                id.Text = foodSelected.id;

                btnUpdate.IsEnabled = true;
                btnDelete.IsEnabled = true;

                rt.Fill = (Brush)bc.ConvertFrom("#FF0BD9EE");
            }
        }
        private void ListViewFood_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (((ListView)sender).SelectedIndex == -1)
            {
                return;
            }

            if (((ListView)sender).ItemContainerGenerator.ContainerFromIndex(((ListView)sender).SelectedIndex) is ListViewItem lvi)
            {
                ListView ListViewSelected = (ListView)sender;
                var      bc = new BrushConverter();

                for (int j = 0; j < Food1.Count; j++)
                {
                    ListViewItem lvi1 = ListViewFood1.ItemContainerGenerator.ContainerFromIndex(j) as ListViewItem;
                    var          cp1  = VisualTreeHelperExtensions.FindVisualChild <ContentPresenter>(lvi1);

                    var dt1 = cp1.ContentTemplate as DataTemplate;
                    var rt1 = (Rectangle)dt1.FindName("BackGround", cp1);
                    var tb1 = (TextBlock)dt1.FindName("NameFood", cp1);
                    rt1.Fill = Brushes.White;
                }

                for (int j = 0; j < Food2.Count; j++)
                {
                    ListViewItem lvi2 = ListViewFood2.ItemContainerGenerator.ContainerFromIndex(j) as ListViewItem;
                    var          cp2  = VisualTreeHelperExtensions.FindVisualChild <ContentPresenter>(lvi2);

                    var dt2 = cp2.ContentTemplate as DataTemplate;
                    var rt2 = (Rectangle)dt2.FindName("BackGround", cp2);
                    var tb2 = (TextBlock)dt2.FindName("NameFood", cp2);
                    rt2.Fill = Brushes.White;
                }

                for (int j = 0; j < Food3.Count; j++)
                {
                    ListViewItem lvi3 = ListViewFood3.ItemContainerGenerator.ContainerFromIndex(j) as ListViewItem;
                    var          cp3  = VisualTreeHelperExtensions.FindVisualChild <ContentPresenter>(lvi3);

                    var dt3 = cp3.ContentTemplate as DataTemplate;
                    var rt3 = (Rectangle)dt3.FindName("BackGround", cp3);
                    var tb3 = (TextBlock)dt3.FindName("NameFood", cp3);
                    rt3.Fill = Brushes.White;
                }

                var cp = VisualTreeHelperExtensions.FindVisualChild <ContentPresenter>(lvi);

                var dt = cp.ContentTemplate as DataTemplate;
                var rt = (Rectangle)dt.FindName("BackGround", cp);
                var tb = (TextBlock)dt.FindName("NameFood", cp);
                rt.Fill = (Brush)bc.ConvertFrom("#FF0BD9EE");

                if (ListViewSelected.Name == "ListViewFood1")
                {
                    foreach (var item in Food1)
                    {
                        if (item.name == tb.Text)
                        {
                            foodSelected = item;
                            break;
                        }
                    }
                }
                else if (ListViewSelected.Name == "ListViewFood2")
                {
                    foreach (var item in Food2)
                    {
                        if (item.name == tb.Text)
                        {
                            foodSelected = item;
                            break;
                        }
                    }
                }
                else
                {
                    foreach (var item in Food3)
                    {
                        if (item.name == tb.Text)
                        {
                            foodSelected = item;
                            break;
                        }
                    }
                }

                string result = API.AddFoodInBill(tableSelected.number, foodSelected);
                if (result == "")
                {
                    return;
                }
                dynamic stuffAddFood = JsonConvert.DeserializeObject(result);

                if (stuffAddFood.message != "successfull")
                {
                    MessageBox.Show("Có lỗi sảy ra, vui lòng thử lại!!!");
                }
                else
                {
                    MessageBox.Show("Thêm món thành công!!!");
                    UpdateBillLayout();
                    rt.Fill = Brushes.White;
                }
            }
        }