Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //LicenseHelper.GenKey();
            LicenseHelper.GetPriKey();

            string guid = LicenseHelper.GetCpuId();


            string license = DateTime.Now.Date.ToString("yyyy-MM-dd") + LicenseHelper.GenLicense(guid);

            txtBoxLicense.Text = FileHelper.Encrypt(license, guid.Substring(0, 8));

            FileHelper.WriteToTextFile(txtBoxLicense.Text, "license.dat");
        }
Esempio n. 2
0
        private void btnGenLicense_Click(object sender, EventArgs e)
        {
            int days = 0;

            if (string.IsNullOrEmpty(textBoxGuid.Text))
            {
                if (DialogResult.No == MessageBox.Show("请输入电脑标识是否按照有效天数生成授权信息?", "提示信息", MessageBoxButtons.YesNo))
                {
                    return;
                }
            }
            else
            {
                if (textBoxGuid.Text.Length < 8)
                {
                    MessageBox.Show("电脑标识必须是大于等于8位的字符串");
                    textBoxGuid.Focus();
                    return;
                }
            }
            try
            {
                days = Convert.ToInt32(textBoxValid.Text);
            }
            catch
            {
                MessageBox.Show("有效使用天数输入不正确,请重新输入!", "错误信息", MessageBoxButtons.OK);
                textBoxValid.Focus();
                return;
            }

            LicenseHelper.GetPriKey();

            string guid = textBoxGuid.Text;

            if (string.IsNullOrEmpty(guid))
            {
                string license;
                if ("0" == textBoxValid.Text)
                {
                    license = "0000-00-00";
                }
                else
                {
                    license = (DateTime.Now.Date.AddDays(days)).ToString("yyyy-MM-dd");
                }

                txtBoxLicense.Text = FileHelper.Encrypt(license);
            }
            else
            {
                string license;
                if ("0" == textBoxValid.Text)
                {
                    license = "0000-00-00";
                }
                else
                {
                    license = (DateTime.Now.Date.AddDays(days)).ToString("yyyy-MM-dd");
                }

                license = license + LicenseHelper.GenLicense(guid);

                txtBoxLicense.Text = FileHelper.Encrypt(license, guid.Substring(0, 8));
            }

            FileHelper.WriteToTextFile(txtBoxLicense.Text, "License.dat");
        }