$(function () {

    $("#sFactoryNo").select2();

    $("#tOrder tr td").click(function () {
        if ($(this).parent().hasClass("totalTd") || $(this).hasClass("td-checkbox")) {
            return;
        }
        else {
          
            ShowDetail($(this).parent().attr("id"));
        }
    }); 
    
    TdRowOverOut("tOrder"); 
    SetSpanColor("tOrder");

    $("#btnExport").click(function () {

        if (checkRequired('dSearch', '') == false) {
            return false;
        }
        if (!checkField()) {
            return;
        }
        location.href = "/FactoryOrder/GetFactoryStatementPdf?sFactoryNo=" + $("#sFactoryNo").val() + "&sBeginDate="
            + "&sFactoryName=" + $("#sFactoryName").val()+ $("#sBeginDate").val() + "&sEndDate=" + $("#sEndDate").val() + "&sPaymentStatus=" + $("#sPaymentStatus").val() + "&sKey=" + "&sInvoiceStatus=" + $("#sInvoiceStatus").val();
    });

    $("#btnExportExcel").click(function () {
        if (checkRequired('dSearch', '') == false) {
            return false;
        }
        if (!checkField()) {
            return;
        }
        location.href = "/FactoryOrder/GetFactoryStatementExcel?sFactoryNo=" + $("#sFactoryNo").val() + "&sBeginDate=" + $("#sBeginDate").val()
            + "&sEndDate=" + $("#sEndDate").val() + "&sPaymentStatus=" + $("#sPaymentStatus").val() + "&sKey="
            + "&sFactoryName=" + $("#sFactoryName").val()+ "&sInvoiceStatus=" + $("#sInvoiceStatus").val();
    });

 
});

function checkField() {
    if (checkRequired('dSearch', '') == false) {
        return false;
    }

    return true;
}

function checkField() {
    ClearErrorMsg();
    if (checkRequired('dSearch', '') == false) {
        return false;
    }
    else if (DateDiff($("#sBeginDate").val(), $("#sEndDate").val()) > 366) {
        SetErrorMsg("提示：起止时间跨度最多为1年。如果时间跨度超过1年，请分多次查询。");
        return false;
    }
    else {
        return true;
    }
}
 
 