<%@ Page Title="" Language="C#" MasterPageFile="~/helpdesk/Simple.Master" AutoEventWireup="true" CodeBehind="Ad_User_List.aspx.cs" Inherits="helpdesk.helpdesk.Ad_User_List" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <script src="../javascript/layer/layer.js"></script>
    <script src="../javascript/common.js"></script>

    <style>

   
      .xxx {
        background-color: #DFF0D8;  font-weight:bold


        }
     </style>

       <input   type="hidden" id="hf_trid" name="hf_trid" />

  


  <div style="border:solid 1px #ccc;padding:10px; margin:10px  " class="form-inline">
      <div style="font-size:11px;">
          当前路径:  <asp:Label runat="server" ID="lbl_adpath"></asp:Label>
      </div>
      <hr />



              
   使用状态  <asp:DropDownList runat="server" ID="ddl_status" CssClass="form-control"
        AutoPostBack="true" 
        OnSelectedIndexChanged="ddl_status_SelectedIndexChanged">
              <asp:ListItem Text="==所有==" Value=""></asp:ListItem>
              <asp:ListItem Text="正常" Value="normal"></asp:ListItem>
              <asp:ListItem Text="禁用" style="color:orange" Value="Disabled"></asp:ListItem>
              <asp:ListItem Text="锁定" style="color:#d44950" Value="Locked"></asp:ListItem> 
         </asp:DropDownList>
      
      


      关键字：<asp:TextBox runat="server" ID="txt_key" Width="280px" CssClass="form-control"></asp:TextBox> 
     
     <asp:Button runat="server" ID="btn_search" Text="查询" CssClass="btn btn-success" OnClick="btn_search_Click1" />

   
      <asp:PlaceHolder runat="server" ID="ph_add" Visible="false"  runat="server" >

       <a href="###"  class="btn btn-primary "   
             onclick="Pop('ad_user_detail.aspx?adpath=<%=Request.QueryString["adpath"] %>',820,550,'添加用户');">添加用户</a>

          </asp:PlaceHolder>



         <asp:Button runat="server" ID="btn_export" Text="导出AD用户" CssClass="btn btn-danger" OnClick="btn_export_Click1" />


      <a href="###"  class="btn btn-success" onclick="Pop('ad_user_import.aspx',600,400,'导入AD用户')">导入AD用户</a>


      </div>
      

     




     <asp:ListView ID="ListView1" runat="server"  
          OnPagePropertiesChanging="ListView1_PagePropertiesChanging" OnItemDataBound="ListView1_ItemDataBound"
          >
          
     
          
        <LayoutTemplate>
         
                        <table id="tbl_users"  style="font-size:12px; font-family:Verdana" class="table  ">
                            <tr   >
                                  
                                 <th   width="80px">状态</th>
                                  <th   width="100px" >登录名</th>
                                  <th  width="120px" >显示名</th>
                                  <th  width="130px" >电话</th>
                                  <th   width="150px">手机</th> 
                                
                                  <th   width="120px" >办公室</th>
                                  <th   width="130px">部门</th> 
                                  <th   width="90px">查看</th>
                            </tr>
                            <tr id="itemPlaceholder" runat="server">
                            </tr>
                        </table>
                   
        </LayoutTemplate>
        
         <ItemTemplate>
            <tr   data-id='<%# Eval("LoginName") %>'  >

                  
                 <td>
                     <asp:Label runat="server" ID="lbl_status" Text=' <%# Eval("Status") %>'></asp:Label>
                     
                </td>

                <td>
                      <%# Eval("LoginName") %>
                </td>
                <td>
                  <%# Eval("displayname") %>
                </td>

                <td>
                  <%# Eval("tel") %>
                </td>

                <td>
                  <%# Eval("mobile") %>
                </td>
                 
                 

                  <td>
                  <%# Eval("office") %>
                </td>

                  <td>
                  <%# Eval("dept") %>
                </td>

                  <td>
                <a href="###" onclick="Pop('ad_user_detail.aspx?loginname=<%# Eval("LoginName") %>',820,550,'查看编辑');">编辑</a>

            
                </td>
            </tr>
        </ItemTemplate>

</asp:ListView>
      
        




    
         
<div>
 <asp:DataPager ID="DataPager1"   class="btn-group btn-group-sm"  
      PagedControlID="ListView1" runat="server" PageSize=10>
 <Fields>
           
     
            <asp:NextPreviousPagerField 
                PreviousPageText="<" 
                FirstPageText="|<" 
                ShowPreviousPageButton="true"
                ShowFirstPageButton="true" 
                ShowNextPageButton="false" 
                ShowLastPageButton="false"
                ButtonCssClass="btn btn-default" 
                RenderNonBreakingSpacesBetweenControls="false" 
                RenderDisabledButtonsAsLabels="false" />

            <asp:NumericPagerField 
                ButtonType="Link" 
                CurrentPageLabelCssClass="btn btn-primary disabled"  
                RenderNonBreakingSpacesBetweenControls="false"
                NumericButtonCssClass="btn btn-default" 
                ButtonCount="10" 
                NextPageText="..." 
                NextPreviousButtonCssClass="btn btn-default" />
            
           <asp:NextPreviousPagerField 
               NextPageText=">" 
               LastPageText=">|" 
               ShowNextPageButton="true"
               ShowLastPageButton="true" 
               ShowPreviousPageButton="false" 
               ShowFirstPageButton="false"
               ButtonCssClass="btn btn-default" 
               RenderNonBreakingSpacesBetweenControls="false" 
               RenderDisabledButtonsAsLabels="false"/>
      

  </Fields> 
</asp:DataPager>
</div>







        
     <ul class="dropdown-menu" id="contextMenu">
        
       
           <li>
            <a href="###"  onclick="_edit(); return false;"  >编辑（可双击）</a>    
        </li>
         
       
       <li role="separator" class="divider"></li>

        <li>
            <a href="#"  onclick="changeDept(); return false;"  >修改部门</a>    
        </li>

            <li>
            <a href="#"  onclick="changeOffice(); return false;"  >修改办公室</a>    
        </li>
         
            <li>
            <a href="#"  onclick="changeOu(); return false;"  >修改组织OU</a>    
        </li>
         
        
  
          <li role="separator" class="divider"></li>

         
           <li>
            <a  href="#" onclick="enableUser(); return false;">启用帐户</a>    
        </li>
   

            <li>
            <a  href="#" onclick="disabledUser(); return false;">禁用帐户</a>    
        </li>

          
         
             <li>
            <a  href="#" onclick="enableUser(); return false;">解锁帐户</a>    
           </li>

     
               <li role="separator" class="divider"></li>  
        <li>
            <a href="#"  onclick="changePwd(); return false;"  >重置密码</a>    
        </li>
         
             <li>
            <a  href="#" onclick="delUser(); return false;">删除用户</a>    
           </li>

 
          

</ul>





    <script>

         

            function FormatTable() {
                $("#tbl_users  tr:not(:first)").each(

                    function () {
                        var status = $(this).find("td").eq(0).text();
                   
                        if (status.trim() == "禁用") { 
                            $(this).css("color", "orange");
                        }

                        if (status.trim() == "锁定") { 
                            $(this).css("color", "#d44950");
                        } 
                    }

                    );

            }

        FormatTable();

         
    </script>












    <script>



        $(document).ready(function () { 

            $('#tbl_users tbody').on('click', 'tr', function () { 
                $(this).toggleClass('xxx'); 
            });


            $('#tbl_users tbody').on('dblclick', 'tr', function () {
                _id = $(this).data("id");
                Pop('ad_user_detail.aspx?loginname='+_id, 820, 550, '查看编辑');

            });


        });


        //文档对象注册鼠标按下事件；
        $(document).on("mousedown", function (event) {
            //button等于0代表左键，button等于1代表中键
            if (event.button == 0 || event.button == 1) {

                if (event.target.nodeName.toLowerCase() == "a") {
                }
                else {
                    $("#contextMenu").hide();//获取菜单停止动画，进行隐藏使用淡出效果
                }
            }
        });




        //文档对象注册上下文（右键）菜单事件
        $("#tbl_users tbody tr").on("contextmenu", function (event) {
            var pageX = event.pageX;//鼠标单击的x坐标
            var pageY = event.pageY;//鼠标单击的y坐标
            //$("#hf_trid").val($(this).attr("id").replace("tr_",""));

            //获取菜单
            var contextMenu = $("#contextMenu");

            var cssObj = {
                top: pageY + "px",//设置菜单离页面上边距离，top等效于y坐标
                left: pageX + "px"//设置菜单离页面左边距离，left等效于x坐标
            };

            //判断横向位置（pageX）+自定义菜单宽度之和，如果超过页面宽度及为溢出，需要特殊处理；
            var menuWidth = contextMenu.width();
            var pageWidth = $(document).width();
            if (pageX + contextMenu.width() > pageWidth) {
                cssObj.left = pageWidth - menuWidth - 5 + "px"; //-5是预留右边一点空隙，距离右边太紧不太美观；
            }

            //设置菜单的位置
            $("#contextMenu").css(cssObj).show();//显示使用淡入效果,比如不需要动画可以使用show()替换;

            event.preventDefault();//阻止浏览器与事件相关的默认行为；此处就是弹出右键菜单
        });





        function showMenu() {

            $('#tbl_users tbody tr').removeClass("xxx");

            $(this).parent().parent().addClass("xxx");
            var pageX = event.pageX;//鼠标单击的x坐标
            var pageY = event.pageY;//鼠标单击的y坐标
            //$("#hf_trid").val($(this).attr("id").replace("tr_",""));

            //获取菜单
            var contextMenu = $("#contextMenu");

            var cssObj = {
                top: pageY + "px",//设置菜单离页面上边距离，top等效于y坐标
                left: pageX + "px"//设置菜单离页面左边距离，left等效于x坐标
            };

            //判断横向位置（pageX）+自定义菜单宽度之和，如果超过页面宽度及为溢出，需要特殊处理；
            var menuWidth = contextMenu.width();
            var pageWidth = $(document).width();
            if (pageX + contextMenu.width() > pageWidth) {
                cssObj.left = pageWidth - menuWidth - 5 + "px"; //-5是预留右边一点空隙，距离右边太紧不太美观；
            }

            //设置菜单的位置
            $("#contextMenu").css(cssObj).show();//显示使用淡入效果,比如不需要动画可以使用show()替换;

            event.preventDefault();//阻止浏览器与事件相关的默认行为；此处就是弹出右键菜单

        }



        function disablescroll() {
            $("body").addClass("hdbody");
            // document.body.style.position = "fixed";
        }

        function enablescroll() {
            $("body").removeClass("hdbody");
        }



        

        

    </script>








    

    <script>



        function MakeSureSelect() {
            var checked = 0;
            var result = "";
            var _c = 0;
            var rows = $("tr.xxx");//table.rows('.selected').data();

            for (var i = 0; i < rows.length; i++) {
                checked++;
                var __id = $(rows[i]).find("td:eq(1)").html().trim();
                result = __id + "," + result;
            }
            result = result + "-1";
            if (checked > 0) {
                $("#hf_trid").val(result);
                return true;
            }
            else {
                $("#hf_trid").val("");
                return false;
            }
        }


        function delUser()
        {

            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val(); 
            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }
             

            $.ajax({ cache: false, url: "ajax_ad/deleteUser.aspx?loginnames=" + _theid });

            $("tr.xxx").remove(); 


        }


        
        function changeOu() {
            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }


            Pop('ad_changeou.aspx?loginnames=' + _theid, 820, 550, '修改OU');

        }

        function changeDept() {
            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }


            Pop('Ad_ChangeDeptOffice.aspx?types=dept&loginnames=' + _theid, 820, 550, '修改部门');

        }


        function changeOffice() {
            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }


            Pop('Ad_ChangeDeptOffice.aspx?types=office&loginnames=' + _theid, 820, 550, '修改办公室');

        }


        function changePwd() {
            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }
         

                Pop('Ad_ChangePwd.aspx?loginnames=' + _theid, 820, 550, '重置密码');

        }



        function _edit() {
            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }
            var _id = _theid.split(',')[0];

            Pop('ad_user_detail.aspx?loginname=' + _id, 820, 550, '查看编辑');
         
        }



   

        function disabledUser()
        {


            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }
             

            $.ajax({ cache: false, url: "ajax_ad/disabledUser.aspx?loginnames=" + _theid });
            layer.msg("操作成功");

        }





        function enableUser() {


            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }


            $.ajax({ cache: false, url: "ajax_ad/enableUser.aspx?loginnames=" + _theid });
            layer.msg("操作成功");

        }



        function _del() {

            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }
            $("#hf_trid").val();



            $.ajax({ cache: false, url: "ajax_pc/del_pc.aspx?ids=" + _theid });

            $("tr.xxx").remove();
        }



        function change(key) {

            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请至少选择一条记录', 12);
                return;
            }
            $("#hf_trid").val();

            //pclist_op.aspx?t=dept&ids=43,42&returnUrl=pc_list.aspx
            Pop("ajax_pc/pclist_op.aspx?ids=" + _theid + "&t=" + key, 500, 400, "更新状态");



        }




        function note(note) {


            MakeSureSelect();
            $("#contextMenu").hide();
            _theid = $("#hf_trid").val();

            if (_theid == "") {
                layer.alert('请选择一台PC，如果选择多个，系统会自动使用其中一个', 12);
                return;
            }
            $("#hf_trid").val();

            Pop("ajax_pc/pc_note.aspx?id=" + _theid.split(",")[0] + "&t=" + note, "500", 400, "更新备注");


        }


    </script>











</asp:Content>
