其实GPM不仅仅是权限管理系统,其实更是一个灵活的轻量级快速.Net开发架构,他需要最短的学习时间,可以最快速入门,并不是通过玩技术来实现我们的日常需求。GPM中只要写一套代码,就可以实现在多种数据库上的稳定运行。
下面我们给大家参考一下如何在GMP中实现系统参数配置的保存功能,开发界面见下图:
数据库中的保存效果如下:
配置文件中的保存效果如下:
实现代码的优点就是,1套代码支持多种数据库,1个参数基本上1行代码就可以实现保存,读取功能,代码的量少稳定性高。见参考代码如下:
1
//
-----------------------------------------------------------------
2 // All Rights Reserved , Copyright (C) 2012 , Hairihan TECH, Ltd.
3 // -----------------------------------------------------------------
4
5 using System;
6 using System.Data;
7 using System.Windows.Forms;
8
9 namespace DotNet.WinForm
10 {
11 using DotNet.Utilities;
12 using 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>
30 public partial class FrmSystemSecurity : BaseForm
31 {
32 public FrmSystemSecurity()
33 {
34 InitializeComponent();
35 }
36
37 /// <summary>
38 /// 从数据库读取当前配置情况
39 /// </summary>
40 private void GetParameter()
41 {
42 string parameter = string.Empty;
43 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " ServerEncryptPassword ");
44 if (! string.IsNullOrEmpty(parameter))
45 {
46 this.chkServerEncryptPassword.Checked = parameter.Equals( true.ToString());
47 }
48 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " PasswordMiniLength ");
49 if (! string.IsNullOrEmpty(parameter))
50 {
51 this.nudPasswordMiniLength.Value = int.Parse(parameter);
52 }
53 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " NumericCharacters ");
54 if (! string.IsNullOrEmpty(parameter))
55 {
56 this.chkNumericCharacters.Checked = parameter.Equals( true.ToString());
57 }
58 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " PasswordCycle ");
59 if (! string.IsNullOrEmpty(parameter))
60 {
61 this.nudPasswordChangeCycle.Value = int.Parse(parameter);
62 }
63 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " CheckOnLine ");
64 if (! string.IsNullOrEmpty(parameter))
65 {
66 this.chkCheckOnLine.Checked = parameter.Equals( true.ToString());
67 }
68 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " AccountMinimumLength ");
69 if (! string.IsNullOrEmpty(parameter))
70 {
71 this.nudAccountMinimumLength.Value = int.Parse(parameter);
72 }
73 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " PasswordErrowLockLimit ");
74 if (! string.IsNullOrEmpty(parameter))
75 {
76 this.nudPasswordErrowLockLimit.Value = int.Parse(parameter);
77 }
78 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " PasswordErrowLockCycle ");
79 if (! string.IsNullOrEmpty(parameter))
80 {
81 this.nudPasswordErrowLockCycle.Value = int.Parse(parameter);
82 }
83 }
84
85 /// <summary>
86 /// 将设置保存到数据库
87 /// </summary>
88 private void 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>
103 private void GetConfig()
104 {
105 this.chkServerEncryptPassword.Checked = BaseSystemInfo.ServerEncryptPassword;
106 this.nudPasswordMiniLength.Value = BaseSystemInfo.PasswordMiniLength;
107 this.chkNumericCharacters.Checked = BaseSystemInfo.NumericCharacters;
108 this.nudPasswordChangeCycle.Value = BaseSystemInfo.PasswordChangeCycle;
109 this.chkCheckOnLine.Checked = BaseSystemInfo.CheckOnLine;
110 this.nudAccountMinimumLength.Value = BaseSystemInfo.AccountMinimumLength;
111 this.nudPasswordErrowLockLimit.Value = BaseSystemInfo.PasswordErrowLockLimit;
112 this.nudPasswordErrowLockCycle.Value = BaseSystemInfo.PasswordErrowLockCycle;
113 }
114
115 /// <summary>
116 /// 当窗体加载时执行的方法,
117 /// 这个方法会自动处理鼠标的忙碌状态等等
118 /// </summary>
119 public override void FormOnLoad()
120 {
121 this.GetConfig();
122 this.GetParameter();
123 }
124
125 /// <summary>
126 /// 将配置文件保存到XML文件里
127 /// </summary>
128 private void 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>
148 private void SaveSystemConfig()
149 {
150 // 设置鼠标繁忙状态,并保留原先的状态
151 Cursor holdCursor = this.Cursor;
152 this.Cursor = Cursors.WaitCursor;
153 try
154 {
155 this.SaveParameter();
156 this.SaveConfig();
157
158 // 是否需要有提示信息?
159 if (BaseSystemInfo.ShowInformation)
160 {
161 // 批量保存,进行提示
162 MessageBox.Show(AppMessage.MSG0011, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
163 }
164 }
165 catch (Exception ex)
166 {
167 this.ProcessException(ex);
168 }
169 finally
170 {
171 // 设置鼠标默认状态,原来的光标状态
172 this.Cursor = holdCursor;
173 }
174 }
175
176 private void btnConfirm_Click( object sender, EventArgs e)
177 {
178 // 保存系统设置
179 this.SaveSystemConfig();
180 }
181
182 private void btnCancel_Click( object sender, EventArgs e)
183 {
184 this.Close();
185 }
186 }
187 }
2 // All Rights Reserved , Copyright (C) 2012 , Hairihan TECH, Ltd.
3 // -----------------------------------------------------------------
4
5 using System;
6 using System.Data;
7 using System.Windows.Forms;
8
9 namespace DotNet.WinForm
10 {
11 using DotNet.Utilities;
12 using 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>
30 public partial class FrmSystemSecurity : BaseForm
31 {
32 public FrmSystemSecurity()
33 {
34 InitializeComponent();
35 }
36
37 /// <summary>
38 /// 从数据库读取当前配置情况
39 /// </summary>
40 private void GetParameter()
41 {
42 string parameter = string.Empty;
43 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " ServerEncryptPassword ");
44 if (! string.IsNullOrEmpty(parameter))
45 {
46 this.chkServerEncryptPassword.Checked = parameter.Equals( true.ToString());
47 }
48 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " PasswordMiniLength ");
49 if (! string.IsNullOrEmpty(parameter))
50 {
51 this.nudPasswordMiniLength.Value = int.Parse(parameter);
52 }
53 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " NumericCharacters ");
54 if (! string.IsNullOrEmpty(parameter))
55 {
56 this.chkNumericCharacters.Checked = parameter.Equals( true.ToString());
57 }
58 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " PasswordCycle ");
59 if (! string.IsNullOrEmpty(parameter))
60 {
61 this.nudPasswordChangeCycle.Value = int.Parse(parameter);
62 }
63 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " CheckOnLine ");
64 if (! string.IsNullOrEmpty(parameter))
65 {
66 this.chkCheckOnLine.Checked = parameter.Equals( true.ToString());
67 }
68 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " AccountMinimumLength ");
69 if (! string.IsNullOrEmpty(parameter))
70 {
71 this.nudAccountMinimumLength.Value = int.Parse(parameter);
72 }
73 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " PasswordErrowLockLimit ");
74 if (! string.IsNullOrEmpty(parameter))
75 {
76 this.nudPasswordErrowLockLimit.Value = int.Parse(parameter);
77 }
78 parameter = DotNetService.Instance.ParameterService.GetParameter( this.UserInfo, " System ", " SystemSecurity ", " PasswordErrowLockCycle ");
79 if (! string.IsNullOrEmpty(parameter))
80 {
81 this.nudPasswordErrowLockCycle.Value = int.Parse(parameter);
82 }
83 }
84
85 /// <summary>
86 /// 将设置保存到数据库
87 /// </summary>
88 private void 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>
103 private void GetConfig()
104 {
105 this.chkServerEncryptPassword.Checked = BaseSystemInfo.ServerEncryptPassword;
106 this.nudPasswordMiniLength.Value = BaseSystemInfo.PasswordMiniLength;
107 this.chkNumericCharacters.Checked = BaseSystemInfo.NumericCharacters;
108 this.nudPasswordChangeCycle.Value = BaseSystemInfo.PasswordChangeCycle;
109 this.chkCheckOnLine.Checked = BaseSystemInfo.CheckOnLine;
110 this.nudAccountMinimumLength.Value = BaseSystemInfo.AccountMinimumLength;
111 this.nudPasswordErrowLockLimit.Value = BaseSystemInfo.PasswordErrowLockLimit;
112 this.nudPasswordErrowLockCycle.Value = BaseSystemInfo.PasswordErrowLockCycle;
113 }
114
115 /// <summary>
116 /// 当窗体加载时执行的方法,
117 /// 这个方法会自动处理鼠标的忙碌状态等等
118 /// </summary>
119 public override void FormOnLoad()
120 {
121 this.GetConfig();
122 this.GetParameter();
123 }
124
125 /// <summary>
126 /// 将配置文件保存到XML文件里
127 /// </summary>
128 private void 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>
148 private void SaveSystemConfig()
149 {
150 // 设置鼠标繁忙状态,并保留原先的状态
151 Cursor holdCursor = this.Cursor;
152 this.Cursor = Cursors.WaitCursor;
153 try
154 {
155 this.SaveParameter();
156 this.SaveConfig();
157
158 // 是否需要有提示信息?
159 if (BaseSystemInfo.ShowInformation)
160 {
161 // 批量保存,进行提示
162 MessageBox.Show(AppMessage.MSG0011, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
163 }
164 }
165 catch (Exception ex)
166 {
167 this.ProcessException(ex);
168 }
169 finally
170 {
171 // 设置鼠标默认状态,原来的光标状态
172 this.Cursor = holdCursor;
173 }
174 }
175
176 private void btnConfirm_Click( object sender, EventArgs e)
177 {
178 // 保存系统设置
179 this.SaveSystemConfig();
180 }
181
182 private void btnCancel_Click( object sender, EventArgs e)
183 {
184 this.Close();
185 }
186 }
187 }
本文转自 jirigala 51CTO博客,原文链接:http://blog.51cto.com/2347979/1196330,如需转载请自行联系原作者