private void DeleteRecordButton_Click(object sender, System.EventArgs e) { if (hookahStoreDataGridView.Rows.Count >= 1) { System.Windows.Forms.DialogResult dialogResult = Mbb.Windows.Forms.MessageBox.Show (text: $"{hookahStoreDataGridView.CurrentRow.Cells[0].Value} حذف گردد؟!", caption: "هشدار", icon: Mbb.Windows.Forms.MessageBoxIcon.Warning, button: Mbb.Windows.Forms.MessageBoxButtons.YesNo); if (dialogResult == System.Windows.Forms.DialogResult.Yes) //----جهت حذف مشترک { string hookahName = hookahStoreDataGridView.CurrentRow.Cells[0].Value.ToString(); using (Models.DataBaseContext dataBaseContext = new Models.DataBaseContext()) { Models.Hookah hookah = dataBaseContext.Hookahs .Where(current => string.Compare(current.HookahName, hookahName) == 0) .FirstOrDefault(); if (hookah != null) { var entry = dataBaseContext.Entry(hookah); if (entry.State == EntityState.Detached) { dataBaseContext.Hookahs.Attach(hookah); } } #region EventLog Username = Program.AuthenticatedUser.Username; FullName = $"{Program.AuthenticatedUser.First_Name} {Program.AuthenticatedUser.Last_Name}"; EventDate = $"{Infrastructure.Utility.PersianCalendar(System.DateTime.Now)}"; EventTime = $"{Infrastructure.Utility.ShowTime()}"; EventTitle = $"{hookahName} حذف گردید."; Infrastructure.Utility.EventLog(username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog dataBaseContext.Hookahs.Remove(hookah); dataBaseContext.SaveChanges(); HookahLoader(); } Infrastructure.Utility.WindowsNotification (message: "کد مورد نظر حذف گردید!", caption: Infrastructure.PopupNotificationForm.Caption.موفقیت); } } else { Mbb.Windows.Forms.MessageBox.Show (text: $"موردی برای حذف وجود ندارد!", caption: "اطلاع", icon: Mbb.Windows.Forms.MessageBoxIcon.Information, button: Mbb.Windows.Forms.MessageBoxButtons.Ok); return; } }