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

<!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/jquery/jquery-1.8.3.min.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" />
    <script src="../scripts/My97DatePicker/lang/zh-cn.js" type="text/javascript"></script>
    <link href="../images/style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var selectcategoryid = "";
        var categorylist;
        var questionlist;
        function LoadCategoryList() {
            categorylist=$("#divCategoryList").ligerGrid({
                height: '97%',
                width: 230,
                columns: [
                { display: '试题分类', width: '86%', name: '_f_categoryname' }
                ],
                toolbar: {
                    items: [
                    { text: '增加', click: itemclick1, icon: 'add' },
                    { line: true },
                    { text: '修改', click: itemclick1, icon: 'modify' },
                    { line: true },
                    { text: '删除', click: itemclick1, icon: 'delete' }
                    ]
                },
                url: 'ajax/questioncategory.ashx?action=getlist', pageSize: 50, pageSizeOptions: [10, 20, 50], rownumbers: true,
                onSelectRow: function (data, rowindex, rowobj) {
                    selectcategoryid = data._f_categoryid;
                    LoadQuestionList();
                },
                onDblClickRow: function (data, rowindex, rowobj) {
                    var id = "";
                    try {
                        id = data._f_categoryid;
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        $.ligerDialog.open({ url: 'questioncategoryedit.aspx?otype=modify&id=' + id, title: '修改分类', height: 200, width: 380, isResize: true
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要修改的分类，请选择');
                    }
                }
            });
            $("#pageloading").hide();
        }
        function LoadQuestionList() {
            var selecttype = document.getElementById("dropQuestionType").value;
            var key=escape(document.getElementById("txtKeywords").value);
            questionlist=$("#divQuestionList").ligerGrid({
                height: '97%',
                columns: [
                { display: '试题分类', width: '120', name: '_f_categoryname' },
                { display: '试题类型', width: '80', name: '_f_type', render: function (rowdata, rowindex, value) {
                    if (value == "1")
                        return "<img src='../images/help_question_mark_24.png' style='width:18px' />&nbsp;&nbsp;<font color='red'>问答题</font>";
                    else if(value == "2")
                        return "<img src='../images/radio_button_off_16.png' style='width:16px' />&nbsp;&nbsp;<font color='green'>单选题</font>";
                    else if (value == "3")
                        return "<img src='../images/check_box_24.png' style='width:18px' />&nbsp;&nbsp;<font color='blue'>多选题</font>";
                    else
                        return "";
                }
                },
                { display: '试题标题', align: 'left', width: '350', name: '_f_title' },
                { display: '试题内容', align:'left', width: '550', name: '_f_content' }
                ],
                toolbar: {
                    items: [
                    { text: '增加', click: itemclick2, icon: 'add' },
                    { line: true },
                    { text: '修改', click: itemclick2, icon: 'modify' },
                    { line: true },
                    { text: '删除', click: itemclick2, icon: 'delete' },
                    { line: true },
                    { text: '所有试题', click: itemclick2, icon: 'attibutes' }
                    ]
                },
                url: 'ajax/question.ashx?action=getlist&categoryid=' + selectcategoryid + '&selecttype=' + selecttype+'&key='+key, pageSize: 50, pageSizeOptions: [10, 20, 50], rownumbers: true,
                onSelectRow: function (data, rowindex, rowobj) {
                },
                onDblClickRow: function (data, rowindex, rowobj) {
                    var vheight = $("#form1").height() - 30;
                    var vwidth = $("#form1").width() * 0.9;
                    if (vwidth > 700) {
                        vwidth = 700;
                    }
                    var id = "";
                    var vtitle = "修改试题";
                    try {
                        id = data._f_questionid;
                        vtitle = "【<font color='red'>" + data._f_title + "</font>】修改试题";
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        var selecttype = document.getElementById("dropQuestionType").value;
                        $.ligerDialog.open({ url: 'questionedit.aspx?otype=modify&id=' + id, title: vtitle, height: vheight, width: vwidth, isResize: true
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要修改的试题，请选择');
                    }
                }
            });
            $("#pageloading").hide();
        }
        function itemclick1(item) {
            switch (item.icon) {
                case "add":
                    $.ligerDialog.open({ url: 'questioncategoryedit.aspx?otype=new', title: '添加分类', height: 200, width: 380, isResize: true
                    });
                    break;
                case "modify":
                    var id = "";
                    try {
                        var rowobj = categorylist.getSelectedRow();
                        id = rowobj._f_categoryid;
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        $.ligerDialog.open({ url: 'questioncategoryedit.aspx?otype=modify&id=' + id, title: '修改分类', height: 200, width: 380, isResize: true
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要修改的分类，请选择');
                    }
                    break;
                case "delete":
                    var id = "";
                    var rowobj;
                    try {
                        rowobj = categorylist.getSelectedRow();
                        id = rowobj._f_categoryid;
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        $.ligerDialog.confirm('确定要删除【<font color="red">' + rowobj._f_categoryname + '</font>】吗？', function (yes) {
                            if (yes) {
                                $.post("ajax/questioncategory.ashx?action=delete&id=" + id, function (data) {
                                    if (data == "success") {
                                        $.ligerDialog.success('删除成功');
                                        LoadCategoryList();
                                    }
                                    else if (data == "error") {
                                        $.ligerDialog.error('删除失败');
                                    }
                                    else {
                                        $.ligerDialog.error('删除失败，此分类下有【<font color="red">' + data + '</font>】个关联试题，无法删除');
                                    }
                                });
                            }
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要删除的分类，请选择');
                    }
                    break;
            }
        }
        function itemclick2(item) {
            switch (item.icon) {
                case "add":
                    var vheight = $("#form1").height() - 30;
                    var vwidth = $("#form1").width() * 0.9;
                    if (vwidth > 700) {
                        vwidth = 700;
                    }
                    var id = "";
                    var vtitle = "添加试题";
                    var rowobj;
                    try {
                        rowobj = categorylist.getSelectedRow();
                        id = rowobj._f_categoryid;
                        vtitle = "【<font color='red'>" + rowobj._f_categoryname + "</font>】分类下添加试题";
                    }
                    catch (e) {
                    }
                    var selecttype = document.getElementById("dropQuestionType").value;
                    $.ligerDialog.open({ url: 'questionedit.aspx?otype=new&categoryid=' + id + '&selecttype=' + selecttype, title: vtitle, height: vheight, width: vwidth, isResize: true
                    });
                    break;
                case "modify":
                    var vheight = $("#form1").height() - 30;
                    var vwidth = $("#form1").width() * 0.9;
                    if (vwidth > 700) {
                        vwidth = 700;
                    }
                    var id = "";
                    var vtitle = "修改试题";
                    var rowobj;
                    try {
                        rowobj = questionlist.getSelectedRow();
                        id = rowobj._f_questionid;
                        vtitle = "【<font color='red'>" + rowobj._f_title + "</font>】修改试题";
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        var selecttype = document.getElementById("dropQuestionType").value;
                        $.ligerDialog.open({ url: 'questionedit.aspx?otype=modify&id=' + id, title: vtitle, height: vheight, width: vwidth, isResize: true
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要修改的试题，请选择');
                    }
                    break;
                case "delete":
                    var id = "";
                    var rowobj;
                    try {
                        rowobj = questionlist.getSelectedRow();
                        id = rowobj._f_questionid;
                    }
                    catch (e) {
                    }
                    if (id != "") {
                        $.ligerDialog.confirm('确定要删除【<font color="red">' + rowobj._f_title + '</font>】试题吗？', function (yes) {
                            if (yes) {
                                $.post("ajax/question.ashx?action=delete&id=" + id, function (data) {
                                    if (data == "success") {
                                        $.ligerDialog.success('删除成功');
                                        LoadQuestionList();
                                    }
                                    else{
                                        $.ligerDialog.error('删除失败');
                                    }
                                });
                            }
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要删除的试题，请选择');
                    }
                    break;
                case "attibutes":
                    selectcategoryid = "";
                    LoadQuestionList();
                    break;
            }
        }
        $(function () {
            //var vheight = $("#form1").height();
            //document.getElementById("tableMessage").style.height = vheight - 80;
            LoadCategoryList();
            LoadQuestionList();
        });
        document.onkeydown = function (event) {
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 13) {
                LoadQuestionList();
            }
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="tools_box">
        <asp:HiddenField ID="hdF_FunctionId" runat="server" />
        <asp:HiddenField ID="hdF_ModuleId" runat="server" />
        <div class="tools_bar">
            <div class="search_box">
                题型：<asp:DropDownList ID="dropQuestionType" runat="server" onchange="LoadQuestionList();" CssClass="selectBox" Width="120px">
                    <asp:ListItem Value="" Text="所有题型"></asp:ListItem>
                    <asp:ListItem Value="1" Text="问答题"></asp:ListItem>
                    <asp:ListItem Value="2" Text="单选题"></asp:ListItem>
                    <asp:ListItem Value="3" Text="多选题"></asp:ListItem>
                </asp:DropDownList>
                &nbsp;&nbsp;关键字：<asp:TextBox ID="txtKeywords" runat="server" CssClass="txtInput"></asp:TextBox>&nbsp;&nbsp;
                <input id="btnSearch" type="button" value="搜 索" class="btnSearch" onclick="LoadQuestionList();" />
            </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>
                <div id="divCategoryList">
                </div>
            </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/icon_attach.png" />&nbsp;试题列表</div>
                    </div>
                </div>
                <div id="divQuestionList">
                </div>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
