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 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"); } }