Exemplo n.º 1
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());
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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 = "";
            }
        }
Exemplo n.º 4
0
        private void aButtonEdit_Click(object sender, EventArgs e)
        {
            License  SelectedLicense         = new License();
            License  SelectedLicense_Changed = new License();
            EditForm _editForm = new EditForm();
            // GET DATA
            DataAccess_GDataTable db = new DataAccess_GDataTable();

            try
            {
                // GET SELECTED LICENSE FROM DB VIA ID
                SelectedLicense = db.GetByID(Convert.ToInt32(aDataGridViewLicenses[0, aDataGridViewLicenses.CurrentCell.RowIndex].FormattedValue), Config.DBDir_Name);
            }
            catch
            {
                MessageBox.Show("Please Select a row");
                return;
            }

            // LAUNCH EDIT FORM
            if (SelectedLicense != null)
            {
                _editForm.InputLicense = SelectedLicense;                // Set License to be passed in
                DialogResult _form = _editForm.ShowDialog();
                if (_form == DialogResult.OK)                            // When editform.Savebutton is clicked
                {
                    SelectedLicense_Changed = _editForm.OutputLicense(); // launch Edit form and return values to SelectedLicense_Changed

                    if (SelectedLicense_Changed != SelectedLicense)
                    {
                        // Update SQL DB using changed License
                        db.UpdateLicenseData(SelectedLicense_Changed, Config.DBDir_Name);

                        // FIND CHANGES
                        List <string> ChangesMade = Utilities.FindChanges(SelectedLicense, SelectedLicense_Changed);
                        // CREATE/SAVE LOGS
                        Utilities.CreateLog(ChangesMade, SelectedLicense.Id);
                    }
                    RefreshDashboard(this, e);
                }
            }
            else
            {
                MessageBox.Show("No license selected to edit");
            }
            RefreshDashboard(this, e);
        }