예제 #1
0
        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 aButtonDelete_Click(object sender, EventArgs e)
        {
            // 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 db = new DataAccess_LicensedMachinesTable();
                db.DeleteLicensedMachine(Convert.ToInt32(aDataGridViewMachines[0, aDataGridViewMachines.CurrentCell.RowIndex].FormattedValue), Config.DBDir_Name);
            }

            RefreshDataGridViewTable();
        }