RDIFramework.NET Development Example ─ Use of Table Constraint Permissions-Web

RDIFramework.NET Development Example ─ Use of Table Constraint Permissions-Web

          In the previous article " RDIFramework.NET Development Example - Use of Table Constraint Permissions - WinForm", we explained the use of table constraint permissions in WinForm. Let's take a look at the use of the Web.

        In practical applications, customers often have such a requirement that a specified user or role can view data under specified conditions. In the RDIFramework.NET framework, the "specified condition" here is called "the constraint expression of the user or role". ". To complete such a function, you can complete it through the "constraint condition permission setting" function of the user or role in the RDIFramework.NET framework, and then call our interface to get the constraint condition expression of the user or role in your business form. can be completed.

         The following interfaces provided by the framework can be invoked to obtain user or role constraints. 

1、RDIFrameworkService.Instance.TableColumnsService.GetConstraint
2、RDIFrameworkService.Instance.TableColumnsService.GetUserConstraint

     Below we use an example to show the setting of the constraint condition permission for the user's reference.

         To use Constraint Privileges, you first need to set the Constraint expression of the user or role in the user privilege or role privilege. The user's "Constraints Permission Settings" are shown in the following figure:

  In "System Management" → "User Rights Management" → "Permission Settings" → "Constraint Permission Settings", the above window can be opened. In the "Table Constraints" setting window, you can select the constraints we need to set the table, and click "Set Condition Expression" to set. As shown below:  

  "Role Constraint Setting" is similar to "User Constraint Setting", you can refer to the above "User Constraint Setting", the role constraint setting window is as follows:

       After the above settings, we can now use the "constraints", which is very simple to use, just use the service interface provided by the framework where the data needs to be displayed. Below we use "Product Management" to demonstrate constraint permissions.

         The user's constraints can be obtained by calling the following interface in the code that obtains paging data in the main interface of "Product Management" 

1. RDIFrameworkService.Instance.TableColumnsService.GetConstraint(this.UserInfo, PiUserTable.TableName, this.UserInfo.Id, ProductInfoTable.TableName); //Get data according to table constraints (by current user).
2. RDIFrameworkService.Instance.TableColumnsService.GetUserConstraint(this.UserInfo, ProductInfoTable.TableName); //Get data according to table constraints (get user and role constraints).

    The complete code is as follows: 

private void GetPageData(RequestParamModel<CASE_PRODUCTINFOEntity> rpm, HttpContext ctx)
{
    var manager = new CASE_PRODUCTINFOManager(this.dbHelper);
    int recordCount = 0;
    string sort = rpm.Sort;
    string order = rpm.Order;
    if (string.IsNullOrEmpty(sort))
    {
        sort = CASE_PRODUCTINFOTable.FieldCREATEON;
    }
    if (string.IsNullOrEmpty(order))
    {
        order = "DESC";
    }
 
    string filter = rpm.Filter;
    if (string.IsNullOrEmpty(filter))
    {
        filter = CASE_PRODUCTINFOTable.FieldDELETEMARK + " = 0 ";
    }
    UserInfo cUser = Utils.UserInfo;
    //string userConstraintExpress = RDIFrameworkService.Instance.TableColumnsService.GetConstraint(cUser, PiUserTable.TableName, cUser.Id, CASE_PRODUCTINFOTable.TableName); //按表约束条件获得数据(按当前用户)。
    string userConstraintExpress = RDIFrameworkService.Instance.TableColumnsService.GetUserConstraint(cUser, CASE_PRODUCTINFOTable.TableName); //按表约束条件获得数据(得到用户与角色的约束条件)。
 
    if (!string.IsNullOrEmpty(userConstraintExpress))
    {
        filter += " AND " + userConstraintExpress;
    }
     
    var dtTemp = manager.GetDTByPage(out recordCount, rpm.Pageindex, rpm.Pagesize, filter, (sort + " " + order));
    ctx.Response.Write(JSONhelper.FormatJSONForEasyuiDataGrid(recordCount, dtTemp));

        在上图中我们对用户”yonghu”设置了约束条件,现在我们以“yonghu”登录系统看下他能看到的数据:

       我们对用户“yonghu”设置的约束条件是单价大于10000,在上图中,可以看到系统已经自动过滤了数据共143条数据。我们再以超级管理员用户登录进来看下,如下图所示: 

 

       以超级管理员登录的数据是8971条。  

       以上只是一个简单的实例展示,还可以更加灵活的应用到其他各个实用的场合。 

作者: EricHu
出处: http://www.cnblogs.com/huyong
Email: [email protected]
QQ:406590790
平台博客: 
      http://blog.csdn.net/chinahuyong
      http://www.cnblogs.com/huyong
关于作者:高级工程师、信息系统项目管理师、DBA。专注于微软平台项目架构、管理和企业解决方案,多年项目开发与管理经验,曾多次组织并开发多个大型项目,精通DotNet,DB(SqlServer、Oracle等)技术。熟悉Java、Delhpi及Linux操作系统,有扎实的网络知识。在面向对象、面向服务以及数据库领域有一定的造诣。现从事DB管理与开发、WinForm、WCF、WebService、网页数据抓取以及ASP.NET等项目管理、开发、架构等工作。
如有问题或建议,请多多赐教!
本文版权归作者和CNBLOGS博客共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,如有问题,可以通过邮箱或QQ 联系我,非常感谢。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326393814&siteId=291194637