Ejemplo n.º 1
0
        /// <summary>
        /// Verify machine doesn't already exist in Database
        /// </summary>
        /// <param name="LicensedMachineName"></param>
        /// <param name="DBDIR_Name"></param>
        public static bool MachineExist(string MachineToLookFor, string DBDIR_Name, out List <int> LicenseIDs)
        {
            DataAccess_LicensedMachinesTable DBLM       = new DataAccess_LicensedMachinesTable();
            List <LicensedMachines>          Duplicates = new List <LicensedMachines>();

            // SEARCH FOR DUPLICATES BY NAME
            Duplicates = DBLM.FindDuplicate(MachineToLookFor, DBDIR_Name);

            // DUPLICATE FOUND return true
            if (Duplicates.Count > 0)
            {
                List <int> DupLicenses = new List <int>();
                foreach (LicensedMachines machine in Duplicates)
                {
                    DupLicenses.Add(machine.LicenseId);;
                }
                LicenseIDs = DupLicenses; // Return License ID's
                return(true);             // Return Duplicate found = true;
            }
            else // NO DUPLICATE FOUND return false
            {
                LicenseIDs = null;
                return(false);
            }
        }
Ejemplo n.º 2
0
        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");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets count of machines assigned to a lincese
        /// </summary>
        /// <param name="idOfLicense"></param>
        /// <param name="DBDir_Name"></param>
        public static void GetMachineCount_toLabel(int idOfLicense, string DBDir_Name, Label Label)
        {
            // Get Machine Count for Label
            List <LicensedMachines> LM = DataAccess_LicensedMachinesTable.GetByLicenseID(idOfLicense, DBDir_Name);

            Label.Text = LM.Count.ToString();
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public void RefreshDataGridViewTable()
        {
            // Get Data from Database
            List <LicensedMachines>            LM         = DataAccess_LicensedMachinesTable.GetByLicenseID(InputLicense.Id, Config.DBDir_Name);
            BindingListView <LicensedMachines> SortableLM = new BindingListView <LicensedMachines>(LM);

            aDataGridViewMachines.DataSource = SortableLM;
            Utilities.CloseSQLConnection();
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        public static void GetMachineCount_UpdateDB(int idOfLicense, string DBDir_Name)
        {
            // get license
            License SourceLicense = DataAccess_GDataTable.GetByID(idOfLicense, DBDir_Name);
            // get license machines
            List <LicensedMachines> sourceLicenseMachines = DataAccess_LicensedMachinesTable.GetByLicenseID(SourceLicense.Id, DBDir_Name);

            // count license machines
            SourceLicense.PCCount = sourceLicenseMachines.Count();
            // update License in database with new count
            DataAccess_GDataTable.UpdateLicenseData(SourceLicense, DBDir_Name);
        }
Ejemplo n.º 8
0
        private void ManagePCsForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //ConfigClass Updated_Config = Utilities.GetConfigData();

            // Get Machine Count for Label
            List <LicensedMachines> LM = DataAccess_LicensedMachinesTable.GetByLicenseID(InputLicense.Id, Config.DBDir_Name);

            License ChangedLicense = new License();

            InputLicense.CopyDataTo(ChangedLicense);
            ChangedLicense.PCCount = LM.Count;
            DataAccess_GDataTable.UpdateLicenseData(ChangedLicense, Config.DBDir_Name);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Checks Database for Updates then asks to Update.
        /// </summary>
        /// <param name="Config"></param>
        public static void CheckDatabaseForUpdates(ConfigClass Config)
        {
            #region Check Licensed Machines Table
            Version DBVer = DataAccess_LicensedMachinesTable.CheckForUpdates(Config);
            #endregion

            #region Check GData Table
            //
            #endregion

            #region Check Change Log Table
            //
            #endregion

            // Compare DB Version to current software version.
            if (DBVer < Class_Library.Settings.CurrentSoftwareVersion)
            {
                // Update found
                string Message = $"Database outdated! " +
                                 $"\n Database Version: {DBVer.ToString()}" +
                                 $"\n Latest Version: {Class_Library.Settings.CurrentSoftwareVersion.ToString()}. " +
                                 $"\n What would you like to do?";

                ErrorForm    ErrForm = new ErrorForm(Message, "Update DB", "Create New DB");
                DialogResult result  = ErrForm.ShowDialog();

                // Solution to the error
                switch (result)
                {
                case DialogResult.Yes:
                    Utilities.UpdateDatabase(Config, DBVer.ToString());
                    break;

                case DialogResult.No:
                    // Create New Database
                    ConfigForm   CF  = new ConfigForm();
                    DialogResult _cf = CF.ShowDialog();
                    if (_cf == DialogResult.OK)
                    {
                        Config = CF.OutputConfig();
                    }
                    break;

                case DialogResult.Abort:
                    // Abort entire application
                    Application.Exit();
                    break;
                }
            }
        }
Ejemplo n.º 10
0
        private void AButtonMoveHere_Click(object sender, EventArgs e)
        {
            try
            {
                DataAccess_GDataTable db = new DataAccess_GDataTable();
                // GET ID OF DESTINATION LICENSE
                int     DestinationLicenseID = (Convert.ToInt32(aDataGridViewLicenses[0, aDataGridViewLicenses.CurrentCell.RowIndex].FormattedValue));
                License DestinationLicense   = db.GetByID(DestinationLicenseID, Config.DBDir_Name);
                // GET OLD LICENSE ID FOR UPDATING PURPOSES
                int     SourceLicenseID = SelectedMachines_Input[0].LicenseId;
                License SourceLicense   = db.GetByID(SourceLicenseID, Config.DBDir_Name);

                // UPDATE LICENSED MACHINES DATABASE
                DataAccess_LicensedMachinesTable DBLM = new DataAccess_LicensedMachinesTable();
                foreach (LicensedMachines machine in SelectedMachines_Input)
                {
                    // SET NEW LICENSEID
                    LicensedMachines OriginalMachine = new LicensedMachines();
                    LicensedMachines ChangedMachine  = new LicensedMachines();
                    machine.CopyDataTo(OriginalMachine);
                    machine.CopyDataTo(ChangedMachine);
                    ChangedMachine.LicenseId = DestinationLicenseID;
                    // UPDATE
                    DBLM.UpdateLicenseId(ChangedMachine, Config.DBDir_Name);
                    // FIND CHANGES MADE
                    List <string> ChangesMade = Utilities.FindChanges(OriginalMachine, ChangedMachine);
                    // CREATE LOG
                    Utilities.CreateLog(ChangesMade, SourceLicenseID);
                }

                // UPDATE MACHINE COUNT
                Utilities.GetMachineCount_UpdateDB(SourceLicenseID, Config.DBDir_Name);
                Utilities.GetMachineCount_UpdateDB(DestinationLicenseID, Config.DBDir_Name);



                // Success!
                MessageBox.Show($"Successfully moved {SelectedMachines_Input.Count} machine(s) " +
                                $"\nFrom {Utilities.GetLicenseName_s(SourceLicense)} ID: {SourceLicenseID.ToString()}" +
                                $"\nTo {Utilities.GetLicenseName_s(DestinationLicense)} ID: {DestinationLicenseID.ToString()}");

                Utilities.CloseSQLConnection();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
        }
Ejemplo n.º 11
0
        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 aButtonEdit_Click(object sender, EventArgs e)
        {
            // INSTANTIATE
            DataAccess_LicensedMachinesTable db    = new DataAccess_LicensedMachinesTable();
            EditLicensedMachineForm          Eform = new EditLicensedMachineForm();

            // GET MACHINE BY ID COLUMN OF SELECTED ROW
            Eform.InputMachine = db.GetByID(Convert.ToInt32(aDataGridViewMachines[0, aDataGridViewMachines.CurrentCell.RowIndex].FormattedValue), Config.DBDir_Name);
            // LAUNCH EDIT FORM
            DialogResult _eform = Eform.ShowDialog();

            if (_eform == DialogResult.OK)
            {
                RefreshDataGridViewTable();
            }
        }
Ejemplo n.º 13
0
        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
            {
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Update all Database Tables
        /// </summary>
        /// <param name="Config"></param>
        /// <param name="DBVer"></param>
        private static void UpdateDatabase(ConfigClass Config, string DBVer)
        {
            try
            {
                #region Update Licensed Machines Table
                DataAccess_LicensedMachinesTable.Update(Config.DBDir_Name, DBVer);
                #endregion

                #region Update GData Table

                #endregion

                #region Update Change Log Table

                #endregion
            }
            catch (Exception err)
            {
                MessageBox.Show($"The was an error! \n {err}");
            }
            MessageBox.Show("Database updated successfully!");
        }
        /// <summary>
        /// Do not access this directly! Use Utilities.CheckDatabaseForUpdates
        /// </summary>
        /// <param name="Config"></param>
        /// <returns></returns>
        public static Version CheckForUpdates(ConfigClass Config)
        {
            Version CurrentVersion; // Declare Return Variable
            // Get the version of the program. The Database should reflect this version if up to date.
            Version SoftwareVersion = new Version(System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString());

            #region Check for v1.3 (Renamed 'DateAdded' Column to 'InstallDate')
            if (!DataAccess_LicensedMachinesTable.ColumnExists(Config.DBDir_Name, "InstallDate") &&
                DataAccess_LicensedMachinesTable.ColumnExists(Config.DBDir_Name, "DateAdded"))
            {
                CurrentVersion = new Version("1.2.0.0");
                return(CurrentVersion);
            }
            #endregion
            // Add more If's for newer version changes here.

            //
            else // Database Should be up to date
            {
                return(SoftwareVersion);
            }
        }
        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();
        }
Ejemplo n.º 17
0
        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();
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Verify machine doesn't already exist in Database
        /// </summary>
        /// <param name="LicensedMachine"></param>
        /// <param name="DBDIR_Name"></param>
        /// <param name="LicenseIDs"></param>
        /// <returns></returns>
        public static bool MachineExist(LicensedMachines MachineBeingEdited, string MachineToLookFor, string DBDIR_Name, out List <int> LicenseIDs)
        {
            List <LicensedMachines> Duplicates = new List <LicensedMachines>();

            // SEARCH FOR DUPLICATES BY NAME
            Duplicates = DataAccess_LicensedMachinesTable.FindDuplicate(MachineToLookFor, DBDIR_Name);

            // COMPARE WITH LICENSE BEING EDITED
            List <LicensedMachines> VerifiedDuplicates = new List <LicensedMachines>();

            if (Duplicates.Count > 0)
            {
                foreach (LicensedMachines machine in Duplicates)
                {
                    // Verify the machine with identical name isn't the machine currently being created/edited
                    if (machine.Id != MachineBeingEdited.Id)
                    {
                        VerifiedDuplicates.Add(machine);
                    }
                }
            }

            // DUPLICATE FOUND return value and true
            if (VerifiedDuplicates.Count > 0)
            {
                List <int> DupLicenses = new List <int>();
                foreach (LicensedMachines machine in VerifiedDuplicates)
                {
                    DupLicenses.Add(machine.LicenseId);;
                }
                LicenseIDs = DupLicenses; // Return License ID's
                return(true);             // Return Duplicate found = true;
            }
            else // NO DUPLICATE FOUND return false
            {
                LicenseIDs = null;
                return(false);
            }
        }
        private void AButtonMove_Click(object sender, EventArgs e)
        {
            DataAccess_LicensedMachinesTable dblm = new DataAccess_LicensedMachinesTable();

            try
            {
                // GET ROW INDEX OF SELECTED CELL(S)
                List <int> rowIndexes = (from sc in aDataGridViewMachines.SelectedCells.Cast <DataGridViewCell>()
                                         select sc.RowIndex).Distinct().ToList();

                // GET ID OF EACH MACHINE SELECTED
                List <int> SelectedMachines_ID = new List <int>();
                foreach (int SelectedRow in rowIndexes)
                {
                    SelectedMachines_ID.Add(Convert.ToInt32(aDataGridViewMachines[0, SelectedRow].FormattedValue));
                }

                // GET LICENSED MACHINES SELECTED
                List <LicensedMachines> MachinesSelectedToMove = new List <LicensedMachines>();
                foreach (int MachineID in SelectedMachines_ID)
                {
                    MachinesSelectedToMove.Add(dblm.GetByID(MachineID, Config.DBDir_Name));
                }

                // LAUNCH MOVE FORM
                MoveForm moveForm = new MoveForm();
                moveForm.SelectedMachines_Input = MachinesSelectedToMove;
                DialogResult _moveForm = moveForm.ShowDialog();
                if (_moveForm == DialogResult.OK)
                {
                    RefreshDataGridViewTable();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
        }
Ejemplo n.º 20
0
        private void aButtonSave_Click(object sender, EventArgs e)
        {
            // Check if machine exists and if duplicates are allowed
            if (Utilities.MachineExist(InputMachine, 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 // if no duplicate and/or duplicates are allowed - edit machine name
            {
                InputMachine.CopyDataTo(ChangedLicense); // Used to get the ID and LicenseID of the input license.

                if (ChangedLicense != InputMachine)
                {
                    // IF DATE INSTALLED IS ENABLED GET DATE
                    ChangedLicense.InstallDate = aDateTimePickerInstalled.Enabled ? aDateTimePickerInstalled.Value.ToShortDateString() : null;

                    // GET THE REST OF THE DATA
                    ChangedLicense.MachineName  = aTextBoxMachineName.Text;
                    ChangedLicense.MachineNotes = aTextBoxNotes.Text;

                    // UPDATE DATABASE
                    DataAccess_LicensedMachinesTable.UpdateLicensedMachineData(ChangedLicense, Config.DBDir_Name);

                    // GET CHANGES MADE
                    List <string> changesmade = Utilities.FindChanges(InputMachine, ChangedLicense);

                    // CREATE CHANGES MADE LOG
                    Utilities.CreateLog(changesmade, InputMachine.LicenseId);
                    Utilities.CloseSQLConnection();
                }
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }