Пример #1
0
        private void decodeLicenseButton_Click(object sender, System.EventArgs e)
        {
            // store the data in a registration data object
            ManagedRegistrationData data = new ManagedRegistrationData();

            data.CustType      = customerTypeComboBox.SelectedIndex;
            data.Functionality = functionalityComboBox.SelectedIndex;
            data.Product       = productComboBox.SelectedIndex;
            if (noExpirationCheckBox.Checked)
            {
                data.NumberOfDaysValid = 0;
            }
            else
            {
                data.NumberOfDaysValid = (int)numDaysValidNumericUpDown.Value;
            }

            if (siteLicenseCheckBox.Checked)
            {
                data.NumberOfLicensesPurchased = 0;
            }
            else
            {
                data.NumberOfLicensesPurchased = (uint)numLicensesNumericUpDown.Value;
            }
            data.SerialNumber    = serialNumberTextBox.Text;
            data.RegistrationKey = registrationKeyTextBox.Text;

            // decode the key
            if (!ManagedRegistrationKeyGenerator.GetInstance().DecodeRegistrationKey(data))
            {
                MessageBox.Show("Could not decode key successfully");
                return;
            }

            // fill in the ui fields with the new data
            customerTypeComboBox.SelectedIndex  = data.CustType;
            functionalityComboBox.SelectedIndex = data.Functionality;
            productComboBox.SelectedIndex       = data.Product;
            if (data.NumberOfDaysValid == 0)
            {
                numDaysValidNumericUpDown.Enabled = false;
                numDaysValidNumericUpDown.Value   = 1;
                noExpirationCheckBox.Checked      = true;
            }
            else
            {
                noExpirationCheckBox.Checked      = false;
                numDaysValidNumericUpDown.Enabled = true;
                numDaysValidNumericUpDown.Value   = data.NumberOfDaysValid;
            }

            if (data.NumberOfLicensesPurchased == 0)
            {
                siteLicenseCheckBox.Checked      = true;
                numLicensesNumericUpDown.Value   = 1;
                numLicensesNumericUpDown.Enabled = false;
            }
            else
            {
                siteLicenseCheckBox.Checked      = false;
                numLicensesNumericUpDown.Value   = data.NumberOfLicensesPurchased;
                numLicensesNumericUpDown.Enabled = true;
            }
            serialNumberTextBox.Text    = data.SerialNumber;
            registrationKeyTextBox.Text = data.RegistrationKey;
        }
Пример #2
0
        //*************************************************************************
        // Method:		generateKeyButton_Click
        // Description: called when the user clicks the generate button
        //
        // Parameters:
        //	sender - the sender of the event
        //	e - the args representing the event
        //
        // Return Value: None
        //*************************************************************************
        private void generateKeyButton_Click(object sender, System.EventArgs e)
        {
            // store the data in a registration data object
            ManagedRegistrationData data = new ManagedRegistrationData();

            data.CustType      = customerTypeComboBox.SelectedIndex;
            data.Functionality = functionalityComboBox.SelectedIndex;
            data.Product       = productComboBox.SelectedIndex;
            if (noExpirationCheckBox.Checked)
            {
                data.NumberOfDaysValid = 0;
            }
            else
            {
                data.NumberOfDaysValid = (int)numDaysValidNumericUpDown.Value;
            }
            if (siteLicenseCheckBox.Checked)
            {
                data.NumberOfLicensesPurchased = 0;
            }
            else
            {
                data.NumberOfLicensesPurchased = (uint)numLicensesNumericUpDown.Value;
            }
            data.SerialNumber    = serialNumberTextBox.Text;
            data.RegistrationKey = registrationKeyTextBox.Text;

            // generate the key
            if (!ManagedRegistrationKeyGenerator.GetInstance().GenerateRegistrationKey(data))
            {
                MessageBox.Show("Could not generate key");
                return;
            }

            // save the data to the database
            try
            {
                regDataDbConnection.Open();

                regDataDbDataAdapter.InsertCommand.CommandText = "INSERT INTO RegData(CompanyName, CustomerName, CustomerType, DaysValid, Functionality, KeyVersion, LicensesPurchased, Product, RegistrationKey, SerialNumber) VALUES (" +
                                                                 "'" + companyNameTextBox.Text + "', " +
                                                                 "'" + customerNameTextBox.Text + "', " +
                                                                 (data.CustType + 1) + ", " +
                                                                 data.NumberOfDaysValid + ", " +
                                                                 (data.Functionality + 1) + ", " +
                                                                 (data.KeyVersion + 1) + ", " +
                                                                 data.NumberOfLicensesPurchased + ", " +
                                                                 (data.Product + 1) + ", " +
                                                                 "'" + data.RegistrationKey + "', " +
                                                                 "'" + data.SerialNumber + "')";

                regDataDbDataAdapter.InsertCommand.ExecuteNonQuery();

                regDataDbConnection.Close();

                MessageBox.Show("Key Generated Successfully!\nData Saved to the Database!");
            }
            catch (System.Data.OleDb.OleDbException)
            {
                MessageBox.Show("Could not save data to the database!");
            }

            // fill out all the UI fields with the new data
            customerTypeComboBox.SelectedIndex  = data.CustType;
            functionalityComboBox.SelectedIndex = data.Functionality;
            productComboBox.SelectedIndex       = data.Product;

            if (data.NumberOfDaysValid == 0)
            {
                numDaysValidNumericUpDown.Enabled = false;
                numDaysValidNumericUpDown.Value   = 1;
                noExpirationCheckBox.Checked      = true;
            }
            else
            {
                noExpirationCheckBox.Checked      = false;
                numDaysValidNumericUpDown.Enabled = true;
                numDaysValidNumericUpDown.Value   = data.NumberOfDaysValid;
            }

            if (data.NumberOfLicensesPurchased == 0)
            {
                siteLicenseCheckBox.Checked      = true;
                numLicensesNumericUpDown.Value   = 1;
                numLicensesNumericUpDown.Enabled = false;
            }
            else
            {
                siteLicenseCheckBox.Checked      = false;
                numLicensesNumericUpDown.Value   = data.NumberOfLicensesPurchased;
                numLicensesNumericUpDown.Enabled = true;
            }
            serialNumberTextBox.Text    = data.SerialNumber;
            registrationKeyTextBox.Text = data.RegistrationKey;
        }