📄 ncore.cs
字号:
/*
* EBI-Software all rights reserved.
* webmaster@ebi-software.de
* This code is only for educational use.
*/
using System;
using System.IO;
using System.Runtime;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.Shared;
using CrystalDecisions.Web.HtmlReportRender;
using System.Runtime.InteropServices;
using EBIsagt.Windows;
using EBIsagt.Windows.API;
namespace EBIsagt.Cnv
{ /// <summary>
/// nCore wie der Name schon besagt Kernstück der Konvertierung,
/// und stellt ein Basis interface für die Datei Erkennung zur Verfügung.
/// <author>
/// Stefan Eberhardt, Stefan_Eberhardt@EBI-Software.de
/// </author>
/// </summary>
public class nCore
{
private static object Unknown =Type.Missing;
private static string scrfile=null;//"d:\\1.ppt";//für debug
private static int CnvID;
private static bool silent= false;
private static string dstfile=null;//"d:\\2.wmf";//für debug
private static string Database="DtoD.mdb";
private static string WorkDir= "C:\\";
/// <summary>
///
/// </summary>
// append unten
public string[] ExtStrings =// CnvOkay beachten
{
"TXT","RTF","DOC","HTM","PPT","PDF","GIF"
,"WMF","EMF","BMP","EXIF","ICO","JPG"
,"PNG","TIF","XLS","WK4","WRI","WPS"};
/// <summary>
/// Unterstütze Dateitypen, neue Datei-Erweiterungen müssen hier eingefügt werden.
/// </summary>
private enum Cnvs : int // CnvOkay beachten
{
TXT = 0,
RTF = 1,
DOC = 2,
HTM = 3,
PPT = 4,
PDF = 5,
GIF = 6,
WMF = 7,
EMF = 8,
BMP = 9,
EXIF=10,
ICO =11,
JPG =12,
PNG =13,
TIF =14,
XLS =15,
WK4 =16,
WRI =17,
WPS =18,
}
/// <summary>
/// Die Konvertierungen die bereits unterstützt werden
/// </summary>
private const int HTM2HTM =((int)(Cnvs.HTM) << 8 )|((int)(Cnvs.HTM));
private const int HTM2DOC =((int)(Cnvs.HTM) << 8 )|((int)(Cnvs.DOC));
private const int DOC2HTM =((int)(Cnvs.DOC) << 8 )|((int)(Cnvs.HTM));
private const int PPT2PDF =((int)(Cnvs.PPT) << 8 )|((int)(Cnvs.PDF));
private const int PPT2WMF =((int)(Cnvs.PPT) << 8 )|((int)(Cnvs.WMF));
private const int TXT2TXT =((int)(Cnvs.TXT) << 8 )|((int)(Cnvs.TXT));
private const int DOC2RTF =((int)(Cnvs.DOC) << 8 )|((int)(Cnvs.RTF));
private const int HTM2RTF =((int)(Cnvs.HTM) << 8 )|((int)(Cnvs.RTF));
private const int RTF2HTM =((int)(Cnvs.RTF) << 8 )|((int)(Cnvs.HTM));
private const int RTF2DOC =((int)(Cnvs.RTF) << 8 )|((int)(Cnvs.DOC));
private const int GIF2EMF =((int)(Cnvs.GIF) << 8 )|((int)(Cnvs.EMF));
private const int BMP2EMF =((int)(Cnvs.BMP) << 8 )|((int)(Cnvs.EMF));
private const int EXIF2EMF=((int)(Cnvs.EXIF)<< 8 )|((int)(Cnvs.EMF));
private const int ICO2EMF =((int)(Cnvs.ICO) << 8 )|((int)(Cnvs.EMF));
private const int JPG2EMF =((int)(Cnvs.JPG) << 8 )|((int)(Cnvs.EMF));
private const int PNG2EMF =((int)(Cnvs.PNG) << 8 )|((int)(Cnvs.EMF));
private const int TIF2EMF =((int)(Cnvs.TIF) << 8 )|((int)(Cnvs.EMF));
private const int WMF2EMF =((int)(Cnvs.WMF) << 8 )|((int)(Cnvs.EMF));
private const int GIF2BMP =((int)(Cnvs.GIF) << 8 )|((int)(Cnvs.BMP));
private const int BMP2BMP =((int)(Cnvs.BMP) << 8 )|((int)(Cnvs.BMP));//Weil ich kann :-)
private const int EXIF2BMP=((int)(Cnvs.EXIF)<< 8 )|((int)(Cnvs.BMP));
private const int ICO2BMP =((int)(Cnvs.ICO) << 8 )|((int)(Cnvs.BMP));
private const int JPG2BMP =((int)(Cnvs.JPG) << 8 )|((int)(Cnvs.BMP));
private const int PNG2BMP =((int)(Cnvs.PNG) << 8 )|((int)(Cnvs.BMP));
private const int TIF2BMP =((int)(Cnvs.TIF) << 8 )|((int)(Cnvs.BMP));
private const int WMF2BMP =((int)(Cnvs.WMF) << 8 )|((int)(Cnvs.BMP));
private const int EMF2BMP =((int)(Cnvs.EMF) << 8 )|((int)(Cnvs.BMP));
private const int PPT2HTM =((int)(Cnvs.PPT) << 8 )|((int)(Cnvs.HTM));
private const int HTM2PPT =((int)(Cnvs.HTM) << 8 )|((int)(Cnvs.PPT));
private const int GIF2PDF =((int)(Cnvs.GIF) << 8 )|((int)(Cnvs.PDF));
private const int BMP2PDF =((int)(Cnvs.BMP) << 8 )|((int)(Cnvs.PDF));
private const int EXIF2PDF=((int)(Cnvs.EXIF)<< 8 )|((int)(Cnvs.PDF));
private const int ICO2PDF =((int)(Cnvs.ICO) << 8 )|((int)(Cnvs.PDF));
private const int JPG2PDF =((int)(Cnvs.JPG) << 8 )|((int)(Cnvs.PDF));
private const int PNG2PDF =((int)(Cnvs.PNG) << 8 )|((int)(Cnvs.PDF));
private const int TIF2PDF =((int)(Cnvs.TIF) << 8 )|((int)(Cnvs.PDF));
private const int WMF2PDF =((int)(Cnvs.WMF) << 8 )|((int)(Cnvs.PDF));
private const int EMF2PDF =((int)(Cnvs.EMF) << 8 )|((int)(Cnvs.PDF));
private const int GIF2RTF =((int)(Cnvs.GIF) << 8 )|((int)(Cnvs.RTF));
private const int BMP2RTF =((int)(Cnvs.BMP) << 8 )|((int)(Cnvs.RTF));
private const int EXIF2RTF=((int)(Cnvs.EXIF)<< 8 )|((int)(Cnvs.RTF));
private const int ICO2RTF =((int)(Cnvs.ICO) << 8 )|((int)(Cnvs.RTF));
private const int JPG2RTF =((int)(Cnvs.JPG) << 8 )|((int)(Cnvs.RTF));
private const int PNG2RTF =((int)(Cnvs.PNG) << 8 )|((int)(Cnvs.RTF));
private const int TIF2RTF =((int)(Cnvs.TIF) << 8 )|((int)(Cnvs.RTF));
private const int WMF2RTF =((int)(Cnvs.WMF) << 8 )|((int)(Cnvs.RTF));
private const int EMF2RTF =((int)(Cnvs.EMF) << 8 )|((int)(Cnvs.RTF));
private const int GIF2HTM =((int)(Cnvs.GIF) << 8 )|((int)(Cnvs.HTM));
private const int BMP2HTM =((int)(Cnvs.BMP) << 8 )|((int)(Cnvs.HTM));
private const int EXIF2HTM=((int)(Cnvs.EXIF)<< 8 )|((int)(Cnvs.HTM));
private const int ICO2HTM =((int)(Cnvs.ICO) << 8 )|((int)(Cnvs.HTM));
private const int JPG2HTM =((int)(Cnvs.JPG) << 8 )|((int)(Cnvs.HTM));
private const int PNG2HTM =((int)(Cnvs.PNG) << 8 )|((int)(Cnvs.HTM));
private const int TIF2HTM =((int)(Cnvs.TIF) << 8 )|((int)(Cnvs.HTM));
private const int WMF2HTM =((int)(Cnvs.WMF) << 8 )|((int)(Cnvs.HTM));
private const int EMF2HTM =((int)(Cnvs.EMF) << 8 )|((int)(Cnvs.HTM));
private const int HTM2PDF =((int)(Cnvs.HTM) << 8 )|((int)(Cnvs.PDF));
private const int DOC2PDF =((int)(Cnvs.DOC) << 8 )|((int)(Cnvs.PDF));
private const int RTF2PDF =((int)(Cnvs.RTF) << 8 )|((int)(Cnvs.PDF));
private const int TXT2PDF =((int)(Cnvs.TXT) << 8 )|((int)(Cnvs.PDF));
private const int HTM2XLS =((int)(Cnvs.HTM) << 8 )|((int)(Cnvs.XLS));
private const int DOC2XLS =((int)(Cnvs.DOC) << 8 )|((int)(Cnvs.XLS));
private const int TXT2XLS =((int)(Cnvs.TXT) << 8 )|((int)(Cnvs.XLS));
private const int GIF2XLS =((int)(Cnvs.GIF) << 8 )|((int)(Cnvs.XLS));
private const int BMP2XLS =((int)(Cnvs.BMP) << 8 )|((int)(Cnvs.XLS));
private const int EXIF2XLS=((int)(Cnvs.EXIF)<< 8 )|((int)(Cnvs.XLS));
private const int ICO2XLS =((int)(Cnvs.ICO) << 8 )|((int)(Cnvs.XLS));
private const int JPG2XLS =((int)(Cnvs.JPG) << 8 )|((int)(Cnvs.XLS));
private const int PNG2XLS =((int)(Cnvs.PNG) << 8 )|((int)(Cnvs.XLS));
private const int TIF2XLS =((int)(Cnvs.TIF) << 8 )|((int)(Cnvs.XLS));
private const int WMF2XLS =((int)(Cnvs.WMF) << 8 )|((int)(Cnvs.XLS));
private const int EMF2XLS =((int)(Cnvs.EMF) << 8 )|((int)(Cnvs.XLS));
///////////////////////////
private const int DOC2TXT =((int)(Cnvs.DOC) << 8 )|((int)(Cnvs.TXT));
private const int WK42HTM =((int)(Cnvs.WK4) << 8 )|((int)(Cnvs.HTM));
private const int WRI2HTM =((int)(Cnvs.WRI) << 8 )|((int)(Cnvs.HTM));
private const int WPS2HTM =((int)(Cnvs.WPS) << 8 )|((int)(Cnvs.HTM));
private const int WK42DOC =((int)(Cnvs.WK4) << 8 )|((int)(Cnvs.DOC));
private const int WRI2DOC =((int)(Cnvs.WRI) << 8 )|((int)(Cnvs.DOC));
private const int WPS2DOC =((int)(Cnvs.WPS) << 8 )|((int)(Cnvs.DOC));
private const int WK42RTF =((int)(Cnvs.WK4) << 8 )|((int)(Cnvs.RTF));
private const int WRI2RTF =((int)(Cnvs.WRI) << 8 )|((int)(Cnvs.RTF));
private const int WPS2RTF =((int)(Cnvs.WPS) << 8 )|((int)(Cnvs.RTF));
private const int WK42TXT =((int)(Cnvs.WK4) << 8 )|((int)(Cnvs.TXT));
private const int WRI2TXT =((int)(Cnvs.WRI) << 8 )|((int)(Cnvs.TXT));
private const int WPS2TXT =((int)(Cnvs.WPS) << 8 )|((int)(Cnvs.TXT));
private const int WK42PDF =((int)(Cnvs.WK4) << 8 )|((int)(Cnvs.PDF));
private const int WRI2PDF =((int)(Cnvs.WRI) << 8 )|((int)(Cnvs.PDF));
private const int WPS2PDF =((int)(Cnvs.WPS) << 8 )|((int)(Cnvs.PDF));
private const int WK42XLS =((int)(Cnvs.WK4) << 8 )|((int)(Cnvs.XLS));
private const int WRI2XLS =((int)(Cnvs.WRI) << 8 )|((int)(Cnvs.XLS));
private const int WPS2XLS =((int)(Cnvs.WPS) << 8 )|((int)(Cnvs.XLS));
private const int TXT2HTM =((int)(Cnvs.TXT) << 8 )|((int)(Cnvs.HTM));
//////////////////////////
/// <summary>
/// Öffnet eine Messagebox mit der übergebenen Fehlermeldung und terminiert,
/// anschliessend das Programm.
/// </summary>
/// <param name="str">Text der Fehlermedung</param>
public static void ErrorHalt(string str)
{
if (!silent) MessageBox.Show(str);
Environment.Exit(0);
}
/// <summary>
/// Öffnet den Dialog für die Input Datei
/// </summary>
/// <returns> 0 wenn alles in Ordnung ist,1 Wenn ein Fehler aufgetreten ist</returns>
public static int SourceFile()
{
OpenFileDialog OFD = new OpenFileDialog();
//OFD.Filter = "Text Datei (*.txt)|*.txt";
OFD.Filter = /*OFD.Filter +*/ "Rich Text Format (*.rtf)|*.rtf";
OFD.Filter = OFD.Filter + "|Word Dokument (*.doc)|*.doc";
//OFD.Filter = OFD.Filter + "|HyperText Markup Language Datein(*.htm*)|*.htm*";
//OFD.Filter = OFD.Filter + "|PowerPoint Datein(*.ppt)|*.ppt";
//OFD.Filter = OFD.Filter + "|Portables Dokumenten Format(*.pdf*)|*.pdf"; //Zukunftsmusik
//OFD.Filter = OFD.Filter + "|Windows Meta File Datein(AutoCAD)(*.wmf)|*.wmf";
//OFD.Filter = OFD.Filter + "|Erweiterte Meta File Datein(*.emf)|*.emf";
//OFD.Filter = OFD.Filter + "|Windows Bitmap(*.bmp)|*.bmp";
//OFD.Filter = OFD.Filter + "|Exchangeable Image File Format(*.exif)|*.exif";
//OFD.Filter = OFD.Filter + "|Windows Icon(*.ico)|*.ico";
//OFD.Filter = OFD.Filter + "|Joint Photographic Experts Group(*.jpg)|*.jpg";
//OFD.Filter = OFD.Filter + "|Portable Network Graphics(*.png)|*.png";
//OFD.Filter = OFD.Filter + "|Tagged Image File Format(*.tif)|*.tif";
//OFD.Filter = OFD.Filter + "|Microsoft Exel Datei(*.xls)|*.xls";
//OFD.Filter = OFD.Filter + "|Lotus 123 Datei(*.wk1,*.wk3,*.wk4)|*.wk*";
//OFD.Filter = OFD.Filter + "|Windows Write Datei(*.wri)|*.wri";
//OFD.Filter = OFD.Filter + "|Microsoft Works Datei(*.wps,*.wpt)|*.wp*";
OFD.InitialDirectory = WorkDir;
OFD.DefaultExt = "txt";
if (OFD.ShowDialog() == DialogResult.OK)
{
scrfile = OFD.FileNames[0].ToLower();
OFD.Dispose();
return 0;
}
else
{
OFD.Dispose();
return 1;}
}
/// <summary>
/// Diese Funktion liefert die ID des DateiTyps zurück.
/// wenn nicht bekannt wird eine Exception geworfen
/// </summary>
/// <param name="Filename">Dateinname mit oder ohne Pfad</param>
/// <returns>ID der Extension</returns>
public static int IDentExt(string Filename)
{
if (Filename.LastIndexOf(".")>-1)
{
string extention = Filename.Substring(Filename.LastIndexOf(".")+1);
switch (extention)
{
case "txt":
return (int)Cnvs.TXT;
case "rtf":
return (int)Cnvs.RTF;
case "doc":
return (int)Cnvs.DOC;
case "htm":
return (int)Cnvs.HTM;
case "html":
return (int)Cnvs.HTM;
case "ppt":
return (int)Cnvs.PPT;
case "pdf":
return (int)Cnvs.PDF;
case "gif":
return (int)Cnvs.GIF;
case "wmf":
return (int)Cnvs.WMF;
case "emf":
return (int)Cnvs.EMF;
case "bmp":
return (int)Cnvs.BMP;
case "exif":
return (int)Cnvs.EXIF;
case "ico":
return (int)Cnvs.ICO;
case "jpg":
return (int)Cnvs.JPG;
case "png":
return (int)Cnvs.PNG;
case "tif":
return (int)Cnvs.TIF;
case "xls":
return (int)Cnvs.XLS;
case "wk1":
return (int)Cnvs.WK4;
case "wk3":
return (int)Cnvs.WK4;
case "wk4":
return (int)Cnvs.WK4;
case "wri":
return (int)Cnvs.WRI;
case "wps":
return (int)Cnvs.WPS;
case "wpt":
return (int)Cnvs.WPS;
default : throw new Exception("Erweiterung unbekannt.");
}
}
else
{
throw new Exception("Mindestens eine Datei Erweiterung fehlt.");
}
}
/// <summary>
/// Erstellt ide Conversion ID die den Input und Output Typ beinhaltet
/// dieser Conversion identifiziert die Konvertierung eindeutig.
/// </summary>
/// <returns>0 alles in Ordnung, 1 Wenn ein fehler aufgetreten ist</returns>
private static int CreateCnvID()
{
try
{
int i = IDentExt(scrfile);
i = i << 8;
CnvID = i | IDentExt(dstfile);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -