<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page
	import="com.zhuozhengsoft.pageoffice.*,com.zhuozhengsoft.pageoffice.excelwriter.*,java.awt.*,javax.servlet.*,javax.servlet.http.*,java.sql.*,java.text.SimpleDateFormat,java.util.Date"%>
<%@ taglib uri="http://java.pageoffice.cn" prefix="po"%>
<%
	Object userName = session.getAttribute("UserName");
	if (userName == null || userName.toString().length() <= 0) {
		response.sendRedirect("login.jsp?tz=true");
	}
	String id = request.getParameter("ID");
	if (id == null || id.trim().length() <= 0) {
		response.sendRedirect("OrderList.jsp");
	}
	Workbook wb = new Workbook();
	Sheet sheet = wb.openSheet("销售订单");
	//避免单元格内公式被覆盖，将其设为只读
	Cell cI6 = sheet.openCell("I6");
	cI6.setReadOnly(true);
	Cell cI16 = sheet.openCell("I16");
	cI16.setReadOnly(true);
	if (id != null && id.length() > 0) {
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//载入驱动程序类别
		String strUrl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="
				+ this.getServletContext().getRealPath("demodata/")
				+ "\\demo.mdb";
		Connection conn = DriverManager.getConnection(strUrl);
		Statement stmt = conn.createStatement();
		ResultSet rs = stmt
				.executeQuery("select * from OrderMaster where ID="
						+ id);
		if (rs.next()) {
			sheet.openCell("D5").setValue(rs.getString("CustName"));
			sheet.openCell("D5").setSubmitName("CustName");
			sheet.openCell("I5").setValue(rs.getString("OrderNum"));
			sheet.openCell("I5").setSubmitName("OrderNum");
			sheet.openCell("D6").setValue(rs.getString("CustDistrict"));
			sheet.openCell("D6").setSubmitName("CustDistrict");
			cI6.setValue(rs.getString("OrderDate"));
			cI6.setSubmitName("OrderDate");
			sheet.openCell("D18").setValue(rs.getString("MakerName"));
			sheet.openCell("H18").setValue(rs.getString("SalesName"));
			sheet.openCell("H18").setSubmitName("SalesName");
			cI16.setSubmitName("Amount");

			String orderId = rs.getString("ID");
			rs = stmt
					.executeQuery("select * from OrderDetail where OrderID="
							+ orderId);

			Table table = sheet.openTable("C9:H15");
			Table table2 = sheet.openTable("D9:D15");
			table2.setReadOnly(true);//避免单元格内公式被覆盖，将其设为只读
			table.setSubmitName("OrderDetail");

			String proCode = "";
			String type = "";
			String unit = "";
			String quantity = "";
			String price = "";

			while (rs.next()) {
				proCode = rs.getString("ProductCode");
				type = rs.getString("ProductType");
				unit = rs.getString("Unit");
				quantity = rs.getString("Quantity");
				price = rs.getString("Price");

				table.getDataFields().get(0).setValue(proCode);
				table.getDataFields().get(2).setValue(type);
				table.getDataFields().get(3).setValue(unit);
				table.getDataFields().get(4).setValue(quantity);
				table.getDataFields().get(5).setValue(price);
				//循环下一行
				table.nextRow();
			}
			table.close();
		}

		rs.close();
		stmt.close();
		conn.close();
	}
	wb.setDisableSheetRightClick(true);
	
	PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);
	poCtrl1.setServerPage("poserver.do"); //此行必须
	String fileName = "OrderForm.xls";
	poCtrl1.setWriter(wb);
	// 创建自定义菜单栏
	poCtrl1.addCustomToolButton("保存", "SaveDocument()", 1);
	poCtrl1.addCustomToolButton("全屏切换", "SetFullScreen()", 4);

	poCtrl1.setMenubar(false);//隐藏菜单栏
	poCtrl1.setOfficeToolbars(false);//隐藏工具栏
	
	poCtrl1.setSaveDataPage("Update.jsp?ID=" + id);
	poCtrl1.webOpen("doc/" + fileName, OpenModeType.xlsSubmitForm, "");
	poCtrl1.setTagId("PageOfficeCtrl1"); //此行必须
%>
<!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>
		<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
		<link rel="stylesheet" type="text/css" href="css/style.css">
		<!--[if lte IE 6]>
<script type="text/javascript" src="js/belatedPNG.js"></script>
<script type="text/javascript">
  DD_belatedPNG.fix('.png_bg,.png_bg a:hover,img,li'); 
</script>
<![endif]-->
		<title>销售订单</title>
	</head>
	<body>
		<!--header-->
		<div class="zz-headBox clearfix">
			<div class="zz-head mc">
				<!--logo-->
				<div class="logo fl">
					<a href="home.html"> <img src="images/logo.png" alt="" />
					</a>
				</div>
				<!--logo end-->
				<ul class="head-rightUl fr">
					<li><a href="http://www.zhuozhengsoft.com" target="_blank">卓正网站</a></li>
                <li><a href="http://www.zhuozhengsoft.com/poask/index.asp" target="_blank">客户问吧</a></li>
                <li class="bor-0"><a href="http://www.zhuozhengsoft.com/contact-us.html" target="_blank">联系我们</a></li>
				</ul>
			</div>
		</div>
		<!--header end-->
		<!--a title-->
		<div class=" topTitle">
			<ul>
				<li class="pd-left">
					销售订单管理系统示例
				</li>
				<li>
					<font>当前用户：</font><%=userName%></li>
				<li>
					<font>当前系统日期：</font><%=new SimpleDateFormat("yyyy/MM/dd").format(new Date())%></li>
				<li>
					<font>当前模块：</font>修改订单
				</li>
			</ul>
		</div>
		<!--content-->
		<div class="zz-content mc clearfix pd-28">
			<!--left-->
			<div class="zz-contentLeft fl">
				<ul class="left-ul">
					<h2 class="fs-12">
						用户功能区
					</h2>
					<li>
						<a href="OrderList.jsp">订单列表</a>
					</li>
					<li>
						<a href="NewOrder.jsp">新建订单</a>
					</li>
					<li>
						<a href="OrderStat.jsp">统计图表</a>
					</li>
					<li>
						<a href="OrderStat2.jsp">查询表</a>
					</li>
					<li class="bo-n">
						<a href="logout.jsp">退出系统</a>
					</li>
				</ul>
			</div>
			<div class="zz-contentRight fl">
				<!--表格内容-->
				<div style="width: 860px; height: 750px;">
					<!-- *********************pageoffice组件的使用 **************************-->
					<script language="javascript">
						function SaveDocument(data) {
							document.getElementById("PageOfficeCtrl1").WebSave();
							if (document.getElementById("PageOfficeCtrl1").CustomSaveResult != "error") {
								alert('保存成功！');
								location.href = "OrderList.jsp";
							}
						}
						function SetFullScreen() {
							document.getElementById("PageOfficeCtrl1").FullScreen = !document
									.getElementById("PageOfficeCtrl1").FullScreen;
						}
					</script>
					<po:PageOfficeCtrl id="PageOfficeCtrl1" />
					<!-- *********************pageoffice组件的使用 **************************-->
				</div>
			</div>
			<!--内容区-->
		</div>
		<!--content end-->
		<!--footer-->
		<div class="login-footer clearfix">
			Copyright 2012 北京卓正志远软件有限公司
		</div>
		<!--footer end-->
	</body>
</html>
