<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RandomMakeQues.aspx.cs"
    Inherits="RM.Web.Training.TrainingTest.RandomMakeQues" %>

<!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><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("UserInfo_Index")%></title>
    <link href="/Themes/Styles/Site.css" rel="stylesheet" type="text/css" />
    <script src="/Themes/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
    <link href="/Themes/Scripts/TreeView/treeview.css" rel="stylesheet" type="text/css" />
    <script src="/Themes/Scripts/TreeView/treeview.pack.js" type="text/javascript"></script>
    <script src="../../Themes/Scripts/jquery.json-2.3.min.js" type="text/javascript"></script>
    <link href="/Themes/Scripts/ShowMsg/msgbox.css" rel="stylesheet" type="text/css" />
    <script src="/Themes/Scripts/ShowMsg/msgbox.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/FunctionJS.js" type="text/javascript"></script>
    <link href="/Training/Exam/Themes/Css/ExamGlobal.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .btnbartitle div { margin-top: -4px; }
        input { border: 1px solid #999; }
        .titleContainer { padding: 0 15px; border: none; border-top: 1px solid #73cc54; line-height: 36px; }
        legend { padding: 0 5px; }
        .iframeContent span { color: #58c6eb; margin: 0 10px; }
        .configureType { width: 70px; display: inline-block; vertical-align: bottom; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
        .configureDetail li { display: inline-block; }
        .configureDel { margin-left: 10px; }
        .configureDel:hover { text-decoration: underline; }
        #correctData, #saveCreateExam, #helpMe { font-size: 9pt; background-color:#92c656;  transition: none; color: White; border-radius: 3px; }
        #correctData:hover, #helpMe:hover { background-color:#97ce4c;  text-decoration: underline; }
        #saveCreateExam { padding: 5px 8px;  background-color:#187bd1;  }
        #saveCreateExam:hover { background-color:#2a89dd }
        #correctData { margin-right: 10px; padding: 5px 20px; }
        #helpMe { padding: 5px 20px; }
        .strTree li ul { display: none; }
        #currScore, #currCount { font-weight: bold; font-size: 11pt; }
        .titleRight { text-align: right; }
        .strTree label { cursor: pointer; }
        #handleIcon { background: url("/Themes/Images/loading.gif") no-repeat scroll 7px 2px #FFFFFF; left: 45%; padding: 6px 5px 6px 40px; position: absolute; top: 45%; z-index: 3000; }
        #configureData { overflow: scroll; }
        /*help*/
        #randomDiscription { width: 800px; position: absolute; border: 1px solid #888; background-color: #FFF; text-align: left; padding: 0 10px 10px; box-shadow: 0 2px 6px rgba(100, 100, 100, 0.3); right: 218px; display: none; top: 95px; border-radius: 3px; }
        #randomTitle { font-size: 11pt; border-bottom: 1px solid #CCC; margin-bottom: 10px; }
        .randomDisContext li { line-height: 23px; text-indent: 2em; }
        .randomTitle { color: #40a9cc; font-weight: bold; }
        .warnText { color: Red !important; padding: 0 2px !important; margin: 0 !important; }
        /*Arrow*/
        .tipArrow { position: absolute; width: 20px; z-index: 0; right: 19px; top: -9px; }
        .tipArrow * { display: block; font-family: "SimSun"; font-size: 16px; height: 16px; line-height: 1.231; overflow: hidden; font-style: normal; }
        .ar_boderLine { color: #888; }
        .ar_bg { margin: -14px 0 0 0 !important; color: #FFF !important; }
        .typeCount { padding-left: 2px; color: #888686; }
        .maxCount { color: Red; display: inline-block; width: 20px; text-align: center; }
        .configureCount,.configureScore{ width:20px;}
        .configureDataCai{ min-width:750px;}
    </style>
    <script type="text/javascript">
        $(function () {
            $("html").css("overflow", "hidden");
            $("body").css("overflow", "hidden");
            divresize(29);
            treeAttrCss();
            iframeresize();
            Loading(true);
            $(".strTree li div").click(function () {
                var id = new Array();
                var text = new Array();
                var maxCount = new Array(); //最大题目数量
                //子目录 
                $(this).parent().find("span").each(function () {
                    if ($(this).html() != ""&&$(this).prev().text()!="") {                        
                        id.push($(this).html());
                        maxCount.push($(this).prev().text());
                        text.push($(this).prev().prev().text());
                    }
                });
                var isExists = true;
                for (var i = 0; i < id.length; i++) {

                    var tempt = $('<li class="configureDataCai"><ul class="configureDetail"><li><span><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Ques_fenlei")%>：</span><label class="configureType" title=""></label></li><li>  <select class="configqtid"> <option value="0"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_bx")%></option><option value="1"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SmartQuestion_danxuan")%></option><option value="2"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SmartQuestion_duoxuan")%></option>  <option value="3"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SmartQuestion_wenda")%></option><option value="4"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SmartQuestion_panduan")%></option>  <option value="5"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SmartQuestion_paixun")%></option><option value="6"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SmartQuestion_tiankong")%></option><option value="7"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SmartQuestion_zonghe")%></option><option value="8"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("BType_questions")%></option> </select></li><li><span><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_Num")%>：</span><input class="configureCount" value="1" maxCount="' + maxCount[i] + '" />&nbsp;<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_maxNum")%>：（<label class="maxCount">' + maxCount[i] + '</label>）</li><li><span><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_fsbz")%>：</span><input class="configureScore" value="1"/></li> <li> <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SmartQuestion_stnandu")%>: <select class="configlv"> <option value="4"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_bx")%></option> <option value="0"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SmartQuestion_easy")%></option><option value="1"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SmartQuestion_yiban")%></option><option value="2"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SmartQuestion_nan1")%></option>  <option value="3"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SmartQuestion_kunnan")%></option><option value="4"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SmartQuestion_hennan")%></option> </select> </li> <li><a href="javascript:;" class="configureDel"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Delete")%></a></li></ul></li>');
                    tempt.find('.configureType').attr('data', id[i]).text(text[i]).attr('title', text[i]);
                    $("#configureData").append(tempt);
                }
                correctData();
                //iframeresize();
            })
            //验证数字 num
            function isInteger(obj, isShowInfo) {
                reg = /^[-+]?\d+$/;
                if (!reg.test(obj)) {
                    if (isShowInfo) showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_isNum")%>', 1500, 3);
                    return false;
                } else {
                    if (parseInt(obj) < 1) {
                        if (isShowInfo) showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_iszero")%>', 1500, 3);
                        return false;
                    }
                    return true;
                }
            }
            $(".configureDel").live("click", function () {//删除题目
                $(this).closest(".configureDataCai").remove();
                var currScore = 0; //当前已经分配过的分
                var sumCount = 0;
                $('.configureDataCai').each(function () {
                    var count = $(this).find('.configureCount').val();
                    var score = $(this).find('.configureScore').val();
                    if (!isInteger(count) || !isInteger(score)) return false;
                    sumCount += parseInt(count);
                    currScore += parseInt(score);
                });
                $("#currCount").text(sumCount);
                $('#currScore').text(currScore); //放置剩余分数
            });
            $(".configureCount").live("blur", function () {//题目总个数
                if (!isInteger($(this).val(), "yes")) return false;
                var sumCount = 0;
                $('.configureCount').each(function () {
                    if (!isInteger($(this).val())) return false;
                    if (parseInt($(this).val()) > parseInt($(this).attr('maxCount'))) {
                        showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_tishi")%>', 3000, 3);
                        return false;
                    };
                    sumCount += parseInt($(this).val());
                });
                $("#currCount").text(sumCount);
            });
            $(".configureScore").live("blur", function () {//当前已分配分值
                if (!isInteger($(this).val(), "yes")) return false;
                var currScore = 0; //当前已经分配过的分
                $('.configureScore').each(function () {
                    if (!isInteger($(this).val())) return false;
                    currScore += parseInt($(this).val());
                });
                $('#currScore').text(currScore); //放置剩余分数
            });

            $('#correctData').click(function () {//矫正数据按钮
                correctData(function () { showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_xz")%>', 1500, 4); });
            });
            $('#saveCreateExam').click(function () {
                //保存并创建试卷
                if (!correctData()) return false;
                var dataScore = 0;
                $('.configureScore').each(function () {
                    dataScore += parseInt($(this).val());
                });
                showConfirmMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_save")%>', function () {
                    var configureList = new Array();
                    $(".configureDetail").each(function () {
                        var dataId = $(this).find('.configureType').attr('data');
                        var count = $(this).find('.configureCount').val();
                        var score = $(this).find('.configureScore').val();
                        var qtid = $(this).find('.configqtid').val();

                        var lv = $(this).find('.configlv').val();
                        
                        configureList.push({ ExamRandom_TypeId: dataId, ExamRandom_QueCount: count, ExamRandom_Proportion: score, ExamRandom_QtId: qtid, ExamRandom_Lv: lv });
                    });
                    $("#handleIcon").fadeIn(200);
                    $.ajax({
                        url: "CreateRandomExam.ashx",
                        type: "post",
                        data: { "array": $.toJSON(configureList), "sS": $('#currScore').text(), "sC": $("#currCount").text() },
                        dataType: "json",
                        success: function (data) {
                            $("#handleIcon").hide(0);
                            var resultStr = "";
                            if (data) {//不为空
                                if (data.err && data.err.length > 0) {//有异常
                                    showTipsMsg(data.err, 3000, 5);
                                } else {
                                    showTipsMsg("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_creatsucc")%>", 3000, 4);
                                    var url = "/Training/TrainingTest/ExaminationPaper_Form.aspx?ExamKey=" + data.examId;
                                    top.openDialog(url, "ExaminationPaper_Form", "<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_info")%> - <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Add")%> ", <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("exam_heigt")%>, 450, 50, 50); //录入试卷信息
                                    $('.configureDataCai').remove();
                                    $('#currScore').text(100);
                                    $('#currCount').text(1);
                                }
                            } else
                                showTipsMsg("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_excep")%>", 3000, 5);
                        },
                        error: function () {
                            showTipsMsg("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Ques_showExcep")%>", 3000, 5);
                            $("#handleIcon").fadeOut(200);
                        }
                    });
                });
            });
            function correctData(callBack) { //矫正数据方法
                if ($('.configureDetail').length < 1) {
                    showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_notrandom")%>', 2000, 3);
                    return false;
                }
                var currCount = 0; //当前总题数
                var currScore = 0; //当前已分配的分数
                var isPass = true; //是否通过验证
                $('.configureCount').each(function () {
                    //验证总题数
                    if (!isInteger($(this).val())) {
                        isPass = false;
                        return false;
                    } else if (parseInt($(this).val()) > parseInt($(this).attr('maxCount'))) {//超过了最大长度
                        isPass = false;
                        return false;
                    } else {
                        currCount += parseInt($(this).val());
                    }
                });

                if (!isPass) {
                    showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_tishi2")%>', 4000, 3);
                    return false;
                }
                $('.configureScore').each(function () {
                    //验证分数比重
                    if (!isInteger($(this).val())) {
                        isPass = false;
                        return false;
                    } else
                        currScore += parseInt($(this).val());
                });
                if (!isPass) {
                    showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_tishi3")%>', 3000, 3);
                    return false;
                }
                $('#currScore').text(currScore);
                $('#currCount').text(currCount);
                if (callBack) callBack();
                return true;
            }
            $("#randomDiscription").click(function (e) { stopBubble(e); });
            $("#helpMe").click(function (e) {
                stopBubble(e);
                $("#randomDiscription").stop().slideDown(300);
                $(window).one("click", function () {
                    $("#randomDiscription").stop().slideUp(300);
                });
            });
            //阻止事件冒泡的通用函数  
            function stopBubble(e) {
                // 如果传入了事件对象，那么就是非ie浏览器  
                if (e && e.stopPropagation) {
                    //因此它支持W3C的stopPropagation()方法  
                    e.stopPropagation();
                } else {
                    //否则我们使用ie的方法来取消事件冒泡  
                    window.event.cancelBubble = true;
                }
            }
        })
        /**自应高度**/
        function iframeresize() {
            resizeU();
            $(window).resize(resizeU);
            function resizeU() {
                var iframeMain = $(window).height() - 140;
                $("#configureData").height(iframeMain);
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="iframeMainContent">
        <div class="iframeleft">
            <div class="btnbartitle">
                <div>
                    <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("coursetype")%>
                        
                </div>
            </div>
                      

            <div class="div-body">
                <ul class="strTree">
                    <%=strHtml.ToString()%>
                </ul>
            </div>
        </div>
        <div class="iframeContent">
            <div class="btnbartitle">
                <div>
                    <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("que_item")%>      
                                               
                </div>
            </div>
            <fieldset class="titleContainer">
                <legend><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_dqzt")%></legend>
                <!--inputSumScore-->
                <div>
                    <div class="titleRight">
                    
                        <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_fpfz")%>：<span id="currScore">0</span>，<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_queNum")%>：<span id="currCount">0</span><a href="javascript:;"
                            id="helpMe"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_help")%></a> <a href="javascript:;" id="correctData"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_jzsj")%></a><a href="javascript:;"
                                id="saveCreateExam"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_saveexam")%></a>
                           
                    </div>
                    <div id="randomDiscription">
                        <h3 id="randomTitle"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_sjcthelp")%></h3>
                        <div class="tipArrow">
                            <em class="ar_boderLine">◆</em> <span class="ar_bg">◆</span>
                        </div>
                        <ul class="randomDisContext">
                            <li class="randomTitle"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Cz")%>：</li>
                            <li>1、<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_cz1")%>（<span class="warnText"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_czA")%></span>），<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_czB")%></li>
                            <li>2、<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_cz2")%></li>
                            <li>3、<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_cz3")%></li>
                            <li>4、<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_cz4")%></li>
                        </ul>
                        <ul >
                            <li class="randomTitle"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_zysx")%>：</li>
                            <li>1、<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_zysx1")%><span class="warnText"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_jzsj")%> </span>，<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_zysxA")%>。</li>
                            <li>2、<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_zysx2")%></li>
                            <li>3、<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_zysx3")%></li>
                            <li>4、<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_zysx4")%></li>
                        </ul>
                    </div>
                </div>
            </fieldset>
            <fieldset class="titleContainer">
                <legend><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("RandomQue_ctpz")%></legend>
                <ul id="configureData">
                </ul>
            </fieldset>
        </div>
    </div>
    </form>
    <div id="handleIcon" style="display: none;"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("UserRight_chuli")%></div>
</body>
</html>
