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]; } } } }
private void aButtonDelete_Click(object sender, EventArgs e) { int SelectedIndex = 0; string Name; try { // FIND NAME OF SELECTED ROW string Company = aDataGridViewLicenses[2, aDataGridViewLicenses.CurrentCell.RowIndex].FormattedValue.ToString(); string FirstName = aDataGridViewLicenses[3, aDataGridViewLicenses.CurrentCell.RowIndex].FormattedValue.ToString(); string LastName = aDataGridViewLicenses[4, aDataGridViewLicenses.CurrentCell.RowIndex].FormattedValue.ToString(); if (Company != "" && FirstName + LastName == "") { Name = Company; } else if (Company != "" && FirstName + LastName != "") { Name = $"{Company} ({FirstName} {LastName})"; } else { Name = $"{FirstName} {LastName}"; } } catch { MessageBox.Show("Please Select a row"); return; } // CONFIRM DELETE DialogResult dialogResult = MessageBox.Show($"Are you sure you want to delete '{Name}' from the database?", "Verification", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { // GET SELECTED ROW FOR PLACE HOLDER SelectedIndex = aDataGridViewLicenses.CurrentCell.RowIndex; DataAccess_GDataTable db = new DataAccess_GDataTable(); // GET ACCOUNTS ID for cleaning purposes int LicenseToDeleteID = Convert.ToInt32(aDataGridViewLicenses[0, aDataGridViewLicenses.CurrentCell.RowIndex].FormattedValue); // DELETE ASSOCIATED LOGS DataAccess_ChangeLogTable logdb = new DataAccess_ChangeLogTable(); logdb.DeleteLogByLicenseID(LicenseToDeleteID, Config.DBDir_Name); // DELETE ASSOCIATED MACHINES DataAccess_LicensedMachinesTable Machinesdb = new DataAccess_LicensedMachinesTable(); Machinesdb.DeleteLicensedMachineBYLicenseId(LicenseToDeleteID, Config.DBDir_Name); // DELETE LICENSE db.DeleteLicense(Convert.ToInt32(aDataGridViewLicenses[0, aDataGridViewLicenses.CurrentCell.RowIndex].FormattedValue), Config.DBDir_Name); } RefreshDashboard(this, e); }
public static void CreateLog(List <string> ChangesMade, int AccountIdentifier) { // GET DB DIRECTORY W/ DB NAME ConfigClass Config = Class_Library.Config.Get(); foreach (string change in ChangesMade) { // CREATE NEW LOG LogClass NewLog = new LogClass(); NewLog.LicenseId = AccountIdentifier; // Identify which account had the changes. DateTime dt = DateTime.Now; // Get current date/time NewLog.Date = dt; NewLog.Log = change; // SAVE NEW LOG DataAccess_ChangeLogTable.CreateNewLog(NewLog, Config.DBDir_Name); } }
private void ViewLogsForm_Shown(object sender, EventArgs e) { DataAccess_ChangeLogTable db = new DataAccess_ChangeLogTable(); if (GetAllLogs == true && InputLicense == null) { List <LogClass> Alllogs = db.GetLogs_GetAllLogs(Config.DBDir_Name); BindingListView <LogClass> AllSortableLogsDGV = new BindingListView <LogClass>(Alllogs); aDataGridViewLogs.DataSource = AllSortableLogsDGV; aDataGridViewLogs.Sort(aDataGridViewLogs.Columns[1], ListSortDirection.Descending); } if (GetAllLogs == false && InputLicense != null) { List <LogClass> logs = db.GetLogs_ByLicenseId(InputLicense.Id, Config.DBDir_Name); BindingListView <LogClass> SortableLogsDGV = new BindingListView <LogClass>(logs); aDataGridViewLogs.DataSource = SortableLogsDGV; aDataGridViewLogs.Sort(aDataGridViewLogs.Columns[1], ListSortDirection.Descending); } }
private void aButtonSave_Click(object sender, EventArgs e) { // VERIFY MACHINE DOESN'T EXIST ELSWHERE if (Utilities.MachineExist(aTextBoxMachineName.Text, Config.DBDir_Name, out List <int> LicenseIDofDupes) && Config.AllowDuplicateMachines == false) { // !ERROR! MessageBox.Show($"This machine name is already being used by License {LicenseIDofDupes[0].ToString()}. " + $"\nNo duplicates are allowed at this time. Please rename the machine and try again.", "Duplicate!", MessageBoxButtons.OK); return; } else { LicensedMachines NewMachine = new LicensedMachines(); // IF DATE INSTALLED IS ENABLED GET DATE NewMachine.InstallDate = aDateTimePickerInstalled.Enabled ? aDateTimePickerInstalled.Value.ToShortDateString() : null; // GET THE REST OF THE DATA NewMachine.MachineName = aTextBoxMachineName.Text; NewMachine.MachineNotes = aTextBoxNotes.Text; NewMachine.LicenseId = LicenseID; // UPDATE DATABASE DataAccess_LicensedMachinesTable.AddLicensedMachines(NewMachine, Config.DBDir_Name); // CREATE NEW MACHINE LOG LogClass NewLog = new LogClass(); NewLog.LicenseId = LicenseID; // Identify which account had the changes. DateTime dt = DateTime.Now; // Get current date/time NewLog.Date = dt; NewLog.Log = $"New Machine added: '{NewMachine.MachineName}'"; // SAVE NEW MACHINE LOG TO LOG DATABASE DataAccess_ChangeLogTable.CreateNewLog(NewLog, Config.DBDir_Name); Utilities.CloseSQLConnection(); this.DialogResult = DialogResult.OK; this.Close(); } }