您的位置:首页 > 运维架构

通用权限管理系统组件中实现系统参数配置保存,附源码

2013-05-09 12:21 1126 查看
通用权限管理系统组件 (GPM - General Permissions Manager) 中实现系统参数配置保存,附源码

其实GPM不仅仅是权限管理系统,其实更是一个灵活的轻量级快速.Net开发架构,他需要最短的学习时间,可以最快速入门,并不是通过玩技术来实现我们的日常需求。GPM中只要写一套代码,就可以实现在多种数据库上的稳定运行。
下面我们给大家参考一下如何在GMP中实现系统参数配置的保存功能,开发界面见下图:



数据库中的保存效果如下:



配置文件中的保存效果如下:



实现代码的优点就是,1套代码支持多种数据库,1个参数基本上1行代码就可以实现保存,读取功能,代码的量少稳定性高。见参考代码如下:


1//-----------------------------------------------------------------
2// All Rights Reserved , Copyright (C) 2012 , Hairihan TECH, Ltd.
3//-----------------------------------------------------------------
4
5using System;
6using System.Data;
7using System.Windows.Forms;
8
9namespace DotNet.WinForm
10 {
11using DotNet.Utilities;
12using DotNet.Business;
13
14///<summary>
15/// FrmSystemSecurity
16/// 用户登录系统
17///
18/// 修改纪录
19///
20/// 2012.02.12 版本:1.1 JiRiGaLa 功能实现。
21/// 2012.01.19 版本:1.0 JiRiGaLa 整理文件。
22///
23/// 版本:1.0
24///
25///<author>
26///<name>JiRiGaLa</name>
27///<date>2012.02.12</date>
28///</author>
29///</summary>
30publicpartialclass FrmSystemSecurity : BaseForm
31 {
32public FrmSystemSecurity()
33 {
34 InitializeComponent();
35 }
36
37///<summary>
38/// 从数据库读取当前配置情况
39///</summary>
40privatevoid GetParameter()
41 {
42string parameter = string.Empty;
43 parameter = DotNetService.Instance.ParameterService.GetParameter(this.UserInfo, "System", "SystemSecurity", "ServerEncryptPassword");
44if (!string.IsNullOrEmpty(parameter))
45 {
46this.chkServerEncryptPassword.Checked = parameter.Equals(true.ToString());
47 }
48 parameter = DotNetService.Instance.ParameterService.GetParameter(this.UserInfo, "System", "SystemSecurity", "PasswordMiniLength");
49if (!string.IsNullOrEmpty(parameter))
50 {
51this.nudPasswordMiniLength.Value = int.Parse(parameter);
52 }
53 parameter = DotNetService.Instance.ParameterService.GetParameter(this.UserInfo, "System", "SystemSecurity", "NumericCharacters");
54if (!string.IsNullOrEmpty(parameter))
55 {
56this.chkNumericCharacters.Checked = parameter.Equals(true.ToString());
57 }
58 parameter = DotNetService.Instance.ParameterService.GetParameter(this.UserInfo, "System", "SystemSecurity", "PasswordCycle");
59if (!string.IsNullOrEmpty(parameter))
60 {
61this.nudPasswordChangeCycle.Value = int.Parse(parameter);
62 }
63 parameter = DotNetService.Instance.ParameterService.GetParameter(this.UserInfo, "System", "SystemSecurity", "CheckOnLine");
64if (!string.IsNullOrEmpty(parameter))
65 {
66this.chkCheckOnLine.Checked = parameter.Equals(true.ToString());
67 }
68 parameter = DotNetService.Instance.ParameterService.GetParameter(this.UserInfo, "System", "SystemSecurity", "AccountMinimumLength");
69if (!string.IsNullOrEmpty(parameter))
70 {
71this.nudAccountMinimumLength.Value = int.Parse(parameter);
72 }
73 parameter = DotNetService.Instance.ParameterService.GetParameter(this.UserInfo, "System", "SystemSecurity", "PasswordErrowLockLimit");
74if (!string.IsNullOrEmpty(parameter))
75 {
76this.nudPasswordErrowLockLimit.Value = int.Parse(parameter);
77 }
78 parameter = DotNetService.Instance.ParameterService.GetParameter(this.UserInfo, "System", "SystemSecurity", "PasswordErrowLockCycle");
79if (!string.IsNullOrEmpty(parameter))
80 {
81this.nudPasswordErrowLockCycle.Value = int.Parse(parameter);
82 }
83 }
84
85///<summary>
86/// 将设置保存到数据库
87///</summary>
88privatevoid SaveParameter()
89 {
90 DotNetService.Instance.ParameterService.SetParameter(this.UserInfo, "System", "SystemSecurity", "ServerEncryptPassword", this.chkServerEncryptPassword.Checked.ToString());
91 DotNetService.Instance.ParameterService.SetParameter(this.UserInfo, "System", "SystemSecurity", "PasswordMiniLength", this.nudPasswordMiniLength.Value.ToString());
92 DotNetService.Instance.ParameterService.SetParameter(this.UserInfo, "System", "SystemSecurity", "NumericCharacters", this.chkNumericCharacters.Checked.ToString());
93 DotNetService.Instance.ParameterService.SetParameter(this.UserInfo, "System", "SystemSecurity", "PasswordCycle", this.nudPasswordChangeCycle.Value.ToString());
94 DotNetService.Instance.ParameterService.SetParameter(this.UserInfo, "System", "SystemSecurity", "CheckOnLine", this.chkCheckOnLine.Checked.ToString());
95 DotNetService.Instance.ParameterService.SetParameter(this.UserInfo, "System", "SystemSecurity", "AccountMinimumLength", this.nudAccountMinimumLength.Value.ToString());
96 DotNetService.Instance.ParameterService.SetParameter(this.UserInfo, "System", "SystemSecurity", "PasswordErrowLockLimit", this.nudPasswordErrowLockLimit.Value.ToString());
97 DotNetService.Instance.ParameterService.SetParameter(this.UserInfo, "System", "SystemSecurity", "PasswordErrowLockCycle", this.nudPasswordErrowLockCycle.Value.ToString());
98 }
99
100///<summary>
101/// 从当前配置文件显示到界面上
102///</summary>
103privatevoid GetConfig()
104 {
105this.chkServerEncryptPassword.Checked = BaseSystemInfo.ServerEncryptPassword;
106this.nudPasswordMiniLength.Value = BaseSystemInfo.PasswordMiniLength;
107this.chkNumericCharacters.Checked = BaseSystemInfo.NumericCharacters;
108this.nudPasswordChangeCycle.Value = BaseSystemInfo.PasswordChangeCycle;
109this.chkCheckOnLine.Checked = BaseSystemInfo.CheckOnLine;
110this.nudAccountMinimumLength.Value = BaseSystemInfo.AccountMinimumLength;
111this.nudPasswordErrowLockLimit.Value = BaseSystemInfo.PasswordErrowLockLimit;
112this.nudPasswordErrowLockCycle.Value = BaseSystemInfo.PasswordErrowLockCycle;
113 }
114
115///<summary>
116/// 当窗体加载时执行的方法,
117/// 这个方法会自动处理鼠标的忙碌状态等等
118///</summary>
119publicoverridevoid FormOnLoad()
120 {
121this.GetConfig();
122this.GetParameter();
123 }
124
125///<summary>
126/// 将配置文件保存到XML文件里
127///</summary>
128privatevoid SaveConfig()
129 {
130 BaseSystemInfo.ServerEncryptPassword = this.chkServerEncryptPassword.Checked;
131 BaseSystemInfo.PasswordMiniLength = (int)this.nudPasswordMiniLength.Value;
132 BaseSystemInfo.NumericCharacters = this.chkNumericCharacters.Checked;
133 BaseSystemInfo.PasswordChangeCycle = (int)this.nudPasswordChangeCycle.Value;
134 BaseSystemInfo.CheckOnLine = this.chkCheckOnLine.Checked;
135 BaseSystemInfo.AccountMinimumLength = (int)this.nudAccountMinimumLength.Value;
136 BaseSystemInfo.PasswordErrowLockLimit = (int)this.nudPasswordErrowLockLimit.Value;
137 BaseSystemInfo.PasswordErrowLockCycle = (int)this.nudPasswordErrowLockCycle.Value;
138
139// 保存用户的信息
140#if (!DEBUG)
141 UserConfigHelper.SaveConfig();
142#endif
143 }
144
145///<summary>
146/// 保存系统设置
147///</summary>
148privatevoid SaveSystemConfig()
149 {
150// 设置鼠标繁忙状态,并保留原先的状态
151 Cursor holdCursor = this.Cursor;
152this.Cursor = Cursors.WaitCursor;
153try
154 {
155this.SaveParameter();
156this.SaveConfig();
157
158// 是否需要有提示信息?
159if (BaseSystemInfo.ShowInformation)
160 {
161// 批量保存,进行提示
162 MessageBox.Show(AppMessage.MSG0011, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
163 }
164 }
165catch (Exception ex)
166 {
167this.ProcessException(ex);
168 }
169finally
170 {
171// 设置鼠标默认状态,原来的光标状态
172this.Cursor = holdCursor;
173 }
174 }
175
176privatevoid btnConfirm_Click(object sender, EventArgs e)
177 {
178// 保存系统设置
179this.SaveSystemConfig();
180 }
181
182privatevoid btnCancel_Click(object sender, EventArgs e)
183 {
184this.Close();
185 }
186 }
187 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐