<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.io.*,java.text.*,java.util.*,java.sql.*" %>
<%@ page import="net.sz600.database.*" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.weboffice.*" %>
<%@ page import="net.sz600.tool.*" %>
<%

  String mRecordID = request.getParameter("RecordID");
  if (mRecordID==null) mRecordID="";
  String mTemplate=new String(request.getParameter("Template").getBytes("8859_1"));
  //String mSubject=new String(request.getParameter("Subject").getBytes("8859_1"));
  String mSubject=SzConvert.strWriteData(request.getParameter("Subject"));
  String mAuthor=new String(request.getParameter("Author").getBytes("8859_1"));
  String mFileDate=new String(request.getParameter("FileDate").getBytes("8859_1"));
  String mFileType=new String(request.getParameter("FileType").getBytes("8859_1"));
  String mHTMLPath=new String(request.getParameter("HTMLPath").getBytes("8859_1"));
  String mStatus="READ";
  

  iDBManager DbaObj=new iDBManager();
boolean flag = false;
if (DbaObj.OpenConnection())
{
  String mysql="SELECT RecordID from  office_Document Where RecordID='" + mRecordID + "'";
  try
  {
    ResultSet result=DbaObj.ExecuteQuery(mysql) ;
    if (result.next())
    {
      mysql="update office_Document set RecordID=?,Template=?,Subject=?,Author=?,FileDate=?,FileType=?,HtmlPath=?,Status=? where RecordID='"+mRecordID+"'";
    }
    else
    {
      mysql="insert into office_Document (RecordID,Template,Subject,Author,FileDate,FileType,HtmlPath,Status) values (?,?,?,?,?,?,?,?)";
      if (SzConn.sDbName.equals(SzProperties.DbName_MYSQL)) {
    	  mysql="insert into office_Document (RecordID,Template,Subject,Author,FileDate,FileType,HtmlPath,Status,DocumentID) values (?,?,?,?,?,?,?,?,?)";
    	  flag = true;
      }
    }
    result.close();
  }
  catch(Exception e)
  {
      System.out.println(e.toString());
  }
  java.sql.PreparedStatement prestmt=null;
  try
  {
      prestmt=DbaObj.Conn.prepareStatement(mysql);
      prestmt.setString(1,mRecordID);
      prestmt.setString(2,mTemplate);
      prestmt.setString(3,mSubject);
      prestmt.setString(4,mAuthor);
      prestmt.setString(5,mFileDate);
      prestmt.setString(6,mFileType);
      prestmt.setString(7,mHTMLPath);
      prestmt.setString(8,"READ");
      if (SzConn.sDbName.equals(SzProperties.DbName_MYSQL) && flag) {
    	  prestmt.setInt(9, SzKey.getInstance().genNextKey("Document"));
      }
      //DbaObj.Conn.setAutoCommit(false) ;
      prestmt.executeUpdate();
      //DbaObj.Conn.commit();

  }
  catch(Exception e)
  {
      System.out.println(e.toString());
  }
  finally
  {
      prestmt.close();
  }
  DbaObj.CloseConnection() ;
}
else
{
  out.println("OpenDatabase Error") ;
}
//response.sendRedirect("DocumentList.jsp");

%>
