示例#1
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                int      selectedBillItemId = int.Parse(dataGridView4.SelectedCells[0].Value.ToString());
                BillItem item = billItems.Where(d => d.id == selectedBillItemId).FirstOrDefault();

                using (Database2019EntitiesRevision database = new Database2019EntitiesRevision())
                {
                    List <Recipe> recipes = database.Recipes.Where(d => d.menu == selectedBillItemId).ToList <Recipe>();

                    recipes.ForEach(d =>
                    {
                        List <Material> materials           = database.Materials.Where(da => da.Id == d.material).ToList <Material>();
                        materials.ForEach(res => res.stock += d.material_consume * item.quantity);

                        database.SaveChanges();
                    });
                }

                billItems.Remove(item);
                refreshBillFix();
                MessageBox.Show("Bill Item Canceled!");
            } catch
            {
                MessageBox.Show("Please select bill item first.");
            }
        }
示例#2
0
        private void refreshBillFix()
        {
            using (Database2019EntitiesRevision database = new Database2019EntitiesRevision())
            {
                dataGridView4.DataSource = null;
                int total = 0;

                List <BillItem> newBills = new List <BillItem>();
                billItems.ForEach(d =>
                {
                    BillItem billItem = new BillItem();
                    billItem.id       = d.id;
                    billItem.name     = d.name;
                    billItem.quantity = d.quantity;
                    billItem.price    = d.price;

                    newBills.Add(billItem);
                    total += d.price;
                });

                dataGridView4.DataSource = newBills;
                textBox2.Text            = total.ToString();

                if (newBills.Count > 0)
                {
                    button1.Enabled = true;
                    button2.Enabled = true;
                }
                else
                {
                    button1.Enabled = false;
                    button2.Enabled = true;
                }
            }
        }
示例#3
0
        private void createOrder(Order order)
        {
            using (Database2019EntitiesRevision database = new Database2019EntitiesRevision())
            {
                try
                {
                    database.Orders.Add(order);
                    Order order1 = new Order();
                    database.SaveChanges();

                    //billItems.ForEach(d =>
                    //{
                    //  OrderItem orderItem = new OrderItem();
                    //orderItem.menu = d.id;
                    //orderItem.order = order1.Id;
                    //orderItem.quantity = d.quantity;

                    //database.OrderItems.Add(orderItem);
                    //database.SaveChanges();
                    //});
                    billItems = new List <BillItem>();
                    refreshBillFix();
                    refreshOrder();
                }
                catch
                {
                    MessageBox.Show("Failed!");
                }
            }
        }
示例#4
0
        private void refreshOrder()
        {
            using (Database2019EntitiesRevision database = new Database2019EntitiesRevision())
            {
                dataGridView3.DataSource = null;

                List <OrderData> orderDatas = new List <OrderData>();
                List <Order>     orders     = database.Orders.Where(d => d.status == 0).ToList <Order>();

                orders.ForEach(d =>
                {
                    OrderData orderData = new OrderData();
                    orderData.id        = d.Id;

                    Member member          = database.Members.Where(e => e.Id == d.member).FirstOrDefault();
                    orderData.customerName = member.name;
                    orderData.date         = (DateTime)d.date;
                    orderData.totalBill    = (int)d.total;

                    orderDatas.Add(orderData);
                });

                dataGridView3.DataSource = orderDatas;
                refreshIncome();
            }
        }
示例#5
0
 private void loadMenu()
 {
     using (Database2019EntitiesRevision database = new Database2019EntitiesRevision())
     {
         List <MenuView> list = database.MenuViews.ToList <MenuView>();
         dataGridView1.DataSource = list;
     }
 }
示例#6
0
        private List <MenuView> searchMenu(string keyword)
        {
            using (Database2019EntitiesRevision database = new Database2019EntitiesRevision())
            {
                List <MenuView> list = database.MenuViews.Where(d => d.name.Contains(keyword)).ToList <MenuView>();

                return(list);
            }
        }
示例#7
0
 private void loadCustomer()
 {
     using (Database2019EntitiesRevision database = new Database2019EntitiesRevision())
     {
         List <Member> members = database.Members.Where(d => d.role == 2).ToList <Member>();
         comboBox1.DataSource    = members;
         comboBox1.DisplayMember = "name";
         comboBox1.ValueMember   = "Id";
     }
 }
示例#8
0
        private void addBillItem()
        {
            try
            {
                int selected = Convert.ToInt32(dataGridView1.SelectedCells[0].Value);

                using (AddToBill form = new AddToBill(selected))
                {
                    var result = form.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        using (Database2019EntitiesRevision database = new Database2019EntitiesRevision())
                        {
                            Menu          menu    = database.Menus.Where(d => d.Id == selected).FirstOrDefault <Menu>();
                            List <Recipe> recipes = database.Recipes.Where(d => d.Id == menu.Id).ToList <Recipe>();

                            recipes.ForEach(d =>
                            {
                                List <Material> materials = database.Materials.Where(da => da.Id == d.material)
                                                            .ToList <Material>();
                                materials.ForEach(da => da.stock = da.stock - d.material_consume * form.quantity);

                                database.SaveChanges();
                            });

                            int index = billItems.FindIndex(d => d.id == menu.Id);

                            if (index == -1)
                            {
                                BillItem newBill = new BillItem();
                                newBill.id       = menu.Id;
                                newBill.name     = menu.name;
                                newBill.quantity = form.quantity;
                                newBill.price    = Convert.ToInt32(menu.price);

                                billItems.Add(newBill);
                            }
                            else
                            {
                                billItems[index].quantity += form.quantity;
                                billItems[index].price     = billItems[index].quantity * (int)menu.price;
                            }


                            refreshBillFix();
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("No Selected Item.");
            }
        }
示例#9
0
        private void loadMenuDetail()
        {
            using (Database2019EntitiesRevision database = new Database2019EntitiesRevision())
            {
                Menu menu = database.Menus.Where(d => d.Id == selectedMenu).FirstOrDefault <Menu>();

                label3.Text   = menu.name;
                label7.Text   = "Rp. " + menu.price;
                textBox1.Text = (menu.price * quantity).ToString();
            }
        }
示例#10
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (Database2019EntitiesRevision database = new Database2019EntitiesRevision())
     {
         Member member = database.Members.Where(d => d.username == textBox1.Text && d.password == maskedTextBox1.Text)
                         .FirstOrDefault <Member>();
         id_user  = member.Id;
         userView = database.UserViews.Where(d => d.Id == id_user)
                    .FirstOrDefault <UserView>();
         this.DialogResult = DialogResult.OK;
     }
 }
示例#11
0
        private void loadRecipe()
        {
            listBox1.Items.Clear();

            using (Database2019EntitiesRevision database = new Database2019EntitiesRevision())
            {
                List <Recipe>       recipes       = database.Recipes.Where(d => d.menu == selectedMenu).ToList <Recipe>();
                List <RecipeObject> recipeObjects = new List <RecipeObject>();

                recipes.ForEach(d => {
                    listBox1.Items.Add(d.Material1.name + " (Need " + (d.material_consume * quantity) + " from " + d.Material1.stock + ") " + (d.Material1.stock >= (d.material_consume * quantity) ? "Enought Material" : "Not Enought Material Stock"));
                });
            }
        }
示例#12
0
        private void refreshIncome()
        {
            using (Database2019EntitiesRevision database = new Database2019EntitiesRevision())
            {
                List <Order> orders = database.Orders.ToList <Order>();
                int          total  = 0;

                if (orders.Count > 0)
                {
                    orders.ForEach(d => total += (int)d.total);
                }

                label10.Text = total.ToString();
            }
        }