Пример #1
0
        private void btnDeleteAccount_Click(object sender, EventArgs e)
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            string userName = txtAccountUserName.Text;

            if (loginAccount.UserName.Equals(userName))
            {
                MessageBox.Show("Bậy nào đừng xóa bản thân mình bạn êi");
                return;
            }

            Account acc = dbcontext.Accounts.Where(x => userName.Equals(x.UserName)).SingleOrDefault();

            dbcontext.Remove(acc);

            int numberRows = dbcontext.SaveChanges();

            if (numberRows > 0)
            {
                MessageBox.Show("Cập nhập tài khoản thành công");
            }
            else
            {
                MessageBox.Show("Cập nhập tài khoản thất bại");
            }

            LoadAccount();
        }
Пример #2
0
        private void btnDeleteFood_Click(object sender, EventArgs e)
        {
            using var dbcontext = new QuanLyQuanCafeContext();

            int id = Convert.ToInt32(txtFoodId.Text);

            Food food = dbcontext.Foods.Where(x => id.Equals(x.Id)).SingleOrDefault();

            dbcontext.BillInfos.Where(x => id.Equals(x.IdFood)).ToList().ForEach(x => { dbcontext.Remove(x); dbcontext.SaveChanges(); });

            dbcontext.Remove(food);

            int numberRows = dbcontext.SaveChanges();

            if (numberRows > 0)
            {
                MessageBox.Show("Xóa món thành công");
                LoadListFood();
            }
            else
            {
                MessageBox.Show("Có lỗi khi xóa thức ăn");
            }
        }