<%@ page language="C#" autoeventwireup="true" inherits="GZ_system_N25175_Department, GZQuery_deploy" enableEventValidation="false" %>

<!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>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/GZ/control/easy_ui/jquery.min.js?v=1")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/GZ/control/easy_ui/jquery.easyui.min.js?v=1")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/GZ/control/easy_ui/locale/easyui-lang-zh_CN.js?v=1")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/GZ/control/easy_ui/jquery.load.js?v=1")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/GZ/control/easy_ui/jquery.json.js?v=1")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/GZ/control/easy_ui/jquery.easyui.validtor.js?v=1")%>"></script>
    <script type="text/javascript" language="javascript" src="<%=ResolveUrl("~/GZ/control/js/PageDialog.js?v=1")%>"></script>
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/GZ/control/easy_ui/themes/gray/easyui.css?v=1")%>" />
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/GZ/control/easy_ui/themes/icon.css?v=1")%>" />
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/GZ/control/easy_ui/load.css?v=1")%>" />
    <link rel="stylesheet" type="text/css" href="<%=ResolveUrl("~/GZ/control/css/main.css?v=1")%>" />
    <script language="javascript" type="text/javascript">
       function query(){
	        $("#dataview").datagrid("load",{
	        					d_name: $("#qd_name").val()
							
						});
   	   }
   </script>
   
   
</head>
<body class="easyui-layout" style="visibility:hidden">
    <div region="center" border="false">
        <table id="dataview">
            <thead>
                <tr>  
					<th field="ck" checkbox="true"></th>
						<th field="id" width="80" formatter='OperFormat'>操作</th>
						<th field="d_name" width="150" >部门名称</th>
						<th field="d_sort" width="70" >排序</th>
						<th field="d_cdate" width="150" >创建日期</th>
						<th field="d_note" width="150" >备注</th>


				</tr>
            </thead>
        </table>
    </div>
    <div id="toolbar"     >
        <a class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="Add()">添 加</a>
        <a class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="deleteList()">删除</a>
        <br/>&nbsp;
        		部门名称 ：<input id="qd_name"  type="text" maxlength="255" onkeydown= "if(event.keyCode==13)query()"/>

		   
        <a class="easyui-linkbutton" iconcls="icon-search" plain="true" onclick="query()">查询 </a>
        <a class="easyui-linkbutton" iconcls="icon-book" plain="true" onclick="$('#dataview').datagrid('load',{})">全部显示</a>
    </div>
    
    <div id="OperMenu" class="easyui-menu" style="width:120px;">    
            <div onclick='editItem(currentMenuKey)' data-options="iconCls:'icon-edit'" >编辑信息</div>
            <div onclick='Add()' data-options="iconCls:'icon-add'" >添加信息</div>
            <div class="menu-sep"></div>
            <div onclick="deleteItem(currentMenuKey)" data-options="iconCls:'icon-cancel'">删除信息</div>
    </div>
    
</body>

<script language="javascript" type="text/javascript">
var currentMenuKey = null;
$(function(){

    $("#dataview").datagrid({
        toolbar:"#toolbar",
        fit:true,
        idfield:"id",
        border:false,
        pageSize:30,
        resizable:true,
        pagination:true,
        rownumbers:true,
        url:"N25175_Department_Dataview.aspx",
        onLoadSuccess:function(){ $('#dataview').datagrid("unselectAll"); },
        onRowContextMenu:function(e,rowindex,row){
            e.preventDefault();
            openMenu(e.pageX,e.pageY,row.id,row.isEdit,row.isDelete);
            $('#dataview').datagrid("unselectAll").datagrid("selectRow",rowindex);
        }
    });
    $("body").css("visibility","visible"); 
});
    function openMenu(left,top,id){
        $('#OperMenu').menu('show',{  
                left:left,  
                top: top 
        });
        currentMenuKey = id;
    }
		
	function OperFormat(value,row,index){
		return "<a href='javascript:void(0)' onclick=\"editItem('"+value+"')\">编辑</a>&nbsp;|&nbsp;<a href='javascript:void(0)' onclick=\"deleteItem('"+value+"')\">删除</a>";
	}	
	
	
	
	
	function deleteItem(key){
	     $.messager.confirm('确认','确定要删除选中吗?',function(r){
	     if(!r){ return }load("删除中...");
	             $.ajax({
	                type: "POST",
	                url:"N25175_Department_Delete.aspx",
	                dataType:"json",
	                data: {"deleteKey": key},
	                success: function(data){
	                  unload();
	                  if(data.state==1){
	                      $.messager.show({title: '提示', msg: data.data});
	                      $('#dataview').datagrid('reload').datagrid("unselectAll");
	                  }
	                  else{
	                     $.messager.alert('错误',data.data,'message');
	                  }
	               }
	            });
	     });
	}
	function deleteList(){
	     var row = $('#dataview').datagrid('getSelections');
	     if(row.length==0){$.messager.alert('提示',"请选择删除项！",'message'); return;}
	     $.messager.confirm('确认','确定要删除选中吗?',function(r){
	     if(r){
	                 load("删除中...");
	                 var list = new Array();
	                 for(var index =0; index<row.length;index++){ list.push(row[index].id);  }
	                 $.ajax({
	                    type: "POST",
	                    url:"N25175_Department_Delete.aspx",
	                    dataType:"json",
	                    data: {"deleteList": list.join(",")}, 
	                    success: function(data){
	                      unload();
	                      if(data.state==1){
	                          $.messager.show({ title: '提示', msg: "总共删除"+data.data+"条信息" });
	                          $('#dataview').datagrid('reload').datagrid("unselectAll");
	                      }else{
	                         $.messager.alert('错误',data.data,'message');
	                      }
	                   }
	                });
	     }
	     });
	}
	
	function editItem(key){
	    ShowDialog("edit","N25175_Department_Edit.aspx?id="+key,600,300,0,0,true);
	}
	function Add(){
	 	ShowDialog("add","N25175_Department_Insert.aspx",600,300,0,0,true);
	}
	function reload(param){
	    if(param=='last'){
	        var grid = $('#dataview'); 
	        var gridOptions = grid.datagrid("options"); 
	        var options = grid.datagrid('getPager').data("pagination").options;  
	        var pagenumber = options.total==0?1:Math.ceil( options.total/options.pageSize);
	        gridOptions.pageNumber = pagenumber 
	        options.pageNumber = pagenumber;
	        $('#dataview').datagrid('reload');
	    }
	    $('#dataview').datagrid('reload');
	}


</script>

</html>
