예제 #1
0
        protected override void Seed(SunwayCafeContext context)
        {
            context.Set <Account>().Add(new Account()
            {
                Username = "******", Password = "******", GivenName = "Kelvin", FamilyName = "Thoo", Gender = "Male", Contact = "018524644", Email = "*****@*****.**", Role = "Admin"
            });
            context.Set <Account>().Add(new Account()
            {
                Username = "******", Password = "******", GivenName = "Mu", FamilyName = "Cheng", Gender = "Female", Contact = "01824658463", Email = "*****@*****.**", Role = "Admin"
            });
            context.Set <Account>().Add(new Account()
            {
                Username = "******", Password = "******", GivenName = "Sam", FamilyName = "Cheng", Gender = "Male", Contact = "01304014041", Email = "*****@*****.**", Role = "SalesStaff"
            });
            context.Set <Account>().Add(new Account()
            {
                Username = "******", Password = "******", GivenName = "Chuan", FamilyName = "Yeppie", Gender = "Female", Contact = "0124578968", Email = "*****@*****.**", Role = "SalesStaff"
            });


            Image img  = Properties.Resources.banana;
            Image img2 = Properties.Resources.Korean_Burger;
            Image img3 = Properties.Resources.Ice_Lemon_Water;
            Image img4 = Properties.Resources.Milo_Ice;
            Image img5 = Properties.Resources.Banana_Cake;
            Image img6 = Properties.Resources.Korean_Fried_Rice;
            Image img7 = Properties.Resources.ButterMilk_Chicken;
            Image img8 = Properties.Resources.Nasi_Lemak;
            Image img9 = Properties.Resources.Cola;

            context.Set <Item>().Add(new Item()
            {
                Name = "Korean Burger", Type = "food", CostPrice = 7.00M, SellingPrice = 15.00M, ImageURL = Global.ConvertImageToBinary(img2)
            });
            context.Set <Item>().Add(new Item()
            {
                Name = "Banana Pie", Type = "food", CostPrice = 5.00M, SellingPrice = 2.00M, ImageURL = Global.ConvertImageToBinary(img)
            });
            context.Set <Item>().Add(new Item()
            {
                Name = "iced Lemon Water", Type = "drinks", CostPrice = 1.50M, SellingPrice = 2.50M, ImageURL = Global.ConvertImageToBinary(img3)
            });
            context.Set <Item>().Add(new Item()
            {
                Name = "Korean Fried Rice", Type = "food", CostPrice = 5.00M, SellingPrice = 12.00M, ImageURL = Global.ConvertImageToBinary(img6)
            });
            context.Set <Item>().Add(new Item()
            {
                Name = "Banana Cake", Type = "food", CostPrice = 8.00M, SellingPrice = 20.00M, ImageURL = Global.ConvertImageToBinary(img5)
            });
            context.Set <Item>().Add(new Item()
            {
                Name = "Milo Ice", Type = "drinks", CostPrice = 1.50M, SellingPrice = 3.50M, ImageURL = Global.ConvertImageToBinary(img4)
            });
            context.Set <Item>().Add(new Item()
            {
                Name = "Butter Milk Chicken", Type = "food", CostPrice = 5.50M, SellingPrice = 10.00M, ImageURL = Global.ConvertImageToBinary(img7)
            });
            context.Set <Item>().Add(new Item()
            {
                Name = "Nasi Lemak", Type = "food", CostPrice = 1.50M, SellingPrice = 4.50M, ImageURL = Global.ConvertImageToBinary(img8)
            });
            context.Set <Item>().Add(new Item()
            {
                Name = "Cola", Type = "drinks", CostPrice = 1.50M, SellingPrice = 2.50M, ImageURL = Global.ConvertImageToBinary(img9)
            });


            //hardcode order
            context.Set <Order>().Add(new Order()
            {
                NetPrice = 12, Status = "Processing", DateTimeCreated = Global.ConvToDateTimeString(DateTime.Now)
            });
            context.Set <Order>().Add(new Order()
            {
                NetPrice = 6, Status = "Processing", DateTimeCreated = Global.ConvToDateTimeString(DateTime.Now)
            });


            context.Set <OrderedItem>().Add(new OrderedItem()
            {
                OrderId = 1, ItemId = 1, Qty = 2
            });
            context.Set <OrderedItem>().Add(new OrderedItem()
            {
                OrderId = 1, ItemId = 2, Qty = 2
            });
            context.Set <OrderedItem>().Add(new OrderedItem()
            {
                OrderId = 1, ItemId = 3, Qty = 2
            });
            context.Set <OrderedItem>().Add(new OrderedItem()
            {
                OrderId = 1, ItemId = 4, Qty = 2
            });
            context.Set <OrderedItem>().Add(new OrderedItem()
            {
                OrderId = 1, ItemId = 5, Qty = 2
            });
            context.Set <OrderedItem>().Add(new OrderedItem()
            {
                OrderId = 1, ItemId = 6, Qty = 2
            });
            context.Set <OrderedItem>().Add(new OrderedItem()
            {
                OrderId = 1, ItemId = 7, Qty = 2
            });
            context.Set <OrderedItem>().Add(new OrderedItem()
            {
                OrderId = 1, ItemId = 8, Qty = 2
            });
            context.Set <OrderedItem>().Add(new OrderedItem()
            {
                OrderId = 2, ItemId = 3, Qty = 2
            });
            context.Set <OrderedItem>().Add(new OrderedItem()
            {
                OrderId = 2, ItemId = 4, Qty = 2
            });
            context.Set <OrderedItem>().Add(new OrderedItem()
            {
                OrderId = 2, ItemId = 7, Qty = 2
            });

            context.Set <Stock>().Add(new Stock()
            {
                Name = "Salt", Type = "Spice", Qty = "10", Unit = "Grams", CriticalLevel = "2"
            });
        }
예제 #2
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            Global.ClearErrors(errorProvider1, textBoxs);
            var success = true;

            if (!decimal.TryParse(priceBox.Text.Trim(), out decimal priceVal))
            {
                errorProvider1.SetError(priceBox, "Numbers only.");
                priceBox.BorderColor = Color.Red;
                success = false;
            }

            if (!decimal.TryParse(costPriceBox.Text.Trim(), out decimal costVal))
            {
                errorProvider1.SetError(costPriceBox, "Numbers only.");
                costPriceBox.BorderColor = Color.Red;
                success = false;
            }

            if (String.IsNullOrEmpty(textBox2.Text.Trim()))
            {
                errorProvider1.SetError(textBox2, "The Name field is required.");
                textBox2.BorderColor = Color.Red;
                success = false;
            }

            var msg = string.Empty;

            using (SunwayCafeContext db = new SunwayCafeContext())
            {
                if (success)
                {
                    if (button1.Text == "Create")
                    {
                        Item item = new Item()
                        {
                            Name         = textBox2.Text.Trim(),
                            ImageURL     = Global.ConvertImageToBinary(pictureBox.Image),
                            SellingPrice = priceVal,
                            CostPrice    = costVal,
                            Type         = Food.Checked ? Food.Text : Drinks.Text
                        };
                        db.Items.Add(item);
                        msg = "Item Created";
                    }
                    else
                    {
                        if (OrderOptions.selectItemName != null)
                        {
                            var item = db.Items.Where(d => d.Name == OrderOptions.selectItemName).First();
                            item.Name = textBox2.Text.Trim();
                            if (pictureBox.Image != OrderOptions.selectedItemImage)
                            {
                                item.ImageURL = Global.ConvertImageToBinary(pictureBox.Image);
                            }
                            item.SellingPrice = priceVal;
                            item.CostPrice    = costVal;
                            item.Type         = Food.Checked ? Food.Text : Drinks.Text;
                            msg = "Item Updated";
                        }
                    }

                    db.SaveChanges();
                    MessageBox.Show(msg);
                    itemPageRef.loadData();
                    this.Close();
                }
            }
        }