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);
            }
        }
示例#2
0
        /// <summary>
        /// Returns a string list of changes made to a License
        /// </summary>
        /// <param name="OriginalLicense"></param>
        /// <param name="ChangedLicense"></param>
        /// <returns></returns>
        public static List <string> FindChanges(License OriginalLicense, License ChangedLicense)
        {
            string        Format  = $"(License: {OriginalLicense.Id})";
            List <string> Changes = new List <string>();

            // COMPANY NAME
            if (OriginalLicense.CompanyName != ChangedLicense.CompanyName)
            {
                if (OriginalLicense.CompanyName == "")
                {
                    Changes.Add($"{Format} Company Name info '{ChangedLicense.CompanyName}' added to {OriginalLicense.FirstName} {OriginalLicense.LastName}");
                }
                else
                {
                    Changes.Add($"{Format} Company Name '{OriginalLicense.CompanyName}' changed to '{ChangedLicense.CompanyName}'");
                }
            }
            // FIRST NAME
            if (OriginalLicense.FirstName != ChangedLicense.FirstName)
            {
                if (OriginalLicense.FirstName == "")
                {
                    Changes.Add($"{Format} First Name info '{ChangedLicense.FirstName}' added to {OriginalLicense.CompanyName}");
                }
                else
                {
                    Changes.Add($"{Format} First Name '{OriginalLicense.FirstName}' changed to '{ChangedLicense.FirstName}'");
                }
            }
            // LAST NAME
            if (OriginalLicense.LastName != ChangedLicense.LastName)
            {
                if (OriginalLicense.LastName == "")
                {
                    Changes.Add($"{Format} Last Name info '{ChangedLicense.LastName}' added to {OriginalLicense.CompanyName}");
                }
                else
                {
                    Changes.Add($"{Format} Last Name '{OriginalLicense.LastName}' changed to '{ChangedLicense.LastName}'");
                }
            }
            // REVIEW STATUS
            if (OriginalLicense.ReviewStatus != ChangedLicense.ReviewStatus)
            {
                Changes.Add($"{Format} Review Status '{OriginalLicense.ReviewStatus}' changed to '{ChangedLicense.ReviewStatus}'");
            }
            // EXPIRATION DATE
            if (OriginalLicense.ExpirationDate != ChangedLicense.ExpirationDate)
            {
                Changes.Add($"{Format} Expiration Date '{OriginalLicense.ExpirationDate.ToShortDateString()}' changed to '{ChangedLicense.ExpirationDate.ToShortDateString()}'");
            }
            // ACTIVE
            if (OriginalLicense.Active != ChangedLicense.Active)
            {
                Changes.Add($"{Format} Active Status '{OriginalLicense.Active}' changed to '{ChangedLicense.Active}'");
            }
            // RENEWAL STATUS
            if (OriginalLicense.RenewalStatus != ChangedLicense.RenewalStatus)
            {
                Changes.Add($"{Format} Renewal Status '{OriginalLicense.RenewalStatus}' changed to '{ChangedLicense.RenewalStatus}'");
            }
            // NOTES
            if (OriginalLicense.Notes != ChangedLicense.Notes)
            {
                Changes.Add($"{Format} Notes changed.");
            }
            // CHKBOX WILL CANCEL
            if (OriginalLicense.ChkBxWillCancel != ChangedLicense.ChkBxWillCancel)
            {
                if (ChangedLicense.ChkBxWillCancel)
                {
                    Changes.Add($"{Format} 'Will Cancel' checked");
                }
                else
                {
                    Changes.Add($"{Format} 'Will Cancel' unchecked");
                }
            }
            // CHKBOX UNINSTALLED
            if (OriginalLicense.ChkBxUninstalled != ChangedLicense.ChkBxUninstalled)
            {
                if (ChangedLicense.ChkBxUninstalled)
                {
                    Changes.Add($"{Format} 'Uninstalled' checked");
                }
                else
                {
                    Changes.Add($"{Format} 'Uninstalled' unchecked");
                }
            }
            // CHKBOX DELETE
            if (OriginalLicense.ChkBxDeleted != ChangedLicense.ChkBxDeleted)
            {
                if (ChangedLicense.ChkBxDeleted)
                {
                    Changes.Add($"{Format} 'Deleted' checked");
                }
                else
                {
                    Changes.Add($"{Format} 'Delete' unchecked");
                }
            }
            return(Changes);
        }