コード例 #1
0
        private void btnDeleteCategory_Click(object sender, EventArgs e)
        {
            if (dtgvCategory.CurrentCell == null)
            {
                MessageBox.Show("Bạn đã xóa hết danh sách danh mục", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string       nameFoodCategory = dtgvCategory.SelectedRows[0].Cells["Danh mục"].Value.ToString();
            FoodCategory foodCategory     = FoodCategoryDAO.Instence.getFoodCategoryByName(nameFoodCategory);

            if (MessageBox.Show("Bạn có chắc muốn xóa không? Việc này sẽ xóa cả danh sách thức ăn đi kèm và không thể hoàn tác", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                bool result = FoodCategoryDAO.Instence.DeleteFoodCategory(foodCategory.Id);

                if (result)
                {
                    MessageBox.Show("Xóa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LoadListFoodCategory();
                    LoadListFood();
                    LoadCategoryIntoCombobox(cbFoodCategory);

                    if (deleteFoodCategory != null)
                    {
                        deleteFoodCategory(this, new EventArgs());
                    }
                }
                else
                {
                    MessageBox.Show("Xóa không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #2
0
        private void cbCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox     cb           = sender as ComboBox;
            FoodCategory foodCategory = cb.SelectedItem as FoodCategory;

            LoadFoodListByCategoryID(foodCategory.Id);
        }
コード例 #3
0
        private void dtgvFood_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            Food         f  = new Food();
            FoodCategory fc = new FoodCategory();

            txtFoodID.Text   = dtgvFood.SelectedCells[0].OwningRow.Cells["id"].Value.ToString();
            txtFoodName.Text = dtgvFood.SelectedCells[0].OwningRow.Cells["Name"].Value.ToString();
            int s = Convert.ToInt32(dtgvFood.SelectedCells[0].OwningRow.Cells["idCategory"].Value.ToString());

            txtPrice.Text = dtgvFood.SelectedCells[0].OwningRow.Cells["Price"].Value.ToString();
        }
コード例 #4
0
 private void TxbFoodID_TextChanged(object sender, EventArgs e)
 {
     try
     {
         int          id           = (int)dgvFood.SelectedCells[0].OwningRow.Cells["IdCategory"].Value;
         FoodCategory foodCategory = FoodCategoryDAO.Instance.GetFoodCategoryById(id);
         cbFoodCategory.Text = foodCategory.Name;
     }
     catch
     {
     }
 }
コード例 #5
0
        private void cbCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            int      id = 1;
            ComboBox cb = sender as ComboBox;

            if (cb.SelectedItem == null)
            {
                return;
            }
            FoodCategory selected = cb.SelectedItem as FoodCategory;

            id = selected.id;
            LoadFoodListbyCategory(id);
        }
コード例 #6
0
        private void btnAddCategory_Click(object sender, EventArgs e)
        {
            if (txtCategoryName.Text == "")
            {
                MessageBox.Show("Xin nhập đầy đủ thông tin", "Thông báo", MessageBoxButtons.OK);
            }

            else
            {
                FoodCategory f = new FoodCategory();

                f.Name = txtCategoryName.Text;
                db.FoodCategories.Add(f);
                db.SaveChanges();
                MessageBox.Show("Thêm danh mục thành công", "Thông báo", MessageBoxButtons.OK);
                dtgvTable.DataSource = (from d in db.TableFoods where d.idStatusDelete == 0 select d).ToList();
                loadDateOnCbbFodoCategories();
            }
        }
コード例 #7
0
        private void btnEditCategory_Click(object sender, EventArgs e)
        {
            if (dtgvCategory.CurrentCell == null)
            {
                MessageBox.Show("Hãy thêm danh mục trước khi thực hiện chỉnh sủa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txbFoodCategory.Text == "")
            {
                MessageBox.Show("Hãy điền đầy đủ thông tin", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string       nameFoodCategory = dtgvCategory.SelectedRows[0].Cells["Danh mục"].Value.ToString();
            FoodCategory foodCategory     = FoodCategoryDAO.Instence.getFoodCategoryByName(nameFoodCategory);
            string       name             = txbFoodCategory.Text;
            bool         result           = FoodCategoryDAO.Instence.UpdateFoodCategory(foodCategory.Id, name);

            if (result)
            {
                MessageBox.Show("Cập nhập danh mục thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                LoadListFoodCategory();
                LoadListFood();
                LoadCategoryIntoCombobox(cbFoodCategory);

                if (updateFoodCategory != null)
                {
                    updateFoodCategory(this, new EventArgs());
                }
            }
            else
            {
                MessageBox.Show("Tên danh mục đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }