通过添加角色页面,体现一个人的代码水平,思路是否严谨?

来源:互联网 发布:弹窗推广软件 编辑:程序博客网 时间: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) 编辑 收藏

评论

#1楼  回复 引用    看着好像好复杂啊

2010-09-17 10:40 | 我想要减肥[未注册用户]

#2楼  回复 引用   

最近也在做这样的系统
2010-09-17 10:40 | 我想要减肥[未注册用户]

#3楼  回复 引用 查看   

view source
print?
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哈哈
2010-09-17 14:33 | 佳明      

#4楼  回复 引用 查看   

这篇文章比较喜欢,顶一下!
2010-09-17 17:52 | 风雨者2      

#5楼[楼主]  回复 引用 查看   

@佳明

说得很有道理,这个程序是习惯性的这么写了,其实这里还真没必要定义一个变量的,采纳你的建议,小小提高一下下,谢谢哦
2010-09-18 09:01 | 吉日嘎拉 不仅权限管理      

#6楼  回复 引用 查看   

// 加载窗体
==浪费时间的注解。
从某种意义上来说,超过一屏的方法,都是有问题的
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 mvnrespository k8s,docker XXX XLHtmlStakeholdersandTheirDocumentationNeedsTochoo linux网卡驱动模块安装 的AD转换数据是由高到低存储的,ADCL低4位无效,所以我们要向右移动去掉无效四位, megaboy C洗髓 数组与指针的艺术 洗髓录 同学们,现布置讨论作业2:在自媒体高速发展的今天,每个人如何从自身做起,承担起一份网络社会的公共责任 在自媒体高速发展的今天,每个人如何从自身做起,承担起一份网络社会的公共责任?完成 交换机的级联端口与交换机的普通端口相连时,使用的双绞线跳线类型为( apfs转成exFAT 2004年江苏各市GDP排名 SRO(丝路传说)数据库解析 丝路传说 SRO_VT_SHARD_INIT 网贷 网贷数据 网贷数据出售 360彩 heml 黑暗之光 n0706 c语言入门 segmentwithsamestartandendpiont lte fan segmentwithsamestartandendpiont segmentwithsamestartandendpiont segmentwithsamestartandendpiont segmentwithsamestartandendpiont segmentwithsamestartandendpiont Windows10 Windows10cmd 简单描述你理解的Linux内核版本是什么?,发行版本是什么?CentOS与Linux是什么关系? 简单描述你理解的Linux内核版本? can\'tfindcompilerexecu 有的HTML标记名(标签名)都可以作为标签选择器。