<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="entitylist.aspx.cs" Inherits="HySoft.BaseCallCenter.Web.formmanage.entitylist" %>

<!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 id="Head1" runat="server">
    <title>实体管理</title>
    <link href="../scripts/ui/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <script src="../scripts/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../scripts/ui/json2.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/core/base.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/ligerui.min.js" type="text/javascript"></script>
    <link href="../scripts/ui/skins/Tab/css/tab.css" rel="stylesheet" type="text/css" />
    <link href="../scripts/ui/skins/Tab/css/grid.css" rel="stylesheet" type="text/css" />
    <script src="../scripts/ui/js/plugins/ligerGrid.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/plugins/ligerLayout.js" type="text/javascript"></script>
    <link href="../scripts/ui/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <link href="../images/style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var gridlist;
        var fieldlist;
        var menu;
        var selectentityid = 0;
        var selectentityname = "";
        function itemclick(item, i) {
            switch (i) {
                case 0:
                    AddAttribute();
                    break;
                case 1:
                    ModifyAttribute();
                    break;
                case 2:
                    DeleteAttribute();
                    break;
                default:
                    break;
            }
        }
        function AddAttribute() {
            $.ligerDialog.open({ url: 'attributeedit.aspx?action=add&entityid=' + selectentityid, title: '新增[<font color=red>' + selectentityname + '</font>]属性', height: 460, width: 600, isResize: true
            });
        }
        $(function () {
            $("#layout1").ligerLayout({
                leftWidth: 399,
                allowCenterBottomResize: false
            });
            menu = $.ligerMenu({ top: 100, left: 100, width: 120, items:
            [
            { text: '增加属性', click: itemclick, icon: 'add' },
            { text: '修改属性', click: itemclick, icon: 'modify' },
            { line: true },
            { text: '删除属性', click: itemclick, icon: 'delete' }
            ]
            });
            LoadList();
            LoadFieldList(0);
        });

        function getWhereStr() {
            var keyWords = "";
            if (document.getElementById("txtKeywords").value != "") {
                keyWords += document.getElementById("txtKeywords").value;
            }
            return keyWords;
        }

        function GetSql() {
            var sql = "";
            if (document.getElementById("txtKeywords").value != "") {
                sql += "&key=" + encodeURIComponent(document.getElementById("txtKeywords").value);
            }
            return sql;
        }

        function LoadList() {
            var sql = GetSql();
            gridlist = $("#diventitylist").ligerGrid({
                height: '95%',
                columns: [
                { display: 'ID', name: '_f_entityid', align: 'left', width: 1, hide: true },
                { display: '实体名称', name: '_f_name', width: 110 },
                { display: '实体表名', name: '_f_dbtablename', width: 100 },
                { display: '是否启用', name: '_f_isactivity', width: 80, render: function (rowdata, rowindex) {
                    if (rowdata._f_isactivity == 1) { return '启用'; }
                    else { return '禁用'; }
                }
                }
                ], url: '../formmanage/ajax/entitylist.ashx?action=getentitylist', pageSize: 10, rownumbers: true,
                onSelectRow: function (data, rowindex, rowobj) {
                    selectentityid = data._f_entityid;
                    selectentityname = data._f_name;
                    LoadFieldList(data._f_entityid);
                },
                onDblClickRow: function (data, rowindex, rowobj) {
                }
            });
            gridlist.changePage('first');
            $("#pageloading").hide();
        }

        function LoadFieldList(entityid) {
            try {
                fieldlist = $("#divfieldlist").ligerGrid({
                    height: '95%',
                    columns: [
                { display: 'ID', name: '_f_attributeid', align: 'left', width: 1, hide: true },
                { display: '显示顺序', name: '_f_columnnumber', width: 60 },
                { display: '属性名称', name: '_f_name', width: 110 },
                { display: '数据字段', name: '_f_dbfieldlname', width: 100 },
                { display: '数据类型', name: '_f_dbtypename', width: 60 },
                { display: '长度', name: '_f_length', width: 60, render: function (rowdata, rowindex) {
                    if (rowdata._f_length == 0) { return ''; }
                    else { return rowdata._f_length; }
                }
                },
                { display: '主键', name: '_f_ispkattribute', width: 50, render: function (rowdata, rowindex) {
                    if (rowdata._f_ispkattribute) { return '<font color=red>是</font>'; }
                    else { return ''; }
                }
                },
                { display: '外键', name: '_f_iscustomfield', width: 50, render: function (rowdata, rowindex) {
                    if (rowdata._f_iscustomfield) { return '<font color=red>是</font>'; }
                    else { return ''; }
                }
                },
                { display: '显示', name: '_f_visibletoplatform', width: 50, render: function (rowdata, rowindex) {
                    if (rowdata._f_visibletoplatform) { return '<font color=red>是</font>'; }
                    else { return ''; }
                }
                },
                { display: '下拉', name: '_f_islookup', width: 50, render: function (rowdata, rowindex) {
                    if (rowdata._f_islookup) { return '<font color=red>是</font>'; }
                    else { return ''; }
                }
                }, { display: '下拉关联', name: '_f_lookupkey', width: 80 }
                ], onContextmenu: function (node, e) {
                    try {
                        actionRow = node;
                        menu.show({ top: e.pageY, left: e.pageX });
                    }
                    catch (e) {
                        alert(e.Message);
                    }
                    return false;
                }, url: '../formmanage/ajax/entitylist.ashx?action=getentityattributelistbyid&id=' + entityid, pageSize: 10, rownumbers: true, 
                    onSelectRow: function (data, rowindex, rowobj) {
                    },
                    onDblClickRow: function (data, rowindex, rowobj) {
                    }
                });
                fieldlist.changePage('first');
                $("#pageloading").hide();
            }
            catch (e) {alert(e.Message);
            }
        }

        function Add() {
            $.ligerDialog.open({ url: 'entityedit.aspx?action=add', title: '新增实体', height: 380, width: 500, isResize: true
            });
        }

        document.onkeydown = function (event) {
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 13) {
                LoadList();
            }
        };
    </script>
</head>
<body style="overflow: hidden;">
    <form id="form1" runat="server">
    <div class="tools_box">
        <div class="tools_bar">
            <a class="tools_btn" href="#" onclick="Add();"><span><b class="add">添加</b></span>
            </a><a class="tools_btn" href="#" onclick="Modify();"><span><b class="modify">修改</b></span>
            </a><a class="tools_btn" href="#" onclick="Delete();"><span><b class="delete">禁用</b></span>
            </a><a class="tools_btn" href="#" onclick="DeleteUser('0');"><span><b class="delete">
                启用</b></span> </a>
            <div class="search_box">
                关键字：<asp:TextBox ID="txtKeywords" runat="server" CssClass="txtInput"></asp:TextBox>&nbsp;&nbsp;
                <input id="btnSearch" type="button" value="搜 索" class="btnSearch" onclick="LoadList();" />
            </div>
        </div>
    </div>
    <div id="layout1" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px;
        padding-top: 0px; width: 100%;">
        <div style="height: 100%; overflow: hidden;" position="left" title="实体列表">
            <div id="diventitylist">
            </div>
        </div>
        <div position="center" title="属性列表">
            <div id="divfieldlist">
            </div>
        </div>
    </div>
    </form>
</body>
</html>
