private void aButtonEdit_Click(object sender, EventArgs e) { try { // SAVE POSITION AND SORTATION Class_Library.DataGridView.DGVPositionInfo DGVPOS = DGVUtilities.GetPosition(aDataGridViewMachines); Class_Library.DataGridView.DGVSortInfo DGVSortInfo = DGVUtilities.GetSortation(aDataGridViewMachines); EditLicensedMachineForm Eform = new EditLicensedMachineForm(); // GET MACHINE BY ID COLUMN OF SELECTED ROW Eform.InputMachine = DataAccess_LicensedMachinesTable.GetByID(Convert.ToInt32(aDataGridViewMachines[0, aDataGridViewMachines.CurrentCell.RowIndex].FormattedValue), Config.DBDir_Name); // LAUNCH EDIT FORM DialogResult _eform = Eform.ShowDialog(); if (_eform == DialogResult.OK) { RefreshDataGridViewTable(); // SET POSITION AND SORTATION DGVUtilities.SetPosition(DGVPOS, aDataGridViewMachines); // Check if user has sorted columns yet. If not, leave it at default (do nothing). if (DGVSortInfo.SortByColumn != 0 && DGVSortInfo.Sortation != SortOrder.None) { DGVUtilities.SetSortation(DGVSortInfo, aDataGridViewMachines); } } } catch (NullReferenceException) { MessageBox.Show("No machines are selected.", "Edit Failed"); } }
private void aButtonDelete_Click(object sender, EventArgs e) { // SAVE POSITION AND SORTATION Class_Library.DataGridView.DGVPositionInfo DGVPOS = DGVUtilities.GetPosition(aDataGridViewMachines); Class_Library.DataGridView.DGVSortInfo DGVSortInfo = DGVUtilities.GetSortation(aDataGridViewMachines); if (aDataGridViewMachines.SelectedCells.Count > 1) // IF MULTIPLE MACHINES ARE SELECTED { // INSTANTIATE LIST FOR STORING MACHINE ID'S List <int> SelectedMachines_ID = new List <int>(); // GET LIST OF MACHINE ID'S SelectedMachines_ID = DGVUtilities.DGVGetColumXofSelectedCell(aDataGridViewMachines, 0); DialogResult dialogResult = MessageBox.Show($"Are you sure you want to delete {SelectedMachines_ID.Count()} machines from the database?", "Verification", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { // GET CHANGES MADE List <string> ChangesMade = new List <string>(); ChangesMade.Add($"Deleted {SelectedMachines_ID.Count} machines."); // CREATE LOG OF DELETED MACHINE Utilities.CreateLog(ChangesMade, InputLicense.Id); // DELETE MACHINE DataAccess_LicensedMachinesTable.DeleteLicensedMachine(SelectedMachines_ID, Config.DBDir_Name); } } else if (aDataGridViewMachines.SelectedCells.Count == 1) // IF 1 MACHINE IS SELECTED { // CONFIRM DELETE string MachineName = $"{aDataGridViewMachines[2, aDataGridViewMachines.CurrentCell.RowIndex].FormattedValue.ToString()}"; DialogResult dialogResult = MessageBox.Show($"Are you sure you want to delete '{MachineName}' from the database?", "Verification", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { // GET CHANGES MADE List <string> ChangesMade = new List <string>(); ChangesMade.Add($"Deleted Machine: '{MachineName}'"); // CREATE LOG OF DELETED MACHINE Utilities.CreateLog(ChangesMade, InputLicense.Id); // DELETE MACHINE DataAccess_LicensedMachinesTable.DeleteLicensedMachine(Convert.ToInt32(aDataGridViewMachines[0, aDataGridViewMachines.CurrentCell.RowIndex].FormattedValue), Config.DBDir_Name); } } else // IF NO MACHINES ARE SELECTED { return; } RefreshDataGridViewTable(); // SET POSITION AND SORTATION DGVPOS.SelectedRow -= 1; // Minus 1 for cases where the last machine in the list was deleted. DGVUtilities.SetPosition(DGVPOS, aDataGridViewMachines); DGVUtilities.SetSortation(DGVSortInfo, aDataGridViewMachines); }
/// <summary> /// Refresh the DGV in Dashboard Form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void RefreshDashboard(object sender, EventArgs e) { aTextBoxNotes.Text = ""; // GET SORTATION INFO Class_Library.DataGridView.DGVSortInfo SavedSortation = DGVUtilities.GetSortation(aDataGridViewLicenses); // GET POSITION Class_Library.DataGridView.DGVPositionInfo SavedPosition = DGVUtilities.GetPosition(aDataGridViewLicenses); // REFRESH DASHBOARD aComboboxSortBy_SelectedIndexChanged(sender, e); aButtonSearch_Click(sender, e); // SET SORTATION DGVUtilities.SetSortation(SavedSortation, aDataGridViewLicenses); // SET POSITION DGVUtilities.SetPosition(SavedPosition, aDataGridViewLicenses); Utilities.CloseSQLConnection(); }