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

 

 

  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  }

 

 

 

 

欢迎高手点评,相应的界面效果如下:

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值