<%@ Page Language="VB" AutoEventWireup="false" CodeFile="TableData.aspx.vb" Inherits="Manager_Tags_TableData" %>

<!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 href="/App_Themes/ManagerTheme/skin.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="/App_Themes/ManagerTheme/Js/jquery.min.js"></script> 
    <script type="text/javascript" src="/App_Themes/ManagerTheme/js/lhgdialog.min.js"></script>
    <style type="text/css">
        .LeftArea{width:500px;}
        .AreaScroll{overflow-x: hidden;overflow:scroll;height:550px;}
        .LeftArea ul{ margin:0px; padding:5px; width:480px;}
        .LeftAreali{list-style:none; line-height:25px; height:25px;}
        .LeftAreali span{ display:block; float:left; margin-left:5px;cursor:pointer;}
        .CenterArea{border-left: 1px solid #C0C0C0;border-right: 1px solid #C0C0C0; width:4px; background-color:#ebeade;}
        .TitleLine{border-bottom: 1px solid #C0C0C0;}
        .TitleLine ul{ margin:0px; padding:5px;}
        .ToolBar{margin:0px; padding:0px 0px 0px 5px;}
        .ToolBar li{float:left; list-style:none; padding-right:15px;cursor:pointer;}
        .RightArea ul{ margin:0px; padding:5px; }
        .RightAreali{list-style:none; line-height:25px; height:25px;}
        .RightAreali span{ display:block; float:left; margin-left:5px;cursor:pointer;}
        .liSelected{background-color:#0373F5;color:#fff;}
    </style>
    <script language="javascript" type="text/javascript">
        $(document).ready(function() {
            GetTableList();
        });
        function tableClick(obj) {
            var tid = $(obj).attr('id').replace('t', '');
            var TableNote = $(obj).attr('title');
            $('#TableNote').attr('value', TableNote);
            $('#TableID').attr('value', tid);
            $('.LeftAreali>span[class="liSelected"]').removeClass();
            $(obj).attr('class', 'liSelected');
            GetFieldsList();
        }
        function fieldClick(obj) {
            var fid = $(obj).attr('id').replace('f', '');
            var FieldNote = $(obj).attr('title');
            $('#FieldNote').attr('value', FieldNote);
            $('#FieldID').attr('value', fid);
            $('.RightAreali>span[class="liSelected"]').removeClass();
            $(obj).attr('class', 'liSelected');
        }
        function callBack() {
            window.location = window.location;
        }
        function openImport() {
            var diaAPI = $.dialog({lock: true,
                                   title: '导入数据表',
                                   content: 'url:/Manager/Tags/TableImportList.aspx',
                                   width: '650',
                                   height: '400',
                                   max: false,
                                   min: false});
       }
       function GetTableList() {
           $('#TableList').html('');
           $.getJSON("/TableList.gdr?tmp=" + (new Date()).getTime(), { "resultType": "json" }, function(data, textStatus) {
               if (data.length > 0) {
                   for (var i = 0; i < data.length; i++) {
                       $('#TableList').append('<li class="LeftAreali"><span><img alt="' + data[i].TableName + '" src="/App_Themes/ManagerTheme/Images/Table.gif" /></span><span id="t' + data[i].ID + '" title="' + data[i].TableNote + '">' + data[i].TableNote + '&nbsp;[' + data[i].TableName + ']</span></li>');
                   }
                   $('.LeftAreali>span[id]').each(function() {
                       $(this).bind('click', function() { tableClick(this); });
                   });
               }
           }); 
       }
       function editTable() {
           var obj = $('.LeftAreali>span[class="liSelected"]');
           if (obj.length == 0) { $.dialog.alert('<div style="width:300px;padding:0px 0px 0px 15px;">请选择编辑的数据表！</div>'); return; }
           $.dialog.prompt('数据表名称：',
                            function(val) {
                                $('#TableNote').attr('value', val);
                                $.get("/EditTable.gdr?TableNote=" + encodeURI(val) + "&TableID=" + $('#TableID').attr('value') + "&tmp=" + (new Date()).getTime(), { "resultType": "html" }, function(data, textStatus) {
                                    if (data == '1') {
                                        GetTableList();
                                    } else {
                                        $.dialog.alert('<div style="width:300px;padding:0px 0px 0px 15px;">数据表说明保存失败！</div>');
                                    }
                                });
                            },
                            $('#TableNote').attr('value'),
                            this);
       }
       function delTable() {
           var obj = $('.LeftAreali>span[class="liSelected"]')
           if (obj.length == 0) { $.dialog.alert('<div style="width:300px;padding:0px 0px 0px 15px;line-height:25px;">请选择要删除的数据表！</div>'); return; }
           $.dialog.confirm('<div style="width:300px;padding:0px 0px 0px 15px;line-height:25px;">单击确定将删除此数据表以及该表所有字段<br />你确定要删除这个数据表吗？</div>',
                            function() {
                                $.get("/DelTable.gdr?TableID=" + $('#TableID').attr('value') + "&tmp=" + (new Date()).getTime(), { "resultType": "html" }, function(data, textStatus) {
                                    if (data == '1') {
                                        GetTableList();
                                    } else {
                                        $.dialog.alert('<div style="width:300px;padding:0px 0px 0px 15px;">数据表删除失败！</div>');
                                    }
                                });
                            },
                            function() { return; }
                            );
       }
       function GetFieldsList() {
           $('#FieldsList').html('');
           var imgField = '';
           $.getJSON("/FieldsList.gdr?TableID=" + $('#TableID').attr('value') + "&tmp=" + (new Date()).getTime(), { "resultType": "json" }, function(data, textStatus) {
               if (data.length > 0) {
                   for (var i = 0; i < data.length; i++) {
                       if (data[i].IsPrimaryKey == '1') {
                           imgField = "PrimaryKey.gif";
                       } else {
                           imgField = "Field.gif";
                       }
                       $('#FieldsList').append('<li class="RightAreali"><span><img alt="' + data[i].FieldName + '" src="/App_Themes/ManagerTheme/Images/' + imgField + '" /></span><span id="f' + data[i].ID + '" title="' + data[i].FieldNote + '" onclick="fieldClick(this);">' + data[i].FieldNote + '&nbsp;[' + data[i].FieldName + ']</span></li>');
                   }
               } else {
                   $.dialog.alert('<div style="width:300px;padding:0px 0px 0px 15px;">请求的字段不存在，请重新导入表数据！</div>');
               }
           }); 
       }
       function DelField() {
           var obj = $('.RightAreali>span[class="liSelected"]')
           if (obj.length == 0) { $.dialog.alert('<div style="width:300px;padding:0px 0px 0px 15px;line-height:25px;">请选择要删除的字段！</div>'); return; }
           $.dialog.confirm('<div style="width:300px;padding:0px 0px 0px 15px;line-height:25px;">单击确定将删除字段<br />你确定要删除这个字段吗？</div>',
                            function() {
                                $.get("/DelField.gdr?FieldID=" + $('#FieldID').attr('value') + "&tmp=" + (new Date()).getTime(), { "resultType": "html" }, function(data, textStatus) {
                                    if (data == '1') {
                                        GetFieldsList();
                                    } else {
                                        $.dialog.alert('<div style="width:300px;padding:0px 0px 0px 15px;">字段删除失败！</div>');
                                    }
                                });
                            },
                            function() { return; }
                            );
       }
       function EditField() {
           var obj = $('.RightAreali>span[class="liSelected"]')
           if (obj.length == 0) { $.dialog.alert('<div style="width:300px;padding:0px 0px 0px 15px;">请选择编辑的字段！</div>'); return; }
           $.dialog.prompt('字段说明：',
                            function(val) {
                                $('#FieldNote').attr('value', val);
                                $.get("/EditField.gdr?FieldNote=" + encodeURI(val) + "&FieldID=" + $('#FieldID').attr('value') + "&tmp=" + (new Date()).getTime(), { "resultType": "html" }, function(data, textStatus) {
                                    if (data == '1') {
                                        GetFieldsList();
                                    } else {
                                        $.dialog.alert('<div style="width:300px;padding:0px 0px 0px 15px;">字段说明保存失败！</div>');
                                    }
                                });
                            },
                            $('#FieldNote').attr('value'),
                            this);
       }
    </script>
</head>
<body>
    <form id="form1" runat="server">
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin-top:10px;">
  <tr>
    <td style="width:17px; background-image:url(/App_Themes/ManagerTheme/Images/mail_leftbg.gif)" valign="top"><img src="/App_Themes/ManagerTheme/Images/left-top-right.gif"  /></td>
    <td valign="top" style="background-image:url(/App_Themes/ManagerTheme/Images/content-bg.gif)" class="LeftArea TitleLine">
        <ul class="ToolBar">
            <li><img src="/App_Themes/ManagerTheme/Images/ImportTable.gif" alt="导入" onclick="openImport();" /></li>
            <li><img src="/App_Themes/ManagerTheme/Images/EditTable.gif" alt="编辑" onclick="editTable();" /></li>
            <li><img src="/App_Themes/ManagerTheme/Images/DeleteTable.gif" alt="删除" onclick="delTable();" /></li>
        </ul>
    </td>
    <td valign="top" style="background-image:url(/App_Themes/ManagerTheme/Images/content-bg.gif)" class="CenterArea"></td>
    <td valign="top" style="background-image:url(/App_Themes/ManagerTheme/Images/content-bg.gif)" class="TitleLine">
        <ul class="ToolBar">
            <li><img src="/App_Themes/ManagerTheme/Images/EditField.gif" alt="编辑" onclick="EditField();" /></li>
            <li><img src="/App_Themes/ManagerTheme/Images/DeleteField.gif" alt="删除" onclick="DelField();" /></li>
        </ul>
    </td>
    <td width="16" valign="top" style="background-image:url(/App_Themes/ManagerTheme/Images/mail_rightbg.gif)"><img src="/App_Themes/ManagerTheme/Images/nav-right-bg.gif" /></td>
  </tr>
  <tr>
    <td valign="middle" style="background-image:url(/App_Themes/ManagerTheme/Images/mail_leftbg.gif)">&nbsp;</td>
    <td valign="top" class="LeftArea">
        <ul class="AreaScroll" id="TableList"></ul>
    </td>
    <td valign="top" class="CenterArea"></td>
     <td valign="top" class="RightArea">
        <ul id="FieldsList" class="AreaScroll"></ul>
     </td>
    <td style="background-image:url(/App_Themes/ManagerTheme/Images/mail_rightbg.gif)">&nbsp;</td>
  </tr>
  <tr>
    <td valign="bottom" style="background-image:url(/App_Themes/ManagerTheme/Images/mail_leftbg.gif)"><img src="/App_Themes/ManagerTheme/Images/buttom_left2.gif" width="17" height="17" /></td>
    <td style="background-image:url(/App_Themes/ManagerTheme/Images/buttom_bgs.gif)"><img src="/App_Themes/ManagerTheme/Images/buttom_bgs.gif" width="17" height="17"></td>
    <td style="background-image:url(/App_Themes/ManagerTheme/Images/buttom_bgs.gif)" class="CenterArea"></td>
    <td style="background-image:url(/App_Themes/ManagerTheme/Images/buttom_bgs.gif)"></td>
    <td valign="bottom" style="background-image:url(/App_Themes/ManagerTheme/Images/mail_rightbg.gif)"><img src="/App_Themes/ManagerTheme/Images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>
<input type="hidden" id="TableID" />
<input type="hidden" id="TableNote" />
<input type="hidden" id="FieldID" />
<input type="hidden" id="FieldNote" />
</form>
    
</body>
</html>
