public static void SetSortationDefault(int Column, SortOrder Ascending_Descending, DataGridView DGVToSort) { // SET DEFAULT SORTATION Class_Library.DataGridView.DGVSortInfo DefaultSortation = new Class_Library.DataGridView.DGVSortInfo(); DefaultSortation.Sortation = Ascending_Descending; DefaultSortation.SortByColumn = Column; DGVUtilities.SetSortation(DefaultSortation, DGVToSort); }
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); }
private void aButtonSearch_Click(object sender, EventArgs e) { aTextBoxNotes.Text = ""; //GET SORTATION Class_Library.DataGridView.DGVSortInfo SavedSortation = DGVUtilities.GetSortation(aDataGridViewLicenses); if (aComboboxSortBy.SelectedItem.ToString() == @"Search by Name\Id") { // GET DATA BY NAME LicensesDGV = DataAccess_GDataTable.GetByName(aTextBoxSearch.Text, Config.DBDir_Name); } else if (aComboboxSortBy.SelectedItem.ToString() == "Search by Machine Name") { // GET DATA BY MACHINE NAME List <LicensedMachines> LicenseFound = DataAccess_LicensedMachinesTable.GetByMachineName(aTextBoxSearch.Text, Config.DBDir_Name); try { // FIND LICENSES BY MACHINE'S LICENSE ID List <License> TempLicensesDGV = new List <License>(); foreach (LicensedMachines _Lic in LicenseFound) { // COMPILE LIST FOR DGV TempLicensesDGV.Add(DataAccess_GDataTable.GetByID(_Lic.LicenseId, Config.DBDir_Name)); } // MOVE LIST TO DGV LicensesDGV = TempLicensesDGV; } catch (ArgumentOutOfRangeException) { } } // PUT DATA INTO SORTABLE LIST BindingListView <License> SortableLicensesDGV = new BindingListView <License>(LicensesDGV); // SET DGV.DATASOURCE aDataGridViewLicenses.DataSource = SortableLicensesDGV; aLabelLicenseFoundInt.Text = aDataGridViewLicenses.Rows.Count.ToString(); // SET SORTATION DGVUtilities.SetSortation(SavedSortation, aDataGridViewLicenses); Utilities.CloseSQLConnection(); // If no licenses were found, clear the notes text box. if (aDataGridViewLicenses.RowCount == 0) { aTextBoxNotes.Text = ""; } }
private void ATextBoxSearch_TextChanged(object sender, EventArgs e) { //GET SORTATION Class_Library.DataGridView.DGVSortInfo SavedSortation = DGVUtilities.GetSortation(aDataGridViewLicenses); // SEARCH FOR DATA LicensesDGV = DataAccess_GDataTable.GetByName(aTextBoxSearch.Text, Config.DBDir_Name); // PUT DATA INTO SORTABLE LIST BindingListView <License> SortableLicensesDGV = new BindingListView <License>(LicensesDGV); // SET DGV.DATASOURCE aDataGridViewLicenses.DataSource = SortableLicensesDGV; // SET SORTATION DGVUtilities.SetSortation(SavedSortation, aDataGridViewLicenses); }
/// <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(); }