<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page
	import="com.zhuozhengsoft.pageoffice.*,com.zhuozhengsoft.pageoffice.wordwriter.*,java.awt.*,javax.servlet.*,javax.servlet.http.*,java.sql.*,java.text.SimpleDateFormat,java.util.Date"%>
<%@ taglib uri="http://java.pageoffice.cn" prefix="po"%>
<%
	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();
	String id = request.getParameter("ID");
	ResultSet rs = stmt.executeQuery("select * from leaveRecord where ID = " + id);

	String docSubject = "", docName = "", docDept = "", docCause = "", docNum = "", docFile = "", docSubmitTime = "";
	if (rs.next()) {
		docFile = rs.getString("FileName");
		docName = rs.getString("Name");
		docDept = rs.getString("Dept");
		docCause = rs.getString("Cause");
		docNum = rs.getString("Num");
		docSubmitTime = rs.getString("SubmitTime");
	}
	rs.close();
	stmt.close();
	conn.close();

	//-----------  PageOffice 服务器端编程开始  -------------------//

	WordDocument doc = new WordDocument();
	doc.setDisableWindowRightClick(true);
	doc.openDataRegion("PO_name").setValue(docName);
	doc.openDataRegion("PO_dept").setValue(docDept);
	doc.openDataRegion("PO_cause").setValue(docCause);
	doc.openDataRegion("PO_num").setValue(docNum);
	doc.openDataRegion("PO_date").setValue(new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat("yyyy-MM-dd").parse(docSubmitTime)));
	doc.openDataRegion("PO_tip").setValue("");
	
	PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);
	poCtrl1.setServerPage("poserver.do"); //此行必须

	// 设置界面样式
	poCtrl1.setCaption("用户填写请假条");
	poCtrl1.setBorderStyle(BorderStyleType.BorderThin);
	// 添加自定义工具条按钮
	poCtrl1.addCustomToolButton("打印", "poPrint", 1);
	poCtrl1.addCustomToolButton("全屏/还原", "poSetFullScreen", 4);
	//隐藏工具栏
	poCtrl1.setOfficeToolbars(false);
	poCtrl1.setMenubar(false);

	//poCtrl1.setJsFunction_OnWordDataRegionClick("OnWordDataRegionClick()");
	// 设置保存文档的服务器页面
	poCtrl1.setSaveDataPage("SaveData.jsp?ID=" + id);
	////获取数据对象
	poCtrl1.setWriter(doc);
	// 打开文档
	poCtrl1.webOpen("doc/template.doc", OpenModeType.docReadOnly,
			"Tom");
	poCtrl1.setTagId("PageOfficeCtrl1"); //此行必须
	//-----------  PageOffice 服务器端编程结束  -------------------//
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>GenDoc</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema"
			content="http://schemas.microsoft.com/intellisense/ie5">
	</HEAD>
	<body>
		<script type="text/javascript">
			function poPrint() {
				document.getElementById("PageOfficeCtrl1").ShowDialog(4);
			}
			function poSetFullScreen() {
				document.getElementById("PageOfficeCtrl1").FullScreen = !document
						.getElementById("PageOfficeCtrl1").FullScreen;
			}
		</script>
		<form id="Form1" method="post">
			<po:PageOfficeCtrl id="PageOfficeCtrl1" />
		</form>
	</body>
</HTML>

