Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public void InitializeLicensesTTR() // Determine if licenses are up for renewal
        {
            List <License>        AllLicenses = new List <License>();
            DataAccess_GDataTable db          = new DataAccess_GDataTable();

            try
            {
                AllLicenses = db.GetAllData(Config.DBDir_Name);
            }
            catch (Exception err) // GetAllData failed
            {
            }


            foreach (License _License in AllLicenses)
            {
                //DateTime ExpDate = DateTime.Parse(_License.ExpirationDate);
                if (DateTime.Now >= _License.ExpirationDate.AddDays(-(Convert.ToInt32(Config.TimeToRenew))) && _License.Active == true && _License.RenewalStatus == "Renewed") // If it expires within 21 days and is currently active
                {
                    _License.ReviewStatus  = "Open";
                    _License.RenewalStatus = "";
                    db.UpdateLicenseData(_License, Config.DBDir_Name);
                }
            }
            Utilities.CloseSQLConnection();
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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.º 5
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);
        }
Exemplo n.º 6
0
        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();
        }
Exemplo n.º 7
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.º 8
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.º 9
0
        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);
        }
Exemplo n.º 10
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);
        }
        /// <summary>
        /// This is only used when the DB structure has changed.
        /// </summary>
        /// <param name="OldDBDir"></param>
        /// <param name="NewDBDir"></param>
        public void MoveDBtoNewDB(string OldDBDir, string NewDBDir)
        {
            DataAccess_GDataTable db             = new DataAccess_GDataTable();
            List <License>        OldLicenseData = db.GetAllData(OldDBDir);


            for (int i = 0; i < OldLicenseData.Count; i++)
            {
                foreach (License _Lic in OldLicenseData)
                {
                    if (_Lic.Id == i)
                    {
                        string   _CompanyName      = Utilities.CorrectApostropheForSQL(_Lic.CompanyName);
                        string   _FirstName        = Utilities.CorrectApostropheForSQL(_Lic.FirstName);
                        string   _LastName         = Utilities.CorrectApostropheForSQL(_Lic.LastName);
                        string   _ReviewStatus     = _Lic.ReviewStatus;
                        DateTime ExpDate           = _Lic.ExpirationDate;
                        int      _PCCount          = _Lic.PCCount;
                        string   _RenewalStatus    = _Lic.RenewalStatus;
                        bool     _Active           = _Lic.Active;
                        string   _Notes            = Utilities.CorrectApostropheForSQL(_Lic.Notes);
                        int      _ID               = _Lic.Id;
                        bool     _ChkBxWillCancel  = _Lic.ChkBxWillCancel;
                        bool     _ChkBxUninstalled = _Lic.ChkBxUninstalled;
                        bool     _ChkBxDeleted     = _Lic.ChkBxDeleted;

                        // Create command for SQL server
                        SqlConnection sqlConnection1 = new SqlConnection((Helper.CnnValCustom(NewDBDir)));
                        SqlDataReader reader;
                        SqlCommand    command = new SqlCommand();
                        command.CommandText = $"INSERT INTO GDataTable (ReviewStatus, CompanyName, FirstName, LastName, ExpirationDate, PCCount, RenewalStatus, Active, Notes) VALUES ('{_ReviewStatus}', '{_CompanyName}', '{_FirstName}', '{_LastName}', '{ExpDate}', '{_PCCount}', '{_RenewalStatus}', '{_Active}', '{_Notes}','{_ChkBxWillCancel}','{_ChkBxUninstalled}','{_ChkBxDeleted}')";
                        command.CommandType = CommandType.Text;
                        command.Connection  = sqlConnection1;

                        sqlConnection1.Open();
                        reader = command.ExecuteReader();

                        sqlConnection1.Close();
                    }
                }
            }
        }
Exemplo n.º 12
0
        private void aButtonAddLicense_Click(object sender, EventArgs e)
        {
            DataAccess_GDataTable db       = new DataAccess_GDataTable();
            License        NewLicense      = new License();
            AddLicenseForm _AddLicenseForm = new AddLicenseForm();
            DialogResult   _form           = _AddLicenseForm.ShowDialog();

            if (_form == DialogResult.Yes) // SAVE AND ADD MACHINES BUTTON
            {
                // GET NEW LICENSE INFO from add license form
                NewLicense = _AddLicenseForm.OutputLicense();

                // ADD NEW LICENSE TO SQL DB
                if (NewLicense != null)
                {
                    db.CreateNewLicense(NewLicense, Config.DBDir_Name);
                }

                InitializeLicensesTTR();

                // GET CREATED LICENSE FROM DB
                List <License> LatestEntry = new List <License>();
                LatestEntry = db.GetLatestEntry(Config.DBDir_Name);
                // CHECK FOR EMPTY LATESTENTRY
                if (LatestEntry[0].CompanyName == null || LatestEntry[0].FirstName == null && LatestEntry[0].LastName == null)
                {
                    MessageBox.Show("There was an error getting the most recently added license.", "Error!");
                    return;
                }

                // LOG LICENSE CREATION DATE
                List <string> changesmade = new List <string>();
                if (NewLicense.CompanyName == "")
                {
                    changesmade.Add($"License Created for '{LatestEntry[0].FirstName} {LatestEntry[0].LastName}'");
                }
                else
                {
                    changesmade.Add($"License Created for '{LatestEntry[0].CompanyName}'");
                }
                Utilities.CreateLog(changesmade, LatestEntry[0].Id);


                RefreshDashboard(this, e);

                // NEXT STEP: MANAGE MACHINES FORM
                ManagePCsForm _ManagePCsForm = new ManagePCsForm();
                _ManagePCsForm.InputLicense = LatestEntry[0]; // Set License to be passed in
                DialogResult _manageform = _ManagePCsForm.ShowDialog();
                if (_manageform == DialogResult.OK || _manageform == DialogResult.Cancel)
                {
                    RefreshDashboard(this, e);
                }
            }
            if (_form == DialogResult.OK) // SAVE BUTTON
            {
                // COLLECT DATA FROM CREATED LICENSE
                NewLicense = _AddLicenseForm.OutputLicense();

                // Update DB using UpdatedLicense
                if (NewLicense != null)
                {
                    db.CreateNewLicense(NewLicense, Config.DBDir_Name);
                }

                // GET LICENSE CREATED FROM DB
                List <License> NewLicense2 = new List <License>();
                NewLicense2 = db.GetLatestEntry(Config.DBDir_Name);

                // LOG LICENSE CREATION DATE
                List <string> changesmade = new List <string>();
                if (NewLicense.CompanyName == "")
                {
                    changesmade.Add($"License Created for '{NewLicense2[0].FirstName} {NewLicense2[0].LastName}'");
                }
                else
                {
                    changesmade.Add($"License Created for '{NewLicense2[0].CompanyName}'");
                }
                Utilities.CreateLog(changesmade, NewLicense2[0].Id);

                InitializeLicensesTTR();
                RefreshDashboard(this, e);
            }
        }