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.
OnDoc/DOCGEN/Klassen/DocGenerator_from_EDOKA.cs

180 lines
7.7 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;
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)
{
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 = "";
Logging.Logging.Debug("Generate_Doc_EDOKA", "Get_Vorlage", dokumentid);
dt = db.Get_Vorlage_By_DokumentID(dokumentid,useoffice);
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();
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);
dok.dokument = sfword.Generate_Word(dt.Rows[0][0].ToString(), docdata);
Logging.Logging.Debug("Generate_Word", "Ende", dokumentid);
}
else
{
Logging.Logging.Debug("Generate_Word_in_Office", "Init", dokumentid);
OnDocOffice.clsWordEdit oo = new OnDocOffice.clsWordEdit("", "","");
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);
Logging.Logging.Debug("Generate_Word_in_Office", "Ende", dokumentid);
oo = null;
}
dok.doktype = "D";
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 "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);
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();
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;
}
}
}