本章节讲述的各个类是后端系统的核心之一,涉及到系统安全验证、操作日志记录、页面与按键权限控制、后端页面功能封装等内容,希望学习本系列的朋友认真查看新增的类与函数,这对以后使用本框架进行开发时非常重要。
1、父类(基类)的实现
在开发后端首页与相关功能页面前,我们首先要实现的是所有页面的基类(父类),将常用的功能都预先实现出来,而后面的相关UI类则直接继承它,这样就能简单的自动实现了相关页面功能,不用再每个页面去编写某些按键功能或其他一些功能,如果有特殊的需要,再重写对应的功能类就可以了,对于常用功能,由于之前的逻辑层与数据层已使用模板生成好了,所以直接调用,这样的话比如实现一个列表页面的一些功能(如下图),只需要简单的在页面控件使用指定名称,那么一些实现代码就不用再编写了,这些控件自动拥有对应的功能,比如刷新、自动排序、保存排序(直接修改下图中排序列的输入框后点击保存排序就可以了,这个功能不用编写任何一个代码,只需要将按键放到下图位置,然后使用指定名称就可以了)等功能。这样操作将使我们后面的开发工作更加轻松。而对于列表的话,也只需要调用逻辑层函数直接绑定(bll.BindGrid(this, Grid1, Grid1.PageIndex + 1, Grid1.PageSize, InquiryCondition(), _order);)就可以实现列表、分页、翻页、排序等功能。当然列表点击审核的√与×就会同步更改数据库对应记录的字段与图标,也只需要在列表控件对应函数复制进简单的几行代码就可以实现,这些会在后面相应章节中具体讲述。
先上父类与接口代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 using System; 2 using System.Collections.Generic; 3 using System.Web.UI; 4 using DotNet.Utilities; 5 using FineUI; 6 using Solution.Logic.Managers; 7 using Solution.Logic.Managers.Application; 8 9 namespace Solution.Web.Managers.WebManage.Application 10 { 11 ///12 /// Web层页面父类 13 /// 本基类封装了各种常用函数,c减少重复代码的编写 14 /// 15 public abstract class PageBase : System.Web.UI.Page, IPageBase 16 { 17 #region 定义对象 18 //逻辑层接口对象 19 protected ILogicBase bll = null; 20 //定义列表对象 21 private FineUI.Grid grid = null; 22 //页面排序容器 23 ListsortList = null; 24 #endregion 25 26 #region 初始化函数 27 protected override void OnInit(EventArgs e) 28 { 29 base.OnInit(e); 30 31 //检测用户是否超时退出 32 OnlineUsersBll.GetInstence().IsTimeOut(); 33 34 if (!IsPostBack) 35 { 36 //检测当前页面是否有访问权限 37 MenuInfoBll.GetInstence().CheckPagePower(this); 38 39 #region 设置页面按键权限 40 //定义按键控件 41 Control btnControl = null; 42 try 43 { 44 //找到页面放置按键控件的位置 45 ControlCollection controls = MenuInfoBll.GetInstence().GetToolBarControls(this.Controls); 46 //逐个读取出来 47 for (int i = 0; i < controls.Count; i++) 48 { 49 //取出控件 50 btnControl = controls[i]; 51 //判断是否除了刷新、查询和关闭以外的按键 52 if (btnControl.ID != "ButtonRefresh" && btnControl.ID != "ButtonSearch" && btnControl.ID != "ButtonClose" && btnControl.ID != "btnReset") 53 { 54 //是的话检查该按键当前用户是否有控件权限,没有的话则禁用该按键 55 ((FineUI.Button)btnControl).Enabled = MenuInfoBll.GetInstence().CheckControlPower(this, btnControl.ID); 56 } 57 } 58 } 59 catch (Exception) { } 60 #endregion 61 62 //记录用户当前所在的页面位置 63 CommonBll.UserRecord(this); 64 } 65 66 //运行UI页面初始化函数,子类继承后需要重写本函数,以提供给本初始化函数调用 67 Init(); 68 } 69 #endregion 70 71 #region 接口函数,用于UI页面初始化,给逻辑层对象、列表等对象赋值 72 73 /// 74 /// 接口函数,用于UI页面初始化,给逻辑层对象、列表等对象赋值 75 /// 76 public abstract void Init(); 77 78 #endregion 79 80 #region 页面各种按键事件 81 82 ///83 /// 刷新按钮事件 84 /// 85 /// 86 /// 87 protected void ButtonRefresh_Click(object sender, EventArgs e) 88 { 89 FineUI.PageContext.RegisterStartupScript("window.location.reload()"