147 lines
5.4 KiB
C#
147 lines
5.4 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Windows.Forms;
|
||
using System.Security.Cryptography;
|
||
using System.IO;
|
||
using SuperMap.RealEstate.Windows.Utility;
|
||
|
||
namespace SuperMap.RealEstate.ServerLicense.Manager
|
||
{
|
||
public partial class frmMain : Form
|
||
{
|
||
public frmMain()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void checkBox1_CheckStateChanged(object sender, EventArgs e)
|
||
{
|
||
textBoxExpiredDateCount.Enabled = !checkBoxExpired.Checked;
|
||
}
|
||
|
||
private void frmMain_Load(object sender, EventArgs e)
|
||
{
|
||
button1.Focus();
|
||
}
|
||
|
||
private void button1_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(textBoxProductName.Text))
|
||
{
|
||
textBoxProductName.Focus();
|
||
return;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(textBoxProductName_En.Text))
|
||
{
|
||
textBoxProductName_En.Focus();
|
||
return;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(textBoxCopyright.Text))
|
||
{
|
||
textBoxCopyright.Focus();
|
||
return;
|
||
}
|
||
if (string.IsNullOrEmpty(textBoxCopyright_En.Text))
|
||
{
|
||
textBoxCopyright_En.Focus();
|
||
return;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(textBoxExpiredDateCount.Text))
|
||
{
|
||
textBoxExpiredDateCount.Text = "0";
|
||
}
|
||
int _DayCount;
|
||
if (!int.TryParse(textBoxExpiredDateCount.Text, out _DayCount))
|
||
{
|
||
textBoxExpiredDateCount.SelectAll();
|
||
textBoxExpiredDateCount.Focus();
|
||
return;
|
||
}
|
||
|
||
string _Lincese =
|
||
//永久授权
|
||
(checkBoxExpired.Checked ? "1" : "0") +
|
||
//创建时间
|
||
"|" + DateTime.Now.ToString()+//ToLongDateString().Replace("/", "-") +
|
||
//到期时间
|
||
"|" + DateTime.Now.AddDays(_DayCount).ToString() +//ToLongDateString().Replace("/", "-") +
|
||
//产品名称
|
||
"|" + textBoxProductName.Text +
|
||
"|" + textBoxProductName_En.Text +
|
||
//版权信息
|
||
"|" + textBoxCopyright.Text +
|
||
"|" + textBoxCopyright_En.Text;
|
||
|
||
SaveToLicFile(AppDomain.CurrentDomain.BaseDirectory + textBoxCopyright.Text, _Lincese);
|
||
|
||
if (MessageBox.Show("成功生成授权文件是否在资源管理器中打开?\r\n文件路径:" + AppDomain.CurrentDomain.BaseDirectory +
|
||
textBoxCopyright.Text + "\\License.lic", "提示",
|
||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||
{
|
||
ApplicationHelper.Run("explorer/n," + AppDomain.CurrentDomain.BaseDirectory + textBoxCopyright.Text);
|
||
}
|
||
}
|
||
|
||
private void SaveToLicFile(string pathName,string _Lincese)
|
||
{
|
||
if (!Directory.Exists(pathName))
|
||
Directory.CreateDirectory(pathName);
|
||
|
||
using (FileStream _FileStream = new FileStream(pathName+"\\License.lic", FileMode.OpenOrCreate, FileAccess.Write))
|
||
{
|
||
Byte[] _byteCollection = Encoding.UTF8.GetBytes(_Lincese);
|
||
|
||
using (DESCryptoServiceProvider _DESCryptoServiceProvider = new DESCryptoServiceProvider())
|
||
{
|
||
byte[] _CryptoServiceKeyBytes = new byte[] { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 };
|
||
_DESCryptoServiceProvider.Key = _CryptoServiceKeyBytes;
|
||
_DESCryptoServiceProvider.IV = _CryptoServiceKeyBytes;
|
||
ICryptoTransform _ICryptoTransform = _DESCryptoServiceProvider.CreateEncryptor();
|
||
|
||
CryptoStream _CryptoStream = new CryptoStream(_FileStream, _ICryptoTransform, CryptoStreamMode.Write);
|
||
_CryptoStream.Write(_byteCollection, 0, _byteCollection.Length);
|
||
_CryptoStream.FlushFinalBlock();
|
||
_FileStream.Flush();
|
||
_CryptoStream.Close();
|
||
}
|
||
_FileStream.Close();
|
||
}
|
||
}
|
||
|
||
private void button2_Click(object sender, EventArgs e)
|
||
{
|
||
Close();
|
||
}
|
||
|
||
//private CryptoStream EncryptedLicenseData(string linceseDataString)
|
||
//{
|
||
// MemoryStream _MemoryStream = new MemoryStream(Encoding.UTF8.GetBytes(linceseDataString));
|
||
|
||
// using (DESCryptoServiceProvider _DESCryptoServiceProvider = new DESCryptoServiceProvider())
|
||
// {
|
||
// byte[] _CryptoServiceKeyBytes = new byte[] { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 };
|
||
// _DESCryptoServiceProvider.Key = _CryptoServiceKeyBytes;
|
||
// _DESCryptoServiceProvider.IV = _CryptoServiceKeyBytes;
|
||
// ICryptoTransform _ICryptoTransform = _DESCryptoServiceProvider.CreateEncryptor();
|
||
|
||
// CryptoStream _CryptoStream = new CryptoStream(_MemoryStream, _ICryptoTransform, CryptoStreamMode.Write);
|
||
// //_CryptoStream.Write(inputByteArray, 0, inputByteArray.Length);
|
||
// _CryptoStream.FlushFinalBlock();
|
||
|
||
// return _CryptoStream;
|
||
|
||
// }
|
||
//}
|
||
|
||
|
||
}
|
||
}
|