profile letter
This commit is contained in:
parent
7b8473faef
commit
dc29f2f17c
|
@ -28,6 +28,18 @@
|
|||
<Compile Remove="Process\NotificationProcess.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<COMReference Include="Microsoft.Office.Interop.Word">
|
||||
<WrapperTool>tlbimp</WrapperTool>
|
||||
<VersionMinor>7</VersionMinor>
|
||||
<VersionMajor>8</VersionMajor>
|
||||
<Guid>00020905-0000-0000-c000-000000000046</Guid>
|
||||
<Lcid>0</Lcid>
|
||||
<Isolated>false</Isolated>
|
||||
<EmbedInteropTypes>true</EmbedInteropTypes>
|
||||
</COMReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ease.Core\Ease.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -1,230 +1,230 @@
|
|||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using System.Collections;
|
||||
//using System.Data;
|
||||
//using System.IO;
|
||||
////using Microsoft.Office.Interop;
|
||||
//using Microsoft.Office.Interop.Word;
|
||||
//using System.Reflection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
//using Microsoft.Office.Interop;
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using System.Reflection;
|
||||
|
||||
//namespace HRM.BO
|
||||
//{
|
||||
// public class MSWord
|
||||
// {
|
||||
// private Hashtable _Pair;
|
||||
// private string _OriginalFile;
|
||||
// private string _PreparedFile;
|
||||
// private Application _wordapp;
|
||||
// public MSWord()
|
||||
// {
|
||||
// //_wordapp = null;
|
||||
// }
|
||||
// public Hashtable Pair
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return _Pair;
|
||||
// }
|
||||
// }
|
||||
namespace HRM.BO
|
||||
{
|
||||
public class MSWord
|
||||
{
|
||||
private Hashtable _Pair;
|
||||
private string _OriginalFile;
|
||||
private string _PreparedFile;
|
||||
private Application _wordapp;
|
||||
public MSWord()
|
||||
{
|
||||
//_wordapp = null;
|
||||
}
|
||||
public Hashtable Pair
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Pair;
|
||||
}
|
||||
}
|
||||
|
||||
// public string OriginalFile
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return _OriginalFile;
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// _OriginalFile = value;
|
||||
// }
|
||||
// }
|
||||
public string OriginalFile
|
||||
{
|
||||
get
|
||||
{
|
||||
return _OriginalFile;
|
||||
}
|
||||
set
|
||||
{
|
||||
_OriginalFile = value;
|
||||
}
|
||||
}
|
||||
|
||||
// public string PreparedFile
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return _PreparedFile;
|
||||
// }
|
||||
// }
|
||||
public string PreparedFile
|
||||
{
|
||||
get
|
||||
{
|
||||
return _PreparedFile;
|
||||
}
|
||||
}
|
||||
|
||||
// public void DeleteFile()
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// File.Delete(_PreparedFile);
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
public void DeleteFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(_PreparedFile);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
// private void CreateCopy()
|
||||
// {
|
||||
// string sRoot = Path.GetDirectoryName(_OriginalFile);
|
||||
// string sFileName = Path.GetFileNameWithoutExtension(_OriginalFile);
|
||||
// string sExtention = Path.GetExtension(_OriginalFile);
|
||||
private void CreateCopy()
|
||||
{
|
||||
string sRoot = Path.GetDirectoryName(_OriginalFile);
|
||||
string sFileName = Path.GetFileNameWithoutExtension(_OriginalFile);
|
||||
string sExtention = Path.GetExtension(_OriginalFile);
|
||||
|
||||
// string sNewFileName = sRoot + "\\" + sFileName + DateTime.Now.ToString("hhmmss") + " " + new Random().Next().ToString()
|
||||
// + sExtention;
|
||||
string sNewFileName = sRoot + "\\" + sFileName + DateTime.Now.ToString("hhmmss") + " " + new Random().Next().ToString()
|
||||
+ sExtention;
|
||||
|
||||
// _PreparedFile = sNewFileName;
|
||||
_PreparedFile = sNewFileName;
|
||||
|
||||
// if (File.Exists(OriginalFile) == true)
|
||||
// {
|
||||
// File.Copy(OriginalFile, PreparedFile);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new Exception("File Not Found : " + "File Path : " + _OriginalFile);
|
||||
// }
|
||||
// }
|
||||
if (File.Exists(OriginalFile) == true)
|
||||
{
|
||||
File.Copy(OriginalFile, PreparedFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("File Not Found : " + "File Path : " + _OriginalFile);
|
||||
}
|
||||
}
|
||||
|
||||
// private void CreateCopy(string destFileName)
|
||||
// {
|
||||
// _PreparedFile = destFileName;
|
||||
private void CreateCopy(string destFileName)
|
||||
{
|
||||
_PreparedFile = destFileName;
|
||||
|
||||
// if (File.Exists(OriginalFile) == true)
|
||||
// {
|
||||
// File.Copy(OriginalFile, PreparedFile, true);
|
||||
// FileInfo fi = new FileInfo(PreparedFile);
|
||||
// if (fi.IsReadOnly)
|
||||
// fi.IsReadOnly = false;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new Exception("File Not Found : " + "File Path : " + _OriginalFile);
|
||||
// }
|
||||
// }
|
||||
if (File.Exists(OriginalFile) == true)
|
||||
{
|
||||
File.Copy(OriginalFile, PreparedFile, true);
|
||||
FileInfo fi = new FileInfo(PreparedFile);
|
||||
if (fi.IsReadOnly)
|
||||
fi.IsReadOnly = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("File Not Found : " + "File Path : " + _OriginalFile);
|
||||
}
|
||||
}
|
||||
|
||||
// public void OpenWordApplication()
|
||||
// {
|
||||
// _wordapp = new Microsoft.Office.Interop.Word.Application();
|
||||
// }
|
||||
// public void CloseWordApplication()
|
||||
// {
|
||||
// object SaveChanges = true;
|
||||
// object Missing = System.Reflection.Missing.Value;
|
||||
public void OpenWordApplication()
|
||||
{
|
||||
_wordapp = new Microsoft.Office.Interop.Word.Application();
|
||||
}
|
||||
public void CloseWordApplication()
|
||||
{
|
||||
object SaveChanges = true;
|
||||
object Missing = System.Reflection.Missing.Value;
|
||||
|
||||
// if (_wordapp != null)
|
||||
// _wordapp.Quit(ref SaveChanges, ref Missing, ref Missing);
|
||||
// }
|
||||
if (_wordapp != null)
|
||||
_wordapp.Quit(ref SaveChanges, ref Missing, ref Missing);
|
||||
}
|
||||
|
||||
// public void PrintWordDoc(object[] argValues, String[] argNames)
|
||||
// {
|
||||
// object Missing = System.Reflection.Missing.Value;
|
||||
public void PrintWordDoc(object[] argValues, String[] argNames)
|
||||
{
|
||||
object Missing = System.Reflection.Missing.Value;
|
||||
|
||||
// object wb = _wordapp.WordBasic;
|
||||
object wb = _wordapp.WordBasic;
|
||||
|
||||
// //first arg is a printer name
|
||||
// wb.GetType().InvokeMember("FilePrintSetup", BindingFlags.InvokeMethod, null,
|
||||
// wb, argValues, null, null, argNames);
|
||||
//first arg is a printer name
|
||||
wb.GetType().InvokeMember("FilePrintSetup", BindingFlags.InvokeMethod, null,
|
||||
wb, argValues, null, null, argNames);
|
||||
|
||||
|
||||
// object myTrue = true; // Print in background
|
||||
// object myFalse = false;
|
||||
object myTrue = true; // Print in background
|
||||
object myFalse = false;
|
||||
|
||||
// _wordapp.PrintOutOld(ref myTrue,
|
||||
// ref myFalse, ref Missing, ref Missing, ref Missing,
|
||||
// ref Missing, ref Missing,
|
||||
// ref Missing, ref Missing, ref Missing, ref myFalse,
|
||||
// ref Missing, ref Missing, ref Missing, ref Missing);
|
||||
_wordapp.PrintOutOld(ref myTrue,
|
||||
ref myFalse, ref Missing, ref Missing, ref Missing,
|
||||
ref Missing, ref Missing,
|
||||
ref Missing, ref Missing, ref Missing, ref myFalse,
|
||||
ref Missing, ref Missing, ref Missing, ref Missing);
|
||||
|
||||
// while (_wordapp.BackgroundPrintingStatus > 0)
|
||||
// {
|
||||
// System.Threading.Thread.Sleep(250);
|
||||
// }
|
||||
while (_wordapp.BackgroundPrintingStatus > 0)
|
||||
{
|
||||
System.Threading.Thread.Sleep(250);
|
||||
}
|
||||
|
||||
// }
|
||||
// public void ReplaceWords(string destFileName, Hashtable tagValueHashTable)
|
||||
// {
|
||||
// object SaveChanges = true;
|
||||
// // if (_wordapp == null) OpenWordApplication();
|
||||
}
|
||||
public void ReplaceWords(string destFileName, Hashtable tagValueHashTable)
|
||||
{
|
||||
object SaveChanges = true;
|
||||
// if (_wordapp == null) OpenWordApplication();
|
||||
|
||||
// object Missing = System.Reflection.Missing.Value;
|
||||
object Missing = System.Reflection.Missing.Value;
|
||||
|
||||
// CreateCopy(destFileName);
|
||||
// Microsoft.Office.Interop.Word.Document oDoc = null;
|
||||
// try
|
||||
// {
|
||||
// object FileName = _PreparedFile;
|
||||
// object ReadOnly = false;
|
||||
// object TrueBool = true;
|
||||
// object FalseBool = false;
|
||||
// object IsVisible = true;
|
||||
// object FindText = "";
|
||||
// object ReplaceText = "";
|
||||
CreateCopy(destFileName);
|
||||
Microsoft.Office.Interop.Word.Document oDoc = null;
|
||||
try
|
||||
{
|
||||
object FileName = _PreparedFile;
|
||||
object ReadOnly = false;
|
||||
object TrueBool = true;
|
||||
object FalseBool = false;
|
||||
object IsVisible = true;
|
||||
object FindText = "";
|
||||
object ReplaceText = "";
|
||||
|
||||
|
||||
// oDoc = _wordapp.Documents.Open(ref FileName, ref Missing, ref ReadOnly, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref IsVisible, ref Missing, ref Missing, ref Missing, ref Missing);
|
||||
// oDoc.Activate();
|
||||
oDoc = _wordapp.Documents.Open(ref FileName, ref Missing, ref ReadOnly, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref IsVisible, ref Missing, ref Missing, ref Missing, ref Missing);
|
||||
oDoc.Activate();
|
||||
|
||||
// object FindContinue = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
|
||||
// object ReplaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
|
||||
// object MatchCase = true;
|
||||
// _Pair = (tagValueHashTable != null) ? tagValueHashTable : new Hashtable();
|
||||
// foreach (string sKey in _Pair.Keys)
|
||||
// {
|
||||
// FindText = sKey;
|
||||
// ReplaceText = tagValueHashTable[sKey];
|
||||
// _wordapp.Selection.Find.Execute(ref FindText, ref MatchCase, ref TrueBool, ref Missing, ref Missing, ref Missing, ref TrueBool, ref FindContinue, ref Missing,
|
||||
// ref ReplaceText, ref ReplaceAll, ref Missing, ref Missing, ref Missing, ref Missing);
|
||||
// }
|
||||
object FindContinue = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
|
||||
object ReplaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
|
||||
object MatchCase = true;
|
||||
_Pair = (tagValueHashTable != null) ? tagValueHashTable : new Hashtable();
|
||||
foreach (string sKey in _Pair.Keys)
|
||||
{
|
||||
FindText = sKey;
|
||||
ReplaceText = tagValueHashTable[sKey];
|
||||
_wordapp.Selection.Find.Execute(ref FindText, ref MatchCase, ref TrueBool, ref Missing, ref Missing, ref Missing, ref TrueBool, ref FindContinue, ref Missing,
|
||||
ref ReplaceText, ref ReplaceAll, ref Missing, ref Missing, ref Missing, ref Missing);
|
||||
}
|
||||
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// throw new Exception("Error: Could not read file from disk. Original error: " + ex.Message);
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// if (oDoc != null) _wordapp.Documents.Close(ref SaveChanges, ref Missing, ref Missing);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Error: Could not read file from disk. Original error: " + ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (oDoc != null) _wordapp.Documents.Close(ref SaveChanges, ref Missing, ref Missing);
|
||||
}
|
||||
}
|
||||
|
||||
// public void printDoc()
|
||||
// {
|
||||
// Microsoft.Office.Interop.Word.Application ac = new Microsoft.Office.Interop.Word.Application();
|
||||
// Microsoft.Office.Interop.Word.Application app = ac.Application;
|
||||
public void printDoc()
|
||||
{
|
||||
Microsoft.Office.Interop.Word.Application ac = new Microsoft.Office.Interop.Word.Application();
|
||||
Microsoft.Office.Interop.Word.Application app = ac.Application;
|
||||
|
||||
// // I'm setting all of the alerts to be off as I am trying to get
|
||||
// // this to print in the background
|
||||
// app.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
|
||||
// I'm setting all of the alerts to be off as I am trying to get
|
||||
// this to print in the background
|
||||
app.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
|
||||
|
||||
// // Open the document to print...
|
||||
// object filename = "myFile.rtf";
|
||||
// object missingValue = Type.Missing;
|
||||
// Open the document to print...
|
||||
object filename = "myFile.rtf";
|
||||
object missingValue = Type.Missing;
|
||||
|
||||
// // Using OpenOld so as to be compatible with other versions of Word
|
||||
// Microsoft.Office.Interop.Word.Document document = app.Documents.OpenOld(ref filename,
|
||||
// ref missingValue, ref missingValue,
|
||||
// ref missingValue, ref missingValue, ref missingValue,
|
||||
// ref missingValue, ref missingValue, ref missingValue, ref missingValue);
|
||||
// Using OpenOld so as to be compatible with other versions of Word
|
||||
Microsoft.Office.Interop.Word.Document document = app.Documents.OpenOld(ref filename,
|
||||
ref missingValue, ref missingValue,
|
||||
ref missingValue, ref missingValue, ref missingValue,
|
||||
ref missingValue, ref missingValue, ref missingValue, ref missingValue);
|
||||
|
||||
// // Set the active printer
|
||||
// app.ActivePrinter = "My Printer Name";
|
||||
// Set the active printer
|
||||
app.ActivePrinter = "My Printer Name";
|
||||
|
||||
// object myTrue = true; // Print in background
|
||||
// object myFalse = false;
|
||||
object myTrue = true; // Print in background
|
||||
object myFalse = false;
|
||||
|
||||
// //// Using PrintOutOld to be version independent
|
||||
// //m_App.ActiveDocument.PrintOutOld(ref myTrue,
|
||||
// //ref myFalse, ref missingValue, ref missingValue, ref missingValue,
|
||||
// // missingValue, ref missingValue,
|
||||
// //ref missingValue, ref missingValue, ref missingValue, ref myFalse,
|
||||
// // ref missingValue, ref missingValue, ref m_MissingValue);
|
||||
//// Using PrintOutOld to be version independent
|
||||
//m_App.ActiveDocument.PrintOutOld(ref myTrue,
|
||||
//ref myFalse, ref missingValue, ref missingValue, ref missingValue,
|
||||
// missingValue, ref missingValue,
|
||||
//ref missingValue, ref missingValue, ref missingValue, ref myFalse,
|
||||
// ref missingValue, ref missingValue, ref m_MissingValue);
|
||||
|
||||
// //document.Close(ref missingValue, ref missingValue, ref missingValue);
|
||||
//document.Close(ref missingValue, ref missingValue, ref missingValue);
|
||||
|
||||
// //// Make sure all of the documents are gone from the queue
|
||||
// //while(m_App.BackgroundPrintingStatus > 0)
|
||||
// //{
|
||||
// //System.Threading.Thread.Sleep(250);
|
||||
// //}
|
||||
//// Make sure all of the documents are gone from the queue
|
||||
//while(m_App.BackgroundPrintingStatus > 0)
|
||||
//{
|
||||
//System.Threading.Thread.Sleep(250);
|
||||
//}
|
||||
|
||||
// //app.Quitref missingValue, ref missingValue, ref missingValue);
|
||||
// }
|
||||
//app.Quitref missingValue, ref missingValue, ref missingValue);
|
||||
}
|
||||
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
|
@ -3611,23 +3611,24 @@ namespace HRM.Report
|
|||
|
||||
if (table != null)
|
||||
{
|
||||
//MSWord file = new MSWord();
|
||||
//FileInfo ossInfo = null;
|
||||
////file.OriginalFile = letterTemplte.FilePath.Trim();
|
||||
//file.OriginalFile = System.IO.Path.Combine(System.Environment.CurrentDirectory + "\\Documents\\LetterTempFolder\\" + lFileName);
|
||||
|
||||
//ossInfo = new FileInfo(sFilePath);
|
||||
//if (ossInfo.Exists)
|
||||
//{
|
||||
// ossInfo.Delete();
|
||||
//}
|
||||
//File.Copy(file.OriginalFile, sFilePath, true);
|
||||
//file = new MSWord();
|
||||
//file.OpenWordApplication();
|
||||
MSWord file = new MSWord();
|
||||
FileInfo ossInfo = null;
|
||||
//file.OriginalFile = letterTemplte.FilePath.Trim();
|
||||
//file.ReplaceWords(sFilePath, table);
|
||||
file.OriginalFile = System.IO.Path.Combine(System.Environment.CurrentDirectory + "\\Documents\\LetterTempFolder\\" + lFileName);
|
||||
|
||||
//file.CloseWordApplication();
|
||||
ossInfo = new FileInfo(sFilePath);
|
||||
if (ossInfo.Exists)
|
||||
{
|
||||
ossInfo.Delete();
|
||||
}
|
||||
File.Copy(file.OriginalFile, sFilePath, true);
|
||||
file = new MSWord();
|
||||
file.OpenWordApplication();
|
||||
//file.OriginalFile = letterTemplte.FilePath.Trim();
|
||||
file.OriginalFile = System.IO.Path.Combine(System.Environment.CurrentDirectory + "\\Documents\\LetterTempFolder\\" + lFileName);
|
||||
file.ReplaceWords(sFilePath, table);
|
||||
|
||||
file.CloseWordApplication();
|
||||
|
||||
}
|
||||
return sFilePath;
|
||||
|
|
Loading…
Reference in New Issue
Block a user