<%@ Page Language="c#" Inherits="WebApp.Wpdcc.selectFields" CodeBehind="selectFields.aspx.cs" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
    <title>显示字段选择</title>
    <link href="../Css/Admin_STYLE.CSS" type="text/css" rel="stylesheet">



    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
        .style1
        {
            color: #ffffff;
        }
        .style2
        {
            font-size: 12px;
        }
        .style3
        {
            font-size: 12px;
            color: #ffffff;
        }
    </style>
</head>
<body topmargin="0" leftmargin="0">
    <form id="myform" method="post" runat="server">
    <font face="宋体">
        <div align="center">
            <font face="宋体">
                <table width="400" border="1" align="left" cellpadding="0" cellspacing="0" bordercolor="#6375d6"
                    id="Table2" style="width: 400px; border-collapse: collapse">
                    <tr>
                        <td height="21" colspan="3" bgcolor="#6375d6">
                            <div align="center">
                            </div>
                            <td colspan="3" bgcolor="#6375d6" style="width: 200px">
                                <div align="center" class="style1">
                                    <div align="center" class="style2">
                                        &nbsp;</div>
                                </div>
                            </td>
                    </tr>
                    <tr>
                        <td width="46" valign="top" bgcolor="#6375d6">
                            <img src="Images/ceng.gif" width="50" height="1">
                        </td>
                        <td width="6" class="bgcolor">
                            <asp:ListBox ID="d_b1" runat="server" SelectionMode="Multiple" Height="232px" Width="168px">
                            </asp:ListBox>
                        </td>
                        <td width="148" align="center" bgcolor="#6375d6">
                            <p>
                                <font face="宋体">
                                    <input onclick="Add()" type="button" value=" → " name="b1">
                                    <br>
                                    <br>
                                    <input onclick="Del()" type="button" value=" ← " name="b1">
                                </font>
                            </p>
                            <p>
                                <font face="宋体">
                                    <input style="width: 32px; height: 22px" onclick="AddAll()" type="button" value=">>"
                                        name="b1">
                                </font>
                            </p>
                            <p>
                                <font face="宋体">
                                    <input style="width: 32px; height: 22px" onclick="DelAll()" type="button" value="<<"
                                        name="b1">
                                    <img src="Images/ceng.gif" width="50" height="8"></font></p>
                        </td>
                        <td width="96" class="bgcolor" style="width: 95px">
                            <font face="宋体">
                                <asp:ListBox ID="d_b2" runat="server" SelectionMode="Multiple" Height="232px" Width="168px">
                                </asp:ListBox>
                            </font>
                        </td>
                        <td width="150" bgcolor="#6375d6">
                            <input onclick="Up()" type="button" value="↑" name="b3" style="display: none">
                            <br>
                            <br>
                            <input onclick="Down()" type="button" value="↓" name="b4" style="display: none">
                            <img src="Images/ceng.gif" width="50" height="1">
                        </td>
                    </tr>
                    <tr>
                        <td colspan="5" align="center">
                            <input type="button" value="确定" onclick="checkform();">&nbsp;&nbsp;&nbsp;&nbsp;<input
                                type="button" value="取消" name="btnClose" onclick="javascript:window.close();">
                        </td>
                    </tr>
                </table>
            </font>
        </div>
    </font>
    <input id="d_name" type="hidden" name="d_button" runat="server"><input id="d_value"
        type="hidden" name="d_button" runat="server">
    </form>
        <script language="javascript">
            // 加入已选
            function Add() {
                var selectFrom = document.myform.d_b1;
                var selectTo = document.myform.d_b2;
                if (selectFrom.selectedIndex < 0) {
                    alert("请选择待选单位！");
                    return;
                }

                for (var loop = 0; loop < selectFrom.options.length; loop++) {
                    if (selectFrom.options[loop].selected == true) {
                        var optionName = selectFrom.options[loop].text;
                        var optionValue = selectFrom.options[loop].value;
                        var flag = false;
                        for (var i = 0; i < selectTo.options.length; i++) {
                            if (optionValue == selectTo.options[i].value) {
                                flag = true;
                                break;
                            }
                        }

                        if (flag == true) {
                            alert("“" + selectFrom.options[loop].text + "”已被选择!");
                        }
                        else {
                            selectTo.add(new Option(optionName, optionValue));
                        }
                    }
                }

            }
            function AddAll() {
                var selectFrom = document.myform.d_b1;
                var selectTo = document.myform.d_b2;


                for (var loop = 0; loop < selectFrom.options.length; loop++) {

                    var optionName = selectFrom.options[loop].text;
                    var optionValue = selectFrom.options[loop].value;
                    var flag = false;
                    for (var i = 0; i < selectTo.options.length; i++) {
                        if (optionValue == selectTo.options[i].value) {
                            flag = true;
                            break;
                        }
                    }

                    if (flag == false) {

                        selectTo.add(new Option(optionName, optionValue));
                    }

                }
            }

            // 从已选中删除
            function Del() {
                var selectTo = document.myform.d_b2;
                var nIndex = selectTo.selectedIndex;
                var nLen = selectTo.length;
                if (nLen < 1) return;
                if (nIndex < 0) {
                    alert("请选择已选单位！");
                    return;
                }

                for (var loop = 0; loop < selectTo.options.length; loop++) {
                    if (selectTo.options[loop].selected) {
                        selectTo.options[loop] = null; loop--;
                    }
                }
            }
            function DelAll() {
                var selectTo = document.myform.d_b2;
                var nLen = selectTo.length;
                if (nLen < 1) return;
                for (var loop = nLen; loop >= 0; loop--) {
                    selectTo.options[loop] = null;
                }
            }

            // 排序：向上移动
            function Up() {
                var sel = document.myform.d_b2;
                var nIndex = sel.selectedIndex;
                var nLen = sel.length;
                if ((nLen < 1) || (nIndex == 0)) return;
                if (nIndex < 0) {
                    alert("请选择一个要移动的已选单位！");
                    return;
                }
                var sValue = sel.options[nIndex].value;
                var sHTML = sel.options[nIndex].innerHTML;
                sel.options[nIndex].value = sel.options[nIndex - 1].value;
                sel.options[nIndex].innerHTML = sel.options[nIndex - 1].innerHTML;
                sel.options[nIndex - 1].value = sValue;
                sel.options[nIndex - 1].innerHTML = sHTML;
                sel.selectedIndex = nIndex - 1;
            }

            // 排序：向下移动
            function Down() {
                var sel = document.myform.d_b2;
                var nIndex = sel.selectedIndex;
                var nLen = sel.length;
                if ((nLen < 1) || (nIndex == nLen - 1)) return;
                if (nIndex < 0) {
                    alert("请选择一个要移动的已选按钮！");
                    return;
                }
                var sValue = sel.options[nIndex].value;
                var sHTML = sel.options[nIndex].innerHTML;
                sel.options[nIndex].value = sel.options[nIndex + 1].value;
                sel.options[nIndex].innerHTML = sel.options[nIndex + 1].innerHTML;
                sel.options[nIndex + 1].value = sValue;
                sel.options[nIndex + 1].innerHTML = sHTML;
                sel.selectedIndex = nIndex + 1;
            }

            // 提交处理
            function checkform() {
                //parent.window.dialogArguments.DelAllField();
                parent.DelAllField();
                var selectFrom = document.myform.d_b2;
                for (var loop = 0; loop < selectFrom.options.length; loop++) {
                    var optionName = selectFrom.options[loop].text;
                    var optionValue = selectFrom.options[loop].value;
                    //parent.window.dialogArguments.checkfield(optionName,optionValue);
                    parent.checkfield(optionName, optionValue);
                }
                //window.close();
                parent.$.fancybox.close();
            }
    </script>
</body>
</html>
