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

<!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.8.3.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>
    <script src="/scripts/ui/js/plugins/ligerTextBox.js" type="text/javascript"></script>
    <script src="/scripts/ui/js/plugins/ligerSpinner.js" type="text/javascript"></script>
    <script src="/scripts/function.js" type="text/javascript"></script>
    <script src="/scripts/utils.js" type="text/javascript"></script>
    <script src="/scripts/ui/js/plugins/ligerDateEditor.js" type="text/javascript"></script>
    <link href="/scripts/ui/skins/Tab/css/grid.css" rel="stylesheet" type="text/css" />
    <link href="/images/style.css" rel="stylesheet" type="text/css" />
    <link href="/scripts/ui/skins/Tab/css/grid.css" rel="stylesheet" type="text/css" />
    <link href="/scripts/ui/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .l-toolbar
        {
            background: none;
            height: 23px;
            border: 0px solid #9CBAE7;
            border-top: 0px solid #EFF7F7;
        }
        .tools_box
        {
            border: 1px solid #D6D6D6;
            border-bottom: 0px;
        }
    </style>
    <script type="text/javascript">
        var sort = 0;
        var itemcount = 0;
        var questionlist;
        var selectlist;
        function CloseThis() {
            parent.SaveRes();
        }
        function ResetWidth() {
            try {
                var fwidth = $("#form1").width() * 0.5;
                document.getElementById("divQuestionList").style.width = fwidth;
                document.getElementById("divSelectList").style.width = fwidth-20;
                questionlist.reload();
                selectlist.reload();
                //LoadQuestionList();
                //LoadSelectList();
                //questionlist.setWidth(fwidth);
                //selectlist.setWidth(fwidth);
                //questionlist.setColumnWidth('_f_title', 80);
            }
            catch (e)
            { }
        }
        $(function () {
            var a = $("#navtab1").ligerTab({
                showSwitch: false,
                contextmenu: false,
                onAfterSelectTabItem: function (targettabid) {
                }
            });
            LoadQuestionList();
            LoadSelectList();
            $("#pageloading_bg,#pageloading").hide();
        });
        function LoadQuestionList() {
            var fwidth = $("#form1").width() * 0.5;
            var selectcategoryid = document.getElementById("dropQuestionCategory").value;
            var selecttype = document.getElementById("dropQuestionType").value;
            var key = escape(document.getElementById("txtKeywords").value);
            var id = document.getElementById("txtId").value;
            var userid = document.getElementById("txtUserId").value;
            questionlist = $("#divQuestionList").ligerGrid({
                height: 236,
                width: fwidth,
                checkbox: true,
                columns: [
                { display: '操作', width: '35', frozen: true, name: '_f_questionid', render: function (rowdata, rowindex, value) {
                    return "<img src='../scripts/ui/skins/icons/right.png' onclick='SelectInItem(\"" + rowdata._f_questionid + "\");' style='width:20px;cursor:hand;' title='选入' />";
                }
                },
                { display: '试题标题', align: 'left', width: '150', frozen: true, name: '_f_title' },
                { 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: '试题分类', width: '120', name: '_f_categoryname' },
                { 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: 'rightall' }
                    ]
                },
                url: 'ajax/question.ashx?action=getlistbypager&pagerid=' + id + '&userid=' + userid + '&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 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 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 "help":

                    break;
                case "rightall":
                    SelectAllInItem();
                    break;
                case "leftall":
                    SelectAllOutItem();
                    break;
            }
        }
        function LoadSelectList() {
//            var selectcategoryid = document.getElementById("dropQuestionCategory").value;
//            var selecttype = document.getElementById("dropQuestionType").value;
//            var key = escape(document.getElementById("txtKeywords").value);
//            var arrid = document.getElementById("txtArrid").value;
            var id = document.getElementById("txtId").value;
            var userid = document.getElementById("txtUserId").value;
            var fwidth = $("#form1").width() * 0.5-20;
            selectlist = $("#divSelectList").ligerGrid({
                height: 236,
                width: fwidth,
                checkbox: true,
                columns: [
                { display: '操作', width: '35', frozen: true, name: '_f_questionid', render: function (rowdata, rowindex, value) {
                    return "<img src='../scripts/ui/skins/icons/left.png' onclick='SelectOutItem(\"" + rowdata._f_itemid + "\");' style='width:20px;cursor:hand;' title='移除' />";
                }
                },
                { display: '排序', width: '50', align: 'left', frozen: true, name: '_f_sort', render: function (rowdata, rowindex, value) {
                    if (value > sort) {
                        sort = value;
                    }
                    if (rowindex == 0)
                        return "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img id='xy_" + rowindex + "' onclick='MoveItem(\"" + rowdata._f_itemid + "\",\"" + value + "\",\"1\");' src='../images/icon_desc.gif' title='下移' style='width:12px; cursor:hand;' />";
                    else
                        return "&nbsp;<img id='sy_" + rowindex + "' onclick='MoveItem(\"" + rowdata._f_itemid + "\",\"" + value + "\",\"-1\");' src='../images/icon_asc.gif' title='上移' style='width:12px; cursor:hand;' />&nbsp;&nbsp;<img id='xy_" + rowindex + "' onclick='MoveItem(\"" + rowdata._f_itemid + "\",\"" + value + "\",\"1\");' src='../images/icon_desc.gif' title='下移' style='width:12px; cursor:hand;' />";
                }
                },
                { display: '试题标题', align: 'left', frozen: true, width: '150', name: '_f_title' },
                { 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: '试题分类', width: '120', name: '_f_categoryname' },
                { display: '试题内容', align: 'left', width: '550', name: '_f_content' }
                ],
                toolbar: {
                    items: [
                    { text: '选出', click: itemclick2, icon: 'leftall' },
                    { line: true },
                    { text: '<span id="spanAllSelect" style="color:red">共有0个问题</span>', click: itemclick2, icon: 'help' }
                    ]
                },
                url: 'ajax/question.ashx?action=getselectlist&pagerid=' + id + '&userid=' + userid, pageSize: 100, pageSizeOptions: [10, 20, 50, 100], rownumbers: true,
                onSelectRow: function (data, rowindex, rowobj) {
                },
                onAfterShowData: function (data) {
                    itemcount = data.Total;
                    try {
                        document.getElementById("spanAllSelect").innerHTML = "共有" + itemcount + "个问题";
                        document.getElementById("txtQuestionCount").value = itemcount;
                    }
                    catch (e) {
                    }
                    var imgindex = itemcount - 1;
                    try {
                        var imgid = "xy_" + imgindex;
                        document.getElementById("xy_" + imgindex).style.display = "none";
                    }
                    catch (e) {
                    }
                }
            });
            $("#pageloading").hide();
        }
        function SelectInItem(questionid) {
            var id = document.getElementById("txtId").value;
            var userid = document.getElementById("txtUserId").value;
            var timeno = new Date().getTime();
            var optaction = "addtemp";
            if (id != "") {
                optaction = "add";
            }
            try {
                $.ajax({
                    type: "get",
                    url: "ajax/pageritems.ashx?action=" + optaction + "&id=" + id + "&questionid=" + questionid + "&userid=" + userid + "&sort=" + sort + "&timeno=" + timeno,
                    dataType: "html",
                    success: function (res) {
                        if (res == "success") {
                            LoadQuestionList();
                            LoadSelectList();
                        } else {
                            $.ligerDialog.error("选入失败");
                        }
                    }
                });
            }
            catch (e) {
            }
        }
        function SelectOutItem(itemid) {
            var id = document.getElementById("txtId").value;
            var userid = document.getElementById("txtUserId").value;
            var timeno = new Date().getTime();
            var optaction = "deletetemp";
            if (id != "") {
                optaction = "delete";
            }
            try {
                $.ajax({
                    type: "get",
                    url: "ajax/pageritems.ashx?action=" + optaction + "&id=" + id + "&itemid=" + itemid + "&userid=" + userid + "&sort=" + sort + "&timeno=" + timeno,
                    dataType: "html",
                    success: function (res) {
                        if (res == "success") {
                            LoadQuestionList();
                            LoadSelectList();
                        } else {
                            $.ligerDialog.error("选出失败");
                        }
                    }
                });
            }
            catch (e) {
            }
        }
        function SelectAllInItem() {
            var id = document.getElementById("txtId").value;
            var userid = document.getElementById("txtUserId").value;
            var timeno = new Date().getTime();
            var optaction = "addalltemp";
            if (id != "") {
                optaction = "addall";
            }
            try {
                var rows = questionlist.getSelectedRows();
                if (rows.length > 0) {
                    var arr = new Array();
                    var i = 0;
                    for (var i = 0; i < rows.length; i++) {
                        arr[i] = rows[i]._f_questionid;
                    }
                    $.ajax({
                        type: "get",
                        url: "ajax/pageritems.ashx?action=" + optaction + "&id=" + id + "&arrid=" + arr.toString() + "&userid=" + userid + "&sort=" + sort + "&timeno=" + timeno,
                        dataType: "html",
                        success: function (res) {
                            if (res == "success") {
                                LoadQuestionList();
                                LoadSelectList();
                            } else {
                                $.ligerDialog.error("选入失败");
                            }
                        }
                    });
                }
                else {
                    $.ligerDialog.error('没有选择要选入的试题');
                }
            }
            catch (e) {
            }
        }
        function SelectAllOutItem() {
            var id = document.getElementById("txtId").value;
            var userid = document.getElementById("txtUserId").value;
            var timeno = new Date().getTime();
            var optaction = "deletealltemp";
            if (id != "") {
                optaction = "deleteall";
            }
            try {
                var rows = selectlist.getSelectedRows();
                if (rows.length > 0) {
                    var arr = new Array();
                    var i = 0;
                    for (var i = 0; i < rows.length; i++) {
                        arr[i] = rows[i]._f_itemid;
                    }
                    $.ajax({
                        type: "get",
                        url: "ajax/pageritems.ashx?action=" + optaction + "&id=" + id + "&arrid=" + arr.toString() + "&userid=" + userid + "&sort=" + sort + "&timeno=" + timeno,
                        dataType: "html",
                        success: function (res) {
                            if (res == "success") {
                                LoadQuestionList();
                                LoadSelectList();
                            } else {
                                $.ligerDialog.error("选出失败");
                            }
                        }
                    });
                }
                else {
                    $.ligerDialog.error('没有选择要选出的试题');
                }
            }
            catch (e) {
            }
        }
        function MoveItem(itemid, ssort, type) {
            var id = document.getElementById("txtId").value;
            var timeno = new Date().getTime();
            var optaction = "movetemp";
            if (id != "") {
                optaction = "move";
            }
            try {
                $.ajax({
                    type: "get",
                    url: "ajax/pageritems.ashx?action=" + optaction + "&pagerid=" + id + "&itemid=" + itemid + "&sort=" + ssort + "&movetype=" + type + "&timeno=" + timeno,
                    dataType: "html",
                    success: function (res) {
                        if (res == "success") {
                            LoadSelectList();
                        } else {
                            $.ligerDialog.error("移动排序失败");
                        }
                    }
                });
            }
            catch (e) {
            }
        }
        function ShowPagerView() {
            var id = document.getElementById("txtId").value;
            parent.ShowPager(id);
        }
        function validate() {
            var i = 0;
            if (!validate2()) {
                i++;
            }

            if (i > 0) {
                return false;
            }
            return true;
        }
        function validate2() {
            if ($("#txtF_Title").val() == "" || $("#txtF_Title").val() == undefined) {
                document.getElementById("lbF_Title").innerHTML = "* 名称不能为空！";
                document.getElementById("lbF_Title").style.color = "red";
                return false;
            }
            else {
                document.getElementById("lbF_Title").innerHTML = "*";
                document.getElementById("lbF_Title").style.color = "#414141";
                return true;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:HiddenField ID="hidF_CategoryId" runat="server" Value="" />
    <asp:HiddenField ID="txtUserId" runat="server" Value="0" />
    <asp:HiddenField ID="txtId" runat="server" Value="" />
    <asp:HiddenField ID="txtArrid" runat="server" Value="" />
    <asp:HiddenField ID="txtQuestionCount" runat="server" Value="0" />
    <div id="pageloading">
        数据加载中，请稍等...
    </div>
    <table class="form_table" style="width: 100%; height: 100%;">
        <colgroup>
            <col width="100" />
            <col />
        </colgroup>
        <tr style="height: 25px;">
            <th style="height: 25px; padding: 0px 8px 0px 0px;">
                问卷名称：
            </th>
            <td style="height: 25px; padding: 2px 0px 0px 8px;">
                <textarea id="txtF_Title" cols="20" rows="4" runat="server" class="txtInput normal"
                    style="width: 380px; height: 30px;"></textarea><label id="lbF_Title" for="txtF_Title"></label>
            </td>
        </tr>
        <tr style="height: 25px;">
            <th style="height: 25px; padding: 0px 8px 0px 0px;">
                问卷说明：
            </th>
            <td style="height: 25px; padding: 5px 0px 5px 8px;">
                <textarea id="txtF_Remark" cols="20" rows="4" runat="server" class="txtInput normal"
                    style="width: 380px; height: 50px;"></textarea>
            </td>
        </tr>
    </table>
    <div id="trSelect" style="width: 99%; text-align: center;">
        <div id="navtab1" style="width: 100%; height: 300px; border: 1px solid #D3D3d3;">
            <div title="选择试题" tabid="tab1">
                <table id="tableMessage" cellpadding="3" cellspacing="3" border="0" style="width: 100%;">
                    <tr>
                        <td style="height: 30px; padding-left: 10px;" colspan="2" align="left">
                            分类：<asp:DropDownList ID="dropQuestionCategory" runat="server" onchange="LoadQuestionList();" CssClass="selectBox"
                                Width="100px">
                            </asp:DropDownList>
                            &nbsp;&nbsp;题型：<asp:DropDownList ID="dropQuestionType" runat="server" onchange="LoadQuestionList();"
                                CssClass="selectBox" Width="60px">
                                <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" Style="width: 100px;"
                                CssClass="txtInput"></asp:TextBox>&nbsp;
                            <input id="btnSearch" type="button" value="搜 索" class="btnSearch" onclick="LoadQuestionList();" />
                        </td>
                    </tr>
                    <tr>
                        <td id="tdLeft" valign="top" style="width:50%; padding: 0px 2px 5px 2px;">
                            <div id="divQuestionList">
                            </div>
                        </td>
                        <td valign="top" style="width:50%;padding: 0px 2px 5px 2px;">
                            <div id="divSelectList">
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    <br />
    <div style="width: 100%; text-align: center;">
        <input id="Button1" type="button" value="预览试卷" class="btnSubmit" style="color:green;" onclick="ShowPagerView();" />&nbsp;&nbsp;&nbsp;<asp:Button ID="btnSubmit" runat="server" Text="生成试卷" CssClass="btnSubmit"
            OnClientClick="return validate();" OnClick="btnSubmit_Click" /></div>
    <br />
    </form>
</body>
</html>
