FrmCreateLicense.cs
23.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace MyCMMI.MakeLicence
{
using System.Threading;
using System.Xml;
using System.Text;
using System.IO;
//using System.Security.Cryptography;
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class FrmCreateLicense : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtVerify;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtVersionNumber;
private System.Windows.Forms.TextBox txtUserCount;
private System.Windows.Forms.DateTimePicker DTPTo;
private System.Windows.Forms.Label LabDataTo;
private System.Windows.Forms.DateTimePicker DTPFrom;
private System.Windows.Forms.Label LabDataFrom;
private System.Windows.Forms.Button BtnCancel;
private System.Windows.Forms.Button BtnOK;
private System.Windows.Forms.Button BtnPath;
private System.Windows.Forms.Label LabSaveFile;
private System.Windows.Forms.Label LabCompanyName;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtFilePath;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private MyCMMI.CreateLicense.LicenceMake LM;
//private const string FILENAME = @"Call Shopping.lic";
//UnicodeEncoding ByteConverter = new UnicodeEncoding();
private string m_SavePath = "";
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox txtCurSerialNo;
private System.Windows.Forms.TextBox txtCompanyName;
private System.Windows.Forms.ComboBox cmbProductName;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.RadioButton rbCVS;
private System.Windows.Forms.RadioButton rbVSS;
private System.Windows.Forms.RadioButton rbBoth;
private System.Windows.Forms.Panel pConfige;
private string m_Txt = "";
public FrmCreateLicense()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.DTPTo.Value = DateTime.Now.AddYears(1);
this.cmbProductName.SelectedIndex = 0;
m_Txt = "<RSAKeyValue><Modulus>wD+BfPFh06qyNMMjyIZfbSeNSVGppoH4VCR6iVTnsrWm+Czjg24EycKvQfZd9SVYHJMASHuKr0VlBCPye2REs2b9UCT3b+yLqhFrde0v7k6m6FTZe4kH4USmhsQaJstcU94LCRDM3PNfWS3r9qZ11ZtJDmrGH1zFtOJsYBWdZAM=</Modulus><Exponent>AQAB</Exponent><P>7NMGb03H7zLLLYZ71RTKte6mJ7TonQfzx6qYmRCCwBsESolDoAInJBe07iFsQ324BCMFNcNrguHaRXH9KDkmow==</P><Q>z9B9NJ3fpMsBNv+J8ynaI18gQHBFcQeRRZw6hnGvN23xeIhf+G2i9RJUPHksY+xc5LVsyMc5gcq/LzeaRD6DIQ==</Q><DP>vwHsvLTlPt2e1dcT5WZhoJ8c0AWvX4fcbPwBG+MfMcYYje1r55AU9Z1RRocahMzPMDb2qsg03FlA7KXlYx3FNQ==</DP><DQ>co281upHw7FbxBNs2auyYVkokBzTSpEfVT3fTQkRyv5B421ZaboV3/3wjT1GaPZ75l7TzoFzg8ZdSQvfb8r9wQ==</DQ><InverseQ>D3R8Pf6C+4C3iS2eqr4CqYyISuIP/YDFm2lIUFJS+jkqOZNv47/IIWXbY4nGK2qpzwjDtcFyO1DiHhOaEMqd8A==</InverseQ><D>CicQao3A0dHQ6XJowF1ASt5s2rNiVzXD7IWkpv4B4nEvaSnNthIoVJNgeAZPvfOD7LZirHFByLHMfOR9GMEZ05wgc+lYuvLaQxuvXjXFPFDjLSR3/SOCXDRcbHtDvx00q2KXSyGJIMa/TANw15rxfvKtecVJetOON+GbCMfOA0E=</D></RSAKeyValue>";
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.txtVerify = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txtVersionNumber = new System.Windows.Forms.TextBox();
this.txtUserCount = new System.Windows.Forms.TextBox();
this.DTPTo = new System.Windows.Forms.DateTimePicker();
this.LabDataTo = new System.Windows.Forms.Label();
this.DTPFrom = new System.Windows.Forms.DateTimePicker();
this.LabDataFrom = new System.Windows.Forms.Label();
this.BtnCancel = new System.Windows.Forms.Button();
this.BtnOK = new System.Windows.Forms.Button();
this.BtnPath = new System.Windows.Forms.Button();
this.txtFilePath = new System.Windows.Forms.TextBox();
this.LabSaveFile = new System.Windows.Forms.Label();
this.LabCompanyName = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.txtCurSerialNo = new System.Windows.Forms.TextBox();
this.txtCompanyName = new System.Windows.Forms.TextBox();
this.cmbProductName = new System.Windows.Forms.ComboBox();
this.pConfige = new System.Windows.Forms.Panel();
this.rbCVS = new System.Windows.Forms.RadioButton();
this.rbVSS = new System.Windows.Forms.RadioButton();
this.rbBoth = new System.Windows.Forms.RadioButton();
this.label6 = new System.Windows.Forms.Label();
this.pConfige.SuspendLayout();
this.SuspendLayout();
//
// txtVerify
//
this.txtVerify.Location = new System.Drawing.Point(144, 32);
this.txtVerify.Name = "txtVerify";
this.txtVerify.Size = new System.Drawing.Size(196, 21);
this.txtVerify.TabIndex = 3;
this.txtVerify.Text = "";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(28, 36);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 17);
this.label2.TabIndex = 2;
this.label2.Text = "硬盘序列号:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(28, 148);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 17);
this.label1.TabIndex = 10;
this.label1.Text = "版本号:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(28, 92);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(60, 17);
this.label3.TabIndex = 6;
this.label3.Text = "用户数量:";
//
// txtVersionNumber
//
this.txtVersionNumber.Location = new System.Drawing.Point(144, 144);
this.txtVersionNumber.Name = "txtVersionNumber";
this.txtVersionNumber.Size = new System.Drawing.Size(196, 21);
this.txtVersionNumber.TabIndex = 11;
this.txtVersionNumber.Text = "";
//
// txtUserCount
//
this.txtUserCount.Location = new System.Drawing.Point(144, 88);
this.txtUserCount.Name = "txtUserCount";
this.txtUserCount.Size = new System.Drawing.Size(196, 21);
this.txtUserCount.TabIndex = 7;
this.txtUserCount.Text = "";
//
// DTPTo
//
this.DTPTo.Location = new System.Drawing.Point(144, 200);
this.DTPTo.Name = "DTPTo";
this.DTPTo.Size = new System.Drawing.Size(196, 21);
this.DTPTo.TabIndex = 15;
//
// LabDataTo
//
this.LabDataTo.AutoSize = true;
this.LabDataTo.Location = new System.Drawing.Point(28, 204);
this.LabDataTo.Name = "LabDataTo";
this.LabDataTo.Size = new System.Drawing.Size(110, 17);
this.LabDataTo.TabIndex = 14;
this.LabDataTo.Text = "授权使用结束日期:";
//
// DTPFrom
//
this.DTPFrom.Location = new System.Drawing.Point(144, 172);
this.DTPFrom.Name = "DTPFrom";
this.DTPFrom.Size = new System.Drawing.Size(196, 21);
this.DTPFrom.TabIndex = 13;
//
// LabDataFrom
//
this.LabDataFrom.AutoSize = true;
this.LabDataFrom.Location = new System.Drawing.Point(28, 176);
this.LabDataFrom.Name = "LabDataFrom";
this.LabDataFrom.Size = new System.Drawing.Size(110, 17);
this.LabDataFrom.TabIndex = 12;
this.LabDataFrom.Text = "授权使用起始日期:";
//
// BtnCancel
//
this.BtnCancel.Location = new System.Drawing.Point(240, 300);
this.BtnCancel.Name = "BtnCancel";
this.BtnCancel.TabIndex = 20;
this.BtnCancel.Text = "取消(&C)";
this.BtnCancel.Click += new System.EventHandler(this.BtnCancel_Click);
//
// BtnOK
//
this.BtnOK.Location = new System.Drawing.Point(144, 300);
this.BtnOK.Name = "BtnOK";
this.BtnOK.TabIndex = 19;
this.BtnOK.Text = "生成(&M)";
this.BtnOK.Click += new System.EventHandler(this.BtnOK_Click);
//
// BtnPath
//
this.BtnPath.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.BtnPath.Font = new System.Drawing.Font("宋体", 5.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.BtnPath.Location = new System.Drawing.Point(340, 228);
this.BtnPath.Name = "BtnPath";
this.BtnPath.Size = new System.Drawing.Size(24, 23);
this.BtnPath.TabIndex = 18;
this.BtnPath.Text = "...";
this.BtnPath.Click += new System.EventHandler(this.BtnPath_Click);
//
// txtFilePath
//
this.txtFilePath.Location = new System.Drawing.Point(144, 228);
this.txtFilePath.Name = "txtFilePath";
this.txtFilePath.Size = new System.Drawing.Size(196, 21);
this.txtFilePath.TabIndex = 17;
this.txtFilePath.Text = "";
//
// LabSaveFile
//
this.LabSaveFile.AutoSize = true;
this.LabSaveFile.Location = new System.Drawing.Point(28, 232);
this.LabSaveFile.Name = "LabSaveFile";
this.LabSaveFile.Size = new System.Drawing.Size(116, 17);
this.LabSaveFile.TabIndex = 16;
this.LabSaveFile.Text = "Licence文件存放到:";
//
// LabCompanyName
//
this.LabCompanyName.AutoSize = true;
this.LabCompanyName.Location = new System.Drawing.Point(28, 64);
this.LabCompanyName.Name = "LabCompanyName";
this.LabCompanyName.Size = new System.Drawing.Size(60, 17);
this.LabCompanyName.TabIndex = 4;
this.LabCompanyName.Text = "公司名称:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(28, 120);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(60, 17);
this.label4.TabIndex = 8;
this.label4.Text = "产品名称:";
this.label4.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// label5
//
this.label5.Location = new System.Drawing.Point(28, 8);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(72, 20);
this.label5.TabIndex = 0;
this.label5.Text = "本机序列号:";
//
// txtCurSerialNo
//
this.txtCurSerialNo.Location = new System.Drawing.Point(144, 4);
this.txtCurSerialNo.Name = "txtCurSerialNo";
this.txtCurSerialNo.ReadOnly = true;
this.txtCurSerialNo.Size = new System.Drawing.Size(196, 21);
this.txtCurSerialNo.TabIndex = 1;
this.txtCurSerialNo.Text = "";
//
// txtCompanyName
//
this.txtCompanyName.Location = new System.Drawing.Point(144, 60);
this.txtCompanyName.Name = "txtCompanyName";
this.txtCompanyName.Size = new System.Drawing.Size(196, 21);
this.txtCompanyName.TabIndex = 28;
this.txtCompanyName.Text = "";
//
// cmbProductName
//
this.cmbProductName.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbProductName.Items.AddRange(new object[] {
"人力资源管理系统HR-MIS",
"金钥办公处理系统G-OFFICE",
"电子商务系统ESCALADE",
"7135企业邮局",
"业务通",
"企业电子杂志E-CATALOG",
"桌面安全系统TOPSAFE",
"销售管理系统SFA",
"电话录音系统",
"客服电话系统CALL SHOPPING",
"互联网服务",
"Staples电子采购系统e-Purchase",
"君再来电子订位系统",
"MyCMMI"});
this.cmbProductName.Location = new System.Drawing.Point(144, 116);
this.cmbProductName.Name = "cmbProductName";
this.cmbProductName.Size = new System.Drawing.Size(196, 20);
this.cmbProductName.TabIndex = 29;
//
// pConfige
//
this.pConfige.Controls.Add(this.rbBoth);
this.pConfige.Controls.Add(this.rbVSS);
this.pConfige.Controls.Add(this.rbCVS);
this.pConfige.Location = new System.Drawing.Point(144, 248);
this.pConfige.Name = "pConfige";
this.pConfige.Size = new System.Drawing.Size(192, 36);
this.pConfige.TabIndex = 30;
//
// rbCVS
//
this.rbCVS.Location = new System.Drawing.Point(4, 4);
this.rbCVS.Name = "rbCVS";
this.rbCVS.Size = new System.Drawing.Size(52, 28);
this.rbCVS.TabIndex = 0;
this.rbCVS.Text = "CVS";
//
// rbVSS
//
this.rbVSS.Location = new System.Drawing.Point(64, 4);
this.rbVSS.Name = "rbVSS";
this.rbVSS.Size = new System.Drawing.Size(44, 28);
this.rbVSS.TabIndex = 1;
this.rbVSS.Text = "VSS";
//
// rbBoth
//
this.rbBoth.Location = new System.Drawing.Point(116, 4);
this.rbBoth.Name = "rbBoth";
this.rbBoth.Size = new System.Drawing.Size(72, 28);
this.rbBoth.TabIndex = 2;
this.rbBoth.Text = "CVS&VSS";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(28, 256);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(48, 17);
this.label6.TabIndex = 31;
this.label6.Text = "配置库:";
//
// FrmCreateLicense
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(376, 333);
this.Controls.Add(this.label6);
this.Controls.Add(this.cmbProductName);
this.Controls.Add(this.txtCompanyName);
this.Controls.Add(this.txtCurSerialNo);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.LabCompanyName);
this.Controls.Add(this.BtnCancel);
this.Controls.Add(this.BtnOK);
this.Controls.Add(this.BtnPath);
this.Controls.Add(this.txtFilePath);
this.Controls.Add(this.LabSaveFile);
this.Controls.Add(this.DTPTo);
this.Controls.Add(this.LabDataTo);
this.Controls.Add(this.DTPFrom);
this.Controls.Add(this.LabDataFrom);
this.Controls.Add(this.txtVerify);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.label3);
this.Controls.Add(this.txtVersionNumber);
this.Controls.Add(this.txtUserCount);
this.Controls.Add(this.pConfige);
this.Name = "FrmCreateLicense";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "创建许可证";
this.pConfige.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void BtnPath_Click(object sender, System.EventArgs e)
{
string ProductName = this.cmbProductName.Items[cmbProductName.SelectedIndex].ToString().Trim();
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "Licence files (*.lic)|*.lic" ;
dlg.FilterIndex = 0;
dlg.InitialDirectory = Application.ExecutablePath;
//设定以选定的产品名称为许可执照的文件名
//修改人:刘宝忠
//修改时间:2005-10-8
dlg.FileName = ProductName + ".lic";//"Call Shopping.lic";
if(dlg.ShowDialog() == DialogResult.OK)
{
this.txtFilePath.Text = dlg.FileName;
}
}
private void BtnOK_Click(object sender, System.EventArgs e)
{
this.m_SavePath = this.txtFilePath.Text;
StartMake();
}
private void StartMake()
{
ThreadStart f_MakeProcess=new ThreadStart(MakeProcess);
Thread ThreadProcedure=new Thread(f_MakeProcess);
ThreadProcedure.Start();
}
private void MakeProcess()
{
CheckInfo();
}
private void CheckInfo()
{
if(this.txtVerify.Text.Trim()=="")
{
MessageBox.Show("请输入硬盘序列号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.txtVerify.Focus();
return ;
}
if(this.txtCompanyName.Text.Trim()=="")
{
MessageBox.Show("请输入公司名称!","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.txtCompanyName.Focus();
return ;
}
if (this.ProductName == "")
{
MessageBox.Show("请输入产品名称!","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.cmbProductName.Focus();
return ;
}
if(this.txtVersionNumber.Text.Trim()=="")
{
MessageBox.Show("请输入版本号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.txtVersionNumber.Focus();
return ;
}
if(Convert.ToDateTime(DTPFrom.Value)>Convert.ToDateTime(DTPTo.Value))
{
MessageBox.Show("授权使用期限设置不当!","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
return;
}
if(this.txtFilePath.Text.Trim()=="")
{
MessageBox.Show("请输入Licence文件的存放路径!","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.txtFilePath.Focus();
return ;
}
try
{
string userCount = this.txtUserCount.Text.Trim();
if(userCount!="")
{
Convert.ToInt32(userCount);
}
else
{
MessageBox.Show("请输入用户数量!","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.txtUserCount.SelectAll();
this.txtUserCount.Focus();
return ;
}
}
catch
{
MessageBox.Show("用户数量为整数型!","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.txtUserCount.SelectAll();
this.txtUserCount.Focus();
return ;
}
CheckLicenceFile();
}
private void CheckLicenceFile()
{
string ProductName = this.ProductName;
if(m_SavePath == "")
{
m_SavePath = Application.ExecutablePath;
if(m_SavePath.EndsWith( @"\"))
m_SavePath += @"\";
m_SavePath = m_SavePath.Substring(0,m_SavePath.LastIndexOf(@"\"));
//m_SavePath += FILENAME;
m_SavePath += ProductName + ".lic";
}
if(!Directory.Exists(m_SavePath.Substring(0,m_SavePath.LastIndexOf(@"\"))))
{
this.TopMost = false;
//if(MessageBox.Show("指定的路径不存在,是否要新建?","Call Shopping Licence",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1) == DialogResult.No)
//更改为通用标识:创建许可证
if(MessageBox.Show("指定的路径不存在,是否要新建?","创建许可证",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1) == DialogResult.No)
{
// BtnOK.Enabled = true;
// TxtCompany.Enabled = true;
// DTPFrom.Enabled = true;
// DTPTo.Enabled = true;
return;
}
try
{
Directory.CreateDirectory(m_SavePath.Substring(0,m_SavePath.LastIndexOf(@"\")));
}
catch(Exception e)
{
MessageBox.Show("无法创建指定的目录!\n" + e.Message,"提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
return;
}
}
if(File.Exists(m_SavePath))
{
//if(MessageBox.Show("已存在名为" + m_SavePath.Substring(m_SavePath.LastIndexOf(@"\")+1) + "的文件,是否要覆盖?","Call Shopping Licence",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1) == DialogResult.No)
//更改为通用标识:创建许可证
if(MessageBox.Show("已存在名为" + m_SavePath.Substring(m_SavePath.LastIndexOf(@"\")+1) + "的文件,是否要覆盖?","创建许可证",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1) == DialogResult.No)
{
// BtnOK.Enabled = true;
// TxtCompany.Enabled = true;
// DTPFrom.Enabled = true;
// DTPTo.Enabled = true;
return;
}
File.Delete(m_SavePath);
}
CreateLicenceInfo();
}
private void CreateLicenceInfo()
{
string Verify=this.txtVerify.Text.Trim();
string CompanyName = this.txtCompanyName.Text.Trim();
string UserCount=this.txtUserCount.Text.Trim();
string ProductName = this.ProductName;
string VersionNumber=this.txtVersionNumber.Text.Trim();
DateTime FromDate = Convert.ToDateTime(DTPFrom.Value);
DateTime ToDate = Convert.ToDateTime(DTPTo.Value);
string ConfigueDepot = "";
if(this.rbCVS.Checked == true)
ConfigueDepot = "CVS";
else if(this.rbVSS.Checked == true)
ConfigueDepot = "VSS";
else if(this.rbBoth.Checked == true)
ConfigueDepot = "CVS and VSS";
LM = new MyCMMI.CreateLicense.LicenceMake();
DataSet m_dsValue = LM.dataSet;
m_dsValue.Tables[LM.TABLENAME].Clear();
DataRow m_dr = m_dsValue.Tables[LM.TABLENAME].NewRow();
m_dr["DiskID"] = Verify;
m_dr["CompanyName"] = CompanyName;
m_dr["UserCount"] = UserCount;
m_dr["ProductName"] = m_SavePath.Substring(m_SavePath.LastIndexOf(@"\") + 1);
m_dr["Version"] = VersionNumber;
m_dr["FromDate"] = FromDate.ToShortDateString();
m_dr["ToDate"] = ToDate.ToShortDateString();
m_dr["ConfigueDepot"] = ConfigueDepot;
m_dsValue.Tables[LM.TABLENAME].Rows.Add(m_dr);
LM.RSAKey = m_Txt;
if(LM.CreateLicenceFile(m_dsValue,m_SavePath))
{
FinishTask();
}
else
{
MessageBox.Show("在生成许可文件时出错!","提示",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
return;
}
}
private void FinishTask()
{
string ProductName = this.ProductName;
MessageBox.Show("你已成功生成一份" + m_SavePath.Substring(m_SavePath.LastIndexOf(@"\") + 1) + "许可证!");
// TxtCompany.Text = "";
// TxtCompany.Enabled = true;
// DTPFrom.Enabled = true;
// DTPTo.Enabled = true;
// TxtFilePath.Enabled = true;
// TxtFilePath.Text = "";
// BtnOK.Enabled = true;
//BtnCancel.Text = "完成(&F)";
}
/*
/// <summary>
/// 将信息写入文件
/// </summary>
/// <param name="f_LicenceInfo">信息</param>
/// <param name="f_LicenceFilePath">文件路径及全名</param>
/// <returns>成功返回True ,失败返回false</returns>
public bool CreateLicenceFile(Hashtable f_LicenceInfo,string f_LicenceFilePath)
{
string f_UnSignedInfo = "";
FileInfo fi = new FileInfo(f_LicenceFilePath);
if(fi.Exists)
{
return false;
}
try
{
XmlTextWriter writer = null;
writer = new XmlTextWriter(f_LicenceFilePath,System.Text.Encoding.Unicode);
writer.Formatting = Formatting.Indented;
writer.WriteStartElement("Licence");
foreach(string f_LicenceKey in f_LicenceInfo.Keys)
{
writer.WriteStartElement("add");
writer.WriteAttributeString("key", f_LicenceKey);
writer.WriteAttributeString("value", f_LicenceInfo[f_LicenceKey].ToString());
writer.WriteEndElement();
f_UnSignedInfo += f_LicenceKey + f_LicenceInfo[f_LicenceKey];
}
writer.Close();
}
catch
{
return false;
}
string f_SignedInfo = MakeLicence(f_UnSignedInfo);
if(f_SignedInfo == "")
{
return false;
}
try
{
StreamWriter f_swfs = new StreamWriter(f_LicenceFilePath,true,System.Text.Encoding.Unicode);
f_swfs.WriteLine("");
f_swfs.WriteLine(f_SignedInfo);
f_swfs.Close();
}
catch
{
return false;
}
return true;
}
/// <summary>
/// 生成Licence序列号
/// </summary>
/// <param name="f_UnSignedInfo">需要签名的信息</param>
/// <returns>已签名的信息</returns>
private string MakeLicence(string f_UnSignedInfo)
{
string SignedInfo = "";
byte[] f_SignedInfoByte;
if(this.m_Txt == "")
{
return "";
}
try
{
// xfpan [5/20/2004]
CspParameters CSPParam = new CspParameters();
CSPParam.Flags = CspProviderFlags.UseMachineKeyStore;
RSACryptoServiceProvider f_RSA = new RSACryptoServiceProvider(CSPParam);
// xfpan [5/20/2004]
f_RSA.FromXmlString(this.m_Txt);
byte[] f_UnSignedInfoByte = ByteConverter.GetBytes(f_UnSignedInfo);
HashAlgorithm sha = new SHA1CryptoServiceProvider();
f_SignedInfoByte = f_RSA.SignData(f_UnSignedInfoByte,sha);
SignedInfo = ByteConverter.GetString(f_SignedInfoByte);
}
catch
{
return "";
}
return SignedInfo;
}
*/
private void BtnCancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}