<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RelevanceDetail.aspx.cs"
    Inherits="Webdisk.RelevanceDetail" %>

<!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 runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="themes/icon.css" />
    <link href="themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script src="js/jquery.easyui.min.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
            <div class="easyui-panel" data-options="border:true" style="margin:2px; padding:10px;  height:150px">
               关联文件：
               <input id="combogrid" name="relevancefile" style="width:500px;" /> 
               <a href="javascript:void(0)" class="easyui-linkbutton" onclick="btnSearch_click()">查找文件</a>
        </div> 
        <div style="padding: 5px;" align="right">
            <a href="#" onclick="btnSave_click()" class="easyui-linkbutton" data-options="iconCls:'icon-add'" id="btnSave">确定</a>
            <%--<a href="javascript:window.opener=null;window.top.close();" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" id="btnclose">关闭</a>--%>
        </div>

        <div id="w" class="easyui-window" title="Modal Window" data-options="modal:true,closed:true,iconCls:'icon-save',url:'RelevanceDetail2.aspx'" style="width:500px;height:400px;padding:10px; display:none">
		    
	</div>
    </form>
</body>
</html>

<script type="text/javascript">
    $(function(){
        var userName='<%=strUserName %>';
        $('#combogrid').combogrid({    
            panelWidth: 500,
			multiple: true,
			idField: 'id',
			textField: 'FileName',
			url: 'RelevanceHandler.ashx?cmd=GetAllpathByUser&username='+userName,
			method: 'post',
            pageList: [10, 15, 20, 25, 30, 40, 50],
            pageSize: 10,
            striped: true,
            pagination: true,           //是否分页
            rownumbers: true,           //序号
            fit: true,                  //自动大小
			columns: [[
				{field:'id',checkbox:true},
				{ field: 'FileName', title: '文件名', align: 'left',fixed:true, sortable: true },
                { 
                    field: 'FileSize', title: '大小', width: 80, align: 'center', sortable: true,
                    formatter: function(value,row,index){
				        if(value>1073741824)
                            return  Math.round(value/1073741824,2)+ "GB";
                        else if (value > 1048576) 
                            return  Math.round(value/1048576,2) + "MB";
                        else if (value > 1024) 
                            return  Math.round(value/1024) +" KB";
                        else return  "0 KB";
			        }
                },
                { field: 'FileExt', title: '文件类型', width: 80, align: 'center', sortable: true },
                { field: 'UserName', title: '所属用户', width: 80, align: 'center', sortable: true }
			]],
			fitColumns: true
            });
             
    });

    function btnSave_click() {
        var ids = $("#combogrid").combogrid('getValues');
        if (ids == undefined || ids == "") {
            alert("请选择要关联的文件！");
            return;
        }
        $.ajax({
            type: "POST",
			cache:false,
            contentType: "application/json;utf-8",
            url: "RelevanceHandler.ashx?cmd=save&sourid="+<%=strID %>+"&ids=" + ids,
            success: function (data) {
               alert("添加成功！");
               window.parent.reloadFile();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误:" + XMLHttpRequest.responseText);
                return false;
            }
        });
    }

    function btnSearch_click()
    {
        window.parent.$("#divTab").tabs("add", {
            title: "查找文件",
            url: "RelevanceDetail2.aspx",
            id: "newtabSearch",
            type:"post",
            datatype: "text",
            closable: true
       });
    }
</script>