private void SaveExecute(object obj) { try { Queue <tblClinicMaintenance> queue = Service.Service.GetMaintenanceQueue(); string message; //just for adding new items if (!isEditingWindow) { message = "Clinic Maintenance has been added."; //if there is already 3 services, remove first one, then continue with adding if (queue != null && queue.Count == 3) { tblClinicMaintenance deleteThis = queue.Dequeue(); Service.Service.DeleteMaintenance(deleteThis); string content = "Clinic Maintenance id: " + deleteThis.maintenanceId + " has been deleted"; LogIntoFile.getInstance().PrintActionIntoFile(content); } } else { message = "Clinic Maintenance has been updated."; } tblClinicMaintenance maintenance = Service.Service.AddMaintenance(newMaintenance); if (maintenance != null) { MessageBox.Show(message); isUpdated = true; LogIntoFile.getInstance().PrintActionIntoFile(message + "Id: " + maintenance.maintenanceId); main.Close(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }