<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AdminNameList.aspx.cs"
    Inherits="PowerEasy.Module.General.WebSite.Admin.User.AdminNameList" %>

<!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 id="Head1" runat="server">
    <title>选择对话框</title>
    <style type="text/css">
        li a:link
        {
            background-color: #eee;
        }
        
        li a:hover
        {
            background-color: #EEE;
            color: #fff;
        }
    </style>
    <base target="_self" />
</head>
<body>
    <form id="myform" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:Panel ID="PnlMulitSelect" runat="server">
        <table width="100%" border="0" cellpadding="2" cellspacing="1" class="border">
            <tr align="center">
                <td class="title" align="left">
                    <b>已选定的管理员名：</b>
                </td>
            </tr>
            <tr class="tdbg">
                <td colspan="2" class="tdbg">
                    <asp:TextBox ID="TxtAdminName" runat="server" Width="420px"></asp:TextBox><br />
                    &nbsp;<input type="button" name="BtnCutLast" id="BtnCutLast" onclick="cutLastString()"
                        value="删除最后" />
                    <input type="button" name="BtnCutAll" id="BtnCutAll" onclick="Javascript: myform.TxtAdminName.value = ''"
                        value="删除全部" />
                    <input type="button" name="BtnReturn" id="BtnReturn" value=" 确 定 " onclick="ReturnValue()" />
                </td>
            </tr>
        </table>
    </asp:Panel>
    <asp:Panel ID="PnlDepartmentList" runat="server" Style="float: left; width: 25%;">
        <pe:ExtendedGridView ID="EgvDepartmentList" runat="server" CheckBoxFieldHeaderWidth="3%"
            IsHoldState="True" SerialText="" AutoGenerateColumns="False">
            <Columns>
                <asp:TemplateField HeaderText="部门列表">
                    <ItemTemplate>
                        <span onclick='GetAdminList(<%# Eval("Key") %>)' style="cursor: pointer;">
                            <%#Eval("Value") %></span>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <SelectedRowStyle BackColor="#33CCFF" />
        </pe:ExtendedGridView>
    </asp:Panel>
    <div style="float: left; width: 74%; margin-left: 3px;">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpnlAdminList_Load">
            <ContentTemplate>
                <table border="0" cellpadding="0" cellspacing="0" style="width: 100%">
                    <tr class="title">
                        <td style="text-align: right">
                            管理员列表：
                        </td>
                        <td>
                            <asp:TextBox ID="TxtSearchRole" runat="server"></asp:TextBox><asp:Button ID="BtnSearch"
                                runat="server" Text="查找" OnClick="BtnSearch_Click" />
                        </td>
                    </tr>
                </table>
                <asp:PlaceHolder ID="PlhRoleList" runat="server"></asp:PlaceHolder>
                <asp:Table CellSpacing="1" CellPadding="0" BorderWidth="0px" Width="100%" CssClass="border"
                    ID="TabEmplyTemplate" runat="server">
                    <asp:TableRow ID="TableRow1" runat="server" CssClass="tdbg" Height="80px" HorizontalAlign="Center"
                        VerticalAlign="Middle">
                        <asp:TableCell ID="TableCell1" runat="server">没有任何数据！</asp:TableCell>
                    </asp:TableRow>
                </asp:Table>
                <div style="width: 100%; text-align: center">
                    当前页：<asp:Label ID="LblCurrenPage" runat="server"></asp:Label>
                    &nbsp; 共&nbsp;<asp:Label ID="LblMaxPage" runat="server"></asp:Label>
                    页 &nbsp;&nbsp;
                    <asp:LinkButton ID="LbtnFirst" runat="server" OnClick="LbtnFirst_Click">首页</asp:LinkButton>&nbsp;
                    <asp:LinkButton ID="LbtnPrevious" runat="server" OnClick="LbtnPrevious_Click">上一页</asp:LinkButton>&nbsp;
                    <asp:LinkButton ID="LbtnNext" runat="server" OnClick="LbtnNext_Click">下一页</asp:LinkButton>&nbsp;
                    <asp:LinkButton ID="LbtnLast" runat="server" OnClick="LbtnLast_Click">尾页</asp:LinkButton>
                    &nbsp; &nbsp;
                    <asp:TextBox ID="TxtRoleNameNum" runat="server" Width="22px" AutoPostBack="True">50</asp:TextBox>个/页
                    &nbsp;&nbsp;转到第<asp:TextBox ID="TxtPage" runat="server" Width="20px" OnTextChanged="TxtPage_TextChanged"></asp:TextBox>页
                </div>
                <asp:HiddenField ID="HdnSearchType" runat="server" />
                <asp:HiddenField ID="HiddenField2" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>
<script language="javascript" type="text/javascript">
 var hdnDepartment = document.getElementById('<%=HiddenField2.ClientID %>');
    document.myform.TxtAdminName.value = (parent.document.getElementById('<%=RequestString("UserCliectId")%>').value).replace(" ", ",");
    document.myform.TxtAdminName.value = (document.myform.TxtAdminName.value).replace(/\s+/g, ",");
    var oldUser = '';
    var type = '<%=m_Type%>';
     function GetAdminList(departmentId) {
        hdnDepartment.value = departmentId;
        __doPostBack("<%=UpdatePanel1.ClientID %>", departmentId)
    }
    function cutLastString() {
        var obj = document.getElementById('<%=TxtAdminName.ClientID%>');
        obj.value = obj.value.substring(0, obj.value.lastIndexOf(","));
    }

    function add(obj) {
        if (obj == '') { return false; }
        var txtAdminName = document.getElementById('<%=TxtAdminName.ClientID%>');

        var singleUser = obj.split(',');
        var ignoreUser = '';
        for (i = 0; i < singleUser.length; i++) {
            if (checkUser(txtAdminName.value, singleUser[i])) {
                ignoreUser = ignoreUser + singleUser[i] + " "
            }
            else {
                if (txtAdminName.value == "") {
                    txtAdminName.value = singleUser[i];
                }
                else {
                    txtAdminName.value = txtAdminName.value + ',' + singleUser[i];
                }
            }
        }
        if (ignoreUser != '') {
            alert(ignoreUser + '已经存在，此操作已经忽略！');
        }
    }

    function checkUser(TxtAdminName, thisUser) {
        if (TxtAdminName == thisUser) {
            return true;
        }
        else {
            var s = TxtAdminName.split(',');
            for (j = 0; j < s.length; j++) {
                if (s[j] == thisUser)
                    return true;
            }
            return false;
        }
    }

    function ReturnValue() {
        if (type != '0') {
            ReturnBack(document.getElementById('<%=TxtAdminName.ClientID%>').value, type);
        } else {
            if (window.opener) {
                window.opener.DoPostBack(document.getElementById('<%=TxtAdminName.ClientID%>').value + '&' + "<%=RequestString("UserCliectId") %>");
                window.opener.focus();
                window.close();
            }
            else {
                parent.DoPostBack(document.getElementById('<%=TxtAdminName.ClientID%>').value + '&' + "<%=RequestString("UserCliectId") %>");
                window.close();
            }

        }
    }
    function ReturnBack(adminName, type) {
        if (window.opener) {
            window.opener.DoPostBack(adminName, type);
        }
        else {
            parent.DoPostBack(adminName, type);
        }
    }
</script>
