SelectUser.aspx
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:10k
源码类别:

OA系统

开发平台:

C#

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="SelectUser.aspx.cs" Inherits="OThinker.H3.Portal.SelectUser" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" >
  4. <head runat="server">
  5.     <title>请选择</title>
  6.     <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
  7. <meta name="CODE_LANGUAGE" Content="C#">
  8. <meta name="vs_defaultClientScript" content="JavaScript">
  9. <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
  10. <LINK href="css/style.CSS" type="text/css" rel="stylesheet">
  11. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  12. <script>
  13. // 选中了一个用户的时候触发
  14. function selectedUser(Text, Value)
  15. {
  16.     var mode = getQueryString("Mode");
  17.     nameControlId = getQueryString("UserControl");
  18.     if(mode == null || mode == "" || mode.toLowerCase() == "single")
  19.     {
  20.         window.opener.document.getElementById(nameControlId).value=Text;
  21.         // 获得隐藏控件的ID
  22.         var idControlId = getQueryString("UserIDControl");
  23.         var idControl = window.opener.document.getElementById(idControlId);
  24.         if(idControl != null)
  25.         {
  26.             idControl.value = Value;
  27.         }
  28.         window.close();
  29.     }
  30.     else
  31.     {
  32.         addUser(Text, Value);
  33.     }
  34. }
  35. // 向List中添加选定的用户
  36. function addUser(Text, Value)
  37. {
  38.     var objlist=document.getElementById("SelectedUsers");
  39.     for(i=objlist.length-1;i>=0;i--)
  40.     {   
  41.         if(objlist.options[i].value == Value)
  42.         {
  43.             return;
  44.         }
  45.     }   
  46.   
  47.     node = document.createElement("<option value='" + Value + "'>");
  48.     text = document.createTextNode(Text);
  49.     node.appendChild(text);
  50.     objlist.appendChild(node);
  51. }
  52.  
  53. function removeUser()
  54.     var objlist=document.getElementById("SelectedUsers");
  55.     for(i=objlist.length-1;i>=0;i--)
  56.     {
  57.         if(objlist.options[i].selected == true)
  58.         {
  59.             objlist.remove(i);
  60.         }
  61.     }
  62. }
  63.   
  64. var x=null; 
  65. var listObj=null; 
  66. //鼠标按下不放时的操作 
  67. function setTimeStart(type) 
  68. {
  69.     listObj=document.getElementById('SelectedUsers');
  70.     //超过0.3秒启动连续的向上(下)的操作
  71.     if(type=="up")
  72.     {
  73.         x=setTimeout(upListItem,300);
  74.     }
  75.     else
  76.     {
  77.         x=setTimeout(downListItem,300);
  78.     }
  79. //将选中item向上 
  80. function upListItem() 
  81.     var selIndex=listObj.selectedIndex; 
  82.     if(selIndex < 0)
  83.     {
  84.         if(x!=null)
  85.         {
  86.             clearTimeout(x);
  87.         }
  88.         return;
  89.     } 
  90.     if(selIndex==0)
  91.     {
  92.         if(x!=null)
  93.         {
  94.             clearTimeout(x);
  95.         }
  96.         return;
  97.     }
  98.  
  99.     var selValue=listObj.options[selIndex].value;
  100.     var selText=listObj.options[selIndex].text;
  101.     listObj.options[selIndex].value=listObj.options[selIndex-1].value;
  102.     listObj.options[selIndex].text=listObj.options[selIndex-1].text;
  103.     listObj.options[selIndex-1].value=selValue;
  104.     listObj.options[selIndex-1].text=selText;
  105.     listObj.selectedIndex=selIndex-1;
  106.     if(selIndex+1>0)
  107.     {
  108.         x=setTimeout(upListItem,200)
  109.     }
  110. //将选中item向下 
  111. function downListItem() 
  112. {
  113.     var selIndex=listObj.selectedIndex;
  114.     if(selIndex<0)
  115.     {
  116.         if(x!=null)
  117.         {
  118.             clearTimeout(x);
  119.         }
  120.         return;
  121.     }
  122.     if(selIndex==listObj.options.length-1) 
  123.     {
  124.         if(x!=null)
  125.         {
  126.             clearTimeout(x);
  127.         }
  128.         return;
  129.     }
  130.     var selValue=listObj.options[selIndex].value;
  131.     var selText=listObj.options[selIndex].text;
  132.     listObj.options[selIndex].value=listObj.options[selIndex+1].value;
  133.     listObj.options[selIndex].text=listObj.options[selIndex+1].text;
  134.     listObj.options[selIndex+1].value=selValue;
  135.     listObj.options[selIndex+1].text=selText;
  136.     listObj.selectedIndex=selIndex+1;
  137.     if(selIndex+1<listObj.options.length-1)
  138.     {
  139.         x=setTimeout(downListItem,200)
  140.     } 
  141. // 加载用户
  142. function loadUser()
  143. {
  144.     // 检查是选择单值还是多值
  145.     var mode = getQueryString("Mode");
  146.     if(mode == null || mode == "" || mode.toLowerCase() == "single")
  147.     {
  148.         // 单值模式
  149.         var curList=document.getElementById("UserListTable");
  150.         curList.style.display = "none";
  151.         var submitButton =document.getElementById("SubmitButton");
  152.         submitButton.style.display = "none";
  153.     }
  154.     else
  155.     {
  156.         // 多值模式
  157.         var parentListId = getQueryString("UserControl");
  158.         if(parentListId == null || parentListId == "")
  159.         {
  160.             return;
  161.         }
  162.         var parentList=window.opener.document.getElementById(parentListId);
  163.         if(parentList == null)
  164.         {
  165.             return;
  166.         }
  167.         var curList=document.getElementById("SelectedUsers");
  168.         for(i=0;i<parentList.length;i++)
  169.         {
  170.             var itemValue = parentList.options[i].value;
  171.             var itemText = parentList.options[i].text;
  172.             
  173.             node = document.createElement("<option value='" + itemValue + "'>");   
  174.             text = document.createTextNode(itemText);
  175.             node.appendChild(text);   
  176.             curList.appendChild(node);
  177.         }   
  178.     }
  179. }
  180. // 讲数据写回到对应的控件上
  181. function writeBackList()
  182. {
  183.     var parentListId = getQueryString("UserControl");
  184.     var parentList=window.opener.document.getElementById(parentListId);
  185.     // 清空旧数据
  186.     for(i=parentList.length-1;i>=0;i--)
  187.     {
  188.         parentList.remove(i);
  189.     }   
  190.     
  191.     var curList=document.getElementById("SelectedUsers");
  192.     var listString = "";
  193.     for(i=0;i<curList.length;i++)
  194.     {
  195.         var itemValue = curList.options[i].value;
  196.         var itemText = curList.options[i].text;
  197.         
  198.         node = window.opener.document.createElement("<option value='" + itemValue + "'>");   
  199.         text = window.opener.document.createTextNode(itemText);
  200.         node.appendChild(text);   
  201.         parentList.appendChild(node);
  202.         listString = listString + itemValue + ";";
  203.      }
  204.     
  205.     // 获得隐藏控件的ID
  206.     var idControlName = getQueryString("UserIDControl");
  207.     if(idControlName != null && idControlName != "")
  208.     {
  209.         var idControl = window.opener.document.getElementById(idControlName);
  210.         if(idControl != null)
  211.         {
  212.             idControl.value = listString;
  213.         }
  214.     }
  215.     window.close();
  216. }
  217. // 查找参数
  218. function getQueryString(name)
  219. {     
  220.     // 如果链接没有参数,或者链接中不存在我们要获取的参数,直接返回空     
  221.     if(location.href.indexOf("?")==-1 || location.href.indexOf(name+'=')==-1)
  222.     {
  223.         return '';
  224.     }
  225.     // 获取链接中参数部分
  226.     var queryString = location.href.substring(location.href.indexOf("?")+1);      
  227.     // 分离参数对 ?key=value&key2=value2     
  228.     var parameters = queryString.split("&");      
  229.     var pos, paraName, paraValue;     
  230.     for(var i=0; i<parameters.length; i++)     
  231.     {         
  232.         // 获取等号位置         
  233.         pos = parameters[i].indexOf('=');         
  234.         if(pos == -1) { continue; }          
  235.         // 获取name 和 value         
  236.         paraName = parameters[i].substring(0, pos);         
  237.         paraValue = parameters[i].substring(pos + 1);          
  238.         // 如果查询的name等于当前name,就返回当前值,同时,将链接中的+号还原成空格         
  239.         if(paraName == name)         
  240.         {             
  241.             return unescape(paraValue.replace(/+/g, " "));         
  242.         }     
  243.     }     
  244.     return ''; 
  245. }
  246. </script>
  247. </head>
  248. <body leftmargin="0" topmargin="0" onload="javascript:loadUser();">
  249.     <form id="form1" runat="server">
  250.     <div>
  251.     <INPUT type="button" value="确定" class="downBtn" onclick="javascript:writeBackList();" ID="SubmitButton" NAME="SubmitButton">
  252.     <table height="100%" width="100%">
  253.         <tr valign=top>
  254.             <td width="50%">
  255.                 <asp:treeview ID="UserTree" runat="server" AutoGenerateDataBindings="false" 
  256.                     ExpandDepth=0 OnTreeNodePopulate="UserTree_TreeNodePopulate" ShowLines="True">
  257.                     <SelectedNodeStyle BackColor="#B5B5B5"></SelectedNodeStyle>
  258.                     <NodeStyle VerticalPadding="2px" Font-Names="Tahoma" Font-Size="8pt" HorizontalPadding="2px" ForeColor="Black"></NodeStyle>
  259.                     <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA"></HoverNodeStyle>
  260.                 </asp:treeview>
  261.             </td>
  262.             <td width="50%">
  263.                 <table id="UserListTable" width=100%>
  264.                     <tr>
  265.                         <td>
  266.                             <SELECT id="SelectedUsers" size="11" name="SelectedUsers" style="WIDTH:100%" ondblclick="javascript:removeUser();"></SELECT>
  267.                         </td>
  268.                     </tr>
  269.                     <tr>
  270.                         <td>
  271.                             <INPUT type="button" value="↑向上" class="upBtn" onmousedown="setTimeStart('up');" onmouseup="clearTimeout(x);" onclick="listObj=document.getElementById('SelectedUsers');upListItem();clearTimeout(x);" ID="Button3" NAME="Button1">
  272.                             <INPUT type="button" value="↓向下" class="downBtn" onmousedown="setTimeStart('down');" onmouseup="clearTimeout(x);" onclick="listObj=document.getElementById('SelectedUsers');downListItem();clearTimeout(x);" ID="Button4" NAME="Button2"> 
  273.                             <INPUT type="button" value="移出" class="btnRemove" onclick="javascript:removeUser();" ID="Button5" NAME="Button7"> 
  274.                             <br />
  275.                             提示:双击列表项的选项可以删除成员</td>
  276.                     </tr>
  277.                 </table>
  278.             </td>
  279.         </tr>
  280.     </table>
  281.     </div>
  282.     </form>
  283. </body>
  284. </html>