public static void UpdateLicensedMachineData(LicensedMachines License, string DBDIR_Name)
        {
            Cursor.Current = Cursors.WaitCursor;
            string _InstallDate = License.InstallDate;

            string _MachineName  = Utilities.CorrectApostropheForSQL(License.MachineName);
            string _MachineNotes = Utilities.CorrectApostropheForSQL(License.MachineNotes);
            // CorrectAprostopheForSQL will take ' and change it to '' so that it imports into the DB correctly.
            // Example: "Nathan's" is changed to "Nathan''s" so that it imports like "Nathan's".

            int _ID = License.Id;

            // Update SQL Table
            SqlConnection sqlConnection1 = new SqlConnection((Helper.CnnValCustom(DBDIR_Name)));
            SqlDataReader reader;
            SqlCommand    command = new SqlCommand();

            command.CommandText = $"UPDATE LicensedMachinesTable SET InstallDate = '{_InstallDate}', MachineName = '{_MachineName}', MachineNotes = '{_MachineNotes}' WHERE Id = '{_ID}'";
            command.CommandType = CommandType.Text;
            command.Connection  = sqlConnection1;

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

            sqlConnection1.Close();
        }
Exemplo n.º 2
0
 public void CopyDataTo(LicensedMachines _license)
 {
     _license.Id           = Id;
     _license.LicenseId    = LicenseId;
     _license.InstallDate  = InstallDate;
     _license.MachineName  = MachineName;
     _license.MachineNotes = MachineNotes;
 }
 public void CopyDataTo(LicensedMachines _license)
 {
     _license.Id           = Id;
     _license.LicenseId    = LicenseId;
     _license.DateAdded    = DateAdded;
     _license.MachineName  = MachineName;
     _license.MachineNotes = MachineNotes;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Returns string list of changes made to a Licensed Machine
        /// </summary>
        /// <param name="OriginalMachine"></param>
        /// <param name="ChangedMachine"></param>
        /// <returns></returns>
        public static List <string> FindChanges(LicensedMachines OriginalMachine, LicensedMachines ChangedMachine)
        {
            string        Format             = $"(License: {OriginalMachine.LicenseId})";
            ConfigClass   Config             = Class_Library.Config.Get();
            List <string> Changes            = new List <string>();
            bool          MachineNameChanged = false;

            // MACHINE NAME
            if (OriginalMachine.MachineName != ChangedMachine.MachineName)
            {
                Changes.Add($"{Format} Machine name changed from '{OriginalMachine.MachineName}' to '{ChangedMachine.MachineName}'");
                MachineNameChanged = true;
            }

            // DATE ADDED
            if (OriginalMachine.InstallDate != ChangedMachine.InstallDate)
            {
                if (MachineNameChanged)
                {
                    Changes.Add($"{Format} 'Install Date' for '{ChangedMachine.MachineName}' changed from '{OriginalMachine.InstallDate}' to '{ChangedMachine.InstallDate}'");
                }
                else
                {
                    Changes.Add($"{Format} 'Install Date' for '{OriginalMachine.MachineName}' changed from '{OriginalMachine.InstallDate}' to '{ChangedMachine.InstallDate}'");
                }
            }
            // MACHINE NOTES
            if (OriginalMachine.MachineNotes != ChangedMachine.MachineNotes)
            {
                if (MachineNameChanged)
                {
                    Changes.Add($"{Format} Machine's Notes changed for {ChangedMachine.MachineName}");
                }
                else
                {
                    Changes.Add($"{Format} Machine's Notes changed for {OriginalMachine.MachineName}");
                }
            }
            // LICENSE ID (If true, License has been moved to another account)
            if (OriginalMachine.LicenseId != ChangedMachine.LicenseId)
            {
                List <string> ChangesMadeFor_MovedTo_Account = new List <string>(); // Log details for the new License that the machine was moved to.
                if (MachineNameChanged)
                {
                    string Message = $"Moved PC '{ChangedMachine.MachineName}' from (License: {OriginalMachine.LicenseId}) to (License: {ChangedMachine.LicenseId}).";
                    Changes.Add(Message);
                    ChangesMadeFor_MovedTo_Account.Add(Message);
                }
                else
                {
                    string Message = $"Moved PC '{OriginalMachine.MachineName}' from (License: {OriginalMachine.LicenseId}) to (License: {ChangedMachine.LicenseId}).";
                    Changes.Add(Message);
                    ChangesMadeFor_MovedTo_Account.Add(Message);
                }
                Utilities.CreateLog(ChangesMadeFor_MovedTo_Account, ChangedMachine.LicenseId);
            }
            return(Changes);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns string list of changes made to a Licensed Machine
        /// </summary>
        /// <param name="OriginalMachine"></param>
        /// <param name="ChangedMachine"></param>
        /// <returns></returns>
        public static List <string> FindChanges(LicensedMachines OriginalMachine, LicensedMachines ChangedMachine)
        {
            string        Format             = $"(License: {OriginalMachine.LicenseId})";
            ConfigClass   Config             = Utilities.GetConfigData();
            List <string> Changes            = new List <string>();
            bool          MachineNameChanged = false;

            // MACHINE NAME
            if (OriginalMachine.MachineName != ChangedMachine.MachineName)
            {
                Changes.Add($"{Format} Machine name changed from '{OriginalMachine.MachineName}' to '{ChangedMachine.MachineName}'");
                MachineNameChanged = true;
            }
            // DATE ADDED
            if (OriginalMachine.DateAdded != ChangedMachine.DateAdded)
            {
                if (MachineNameChanged)
                {
                    Changes.Add($"{Format} 'Date Added' for '{ChangedMachine.MachineName}' changed from '{OriginalMachine.DateAdded}' to '{ChangedMachine.DateAdded}'");
                }
                else
                {
                    Changes.Add($"{Format} 'Date Added' for '{OriginalMachine.MachineName}' changed from '{OriginalMachine.DateAdded}' to '{ChangedMachine.DateAdded}'");
                }
            }
            // MACHINE NOTES
            if (OriginalMachine.MachineNotes != ChangedMachine.MachineNotes)
            {
                if (MachineNameChanged)
                {
                    Changes.Add($"{Format} Machine's Notes changed for {ChangedMachine.MachineName}");
                }
                else
                {
                    Changes.Add($"{Format} Machine's Notes changed for {OriginalMachine.MachineName}");
                }
            }
            // LICENSE ID
            if (OriginalMachine.LicenseId != ChangedMachine.LicenseId)
            {
                if (MachineNameChanged)
                {
                    Changes.Add($"Moved PC '{ChangedMachine.MachineName}' from (License: {OriginalMachine.LicenseId}) to (License: {ChangedMachine.LicenseId}).");
                }
                else
                {
                    Changes.Add($"Moved PC '{OriginalMachine.MachineName}' from (License: {OriginalMachine.LicenseId}) to (License: {ChangedMachine.LicenseId}).");
                }
            }
            return(Changes);
        }
Exemplo n.º 6
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());
            }
        }
        public static void UpdateLicenseId(LicensedMachines License, string DBDIR_Name)
        {
            Cursor.Current = Cursors.WaitCursor;

            // Create command for SQL server
            SqlConnection sqlConnection1 = new SqlConnection((Helper.CnnValCustom(DBDIR_Name)));
            SqlDataReader reader;
            SqlCommand    command = new SqlCommand();

            command.CommandText = $"UPDATE LicensedMachinesTable SET LicenseId = '{License.LicenseId}' WHERE Id = '{License.Id}'";
            command.CommandType = CommandType.Text;
            command.Connection  = sqlConnection1;

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

            sqlConnection1.Close();
        }
        public static void AddLicensedMachines(LicensedMachines MachineAdded, string DBDIR_Name)
        {
            Cursor.Current            = Cursors.WaitCursor;
            MachineAdded.MachineName  = Utilities.CorrectApostropheForSQL(MachineAdded.MachineName);
            MachineAdded.MachineNotes = Utilities.CorrectApostropheForSQL(MachineAdded.MachineNotes);

            // Create command for SQL server
            SqlConnection sqlConnection1 = new SqlConnection((Helper.CnnValCustom(DBDIR_Name)));
            SqlDataReader reader;
            SqlCommand    command = new SqlCommand();

            command.CommandText = $"INSERT INTO LicensedMachinesTable (InstallDate, MachineName, MachineNotes, LicenseId) VALUES ('{MachineAdded.InstallDate}', '{MachineAdded.MachineName}', '{MachineAdded.MachineNotes}', '{MachineAdded.LicenseId}')";

            command.CommandType = CommandType.Text;
            command.Connection  = sqlConnection1;

            // open connection, run command, close connection.
            sqlConnection1.Open();
            reader = command.ExecuteReader();
            sqlConnection1.Close();
        }
Exemplo n.º 9
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();
            }
        }
Exemplo n.º 10
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);
            }
        }