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

<!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="../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>
    <script src="../scripts/ui/js/plugins/ligerTree.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/plugins/ligerMenu.js" type="text/javascript"></script>
    <script src="../scripts/CustomersData.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 src="../scripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript">
        var menu;
        var menucategory;
        var actionNode;
        var actionRow;
        var categorytree = null;
        var gridlist = null;
        var singleClick;
        $(function () {
            //            $("#layout1").ligerLayout({
            //                leftWidth: 200
            //            });
            try
            {
            var vheight = document.body.clientHeight;
            document.getElementById("tableMessage").style.height = vheight - 130;
            document.getElementById("divTree").style.height = vheight - 130;
        }
        catch (e)
            { }
            InitMenu();
            InitCategory();
            InitList("");
        });
        function InitMenu() {
            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' }
            ]
            });
            menucategory = $.ligerMenu({ top: 100, left: 100, width: 120, items:
            [
            { text: '增加', click: itemcategoryclick, icon: 'add' },
            { text: '修改', click: itemcategoryclick, icon: 'modify' },
            { line: true },
            { text: '删除', click: itemcategoryclick, icon: 'delete' }
            ]
            });
        }
        function itemcategoryclick(item, i) {
            switch (i) {
                case 0:
                    AddCategory();
                    break;
                case 1:
                    ModifyCategory();
                    break;
                case 2:
                    DeleteCategory();
                    break;
                default:
                    break;
            }
        }
        function itemclick(item, i) {
            switch (i) {
                case 0:
                    Add();
                    break;
                case 1:
                    Modify();
                    break;
                case 2:
                    Delete();
                    break;
                default:
                    break;
            }
        }
        function InitCategory() {

            try {
                categorytree = $("#treecategory").ligerTree({
                    checkbox: false,
                    nodeWidth: 200,
                    url: 'ajax/dictionarymanage.ashx?action=gettreelist',
                    onContextmenu: function (node, e) {
                        actionNode = node;
                        categorytree.selectNode(actionNode.data.id);
                        menucategory.show({ top: e.pageY, left: e.pageX });
                        return false;
                    },
                    onClick: function (node, e) {
                        InitList(node.data.id);
                    }
                });
            }
            catch (e) {
                alert(e.Message);
            }
        }
        function GetSql() {
            var sql = "";
            if (document.getElementById("F_DictionaryFlag").value != "") {
                sql += "&flag=" + escape(document.getElementById("F_DictionaryFlag").value);
            }
            if (document.getElementById("F_Name").value != "") {
                sql += "&name=" + document.getElementById("F_Name").value;
            }
            return sql;
        }
        function InitList(id) {
            var sql = GetSql();
            try {
                gridlist = $("#divDataList").ligerGrid({
                    checkbox: true,
                    height: '95%',
                    columns: [
                { display: 'ID', name: '_f_dictionaryvalueid', width: '1%', hide: 'ID' },
                { display: '字典标识', name: '_f_dictionaryflag', align: 'left', width: '15%' },
                { display: '字典值', name: '_f_name', width: '20%' },
                { display: '备注', name: '_f_describe', width: '32%' },
                { display: '排序编号', name: '_f_sort', width: '25%' }
                ],
                    onContextmenu: function (node, e) {
                        try {
                            actionRow = node;
                            //gridlist.select(node);
                            menu.show({ top: e.pageY, left: e.pageX });
                        }
                        catch (e) {
                            alert(e.Message);
                        }
                        return false;
                    },
                    url: 'ajax/dictionarymanage.ashx?action=getlist&id=' + id + sql, pageSize: 10, rownumbers: true,
                    onSelectRow: function (data, rowindex, rowobj) {
                        singleClick = data._f_dictionaryvalueid;
                    },
                    onDblClickRow: function (data, rowindex, rowobj) {
                        Modify();
                    },
                    onAfterShowData: function (data) {
                        var vheight = $("#divDataList").height();
                        document.getElementById("tableMessage").style.height = vheight;
                        document.getElementById("divTree").style.height = vheight-30;
                    }
                });
            }
            catch (e) {
                alert(e.Message);
            }
            gridlist.changePage('first');
            $("#pageloading").hide();
        }
        function AddCategory() {
            $.ligerDialog.open({ url: 'dictionarytreeedit.aspx?getPuction=Add', title: '添加字典信息', height: 370, width: 700, isResize: true
            });
        }
        function ModifyCategory() {
            //获取选择的分类
            var node = categorytree.getSelected();
            if (node) {
                $.ligerDialog.open({ url: 'dictionarytreeedit.aspx?getPuction=Edit&id=' + node.data.id, title: '修改[<font color="red">' + node.data.text + '</font>]字典分类', height: 370, width: 700, isResize: true
                });
            }
            else {
                $.ligerDialog.error('没有选择要修改的分类');
            }
        }
        function DeleteCategory() {
            //获取选择的分类
            var node = categorytree.getSelected();
            if (node) {
                $.ligerDialog.confirm('确定要删除【<font color="red">' + node.data.text + '</font>】吗？', function (yes) {
                    if (yes) {
                        $.post("ajax/dictionarymanage.ashx?action=deletetree&id=" + node.data.id, function (data) {
                            if (data == "success") {
                                $.ligerDialog.success('删除成功');
                                InitCategory();
                            }
                            else {
                                $.ligerDialog.error('删除失败');
                            }
                        });
                    }
                    else {
                    }
                });
            }
            else {
                $.ligerDialog.error('没有选择要删除的分类');
            }
        }
        function Add() {
            //获取选择的分类
            var node = categorytree.getSelected();
            if (node) {
                $.ligerDialog.open({ url: 'dictionarylistedit.aspx?getPuction=Add&id=' + node.data.id, title: '添加字典信息', height: 400, width: 700, isResize: true
                });
            }
            else {
                $.ligerDialog.error('没有选择要添加的分类');
            }
        }
        function Modify() {
            if (singleClick == "" || singleClick == undefined) {
                alert("请选择修改行！");
            } else {
                $.ligerDialog.open({ url: 'dictionarylistedit.aspx?getPuction=Edit' + '&singleFlage=' + singleClick, title: '修改字典信息', height: 400, width: 700, isResize: true
                });
            }
        }
        function Delete() {
            try {
                //获取选择的行
                var rows = gridlist.getSelectedRows();
                if (rows.length > 0) {
                    $.ligerDialog.confirm('确定要批量删除选择的记录吗？', function (yes) {
                        if (yes) {
                            try {
                                var arr = new Array();
                                var i = 0;
                                for (var i = 0; i < rows.length; i++) {
                                    arr[i] = rows[i]._f_dictionaryvalueid;
                                }
                                $.post("ajax/dictionarymanage.ashx?action=deletelist&arrid=" + arr.toString(), function (data) {
                                    if (data == "success") {
                                        $.ligerDialog.success('删除成功');
                                        InitList("");
                                    }
                                    else {
                                        $.ligerDialog.error('删除失败');
                                    }
                                });
                            }
                            catch (e) {
                                alert(e.Message);
                            }
                        }
                        else {
                        }
                    });
                }
                else {
                    $.ligerDialog.error('没有选择要删除的行');
                }
            }
            catch (e) {
                $.ligerDialog.error(e.Message);
            }
        }
        function ZiShiYing() {
            InitList("");
        }
        document.onkeydown = function (event) {
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 13) {
                InitList();
            }
        };
    </script>
</head>
<body>
    <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>
            <div class="search_box">
                字典标识：<asp:TextBox ID="F_DictionaryFlag" runat="server" CssClass="txtInput"></asp:TextBox>&nbsp;&nbsp;
                字典值：<asp:TextBox ID="F_Name" runat="server" CssClass="txtInput"></asp:TextBox>&nbsp;&nbsp;
                <input id="btnSearch" type="button" value="搜 索" class="btnSearch" onclick="InitList();" />
            </div>
        </div>
    </div>
    <table id="tableMessage" cellpadding="3" cellspacing="3" border="0" style="width: 100%;">
        <tr>
            <td valign="top" style="width: 230px; padding: 0px 2px 5px 2px;">
                <div class="tools_box" style="height: 30px;">
                    <div class="tools_bar">
                        <div style="float: left; padding-top: 6px; padding-left: 1px; font-weight: bold;
                            color: red;">
                            <img src="../images/icon_site.gif" />&nbsp;字典类别</div>
                    </div>
                </div>
                <table id="tableTree" cellpadding="0" cellspacing="0" style="width: 100%; border: 1px solid #D6D6D6;">
                    <tr>
                        <td valign="top">
                            <table cellpadding="0" cellspacing="0" border="0">
                                <tr height="30px">
                                    <td>
                                        <div class="tools_box" style="height: 30px;">
                                            <div class="tools_bar" style="text-align: left; padding-left: 10px;">
                                                <input id="btnAddCategory" type="button" value="添 加" class="btnSearch" onclick="AddCategory();" />&nbsp;&nbsp;
                                                <input id="btnModifyCategory" type="button" value="修 改" class="btnSearch" onclick="ModifyCategory();" />&nbsp;&nbsp;
                                                <input id="btnDeleteCategory" type="button" value="删 除" class="btnSearch" onclick="DeleteCategory();" />
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                <tr valign="top">
                                    <td>
                                        <div id="divTree" style="overflow: auto;">
                                            <ul id="treecategory">
                                            </ul>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
            <td valign="top" style="padding: 0px 2px 5px 2px;">
                <div class="tools_box" style="height: 30px;">
                    <div class="tools_bar">
                        <div style="float: left; padding-top: 6px; padding-left: 1px; font-weight: bold;
                            color: red;">
                            <img src="../images/ico-show-txt.png" />&nbsp;字典列表</div>
                    </div>
                </div>
                <div id="divDataList" style="width: 100%;">
                </div>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
