Commit 90e62473 张东亮

更改配置为超级管理配置

1 个父辈 5b33ecee
正在显示 42 个修改的文件 包含 2295 行增加237 行删除

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30413.136
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "source\Common\Common.csproj", "{43CDD09E-FCF3-4960-A01D-3BBFE9933122}"
EndProject
......@@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XLRStore", "source\XLRStore
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HuichuanLibrary", "source\HuichuanLibrary\HuichuanLibrary.csproj", "{C9575C5E-9D4B-4B4F-BE41-926652B8985F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfigHelper", "source\ConfigHelper\ConfigHelper\ConfigHelper.csproj", "{290182DB-D949-434E-9FF7-C59BDE3F433A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -39,6 +41,10 @@ Global
{C9575C5E-9D4B-4B4F-BE41-926652B8985F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9575C5E-9D4B-4B4F-BE41-926652B8985F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9575C5E-9D4B-4B4F-BE41-926652B8985F}.Release|Any CPU.Build.0 = Release|Any CPU
{290182DB-D949-434E-9FF7-C59BDE3F433A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{290182DB-D949-434E-9FF7-C59BDE3F433A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{290182DB-D949-434E-9FF7-C59BDE3F433A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{290182DB-D949-434E-9FF7-C59BDE3F433A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -73,6 +73,12 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConfigHelper\ConfigHelper\ConfigHelper.csproj">
<Project>{290182db-d949-434e-9ff7-c59bde3f433a}</Project>
<Name>ConfigHelper</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.
......
......@@ -7,15 +7,13 @@ using System.Threading;
using System.Xml;
using System.Windows.Forms;
using log4net;
using ConfigHelper;
namespace OnlineStore.Common
{
public class ConfigAppSettings
{
//public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static int seq = 1;
static object lockobj = new object();
public static int nextSeq()
{
if (seq.Equals(Int32.MaxValue))
......@@ -26,189 +24,44 @@ namespace OnlineStore.Common
Interlocked.Increment(ref seq);
return seq;
}
public static string GetValue(string keyStr, string storeStr)
/// <summary>
/// 获取配置值
/// </summary>
/// <param name="key">键</param>
/// <param name="failVal">不存在键时返回的默认值</param>
/// <returns></returns>
public static string GetValue(string key, string failVal = "")
{
string key = keyStr + storeStr;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
return GetValue(keyStr);
}
else
{
return config.AppSettings.Settings[key].Value;
}
return Config.Get(key, failVal);
}
public static string GetValue(string key)
public static bool GetBoolValue(string key, bool failVal = false)
{
string res = "";
if (Monitor.TryEnter(lockobj, 500))
{
try
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
}
else
{
res= config.AppSettings.Settings[key].Value;
}
}
finally
{
Monitor.Exit(lockobj);
}
}
return res;
return Config.Get(key, failVal);
}
public static decimal GetNumValue(string key)
{
decimal a = 0;
if (Monitor.TryEnter(lockobj, 500))
{
try
{
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
}
else
{
Decimal.TryParse(config.AppSettings.Settings[key].Value, out a);
}
}
finally
{
Monitor.Exit(lockobj);
}
}
Decimal.TryParse(GetValue(key, "0"), out a);
return a;
}
public static int GetIntValue(string key)
public static int GetIntValue(string key, int defaulVal = 0)
{
int a = 0;
if (Monitor.TryEnter(lockobj, 500))
{
try
{
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
}
else
{
Int32.TryParse(config.AppSettings.Settings[key].Value, out a);
}
}
finally
{
Monitor.Exit(lockobj);
}
}
Int32.TryParse(GetValue(key, defaulVal.ToString()), out a);
return a;
}
public static void SaveValue(string key, int value)
{
SaveValue(key, value.ToString());
}
public static void SaveValue(string key, string value)
public static void SaveValue(string key, bool value)
{
if (Monitor.TryEnter(lockobj, 300))
{
try
{
if (key.Equals(""))
//if (key.Equals("") || value.Equals(""))
{
return;
}
//增加的内容写在appSettings段下 <add key="RegCode" value="0"/>
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
SetValue(key, value);
}
else
{
UpdateConfig(key, value);
}
}
catch (Exception ex)
{
LogUtil.error("SaveValue保存配置出错:AppKey=" + key + ",AppValue=" + value + ",", ex);
}
finally
{
Monitor.Exit(lockobj);
}
}
}
public static string GetValue(object debugDeviceId)
{
throw new NotImplementedException();
}
/// <summary>
/// 更新配置文件信息
/// </summary>
/// <param name="name">配置文件字段名称</param>
/// <param name="Xvalue">值</param>
private static void UpdateConfig(string name, string Xvalue)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(Application.ExecutablePath + ".config");
XmlNode node = doc.SelectSingleNode(@"//add[@key='" + name + "']");
XmlElement ele = (XmlElement)node;
ele.SetAttribute("value", Xvalue);
doc.Save(Application.ExecutablePath + ".config");
}
catch (Exception ex)
{
LogUtil.error("UpdateConfig保存配置出错:name=" + name + ",Xvalue=" + Xvalue + ",", ex);
}
SaveValue(key, value.ToString());
}
///<summary>
///向.config文件的appKey结写入信息AppValue 保存设置
///</summary>
///<param name="AppKey">节点名</param>
///<param name="AppValue">值</param>
private static void SetValue(String AppKey, String AppValue)
public static void SaveValue(string key, string value)
{
try
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");
XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if (xElem1 != null)
xElem1.SetAttribute("value", AppValue);
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key", AppKey);
xElem2.SetAttribute("value", AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
}
catch (Exception ex)
{
LogUtil.error("SetValue保存配置出错:AppKey=" + AppKey + ",AppValue=" + AppValue + ",", ex);
}
Config.Set(key, value);
}
}
}
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30503.244
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfigHelper", "ConfigHelper\ConfigHelper.csproj", "{290182DB-D949-434E-9FF7-C59BDE3F433A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "testconfig", "testconfig\testconfig.csproj", "{E7BDF034-75B7-4499-A934-8B9726968313}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{290182DB-D949-434E-9FF7-C59BDE3F433A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{290182DB-D949-434E-9FF7-C59BDE3F433A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{290182DB-D949-434E-9FF7-C59BDE3F433A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{290182DB-D949-434E-9FF7-C59BDE3F433A}.Release|Any CPU.Build.0 = Release|Any CPU
{E7BDF034-75B7-4499-A934-8B9726968313}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7BDF034-75B7-4499-A934-8B9726968313}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7BDF034-75B7-4499-A934-8B9726968313}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7BDF034-75B7-4499-A934-8B9726968313}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9D1FAAA2-1A90-4C33-BE7E-469B954F7945}
EndGlobalSection
EndGlobal

namespace ConfigHelper
{
partial class AdvanceConfigEdit
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
this.btn_save = new System.Windows.Forms.Button();
this.cb_backuplist = new System.Windows.Forms.ComboBox();
this.btn_backup = new System.Windows.Forms.Button();
this.btn_restore = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// propertyGrid1
//
this.propertyGrid1.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.propertyGrid1.Location = new System.Drawing.Point(0, 0);
this.propertyGrid1.Name = "propertyGrid1";
this.propertyGrid1.Size = new System.Drawing.Size(614, 374);
this.propertyGrid1.TabIndex = 0;
//
// btn_save
//
this.btn_save.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_save.Location = new System.Drawing.Point(526, 380);
this.btn_save.Name = "btn_save";
this.btn_save.Size = new System.Drawing.Size(88, 42);
this.btn_save.TabIndex = 1;
this.btn_save.Text = "Save";
this.btn_save.UseVisualStyleBackColor = true;
this.btn_save.Click += new System.EventHandler(this.btn_save_Click);
//
// cb_backuplist
//
this.cb_backuplist.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.cb_backuplist.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cb_backuplist.FormattingEnabled = true;
this.cb_backuplist.Location = new System.Drawing.Point(94, 392);
this.cb_backuplist.Name = "cb_backuplist";
this.cb_backuplist.Size = new System.Drawing.Size(144, 20);
this.cb_backuplist.TabIndex = 2;
//
// btn_backup
//
this.btn_backup.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btn_backup.Location = new System.Drawing.Point(0, 380);
this.btn_backup.Name = "btn_backup";
this.btn_backup.Size = new System.Drawing.Size(88, 42);
this.btn_backup.TabIndex = 1;
this.btn_backup.Text = "Backup";
this.btn_backup.UseVisualStyleBackColor = true;
this.btn_backup.Click += new System.EventHandler(this.btn_backup_Click);
//
// btn_restore
//
this.btn_restore.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btn_restore.Location = new System.Drawing.Point(244, 380);
this.btn_restore.Name = "btn_restore";
this.btn_restore.Size = new System.Drawing.Size(88, 42);
this.btn_restore.TabIndex = 1;
this.btn_restore.Text = "Restore";
this.btn_restore.UseVisualStyleBackColor = true;
this.btn_restore.Click += new System.EventHandler(this.btn_restore_Click);
//
// AdvanceConfigEdit
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.cb_backuplist);
this.Controls.Add(this.btn_restore);
this.Controls.Add(this.btn_backup);
this.Controls.Add(this.btn_save);
this.Controls.Add(this.propertyGrid1);
this.Name = "AdvanceConfigEdit";
this.Size = new System.Drawing.Size(614, 422);
this.Load += new System.EventHandler(this.AdvanceConfigEdit_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PropertyGrid propertyGrid1;
private System.Windows.Forms.Button btn_save;
private System.Windows.Forms.ComboBox cb_backuplist;
private System.Windows.Forms.Button btn_backup;
private System.Windows.Forms.Button btn_restore;
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConfigHelper
{
public partial class AdvanceConfigEdit : UserControl
{
public AdvanceConfigEdit()
{
InitializeComponent();
}
/// <summary>
/// 自定义编辑器
/// </summary>
public Dictionary<string, Type> CustomEditor = new Dictionary<string, Type>();
private void AdvanceConfigEdit_Load(object sender, EventArgs e)
{
propertyGrid1.PropertySort = PropertySort.Categorized;
propertyGrid1.SelectedObject = new DictionaryPropertyGridAdapter(Config.ConfigList, CustomEditor);
backupload();
}
private void btn_save_Click(object sender, EventArgs e)
{
if (Config.HasChange)
btn_backup_Click(this, EventArgs.Empty);
Config.SaveChange();
}
static string BaseDIr = System.AppDomain.CurrentDomain.BaseDirectory;
void backupload() {
var backdir = Path.Combine(BaseDIr, "Config");
backdir = Path.Combine(backdir, "Backup");
if (!Directory.Exists(backdir))
return;
var backdirs = Directory.GetDirectories(backdir);
if (backdirs.Length == 0)
return;
var backdirlist = backdirs.ToList().ConvertAll((x) => {
return Path.GetFileName(x);
});
backdirlist.Sort();
backdirlist.Reverse();
cb_backuplist.Items.Clear();
cb_backuplist.Items.AddRange(backdirlist.ToArray());
cb_backuplist.SelectedIndex = 0;
}
private void btn_backup_Click(object sender, EventArgs e)
{
var backdir = Path.Combine(BaseDIr, "Config");
backdir = Path.Combine(backdir, "Backup");
backdir = Path.Combine(backdir, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
Directory.CreateDirectory(backdir);
Config.ConfigList.Values.ToList().ForEach((c) => {
var cfgbckFile = Path.Combine(backdir, c.configFile);
var cfgFile = Path.Combine(BaseDIr, "Config\\" + c.configFile);
if (!File.Exists(cfgbckFile) && File.Exists(cfgFile))
File.Copy(cfgFile, cfgbckFile);
});
backupload();
}
private void btn_restore_Click(object sender, EventArgs e)
{
var configdir = Path.Combine(BaseDIr, "Config");
var backdir = Path.Combine(configdir, "Backup");
backdir = Path.Combine(backdir, cb_backuplist.SelectedItem.ToString());
var cfgfiles = Directory.GetFiles(backdir, "*.config");
cfgfiles.ToList().ForEach((x) => {
var cn = Path.GetFileName(x);
File.Copy(x, Path.Combine(configdir,cn), true);
});
Config.ReloadConfig();
propertyGrid1.SelectedObject = new DictionaryPropertyGridAdapter(Config.ConfigList, CustomEditor);
}
}
class DictionaryPropertyGridAdapter : ICustomTypeDescriptor
{
Dictionary<string, ConfigStruct> _dictionary;
Dictionary<string, Type> _customeditor;
public DictionaryPropertyGridAdapter(Dictionary<string, ConfigStruct> d, Dictionary<string, Type> customeditor)
{
_dictionary = d;
_customeditor = customeditor;
}
//Three of the ICustomTypeDescriptor methods are never called by the property grid, but we'll stub them out properly anyway:
public string GetComponentName()
{
return TypeDescriptor.GetComponentName(this, true);
}
public EventDescriptor GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(this, true);
}
public string GetClassName()
{
return TypeDescriptor.GetClassName(this, true);
}
//Then there's a whole slew of methods that are called by PropertyGrid, but we don't need to do anything interesting in them:
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{
return TypeDescriptor.GetEvents(this, attributes, true);
}
EventDescriptorCollection System.ComponentModel.ICustomTypeDescriptor.GetEvents()
{
return TypeDescriptor.GetEvents(this, true);
}
public TypeConverter GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
}
public object GetPropertyOwner(PropertyDescriptor pd)
{
return _dictionary;
}
public AttributeCollection GetAttributes()
{
return TypeDescriptor.GetAttributes(this, true);
}
public object GetEditor(Type editorBaseType)
{
return TypeDescriptor.GetEditor(this, editorBaseType, true);
}
public PropertyDescriptor GetDefaultProperty()
{
return null;
}
PropertyDescriptorCollection System.ComponentModel.ICustomTypeDescriptor.GetProperties()
{
return ((ICustomTypeDescriptor)this).GetProperties(new Attribute[0]);
}
//Then the interesting bit. We simply iterate over the IDictionary, creating a property descriptor for each entry:
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
ArrayList properties = new ArrayList();
foreach (var e in _dictionary)
{
Type cust = null;
if (_customeditor.ContainsKey(e.Value.Key))
{
cust = _customeditor[e.Value.Key];
}
properties.Add(new DictionaryPropertyDescriptor(e.Value,cust));
//properties.Add
}
PropertyDescriptor[] props =
(PropertyDescriptor[])properties.ToArray(typeof(PropertyDescriptor));
return new PropertyDescriptorCollection(props);
}
}
class DictionaryPropertyDescriptor : PropertyDescriptor
{
//PropertyDescriptor provides 3 constructors. We want the one that takes a string and an array of attributes:
ConfigStruct configStruct;
internal DictionaryPropertyDescriptor(ConfigStruct cs, Type customEditor)
: base(cs.Key.ToString(), attributes1(cs, customEditor))
{
configStruct = cs;
}
static Attribute[] attributes1(ConfigStruct d,Type customEditor) {
List<Attribute> attributes = new List<Attribute>();
CategoryAttribute myAttribute = new CategoryAttribute(d.configFile);
DescriptionAttribute displayNameAttribute = new DescriptionAttribute(d.Comment.Trim());
attributes.Add(myAttribute);
attributes.Add(displayNameAttribute);
if (customEditor !=null) {
EditorAttribute editorAttribute = new EditorAttribute(typeof(CustEditorProvider), typeof(System.Drawing.Design.UITypeEditor));
attributes.Add(editorAttribute);
System.ComponentModel.TypeDescriptionProviderAttribute typeDescriptionProviderAttribute = new TypeDescriptionProviderAttribute(customEditor);
attributes.Add(typeDescriptionProviderAttribute);
}
return attributes.ToArray();
}
//The attributes are used by PropertyGrid to organise the properties into categories, to display help text and so on. We don't bother with any of that at the moment, so we simply pass null.
//The first interesting member is the PropertyType property. We just get the object out of the dictionary and ask it:
public override Type PropertyType
{
get { return configStruct.type; }
//get { return typeof(int); }
}
//If you knew that all of your values were strings, for example, you could just return typeof(string).
//Then we implement SetValue and GetValue:
public override void SetValue(object component, object value)
{
if (configStruct.type.Name == "Color")
configStruct.Value = ((Color)value).Name;
else if(configStruct.type.Name == "String[]")
configStruct.Value = string.Join("\n",(String[])value);
else
configStruct.Value = value.ToString();
Config.SetBindData(configStruct.Key, configStruct.Value);
configStruct.haschange = true;
}
public override object GetValue(object component)
{
if (configStruct.type.Name == "Color")
return Color.FromName(configStruct.Value);
if (configStruct.type.Name == "String[]")
return configStruct.Value.Split(new char[] {'\n'});
if (configStruct.type.BaseType.Name == "Enum")
{
//return Enum.Parse(configStruct.type, configStruct.Value);
try
{
return Enum.Parse(configStruct.type, configStruct.Value); ;
}
catch
{
return Enum.Parse(configStruct.type, Enum.GetNames(configStruct.type)[0]);
}
}
return configStruct.Value;
}
public override bool IsReadOnly
{
get { return false; }
}
public override Type ComponentType
{
get { return null; }
}
public override bool CanResetValue(object component)
{
return false;
}
public override void ResetValue(object component)
{
}
public override bool ShouldSerializeValue(object component)
{
return false;
}
}
}
<?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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file

namespace ConfigHelper
{
partial class AdvanceConfigForm
{
/// <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.advanceConfigEdit1 = new ConfigHelper.AdvanceConfigEdit();
this.SuspendLayout();
//
// advanceConfigEdit1
//
this.advanceConfigEdit1.Dock = System.Windows.Forms.DockStyle.Fill;
this.advanceConfigEdit1.Location = new System.Drawing.Point(0, 0);
this.advanceConfigEdit1.Name = "advanceConfigEdit1";
this.advanceConfigEdit1.Size = new System.Drawing.Size(800, 450);
this.advanceConfigEdit1.TabIndex = 0;
this.advanceConfigEdit1.Load += new System.EventHandler(this.advanceConfigEdit1_Load);
//
// AdvanceConfigForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.advanceConfigEdit1);
this.MinimizeBox = false;
this.Name = "AdvanceConfigForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Advance Config Edit";
this.Load += new System.EventHandler(this.AdvanceConfigForm_Load);
this.ResumeLayout(false);
}
#endregion
private AdvanceConfigEdit advanceConfigEdit1;
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConfigHelper
{
public partial class AdvanceConfigForm : Form
{
public AdvanceConfigForm()
{
InitializeComponent();
advanceConfigEdit1.CustomEditor = CustomEditor;
}
static Dictionary<string, Type> CustomEditor = new Dictionary<string, Type>();
static DateTime lasthit = DateTime.Now;
static int hitcount = 0;
/// <summary>
/// 添加自定义编辑器
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="name"></param>
public static void AddCustomEditor<T>(string name) where T:ICustEditor
{
CustomEditor.Add(name, typeof(T));
}
/// <summary>
/// 显示配置界面,2秒内调用约6次后显示
/// </summary>
/// <param name="owner"></param>
/// <param name="TopMost"></param>
public static void ShowEditDialog(IWin32Window owner,bool TopMost=false)
{
var currhit = DateTime.Now;
var dd = currhit - lasthit;
if (dd.TotalSeconds <= 2)
hitcount++;
else
hitcount = 0;
lasthit = currhit;
if (hitcount < 5)
return;
hitcount = 0;
if (MessageBox.Show("即将打开高级配置界面,该功能仅供原厂工程师使用,擅自调整将产生不可预期的故障.\n\nThe advanced configuration interface is about to be opened. This function is only used by the original engineer. Unauthorized adjustment will cause unpredictable failures.\n\n高度な設定インターフェースが開かれようとしています。この機能は元のエンジニアのみが使用します。許可されていない調整を​​行うと、予期しない障害が発生します。", "Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
return;
AdvanceConfigForm advanceConfigForm = new AdvanceConfigForm();
advanceConfigForm.TopMost = TopMost;
advanceConfigForm.ShowDialog(owner);
}
private void advanceConfigEdit1_Load(object sender, EventArgs e)
{
}
private void AdvanceConfigForm_Load(object sender, EventArgs e)
{
}
}
}
<?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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{290182DB-D949-434E-9FF7-C59BDE3F433A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ConfigHelper</RootNamespace>
<AssemblyName>ConfigHelper</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\ConfigHelper.xml</DocumentationFile>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AdvanceConfigEdit.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="AdvanceConfigEdit.Designer.cs">
<DependentUpon>AdvanceConfigEdit.cs</DependentUpon>
</Compile>
<Compile Include="AdvanceConfigForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="AdvanceConfigForm.Designer.cs">
<DependentUpon>AdvanceConfigForm.cs</DependentUpon>
</Compile>
<Compile Include="Config.cs" />
<Compile Include="ConfigStruct.cs" />
<Compile Include="Config_partial.cs" />
<Compile Include="CustEditorProvider.cs" />
<Compile Include="ICustEditor.cs" />
<Compile Include="IMyConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SaveHandle.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="AdvanceConfigEdit.resx">
<DependentUpon>AdvanceConfigEdit.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="AdvanceConfigForm.resx">
<DependentUpon>AdvanceConfigForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
namespace ConfigHelper
{
internal class ConfigStruct
{
public string configFile;
//public string configKey;
public string Key;
public string Value;
public int configVer;
public bool haschange = false;
public Type type=typeof(string);
public string Comment="";
}
internal class BindStruct
{
//public string configFile;
//public string configKey;
public string Key;
//public string Property;
public object obj;
public Type ValueType = typeof(string);
public PropertyInfo PropertyInfo;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
namespace ConfigHelper
{
public partial class Config
{
/// <summary>
/// 绑定UI属性
/// </summary>
/// <param name="key">配置key</param>
/// <param name="uiobj">ui对象</param>
/// <param name="Property">绑定属性</param>
/// <param name="SaveEvent">绑定事件(object s, EventArgs x),可以为空</param>
/// <param name="defaultvalue">默认值</param>
public static void PropertyBind(object key, object uiobj, string Property, string SaveEvent, string defaultvalue = "")
{
PropertyBind<string>(key, uiobj, Property, SaveEvent, defaultvalue);
}
/// <summary>
/// 绑定UI属性
/// </summary>
/// <param name="key">配置key</param>
/// <param name="uiobj">ui对象</param>
/// <param name="Property">绑定属性</param>
/// <param name="SaveEvent">绑定事件(object s, EventArgs x),可以为空</param>
/// <param name="defaultvalue">默认值</param>
public static void PropertyBind<T>(object key, object uiobj, string Property, string SaveEvent, T defaultvalue= default)
{
var ot = uiobj.GetType();
var pi = ot.GetProperty(Property);
if (pi == null)
throw new Exception($"无法找到对象:[{ot}]的属性:[{Property}]");
if (SaveEvent != null && SaveEvent!="")
{
var ev = ot.GetEvent(SaveEvent);
if (ev == null)
throw new Exception($"无法找到对象:[{ot}]的事件:[{SaveEvent}]");
changeHandler = Delegate.CreateDelegate(ev.EventHandlerType, clickHandler);
ev.AddEventHandler(uiobj, changeHandler);
}
//Get(key)
var val = TypeDataProcess(pi.PropertyType, Get<string>(key, null), defaultvalue);
if (val != null)
{
try
{
pi.SetValue(uiobj, val, null);
}
catch { }
}
BindStruct bindStruct = new BindStruct();
bindStruct.Key = key.ToString();
bindStruct.obj = uiobj;
bindStruct.PropertyInfo = pi;
bindStruct.ValueType = typeof(T);
bindStructlist[key.ToString()] = bindStruct;
}
static object GeyBindData(string key)
{
var bs = bindStructlist[key];
var ot = bs.obj.GetType();
if (bs.obj is System.Windows.Forms.Control) {
var cc = bs.obj as System.Windows.Forms.Control;
if (cc.IsDisposed)
return null;
if (cc.InvokeRequired) {
return cc.Invoke(new Func<object>(()=> {
return GeyBindData(key);
}));
}
}
var ov = bs.PropertyInfo.GetValue(bs.obj, null);
if (bs.PropertyInfo.PropertyType.ToString() == "System.String")
{
var val = TypeDataProcess(bs.ValueType, ov.ToString(), Get(key));
if (val != null)
{
bs.PropertyInfo.SetValue(bs.obj, val.ToString(), null);
ov = val;
}
}
return ov;
}
internal static void SetBindData(string key, string value)
{
if (!bindStructlist.ContainsKey(key))
return;
var bs = bindStructlist[key];
var ot = bs.obj.GetType();
if (bs.obj is System.Windows.Forms.Control)
{
var cc = bs.obj as System.Windows.Forms.Control;
if (cc.IsDisposed)
return;
if (cc.InvokeRequired)
{
cc.Invoke(new Action(() => {
SetBindData(key, value);
}));
}
}
bs.PropertyInfo.SetValue(bs.obj, value.ToString(), null);
}
static void SaveBindData()
{
foreach (var key in bindStructlist.Keys.ToArray()) {
var ov = GeyBindData(key);
var cv = Get(key);
if (ov!=null && cv!=null && ov.ToString()!= cv.ToString())
Set(key, ov.ToString());
}
}
static Type myConfig=null;
internal static bool SaveAsDefault = true;
/// <summary>
/// 转换自定义配置类
/// </summary>
/// <param name="ConfigClassType"></param>
/// <returns>加载到的配置Key数量</returns>
public static int LoadMyConfig(Type ConfigClassType)
{
if (ConfigClassType == null)
return 0;
if (!init) LoadConfig();
myConfig = ConfigClassType;
var fs = ConfigClassType.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
int configcount = 0;
foreach (var field in fs) {
if (!field.FieldType.FullName.StartsWith("ConfigHelper.MyConfig"))
continue;
var fcas = field.GetCustomAttributes(false);
string Description = "";
if (fcas.Length > 0) {
Description = (fcas[0] as DescriptionAttribute).Description;
}
var gv = field.GetValue(null);
if (gv == null)
{
var fdarg = field.FieldType.GetGenericArguments();
var t = fdarg.ElementAt(0);
var key = field.Name;
Type MyConfigType = typeof(MyConfig<>);
Type newType = MyConfigType.MakeGenericType(new Type[] { t });
var obj = Activator.CreateInstance(newType, new object[] { key, Description });
field.SetValue(null, obj);
}
else
{
var KeyField = gv.GetType().GetField("Key");
var key = KeyField.GetValue(gv);
if (key==null || string.IsNullOrEmpty(key.ToString()))
{
var gm = gv.GetType().GetMethod("SetKey", BindingFlags.NonPublic | BindingFlags.Instance);
gm.Invoke(gv, new object[] { field.Name, Description });
}
}
configcount++;
}
SaveAsDefault = false;
return configcount;
}
internal static void ReFreshMyConfig() {
LoadMyConfig(myConfig);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Windows.Forms.Design;
namespace ConfigHelper
{
class CustEditorProvider : System.Drawing.Design.UITypeEditor
{
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
var at = context.PropertyDescriptor.Attributes[typeof(TypeDescriptionProviderAttribute)];
var tm = ((System.ComponentModel.TypeDescriptionProviderAttribute)at).TypeName;
var tt = Type.GetType(tm);
var obj = Activator.CreateInstance(tt);
//IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
//if (edSvc != null)
//{
// edSvc.ShowDialog(f);
//}
return tt.GetMethod("ValueEdit").Invoke(obj, new object[] { value });
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConfigHelper
{
/// <summary>
/// 自定义编辑器接口
/// </summary>
public interface ICustEditor
{
/// <summary>
/// 自己的编辑方法或界面
/// </summary>
/// <param name="value">传入的值</param>
/// <returns>传出的值</returns>
object ValueEdit(object value);
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace ConfigHelper
{
/// <summary>
/// 自动化我的配置
/// </summary>
public class MyConfig<T>
{
/// <summary>
/// 配置的Key
/// </summary>
public string Key;
internal T tempval;
T defaultval=default;
internal void SetKey(string key, string description) {
Key = key;
if (Config.SaveAsDefault && Config.ConfigList.ContainsKey(key))
defaultval = tempval;
else
Set(tempval);
Config.ConfigList[Key].type = typeof(T);
Config.SetComment(Key, description);
}
/// <summary>
/// 配置的值
/// </summary>
public T Val { get => Get(); set => Set(value); }
internal MyConfig(string k, string description) {
Key = k;
if (Config.ConfigList.ContainsKey(Key))
{
Config.ConfigList[Key].type = typeof(T);
Config.SetComment(Key, description);
}
}
T Get(T defaultvalue = default)
{
if (string.IsNullOrEmpty(Key))
Config.ReFreshMyConfig();
return Config.Get(Key, defaultvalue);
}
void Set(T value)
{
Config.Set(Key, value);
}
/// <summary>
/// 获取配置数据的文本
/// </summary>
/// <returns></returns>
public override string ToString()
{
return Config.Get(Key);
}
/// <summary>
/// 隐式转换
/// </summary>
/// <param name="m1"></param>
public static implicit operator T(MyConfig<T> m1) {
return m1.Get(m1.defaultval);
}
/// <summary>
/// 隐式转换
/// </summary>
/// <param name="v1"></param>
public static implicit operator MyConfig<T>(T v1)
{
var c = new MyConfig<T>("","");
c.tempval = v1;
Config.SaveChangeDebounce();
return c;
}
}
/// <summary>
/// 自定义配置描述
/// </summary>
public class MyConfigComment : DescriptionAttribute
{
/// <summary>
/// 配置的说明
/// </summary>
/// <param name="comment"></param>
public MyConfigComment(string comment) : base(comment) { }
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("ConfigHelper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConfigHelper")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("290182db-d949-434e-9ff7-c59bde3f433a")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConfigHelper
{
internal class SaveHandle
{
~SaveHandle() {
Config.SaveChangeDebounceStop = true;
Config.SaveChange();
}
}
}
class Program
{
public static class configset
{
//key按照下划线分类, 按照下划线前半部分归类
[MyConfigComment("软件是否自动启动")]
public static MyConfig<bool> App_AutoRun = false;
[MyConfigComment("软件窗口标题")]
public static MyConfig<string> App_Title = "SMD-BOX-XLC";
[MyConfigComment("温湿度串口号")]
public static MyConfig<Port> Device_COMPORT = Port.COM1;
}
public enum Port
{
COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, COM10, COM11, COM12, COM13, COM14, COM15, COM16, COM17
}
static void Main(string[] args)
{
//初始化参数类
Config.LoadMyConfig(typeof(configset));
//读取值
bool a = configset.App_AutoRun;
string b = configset.App_Title;
Port c = configset.Device_COMPORT;
//写入值
configset.App_AutoRun = true;
var cb_port = new System.Windows.Forms.ComboBox();//实际直接使用控件变量
var cb_autorun = new System.Windows.Forms.CheckBox();//实际直接使用控件变量
//双向绑定界面控件
Config.PropertyBind(configset.Device_COMPORT.Key, cb_port, "SelectedItem", "SelectedIndexChanged");
Config.PropertyBind(configset.App_AutoRun.Key, cb_autorun, "Checked", "CheckedChanged");
//显示遍历配置界面
AdvanceConfigForm advanceConfigForm = new AdvanceConfigForm();
advanceConfigForm.ShowDialog();
}
}
文件属性发生变化
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>

namespace testconfig
{
partial class Form1
{
/// <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.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(149, 121);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(65, 12);
this.label1.TabIndex = 0;
this.label1.Text = "自定义界面";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(494, 332);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace testconfig
{
public partial class Form1 : Form, ConfigHelper.ICustEditor
{
public Form1()
{
InitializeComponent();
}
public object ValueEdit(object value)
{
this.ShowDialog();
return "3456";
}
}
}
<?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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
using ConfigHelper;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace testconfig
{
class Program
{
static void Main(string[] args)
{
Config.SaveToAppdata = true;
//var i = Config.LoadMyConfig(Type.GetType("testconfig.configset"));
configset.CodeScan_CodeType = new string[] {"123","345" };
string x = configset.CodeScan_ParamPath;
AdvanceConfigForm advanceConfigForm = new AdvanceConfigForm();
advanceConfigForm.ShowDialog();
var xx = ConfigHelper.Config.Get<Port>("XRay_Port", Port.COM5);
var aa = Config.Get<int>("testb");
var bb = Config.Get<Color>("tasdasdestb");
var cc = Config.Get<int>(setting.seta);
Console.WriteLine(cc);
var dd = Config.Get<string[]>(setting.setb);
Config.Set<int>(setting.seta, 6);
Config.Set<Color>("tasdasdestb",Color.White);
var xxxx =ConfigHelper.Config.Get<string[]>("wiston_spnlist");
Config.Set(setting.setb, new string[] { "aa33a", "3945", "12312" });
Config.Get("aaa");
AdvanceConfigForm.AddCustomEditor<Form1>("aaa");//自定义配置界面
//AdvanceConfigForm advanceConfigForm = new AdvanceConfigForm();
//advanceConfigForm.ShowDialog();
}
enum aaa {
ddd,
sss,
eee
}
enum setting {
seta,
setb,
}
enum Port
{
COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, COM10, COM11, COM12, COM13, COM14, COM15, COM16, COM17
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("testconfig")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("testconfig")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("e7bdf034-75b7-4499-a934-8b9726968313")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using ConfigHelper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace testconfig
{
public static class configset
{
[MyConfigComment("软件是否自动启动")]
public static MyConfig<bool> App_AutoRun = false;
[MyConfigComment("软件窗口标题")]
public static MyConfig<string> App_Title = "SMD-BOX-XLC";
[MyConfigComment("软件语言")]
public static MyConfig<string> App_Language = "zh-CN";
[MyConfigComment("服务器识别ID")]
public static MyConfig<string> Server_CID = "";
[MyConfigComment("服务器地址")]
public static MyConfig<string> Server_Addr = "";
[MyConfigComment("是否启用蜂鸣器")]
public static MyConfig<bool> Device_EnableBuzzer = true;
[MyConfigComment("扫码识别类型")]
public static MyConfig<string[]> CodeScan_CodeType = new string[] { "QR Code" };
[MyConfigComment("扫码读码数量")]
public static MyConfig<int> CodeScan_CodeCount = 3;
[MyConfigComment("扫码读码匹配参数")]
public static MyConfig<string> CodeScan_ParamPath = "Conifg\\";
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E7BDF034-75B7-4499-A934-8B9726968313}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>testconfig</RootNamespace>
<AssemblyName>testconfig</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="configset.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConfigHelper\ConfigHelper.csproj">
<Project>{290182db-d949-434e-9ff7-c59bde3f433a}</Project>
<Name>ConfigHelper</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
......@@ -223,6 +223,12 @@
<Content Include="SDK\MotorMaster.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Settings\param.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Settings\system.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
......
<?xml version="1.0" encoding="UTF-8"?>
<config ver="10">
<!-- 开始吹气的判断值(配置值=服务器发送的湿度值-开始吹气值)-->
<item key="StartBlowValue" ver="10" value="4" />
<!-- 停止吹气的判断值(配置值=服务器发送的湿度值-停止吹气值)-->
<item key="StopBlowValue" ver="10" value="4" />
<!--温控器类型,0=壁挂王字壳温湿度变送器,1=妙昕温湿度记录仪-->
<item key="HumitureControllerType" ver="10" value="0" />
<!--二维码类型列表配置,用#分割,一维码=Barcode 二维码: QR Code#Data Matrix ECC 200#Micro QR Code-->
<item key="CodeType" value="Data Matrix ECC 200#QR Code"/>
<!--二维码参数文件所在路径,文件名与二维码类型名一样-->
<item key="CodeParamPath" value="\CodeParam\"/>
<!--有效条码数量-->
<item key="CodeCount" ver="10" value="4" />
<!--扫码失败时是否保存图片-->
<item key="SaveErrorImageToFile" ver="10" value="1" />
<!--AGV调度服务器地址-->
<item key="AgvServerIp" value="127.0.0.1"/>
<!--RFID的服务器端口-->
<item key="RfidServer_Port" value="12001"/>
<!--料盘厚度对应的偏移量-->
<item key="ReelHeightOffset" ver="10" value="12=0#16=100#24=200#32=300" />
<!--夹爪夹紧时忽略的料号列表,多个用#分割-->
<item key="PNList" value="3402021720#3402021721#3402021100#3402021101#3402021102#3402021103#3402021104#3402021105#3402021106#3402021107#3402021108#3402021109#3402021112#3402021122"/>
<!--客户端配置文件路径,相对于程序文件-->
<item key="ConfigPath_XLRStore" ver="10" value="\Config\Config_Store.csv" />
<!--入料机构配置文件路径,相对于程序文件-->
<item key="ConfigPath_Input" ver="10" value="\Config\Config_InputEquip.csv" />
<!--存储机构配置文件路径,相对于程序文件-->
<item key="ConfigPath_Box" ver="10" value="\Config\Config_BoxEquip.csv" />
<!--存储机构库位文件路径,相对于程序文件-->
<item key="ConfigPath_BoxPosition" ver="10" value="\Config\linePositions.csv" />
<!--存储机构滑梯位置文件路径,相对于程序文件-->
<item key="ConfigPath_SlidePosition" ver="10" value="\Config\slidePos.data" />
<!--容器缓存文件路径,相对于程序文件-->
<item key="ConfigPath_TrayList" ver="10" value="\Config\TrayList.data" />
<!--库位调试信息文件路径,相对于程序文件-->
<item key="ConfigPath_PosDebugInfo" ver="10" value="\Config\PosDebugInfo.json" />
<!--抽屉位置信息文件路径,相对于程序文件-->
<item key="ConfigPath_DrawerPosition" ver="10" value="\Config\DrawerPosition.csv" />
<!--出库等待料盘拿走的时间,秒-->
<item key="OutStoreWaitSeconds" ver="10" value="10" />
<!--是否需要扫码-->
<item key="NeedScanCode" ver="10" value="1" />
<!--料盘厚度列表,多个使用分号相隔。为空时厚度列表为8, 12, 16, 20, 24, 28, 36, 48-->
<item key="TrayHeightList" ver="10" value="8;12;16;20;24;28;36;48" />
<!--A侧入库缓存区料盘信息-->
<item key="AInStoreInfo" ver="10" value="" />
<!--A侧出库缓存区料盘信息-->
<item key="AOutStoreInfo" ver="10" value="" />
<!--B侧入库缓存区料盘信息-->
<item key="BInStoreInfo" ver="10" value="" />
<!--B侧出库缓存区料盘信息-->
<item key="BOutStoreInfo" ver="10" value="" />
<!--入料机构上有料串时是否自动入库-->
<item key="AutoInput" ver="10" value="1" />
<!--入料机构A侧料串信息-->
<item key="AShelfInfo" ver="10" value="" />
<!--入料机构B侧料串信息-->
<item key="BShelfInfo" ver="10" value="" />
<!--使用RFID时若设备为服务端时,为监听端口-->
<item key="Rfid_Port" ver="10" value="12001" />
<!--QRCode 数量-->
<item key="QRCodeCount" ver="10" value="4" />
<!--关闭相机的抽屉检测功能-->
<item key="CloseCamDetect" ver="10" value="True" />
<!--是否打开托盘编码界面-->
<item key="OpenRFIDWrite" ver="10" value="1" />
<!--是否打开与服务器通讯日志-->
<item key="Server_Log_Open" ver="10" value="0" />
<!--默认的托盘号-->
<item key="DefaultTrayNum" ver="10" value="0" />
</config>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<config ver="10">
<!--软件名称-->
<item key="App_Title" ver="10" value="智能存储仓客户端" />
<!--是否开机自动启动料仓-->
<item key="App_AutoRun" ver="10" value="1" />
<!--服务器地址-->
<item key="http.server" ver="10" value="http://127.0.0.1/smf-core/" />
<!--设备唯一编号-->
<item key="Line_CID" ver="10" value="01" />
<!--默认填充的密码-->
<item key="DefaultPWD" ver="10" value="123456" />
<!--配置的密码-->
<item key="Config_Pwd" ver="10" value="123456" />
<!--是否开启门禁-->
<item key="UseSecurityAccess" ver="10" value="0" />
<!--是否使用蜂鸣器-->
<item key="UseBuzzer" ver="10" value="0" />
<!--系统日志打印等级:info,debug,warn,error-->
<item key="LogLevel" ver="10" value="info" />
<!--是否打印AGV日志-->
<item key="Agv_Log_Open" ver="10" value="0" />
<!--打印调试日志-->
<item key="debug_log" ver="10" value="0" />
<!--图片保存路径-->
<item key="ImagePath" ver="10" value="\Images\" />
</config>
\ No newline at end of file
......@@ -3,75 +3,6 @@
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<appSettings>
<!--是否开机自动启动料仓-->
<add key="App_AutoRun" value="1" />
<add key="App_Title" value="智能存储仓客户端" />
<!--Server address-->
<!-- <add key="http.server" value="http://localhost/smdbox/" /> -->
<add key="http.server" value="http://192.168.33.100/smf-core/" />
<!-- 开始吹气的判断值(配置值=服务器发送的湿度值-开始吹气值)-->
<add key="StartBlowValue" value="4" />
<!-- 停止吹气的判断值(配置值=服务器发送的湿度值-停止吹气值)-->
<add key="StopBlowValue" value="4" />
<!--温控器类型,0=壁挂王字壳温湿度变送器,1=妙昕温湿度记录仪-->
<add key="HumitureControllerType" value="0" />
<!--start one store config-->
<add key="ConfigPath_XLRStore" value="\Config\Config_Store.csv" />
<add key="ConfigPath_Input" value="\Config\Config_InputEquip.csv" />
<add key="ConfigPath_Box" value="\Config\Config_BoxEquip.csv" />
<add key="ConfigPath_BoxPosition" value="\Config\linePositions.csv" />
<add key="ConfigPath_DrawerPosition" value="\Config\DrawerPosition.csv" />
<add key="ConfigPath_TrayList" value="\LineConfig\TrayList.data" />
<add key="ConfigPath_PosDebugInfo" value="\Config\PosDebugInfo.json" />
<add key="Line_CID" value="05" />
<add key="ImagePath" value="\Images\" />
<!--end one store config-->
<!--二维码类型列表配置,用#分割,一维码=Barcode 二维码: QR Code#Data Matrix ECC 200#Micro QR Code-->
<add key="CodeType" value="Data Matrix ECC 200#QR Code" />
<!--<add key="CodeType" value="Data Matrix ECC 200"/>-->
<!--二维码参数文件所在路径,文件名与二维码类型名一样-->
<add key="CodeParamPath" value="\CodeParam\" />
<add key="ACBaudRate" value="115200" />
<add key="Config_Pwd" value="123456" />
<!--出库等待料盘拿走的时间,秒-->
<add key="OutStoreWaitSeconds" value="10" />
<!--流水线监听端口-->
<add key="TCPServerPort" value="5246" />
<!--AGV调度服务器地址-->
<add key="AgvServerIp" value="10.85.162.40" />
<!--ABB机器人服务器-->
<add key="ABBServerPort" value="21" />
<!--关闭相机的抽屉检测功能-->
<add key="CloseCamDetect" value="True" />
<!--是否打开托盘编码界面-->
<add key="OpenRFIDWrite" value="1" />
<add key="DefaultPWD" value="123456" />
<add key="Server_Log_Open" value="0" />
<add key="CodeCount" value="4" />
<add key="DefaultTrayNum" value="0" />
<add key="NeedScanCode" value="1" />
<add key="Agv_Log_Open" value="0" />
<add key="NeedCheckTray" value="0" />
<add key="Feed_LastShelfID_101" value="B19" />
<add key="Feed_LastShelfID_102" value="B23" />
<add key="Feed_LastShelfID_103" value="B25" />
<add key="Feed_LastShelfID_104" value="B7" />
<add key="SaveErrorImageToFile" value="1" />
<add key="RfidServer_Port" value="12001" />
<add key="TrayHeightList" value="8;12;16;20;24;28;36;48" />
<!--夹爪夹紧时忽略的料号列表,多个用#分割-->
<add key="PNList" value="3402021720#3402021721#3402021100#3402021101#3402021102#3402021103#3402021104#3402021105#3402021106#3402021107#3402021108#3402021109#3402021112#3402021122" />
<add key="BOutStoreInfo" value="" />
<add key="AOutStoreInfo" value="" />
<add key="AutoInput" value="1" />
<add key="BShelfInfo" value="{&quot;ShelfRfid&quot;:&quot;000&quot;,&quot;ShelfState&quot;:3,&quot;XuniRfid&quot;:&quot;&quot;}" />
<add key="AInStoreInfo" value="{&quot;singleOut&quot;:false,&quot;barcode&quot;:&quot;TJM220317000620&quot;,&quot;PosId&quot;:&quot;05AA03060413&quot;,&quot;PlateW&quot;:7,&quot;PlateH&quot;:8,&quot;urgentReel&quot;:false,&quot;cutReel&quot;:false,&quot;smallReel&quot;:false,&quot;rfid&quot;:&quot;000&quot;,&quot;rfidLoc&quot;:0,&quot;IsNG&quot;:false,&quot;NgMsg&quot;:&quot;&quot;}" />
<add key="BInStoreInfo" value="" />
<add key="AShelfInfo" value="{&quot;ShelfRfid&quot;:&quot;000&quot;,&quot;ShelfState&quot;:2,&quot;XuniRfid&quot;:&quot;&quot;}" />
<add key="UseSecurityAccess" value="1" />
<add key="UseBuzzer" value="0" />
</appSettings>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs/XLR-SO908.log" />
......
......@@ -59,6 +59,7 @@
this.lblVersion.TabIndex = 276;
this.lblVersion.Text = "版本号:1.1.0000.0000";
this.lblVersion.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lblVersion.Click += new System.EventHandler(this.lblVersion_Click);
//
// lblTime
//
......@@ -94,7 +95,7 @@
//
// FrmAbout
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(543, 248);
this.Controls.Add(this.btnCopy);
......
......@@ -37,5 +37,10 @@ namespace OnlineStore.XLRStore
{
Clipboard.SetDataObject(GetCodeNum(), true);
}
private void lblVersion_Click(object sender, EventArgs e)
{
ConfigHelper.AdvanceConfigForm.ShowEditDialog(this);
}
}
}
......@@ -326,6 +326,10 @@
<Project>{43cdd09e-fcf3-4960-a01d-3bbfe9933122}</Project>
<Name>Common</Name>
</ProjectReference>
<ProjectReference Include="..\ConfigHelper\ConfigHelper\ConfigHelper.csproj">
<Project>{290182db-d949-434e-9ff7-c59bde3f433a}</Project>
<Name>ConfigHelper</Name>
</ProjectReference>
<ProjectReference Include="..\DeviceLibrary\DeviceLibrary.csproj">
<Project>{513bc1c9-800d-43a6-9499-3700baec3554}</Project>
<Name>DeviceLibrary</Name>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!