InitInviteFrom.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using System.Configuration;
  12. using System.IO;
  13. using System.Security.Cryptography;
  14. using System.Management;
  15. namespace Uninpho.Tools.components.SomethingSetting
  16. {
  17. public partial class InitInviteFrom : DevExpress.XtraEditors.XtraForm
  18. {
  19. public InitInviteFrom()
  20. {
  21. InitializeComponent();
  22. }
  23. private void InitInviteFrom_Load(object sender, EventArgs e)
  24. {
  25. loadText();
  26. }
  27. private void simpleButton1_Click(object sender, EventArgs e)
  28. {
  29. if (UserInform.userinf.Pow != 0)
  30. {
  31. if (XtraMessageBox.Show("软件已授权,您确定要更改授权码吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  32. {
  33. SaveAppConfig("sqssrY", richTextBox1.Text);
  34. }
  35. }
  36. else
  37. {
  38. SaveAppConfig("sqssrY", richTextBox1.Text);
  39. }
  40. }
  41. /// <summary>
  42. /// 保存配置文件的设定
  43. /// </summary>
  44. /// <param name="Key"></param>
  45. /// <param name="Value"></param>
  46. private void SaveAppConfig(string Key, string Value)
  47. {
  48. string strFilePath = System.Windows.Forms.Application.ExecutablePath;
  49. Configuration objConfig = ConfigurationManager.OpenExeConfiguration(strFilePath);
  50. bool bolExist = false;
  51. foreach (string Item in objConfig.AppSettings.Settings.AllKeys)
  52. {
  53. if (Item == Key)
  54. {
  55. bolExist = true;
  56. break;
  57. }
  58. }
  59. if (bolExist)
  60. {
  61. objConfig.AppSettings.Settings.Remove(Key);
  62. }
  63. objConfig.AppSettings.Settings.Add(Key, Value);
  64. objConfig.Save(ConfigurationSaveMode.Modified);
  65. ConfigurationManager.RefreshSection("appSettings");
  66. try
  67. {
  68. UserInform.sqCode = Value;
  69. string[] straa = sqClass.Decrypt(UserInform.sqCode, UserInform.sqkey).Split('灬');
  70. UserInform.sqDate = straa[1];
  71. if (UserInform.CPUID == straa[0])
  72. {
  73. if (straa[1] == "forever")
  74. {
  75. UserInform.userinf.Pow = 1;
  76. UserInform.sqType = "Long";
  77. }
  78. else
  79. {
  80. UserInform.sqType = "Short";
  81. DateTime nowtime = DateTime.Now;
  82. DateTime timeLim = Convert.ToDateTime(straa[1]);
  83. if (nowtime < timeLim)
  84. {
  85. UserInform.userinf.Pow = 1;
  86. }
  87. else
  88. {
  89. UserInform.userinf.Pow = 0;
  90. }
  91. }
  92. }
  93. }
  94. catch
  95. {
  96. UserInform.userinf.Pow = 0;
  97. }
  98. finally
  99. {
  100. loadText();
  101. }
  102. }
  103. private void loadText()
  104. {
  105. mechKey.Text = UserInform.CPUID;
  106. if (UserInform.userinf.Pow == 0)
  107. {
  108. if (UserInform.sqType == "Short")
  109. {
  110. labelControl3.Text = "授权已过期";
  111. }
  112. else
  113. {
  114. labelControl3.Text = "未授权";
  115. }
  116. }
  117. else
  118. {
  119. if (UserInform.sqType == "Short")
  120. {
  121. labelControl3.Text = "已授权,授权期限:" + UserInform.sqDate;
  122. }
  123. else
  124. {
  125. labelControl3.Text = "永久授权";
  126. }
  127. }
  128. richTextBox1.Text = UserInform.sqCode;
  129. }
  130. }
  131. }