<%@ page language="C#" autoeventwireup="true" inherits="Rest_Manage_RestOrderPrintSubmit4, DoodiiShop" enableEventValidation="false" viewStateEncryptionMode="Never" %>

<!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>都来订网络外卖订餐系统 - 单列订单打印(无边距)</title>

    <script type="text/javascript" src="../../js/jquery.js"></script>
    <script type="text/javascript" src="../../js/Format.js"></script>

    <script type="text/javascript">
        var gWB = null;
        var gPosition = 1;
        var gOrderList = "";
        var gOrderArr = null;
        var gTotalCount = 0;//总份数
        var oOrderInfos = new Array();//订单缓存        
        $(document).ready( function(){ init() });
        
        function init()
        {
            gWB = document.getElementById("wb");
            gPosition = parseInt(getQueryString("Position"));
            gMode = parseInt(getQueryString("Mode"));
            if (isNaN(gPosition)) gPosition = 1;
            if (gPosition < 1 || gPosition > 30) gPosition = 1;
            gOrderList = getQueryString("OrderList");
            gOrderArr = gOrderList.split("|");
            if (gOrderArr.length == 0)
            {
                alert("没有要打印的订单！");
                return;
            }
            $("#btnPrint").bind("click", function(){ print() });
            $("#btnPrintSetup").bind("click", function(){ printSetup() });
            $("#btnPrintPreview").bind("click", function(){ printPreview() });
            fillData();
            gWB.execwb(6, 6);//打印
        }
        
        
        function createPart()
        {
            var divPart = document.createElement("div");
            divPart.className = "PagePart";
            return divPart;
        }
        
        function createItem(className)
        {            
            var div = document.createElement("div");
            if (className!=null)
                div.className = className;
            else
                div.className = "Item";
            
            return div;
        }
        
        function fillData()
        {
            if (gPosition > 1)
            {
                for (var i = 0; i < gPosition-1; i++)
                {
                    oOrderInfos.push(createItem());
                }
            }
            for (var i = 0; i < gOrderArr.length; i ++)
            {
                var _OrderInfo = gOrderArr[i].split(":");
                var _OrderId = parseInt(_OrderInfo[0]);
                var _OrderType = parseInt(_OrderInfo[1]);
                if (isNaN(_OrderId) || isNaN(_OrderType))
                {
                    alert("订单数据错误！");
                    return;
                }
                if (_OrderType == 1)
                    var ret = Rest_Manage_RestOrderPrintSubmit4.GetCommonOrderInfo(_OrderId).value;
                else
                    var ret = Rest_Manage_RestOrderPrintSubmit4.GetSuiteMenuOrderInfo(_OrderId).value;
                if (ret == null || typeof(ret) != "object")
                {
                    alert("获取订单数据失败");
                    return;
                }
                var _Name = ret.Name;
                var _Phone = ret.Phone;
                var _Total = ret.Total;
                var _Address = ret.Address;
                var _DateTime = ret.DateTime;
                var _DeliverDate = ret.DeliverDate;                
                var _OrderCount = 0;
                var _Note = ret.Note;
                var _Count = 0;
                var _RestName = ret.RestName
                //写基本信息                
                var divItem = createItem("Item OrderItemTop");
                $(divItem).append(createContainer1(_OrderId, _Name, _Phone, _Address, _DeliverDate,_Total,_Note,_RestName));
                oOrderInfos.push(divItem);
                
                for (var j = 0; j < ret.DetailInfos.length; j++) _OrderCount += parseInt(ret.DetailInfos[j].Amount);
                var _OrderDetailIndex = 0;
                var _OrderDetailCount = ret.DetailInfos.length;
                var divContainer = document.createElement("div");
                divContainer.className = "Container";
                for (var j = 0; j < ret.DetailInfos.length; j++)
                {
                    /*for (var m = 0; m < ret.DetailInfos[j].Amount; m++)
                    {}*/
                    _OrderDetailIndex++;
                    var _Price = ret.DetailInfos[j].Price;
                    var _Amount = ret.DetailInfos[j].Amount;
                    _Count += _Amount;                    
                    
                    if (_OrderType == 1)
                        var _OrderContent = ret.DetailInfos[j].MenuName;
                    else
                        var _OrderContent = ret.DetailInfos[j].MenuName;
                    
                    var nextPageCss = "";    
                    
                    var divItem = createItem();                    
                    $(divItem).append(createContainer2(_OrderDetailIndex, _OrderDetailCount, _Price, _Amount, _Total, _OrderContent));                                       
                    oOrderInfos.push(divItem); 
                }
                var divItem = createItem("Item OrderItemBottom");
                $(divItem).append(createContainer3(_Total,_Count));
//                if (i < gOrderArr.length-1)
//                {
//                    divItem.className = "nextPage";
//                } 
                oOrderInfos.push(divItem); 
            }
            renderData();
        }
        function createContainer1(OrderId, Name, Phone, Address, DeliverDate,Total,Note,RestName)
        {
            var divContainer = document.createElement("div");
            divContainer.className = "Container";
            divContainer.innerHTML =               
                "<div style='border-bottom:3px double black;width:100%;text-align:center;padding-bottom:5px;margin-bottom:15px;'>" + RestName + "</div>"
                + "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td>收 餐 人：" + Name + "</td><td align='right'>订单号：#" + OrderId + "</td></tr></table>"
                + "要餐时间：" + formatDateTimeFromDateStr(DeliverDate, 1)
                + "<br />联络电话：" + Phone
                + "<br />送餐地址：" + Address
                + "<br />备&nbsp;&nbsp;&nbsp;&nbsp;注：<b>" + Note + "</b>"
                + "<br /><br /><table width='100%' border='0' cellpadding='0' cellspacing='0'>"
                + "<tr><td width='140' align='left'>餐品名称</td><td width='25' align='right'>份数</td><td width='50' align='right'>单价</td><td align='right'>小计</td></tr></table>"
                + "<div style='padding-top:5px;'></div>"; 
            return divContainer;
        }
        function createContainer2(OrderDetailIndex, OrderDetailCount, Price,Amount, Total, OrderContent)
        {
            var divContainer = document.createElement("div");
            divContainer.className = "Container";
            divContainer.innerHTML = "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
                + "<tr><td width='140' align='left'>"  + OrderContent + "</td><td width='25' align='right'>" + Amount + "</td><td width='50' align='right'>" + formatToMoney(Price) + "</td><td align='right'>" + formatToMoney(Price*Amount) + "</td></tr></table>"
                + "<div style='padding-top:5px;'></div>";
                /*"<div style='float:left;'>(" + OrderDetailIndex + "/" + OrderDetailCount + ")&nbsp;</div>"
                + "<div style='float:left;width:222px;padding-bottom:5px;'>" + OrderContent 
                + "<br />单价：" + formatToMoney(Price)
                + "&nbsp;份数：" + Amount
                + "&nbsp;小计：" + formatToMoney(Price*Amount)
                + "</div>"
                ;*///+ "&nbsp;[豆丁网]";
                /* "#" + OrderId + " " + OrderDetailIndex + "/" + OrderCount
                + " 单价：" + formatToMoney(Price) + "元 总价：" + formatToMoney(Total) + "元"
                + "<br />姓名：" + Name
                + " 电话：" + Phone
                + "<br />地址：" + Address
                + "<br />送达时间：" + formatDateTimeFromDateStr(DeliverDate, 1)
                + "<br />餐品内容：" + OrderContent + "&nbsp;[豆丁网]";*/
            return divContainer;
        }
        function createContainer3(Total,Count)
        {
            var divContainer = document.createElement("div");  
            //divContainer.className = "OrderItemBottom";
            divContainer.innerHTML = "总份数：<b>" + Count + "份</b>&nbsp;&nbsp;&nbsp;&nbsp;合计：<b>" + formatToMoney(Total) + "元</b>"
                    + "<div style='border-top:3px double black;width:100%;text-align:center;padding-top:5px;margin-top:15px;'></div>";
            
            return divContainer;
        }
        function renderData()
        {
            var divPart = createPart();
            divPart.className = "PagePartFirst";
            for (var i = 1; i <= oOrderInfos.length; i ++)
            {    
                //if (i % 2 == 0) $(oOrderInfos[i-1]).css("background-color", "#f3f3f3");
                divPart.appendChild(oOrderInfos[i-1]);
                if (i == oOrderInfos.length)
                {
                    $("#form1").append(divPart);
                    break;
                }
                if (i % 30 == 0 && i != 1)
                {
                    $("#form1").append(divPart);
                    var divPart = createPart();
                }
            }
        }
        
        function print()
        {
            var isAllow='<%=IsAllow %>';
            if(isAllow=="False")
            {
                alert("您还没有权限使用此功能，请赶快申请许可证。");
                return;
            }
            if (window.confirm("您确定现在开始打印吗?"))
            {
                
                gWB.execwb(6, 6);
            }
        }
        
        function printPreview()
        {
            gWB.execwb(7, 1);
        }
        
        function printSetup()
        {
            gWB.execwb(8, 1);
        }
    </script>

    <style type="text/css">
        .nextPage{page-break-after: always} 
        body, td
        {
            font-size:12px;
            font-family:'宋体', MS Reference Sans Serif;
        }
        body
        {
            margin:0px;
            padding:0px;
        }
        form
        {
            margin:0px;
            padding:0px;
        }
        .noprint
        {
            padding:5px;
            text-align:center;display:none;
        }
        .Item
        {
            
            width:264px;
            <%--height:111px;--%>
            <%--height:112px;--%>
            float:left;
            overflow:hidden;
            border:0px solid #ccc;
        }
        .Item 
        {
            margin-left:5px;
        }
        .Container
        {
            margin-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;
        }
        .PagePartFirst
        {
            float:left;
            border:0px solid #FFF;
            margin-top:0px;width:264px;
        }
        .PagePart
        {
            float:left;
            border:1px solid #ccc;
            margin-top:20px;
        }        
        .OrderItemTop
        {
            border-bottom:1px dashed #000;padding-left:0px;margin-bottom:5px;
        }
        .OrderItemBottom
        {
            border-top:1px dashed #000;padding-left:0px;padding-top:5px;padding-bottom:20px;
        }
    </style>
    <style type="text/css" media="print">
        .nextPage{page-break-after: always} 
        .noprint
        {
            display:none;
        }
        .Item
        {
            
            width:264px;
            <%--height:111px;--%>
            <%--height:112px;--%>
            float:left;
            overflow:hidden;
            border:0px solid #ccc;
        }
        .Item 
        {
            margin-left:5px;
        }
        .Container
        {
            margin-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;
        }
        .PagePartFirst
        {
            float:left;
            border:0px solid #FFF;
            margin-top:0px;width:264px;
        }
        .PagePart
        {
            float:left;
            border:1px solid #ccc;
            margin-top:20px;
        }        
        .OrderItemTop
        {
            border-bottom:1px dashed #000;padding-left:0px;margin-bottom:5px;
        }
        .OrderItemBottom
        {
            border-top:1px dashed #000;padding-left:0px;padding-top:5px;padding-bottom:20px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <object id="wb" height="0" width="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"
            name="wb">
        </object>
        <div class="noprint">
            <input id="btnPrint" type="button" value="直接打印" />
            <input id="btnPrintSetup" type="button" value="页面设置" />
            <input id="btnPrintPreview" type="button" value="打印预览" />
            <hr />
        </div>
    </form>
</body>
</html>
