通过添加角色页面,体现一个人的代码水平,思路是否严谨?
来源:互联网 发布:弹窗推广软件 编辑:程序博客网 时间:2024/06/08 04:16
1 //-----------------------------------------------------------
2 // All Rights Reserved , Copyright (C) 2010 ,Jirisoft , Ltd .
3 //-----------------------------------------------------------
4
5 using System;
6 using System.Windows.Forms;
7
8 namespace DotNet.WinForm.Role
9 {
10 using DotNet.Model;
11 // 这个按规范的做法,是不能引用的,需要实现瘦客户端(商业逻辑写在服务器上)
12 // using DotNet.Business;
13 using DotNet.Service;
14 using DotNet.Utilities;
15 using DotNet.WinForm.Utilities;
16
17 /// <summary>
18 /// FrmRoleAdd.cs
19 /// 角色管理 - 添加角色(用户组)管理
20 ///
21 /// 修改记录
22 ///
23 /// 2010.09.16 版本:2.0 JiRiGaLa 多种调用方法的例子说明编写。
24 /// 2010.03.15 版本:1.8 JiRiGaLa 改进接口、以传递对象方式实现添加功能。
25 /// 2007.06.05 版本:1.7 JiRiGaLa 整理主键。
26 /// 2007.06.01 版本:1.3 JiRiGaLa 整体整理主键
27 /// 2007.05.17 版本:1.2 JiRiGaLa 增加了多国语言功能,调整了细节部分。
28 /// 2007.05.14 版本:1.1 JiRiGaLa 改进CheckInput(),SaveEntity()。
29 /// 2007.05.10 版本:1.0 JiRiGaLa 角色添加功能页面编写。
30 ///
31 /// 版本:2.0
32 ///
33 /// <author>
34 /// <name>JiRiGaLa</name>
35 /// <date>2010.09.16</date>
36 /// </author>
37 /// </summary>
38 public partial class FrmRoleAdd : BaseForm
39 {
40 public FrmRoleAdd()
41 {
42 InitializeComponent();
43 }
44
45 #region public override void SetControlState() 设置按钮状态
46 /// <summary>
47 /// 设置按钮状态
48 /// </summary>
49 public override void SetControlState()
50 {
51 // 焦点定位
52 this.chkEnabled.Checked = this.UserInfo.IsAdministrator;
53 this.ActiveControl = this.txtRealname;
54 }
55 #endregion
56
57 #region public override bool CheckInput() 检查输入的有效性
58 /// <summary>
59 /// 检查输入的有效性
60 /// </summary>
61 /// <returns>有效</returns>
62 public override bool CheckInput()
63 {
64 bool returnValue = true;
65 this.txtRealname.Text = this.txtRealname.Text.TrimEnd();
66 if (string.IsNullOrEmpty(this.txtRealname.Text))
67 {
68 MessageBox.Show(AppMessage.Format(AppMessage.MSG0007, AppMessage.MSG9978), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
69 this.txtRealname.Focus();
70 return false;
71 }
72 return returnValue;
73 }
74 #endregion
75
76 #region private BaseRoleEntity GetEntity()
77 /// <summary>
78 /// 读取屏幕数据
79 /// </summary>
80 /// <returns>角色实体</returns>
81 private BaseRoleEntity GetEntity()
82 {
83 BaseRoleEntity roleEntity = new BaseRoleEntity();
84 roleEntity.Realname = this.txtRealname.Text;
85 roleEntity.Code = this.txtCode.Text;
86 roleEntity.Description = this.txtDescription.Text;
87 roleEntity.Enabled = this.chkEnabled.Checked ? 1:0;
88 roleEntity.Category = this.rbtnRole.Checked ? "Role" : "UserGroup";
89 roleEntity.AllowDelete = 1;
90 roleEntity.AllowEdit = 1;
91 roleEntity.DeleteMark = 0;
92 return roleEntity;
93 }
94 #endregion
95
96 #region public override bool SaveEntity() 保存
97 /// <summary>
98 /// 保存
99 /// </summary>
100 /// <returns>保存成功</returns>
101 public override bool SaveEntity()
102 {
103 bool returnValue = false;
104 string statusCode = string.Empty;
105 string statusMessage = string.Empty;
106 BaseRoleEntity roleEntity = this.GetEntity();
107
108 // 直接操作数据库,拼接sql语句的。
109
110 // 有参数化的、能防sql注入攻击等的。
111
112 // 有数据库访问组建的。
113
114 // 【入门级别、兴趣爱好者用】
115 // 添加方法一:直接通过添加实体的方式添加数据(入门级的方法,胖客户端,没有逻辑判断的,本地数据库连接)
116 // BaseRoleManager roleManager = new BaseRoleManager(this.UserInfo);
117 // 判断是否存在重复数据
118 // if (!roleManager.Exists(BaseRoleTable.FieldRealname, roleEntity.Realname, BaseRoleTable.FieldDeleteMark, 0))
119 // {
120 // this.EntityId = roleManager.AddEntity(roleEntity);
121 // }
122
123 // 【推荐、开发效率高,B/S项目建议写法】
124 // 添加方法二:通过管理器的,有业务逻辑的,判断是否重复等方式添加数据(推荐的做法,胖客户端,最高效的做法,本地数据库连接)
125 // BaseRoleManager roleManager = new BaseRoleManager(this.UserInfo);
126 // this.EntityId = roleManager.Add(roleEntity, out statusCode);
127
128 // 【直接调用服务的方式,技术要求低,以后有扩展WCF、Remoting、WebService的余地】
129 // 添加方法三:直接调用服务器(胖客户端,商业逻辑在服务层上,本地数据库连接)
130 // RoleService roleService = new RoleService();
131 // this.EntityId = roleService.Add(this.UserInfo, roleEntity, out statusCode, out statusMessage);
132
133 // 【架构完美、开发成本高,真正分布式运行的推荐写法】
134 // 添加方法四:最标准的通过服务工厂来调用添加方法(可以适应多种运行模式,为了实现完美架构,最完美的架构,服务器上连接数据库,非本地数据库连接)
135 this.EntityId = ServiceManager.Instance.RoleService.Add(UserInfo, roleEntity, out statusCode, out statusMessage);
136 if (statusCode == StatusCode.OKAdd.ToString())
137 {
138 if (BaseSystemInfo.ShowInformation)
139 {
140 // 添加成功,进行提示
141 MessageBox.Show(statusMessage, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
142 }
143 this.DialogResult = DialogResult.OK;
144 returnValue = true;
145 }
146 else
147 {
148 MessageBox.Show(statusMessage, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
149 // 是否名称重复了,提高友善性
150 if (statusCode == StatusCode.ErrorNameExist.ToString())
151 {
152 this.txtRealname.SelectAll();
153 this.txtRealname.Focus();
154 }
155 }
156 return returnValue;
157 }
158 #endregion
159
160 private void btnAdd_Click(object sender, EventArgs e)
161 {
162 // 检查输入的有效性
163 if (this.CheckInput())
164 {
165 // 设置鼠标繁忙状态
166 this.Cursor = Cursors.WaitCursor;
167 try
168 {
169 if (this.SaveEntity())
170 {
171 this.DialogResult = DialogResult.OK;
172 // 关闭窗口
173 this.Close();
174 }
175 }
176 catch (Exception ex)
177 {
178 this.ProcessException(ex);
179 }
180 finally
181 {
182 // 设置鼠标默认状态
183 this.Cursor = Cursors.Default;
184 }
185 }
186 }
187
188 private void btnCancel_Click(object sender, EventArgs e)
189 {
190 this.DialogResult = DialogResult.Cancel;
191 this.Close();
192 }
193 }
194 }
欢迎高手点评,相应的界面效果如下:
posted on 2010-09-17 00:23 吉日嘎拉 不仅权通用权限 阅读(498) 评论(6) 编辑 收藏
- 通过添加角色页面,体现一个人的代码水平,思路是否严谨?
- 严谨的代码
- 一道笔试题 体现出的严谨和算法
- 浅谈思路严谨的管理软件中的用户在线状态控制【附部分C#参考代码】
- 浅谈思路严谨的管理软件中的用户在线状态控制【附部分C#参考代码】
- 面向对象的代码体现
- C++细节体现水平
- 如何验证页面上GA监测代码是否添加正确
- NYOJ 663 弟弟的作业【简单题更能体现水平。。。】
- 页面角色的思考
- 基于水平投影,垂直投影的字符图像分割思路和代码实现
- 一行代码添加的页面效果
- 数据库水平切分的两个思路
- 如何在高强压,事务繁多的情况下,保持认真,清晰,严谨的思路
- 如何通过笔迹分析一个人的性格?
- 魏尔斯特拉斯---严谨的典范
- 严谨的程序员
- 实验的严谨性
- 视觉中国的NoSQL之路:从MySQL到MongoDB
- JMF简介(百度百科)
- 创建快捷方式到Windows Mobile程序菜单
- VC++ 6.0 编译器参数设置
- UNICODE字符集下CString与char*的转换
- 通过添加角色页面,体现一个人的代码水平,思路是否严谨?
- VB:绘图示例—屏保软件设计2
- UART设备驱动分析
- TileList渲染器中set data调用两次(对同一数据)
- 分析Hibernate的事务处理机制
- MFC程序中ASSERT与VERIFY两个宏的区别
- oracle中以dba_、user_、v$_、all_、session_、index_开头的常用表和视图
- Oracle时间处理方法大全(网上收集)
- Liferay 如何设置用户的默认语言为简体中文
评论
1920105#2楼 回复 引用
最近也在做这样的系统#3楼 回复 引用 查看
01
#region
public
override bool CheckInput() 检查输入的有效性
02
/// <summary>
03
/// 检查输入的有效性
04
/// </summary>
05
/// <returns>有效</returns>
06
public
override bool CheckInput()
07
{
08
bool returnValue =
true
;
09
this
.txtRealname.Text =
this
.txtRealname.Text.TrimEnd();
10
if
(string.IsNullOrEmpty(
this
.txtRealname.Text))
11
{
12
MessageBox.Show(AppMessage.Format(AppMessage.MSG0007, AppMessage.MSG9978), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
13
this
.txtRealname.Focus();
14
return
false
;
15
}
16
return
returnValue;
17
}
18
#endregion
19
20
21
我觉得 bool returnValue =
true
; 其实是可以省略的
22
你都有
return
false
;
23
最后直接可以
return
true
;
24
如果要用 bool returnValue =
true
;
25
我觉得
return
false
; 应该也要用returnValue =
false
; 只是个人想法,这样看上去就顺眼一点
26
哈哈
#4楼 回复 引用 查看
这篇文章比较喜欢,顶一下!#5楼[楼主] 回复 引用 查看
@佳明说得很有道理,这个程序是习惯性的这么写了,其实这里还真没必要定义一个变量的,采纳你的建议,小小提高一下下,谢谢哦
#6楼 回复 引用 查看
// 加载窗体==浪费时间的注解。
从某种意义上来说,超过一屏的方法,都是有问题的