Exemplo n.º 1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            for (int i = 1; i < extra_cmbbx.Items.Count; i++)
            {
                string name = extra_cmbbx.Items[i].ToString();
                name = name.Substring(38);
                List <list_product> lst_p = new List <list_product>();
                lst_p = db1.list_product.ToList();
                bool flag = true;
                foreach (list_product lprod in lst_p)
                {
                    if (lprod.name == name)
                    {
                        flag = false;
                    }
                }
                if (flag)
                {
                    list_product lp = new list_product {
                        name = name, price = price, kind = "Extra"
                    };
                    db1.list_product.Add(lp);
                    db1.SaveChanges();
                }
            }
            List <list_product> lsp = new List <list_product>();

            lsp = db1.list_product.ToList();
            if (lsp.Count > 45)
            {
                for (int i = 45; i < lsp.Count; i++)
                {
                    if (lsp[i].kind == "Extra")
                    {
                        extra_cmbbx.Items.Add(lsp[i].name);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void add_product_btn_Click_1(object sender, RoutedEventArgs e)
        {
            int price = 0;

            if (name_add_product.Text != "" && price_add_product.Text != "" && kind_add_product.SelectedItem != null)
            {
                string name = name_add_product.Text;
                try
                {
                    price = Int32.Parse(price_add_product.Text);
                    string       kind = kind_add_product.Text;
                    list_product lstp = new list_product {
                        name = name, price = price, kind = kind
                    };
                    db1.list_product.Add(lstp);
                    db1.SaveChanges();
                    this.Close();
                }
                catch
                {
                    MessageBox.Show("enter the price", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
Exemplo n.º 3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < food_cmbbx.Items.Count; i++)
            {
                string name = food_cmbbx.Items[i].ToString();
                name = name.Substring(38);
                if (name == "Pizza")
                {
                    for (int j = 0; j < size_cmbbx.Items.Count; j++)
                    {
                        name += " " + size_cmbbx.Items[j].ToString();
                        name  = name.Remove(6, 38);
                        List <list_product> lstp = new List <list_product>();
                        lstp = db1.list_product.ToList();
                        bool flg = true;
                        foreach (list_product lprod in lstp)
                        {
                            if (lprod.name == name)
                            {
                                flg = false;
                            }
                        }
                        int pr = Calculating_price(name, i);
                        if (flg)
                        {
                            list_product lp = new list_product {
                                name = name, price = pr, kind = "Food"
                            };
                            db1.list_product.Add(lp);
                            db1.SaveChanges();
                        }
                        name = food_cmbbx.Items[i].ToString();
                        name = name.Substring(38);
                    }
                    i++;
                }
                name = food_cmbbx.Items[i].ToString();
                name = name.Substring(38);
                List <list_product> lst_p = new List <list_product>();
                lst_p = db1.list_product.ToList();
                bool flag = true;
                foreach (list_product lprod in lst_p)
                {
                    if (lprod.name == name)
                    {
                        flag = false;
                    }
                }
                int prc = Calculating_price(name, i);
                if (flag)
                {
                    list_product lp = new list_product {
                        name = name, price = prc, kind = "Food"
                    };
                    db1.list_product.Add(lp);
                    db1.SaveChanges();
                }
            }
            for (int i = 0; i < beverage_cmbbx.Items.Count; i++)
            {
                string name = beverage_cmbbx.Items[i].ToString();
                name = name.Substring(38);
                List <list_product> lst_p = new List <list_product>();
                lst_p = db1.list_product.ToList();
                bool flag = true;
                foreach (list_product lprod in lst_p)
                {
                    if (lprod.name == name)
                    {
                        flag = false;
                    }
                }
                int prc = Calculating_price(name, i);
                if (flag)
                {
                    list_product lp = new list_product {
                        name = name, price = prc, kind = "Beverage"
                    };
                    db1.list_product.Add(lp);
                    db1.SaveChanges();
                }
            }
            List <list_product> lsp = new List <list_product>();

            lsp = db1.list_product.ToList();
            if (lsp.Count > 45)
            {
                for (int i = 45; i < lsp.Count; i++)
                {
                    if (lsp[i].kind == "Food")
                    {
                        food_cmbbx.Items.Add(lsp[i].name);
                    }
                    if (lsp[i].kind == "Beverage")
                    {
                        beverage_cmbbx.Items.Add(lsp[i].name);
                    }
                }
            }
        }