public void WireUpForm1() { // SELECT DEFAULT VIEW aComboboxSortBy.SelectedIndex = 0; DGVUtilities.SetSortationDefault(5, SortOrder.Descending, aDataGridViewLicenses); }
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 aButtonDeleteLog_Click(object sender, EventArgs e) { List <int> SelectedRows = new List <int>(); SelectedRows = DGVUtilities.DGVGetSelectedRows_Int(aDataGridViewLogs); // Gets Row Id of each selected row/cell. int SelectedRowIndex = aDataGridViewLogs.CurrentCell.RowIndex; if (SelectedRows.Count >= 1) { // VERIFY DELETE DialogResult dialogResultMulti = MessageBox.Show($"Are you sure you want to delete the selected logs from the database?", "Verification", MessageBoxButtons.YesNo); if (dialogResultMulti == DialogResult.Yes) { // DELETE SELECTED ROW/S foreach (int row in SelectedRows) { DataAccess_ChangeLogTable db = new DataAccess_ChangeLogTable(); db.DeleteLog(row, Config.DBDir_Name); } // REFRESH LOGS ViewLogsForm_Shown(this, e); if (SelectedRowIndex > 0) { aDataGridViewLogs.CurrentCell = aDataGridViewLogs.Rows[SelectedRowIndex - 1].Cells[1]; } else { aDataGridViewLogs.CurrentCell = aDataGridViewLogs.Rows[SelectedRowIndex].Cells[1]; } } } }
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 MoveForm_Shown(object sender, EventArgs e) { // GET DEFAULT DATA LicensesDGV = DataAccess_GDataTable.GetAllData(Config.DBDir_Name); // PUT DATA INTO SORTABLE LIST BindingListView <License> SortableLicensesDGV = new BindingListView <License>(LicensesDGV); // SET DGV.DATASOURCE aDataGridViewLicenses.DataSource = SortableLicensesDGV; // SET DEFAULT SORTATION DGVUtilities.SetSortationDefault(5, SortOrder.Descending, aDataGridViewLicenses); Utilities.CloseSQLConnection(); }
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); }
private void ADataGridViewLicenses_CellEnter(object sender, DataGridViewCellEventArgs e) { try { // GET LICENSED MACHINES OF SELECTED LICENSE int IDOfSelectedLicense = (Convert.ToInt32(aDataGridViewLicenses[0, aDataGridViewLicenses.CurrentCell.RowIndex].FormattedValue)); LicensedMachinesDGV = DataAccess_LicensedMachinesTable.GetByLicenseID(IDOfSelectedLicense, Config.DBDir_Name); BindingListView <LicensedMachines> SortableLicensedMachinesDGV = new BindingListView <LicensedMachines>(LicensedMachinesDGV); aDataGridViewMachines.DataSource = SortableLicensedMachinesDGV; DGVUtilities.SetSortationDefault(2, SortOrder.Ascending, aDataGridViewMachines); Utilities.CloseSQLConnection(); } catch { } }
/// <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(); }
private void Form1_Load(object sender, EventArgs e) { try { // VERIFY INTEGRITY OF CONFIG & DATABASE | GET CONFIG INFO //Config = Utilities.GetConfigData(); Config = Class_Library.Config.Get(); // Check If DB is current Version Utilities.CheckDatabaseForUpdates(Config); // Check if Licenses are up for renewal InitializeLicensesTTR(); // #Finish Setup# // SELECT DEFAULT VIEW aComboboxSortBy.SelectedIndex = 0; DGVUtilities.SetSortationDefault(5, SortOrder.Descending, aDataGridViewLicenses); } catch (System.Data.SqlClient.SqlException err) { // General SQL error message string errorMessage = $"Error message:\n\"{err.Message}\" \n\nWould you like to re-configure your database settings?"; // SQL Login Failed error message if (err.Message.Contains("Login Failed")) { errorMessage = $"Error message:\n\"{err.Message}\" " + $"\n\n" + $"This is likely due to another machine accessing the databse file. Typically this can be resolved by restarting the application." + $"\n\n" + $"Would you like to re-configure your database settings?"; } DialogResult dresult = MessageBox.Show(errorMessage, "Error!", MessageBoxButtons.YesNo); // Unable to Access Database if (dresult == DialogResult.Yes) // If user wants to change database directory { // SETUP CONFIG FORM -- to re-configure database ConfigForm _configform = new ConfigForm(); DialogResult _Configform = _configform.ShowDialog(); if (_Configform == DialogResult.OK) { Application.Restart(); // If User saves changes to Database directory } else { Application.Exit(); // If user decides to change nothing } } else // If user does NOT want to change database directory { Application.Exit(); } } catch (Exception err) { MessageBox.Show(err.ToString()); } }