<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CreateDoc.aspx.cs" Inherits="WorkFlow.FlowPage.WordOpen.CreateDoc" %>

<!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>
</head>
<body style="text-align: center;">
    <form id="form1" name="myform" action="#">
    <% //获取服务器的地址
        string URL = this.Session["URL"].ToString();
        string ID;
        string DocType;
        string DocTitle = "";
        //起草文件,则ID为NULL,否则为记录的主键
        ID = Request.QueryString["ID"];
        if (ID == null || ID == "")
        {
            //获取新建文件的类型         
            DocType = Request.Form["DocType"];
        }
        else
        {
            //获取DocTitle
            DocTitle = Request.QueryString["DocTitle"];
            //获取文件的 类型       
            DocType = Request.QueryString["DocType"];
        }
 %>
    <input name="DocTitle" size="14" id="Text1" />
    <input type="button" value="上传到服务器" onclick="return SaveDoc()" />

    <script language="javascript" type="text/javascript">
      var s = ""
s += "<object id=WebOffice1 height=586 width='100%' style='LEFT: 0px; TOP: 0px'  classid='clsid:E77E049B-23FC-4DB8-B756-60529A35FAD5' codebase=WebOffice.cab#V6,0,2,0>"
s +="<param name='_ExtentX' value='6350'><param name='_ExtentY' value='6350'>"
s +="</OBJECT>"
document.write(s)
    </script>

    <script language="javascript" type="text/javascript" for="WebOffice1" event="NotifyCtrlReady">
        WebOffice1_NotifyCtrlReady();
    </script>

    <script language="javascript" type="text/javascript">
    function return_onclick() {
	document.all.WebOffice1.Close();
	window.location.href  = "Default.aspx"
}
        function window_onunload() {
	        document.all.WebOffice1.Close();
        }
        // -----------------------------== 修订文档 ==------------------------------------ //
        function ProtectRevision() {
	        document.all.WebOffice1.SetTrackRevisions(1) 
        }

        // -----------------------------== 隐藏修订 ==------------------------------------ //
        function UnShowRevisions() {
	        document.all.WebOffice1.ShowRevisions(0);
        }
        // --------------------------== 显示当前修订 ==---------------------------------- //
        function ShowRevisions() {
	        document.all.WebOffice1.ShowRevisions(1);
        }
        // -------------------------== 接受当前所有修订 ------------------------------ //
        function AcceptAllRevisions() {
            document.all.WebOffice1.SetTrackRevisions(4);
        }     
     function WebOffice1_NotifyCtrlReady() {
		document.all.WebOffice1.LoadOriginalFile("", "doc");
}
// -----------------------------== 保存文档 ==------------------------------------ //
function SaveDoc() {
	 if(myform.DocTitle.value ==""){
		alert("标题不可为空")
		myform.DocTitle.focus();
		return false;
	}
	//恢复被屏蔽的菜单项和快捷键
    document.all.WebOffice1.SetToolBarButton2("Standard",1,3);
    document.all.WebOffice1.SetToolBarButton2("Standard",2,3);
    document.all.WebOffice1.SetToolBarButton2("Standard",3,3);
    document.all.WebOffice1.SetToolBarButton2("Standard",6,3);           
    <%if (DocType   == "doc") {%>
        //恢复文件菜单项
        document.all.WebOffice1.SetToolBarButton2("Menu Bar",1,4);
        //恢复 保存快捷键(Ctrl+S) 
        document.all.WebOffice1.SetKeyCtrl(595,0,0);
        //恢复 打印快捷键(Ctrl+P) 
        document.all.WebOffice1.SetKeyCtrl(592,0,0);
    <%}else if(DocType   == "xls") {%>
        //恢复文件菜单项
        document.all.WebOffice1.SetToolBarButton2("Worksheet Menu Bar",1,4);         
    <%} %>
//初始化Http引擎
	document.all.WebOffice1.HttpInit();			
//添加相应的Post元素
	<%
	if(ID != ""){          
	%>
	document.all.WebOffice1.SetTrackRevisions(0);
	document.all.WebOffice1.ShowRevisions(0);
	document.all.WebOffice1.HttpAddPostString("ID","<%=ID%>");
	 <%
	 }
	 %>	
	document.all.WebOffice1.HttpAddPostString("DocTitle", myform.DocTitle.value);
	document.all.WebOffice1.HttpAddPostString("DocType","<%=DocType%>");
	//把当前文档添加到Post元素列表中，文件的标识符䶿DocContent
	document.all.WebOffice1.HttpAddPostCurrFile("DocContent","");		// 涓婁紶鏂囦欢
	var vtRet;
    //HttpPost执行上传的动仿WebOffice支持Http的直接上传，在upload.aspx的页面中,解析Post过去的数慿
    //拆分出Post元素和文件数据，可以有选择性的保存到数据库中，或保存在服务器的文件中⾿
	//HttpPost的返回值，根据upload.aspx中的设置，返回upload.aspx中Response.Write回来的数据
	vtRet = document.all.WebOffice1.HttpPost("<%=URL %>/upload.aspx");

 	//alert(vtRet);
 	if("succeed" == vtRet){
		alert("文件上传成功");	
	}else{
		alert("文件上传失败");
	}
	return_onclick(); 
}
    </script>
<span style="color: red">服务器地址:<%=this.Session["URL"].ToString() %> </span>
    </form>
</body>
</html>
