You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
286 lines
12 KiB
286 lines
12 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using edoka_dms;
|
|
using DOCGEN.Klassen;
|
|
using Database;
|
|
using System.Data;
|
|
using Model;
|
|
using System.Diagnostics;
|
|
using NLog;
|
|
using System.Security.Policy;
|
|
using OfficePrinter;
|
|
using Syncfusion.XlsIO.Implementation.PivotAnalysis;
|
|
using OnDocOffice;
|
|
using System.Threading;
|
|
using System.IO;
|
|
using Syncfusion.XlsIO.Implementation.XmlSerialization;
|
|
|
|
namespace DOCGEN.Generator
|
|
{
|
|
|
|
public class DocGenerator_from_EDOKA
|
|
{
|
|
public string connectionstring;
|
|
public string DokumentID;
|
|
public string tempdir;
|
|
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
|
|
public string apikey = "";
|
|
public string resturi = "";
|
|
public int Office_Fill_DocIO = 0;
|
|
|
|
public void Lic()
|
|
{
|
|
// 25. string lickey = "Ngo9BigBOggjHTQxAR8/V1NCaF5cXmZCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdnWXdecXRdQ2heUU13XUI="
|
|
//string lickey = "Ngo9BigBOggjHTQxAR8/V1NCaF5cXmZCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdnWXZeeXRQR2NZUEZ2WkE=";
|
|
string lickey = "Ngo9BigBOggjHTQxAR8/V1NCaF1cXGJCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdnWXZeeXRQR2ZfVEV2VkA=";
|
|
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(lickey);
|
|
}
|
|
|
|
public DocGenerator_from_EDOKA(string connectionstring)
|
|
{
|
|
this.connectionstring = connectionstring;
|
|
Lic();
|
|
}
|
|
public DocGenerator_from_EDOKA(string connectionstring, string RestUri, string ApiKey)
|
|
{
|
|
this.connectionstring = connectionstring;
|
|
Lic();
|
|
this.apikey = ApiKey;
|
|
this.resturi = RestUri;
|
|
}
|
|
|
|
public DocGenerator_from_EDOKA(string connectionstring, string tempdir, string RestUri, string ApiKey, int Office_Fill_DocIO)
|
|
{
|
|
this.connectionstring = connectionstring;
|
|
this.tempdir = tempdir;
|
|
this.resturi = RestUri;
|
|
this.apikey = ApiKey;
|
|
this.Office_Fill_DocIO = Office_Fill_DocIO;
|
|
}
|
|
|
|
public clsdok Generate_Doc_EDOKA(string dokumentid, ref clsDocData docdata, bool useoffice = false, int OfficeSleep = 0, bool vbfilemanagement = false, bool editdoc = false)
|
|
{
|
|
if (docdata.Bezeichnung.Contains("QDF"))
|
|
{
|
|
generate_docdata(dokumentid, ref docdata);
|
|
Generate_QDF(dokumentid, ref docdata, tempdir);
|
|
clsdok dokempty = new clsdok("", "", "QDF","");
|
|
return dokempty;
|
|
}
|
|
useoffice = docdata.Erstellung_in_Office;
|
|
try
|
|
{
|
|
if (docdata.FillOffice == true) { Office_Fill_DocIO = 0; } else { Office_Fill_DocIO = 1; }
|
|
}
|
|
catch { Office_Fill_DocIO = 0; }
|
|
|
|
DB db = new DB(connectionstring);
|
|
DataTable dt = new DataTable();
|
|
DataTable dt2 = new DataTable();
|
|
string Apptype = "";
|
|
string Extension = "";
|
|
string Prefix = "";
|
|
Logging.Logging.Debug("Generate_Doc_EDOKA", "Get_Vorlage", dokumentid);
|
|
if (!editdoc)
|
|
{
|
|
dt = db.Get_Vorlage_By_DokumentID(dokumentid, useoffice, tempdir, false);
|
|
}
|
|
else
|
|
{
|
|
dt = db.Get_Vorlage_By_DokumentID(dokumentid, useoffice, tempdir, true);
|
|
|
|
}
|
|
db.dsdaten.Tables.Clear();
|
|
dt2 = db.Get_ApplicationType_from_Vorlage(Convert.ToInt32(dt.Rows[0]["nr"].ToString()));
|
|
Apptype = dt2.Rows[0][0].ToString();
|
|
Extension = dt2.Rows[0][1].ToString();
|
|
Prefix = dt2.Rows[0][2].ToString();
|
|
docdata.prefix = Prefix;
|
|
switch (Apptype.ToUpper())
|
|
{
|
|
case "DOCX": case "DOCM": case "DOC": case "DOT":
|
|
case "WORD": case "DOTM":
|
|
SyncFWord sfword = new SyncFWord(resturi, apikey);
|
|
generate_docdata(dokumentid, ref docdata);
|
|
clsdok dok = new clsdok("", "", "", "");
|
|
if (useoffice == false) {
|
|
Logging.Logging.Debug("Generate_Word", "Start", dokumentid);
|
|
if (docdata.remove_signature)
|
|
{
|
|
Helper.clsFileHelper fh = new Helper.clsFileHelper();
|
|
string filename = tempdir + dokumentid + ".tmp";
|
|
fh.SaveBase64ToFile(dt.Rows[0][0].ToString(), filename);
|
|
|
|
word_signature ws = new word_signature(this.connectionstring);
|
|
ws.remove_unterschriften_synfusion(filename);
|
|
dt.Rows[0][0] = fh.Base64FromFile(filename);
|
|
ws = null;
|
|
}
|
|
dok.dokument = sfword.Generate_Word(dt.Rows[0][0].ToString(), docdata);
|
|
Logging.Logging.Debug("Generate_Word", "Ende", dokumentid);
|
|
Thread.Sleep(OfficeSleep);
|
|
}
|
|
else
|
|
{
|
|
Logging.Logging.Debug("Generate_Word_in_Office", "Init", dokumentid);
|
|
OnDocOffice.clsWordEdit oo = new OnDocOffice.clsWordEdit("", "", "", resturi, apikey);
|
|
Logging.Logging.Debug("Generate_Word_in_Office", "Start", dokumentid);
|
|
|
|
dok.dokument = oo.Generate_Word_in_Office(ref docdata, ref dok, dt.Rows[0][0].ToString(), connectionstring, tempdir, dokumentid, Apptype, Extension, OfficeSleep, Office_Fill_DocIO, vbfilemanagement, editdoc);
|
|
Logging.Logging.Debug("Generate_Word_in_Office", "Ende", dokumentid);
|
|
oo = null;
|
|
}
|
|
|
|
dok.doktype = "W";
|
|
dok.extension = dt2.Rows[0][1].ToString();
|
|
//if (dok.extension.ToUpper()=="DOTM") { dok.extension = "docm"; }
|
|
return dok;
|
|
case "XLSM": case "XLSX": case "XLST": case "XLS": case "XLT":
|
|
case "XLTM":
|
|
case "EXCEL":
|
|
|
|
SyncFExcel sfexcel = new SyncFExcel();
|
|
generate_docdata(dokumentid, ref docdata);
|
|
clsdok dokexcel = new clsdok("", "", "", "");
|
|
if (useoffice == false)
|
|
{
|
|
dokexcel.dokument = sfexcel.Generate_Excel(dt.Rows[0][0].ToString(), docdata, Apptype.ToUpper());
|
|
dokexcel.doktype = "X";
|
|
dokexcel.extension = dt2.Rows[0][1].ToString();
|
|
}
|
|
else
|
|
{
|
|
OnDocOffice.clsExcelEdit eo = new OnDocOffice.clsExcelEdit("", "", "");
|
|
dokexcel.dokument = eo.Generate_Excel_in_Office(ref docdata, ref dokexcel, dt.Rows[0][0].ToString(), connectionstring, tempdir, dokumentid, Apptype, Extension, OfficeSleep, Office_Fill_DocIO);
|
|
dokexcel.doktype = "X";
|
|
dokexcel.extension = dt2.Rows[0][1].ToString();
|
|
eo = null;
|
|
}
|
|
return dokexcel;
|
|
//break;
|
|
case "PDF": case "ACROBAT": case "FORMULAR": case "DOKUMENT":
|
|
clsdok dokpdf = new clsdok("", "", "", "");
|
|
dokpdf.dokument = dt.Rows[0][0].ToString();
|
|
dokpdf.extension = Extension;
|
|
dokpdf.doktype = "P";
|
|
return dokpdf;
|
|
//break ;
|
|
default:
|
|
Logger.Info("DocGenerator_from_EDOKA: FileType unknown" + Apptype);
|
|
clsdok dokempty = new clsdok("", "", "", "");
|
|
return dokempty;
|
|
//break;
|
|
}
|
|
|
|
//db.get_vorlage_to_file(db.dsdaten.Tables[0].Rows[0][1].ToString(),tempdir,dokumentid );
|
|
}
|
|
|
|
|
|
public void generate_docdata(string dokumentid, ref clsDocData docdata)
|
|
{
|
|
List<clsDocValue> docValues = new List<clsDocValue>();
|
|
DB db = new DB(connectionstring);
|
|
db.Get_Tabledata("exec sp_dokumentwerte '" + dokumentid + "',0", false, true);
|
|
foreach (DataRow r in db.dsdaten.Tables[0].Rows)
|
|
{
|
|
clsDocValue dv = new clsDocValue();
|
|
dv.TMBeginn = r["beginntextmarke"].ToString();
|
|
dv.TMEnd = r["endetextmarke"].ToString();
|
|
dv.FieldName = r["feldname"].ToString();
|
|
dv.Value = r["xvalue"].ToString();
|
|
docValues.Add(dv);
|
|
}
|
|
clsDocValue dv1 = new clsDocValue();
|
|
|
|
docdata.DocValues = docValues;
|
|
|
|
db.Get_Tabledata("Select * from view_ER_Makros where dokumentid='" + dokumentid + "' order by reihenfolge", false, true);
|
|
List<clsDocMacro> docMacros = new List<clsDocMacro>();
|
|
foreach (DataRow r in db.dsdaten.Tables[0].Rows)
|
|
{
|
|
clsDocMacro dm = new clsDocMacro();
|
|
dm.Name = r["makro"].ToString().Trim();
|
|
dm.BookMark = r["BookMark"].ToString().Trim();
|
|
docMacros.Add(dm);
|
|
}
|
|
docdata.DocMacros = docMacros;
|
|
|
|
//db.Get_Tabledata("Select * from OnDocTMFaksimile", false, true);
|
|
//List<clsNameVOrnameTM> NameVornameTM = new List<clsNameVOrnameTM>();
|
|
//foreach (DataRow r in db.dsdaten.Tables[0].Rows)
|
|
//{
|
|
// clsNameVOrnameTM clsNameVOrnameTM = new clsNameVOrnameTM();
|
|
// clsNameVOrnameTM.TM = r[1].ToString().Trim();
|
|
// clsNameVOrnameTM.FNKT = r[2].ToString().Trim();
|
|
// NameVornameTM.Add(clsNameVOrnameTM);
|
|
|
|
//}
|
|
//docdata.VornameNameTextmarken = NameVornameTM;
|
|
db = null;
|
|
}
|
|
|
|
public void Generate_QDF(string dokumentid, ref clsDocData docdata, string tempdir)
|
|
{
|
|
DB db = new DB(connectionstring);
|
|
|
|
db.Get_Tabledata("Select * from ondoc_qdf_parameter where aktiv=1", false, true);
|
|
string qdfsource = db.dsdaten.Tables[0].Rows[0][1].ToString();
|
|
string qdfviewer = db.dsdaten.Tables[0].Rows[0][2].ToString();
|
|
string dokumentname = tempdir + dokumentid + ".qdf";
|
|
System.IO.File.Copy(qdfsource, dokumentname);
|
|
StreamReader fi = new StreamReader(dokumentname);
|
|
string daten;
|
|
daten = fi.ReadToEnd();
|
|
generate_docdata(dokumentid, ref docdata);
|
|
|
|
db.clear_parameter();
|
|
db.add_parameter("@fnkt", "1");
|
|
db.add_parameter("@partnernr", docdata.PartnerNr.ToString());
|
|
db.add_parameter("@mitarbeiternr", docdata.Ersteller.ToString());
|
|
foreach (clsDocValue dv in docdata.DocValues)
|
|
{
|
|
try
|
|
{
|
|
if (dv.FieldName.ToString() == "&policen_nr&")
|
|
{
|
|
db.add_parameter("@policenr", dv.Value.ToString());
|
|
}
|
|
//daten = daten.Replace(dv.FieldName.ToString(), dv.Value);
|
|
}
|
|
catch { }
|
|
}
|
|
db.Get_Tabledata("ondoc_qdf_parameters", true, false);
|
|
clsDocValue docval = new clsDocValue();
|
|
docval.FieldName = "&meldungs_nr&";
|
|
docval.Value = db.dsdaten.Tables[0].Rows[0][0].ToString();
|
|
docdata.DocValues.Add(docval);
|
|
|
|
foreach (clsDocValue dv in docdata.DocValues)
|
|
{
|
|
try
|
|
{
|
|
daten = daten.Replace(dv.FieldName.ToString(), dv.Value);
|
|
}
|
|
catch { }
|
|
}
|
|
fi.Close();
|
|
StreamWriter fo = new StreamWriter(dokumentname);
|
|
fo.Write(daten);
|
|
fo.Flush();
|
|
fo.Close();
|
|
ProcessStartInfo PI = new ProcessStartInfo();
|
|
PI.FileName = qdfviewer;
|
|
PI.Arguments = dokumentname;
|
|
Process.Start(PI);
|
|
db.add_parameter("@dokumentid", dokumentid);
|
|
db.Get_Tabledata("ondoc_check_delete_einzeldokument", true, false);
|
|
db = null;
|
|
//Process.Start(qdfviewer + " " + dokumentname);
|
|
}
|
|
|
|
}
|
|
}
|