<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="roleList.aspx.cs" Inherits="Czou2012.UI.Manager.AdminUser.roleList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>角色管理</title>
    <link type="text/css" rel="stylesheet" href="../Styles/style.css" />
     <link type="text/css" rel="stylesheet" href="../Styles/pagination.css" />
     <link type="text/css" rel="stylesheet" href="../Styles/table.css" />
     <link rel="stylesheet" type="text/css" href="../Scripts/themes/default/easyui.css" />
     <link rel="stylesheet" type="text/css" href="../Scripts/themes/icon.css" />
     <link type="text/css" rel="stylesheet" href="../Scripts/Tips/tip-yellowsimple/tip-yellowsimple.css" />
    <script type="text/javascript" src="../Scripts/jquery.min.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.form.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.floatdiv.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.validate.field.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.fixedtableheader.min.js"></script>
    <script type="text/javascript">

        function clickHandler(k, list1, list2, list3, list4, list5, list6, list7, list8) {   
            $("tbody input:checkbox").each(function (i) {
                if ($("tbody input:checkbox").eq(i).attr("checked") == true) {
                  $("tbody input:checkbox").eq(i).attr("checked","");
                }
            });
            var cc = "#check" + k;
            $(cc).attr('checked', true);
            checkboxClick();

            $("#txtUserID").val(list1);
            $("#txtUserName").val(list2);
            $("#txtTrueName").val(list3);
            $("#txtOrganName").val(list4);
            $("#txtOrganID").val(list5);
            $("#txtRemark").val(list6);
            $("#txtSort").val(list7);
            $("#txtState").val(list8);

            $('#btnModify').linkbutton('<%=Czou2012.UI.Manager.CommonClass.OperatorRight.IsRightButton("enable","m")%>');    // disable the button  
            $('#btnForbid').linkbutton('<%=Czou2012.UI.Manager.CommonClass.OperatorRight.IsRightButton("enable","m")%>');    // disable the button  
            if (list8 == "1") { $('#btnForbid').linkbutton({ text: "禁用" }); }
            if (list8 == "0") { $('#btnForbid').linkbutton({ text: "启用" }); }
            $('#btnDelete').linkbutton('<%=Czou2012.UI.Manager.CommonClass.OperatorRight.IsRightButton("enable","d")%>');    // disable the button  
            $('#btnAdd').linkbutton('disable');    // disable the button

            $.ajax({  
                type: "GET",
                url: "authorizationSet.aspx?UserID=" + list1,
                beforeSend: function () { $("#frmRight", parent.document.body).attr("src", "../Utility/loadingDiv.htm"); }, //执行ajax前执行loading函数.直到success 
                success: function () { $("#frmRight", parent.document.body).attr("src", "authorizationSet.aspx?SendTime=" + Math.random() + "&UserID=" + list1); } //成功时执行Response函数 
            });

	
    }


    //add按钮新增栏目事件------------------------------------------------------------/
    function btnAdd() {
   
            var nUserName = $.trim($('#txtUserName').val());
            var nTrueName = $.trim($('#txtTrueName').val());
            var nPassword = $.trim($('#txtPassword').val());
            var nOrganName = $.trim($('#txtOrganName').val());
            var nRemark = $.trim($('#txtRemark').val());
            var nSort = $.trim($('#txtSort').val());

            var msg = $.ValidateField.CommonValidata(nUserName, "角色代码", 1);

            if (msg != $.ValidateField.OK) {
                msg = "(" + msg + ")";
                $('#lblInfo').html(msg);
                $('#txtUserName').focus();
                $('#txtUserName').select();
                return;
            } else { $('#lblInfo').html(""); }


            msg = $.ValidateField.CommonValidata(nTrueName, "角色名称", 2);

            if (msg != $.ValidateField.OK) {
                msg = "(" + msg + ")";
                $('#lblInfo').html(msg);
                $('#txtTrueName').focus();
                $('#txtTrueName').select();
                return;
            } else { $('#lblInfo').html(""); }


            var options = {
                //ajaxSubmit表单提交参数
                //参数说明：
                //1.用此方式提交时，form不能为runat="server"；
                //2.必须在表单form中加method="post"，此参数中加的method:'post'不能提交含大量表单域的form；
                //3.必须在cs文件中用Request["名称"]获取表单域的值，否则RequestString获取字符串长度有限制.
                target: '#lblInfo',
                method: 'post',
                url: 'roleList.aspx?type=add&RowNumPerPage=<%=nRowNumPerPage%>',
                success: function (msg) {
                    if (msg == "1") {
                        $("#lblInfo").text("新增成功！");
                        window.location.href = "<%=nCurrentRequestUrl%>";
                    }
                    else {
                        $("#lblInfo").text("新增有误，请检查！");
                    }
                    return false;
                },
                error: function () { $.messager.alert("操作提示", "请求异常！", "warning"); }
            };
            $('#formmodify').ajaxSubmit(options);
        }

        //modify修改事件--------------------------------------------------------------/
        function btnModify() {

            $("#frmRight", parent.document.body).contents().find("#UserID").val($.trim($('#txtUserID').val()));
            $("#frmRight", parent.document.body).contents().find("#UserName").val($.trim($('#txtUserName').val()));
            $("#frmRight", parent.document.body).contents().find("#Password").val($.trim($('#txtPassword').val()));
            $("#frmRight", parent.document.body).contents().find("#TrueName").val($.trim($('#txtTrueName').val()));
            $("#frmRight", parent.document.body).contents().find("#OrganName").val($.trim($('#txtOrganName').val()));
            $("#frmRight", parent.document.body).contents().find("#OrganID").val($.trim($('#txtOrganID').val()));
            $("#frmRight", parent.document.body).contents().find("#GroupID").val("0");
            $("#frmRight", parent.document.body).contents().find("#Remark").val($.trim($('#txtRemark').val()));
            $("#frmRight", parent.document.body).contents().find("#Sort").val($.trim($('#txtSort').val()));


            var options = {
                target: '#lblInfo',
                method: 'post',
                url: 'authorizationUpdate.aspx',
                success: function (msg) {
                    if (msg == "1") {
                        $("#lblInfo").text("操作成功！");
                        $.messager.alert('系统提示', '修改成功', 'question', function () {
                        window.location.href = "<%=nCurrentRequestUrl%>";
                        });                       
                    }
                    else
                        $("#lblInfo").text("操作有误，请检查！");
                    return false;
                },
                error: function () { $.messager.alert("操作提示", "请求异常！", "warning"); }
            };
            $("#frmRight", parent.document.body).contents().find("#frmAuthorization").ajaxSubmit(options);

        }

       //Query查询事件--------------------------------------------------------------/
        function btnQuery() {
            document.forms[0].action="roleList.aspx?type=query&RowNumPerPage=<%=nRowNumPerPage%>";
            document.forms[0].submit();
        }

        //Forbid事件--------------------------------------------------------------/
        function btnForbid() {
            var options = {
                target: '#lblInfo',
                method: 'post',
                url: 'roleList.aspx?type=forbid&RowNumPerPage=<%=nRowNumPerPage%>',
                success: function (msg) {
                    if (msg == "1") {
                        $("#lblInfo").text("操作成功！");
                        window.location.href = "<%=nCurrentRequestUrl%>";
                    }
                    else
                        $("#lblInfo").text("操作有误，请检查！");
                    return false;
                },
                error: function () { $.messager.alert("操作提示", "请求异常！", "warning"); }
            };
            $('#formmodify').ajaxSubmit(options);

        }

        //delete按钮事件--------------------------------------------------------------/
        function btnDelete() {
            var ifSelected = "0";
            $("tbody input:checkbox").each(function (i) {
                if ($("tbody input:checkbox").eq(i).attr("checked") == true) {
                    ifSelected = "1";
                }
            });

            if (ifSelected == "1") {
                var options = {
                    //参数说明：
                    //1.用此方式提交时，form不能为runat="server"；
                    //2.必须在表单form中加method="post"，此参数中加的method:'post'不能提交含大量表单域的form；
                    //3.必须在cs文件中用Request["名称"]获取表单域的值，否则RequestString获取字符串长度有限制.
                    target: '#lblInfo',
                    method: 'post',
                    url: 'roleList.aspx?type=delete&RowNumPerPage=<%=nRowNumPerPage%>',
                    success: function (msg) {
                        if (msg == "1") {
                            $("#lblInfo").text("删除成功！");
                            $.messager.alert('系统提示', '删除成功', 'question', function () {
                                window.location.href = "<%=nCurrentRequestUrl%>";
                            });
                        }
                        else
                            $("#lblInfo").text("删除有误，请检查！");
                        return false;
                    },
                    error: function () { $.messager.alert("操作提示", "请求异常！", "warning"); }

                };
                $('#formmodify').ajaxSubmit(options);
            }
            else {
                $.messager.alert("操作提示", "您没有选择角色！", "warning");
            }

        }


        //reset复原按钮---------------------------------------------------------------------/
        function btnReset() {
            $("form").each(function () {
                this.reset(); //有效，其他无效
            });

            $('#btnModify').linkbutton('disable');    // disable the button  
            $('#btnForbid').linkbutton('disable');    // disable the button  
            $('#btnDelete').linkbutton('disable');    // disable the button  
            $('#btnAdd').linkbutton('<%=Czou2012.UI.Manager.CommonClass.OperatorRight.IsRightButton("enable","w")%>');    // enable the button  
            window.location.href = "<%=nCurrentInitUrl%>";
            checkboxClick();
            $("#frmRight", parent.document.body).attr("src", "../Utility/blank.htm");
        }

        //checkbox全选事件--------------------------------------------------------------/
        function selectAll(o) {
            if (o.checked) {
                $("input:checkbox").attr("checked", true);

            } else {
                $("input:checkbox").attr("checked", false);
            }
            checkboxClick();
        }

        //checkbox点击事件--------------------------------------------------------------/
        function checkboxClick() {

            $("tbody input:checkbox").each(function (i) {

                if ($("tbody input:checkbox").eq(i).attr("checked") == true) {
                    $("tbody input:checkbox").eq(i).parent().parent().addClass("trSelected");
                } else {
                    $("tbody input:checkbox").eq(i).parent().parent().removeClass("trSelected");
                }
            });

        }

        //文本框改变事件--------------------------------------------------------------/
        function inputChange(obj, i) {
            var cc = "#check" + i;
            $(obj).addClass("inputChange");
            $(cc).attr('checked', true);
            checkboxClick()
        }

        //检查是否输入数字-----------------------------------------------------------/
        function inputNumber(obj) {
            var nNumTemp = obj.value;
            var msg = $.ValidateField.ValidateNumber(nNumTemp);
            if (msg != 'ok') {
                alert(msg);
                obj.value = "0";
            }
        }

        //页面属性 Start--------------------------------------------------------------/
        $(function () {
            $("#tableContent table>tbody>tr input:text").addClass("inputText");
            $("#tableContent table>tbody>tr select").addClass("inputText");
            $("#allCheck").attr("disabled", true)
            //linkbutton失效实例,增加权限控制
            $('#btnModify').linkbutton('disable');    // disable the button  
            $('#btnForbid').linkbutton('disable');    // disable the button  
            $('#btnDelete').linkbutton('disable');    // disable the button  
            $('#btnAdd').linkbutton('<%=Czou2012.UI.Manager.CommonClass.OperatorRight.IsRightButton("enable","w")%>');    // disable the button  
            // $('#btnForbid').linkbutton({ text: "可以" });
            $("#roleTable").fixedtableheader();

            $("#txtOrganName").popup("../Organization/organizationSelect.aspx?OrganID=0&OrganLayers=2&ReturnCodeID=txtOrganID&ReturnNameID=txtOrganName&ReturnSelectType=single", {
                width: '300', height: '200', frame: true, alignType: 'topleft'
            })
        })
    
    </script>
</head>

<body>  

<form id="formmodify" method="post" style="width:100%;height:100%;" >
  <div id="tableContent" style="height:60%;overflow:auto; border:0;margin:0;padding:0" scroll="no">
  <table class="commonTable" id="roleTable">
                <thead>
                    <tr>
                        <th scope="col" style="width: 15px; text-align: center;">
                            <input type="checkbox" id="allCheck" style="border: 0px;" onclick="selectAll(this)" />
                        </th>
                        <th scope="col" style="min-width: 90px;text-align:left;"> 角色代码</th>                    
                        <th scope="col" style="min-width: 90px;text-align:left;">角色名称</th>
                        <th scope="col" style="text-align:left;">所属机构</th>
                        <th scope="col" style="width: 40px;">顺序</th>
                        <th scope="col" style="width: 40px;text-align:center;">状态</th>
                        <th scope="col" style="min-width: 80px;text-align:center;">权限管理</th>
                    </tr>
                </thead>
                <tbody>
                    <asp:Label ID="tbodyDiv" runat="server"></asp:Label>
                    <asp:Repeater runat="server" ID="columnRepeater">
                        <ItemTemplate>
                            <tr style='cursor:pointer;'  id='tr_<%#Container.ItemIndex%>'  onclick="clickHandler('<%#Container.ItemIndex%>','<%# Eval("UserID")%>','<%# Eval("UserName")%>','<%# Eval("TrueName")%>','<%# Eval("OrganName")%>','<%# Eval("OrganID")%>','<%# Eval("ReMark")%>','<%# Eval("Sort")%>','<%# Eval("State")%>')">
                                <td style="text-align: center;">
                                    <input type="checkbox" value="1" id="<%#"check"+Container.ItemIndex %>" name="<%#"check"+Container.ItemIndex %>"
                                        onclick="checkboxClick();">
                                </td>
                                <td><%# Czou.Common.ComStringHelper.IntParse(Eval("SysSign")) == 1 ? "<span class='fontSign'>"+Eval("UserName")+"<span>" : Eval("UserName")%></td>
                                <td><%# Eval("TrueName")%></td>
                                <td><%# Eval("OrganName")%></td>
                                <td><%# Eval("Sort")%></td>
                                 <td><%# int.Parse(Eval("state").ToString())==1 ? "启用" : "<font color=red>禁用</font>"%></td>
                                <td style="text-align:center;">权限设置</td>
                            </tr>
                          
                      </ItemTemplate>
                    </asp:Repeater>    
                </tbody>
            </table>
        </div>
<table style="border:0px;width:100%;" cellpadding="0" cellspacing="0">
<tr><td style="height:28px; background:#eee;">
    <div style="float: left;">
          <asp:Label ID="LblPageNavigator" runat="server"></asp:Label>
    </div>
</td></tr>
<tr><td  style="height:28px;">
 <span id="lblInfo" style="line-height: 25px; color: #ff0000;" class="lblInfo"></span>
</td></tr>
</table>


<table class="commonTable" style="border:1px solid #ccc" >
<tr>
  <td>角色代码</td><td><input type="text"  id="txtUserName" name="txtUserName"  class="inputAdd" style="width: 90%;" size="15" /><input id="txtUserID"  name="txtUserID" type="hidden" value="0"/></td>
  <td>角色名称</td><td><input type="text"  id="txtTrueName" name="txtTrueName"  class="inputAdd" style="width: 90%;" size="15" /></td>
  <td>简要说明</td><td><input type="text"  id="txtRemark" name="txtRemark"   class="inputAdd" style="width: 90%;" size="15" />
    <input type="hidden"  id="txtPassword" name="txtPassword" class="inputAdd" style="width: 90%;"  size="15"  /></td>
  </tr><tr>
  <td>所属机构</td><td colspan="3"><input type="text"  id="txtOrganName" name="txtOrganName"   class="inputAdd" style="width: 97%;"  size="15" />
    <input type="hidden"  id="txtOrganID" name="txtOrganID"/>
  </td>
  <td>顺序</td><td><input type="text" id="txtSort" name="txtSort"   class="inputAdd" style="width: 90%;"   size="15"/><input id="txtState" name="txtState"  type="hidden"/></td></tr>
</table>
<table style="border:0px;width:100%;height:35px; vertical-align:middle;"   cellpadding="3" cellspacing="1">
<tr><td  align="center">
  <div style="text-align:center; vertical-align: middle;margin-top:-2px;">
    <a id="btnAdd"    class="easyui-linkbutton" href="javascript:btnAdd();" tabindex="10">新增</a>
    <a id="btnModify" class="easyui-linkbutton" href="javascript:btnModify();" tabindex="11">修改保存</a>
    <a id="btnForbid" class="easyui-linkbutton" href="javascript:btnForbid();" tabindex="12">禁用</a>
    <a id="btnQuery"  class="easyui-linkbutton" href="javascript:btnQuery();" tabindex="13">查询</a>
    <a id="btnDelete" class="easyui-linkbutton" href="#" tabindex="14" onclick='{ $.messager.confirm("操作提示", "删除的角色将不能恢复，您确定要继续吗？\n", function (data) {if (data) {btnDelete();}else {return false;}});}'>选择删除</a>     
    <a id="btnReset"  class="easyui-linkbutton" href="javascript:btnReset();" tabindex="15">复原</a>
  </div>
  </td>         
</tr>
</table>
</form>


</body>
</html>
