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 aComboboxSortBy_SelectedIndexChanged(object sender, EventArgs e) { DataAccess_GDataTable db = new DataAccess_GDataTable(); Class_Library.DataGridView.DGVSortInfo SavedSortation = new Class_Library.DataGridView.DGVSortInfo(); SavedSortation = DGVUtilities.GetSortation(aDataGridViewLicenses); if (aComboboxSortBy.SelectedItem.ToString() == "Opened Licenses") { Utilities.EnableSearch(aButtonSearch, aTextBoxSearch, aLabelSearch, false); LicensesDGV = db.GetByReviewStatus("Open", Config.DBDir_Name); BindingListView <License> SortableLicensesDGV = new BindingListView <License>(LicensesDGV); aDataGridViewLicenses.DataSource = SortableLicensesDGV; aLabelLicenseFoundInt.Text = aDataGridViewLicenses.Rows.Count.ToString(); } if (aComboboxSortBy.SelectedItem.ToString() == @"Search by Name\Id") { Utilities.EnableSearch(aButtonSearch, aTextBoxSearch, aLabelSearch, true); } if (aComboboxSortBy.SelectedItem.ToString() == "Search by Machine Name") { Utilities.EnableSearch(aButtonSearch, aTextBoxSearch, aLabelSearch, true); } if (aComboboxSortBy.SelectedItem.ToString() == "All Licenses") { Utilities.EnableSearch(aButtonSearch, aTextBoxSearch, aLabelSearch, false); LicensesDGV = db.GetAllData(Config.DBDir_Name); BindingListView <License> SortableLicensesDGV = new BindingListView <License>(LicensesDGV); aDataGridViewLicenses.DataSource = SortableLicensesDGV; aLabelLicenseFoundInt.Text = aDataGridViewLicenses.Rows.Count.ToString(); } DGVUtilities.SetSortation(SavedSortation, aDataGridViewLicenses); Utilities.CloseSQLConnection(); }
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(); }