Beispiel #1
0
 public void delete(Food_Dish obj)
 {
     using (ModelContext db = new ModelContext())
     {
         db.Entry <Food_Dish>(obj).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
Beispiel #2
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure want to delete this dish ?", "Waring", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         Food_Dish fdish = foodDishBindingSource.Current as Food_Dish;
         Food_DishBUS.delete(fdish);
         foodDishBindingSource.DataSource = Food_DishBUS.GetAll();
     }
 }
Beispiel #3
0
        private void btnChangeQuan_Click(object sender, EventArgs e)
        {
            CusOrders cusO       = cusOrdersBindingSource.Current as CusOrders;
            Food_Dish fd         = Food_DishBUS.GetByName(cusO.name);
            CusOrders cusOder    = CusOrderBUS.GetByName(cusO.name);
            int       tempDish   = 0;
            int       changeQuan = int.Parse(txtChangeQuan.Text);

            if (changeQuan == 0 || txtChangeQuan.Text == " " || txtChangeQuan.Text == "")
            {
                MessageBox.Show("Number of dish can not be 0!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtChangeQuan.Clear();
                txtChangeQuan.Focus();
                foodDishBindingSource.DataSource = Food_DishBUS.dish_NotLocked();
                return;
            }
            else
            {
                if (cusO != null)
                {
                    if (changeQuan > fd.stock)
                    {
                        MessageBox.Show("Only " + fd.stock + "left!", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        cusOrdersBindingSource.DataSource = CusOrderBUS.GetAll();
                        return;
                    }
                    else
                    {
                        if (changeQuan > cusOder.numberDish)
                        {
                            tempDish = changeQuan - cusOder.numberDish;
                            CusOrderBUS.changeQuantity(cusO);
                            Food_DishBUS.stockCalulate(fd.Id, tempDish, true);
                            foodDishBindingSource.DataSource = Food_DishBUS.dish_NotLocked();
                            labelCost.Text = CusOrderBUS.TotalCost().ToString() + "$";
                        }
                        else
                        {
                            tempDish = cusOder.numberDish - changeQuan;
                            CusOrderBUS.changeQuantity(cusO);
                            Food_DishBUS.stockCalulate(fd.Id, tempDish, false);
                            foodDishBindingSource.DataSource = Food_DishBUS.dish_NotLocked();
                            labelCost.Text = CusOrderBUS.TotalCost().ToString() + "$";
                        }
                    }
                }
                else
                {
                    return;
                }
            }
        }
Beispiel #4
0
        private void btnLock_Unclock_Click(object sender, EventArgs e)
        {
            Food_Dish fd = foodDishBindingSource.Current as Food_Dish;

            if (fd == null)
            {
                return;
            }
            else
            {
                int id = fd.Id;
                Food_DishBUS.dishLock_Unlock(id);
                foodDishBindingSource.DataSource = Food_DishBUS.GetAll();
            }
        }
Beispiel #5
0
 private void btnBrowse_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog ofd = new OpenFileDialog()
     {
         Filter = "(*.jpg;*.jpeg;*.bmp;) | *.jpg;*.jpeg;*.bmp;"
     })
     {
         ofd.Multiselect = false;
         if (ofd.ShowDialog() == DialogResult.OK)
         {
             picBox.Image = Image.FromFile(ofd.FileName);
             Food_Dish fd = foodDishBindingSource.Current as Food_Dish;
             if (fd != null)
             {
                 fd.imaGeURL = ofd.FileName;
             }
         }
     }
 }
Beispiel #6
0
        private void dataGrid_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            Food_Dish fdish = foodDishBindingSource.Current as Food_Dish;

            if (fdish.Id != 0)
            {
                int typeID = fdish.TypeId;
                int sizeID = fdish.SizeId;
                foodTypeBindingSource.DataSource = Food_TypeBUS.showType(typeID);
                foodSizeBindingSource.DataSource = Food_SizeBUS.showSize(sizeID);
                if (fdish.imaGeURL != null)
                {
                    picBox.Image = Image.FromFile(fdish.imaGeURL);
                }
                else
                {
                    picBox.Image = null;
                }
            }
        }
Beispiel #7
0
        public void edit(Food_Dish dishEdit, string E_Dname, double E_DPrice, string E_DDescription, string E_DImage, string E_DType, string E_DSize, int E_DId, int E_DStock)
        {
            using (ModelContext db = new ModelContext())
            {
                Food_Size fsi  = db.size_list.FirstOrDefault(fsize => fsize.name == E_DSize);
                Food_Type ftyp = db.type_list.FirstOrDefault(typ => typ.nameType == E_DType);
                dishEdit = (from dish in db.dish_list
                            where dish.Id == E_DId
                            select dish).First();

                dishEdit.name        = E_Dname;
                dishEdit.price       = E_DPrice;
                dishEdit.description = E_DDescription;
                dishEdit.imaGeURL    = E_DImage;
                dishEdit.TypeId      = ftyp.Id;
                dishEdit.SizeId      = fsi.Id;
                dishEdit.stock       = E_DStock;
                db.SaveChanges();
            }
        }
Beispiel #8
0
        private void dataDishView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            txtChangeQuan.Enabled = false;
            btnChangeQuan.Enabled = false;
            txtNumberD.Enabled    = true;
            btnOrder.Enabled      = true;
            Food_Dish fdish = foodDishBindingSource.Current as Food_Dish;

            if (fdish.Id != 0)
            {
                int typeID = fdish.TypeId;
                int sizeID = fdish.SizeId;
                foodTypeBindingSource.DataSource = Food_TypeBUS.showType(typeID);
                foodSizeBindingSource.DataSource = Food_SizeBUS.showSize(sizeID);
                //picBox.Image = Image.FromFile(fdish.imaGeURL);
                txtNumberD.Clear();
            }
            else
            {
                return;
            }
        }
Beispiel #9
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            CusOrders cusOrder = cusOrdersBindingSource.Current as CusOrders;
            CusOrders cusO     = CusOrderBUS.GetByName(cusOrder.name);
            Food_Dish fd       = Food_DishBUS.GetByName(cusO.name);

            if (cusOrder != null)
            {
                Food_DishBUS.stockCalulate(fd.Id, cusO.numberDish, false);
                CusOrderBUS.delete(cusOrder);
                cusOrdersBindingSource.RemoveCurrent();
                labelCost.Text = CusOrderBUS.TotalCost().ToString() + "$";
                foodDishBindingSource.DataSource = Food_DishBUS.dish_NotLocked();
            }
            else
            {
                if (MessageBox.Show("List is empty! Please choose your food.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
                {
                    dataDishView.Focus();
                }
                return;
            }
        }
Beispiel #10
0
 public static void edit(Food_Dish dishEdit, string E_Dname, double E_DPrice, string E_DDescription, string E_DImage, string E_DType, string E_DSize, int E_DId, int E_DStock)
 {
     dish_act.edit(dishEdit, E_Dname, E_DPrice, E_DDescription, E_DImage, E_DType, E_DSize, E_DId, E_DStock);
 }
Beispiel #11
0
 public static void delete(Food_Dish Fdish)
 {
     dish_act.delete(Fdish);
 }
Beispiel #12
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Food_Dish fdish      = foodDishBindingSource.Current as Food_Dish;
            Food_Size fsize      = foodSizeBindingSource.Current as Food_Size;
            Food_Type ftype      = foodTypeBindingSource.Current as Food_Type;
            string    sizeName   = fsize.name;
            string    typeName   = ftype.nameType;
            string    D_Name     = txtD_Name.Text;
            double    D_Price    = double.Parse(txtD_Price.Text);
            string    D_Descript = txtD_Description.Text;
            string    D_ImageURL = fdish.imaGeURL;
            int       D_Stock    = int.Parse(txtStock.Text);
            int       D_Id       = fdish.Id;

            if (fdish == null)
            {
                MessageBox.Show("Nothing to edit!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                foodDishBindingSource.DataSource = Food_DishBUS.GetAll();
                return;
            }
            else
            {
                if (string.IsNullOrEmpty(txtD_Name.Text) || string.IsNullOrEmpty(txtD_Price.Text) || string.IsNullOrEmpty(txtD_Description.Text))
                {
                    MessageBox.Show("Please type all the information!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    if (fdish.Id == 0)
                    {
                        if (Food_DishBUS.chekName(txtD_Name.Text))
                        {
                            MessageBox.Show("This name is already exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                            txtD_Name.Clear();
                            txtD_Price.Clear();
                            txtD_Description.Clear();
                        }
                        else
                        {
                            Food_DishBUS.insert(D_Name, D_Price, D_Descript, D_ImageURL, typeName, sizeName, D_Stock);
                            MessageBox.Show("Insert successfully!", "Insert dish name", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            foodDishBindingSource.DataSource = Food_DishBUS.GetAll();
                            foodDishBindingSource.MoveLast();
                            panCRUD.Enabled      = true;
                            panFilter.Enabled    = true;
                            panSave.Enabled      = false;
                            dataGridDish.Enabled = true;
                        }
                    }
                    else
                    {
                        Food_DishBUS.edit(fdish, D_Name, D_Price, D_Descript, D_ImageURL, typeName, sizeName, D_Id, D_Stock);
                        MessageBox.Show("Update successfully!", "Update dish name", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        foodDishBindingSource.DataSource = Food_DishBUS.GetAll();
                        panCRUD.Enabled      = true;
                        panSave.Enabled      = false;
                        panFilter.Enabled    = true;
                        dataGridDish.Enabled = true;
                    }
                }
            }
        }
Beispiel #13
0
        private void btnOrder_Click(object sender, EventArgs e)
        {
            cusOrdersBindingSource.Add(new CusOrders());
            cusOrdersBindingSource.MoveLast();
            Food_Dish fd = foodDishBindingSource.Current as Food_Dish;

            if (fd != null)
            {
                Regex pattern = new Regex(@"[0-9]");
                if (pattern.IsMatch(txtNumberD.Text))
                {
                    string   dName  = fd.name;
                    double   dPrice = fd.price;
                    int      quantity;
                    DateTime orderdate = DateTime.Now;
                    if (int.TryParse(txtNumberD.Text, out quantity))
                    {
                        if (CusOrderBUS.check_DishExist(dName) == false)
                        {
                            if (fd.stock < quantity)
                            {
                                MessageBox.Show("Only " + fd.stock + "left!", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                txtNumberD.Focus();
                            }
                            else
                            {
                                CusOrderBUS.insert(dName, dPrice, quantity, orderdate);
                                cusOrdersBindingSource.MoveLast();
                                cusOrdersBindingSource.DataSource = CusOrderBUS.GetAll();
                                labelCost.Text = CusOrderBUS.TotalCost().ToString() + "$";
                                txtNumberD.Clear();
                                Food_DishBUS.stockCalulate(fd.Id, quantity, true);
                                foodDishBindingSource.DataSource = Food_DishBUS.dish_NotLocked();
                            }
                        }
                        else
                        {
                            MessageBox.Show("This food is already in your list! Please chood another food.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            dataDishView.Focus();
                            cusOrdersBindingSource.RemoveCurrent();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Wrong number! Please type your number again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtNumberD.Focus();
                        cusOrdersBindingSource.RemoveCurrent();
                    }
                }
                else
                {
                    if (MessageBox.Show("Please type the quantity of your dish!", "Missing your dish quantity!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information) == DialogResult.Retry)
                    {
                        cusOrdersBindingSource.MoveLast();
                        txtNumberD.Focus();
                        txtNumberD.Select();
                        cusOrdersBindingSource.RemoveCurrent();
                    }
                }
            }
            else
            {
                if (MessageBox.Show("Pleas choose your dish!", "Your order is empty!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Information) == DialogResult.Retry)
                {
                    txtNumberD.Clear();
                    dataDishView.Focus();
                    cusOrdersBindingSource.RemoveCurrent();
                }
            }
        }
Beispiel #14
0
 public void uploadImage(Food_Dish obj)
 {
     using (ModelContext db = new ModelContext())
     {
     }
 }