Exemplo n.º 1
0
 private void MetroSetButton1_Click(object sender, EventArgs e)
 {
     using (var db = new SunwayCafeContext())
     {
         var id    = int.Parse(orderID.Text);
         var query = db.OrderedItems.Where(x => x.OrderId == id).Select(x => x.Order).FirstOrDefault();
         query.Status         = "Closed";
         query.DateTimeClosed = Global.ConvToDateTimeString(DateTime.Now);
         db.SaveChanges();
     }
     kitchenPage.RefreshKitchenOrder();
 }
Exemplo n.º 2
0
        public BusinessReportPage()
        {
            InitializeComponent();

            using (var db = new SunwayCafeContext())
            {
                var orders = db.OrderedItems.Where(x => x.Order.Status == "Closed")
                             .GroupBy(x => x.ItemId)
                             .Select(x => new BusinessReport()
                {
                    Name             = x.FirstOrDefault().Item.Name,
                    Qty              = x.Sum(y => y.Qty),
                    UnitCostPrice    = x.FirstOrDefault().Item.CostPrice,
                    UnitSellingPrice = x.FirstOrDefault().Item.SellingPrice,
                }).ToList();

                var tcp = orders.Sum(x => x.TotalCostPrice);
                var tsp = orders.Sum(x => x.TotalSellingPrice);



                var param = new ReportParameter[]
                {
                    new ReportParameter("Date", Global.ConvToDateTimeString(DateTime.Now)),
                    new ReportParameter("TCP", $"{tcp:0.00}"),
                    new ReportParameter("TSP", $"{tsp:0.00}"),
                    new ReportParameter("TOrder", $"{db.Orders.Where(x => x.Status == "Closed").Count()}"),
                    new ReportParameter("TSST", $"{tsp * 0.06M:0.00}"),
                    new ReportParameter("TSC", $"{tsp * 0.10M:0.00}"),
                    new ReportParameter("TRevenue", $"{tsp - tcp:0.00}"),
                };

                //create a dummy data set
                var ds = new ReportDataSource("BusinessReport", orders.OrderBy(x => x.Name));
                reportViewer1.LocalReport.SetParameters(param);
                reportViewer1.LocalReport.DataSources.Clear();
                reportViewer1.LocalReport.DataSources.Add(ds);
                reportViewer1.RefreshReport();
            }
        }
Exemplo n.º 3
0
        private void Pay_Click_1(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count - 1 <= 0)
            {
                MessageBox.Show("Zero item detected. Please order at least one item.", "Empty Order", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                decimal py;
                if (decimal.TryParse(payment.Text, out py))
                {
                    if (py < decimal.Parse(lbltotal.Text))
                    {
                        MessageBox.Show("Payment must be higher or equal to total.", "Insufficient Payment", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        var order = new Order()
                        {
                            NetPrice        = decimal.Parse(lbltotal.Text) / 1.16M,
                            TotalPrice      = decimal.Parse(lbltotal.Text),
                            Status          = "Processing",
                            DateTimeCreated = Global.ConvToDateTimeString(DateTime.Now),
                        };

                        using (var db = new SunwayCafeContext())
                        {
                            var lst = new List <OrderedItem>();
                            //Add all item object from datagrid using id
                            for (int i = 0; i < DataGridView1.Rows.Count - 1; i++)
                            {
                                var id   = Convert.ToInt32((dataGridView1.Rows[i].Cells[0].Value));
                                var item = db.Items.Where(x => x.Id == id).FirstOrDefault();
                                if (item == null)
                                {
                                    MessageBox.Show("Unable to retrieve item from database", "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                                else
                                {
                                    lst.Add(new OrderedItem()
                                    {
                                        Order = order,
                                        Item  = item,
                                        Qty   = Convert.ToInt32((dataGridView1.Rows[i].Cells["Quantity1"].Value))
                                    });
                                }
                            }

                            order.OrderedItems = lst;
                            db.Orders.Add(order);
                            db.SaveChanges();
                        }

                        var receiptItems = new List <ReceiptItem>();
                        foreach (var item in order.OrderedItems)
                        {
                            receiptItems.Add(new ReceiptItem()
                            {
                                Qty = item.Qty, Name = item.Item.Name, UnitPrice = item.Item.SellingPrice
                            });
                        }


                        var reportPage = new ReceiptPage(new Receipt()
                        {
                            Subtotal     = order.NetPrice,
                            ReceiptItems = receiptItems,
                            Date         = order.DateTimeCreated,
                            OrderType    = radioButton1.Checked ? radioButton1.Text : radioButton2.Text,
                            Payment      = py
                        });

                        dataGridView1.Rows.Clear();
                        lbltotal.Text = "0.00";
                        payment.Text  = "0.00";

                        reportPage.Show();
                    }
                }
                else
                {
                    MessageBox.Show("Please enter number only", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Exemplo n.º 4
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"
            });
        }