var arrHead = {};
var bodyList = {};

$(document).ready(function(){

});

function TransferString(content)
{
    var string = content;
    try{
        string=string.replace(/\r\n/g,"#");
        string=string.replace(/\n/g,"#");
    }catch(e) {
        alert(e.message);
    }
    return string;
}

function check(){
    var textArea = $("#textArea").val();
    var source = $("#source_code").val();

    if(textArea == ""){
        alertui("查询sql不可以为空，请确认!");
        return false;
    }
    textArea = textArea.toLowerCase();
    $.ajax({
        url : "executeSql.do",
        async : false,
        dataType:"json",
        type : "post",
        data : {
            textArea:textArea,
            source:source
        },
        success : function(data) {
            if(data.result == "success" && data.flag=="select"){
                var contextHead = "";
                var contextBody = "";
                arrHead = data.arrHead;
                bodyList = data.bodyList;
                var length = data.length;
                if(arrHead != null){
                    for (var j = 0; j < arrHead.length; j++) {
                        var colHead = arrHead[j];
                        contextHead += "<th>"+colHead+"</th>";
                    }
                    $("#context_body_header").html(contextHead);
                }

                if(bodyList != null){
                    for (var i = 0; i < bodyList.length; i++) {
                        var bodyHead = bodyList[i];
                        contextBody += "<tr>";
                        for(var n=0;n<length;n++){
                            contextBody += "<td>"+bodyHead[n]+"</td>";
                        }
                        contextBody += "</tr>";
                    }
                    $("#context_body_manager").html(contextBody);
                }
            }else if(data.result == "success" && data.flag!="select"){
                $("#context_body_header").html("");
                $("#context_body_manager").html("");
                var message = data.message;
                $(".modal-body").html(message);
                $("#myModal").attr("style","display: block;z-index: 9999;");
                $("#myModal").modal("show");
            }else {
                $("#context_body_header").html("");
                $("#context_body_manager").html("");
                var message = data.message;
                $(".modal-body").html(message);
                $("#myModal").attr("style","display: block;z-index: 9999;");
                $("#myModal").modal("show");
            }
        }
    });
}

function resetSelect(){
    $(".sql_area").val("");
    $("#context_body_header").html("");
    $("#context_body_manager").html("");
}