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(); }
private void btnEditAccount_Click(object sender, EventArgs e) { using var dbcontext = new QuanLyQuanCafeContext(); string userName = txtAccountUserName.Text; string displayName = txtAccountDisplayName.Text; int type = (int)txtAccountType.Value; Account acc = dbcontext.Accounts.Where(x => userName.Equals(x.UserName)).SingleOrDefault(); acc.DisplayName = displayName; acc.Type = type; 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(); }
private void btnAddAccount_Click(object sender, EventArgs e) { using var dbcontext = new QuanLyQuanCafeContext(); string userName = txtAccountUserName.Text; string displayName = txtAccountDisplayName.Text; int type = (int)txtAccountType.Value; Account newAcc = new Account(); newAcc.UserName = userName; newAcc.DisplayName = displayName; newAcc.Type = type; dbcontext.Add(newAcc); int numberRows = dbcontext.SaveChanges(); if (numberRows > 0) { MessageBox.Show("Thêm tài khoản thành công"); LoadAccount(); } else { MessageBox.Show("Có lỗi khi thêm tài khoản"); } }
private void btnEditFood_Click(object sender, EventArgs e) { using var dbcontext = new QuanLyQuanCafeContext(); string name = txtFoodName.Text; int categoryID = (cbFoodCategory.SelectedItem as FoodCategory).Id; float price = (float)nudFoodPrice.Value; int id = Convert.ToInt32(txtFoodId.Text); Food food = dbcontext.Foods.Where(x => id.Equals(x.Id)).SingleOrDefault(); food.Name = name; food.IdCategory = categoryID; food.Price = price; int numberRows = dbcontext.SaveChanges(); if (numberRows > 0) { MessageBox.Show("Sửa món thành công"); LoadListFood(); } else { MessageBox.Show("Có lỗi khi sửa thức ăn"); } }
private void btnAddFood_Click(object sender, EventArgs e) { using var dbcontext = new QuanLyQuanCafeContext(); string name = txtFoodName.Text; int categoryID = (cbFoodCategory.SelectedItem as FoodCategory).Id; float price = (float)nudFoodPrice.Value; Food newfood = new Food(); newfood.Name = name; newfood.IdCategory = categoryID; newfood.Price = price; dbcontext.Add(newfood); int numberRows = dbcontext.SaveChanges(); if (numberRows > 0) { MessageBox.Show("Thêm món thành công"); LoadListFood(); } else { MessageBox.Show("Có lỗi khi thêm thức ăn"); } }
private void btnResetPassword_Click(object sender, EventArgs e) { using var dbcontext = new QuanLyQuanCafeContext(); string userName = txtAccountUserName.Text; Account acc = dbcontext.Accounts.Where(x => userName.Equals(x.UserName)).SingleOrDefault(); acc.PassWord = "******"; int numberRows = dbcontext.SaveChanges(); if (numberRows > 0) { MessageBox.Show("Đặt lại tài khoản thành công"); } else { MessageBox.Show("Đặt lại tài khoản thất bại"); } LoadAccount(); }
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"); } }