dev_mashfiq #31

Open
Mashfiq wants to merge 8 commits from dev_mashfiq into devqc
3 changed files with 220 additions and 207 deletions
Showing only changes of commit dc29f2f17c - Show all commits

View File

@ -28,6 +28,18 @@
<Compile Remove="Process\NotificationProcess.cs" /> <Compile Remove="Process\NotificationProcess.cs" />
</ItemGroup> </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> <ItemGroup>
<ProjectReference Include="..\Ease.Core\Ease.Core.csproj" /> <ProjectReference Include="..\Ease.Core\Ease.Core.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -1,230 +1,230 @@
//using System; using System;
//using System.Collections.Generic; using System.Collections.Generic;
//using System.Text; using System.Text;
//using System.Collections; using System.Collections;
//using System.Data; using System.Data;
//using System.IO; using System.IO;
////using Microsoft.Office.Interop; //using Microsoft.Office.Interop;
//using Microsoft.Office.Interop.Word; using Microsoft.Office.Interop.Word;
//using System.Reflection; using System.Reflection;
//namespace HRM.BO namespace HRM.BO
//{ {
// public class MSWord public class MSWord
// { {
// private Hashtable _Pair; private Hashtable _Pair;
// private string _OriginalFile; private string _OriginalFile;
// private string _PreparedFile; private string _PreparedFile;
// private Application _wordapp; private Application _wordapp;
// public MSWord() public MSWord()
// { {
// //_wordapp = null; //_wordapp = null;
// } }
// public Hashtable Pair public Hashtable Pair
// { {
// get get
// { {
// return _Pair; return _Pair;
// } }
// } }
// public string OriginalFile public string OriginalFile
// { {
// get get
// { {
// return _OriginalFile; return _OriginalFile;
// } }
// set set
// { {
// _OriginalFile = value; _OriginalFile = value;
// } }
// } }
// public string PreparedFile public string PreparedFile
// { {
// get get
// { {
// return _PreparedFile; return _PreparedFile;
// } }
// } }
// public void DeleteFile() public void DeleteFile()
// { {
// try try
// { {
// File.Delete(_PreparedFile); File.Delete(_PreparedFile);
// } }
// catch catch
// { {
// } }
// } }
// private void CreateCopy() private void CreateCopy()
// { {
// string sRoot = Path.GetDirectoryName(_OriginalFile); string sRoot = Path.GetDirectoryName(_OriginalFile);
// string sFileName = Path.GetFileNameWithoutExtension(_OriginalFile); string sFileName = Path.GetFileNameWithoutExtension(_OriginalFile);
// string sExtention = Path.GetExtension(_OriginalFile); string sExtention = Path.GetExtension(_OriginalFile);
// string sNewFileName = sRoot + "\\" + sFileName + DateTime.Now.ToString("hhmmss") + " " + new Random().Next().ToString() string sNewFileName = sRoot + "\\" + sFileName + DateTime.Now.ToString("hhmmss") + " " + new Random().Next().ToString()
// + sExtention; + sExtention;
// _PreparedFile = sNewFileName; _PreparedFile = sNewFileName;
// if (File.Exists(OriginalFile) == true) if (File.Exists(OriginalFile) == true)
// { {
// File.Copy(OriginalFile, PreparedFile); File.Copy(OriginalFile, PreparedFile);
// } }
// else else
// { {
// throw new Exception("File Not Found : " + "File Path : " + _OriginalFile); throw new Exception("File Not Found : " + "File Path : " + _OriginalFile);
// } }
// } }
// private void CreateCopy(string destFileName) private void CreateCopy(string destFileName)
// { {
// _PreparedFile = destFileName; _PreparedFile = destFileName;
// if (File.Exists(OriginalFile) == true) if (File.Exists(OriginalFile) == true)
// { {
// File.Copy(OriginalFile, PreparedFile, true); File.Copy(OriginalFile, PreparedFile, true);
// FileInfo fi = new FileInfo(PreparedFile); FileInfo fi = new FileInfo(PreparedFile);
// if (fi.IsReadOnly) if (fi.IsReadOnly)
// fi.IsReadOnly = false; fi.IsReadOnly = false;
// } }
// else else
// { {
// throw new Exception("File Not Found : " + "File Path : " + _OriginalFile); throw new Exception("File Not Found : " + "File Path : " + _OriginalFile);
// } }
// } }
// public void OpenWordApplication() public void OpenWordApplication()
// { {
// _wordapp = new Microsoft.Office.Interop.Word.Application(); _wordapp = new Microsoft.Office.Interop.Word.Application();
// } }
// public void CloseWordApplication() public void CloseWordApplication()
// { {
// object SaveChanges = true; object SaveChanges = true;
// object Missing = System.Reflection.Missing.Value; object Missing = System.Reflection.Missing.Value;
// if (_wordapp != null) if (_wordapp != null)
// _wordapp.Quit(ref SaveChanges, ref Missing, ref Missing); _wordapp.Quit(ref SaveChanges, ref Missing, ref Missing);
// } }
// public void PrintWordDoc(object[] argValues, String[] argNames) public void PrintWordDoc(object[] argValues, String[] argNames)
// { {
// object Missing = System.Reflection.Missing.Value; object Missing = System.Reflection.Missing.Value;
// object wb = _wordapp.WordBasic; object wb = _wordapp.WordBasic;
// //first arg is a printer name //first arg is a printer name
// wb.GetType().InvokeMember("FilePrintSetup", BindingFlags.InvokeMethod, null, wb.GetType().InvokeMember("FilePrintSetup", BindingFlags.InvokeMethod, null,
// wb, argValues, null, null, argNames); wb, argValues, null, null, argNames);
// object myTrue = true; // Print in background object myTrue = true; // Print in background
// object myFalse = false; object myFalse = false;
// _wordapp.PrintOutOld(ref myTrue, _wordapp.PrintOutOld(ref myTrue,
// ref myFalse, ref Missing, ref Missing, ref Missing, ref myFalse, ref Missing, ref Missing, 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 myFalse,
// ref Missing, ref Missing, ref Missing, ref Missing); ref Missing, ref Missing, ref Missing, ref Missing);
// while (_wordapp.BackgroundPrintingStatus > 0) while (_wordapp.BackgroundPrintingStatus > 0)
{
System.Threading.Thread.Sleep(250);
}
}
public void ReplaceWords(string destFileName, Hashtable tagValueHashTable)
{
object SaveChanges = true;
// if (_wordapp == null) OpenWordApplication();
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 = "";
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);
}
}
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;
// 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;
// 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";
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);
//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); //System.Threading.Thread.Sleep(250);
//} //}
// } //app.Quitref missingValue, ref missingValue, ref missingValue);
// public void ReplaceWords(string destFileName, Hashtable tagValueHashTable) }
// {
// object SaveChanges = true;
// // if (_wordapp == null) OpenWordApplication();
// 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 = "";
// 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);
// }
// }
// 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;
// // 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;
// // 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";
// 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);
// //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);
// //}
// //app.Quitref missingValue, ref missingValue, ref missingValue);
// }
// }
//}

View File

@ -3611,23 +3611,24 @@ namespace HRM.Report
if (table != null) if (table != null)
{ {
//MSWord file = new MSWord(); MSWord file = new MSWord();
//FileInfo ossInfo = null; 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();
//file.OriginalFile = letterTemplte.FilePath.Trim(); //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; return sFilePath;