角色权限批量设置,随点!

<% @ Page Language = " C# "  MasterPageFile = " ~/Master Page/Site.Master "  AutoEventWireup = " true "  CodeBehind = " PopPupRolePerm.aspx.cs "  Inherits = " tt.Security.PopPupControls.PopPupRolePerm "  Title = " 无标题页 "   %>
<% @ MasterType VirtualPath = " ~/Master Page/Site.Master "   %>
<% @ Import Namespace = " WayGo.Enterprise.Web "   %>
<% @ Register Src = " ../UserControls/ModuleSearch.ascx "  TagName = " Search "  TagPrefix = " uc "   %>
< asp:Content ID = " Content1 "  ContentPlaceHolderID = " head "  runat = " server " >
< script type = " text/javascript " > var idControl = ' <%=hidSelectedID.ClientID %> ' ; </ script >
</ asp:Content >
< asp:Content ID = " Content2 "  ContentPlaceHolderID = " ContentPlaceHolder1 "  runat = " server " >
    
< asp:UpdatePanel ID = " up1 "  runat = " server "  UpdateMode = " Conditional " >
        
< ContentTemplate >
            
< asp:HiddenField ID = " hidSelectedID "  runat = " server "   />
            
< asp:TextBox ID = " txtModuleIds "  runat = " server "  style = "  display:none; " ></ asp:TextBox >
            
< uc:Search ID = " ucSearch "  runat = " server "   />
            
< asp:LinkButton ID = " btnDelete "  runat = " server "  OnClick = " btnDelete_Click " >< span > 保存设置 </ span ></ asp:LinkButton >
            
< asp:LinkButton ID = " LinkButton1 "  runat = " server "  OnClick = " btnDelete_Click2 " >< span > 取消设置 </ span ></ asp:LinkButton >
            
< asp:LinkButton ID = " LinkButton2 "  runat = " server "  OnClick = " btnDelete_Click3 " >< span > 保存设置 </ span ></ asp:LinkButton >
            
< Framework:SmartGridView ID = " gvList "  runat = " server "  DefaultSortColumn = " id "  PageSize = " 10 "
                DataKeyNames
= " id "  AllowPaging = " true "  Width = " 100% "  AutoGenerateColumns = " false "
                OnRowCommand
= " gvList_RowCommand "  SelectedRowStyle - BackColor = " #FFE88A " >
                
< Columns >
                    
< asp:TemplateField >
                        
< HeaderTemplate >
                            
< asp:LinkButton ID = " btnSelector "  OnClientClick = " return false; "  runat = " server "  CommandName = " Select "  CommandArgument = " <%#Container.DataItemIndex %> "
                                ToolTip
= " 选中此行 "  CausesValidation = " false "  SkinID = " none " >
                                
< span > 选择 </ span >
                            
</ asp:LinkButton >
                        
</ HeaderTemplate >
                        
< ItemTemplate >
                            
< asp:LinkButton ID = " btnSelector "  runat = " server "  CommandName = " Select "  CommandArgument = " <%#Container.DataItemIndex %> "
                                ToolTip
= " 选中此行 "  CausesValidation = " false "  SkinID = " none " >
                                
< span > 选择 </ span >
                            
</ asp:LinkButton >
                        
</ ItemTemplate >
                    
</ asp:TemplateField >
                    
< asp:TemplateField >
                        
< HeaderTemplate >
                            
< input id = " chkCheckAll "  onclick = " checkAll(this,'chkID') "  type = " checkbox "   />
                        
</ HeaderTemplate >
                        
< ItemTemplate >
                            
< input name = " chkID "  type = " checkbox "  value = ' <%#Eval("moduleId") %> '  onpropertychange = " checkAll(this,'chkID<%#Eval( " moduleid " ) %>') "   />
                        
</ ItemTemplate >
                    
</ asp:TemplateField >
                    
< asp:BoundField HeaderText = " 功能名称 "  DataField = " name "  SortExpression = " name " ></ asp:BoundField >
                    
< asp:BoundField HeaderText = " 功能编号 "  DataField = " code "  SortExpression = " code " ></ asp:BoundField >
                    
< asp:TemplateField HeaderText = " 页面显示 " >
                        
< ItemTemplate >
                            
< input value = " 1 "  name = " chk<%#Eval( " moduleId " ) %>allowshow "   <% #Eval( " allowshow " ).ToString() == " 1 " ? " checked='checked' " : "" %>  id = " chkID<%#Eval( " moduleid " ) %> "  type = " checkbox "   />
                        
</ ItemTemplate >
                    
</ asp:TemplateField >
                    
< asp:TemplateField HeaderText = " 查询权限 " >
                        
< ItemTemplate >
                            
< input value = " 1 "  name = " chk<%#Eval( " moduleId " ) %>allowquery "   <% #Eval( " allowquery " ).ToString() == " 1 " ? " checked='checked' " : "" %>  id = " chkID<%#Eval( " moduleid " ) %> "  type = " checkbox "   />
                        
</ ItemTemplate >
                    
</ asp:TemplateField >
                    
< asp:TemplateField HeaderText = " 添加权限 " >
                        
< ItemTemplate >
                            
< input value = " 1 "  name = " chk<%#Eval( " moduleId " ) %>allowadd "   <% #Eval( " allowadd " ).ToString() == " 1 " ? " checked='checked' " : "" %>  id = " chkID<%#Eval( " moduleid " ) %> "  type = " checkbox "   />
                        
</ ItemTemplate >
                    
</ asp:TemplateField >
                    
< asp:TemplateField HeaderText = " 修改权限 " >
                        
< ItemTemplate >
                            
< input value = " 1 "  name = " chk<%#Eval( " moduleId " ) %>allowedit "   <% #Eval( " allowedit " ).ToString() == " 1 " ? " checked='checked' " : "" %>  id = " chkID<%#Eval( " moduleid " ) %> "  type = " checkbox "   />
                        
</ ItemTemplate >
                    
</ asp:TemplateField >
                    
< asp:TemplateField HeaderText = " 删除权限 " >
                        
< ItemTemplate >
                            
< input value = " 1 "  name = " chk<%#Eval( " moduleId " ) %>allowdelete "   <% #Eval( " allowdelete " ).ToString() == " 1 " ? " checked='checked' " : "" %>  id = " chkID<%#Eval( " moduleid " ) %> "  type = " checkbox "   />
                        
</ ItemTemplate >
                    
</ asp:TemplateField >
                    
< asp:TemplateField HeaderText = " 打印权限 " >
                        
< ItemTemplate >
                            
< input value = " 1 "  name = " chk<%#Eval( " moduleId " ) %>allowprint "   <% #Eval( " allowprint " ).ToString() == " 1 " ? " checked='checked' " : "" %>  id = " chkID<%#Eval( " moduleid " ) %> "  type = " checkbox "   />
                        
</ ItemTemplate >
                    
</ asp:TemplateField >
                    
< asp:TemplateField HeaderText = " 审批权限 " >
                        
< ItemTemplate >
                            
< input value = " 1 "  name = " chk<%#Eval( " moduleId " ) %>allowcheck "   <% #Eval( " allowcheck " ).ToString() == " 1 " ? " checked='checked' " : "" %>  id = " chkID<%#Eval( " moduleid " ) %> "  type = " checkbox "   />
                        
</ ItemTemplate >
                    
</ asp:TemplateField >
                    
< asp:TemplateField HeaderText = " 导出权限 " >
                        
< ItemTemplate >
                            
< input value = " 1 "  name = " chk<%#Eval( " moduleId " ) %>allowexport "   <% #Eval( " allowexport " ).ToString() == " 1 " ? " checked='checked' " : "" %>  id = " chkID<%#Eval( " moduleid " ) %> "  type = " checkbox "   />
                        
</ ItemTemplate >
                    
</ asp:TemplateField >
                    
< asp:TemplateField HeaderText = " 批注权限 "  ItemStyle - Width = " 100% " >
                        
< ItemTemplate >
                            
< input value = " 1 "  name = " chk<%#Eval( " moduleId " ) %>allownote "   <% #Eval( " allownote " ).ToString() == " 1 " ? " checked='checked' " : "" %>  id = " chkID<%#Eval( " moduleid " ) %> "  type = " checkbox "   />
                        
</ ItemTemplate >
                    
</ asp:TemplateField >
                
</ Columns >
            
</ Framework:SmartGridView >
        
</ ContentTemplate >
    
</ asp:UpdatePanel >
</ asp:Content >
using  System;
using  System.Collections;
using  System.Configuration;
using  System.Data;
using  System.Linq;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;
using  System.Xml.Linq;
using  WayGo.Framework.UI.WebControls;
using  WayGo.Framework.UI;
using  DMC.BLL;
using  DMC.Model;
using  WayGo.Enterprise.Web;
using  Milo.Common;
using  WayGo.Framework.Models;
using  System.Collections.Generic;

namespace  tt.Security.PopPupControls
{
    
public   partial   class  PopPupRolePerm : WayGo.Framework.UI.ListBasePage2
    {
        
private   int  PageNum {  get set ; }

        
protected   string  SelectedID
        {
            
get
            {
                
if  ( this .gvList.SelectedIndex  ==   - 1   ||   this .gvList.SelectedIndex  >=   this .gvList.DataKeys.Count)  return   "" ;
                
return   this .gvList.DataKeys[ this .gvList.SelectedIndex].Values[ 0 ].ToString();
            }
        }

        
protected   void  Page_Load( object  sender, EventArgs e)
        {
            Master.Nav.Text 
=   " 测试 " ;
            
if  ( ! IsPostBack)
            {
                
int  tempPage  =  RequestHandler.GetIntQueryString( " pg " );
                
if  (tempPage  !=   int .MinValue)
                {
                    PageNum 
=  tempPage;
                }
            }
            
else
            {
                
int  tempPage  =  ConvertHandler.ToInt32(ViewState[ " pg " ]);
                
if  (tempPage  !=   int .MinValue)
                {
                    PageNum 
=  tempPage;
                }
            }
        }

        
///   <summary>
        
///  获取数据源
        
///   </summary>
        
///   <param name="pageIndex"></param>
        
///   <param name="pageSize"></param>
        
///   <returns></returns>
         protected   override   object  GetDataSource( int  pageIndex,  int  pageSize)
        {
            
if  ( ! IsPostBack  &&  PageNum  !=   0 )
            {
                pageIndex 
=  PageNum;
            }

            PageNum 
=  pageIndex;
            ViewState[
" pg " =  PageNum;

            
string  sortExp  =   string .Empty;
            
if  ( ! string .IsNullOrEmpty(SortingExpression))
                sortExp 
=  SortingExpression  +  (SortingOrder  ==  SortDirection.Ascending  ?   ""  :  "  DESC  " );
            
else
                sortExp 
=  DefaultSortField;

            
int  RecordCount  =   0 ;

            
int  sid  =  RequestHandler.GetIntQueryString( " sid " );
            
if  (sid  ==   int .MinValue)
            {
                
return   null ;
            }

            ConditionCollection cc 
=   new  ConditionCollection();
            SearchCondition sc 
=   new  SearchCondition( " role_id " , sid.ToString(), OperatorType.Equal,  false );
            cc.Add(sc);
            
if  (SearchControl  !=   null )
            {
                
foreach  (SearchCondition s  in  SearchControl.Conditions)
                {
                    cc.Add(s);
                }
            }

            
// --------------------------------------------------------
             object  o  =  CommonPageListDAL.GetPageList( " AAALUO_LS_PopPupRolePerm " "" , sortExp,  0 100000 , cc,  out  RecordCount);
            
            List
< string >  moduleIdList  =   new  List < string > ();
            DataTable dt
= ((DataSet)o).Tables[ 0 ];
            
for  ( int  i  =   0 ; i  <  dt.Rows.Count;i ++  )
            {
                
string  tempId  =  dt.Rows[i][ " moduleid " ].ToString();
                
if  (moduleIdList.Contains(tempId)  ==   false )
                {
                    moduleIdList.Add(tempId);
                }
            }
            AAALUO_LS_ModuleBLL bll 
=   new  AAALUO_LS_ModuleBLL();
            DataTable dt2 
=  bll.GetAllList().Tables[ 0 ];

            
for  ( int  i  =   0 ; i  <  dt2.Rows.Count; i ++ )
            {
                
if  (moduleIdList.Contains(dt2.Rows[i][ " Id " ].ToString())  ==   false )
                {
                    AAALUO_LS_RoleModule roleModule 
=   new  AAALUO_LS_RoleModule();
                    roleModule.Module_ID 
=  ConvertHandler.ToInt32(dt2.Rows[i][ " Id " ].ToString());
                    roleModule.Role_ID 
=  sid;
                    roleModule.SysCreateTime 
=  DateTime.Now;
                    roleModule.SysCreateUserID 
=  CurrentUser.ID;
                    AAALUO_LS_RoleModuleBLL bll2 
=   new  AAALUO_LS_RoleModuleBLL();
                    bll2.Add(roleModule);
                    moduleIdList.Add(dt2.Rows[i][
" Id " ].ToString());
                }
            }
            
// --------------------------------------------------------
            
            
object  o2  =  CommonPageListDAL.GetPageList( " AAALUO_LS_PopPupRolePerm " "" , sortExp, pageIndex, pageSize, cc,  out  RecordCount);

            DataTable dt3 
=  ((DataSet)o2).Tables[ 0 ];
            txtModuleIds.Text 
=   "" ;
            
for  ( int  i  =   0 ; i  <  dt3.Rows.Count; i ++ )
            {
                
string  tempId  =  dt3.Rows[i][ " moduleid " ].ToString();
                
if  (i  ==   0 )
                {
                    txtModuleIds.Text 
=  tempId  +   " , " ;
                }
                
else
                {
                    txtModuleIds.Text 
+=  tempId  +   " , " ;
                }
            }

            gvList.TotalRecords 
=  RecordCount;
            gvList.PageIndex 
=  pageIndex;
            ScriptManagerHandler.ScriptManagerRegisterStartupScript(
this " pg " string .Format( " var pg={0}; " , PageNum));
            
return  o2;
        }

        
///   <summary>
        
///  添加
        
///   </summary>
        
///   <param name="sender"></param>
        
///   <param name="e"></param>
         protected   void  btnDelete_Click( object  sender, EventArgs e)
        {
            
string  ids  =  RequestHandler.GetIntsForm( " chkID " );
            
int  sid  =  RequestHandler.GetIntQueryString( " sid " );
            
if  (ids  ==   string .Empty  ||  sid  ==   int .MinValue)
            {
                
return ;
            }

            AAALUO_LS_RoleModuleBLL bll 
=   new  AAALUO_LS_RoleModuleBLL();
            bll.batchSetPerm(ids, 
1 , sid);

            ScriptManager.RegisterStartupScript(
this .up1, up1.GetType(),  " deleteOK " " alert('设置成功!'); " true );

            
base .BindControls( this .gvList.PageIndex);
        }

        
///   <summary>
        
///  删除
        
///   </summary>
        
///   <param name="sender"></param>
        
///   <param name="e"></param>
         protected   void  btnDelete_Click2( object  sender, EventArgs e)
        {
            
string  ids  =  RequestHandler.GetIntsForm( " chkID " );
            
int  sid  =  RequestHandler.GetIntQueryString( " sid " );
            
if  (ids  ==   string .Empty  ||  sid  ==   int .MinValue)
            {
                
return ;
            }

            AAALUO_LS_RoleModuleBLL bll 
=   new  AAALUO_LS_RoleModuleBLL();
            bll.batchSetPerm(ids, 
0 , sid);

            ScriptManager.RegisterStartupScript(
this .up1, up1.GetType(),  " deleteOK " " alert('取消成功!'); " true );

            
base .BindControls( this .gvList.PageIndex);
        }

        
///   <summary>
        
///  保存设置
        
///   </summary>
        
///   <param name="sender"></param>
        
///   <param name="e"></param>
         protected   void  btnDelete_Click3( object  sender, EventArgs e)
        {
            
int  sid  =  RequestHandler.GetIntQueryString( " sid " );
            
string [] mIds  =  txtModuleIds.Text.Split( ' , ' );
            
foreach  ( string  mId  in  mIds)
            {
                
if  (mId  !=   string .Empty)
                {
                    AAALUO_LS_RoleModuleBLL bll 
=   new  AAALUO_LS_RoleModuleBLL();
                    AAALUO_LS_RoleModule model 
=   new  AAALUO_LS_RoleModule();
                    model.Role_ID 
=  sid;
                    model.Module_ID 
=  ConvertHandler.ToInt32(mId);

                    model.AllowAdd 
=  RequestHandler.GetIntForm( " chk " + mId + " allowadd " );
                    model.AllowCheck 
=  RequestHandler.GetIntForm( " chk "   +  mId  +   " AllowCheck " );
                    model.AllowDelete 
=  RequestHandler.GetIntForm( " chk "   +  mId  +   " AllowDelete " );
                    model.AllowEdit 
=  RequestHandler.GetIntForm( " chk "   +  mId  +   " AllowEdit " );
                    model.AllowExport 
=  RequestHandler.GetIntForm( " chk "   +  mId  +   " AllowExport " );
                    model.AllowNote 
=  RequestHandler.GetIntForm( " chk "   +  mId  +   " AllowNote " );
                    model.AllowPrint 
=  RequestHandler.GetIntForm( " chk "   +  mId  +   " AllowPrint " );
                    model.AllowQuery 
=  RequestHandler.GetIntForm( " chk "   +  mId  +   " AllowQuery " );
                    model.AllowShow 
=  RequestHandler.GetIntForm( " chk "   +  mId  +   " AllowShow " );
                    bll.Update(model);
                }
            }
            ScriptManager.RegisterStartupScript(
this .up1, up1.GetType(),  " deleteOK " " alert('保存成功!'); " true );

            
base .BindControls( this .gvList.PageIndex);
        }

        
protected   override   string  DefaultSortField
        {
            
get  {  return   this .gvList.DefaultSortColumn.ToString(); }
        }

        
protected   override  ISearchView SearchControl
        {
            
get
            {
                
return   this .ucSearch;

            }
        }

        
protected   override  IDataBoundable BoundableControl
        {
            
get  {  return   new  ControlDataBoundExtender( this .gvList); }
        }

        
protected   override  WayGo.Framework.UI.WebControls.IPagerable PagerControl
        {
            
get  {  return   this .gvList  as  IPagerable; }
        }

        
protected   override   void  OnPreRender(EventArgs e)
        {
            
base .OnPreRender(e);
            
this .hidSelectedID.Value  =   this .SelectedID;
        }

        
///   <summary>
        
///  选择
        
///   </summary>
        
///   <param name="sender"></param>
        
///   <param name="e"></param>
         protected   void  gvList_RowCommand( object  sender, GridViewCommandEventArgs e)
        {
            
switch  (e.CommandName.ToLower())
            {
                
case   " select " :
                    
int  index  =   int .Parse(e.CommandArgument.ToString());
                    
this .gvList.SelectedIndex  =  index;
                    
break ;
            }
        }
    }
}

转载于:https://www.cnblogs.com/luoyaoquan/archive/2011/04/21/2024321.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值