<%@ 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 = "", docDate = "", docFile = "";
	
	//-----------  PageOffice 服务器端编程开始  -------------------//
	if (rs.next()) {
		docFile = rs.getString("FileName");
		docSubject = rs.getString("Subject");
		docName = rs.getString("Name");
		docDept = rs.getString("Dept");
		docCause = rs.getString("Cause");
		docNum = rs.getString("Num");
		docDate = rs.getString("SubmitTime");
	}
	rs.close();
	stmt.close();
	conn.close();

	WordDocument doc = new WordDocument();
	DataRegion drName = doc.openDataRegion("PO_name");
	drName.setValue(docName);
	drName.setEditing(true);
	DataRegion drDept = doc.openDataRegion("PO_dept");
	drDept.setValue(docDept);
	drDept.getShading().setBackgroundPatternColor(Color.GRAY);
	//drDept.setEditing(true);  
	DataRegion drCause = doc.openDataRegion("PO_cause");
	drCause.setValue(docCause);
	drCause.setEditing(true);
	DataRegion drNum = doc.openDataRegion("PO_num");
	drNum.setValue(docNum);
	drNum.setEditing(true);
	DataRegion drDate = doc.openDataRegion("PO_date");
	drDate.setValue(new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat("yyyy-MM-dd").parse(docDate)));
	drDate.getShading().setBackgroundPatternColor(Color.pink);
	//drDate.setEditing(true);
	DataRegion drTip = doc.openDataRegion("PO_tip");
	drTip.getFont().setItalic(true);
	drTip.setValue("提示：带背景色的文字是只能通过选择设置，[]中的文字是可以录入编辑的。");
	
	// 设置PageOffice组件服务页面
	doc.getWaterMark().setText("PageOffice平台");

	PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);
	poCtrl1.setServerPage("poserver.do"); //此行必须

	// 设置界面样式
	poCtrl1.setCaption("用户填写请假条");
	poCtrl1.setBorderStyle(BorderStyleType.BorderThin);
	// 添加自定义工具条按钮
	poCtrl1.addCustomToolButton("保存", "poSave()", 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.docSubmitForm, "Tom");
	poCtrl1.setTagId("PageOfficeCtrl1"); //此行必须
	//-----------  PageOffice 服务器端编程结束  -------------------//
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
	<HEAD>
		<title>用户填写请假条</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 language="JavaScript">
	function OnWordDataRegionClick(Name, Value, Left, Bottom) {
		if (Name == "PO_date") {
			dv = window.showModalDialog(
							"datetimer.htm",
							"44",
							"center:1;help:no;status:no;dialogLeft:" + Left	+ ";dialogTop:" + Bottom + ";dialogHeight:246px;dialogWidth:216px;scroll:no")
			if (dv) {
				if (dv == "null")
					obj.value = '';
				else
					return dv;
			}
		}
		if (Name == "PO_dept") {
			var mObject = new Object();
			mObject.SelectValue = "";
			window.showModalDialog(
							"selectDept.htm",
							mObject,
							"dialogLeft:"+ Left + "px; dialogTop:" + Bottom + "px; dialogHeight:120px; dialogWidth:200px;center:no;scroll:no;status:no;");
			if (mObject.SelectValue != "") {
				return (mObject.SelectValue);
			}
		}
	}
</script>
		<form id="Form1" method="post">

			<!-- *********************pageoffice组件的使用 **************************-->
			<script type="text/javascript">
				//保存
				function poSave() {
					document.getElementById("PageOfficeCtrl1").WebSave();
				}
				//全屏
				function poSetFullScreen() {
					document.getElementById("PageOfficeCtrl1").FullScreen = !document.getElementById("PageOfficeCtrl1").FullScreen;
				}
			</script>
			<po:PageOfficeCtrl id="PageOfficeCtrl1" />
			<!-- *********************pageoffice组件的使用 **************************-->

		</form>
	</body>
</HTML>
