115 lines
3.4 KiB
C#
115 lines
3.4 KiB
C#
// ========================================================================
|
|
// Copyright 2006 - Volian Enterprises, Inc. All rights reserved.
|
|
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
|
|
// ------------------------------------------------------------------------
|
|
// $Workfile: $ $Revision: $
|
|
// $Author: $ $Date: $
|
|
//
|
|
// $History: $
|
|
// ========================================================================
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Collections;
|
|
using System.ComponentModel;
|
|
using System.Windows.Forms;
|
|
using System.Data;
|
|
using System.Data.OleDb;
|
|
using System.Collections.Specialized;
|
|
using System.Collections.Generic;
|
|
using System.Xml;
|
|
using System.IO;
|
|
using System.Text;
|
|
using Volian.MSWord;
|
|
using VEPROMS.CSLA.Library;
|
|
|
|
namespace DataLoader
|
|
{
|
|
public partial class Loader
|
|
{
|
|
private void SaveSectionDocument(string fname, string stpseq, ref int cid)
|
|
{
|
|
int docid = SaveWordDoc(fname);
|
|
switch (docid)
|
|
{
|
|
case 0:
|
|
// could add the following back in - but many of these may be put out in the log, and
|
|
// don't supply any pertinent info.
|
|
//log.InfoFormat("Timing problem for save of word document, will retry. oldstepsequence = {0}", stpseq);
|
|
break;
|
|
case -1:
|
|
log.ErrorFormat("Could not complete save of word document, oldstepsequence = {0}", stpseq);
|
|
break;
|
|
default:
|
|
cid = docid;
|
|
break;
|
|
}
|
|
}
|
|
private int SaveWordDoc(string fname, string title, ConfigInfo ci)
|
|
{
|
|
int docid = 0;
|
|
if (System.IO.File.Exists(fname))
|
|
{
|
|
if (frmMain.cbSaveDocChecked)
|
|
{
|
|
WordDoc d = new WordDoc(fname);
|
|
string temppath = Path.GetTempFileName();
|
|
string s = d.Save(temppath);
|
|
d.Close();
|
|
WaitMS(wms);
|
|
docid = SaveDoc(temppath, title, ci);
|
|
File.Delete(temppath);
|
|
}
|
|
else
|
|
{
|
|
if (frmMain.cbSaveRTFChecked)
|
|
docid = SaveDoc(fname, title, ci);
|
|
}
|
|
}
|
|
else
|
|
log.ErrorFormat("Missing rtf file: {0}", fname);
|
|
return docid;
|
|
}
|
|
private int SaveWordDoc(string temppath)
|
|
{
|
|
return SaveWordDoc(temppath, String.Empty, null);
|
|
}
|
|
private int SaveTheDoc(string temppath, string title, ConfigInfo ci)
|
|
{
|
|
try
|
|
{
|
|
FileStream fs = File.Open(temppath, FileMode.Open, FileAccess.Read, FileShare.None);
|
|
long len = fs.Length + 1;
|
|
byte[] ByteArray = new byte[len];
|
|
int nBytesRead = fs.Read(ByteArray, 0, (int)len);
|
|
fs.Close();
|
|
string t1 = (title == null || title == "") ? null : title;
|
|
Document doc = Document.MakeDocument(t1, ByteArray, null, ci == null ? null : ci.ToString(), DateTime.Now, "Migration");
|
|
return doc.DocID;
|
|
}
|
|
// for an io exception, keep trying
|
|
catch (IOException)
|
|
{
|
|
Wait(2);
|
|
return 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error("Save Word Doc");
|
|
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
|
|
return -1;
|
|
}
|
|
|
|
}
|
|
private int SaveDoc(string temppath, string title, ConfigInfo ci)
|
|
{
|
|
int done = 0;
|
|
int ntry = 0;
|
|
while (done == 0 && ntry < 4)
|
|
{
|
|
ntry++;
|
|
done = SaveTheDoc(temppath, title, ci);
|
|
}
|
|
return done;
|
|
}
|
|
}
|
|
} |