private void btnRemove_Click(object sender, EventArgs e) { string recordId = SelectedRowId(); if (recordId == null) { return; } var choice = XtraMessageBox.Show("Sure want to delete this record?", "?? :D ??", MessageBoxButtons.YesNo); if (choice == DialogResult.Yes) { try { using (var context = PharmacyDbContext.Create()) { var commodity = new Commodity { Id = int.Parse(recordId) }; context.Commodities.Attach(commodity); context.Commodities.Remove(commodity); context.SaveChanges(); } XtraMessageBox.Show("Remove successfully", "Pharmacy management"); RefillGrid(); } catch (Exception ex) { XtraMessageBox.Show($"Some error occured\nDetails:\n{ex.Message}", "Xome Pug Found"); } } }
private void UpdateUserDetails(string userName) { using (var dbContext = PharmacyDbContext.Create()) { var user = dbContext.Users .Where(u => u.UserName == userName) .Select(u => new UserViewModel { Id = u.Id, UserName = u.UserName, Address = u.Address, Birthday = u.Birthday, FullName = u.FullName, Gender = u.Gender, Image = u.Image, Created = u.Created, Role = u.Role }).FirstOrDefault(); if (user != null) { lblUsername.Text = user.UserName; lblFullName.Text = user.FullName; lblAddress.Text = user.Address; lblBirthDay.Text = user.Birthday.ToString("D"); lblRole.Text = user.Role.Name; picAvatar.Image = (user.Gender) ? global::PharmacyManagement.Properties.Resources._016_man : global::PharmacyManagement.Properties.Resources._015_woman; } else { lblUsername.Text = "Sellect a user"; lblFullName.Text = ""; lblAddress.Text = ""; lblBirthDay.Text = ""; lblRole.Text = ""; } } }
public PharmacyBusiness() { context = PharmacyDbContext.Create(); }