diff --git a/CommonLibrary/AccountSupport/FormAccountManage.designer.cs b/CommonLibrary/AccountSupport/FormAccountManage.designer.cs index 89353c1..0da2ef8 100644 --- a/CommonLibrary/AccountSupport/FormAccountManage.designer.cs +++ b/CommonLibrary/AccountSupport/FormAccountManage.designer.cs @@ -1,4 +1,6 @@ -namespace CommonLibrary +using HslCommunication.Controls; + +namespace CommonLibrary { partial class FormAccountManage { @@ -30,8 +32,8 @@ { this.textBox1 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); - this.userButton2 = new BasicFramework.UserButton(); - this.userButton1 = new BasicFramework.UserButton(); + this.userButton2 = new UserButton(); + this.userButton1 = new UserButton(); this.SuspendLayout(); // // textBox1 diff --git a/CommonLibrary/AccountSupport/FormMaintenance.cs b/CommonLibrary/AccountSupport/FormMaintenance.cs new file mode 100644 index 0000000..e9ea1be --- /dev/null +++ b/CommonLibrary/AccountSupport/FormMaintenance.cs @@ -0,0 +1,77 @@ +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; + +namespace CommonLibrary +{ + /// + /// 维护变更的窗口,用来维护服务器的状态,有可能处于维护中 + /// + public partial class FormMaintenance : Form + { + /// + /// 实例化一个窗口对象,用来更改系统的维护状态,然后进行保存 + /// + /// 服务器的参数对象 + public FormMaintenance(ServerSettings settings) + { + InitializeComponent(); + Settings = settings; + } + + private void userButton1_Click(object sender, EventArgs e) + { + if (!userButton1.Selected) + { + userButton1.Selected = true; + userButton2.Selected = false; + } + } + + private void userButton2_Click(object sender, EventArgs e) + { + if (!userButton2.Selected) + { + userButton1.Selected = false; + userButton2.Selected = true; + } + } + + private ServerSettings Settings = null; + + private void FormMaintenance_Shown(object sender, EventArgs e) + { + if (Settings.Can_Account_Login) + { + userButton1.Selected = true; + } + else + { + userButton2.Selected = true; + } + textBox1.Text = Settings.Account_Forbidden_Reason; + } + + private void userButton3_Click(object sender, EventArgs e) + { + if (userButton1.Selected) + { + Settings.Can_Account_Login = true; + } + else + { + Settings.Can_Account_Login = false; + } + + Settings.Account_Forbidden_Reason = textBox1.Text; + Settings.SaveToFile(); + MessageBox.Show("保存成功"); + Close(); + } + } +} diff --git a/CommonLibrary/AccountSupport/FormMaintenance.designer.cs b/CommonLibrary/AccountSupport/FormMaintenance.designer.cs new file mode 100644 index 0000000..ffd165f --- /dev/null +++ b/CommonLibrary/AccountSupport/FormMaintenance.designer.cs @@ -0,0 +1,134 @@ +using HslCommunication.Controls; + +namespace CommonLibrary +{ + partial class FormMaintenance + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.userButton1 = new UserButton(); + this.userButton2 = new UserButton(); + this.label1 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.userButton3 = new UserButton(); + this.SuspendLayout(); + // + // userButton1 + // + this.userButton1.BackColor = System.Drawing.Color.Transparent; + this.userButton1.CustomerInformation = ""; + this.userButton1.EnableColor = System.Drawing.Color.FromArgb(((int)(((byte)(190)))), ((int)(((byte)(190)))), ((int)(((byte)(190))))); + this.userButton1.Font = new System.Drawing.Font("微软雅黑", 15F); + this.userButton1.Location = new System.Drawing.Point(12, 13); + this.userButton1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.userButton1.Name = "userButton1"; + this.userButton1.Size = new System.Drawing.Size(176, 61); + this.userButton1.TabIndex = 0; + this.userButton1.UIText = "可登录"; + this.userButton1.Click += new System.EventHandler(this.userButton1_Click); + // + // userButton2 + // + this.userButton2.BackColor = System.Drawing.Color.Transparent; + this.userButton2.CustomerInformation = ""; + this.userButton2.EnableColor = System.Drawing.Color.FromArgb(((int)(((byte)(190)))), ((int)(((byte)(190)))), ((int)(((byte)(190))))); + this.userButton2.Font = new System.Drawing.Font("微软雅黑", 15F); + this.userButton2.Location = new System.Drawing.Point(231, 13); + this.userButton2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.userButton2.Name = "userButton2"; + this.userButton2.Size = new System.Drawing.Size(189, 61); + this.userButton2.TabIndex = 1; + this.userButton2.UIText = "维护中"; + this.userButton2.Click += new System.EventHandler(this.userButton2_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 78); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(92, 17); + this.label1.TabIndex = 2; + this.label1.Text = "维护中文本说明"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(12, 98); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(411, 55); + this.textBox1.TabIndex = 3; + // + // userButton3 + // + this.userButton3.BackColor = System.Drawing.Color.Transparent; + this.userButton3.CustomerInformation = ""; + this.userButton3.EnableColor = System.Drawing.Color.FromArgb(((int)(((byte)(190)))), ((int)(((byte)(190)))), ((int)(((byte)(190))))); + this.userButton3.Font = new System.Drawing.Font("微软雅黑", 9F); + this.userButton3.Location = new System.Drawing.Point(158, 162); + this.userButton3.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.userButton3.Name = "userButton3"; + this.userButton3.Size = new System.Drawing.Size(115, 37); + this.userButton3.TabIndex = 4; + this.userButton3.UIText = "保存"; + this.userButton3.Click += new System.EventHandler(this.userButton3_Click); + // + // FormMaintenance + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(435, 209); + this.Controls.Add(this.userButton3); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); + this.Controls.Add(this.userButton2); + this.Controls.Add(this.userButton1); + this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.MaximizeBox = false; + this.MaximumSize = new System.Drawing.Size(451, 248); + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(451, 248); + this.Name = "FormMaintenance"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "维护变更"; + this.Shown += new System.EventHandler(this.FormMaintenance_Shown); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private UserButton userButton1; + private UserButton userButton2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox1; + private UserButton userButton3; + } +} \ No newline at end of file diff --git a/CommonLibrary/AccountSupport/FormMaintenance.resx b/CommonLibrary/AccountSupport/FormMaintenance.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/CommonLibrary/AccountSupport/FormMaintenance.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CommonLibrary/AccountSupport/FormPasswordModify.cs b/CommonLibrary/AccountSupport/FormPasswordModify.cs new file mode 100644 index 0000000..0f02d2e --- /dev/null +++ b/CommonLibrary/AccountSupport/FormPasswordModify.cs @@ -0,0 +1,148 @@ +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; + +namespace CommonLibrary +{ + /// + /// 一个简单的修改密码的类 + /// + public partial class FormPasswordModify : Form + { + /// + /// 实例化一个密码修改窗口,需要指定密码修改的方法 + /// + /// 旧密码,需要用来验证权限 + /// 修改密码的真正方法 + /// 指定密码长度最小值,可不提供 + /// 指定密码长度最大值,可不提供 + public FormPasswordModify(string password_old, + Func submitMethod, + int passwordLengthMin = 4, + int passwordLengthMax = 8) + { + InitializeComponent(); + PasswordLengthMin = passwordLengthMin; + PasswordLengthMax = passwordLengthMax; + PasswordOriginal = password_old; + SubmitMethod = submitMethod; + } + + private void FormPasswordModify_Load(object sender, EventArgs e) + { + Text = "密码修改 [务必不要使用简单的密码] "; + timer1.Interval = 1000; + timer1.Tick += Timer1_Tick; + label4.Text = $"剩余修改时间:{WaittingTime}秒"; + } + + private void Timer1_Tick(object sender, EventArgs e) + { + if (WaittingTime > 0) + { + label4.Text = $"剩余修改时间:{WaittingTime--}秒"; + } + else + { + WaittingTime = 120; + panel1.Visible = false; + label4.Text = $"剩余修改时间:{WaittingTime}秒"; + textBox2.Text = ""; + textBox3.Text = ""; + textBox1.Enabled = true; + userButton1.Enabled = true; + timer1.Stop(); + } + } + + private int WaittingTime { get; set; } = 120; + + private void textBox1_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + userButton1.PerformClick(); + } + } + + private void FormPasswordModify_Shown(object sender, EventArgs e) + { + textBox1.Focus(); + } + + private void textBox2_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + textBox3.Focus(); + } + } + + + private void userButton1_Click(object sender, EventArgs e) + { + //验证原密码 + if (textBox1.Text == PasswordOriginal) + { + textBox1.Enabled = false; + userButton1.Enabled = false; + panel1.Visible = true; + textBox2.Focus(); + timer1.Start(); + } + else + { + MessageBox.Show("密码验证错误!"); + } + } + + + private string PasswordOriginal { get; set; } = ""; + private int PasswordLengthMin { get; set; } = 4; + private int PasswordLengthMax { get; set; } = 8; + private Func SubmitMethod = null; + private void userButton2_Click(object sender, EventArgs e) + { + if (textBox2.Text.Length >= PasswordLengthMin && + textBox2.Text.Length <= PasswordLengthMax) + { + if (textBox2.Text != textBox3.Text) + { + MessageBox.Show("两次密码不一致,请重新输入"); + } + else + { + if (SubmitMethod == null) + { + MessageBox.Show("该功能未实现!"); + } + else + { + if (SubmitMethod(textBox2.Text)) + { + MessageBox.Show("密码更新成功!"); + } + else + { + MessageBox.Show("密码更新失败!请稍候重试!"); + } + } + } + } + else + { + MessageBox.Show($"密码长度不正确,请控制在{PasswordLengthMin}-{PasswordLengthMax}位之间"); + } + } + + private void FormPasswordModify_FormClosing(object sender, FormClosingEventArgs e) + { + timer1.Stop(); + } + } +} diff --git a/CommonLibrary/AccountSupport/FormPasswordModify.designer.cs b/CommonLibrary/AccountSupport/FormPasswordModify.designer.cs new file mode 100644 index 0000000..68c2547 --- /dev/null +++ b/CommonLibrary/AccountSupport/FormPasswordModify.designer.cs @@ -0,0 +1,200 @@ +using HslCommunication.Controls; + +namespace CommonLibrary +{ + partial class FormPasswordModify + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.label1 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.userButton1 = new UserButton(); + this.panel1 = new System.Windows.Forms.Panel(); + this.label4 = new System.Windows.Forms.Label(); + this.userButton2 = new UserButton(); + this.textBox3 = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.panel1.SuspendLayout(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(163, 20); + this.label1.TabIndex = 0; + this.label1.Text = "请输入原密码进行验证:"; + // + // textBox1 + // + this.textBox1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.textBox1.Location = new System.Drawing.Point(16, 36); + this.textBox1.Name = "textBox1"; + this.textBox1.PasswordChar = '*'; + this.textBox1.Size = new System.Drawing.Size(287, 23); + this.textBox1.TabIndex = 1; + this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown); + // + // userButton1 + // + this.userButton1.BackColor = System.Drawing.Color.Transparent; + this.userButton1.CustomerInformation = ""; + this.userButton1.EnableColor = System.Drawing.Color.FromArgb(((int)(((byte)(190)))), ((int)(((byte)(190)))), ((int)(((byte)(190))))); + this.userButton1.Font = new System.Drawing.Font("微软雅黑", 9F); + this.userButton1.Location = new System.Drawing.Point(310, 35); + this.userButton1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.userButton1.Name = "userButton1"; + this.userButton1.Size = new System.Drawing.Size(73, 24); + this.userButton1.TabIndex = 2; + this.userButton1.UIText = "确认"; + this.userButton1.Click += new System.EventHandler(this.userButton1_Click); + // + // panel1 + // + this.panel1.Controls.Add(this.label4); + this.panel1.Controls.Add(this.userButton2); + this.panel1.Controls.Add(this.textBox3); + this.panel1.Controls.Add(this.label3); + this.panel1.Controls.Add(this.textBox2); + this.panel1.Controls.Add(this.label2); + this.panel1.Location = new System.Drawing.Point(8, 71); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(384, 328); + this.panel1.TabIndex = 3; + this.panel1.Visible = false; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.ForeColor = System.Drawing.Color.Gray; + this.label4.Location = new System.Drawing.Point(4, 164); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(107, 20); + this.label4.TabIndex = 7; + this.label4.Text = "剩余修改时间:"; + // + // userButton2 + // + this.userButton2.BackColor = System.Drawing.Color.Transparent; + this.userButton2.CustomerInformation = ""; + this.userButton2.EnableColor = System.Drawing.Color.FromArgb(((int)(((byte)(190)))), ((int)(((byte)(190)))), ((int)(((byte)(190))))); + this.userButton2.Font = new System.Drawing.Font("微软雅黑", 10.5F); + this.userButton2.Location = new System.Drawing.Point(134, 235); + this.userButton2.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.userButton2.Name = "userButton2"; + this.userButton2.Size = new System.Drawing.Size(117, 31); + this.userButton2.TabIndex = 6; + this.userButton2.UIText = "提交"; + this.userButton2.Click += new System.EventHandler(this.userButton2_Click); + // + // textBox3 + // + this.textBox3.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.textBox3.Location = new System.Drawing.Point(8, 124); + this.textBox3.Name = "textBox3"; + this.textBox3.PasswordChar = '*'; + this.textBox3.Size = new System.Drawing.Size(287, 23); + this.textBox3.TabIndex = 5; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(4, 97); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(135, 20); + this.label3.TabIndex = 4; + this.label3.Text = "请再次输入新密码:"; + // + // textBox2 + // + this.textBox2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.textBox2.Location = new System.Drawing.Point(8, 61); + this.textBox2.Name = "textBox2"; + this.textBox2.PasswordChar = '*'; + this.textBox2.Size = new System.Drawing.Size(287, 23); + this.textBox2.TabIndex = 3; + this.textBox2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox2_KeyDown); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(4, 34); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(107, 20); + this.label2.TabIndex = 2; + this.label2.Text = "请输入新密码:"; + // + // FormPasswordModify + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(396, 407); + this.Controls.Add(this.panel1); + this.Controls.Add(this.userButton1); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); + this.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5); + this.MaximizeBox = false; + this.MaximumSize = new System.Drawing.Size(412, 446); + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(412, 446); + this.Name = "FormPasswordModify"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "密码修改窗口"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormPasswordModify_FormClosing); + this.Load += new System.EventHandler(this.FormPasswordModify_Load); + this.Shown += new System.EventHandler(this.FormPasswordModify_Shown); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox1; + private UserButton userButton1; + private System.Windows.Forms.Panel panel1; + private UserButton userButton2; + private System.Windows.Forms.TextBox textBox3; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.Label label4; + } +} \ No newline at end of file diff --git a/CommonLibrary/AccountSupport/FormPasswordModify.resx b/CommonLibrary/AccountSupport/FormPasswordModify.resx new file mode 100644 index 0000000..886d0de --- /dev/null +++ b/CommonLibrary/AccountSupport/FormPasswordModify.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/CommonLibrary/AccountSupport/ServerAccount.cs b/CommonLibrary/AccountSupport/ServerAccount.cs index 42047da..cb43401 100644 --- a/CommonLibrary/AccountSupport/ServerAccount.cs +++ b/CommonLibrary/AccountSupport/ServerAccount.cs @@ -8,10 +8,10 @@ using Newtonsoft.Json.Linq; namespace CommonLibrary { /// - /// 服务器的账户管理类,如果你采用这种方式存储,必须仔细阅读说明手册 + /// 服务器的账户管理类,如果你采用这种方式存储,请参照本项目事例 /// /// 账户类,该类必须派生自UserAccount类 - public class ServerAccounts where T : UserAccount, new() + public class ServerAccounts : HslCommunication.BasicFramework.SoftFileSaveBase where T : UserAccount, new() { /// /// 初始化构造方法 @@ -28,11 +28,6 @@ namespace CommonLibrary all_list_accounts.AddRange(accounts); } - /// - /// 所有的帳戶信息存儲的位置,只有設置了才進行保存 - /// - public string FileSavePath { get; set; } = ""; - private List all_list_accounts = new List(); private object lock_list_accounts = new object(); @@ -129,15 +124,8 @@ namespace CommonLibrary /// 成功True,失败False public bool AddNewAccount(string json_account) { - try - { - T account = JObject.Parse(json_account).ToObject(); - return AddNewAccount(account); - } - catch - { - return false; - } + T account = JObject.Parse(json_account).ToObject(); + return AddNewAccount(account); } /// /// 新增一个账户,如果账户名称已经存在,则返回False,注册成功返回True @@ -218,72 +206,46 @@ namespace CommonLibrary { all_list_accounts = JArray.Parse(json).ToObject>(); } - catch + catch(Exception ex) { - - } - } - } - - /// - /// 使用Base64编码将所有的账户信息保存到文件 - /// - public void SaveFile() - { - SaveFile(m => Convert.ToBase64String(Encoding.Unicode.GetBytes(m))); - } - - /// - /// 使用自定义的加密方法将所有账户信息保存到文件 - /// - /// 加密的方式 - public void SaveFile(Converter encrypt) - { - if (FileSavePath != "") - { - string result = GetAllAccountsJson(); - StreamWriter sw = new StreamWriter(FileSavePath, false, Encoding.Default); - sw.Write(encrypt(result)); - sw.Flush(); - sw.Dispose(); - } - } - - /// - /// 使用Base64编码从文件加载所有的账户 - /// - public void LoadByFile() - { - LoadByFile(m => Encoding.Unicode.GetString(Convert.FromBase64String(m))); - } - /// - /// 使用自定义的解密方法加载所有的账户 - /// - public void LoadByFile(Converter decrypt) - { - if (FileSavePath != "") - { - if (File.Exists(FileSavePath)) - { - StreamReader sr = new StreamReader(FileSavePath, Encoding.Default); - string result = sr.ReadToEnd(); - sr.Close(); - sr.Dispose(); - result = decrypt(result); - LoadAllAccountsJson(result); + LogHelper.LogSave(Resource.StringResouce.AccountLoadFailed, ex); } } } - /************************************************************** - * - * 日志记录块,保存运行中的所有的异常信息,方便追踪系统异常 - * - *************************************************************/ + + + /// - /// 日志记录对象 + /// 从字符串加载数据内容 /// - public HslCommunication.Enthernet.HslLogHelper LogHelper { get; set; } + /// + public override void LoadByString(string content) + { + LoadAllAccountsJson(content); + } + /// + /// 获取需要保存的数据内容 + /// + /// + public override string ToSaveString() + { + return GetAllAccountsJson(); + } + /// + /// 使用加密规则从文件加载 + /// + public override void LoadByFile() + { + LoadByFile(m => m); + } + /// + /// 使用加密规则保存到文件 + /// + public override void SaveToFile() + { + SaveToFile(m => m); + } } } diff --git a/CommonLibrary/BasicSupport/FormUpdateLog.cs b/CommonLibrary/BasicSupport/FormUpdateLog.cs new file mode 100644 index 0000000..e0e4a32 --- /dev/null +++ b/CommonLibrary/BasicSupport/FormUpdateLog.cs @@ -0,0 +1,61 @@ +using HslCommunication.BasicFramework; +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; + +namespace CommonLibrary +{ + /// + /// 系统更新日志类窗体 + /// + public partial class FormUpdateLog : Form + { + /// + /// 实例化一个更新窗口的对象,用来呈现更新日志 + /// + /// 包含了更新细节的一个对象,更新日志,更新内容 + public FormUpdateLog(IEnumerable versions) + { + InitializeComponent(); + Versions = versions; + } + private IEnumerable Versions = null; + + private void FormUpdateLog_Load(object sender, EventArgs e) + { + richTextBox1.SelectionIndent = 3; + richTextBox1.SelectionHangingIndent = 16; + richTextBox1.SelectionRightIndent = 3; + + listBox1.DataSource = Versions; + listBox1.SelectedIndexChanged += ListBox1_SelectedIndexChanged; + ListBox1_SelectedIndexChanged(null, new EventArgs()); + } + private void ListBox1_SelectedIndexChanged(object sender, EventArgs e) + { + if (listBox1.SelectedItem != null) + { + VersionInfo info = listBox1.SelectedItem as VersionInfo; + if (info != null) + { + richTextBox1.Clear(); + richTextBox1.AppendText("版本:" + info.VersionNum + Environment.NewLine); + richTextBox1.AppendText("日期:" + info.ReleaseDate.ToShortDateString() + Environment.NewLine); + + + richTextBox1.AppendText(Environment.NewLine); + + richTextBox1.AppendText("内容:" + Environment.NewLine + + info.UpdateDetails.ToString() + Environment.NewLine); + + richTextBox1.SelectionStart = 0; + } + } + } + } +} diff --git a/CommonLibrary/BasicSupport/FormUpdateLog.designer.cs b/CommonLibrary/BasicSupport/FormUpdateLog.designer.cs new file mode 100644 index 0000000..0213a1f --- /dev/null +++ b/CommonLibrary/BasicSupport/FormUpdateLog.designer.cs @@ -0,0 +1,119 @@ +namespace CommonLibrary +{ + partial class FormUpdateLog + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.listBox1 = new System.Windows.Forms.ListBox(); + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.SuspendLayout(); + // + // label2 + // + this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label2.ForeColor = System.Drawing.Color.Black; + this.label2.Location = new System.Drawing.Point(144, 9); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(90, 21); + this.label2.TabIndex = 9; + this.label2.Text = "更新日志:"; + // + // label1 + // + this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label1.ForeColor = System.Drawing.Color.Black; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(74, 21); + this.label1.TabIndex = 8; + this.label1.Text = "版本号:"; + // + // listBox1 + // + this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.listBox1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.listBox1.FormattingEnabled = true; + this.listBox1.ItemHeight = 21; + this.listBox1.Location = new System.Drawing.Point(15, 39); + this.listBox1.Name = "listBox1"; + this.listBox1.Size = new System.Drawing.Size(123, 403); + this.listBox1.TabIndex = 10; + // + // richTextBox1 + // + this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.richTextBox1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.richTextBox1.Location = new System.Drawing.Point(148, 38); + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical; + this.richTextBox1.Size = new System.Drawing.Size(489, 394); + this.richTextBox1.TabIndex = 11; + this.richTextBox1.Text = ""; + // + // FormUpdateLog + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(651, 448); + this.Controls.Add(this.richTextBox1); + this.Controls.Add(this.listBox1); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormUpdateLog"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "更新日志"; + this.Load += new System.EventHandler(this.FormUpdateLog_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox listBox1; + private System.Windows.Forms.RichTextBox richTextBox1; + } +} \ No newline at end of file diff --git a/CommonLibrary/BasicSupport/FormUpdateLog.resx b/CommonLibrary/BasicSupport/FormUpdateLog.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/CommonLibrary/BasicSupport/FormUpdateLog.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CommonLibrary/BasicSupport/FormVersionControl.cs b/CommonLibrary/BasicSupport/FormVersionControl.cs new file mode 100644 index 0000000..b6cdff6 --- /dev/null +++ b/CommonLibrary/BasicSupport/FormVersionControl.cs @@ -0,0 +1,59 @@ +using HslCommunication.BasicFramework; +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; + +namespace CommonLibrary +{ + /// + /// 控制版本号的窗口类 + /// + public partial class FormVersionControl : Form + { + /// + /// + /// + /// + public FormVersionControl(ServerSettings settings) + { + InitializeComponent(); + Settings = settings; + } + private ServerSettings Settings = null; + + private void FormVersionControl_Shown(object sender, EventArgs e) + { + textBox1.Text = Settings.SystemVersion.ToString(); + textBox2.Focus(); + } + + private void userButton1_Click(object sender, EventArgs e) + { + try + { + Settings.SystemVersion = new SystemVersion(textBox2.Text); + } + catch(Exception ex) + { + MessageBox.Show("版本号格式错误:应为1.0.0" + Environment.NewLine + + "错误描述:" + ex.Message); + } + + try + { + Settings.SaveToFile(); + MessageBox.Show("保存成功"); + } + catch(Exception ex) + { + MessageBox.Show("数据保存失败" + Environment.NewLine + + "错误描述:" + ex.Message); + } + } + } +} diff --git a/CommonLibrary/BasicSupport/FormVersionControl.designer.cs b/CommonLibrary/BasicSupport/FormVersionControl.designer.cs new file mode 100644 index 0000000..c683178 --- /dev/null +++ b/CommonLibrary/BasicSupport/FormVersionControl.designer.cs @@ -0,0 +1,122 @@ +using HslCommunication.Controls; + +namespace CommonLibrary +{ + partial class FormVersionControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.userButton1 = new UserButton(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(24, 31); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(68, 17); + this.label1.TabIndex = 0; + this.label1.Text = "当前版本:"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(101, 28); + this.textBox1.Name = "textBox1"; + this.textBox1.ReadOnly = true; + this.textBox1.Size = new System.Drawing.Size(261, 23); + this.textBox1.TabIndex = 1; + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(101, 68); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(261, 23); + this.textBox2.TabIndex = 3; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(24, 71); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(68, 17); + this.label2.TabIndex = 2; + this.label2.Text = "更新版本:"; + // + // userButton1 + // + this.userButton1.BackColor = System.Drawing.Color.Transparent; + this.userButton1.CustomerInformation = ""; + this.userButton1.EnableColor = System.Drawing.Color.FromArgb(((int)(((byte)(190)))), ((int)(((byte)(190)))), ((int)(((byte)(190))))); + this.userButton1.Font = new System.Drawing.Font("微软雅黑", 9F); + this.userButton1.Location = new System.Drawing.Point(145, 110); + this.userButton1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.userButton1.Name = "userButton1"; + this.userButton1.Size = new System.Drawing.Size(110, 30); + this.userButton1.TabIndex = 4; + this.userButton1.UIText = "保存"; + this.userButton1.Click += new System.EventHandler(this.userButton1_Click); + // + // FormVersionControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(397, 158); + this.Controls.Add(this.userButton1); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.label2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); + this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.MaximizeBox = false; + this.MaximumSize = new System.Drawing.Size(413, 197); + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(413, 197); + this.Name = "FormVersionControl"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "系统版本更新"; + this.Shown += new System.EventHandler(this.FormVersionControl_Shown); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.Label label2; + private UserButton userButton1; + } +} \ No newline at end of file diff --git a/CommonLibrary/BasicSupport/FormVersionControl.resx b/CommonLibrary/BasicSupport/FormVersionControl.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/CommonLibrary/BasicSupport/FormVersionControl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CommonLibrary/BasicSupport/SoftSettings.cs b/CommonLibrary/BasicSupport/SoftSettings.cs new file mode 100644 index 0000000..f278b8a --- /dev/null +++ b/CommonLibrary/BasicSupport/SoftSettings.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json.Linq; +using System.IO; +using HslCommunication.BasicFramework; + +//2017-02-10 + +namespace CommonLibrary +{ + /// + /// 服务器的常用参数保存,包含了版本号,公告,是否允许登录,不能登录说明 + /// + public class ServerSettings : SoftFileSaveBase + { + /// + /// 系统的版本号,可以用来验证版本更新的依据 + /// 初始化1.0.0 + /// + public SystemVersion SystemVersion { get; set; } = new SystemVersion("1.0.0"); + /// + /// 系统的公告信息,默认为测试公告 + /// + public string Announcement { get; set; } = "测试公告"; + /// + /// 是否允许账户登录 + /// 超级管理员账户除外 + /// + public bool Can_Account_Login { get; set; } = true; + /// + /// 不允许登录系统的原因 + /// + public string Account_Forbidden_Reason { get; set; } = "系统处于维护中,请稍后登录。"; + + /// + /// 获取需要存储的数据 + /// + /// + public override string ToSaveString() + { + JObject json = new JObject + { + { nameof(SystemVersion), new JValue(SystemVersion.ToString()) }, + { nameof(Announcement), new JValue(Announcement) }, + { nameof(Can_Account_Login), new JValue(Can_Account_Login) }, + { nameof(Account_Forbidden_Reason), new JValue(Account_Forbidden_Reason) } + }; + return json.ToString(); + } + /// + /// 从字符串数据加载配置 + /// + /// + public override void LoadByString(string content) + { + JObject json = JObject.Parse(content); + SystemVersion = new SystemVersion(json.Property(nameof(SystemVersion)).Value.Value()); + Announcement = json.Property(nameof(Announcement)).Value.Value(); + Can_Account_Login = SoftBasic.GetValueFromJsonObject(json, nameof(Can_Account_Login), Can_Account_Login); + Account_Forbidden_Reason = SoftBasic.GetValueFromJsonObject(json, nameof(Account_Forbidden_Reason), Account_Forbidden_Reason); + } + + } + + + /// + /// 用户客户端存储本地JSON数据的类,包含了所有需要存储的信息 + /// + public class JsonSettings : SoftFileSaveBase + { + /// + /// 实例化一个设置的对象 + /// + public JsonSettings() + { + SystemInfo = SoftAuthorize.GetInfo(); + } + /// + /// 指示系统是否是更新后第一次运行 + /// + public bool IsNewVersionRunning { get; set; } = true; + /// + /// 上次系统登录的用户名 + /// + public string LoginName { get; set; } = ""; + /// + /// 上次系统登录的密码 + /// + public string Password { get; set; } = ""; + + /// + /// 当前计算机的机器码,用来判定参数是否是正确的 + /// + public string SystemInfo { get; private set; } + + + + + + + public override string ToSaveString() + { + JObject json = new JObject(); + json.Add(nameof(LoginName), new JValue(LoginName)); + json.Add(nameof(Password), new JValue(Password)); + json.Add(nameof(IsNewVersionRunning), new JValue(IsNewVersionRunning)); + json.Add(nameof(SystemInfo), new JValue(SystemInfo)); + return json.ToString(); + } + public override void LoadByString(string content) + { + JObject json = JObject.Parse(content); + string systemInfo = SoftBasic.GetValueFromJsonObject(json, nameof(SystemInfo), ""); + if (systemInfo == SystemInfo) + { + //文件匹配正确 + LoginName = SoftBasic.GetValueFromJsonObject(json, nameof(LoginName), LoginName); + IsNewVersionRunning = SoftBasic.GetValueFromJsonObject(json, nameof(IsNewVersionRunning), IsNewVersionRunning); + Password = SoftBasic.GetValueFromJsonObject(json, nameof(Password), Password); + } + } + + /// + /// 使用指定的解密实现数据解密 + /// + public override void LoadByFile() + { + LoadByFile(m => SoftSecurity.MD5Decrypt(m, CommonLibrary.Security)); + } + public override void SaveToFile() + { + SaveToFile(m => SoftSecurity.MD5Encrypt(m, CommonLibrary.Security)); + } + + } +} diff --git a/CommonLibrary/Common.cs b/CommonLibrary/Common.cs index 4e4eab0..a46921f 100644 --- a/CommonLibrary/Common.cs +++ b/CommonLibrary/Common.cs @@ -36,7 +36,10 @@ namespace CommonLibrary #endregion - + /// + /// 整个系统的加密解密密码 + /// + public const string Security = "qwertyui"; } diff --git a/CommonLibrary/CommonLibrary.csproj b/CommonLibrary/CommonLibrary.csproj index 72c7d40..c2a87ac 100644 --- a/CommonLibrary/CommonLibrary.csproj +++ b/CommonLibrary/CommonLibrary.csproj @@ -52,8 +52,33 @@ FormAccountManage.cs + + Form + + + FormMaintenance.cs + + + Form + + + FormPasswordModify.cs + + + Form + + + FormUpdateLog.cs + + + Form + + + FormVersionControl.cs + + @@ -68,7 +93,20 @@ FormAccountManage.cs + + FormMaintenance.cs + + + FormPasswordModify.cs + + + FormUpdateLog.cs + + + FormVersionControl.cs + +