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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>题目拆分</title>
    <link href="../css/default.css" rel="stylesheet" />
    <script src="../js/jquery-1.10.2.min.js"></script>
    <script src="../js/jquery.cookie.js"></script>
    <link href="../css/SplitQuestion.css" rel="stylesheet" />
    
     <%-- 禁用浏览器缓存 --%>
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Cache" content="no-cache">
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
</head>
<body>
    <input type="hidden" id="QuestionTempValue" value="<%=QuestionTempValue %>" />
    <input type="hidden" id="PaperType" value="<%=PaperType %>" />
    <input type="hidden" id="ystihaoList" value="<%=ystihaoList %>" />
    <input type="hidden" id="TemDataID" value="<%=TempID %>" />
    <input type="hidden" id="tenant" value="<%=tenant %>" />
    <input type="hidden" id="questionNum" value="<%=questionNum %>" />
    <input type="hidden" id="exam_subject_id" value="<%=exam_subject_id %>" />
    <input type="hidden" id="subjective" value="<%=subjective %>" />
    <input type="hidden" id="TempMainID" value="<%=TempMainID %>" />

    <div style="width: 1600px; height: auto; overflow: hidden; margin: 10px 200px 0 0; border: 1px solid #999; padding: 10px; box-shadow: 5px 5px 5px #000;">
        <h1 style="text-align: center; font-size: 16px; width: 100%; border-bottom: 1px solid #999; padding-bottom: 10px; margin-bottom: 10px;">题目拆分</h1>
        <div class="leftControl" style="width: 1200px; border: 4px solid #666; float: left; position: relative;">
            <div class="main_papermain">
                <img src="<%=TempPicture64_nvarchar %>" />
            </div>
        </div>
        <div class="rigthtControl">
            <h3 style="border-bottom: 1px solid #999;">题目拆分</h3>
            <div>
                <ul class="xul">
                    <li style="font-size: 18px; border: 1px solid #ddd;">序号:
                        <label style="font-weight: bold; color: #f00; font-size: 30px;"><%=xuhao %></label>
                        <%--小题:--%><label style="display:none"><%=xiaoti %></label><br />
                        分数:<label style="font-weight: bold; color: #f00; font-size: 30px;" id="oldScore"><%=fenshu %></label>
                        阅卷跳分:<label><%=yuejuanfen %></label></li>
                </ul>
            </div>
            <h3 style="border-bottom: 1px solid #999; float: left; width: 100%; text-align: center; margin-top: 10px;">重新布置</h3>
            <div style="float: left; margin-top: 10px;">
                题号：<input type="text" id="zhuguan_tihao" style="width: 200px; font-size: 14px; height: 30px;" value="" placeholder="题号不能与原题号一致建议13.1" /><br />
                <br />
                <%--小题：--%><input type="text" id="zhuguan_xiaoti" style="width: 80px; font-size: 14px; height: 30px; display:none;" value="0" placeholder="" />
                分数：
                 <select id="zgquestionscroe" style="font-size: 14px; width: 80px; height: 30px; text-align: center;">
                     <option value="">无分</option>
                     <option value="0.5">0.5</option>
                 </select>
                <br />
                <br />
                间隔：
                 <select id="questionscroetype" style="font-size: 14px; width: 80px; height: 30px; margin-top: 5px; text-align: center;">
                     <option value="5">5分</option>
                     <option value="4.5">4.5分</option>
                     <option value="4">4分</option>
                     <option value="3.5">3.5分</option>
                     <option value="3">3分</option>
                     <option value="2.5">2.5分</option>
                     <option value="2">2分</option>
                     <option value="1.5">1.5分</option>
                     <option value="1" selected="selected">1分</option>
                     <option value=".5">0.5分</option>
                 </select>

                类型：
                 <select id="questiontype_zg" style="font-size: 14px; height: 30px; width: 80px; margin-top: 5px; text-align: center;">
                     <option value="1">大题</option>
                     <option value="2">填空题</option>
                 </select>
                <br />
                <br />
                <div style="margin-left: 45px;" class="goPeizhi" onclick="SetZhuguanTi()">开始配置</div>
            </div>
                <h3 style="border-bottom: 1px solid #999; padding-bottom: 10px; float: left; width: 100%; text-align: center; margin-top: 10px;">拆题数据</h3>
            <div style="float: left; width: 100%; margin-top: 20px;">
                <div style="float: left; width: 85%; background: #000; box-shadow: 5px 5px 5px #444; color: #fff; padding: 5%;">
                    总分数:<label id="totalScorew">0</label>
                    拆分题数：<label id="totalChatiNum">0</label>
                </div>
            </div>
            <div style="float: left; width: 280px;overflow:auto;height:300px;border:1px solid black" id="chaiBox">

            </div>

            

            <div style="float: left; width: 100%; margin-top: 20px;">
                <input type="button" id="submit" onclick="SubmitChai()" value="确认保存(保存后无法修改)" style="float: left; width: 70%; margin-left: 15%; cursor: pointer;background: #f00; border-radius: 3px; box-shadow: 5px 5px 5px #444; color: #fff; text-align: center; padding: 5%;" />

            </div>
        </div>
    </div>

    <script>


        //获取主观题
        function GetZhuguanPostion() {
            var xy = "";
            if ($(".zhuguanti").length == 0) {
                return "";
            }
            $(".zhuguanti").each(function () {
                xy += parseFloat($(this).position().left) + ","
                    + parseFloat($(this).position().top) + ","
                    + parseFloat($(this).width()) + "," +
                    parseFloat($(this).height()) + "," +
                    $(this).attr("tihaovalue") + "," +
                    $(this).attr("zhuguan_xiaoti") + "," +
                    $(this).attr("score") + "," +
                    $(this).attr("scoretype") + "," +
                    $(this).attr("questiontype_zg") + "^";
            })
            return xy.trim('^');
        }

        function SubmitChai() {

            if ($(".scoreTotal").length == 0) {
                alert("你还未进行拆题");
                return false;
            }

            if (confirm("拆题后，之前的数据将无法恢复，请谨慎使用")) {
                var totalScorew = $("#totalScorew").html() == '' ? 0 : parseFloat($("#totalScorew").html());
                var oldScore = $("#oldScore").html() == '' ? 0 : parseFloat($("#oldScore").html());

                if (totalScorew != oldScore) {
                    if (confirm("原始分数与拆解后分数不一致，是否继续？")) {

                    }
                    else {
                        return false;
                    }
                }
                var zhuguantiList = GetZhuguanPostion();
                console.log(zhuguantiList);
                var tenant = $("#tenant").val();
                var TemDataID = $("#TemDataID").val();
                var questionNum = $("#questionNum").val();
                var exam_subject_id = $("#exam_subject_id").val();
                var subjective = $("#subjective").val();
                var token = localStorage.getItem("token");
                var TempMainID = $("#TempMainID").val();
                var exam_subject_id = $("#exam_subject_id").val();
                $("#submit").attr("disabled", "disabled");

                $.post("SplitQuestion.aspx", { action: 1, rd: Math.random(), exam_subject_id: exam_subject_id, TempMainID: TempMainID, zhuguantiList: encodeURIComponent(zhuguantiList), TemDataID, TemDataID, tenant: tenant, questionNum: questionNum, exam_subject_id: exam_subject_id, subjective: subjective, token: token }, function (res) {
                    if (res == "1") {
                        alert("操作成功,窗口即将关闭!");
                        window.close();
                        document.location.href = 'SuccessCut.aspx';
                    }
                    else {
                        alert(res);
                    }
                    $("#submit").removeAttr("disabled");
                })
            }
        }


        function SelectValueList() {
            var html = "";
            var score = 0.5;
            var git = document.getElementById("zgquestionscroe");
            git.options[0] = new Option("0分", "0");
            for (var i = 1; i <= 121; i++) {
                score = parseFloat(score) + parseFloat(0.5);
                git.options[i] = new Option(score, score);
            }
        }
        SelectValueList();
        function SetZhuguanTi() {

            var zhuguan_tihao = $("#zhuguan_tihao").val().toUpperCase().replace(/\./g, "·").replace(/\(/g, "（").replace(/\)/g, "）").replace(/\=/g, "＝").replace(/\@/g, "＠");
            if (!CheckTihao(zhuguan_tihao)) {
                alert("该题号原试卷已经存在");
                return;
            }
            if (zhuguan_tihao == "") {
                alert("主观题 题号不能为空");
                return;
            }
            var score = $("#zgquestionscroe").val();
            var scoretype = $("#questionscroetype").val();
            var questiontype_zg = $("#questiontype_zg").val();
            //var scoretypeText = scoretype == "1" ? "全分" : "半分";
            var scoretypeText = scoretype;

            if (document.getElementById("keguan_" + zhuguan_tihao) != undefined) {
                alert("0题目配置重复:" + zhuguan_tihao);
                return;
            }
            var zhuguan_xiaoti = $("#zhuguan_xiaoti").val();
            if (zhuguan_xiaoti == "") {
                zhuguan_xiaoti = "0";
            }
            var lineWh = "width:800px;height:200px;";
            var lineWhTx = "大题";
            if (questiontype_zg == "2") {
                var lineWh = "width:200px;height:90px;";
                lineWhTx = "填空"
            }
            $(".main_papermain").append("<div id=\"keguan_" + zhuguan_tihao + "\"  class='main_tabletop zhuguanti' questiontype_zg='" + questiontype_zg + "'  tihaovalue='" + zhuguan_tihao + "' zhuguan_xiaoti='" + zhuguan_xiaoti + "' score='" + score + "' scoretype='" + scoretype + "'  style='" + lineWh + ";background:none; left:100px; top:" + (100 + $(document).scrollTop()) + "px;'><div style=\" float:left;  width:auto;text-align:center; height:30px;  position:absolute; margin-top:-30px;z-index:22; color:#fff; line-height:30px; background:#666;\">" + lineWhTx + "：" + zhuguan_tihao + "</div><div  style='width:100%;height:100%;background:#fff;border:1px solid red;'></div></div>");
            $("#keguan_" + zhuguan_tihao).draggable({ containment: ".main_papermain" });
            $("#keguan_" + zhuguan_tihao).resizable({ containment: ".main_papermain", handles: 'all' });

            var html = "<div class=\"boxscore\" id='box_" + zhuguan_tihao + "'>";
            html += "";
            html += "<label><b>题号：" + zhuguan_tihao + "</b></label>";
            html += "<label style=\"display:none\">小题:" + zhuguan_xiaoti + "</label>";
            html += "<label>分数:<b class='scoreTotal'>" + score + "</b></label>";
            html += "<label>间隔:" + scoretype + "</label>";
            html += "<label>" + lineWhTx + "</label>";
            html += "<span onclick=\"BoxClose('" + zhuguan_tihao + "')\">";
            html += "        X";
            html += "    </span>";
            html += "</div>";
            $("#chaiBox").append(html);
            scoreTotal();
        }

        function BoxClose(id) {
            $("#box_" + id).remove();
            $("#keguan_" + id).remove();
            scoreTotal();
        }

        //
        function scoreTotal() {
            var totalNum = 0;
            var count = 0;
            $(".scoreTotal").each(function () {
                count++;
                totalNum += parseFloat($(this).html());
            })
            $("#totalScorew").html(totalNum);
            $("#totalChatiNum").html(count);
        }

        /////////////////设置主观题//////////////////////
        function SetZhuguanTiPostion(PostionData) {

            if (PostionData == "" || PostionData == undefined) {
                return;
            }
            //左边距,右边距,长,高,题号,小题数量
            var listdata = PostionData.split('^');

            for (var i = 0; i < listdata.length; i++) {
                var zhuguanList = listdata[i].split(',');
                var zhuguan_tihao = zhuguanList[4].toUpperCase().replace(".", "·").replace("(", "（").replace(")", "）").replace(")", "）").replace("=", "＝").replace("@", "＠");
                var score = zhuguanList[6] == undefined ? "" : zhuguanList[6];

                var scoretype = zhuguanList[7] == undefined ? "1" : zhuguanList[7];

                //var scoretypetext = scoretype;
                var scoretypetext = scoretype;
                var questiontype_zg = zhuguanList[8] == undefined ? "1" : zhuguanList[8];


                if (document.getElementById("keguan_" + zhuguan_tihao) != undefined && document.getElementById("keguan_" + zhuguan_tihao) != null) {
                    alert("2题目配置重复:" + zhuguan_tihao);
                    return;
                }



                var lineWhTx = "原始大题";
                if (questiontype_zg == "2") {
                    lineWhTx = "原始填空"
                }
                var zhuguan_xiaoti = zhuguanList[5];
                $(".main_papermain").append("<div id=\"keguan_" + zhuguan_tihao + "\"  class='main_tabletop' questiontype_zg='" + questiontype_zg + "' tihaovalue='" + zhuguan_tihao + "' zhuguan_xiaoti='" + zhuguan_xiaoti + "' score='" + score + "' scoretype='" + scoretype + "'  style=' left:" + zhuguanList[0] + "px; top:" + zhuguanList[1] + "px;width:" + zhuguanList[2] + "px;height:" + zhuguanList[3] + "px; background:none; '><div style=\" float:left; width:auto; text-align:center; height:30px;  position:absolute; margin-top:-30px;z-index:22; color:#fff; line-height:30px; background:#666;\">" + lineWhTx + ":" + zhuguan_tihao + "</div><div  style='width:100%;border:5px solid blue;height:100%;background:#fff;'></div></div>");
                //$("#keguan_" + zhuguan_tihao).draggable({ containment: ".main_papermain" });
               // $("#keguan_" + zhuguan_tihao).resizable({ containment: ".main_papermain", handles: 'all' });

                //$("#NowSelect").append("<li style='background:#fff;' id='selectNow_" + zhuguan_tihao + "'><div class='sp'><div class='go'>主观题</div></div><div class='sf'>" + zhuguan_tihao + "</div><div class='sm'>" + zhuguan_xiaoti + "</div><div class='ss' id='ss_" + zhuguan_tihao + "' idAtt='keguan_" + zhuguan_tihao + "'  onclick=\"UpdateBaseData(1,'" + score + "','" + zhuguan_tihao + "','主观题')\">" + score + "</div><div class='ssd' id='ssd_" + zhuguan_tihao + "'  onclick=\"UpdateBaseData(2,'" + scoretype + "','" + zhuguan_tihao + "','主观题')\">" + scoretypetext + "</div><div class='sd' onclick=\"DeleteKeguanti('" + zhuguan_tihao + "')\">x</div></li>");
            }
        }
        ////////////////设置主观题//////////////////////
        $(document).ready(function () {
            var PaperType = $("#PaperType").val();
            if (PaperType == "1") {
                $(".main_papermain").width("1570px");
                $(".leftControl").width("1570px");
            }
            else {
                $(".main_papermain").width("1200px");
                $(".leftControl").width("1200px");
            }
            SetZhuguanTiPostion($("#QuestionTempValue").val())
        })
        function CheckTihao(t) {
            var ystihaoList = $("#ystihaoList").val().split(',');
            for (var i = 0; i < ystihaoList.length; i++) {
                if (t == ystihaoList[i]) {

                    return; false;
                }
            }
            return true;
        }
        String.prototype.trim = function (char, type) {
            if (char) {
                if (type == 'left') {
                    return this.replace(new RegExp('^\\' + char + '+', 'g'), '');
                } else if (type == 'right') {
                    return this.replace(new RegExp('\\' + char + '+$', 'g'), '');
                }
                return this.replace(new RegExp('^\\' + char + '+|\\' + char + '+$', 'g'), '');
            }
            return this.replace(/^\s+|\s+$/g, '');
        };
    </script>
</body>
</html>
