<%@ Page Language="C#" AutoEventWireup="true" CodeFile="answer_manage.aspx.cs" Inherits="SYSadmin_Products_answer" %>

<!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>
    <title>答题管理系统</title>
    <link href="../../SYSadmin/css/style.css" rel="stylesheet" type="text/css" />
    <link href="../../SYSadmin/css/neiye.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">
    function $(obj){
        var element = null;
        if(document.getElementById){
            element = document.getElementById(obj);
        }else if(document.all){
            element = document.all[obj];
        }
        return element;
    } 
    function selectall(sForm, sName, sObj, sObjName) {
        for (var i = 0; i < sForm.elements.length; i++) {
            var e = sForm.elements[i];
            if ( e.name == sName && e.type == 'checkbox') {
	            e.checked = sObj.checked;
            }
        }
        if(sObj.checked) {
            $(sObjName).innerHTML = "取消全选";
        } else {
            $(sObjName).innerHTML = "全选";
        }
    }
    function submitForm(sForm, sAction, sName) {
        var j = 0;
        for (var i = 0; i < sForm.elements.length; i++) {
            var e = sForm.elements[i];
            if ( e.name == sName && e.type == 'checkbox' && e.checked) {
                j = j + 1;
            }
        }
        if(j > 0) {
            if(confirm('你确认要删除所选择的项目吗?'))
            {
                sForm.action=sAction;
                sForm.submit();
            }else{
                return false;
            }
        }else{
            alert("请至少选择一项你需要删除的项目!");
            return false;
        }
    }
    function postBack(sUrl) {
        return document.location.href=sUrl;
    }
    </script>

</head>
<body>
    <div class="tright">
        <span class="float: left">
            <li>
                <asp:HyperLink ID="showtest" runat="server" NavigateUrl="?action=showtest">查看试题</asp:HyperLink></li>
        </span><span style="float: right; font-size: 12px; font-weight: normal;">
            <asp:Label ID="pagebarinfo" runat="server" Text="显示记录总数"></asp:Label>
        </span>
    </div>
    <form id="showlistForm" runat="server">
        <asp:Panel ID="testlistPanel" runat="server" Width="100%">
            <div align="center" style="padding-top: 10px;">
                <asp:GridView ID="GridView_Test" runat="server" AllowPaging="True" HorizontalAlign="Center"
                    PageSize="15" Width="98%" AutoGenerateColumns="False" OnPageIndexChanging="GridView_Test_PageIndexChanging"
                    OnRowDataBound="GridView_Test_RowDataBound">
                    <HeaderStyle CssClass="tright" />
                    <PagerSettings FirstPageText="[首页]" LastPageText="[尾页]" Mode="NextPreviousFirstLast"
                        NextPageText="[下一页]" PageButtonCount="15" PreviousPageText="[上一页]" />
                    <Columns>
                        <asp:TemplateField HeaderText="选择">
                            <HeaderStyle HorizontalAlign="Center" />
                            <ItemTemplate>
                                <input type="checkbox" name="id" value="<%# Eval("A_ID") %>" />
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" Width="50px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="试题名称">
                            <HeaderStyle HorizontalAlign="Center" />
                            <ItemTemplate>
                                <a href="?action=showsubject&sid=<%# Eval("A_ID") %>">
                                    <%# new Cls_Operation().Cutstring(Convert.ToString(Eval("A_Name")), 50)%>
                                </a>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Left" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="题目总数">
                            <HeaderStyle HorizontalAlign="Center" />
                            <ItemTemplate>
                                <%# GetSubjectCount(Convert.ToString(Eval("A_ID"))) %>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" Width="80px" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="A_Hit" HeaderText="测试次数">
                            <ItemStyle HorizontalAlign="Center" Width="80px" />
                        </asp:BoundField>
                        <asp:HyperLinkField DataNavigateUrlFields="A_ID" DataNavigateUrlFormatString="?action=edittest&amp;id={0}"
                            HeaderText="编辑" Text="[编辑]">
                            <ItemStyle HorizontalAlign="Center" Width="50px" />
                        </asp:HyperLinkField>
                        <asp:HyperLinkField DataNavigateUrlFields="A_ID" DataNavigateUrlFormatString="?action=del_test&amp;id={0}"
                            HeaderText="删除" Text="[删除]">
                            <ItemStyle HorizontalAlign="Center" Width="50px" />
                        </asp:HyperLinkField>
                    </Columns>
                    <PagerStyle HorizontalAlign="Right" />
                </asp:GridView>
                <asp:Panel ID="testinfoPanel" runat="server" Width="98%" Height="30px" HorizontalAlign="Left">
                    <div style="padding-top: 5px;">
                        <span style="float: left">&nbsp;&nbsp;&nbsp;
                            <input type="checkbox" name="selectalltest" onclick="selectall(document.showlistForm, 'id', document.showlistForm.selectalltest, 'selectalltestlabel');" />
                            <font id="selectalltestlabel">全选</font>&nbsp; </span><span style="float: right"><a
                                onclick="return submitForm(document.showlistForm, '?action=del_seltest', 'id');"
                                class="btn" href="#" style="display: inline-block; width: 65px;">删除选择</a> <a href="?action=addtest"
                                    class="btn" style="display: inline-block; width: 65px;">添加试题</a></span>
                    </div>
                </asp:Panel>
                <asp:Panel ID="notestPanel" runat="server" Width="98%" HorizontalAlign="center" Visible="False">
                    <br />
                    <asp:Label ID="notestinfo" runat="server" BackColor="Transparent" Font-Bold="True"
                        ForeColor="Red" Text="暂无试题记录!"></asp:Label>
                    <br />
                    <br />
                    <a href="?action=addtest" class="btn" style="display: inline-block; width: 65px;">添加试题</a>
                </asp:Panel>
            </div>
        </asp:Panel>
        <asp:Panel ID="addtestPanel" runat="server" Width="100%">

            <script type="text/javascript">
            function checkaddTest() {
                var sForm = document.forms['showlistForm'];
                if (!sForm) {
                    sForm = document.showlistForm;
                }
                if(sForm.A_Name.value!="") {
                    if(sForm.A_ID.value=="") {
                        sForm.action="?action=add_test";
                    }else{
                        sForm.action="?action=update_test";
                    }
                    sForm.submit();
                }else{
                    alert("请把试题名称与试题答案填写完善!");
                    sForm.A_Name.focus();
                }
            }
            </script>

            <table cellspacing="0" align="Center" rules="all" border="1" style="width: 98%; border-collapse: collapse;
                margin-top: 10px;">
                <tr class="tright">
                    <th align="center" valign="middle" scope="col" colspan="2" style="height: 25px">
                        <asp:Label ID="testtitle" runat="server" Text="添加新试题"></asp:Label></th>
                </tr>
                <tr>
                    <td style="text-align: right; width: 120px;">
                        试题名称：</td>
                    <td>
                        <asp:HiddenField ID="A_ID" runat="server" />
                        <asp:TextBox ID="A_Name" runat="server" Width="360px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="text-align: right; vertical-align: top; width: 120px;">
                        试题答案：</td>
                    <td style="color: dimgray">
                        <asp:TextBox ID="A_Answer" runat="server" Width="500px" Height="120px" TextMode="MultiLine">答案|描述@@@答案|答案</asp:TextBox>&nbsp;
                        <br />
                        (注意:请把答案与描述之间用"|"分开,答案与答案之间用"@@@"分开)</td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align: center; height: 25px;">
                        <a href="#" onclick="checkaddTest();" class="btn" style="display: inline-block; width: 65px;">
                            保存</a>&nbsp; <a href="?action=showtest" class="btn" style="display: inline-block;
                                width: 65px;">取消</a></td>
                </tr>
            </table>
        </asp:Panel>
        <asp:Panel ID="subjectlistPanel" runat="server" Width="100%">
            <asp:HiddenField ID="S_ClassID" runat="server" />
            <div align="center" style="padding-top: 10px;">
                <asp:GridView ID="GridView_Subject" runat="server" AllowPaging="True" HorizontalAlign="Center"
                    PageSize="15" Width="98%" AutoGenerateColumns="False" OnPageIndexChanging="GridView_Subject_PageIndexChanging"
                    OnRowDataBound="GridView_Subject_RowDataBound">
                    <HeaderStyle CssClass="tright" />
                    <PagerSettings FirstPageText="[首页]" LastPageText="[尾页]" Mode="NextPreviousFirstLast"
                        NextPageText="[下一页]" PageButtonCount="15" PreviousPageText="[上一页]" />
                    <Columns>
                        <asp:TemplateField HeaderText="选择">
                            <HeaderStyle HorizontalAlign="Center" />
                            <ItemTemplate>
                                <input type="checkbox" name="id" value="<%# Eval("S_ID") %>" />
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" Width="50px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="题目名称">
                            <HeaderStyle HorizontalAlign="Center" />
                            <ItemTemplate>
                                <%# new Cls_Operation().Cutstring(Convert.ToString(Eval("S_Description")), 50)%>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Left" />
                        </asp:TemplateField>
                        <asp:HyperLinkField DataNavigateUrlFields="S_ID,S_Class" DataNavigateUrlFormatString="?action=editsubject&amp;sid={1}&amp;id={0}"
                            HeaderText="编辑" Text="[编辑]">
                            <ItemStyle HorizontalAlign="Center" Width="50px" />
                        </asp:HyperLinkField>
                        <asp:HyperLinkField DataNavigateUrlFields="S_ID,S_Class" DataNavigateUrlFormatString="?action=del_subject&amp;sid={1}&amp;id={0}"
                            HeaderText="删除" Text="[删除]">
                            <ItemStyle HorizontalAlign="Center" Width="50px" />
                        </asp:HyperLinkField>
                    </Columns>
                    <PagerStyle HorizontalAlign="Right" />
                </asp:GridView>
                <asp:Panel ID="subjectinfoPanel" runat="server" Width="98%" HorizontalAlign="Left"
                    Height="30px">
                    <div style="padding-top: 5px;">
                        <span style="float: left">&nbsp; &nbsp;
                            <input type="checkbox" name="selectallsubject" id="selectallsubject" onclick="selectall(document.showlistForm, 'id', document.showlistForm.selectallsubject, 'selectallsubjectlabel');" />
                            <font id="selectallsubjectlabel">全选</font>&nbsp; </span><span style="float: right"><a
                                onclick="return submitForm(document.showlistForm, '?action=del_selsubject&sid='+document.showlistForm.S_ClassID.value, 'id');"
                                class="btn" href="#" style="display: inline-block; width: 65px;">删除选择</a> <a class="btn"
                                    href="javascript:postBack('?action=addsubject&sid='+this.showlistForm.S_ClassID.value);"
                                    style="display: inline-block; width: 65px;">添加题目</a>&nbsp;</span></div>
                </asp:Panel>
                <asp:Panel ID="nosubjectPanel" runat="server" Width="98%" HorizontalAlign="center"
                    Visible="false">
                    <br />
                    <asp:Label ID="nosubjectinfo" runat="server" BackColor="Transparent" Font-Bold="True"
                        ForeColor="Red" Text="此试题暂无题目!"></asp:Label>
                    <br />
                    <br />
                    <a class="btn" href="javascript:postBack('?action=addsubject&sid='+this.showlistForm.S_ClassID.value);"
                        style="display: inline-block; width: 65px;">添加题目</a></asp:Panel>
            </div>
        </asp:Panel>
        <asp:Panel ID="addsubjectPanel" runat="server" Width="100%">

            <script type="text/javascript">
            function checkaddSubject() {
                var sForm = document.forms['showlistForm'];
                if (!sForm) {
                    sForm = document.showlistForm;
                }
                var o = 0;
                var s = 0;
                for (var i = 0; i < sForm.elements.length; i++) {
                    var e = sForm.elements[i];
                    if (e.name.indexOf('S_Option') != -1 && e.type == 'text' && e.value != '') {
                        o = o + 1;
                    }
                    if (e.name.indexOf('S_Score') != -1 && e.type == 'text' && e.value != '') {
                        s = s + 1;
                    }
                }
                if(sForm.S_Description.value!="" && sForm.S_Option1.value!="" && sForm.S_Option2.value!="") {
                    if( s != 0 && s != o ) {
                        alert("请对应填写好选项内容与分数,分数可为空!");
                    }else{
                        if(sForm.S_ID.value=="") {
                            sForm.action="?action=add_subject&sid="+sForm.S_Class.value;
                        }else{
                            sForm.action="?action=update_subject&sid="+sForm.S_Class.value;
                        }
                        sForm.submit();
                    }
                }else{
                    alert("请至少填写题目内容与两个选项!");
                    sForm.S_Description.focus();
                }
            }
            </script>

            <table cellspacing="0" align="Center" rules="all" border="1" style="width: 98%; border-collapse: collapse;
                margin-top: 10px;">
                <tr class="tright">
                    <th align="center" valign="middle" scope="col" colspan="4" style="height: 25px">
                        <asp:Label ID="subjecttitle" runat="server" Text="添加题目"></asp:Label></th>
                </tr>
                <tr>
                    <td style="text-align: right; width: 180px;">
                        题目内容：</td>
                    <td colspan="3">
                        <asp:HiddenField ID="S_ID" runat="server" />
                        <asp:HiddenField ID="S_Class" runat="server" />
                        <asp:TextBox ID="S_Description" runat="server" Width="366px" Height="50px" TextMode="MultiLine"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="text-align: right; width: 180px;">
                        选项1：</td>
                    <td style="text-align: left;">
                        <asp:TextBox ID="S_Option1" runat="server" Width="200px"></asp:TextBox>
                        &nbsp; 分数：
                        <asp:TextBox ID="S_Score1" runat="server" Width="100px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="text-align: right; width: 180px;">
                        选项2：</td>
                    <td style="text-align: left;">
                        <asp:TextBox ID="S_Option2" runat="server" Width="200px"></asp:TextBox>
                        &nbsp; 分数：
                        <asp:TextBox ID="S_Score2" runat="server" Width="100px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="text-align: right; height: 30px; width: 180px;">
                        选项3：</td>
                    <td style="text-align: left; height: 30px;">
                        <asp:TextBox ID="S_Option3" runat="server" Width="200px"></asp:TextBox>
                        &nbsp; 分数：
                        <asp:TextBox ID="S_Score3" runat="server" Width="100px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="text-align: right; width: 180px;">
                        选项4：</td>
                    <td style="text-align: left;">
                        <asp:TextBox ID="S_Option4" runat="server" Width="200px"></asp:TextBox>
                        &nbsp; 分数：
                        <asp:TextBox ID="S_Score4" runat="server" Width="100px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="text-align: right; width: 180px;">
                        选项5：</td>
                    <td style="text-align: left;">
                        <asp:TextBox ID="S_Option5" runat="server" Width="200px"></asp:TextBox>
                        &nbsp; 分数：
                        <asp:TextBox ID="S_Score5" runat="server" Width="100px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="text-align: right; height: 30px; width: 180px;">
                        选项6：</td>
                    <td style="text-align: left; height: 30px;">
                        <asp:TextBox ID="S_Option6" runat="server" Width="200px"></asp:TextBox>
                        &nbsp; 分数：
                        <asp:TextBox ID="S_Score6" runat="server" Width="100px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="text-align: right; width: 180px;">
                        选项7：</td>
                    <td style="text-align: left;">
                        <asp:TextBox ID="S_Option7" runat="server" Width="200px"></asp:TextBox>
                        &nbsp; 分数：
                        <asp:TextBox ID="S_Score7" runat="server" Width="100px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="text-align: right; width: 180px;">
                        选项8：</td>
                    <td style="text-align: left;">
                        <asp:TextBox ID="S_Option8" runat="server" Width="200px"></asp:TextBox>
                        &nbsp; 分数：
                        <asp:TextBox ID="S_Score8" runat="server" Width="100px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="text-align: right; width: 180px;">
                        选项9：</td>
                    <td style="text-align: left;">
                        <asp:TextBox ID="S_Option9" runat="server" Width="200px"></asp:TextBox>
                        &nbsp; 分数：
                        <asp:TextBox ID="S_Score9" runat="server" Width="100px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="text-align: right; width: 180px;">
                        选项10：</td>
                    <td style="text-align: left;">
                        <asp:TextBox ID="S_Option10" runat="server" Width="200px"></asp:TextBox>
                        &nbsp; 分数：
                        <asp:TextBox ID="S_Score10" runat="server" Width="100px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td colspan="4" style="text-align: center; height: 25px;">
                        <a href="javascript:checkaddSubject();" class="btn" style="display: inline-block;
                            width: 65px;">保存</a>&nbsp; <a href="javascript:postBack('?action=showsubject&sid='+this.showlistForm.S_Class.value);"
                                class="btn" style="display: inline-block; width: 65px;">取消</a></td>
                </tr>
            </table>
        </asp:Panel>
    </form>
</body>
</html>
