准备调整基础框架组件,重构代码,将账户及参数保存代码移动到本框架

This commit is contained in:
dathlin
2017-05-03 15:50:34 +08:00
parent d3d18dc4eb
commit 119eafd6b2
5 changed files with 312 additions and 3 deletions

View File

@@ -0,0 +1,57 @@
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
{
/// <summary>
/// 一个简单的账户管理窗口类
/// </summary>
public partial class FormAccountManage : Form
{
/// <summary>
/// 实例化一个简单的账户管理
/// </summary>
/// <param name="setAccounts">设置账户信息的方法</param>
/// <param name="getAccounts">获取账户信息的方法</param>
public FormAccountManage(Func<string> getAccounts,Func<string,bool> setAccounts)
{
InitializeComponent();
GetAccounts = getAccounts;
SetAccounts = setAccounts;
}
private Func<string> GetAccounts = null;
private Func<string, bool> SetAccounts = null;
private void FormAccountManage_Load(object sender, EventArgs e)
{
}
private void userButton1_Click(object sender, EventArgs e)
{
textBox1.Text = GetAccounts();
}
private void userButton2_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
SetAccounts(textBox1.Text);
MessageBox.Show("账户更新成功");
}
}
private void FormAccountManage_FormClosing(object sender, FormClosingEventArgs e)
{
GetAccounts = null;
SetAccounts = null;
}
}
}

View File

@@ -0,0 +1,118 @@
namespace CommonLibrary
{
partial class FormAccountManage
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
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.SuspendLayout();
//
// textBox1
//
this.textBox1.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.textBox1.Location = new System.Drawing.Point(12, 29);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox1.Size = new System.Drawing.Size(443, 430);
this.textBox1.TabIndex = 0;
//
// 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(256, 17);
this.label1.TabIndex = 1;
this.label1.Text = "数据格式为JSON格式请确认账户信息再修改";
//
// userButton2
//
this.userButton2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
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("微软雅黑", 9F);
this.userButton2.Location = new System.Drawing.Point(465, 69);
this.userButton2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.userButton2.Name = "userButton2";
this.userButton2.Size = new System.Drawing.Size(91, 32);
this.userButton2.TabIndex = 3;
this.userButton2.UIText = "提交";
this.userButton2.Click += new System.EventHandler(this.userButton2_Click);
//
// userButton1
//
this.userButton1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
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(465, 29);
this.userButton1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.userButton1.Name = "userButton1";
this.userButton1.Size = new System.Drawing.Size(91, 32);
this.userButton1.TabIndex = 2;
this.userButton1.UIText = "查看";
this.userButton1.Click += new System.EventHandler(this.userButton1_Click);
//
// FormAccountManage
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(564, 471);
this.Controls.Add(this.userButton2);
this.Controls.Add(this.userButton1);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox1);
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 = "FormAccountManage";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "账户管理界面";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormAccountManage_FormClosing);
this.Load += new System.EventHandler(this.FormAccountManage_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private UserButton userButton1;
private UserButton userButton2;
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -14,14 +14,14 @@ namespace CommonLibrary
public class ServerAccounts<T> where T : UserAccount, new() public class ServerAccounts<T> where T : UserAccount, new()
{ {
/// <summary> /// <summary>
/// 初始化造方法 /// 初始化造方法
/// </summary> /// </summary>
public ServerAccounts() public ServerAccounts()
{ {
} }
/// <summary> /// <summary>
/// 初始化造方法,将添加几个初始化账户 /// 初始化造方法,将添加几个初始化账户
/// </summary> /// </summary>
public ServerAccounts(IEnumerable<T> accounts) public ServerAccounts(IEnumerable<T> accounts)
{ {
@@ -226,7 +226,7 @@ namespace CommonLibrary
} }
/// <summary> /// <summary>
/// 使用Base64编码所有的帳戶信息保存到文件 /// 使用Base64编码所有的账户信息保存到文件
/// </summary> /// </summary>
public void SaveFile() public void SaveFile()
{ {
@@ -236,6 +236,7 @@ namespace CommonLibrary
/// <summary> /// <summary>
/// 使用自定义的加密方法将所有账户信息保存到文件 /// 使用自定义的加密方法将所有账户信息保存到文件
/// </summary> /// </summary>
/// <param name="encrypt">加密的方式</param>
public void SaveFile(Converter<string, string> encrypt) public void SaveFile(Converter<string, string> encrypt)
{ {
if (FileSavePath != "") if (FileSavePath != "")

View File

@@ -38,12 +38,20 @@
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AccountSupport\FormAccountManage.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="AccountSupport\FormAccountManage.designer.cs">
<DependentUpon>FormAccountManage.cs</DependentUpon>
</Compile>
<Compile Include="AccountSupport\ServerAccount.cs" /> <Compile Include="AccountSupport\ServerAccount.cs" />
<Compile Include="AccountSupport\UserAccount.cs" /> <Compile Include="AccountSupport\UserAccount.cs" />
<Compile Include="Common.cs" /> <Compile Include="Common.cs" />
@@ -56,6 +64,11 @@
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="AccountSupport\FormAccountManage.resx">
<DependentUpon>FormAccountManage.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.