コード例 #1
0
        /// <summary>Activate button click event handler</summary>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">Event arguments.</param>
        private void activateButton_Click(object sender, EventArgs e)
        {
            Int32  licenseId  = 0;
            string password   = passwordTextBox.Text;
            bool   successful = false;

            if (string.IsNullOrEmpty(licenseIDTextBox.Text))
            {
                MessageBox.Show(this, "Please enter a License ID.", "Activation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                licenseIDTextBox.Focus();
                return;
            }

            if (!Int32.TryParse(licenseIDTextBox.Text, out licenseId))
            {
                MessageBox.Show(this, "The License ID may only contain numbers.", "Activation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                licenseIDTextBox.Focus();
                return;
            }

            if (!Int32.TryParse(licenseIDTextBox.Text, out licenseId))
            {
                MessageBox.Show(this, "The License ID may only contain numbers.", "Activation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                licenseIDTextBox.Focus();
                return;
            }

            if (string.IsNullOrEmpty(passwordTextBox.Text))
            {
                MessageBox.Show(this, "Enter your password.", "Activation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                passwordTextBox.Focus();
                return;
            }

            m_license.InstallationName = installationNameTextBox.Text;

            successful = m_license.ActivateOnline(licenseId, password);

            if (successful)
            {
                MessageBox.Show(this, "Activation Successful!", "Activation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                m_mainDialog.ReloadLicense();
                Close();
            }
            else
            {
                MessageBox.Show(this, "Activation Failed." + Environment.NewLine + Environment.NewLine + m_license.LastError.ToString(), "Activation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }