|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing.Printing;
- using System.Threading;
-
- namespace Common.system
- {
-
-
-
-
- public class LatticeFileHelper
- {
-
-
-
- public static Process PrintProcess = null;
-
-
-
-
- private static string LogPath = "";
-
-
-
- public static void RunPrintConfig()
- {
- string Path = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintConfig.exe");
- Process myProcess = new Process();
- LogPath = CreateLog();
- myProcess.StartInfo.FileName = Path;
-
- myProcess.StartInfo.UseShellExecute = false;
- myProcess.StartInfo.RedirectStandardError = true;
- myProcess.StartInfo.CreateNoWindow = true;
- myProcess.StartInfo.RedirectStandardInput = true;
-
- myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
- myProcess.Start();
- myProcess.BeginErrorReadLine();
- myProcess.WaitForExit();
- myProcess.Close();
- myProcess.Dispose();
- }
-
-
-
-
-
-
-
-
-
-
- public static void GeneratingPDF(string PDFPath, string SavePath, out int PrintResult, out string StandardError, out string StandardOutput, int PointType = 0)
- {
-
- string XmlFile = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/print_license.xml");
- string ContentParameter = null;
- ContentParameter = "-sMode=Generate \"-sPDF=" + PDFPath + "\" \"-sLIC=" + XmlFile + "\" \"-oTPF=" + SavePath + "\" \"-dType=" + PointType + "\" ";
- #region 制作点阵文件参数说明
-
-
-
-
-
-
-
-
-
-
- #endregion
- while (PrintProcess != null)
- {
- Thread.Sleep(100);
- }
- Process[] KillProcessArray = Process.GetProcessesByName("PrintTool");
- foreach (Process KillProcess in KillProcessArray)
- {
- KillProcess.Kill();
- }
- PrintProcess = new Process();
- LogPath = CreateLog();
- PrintProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintTool.exe");
- PrintProcess.StartInfo.Arguments = ContentParameter;
- PrintProcess.StartInfo.UseShellExecute = false;
- PrintProcess.StartInfo.RedirectStandardError = true;
- PrintProcess.StartInfo.RedirectStandardOutput = true;
- PrintProcess.StartInfo.CreateNoWindow = true;
- PrintProcess.StartInfo.RedirectStandardInput = true;
-
- PrintProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
- PrintProcess.Start();
- PrintProcess.WaitForExit();
- StandardError = PrintProcess.StandardError.ReadToEnd();
- StandardOutput = PrintProcess.StandardOutput.ReadToEnd();
-
- Output("【制作点阵文件】错误:" + StandardError);
- Output("【制作点阵文件】返回信息:" + StandardOutput);
- PrintResult = PrintProcess.ExitCode;
- Output("【制作点阵文件】" + ContentParameter);
- PrintProcess.Close();
- PrintProcess.Dispose();
- #region 进程是否已经释放
- bool IsRunning = true;
- while (IsRunning)
- {
- IsRunning = false;
- Process[] ProcessArray = Process.GetProcessesByName("PrintTool");
- foreach (Process KillProcess in ProcessArray)
- {
- IsRunning = true;
- Thread.Sleep(100);
- }
- }
- #endregion
- PrintProcess = null;
- }
-
-
-
-
-
-
- public static List<string> GetPrinterList(out string DefaultPrinter)
- {
- List<string> PrintersList = new List<string>();
- DefaultPrinter = null;
- try
- {
- PrintDocument print = new PrintDocument();
- DefaultPrinter = print.PrinterSettings.PrinterName;
- foreach (string sPrint in PrinterSettings.InstalledPrinters)
- {
- PrintersList.Add(sPrint);
- }
- }
- catch (Exception)
- {
-
- }
- return PrintersList;
- }
-
-
-
-
-
-
-
-
-
-
- public static void PrinterTPFFile(string TPFPath, int PrinterNum, string PrinterName, out int PrintResult, out string StandardError, out string StandardOutput)
- {
- TPFPath = TPFPath.Replace("/", "\\");
-
-
- string ContentParameter = null;
- ContentParameter = " -sMode=Print \"-sTPF=" + TPFPath + "\" \"-sPrinter=" + PrinterName + "\" \"-dCopy=" + PrinterNum + "\"";
- #region 打印参数说明
-
-
-
-
-
-
-
-
-
- #endregion
- while (PrintProcess != null)
- {
- Thread.Sleep(100);
- }
- Process[] KillProcessArray = Process.GetProcessesByName("PrintTool");
- foreach (Process KillProcess in KillProcessArray)
- {
- KillProcess.Kill();
- }
- PrintProcess = new Process();
- LogPath = CreateLog();
- PrintProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintTool.exe").Replace("/", "\\"); ;
- PrintProcess.StartInfo.Arguments = ContentParameter;
- PrintProcess.StartInfo.UseShellExecute = false;
- PrintProcess.StartInfo.RedirectStandardError = true;
- PrintProcess.StartInfo.RedirectStandardOutput = true;
- PrintProcess.StartInfo.CreateNoWindow = true;
- PrintProcess.StartInfo.RedirectStandardInput = true;
-
- PrintProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
- PrintProcess.Start();
-
- PrintProcess.WaitForExit();
- StandardError = PrintProcess.StandardError.ReadToEnd();
- StandardOutput = PrintProcess.StandardOutput.ReadToEnd();
- Output("【制作点阵文件】错误:" + StandardError);
- Output("【制作点阵文件】返回信息:" + StandardOutput);
- PrintResult = PrintProcess.ExitCode;
- Output("【打印TPF文件】" + ContentParameter);
- PrintProcess.Close();
- PrintProcess.Dispose();
- #region 进程是否已经释放
- bool IsRunning = true;
- while (IsRunning)
- {
- IsRunning = false;
- Process[] ProcessArray = Process.GetProcessesByName("PrintTool");
- foreach (Process KillProcess in ProcessArray)
- {
- IsRunning = true;
- Thread.Sleep(100);
- }
- }
- #endregion
- PrintProcess = null;
- }
-
-
-
-
-
- private static string CreateLog()
- {
- string LogFileName = DateTime.Now.ToString("yyyyMMdd");
- string LogFilePath = FileToolsCommon.GetFileAbsolutePath("/Log/PrintLog/");
- FileToolsCommon.CreateDirectory(LogFilePath);
- string LogName = LogFilePath + LogFileName + ".log";
- try
- {
- if (!FileToolsCommon.IsExistFile(LogName))
- {
- FileToolsCommon.CreateFile(LogName);
-
-
- return LogName;
- }
- else
- {
- int num = 0;
- while (FileToolsCommon.GetFileSizeByMB(LogName) > 2)
- {
- num++;
- LogName = LogFilePath + LogFileName + "_" + num + ".log";
- FileToolsCommon.CreateFile(LogName);
- }
-
-
- return LogName;
- }
- }
- catch (Exception)
- {
- return LogName;
- }
- }
-
-
-
-
-
- private static void Output(string Message)
- {
- if (!string.IsNullOrEmpty(Message))
- {
- FileToolsCommon.AppendText(LogPath, Message + "\r\n");
- FileToolsCommon.AppendText(LogPath, "\r\n****************************************************************************************************" +
- "****************************************************************************************************\r\n");
- }
- }
-
-
-
-
-
- private static void Output(object sendProcess, DataReceivedEventArgs output)
- {
- Output(output.Data);
- }
- }
- }
|