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.

252 lines
9.6 KiB

using DOCGEN.Klassen;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using edoka_dms;
using Syncfusion.XlsIO.Parser.Biff_Records;
using Syncfusion.DocIO.DLS;
using System.Data.SqlClient;
using System.Data;
using System.Runtime.CompilerServices;
using Model;
using Database;
using NLog.Config;
using System.Runtime.Serialization;
using System.Xml.Linq;
using NLog.LayoutRenderers;
using System.Configuration;
using Syncfusion.DocIO;
using Syncfusion.Pdf;
using System.IO;
using Syncfusion.Compression.Zip;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
namespace DOCGEN
{
public class DocGen
{
public edoka_dms.clsConnectionProvider conn_edoka = new edoka_dms.clsConnectionProvider();
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
public string DokumentID = "";
private string startupdir = "";
public string connectionstring = "";
public clsDocData DocData = new clsDocData();
DB db = new DB();
public string apikey = "";
public string resturi = "";
public void Lic()
{
// 25. string lickey = "Ngo9BigBOggjHTQxAR8/V1NCaF5cXmZCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdnWXdecXRdQ2heUU13XUI="
//string lickey = "Ngo9BigBOggjHTQxAR8/V1NCaF5cXmZCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdnWXZeeXRQR2NZUEZ2WkE=";
string lickey = "MzYzODg2NkAzMjM4MmUzMDJlMzBTOWljRmxNelA1d1VGOHpGR0lxQzB6UTAwKzIxK2VBNEhBZFp5alcxb1NVPQ==";
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(lickey);
}
public DocGen() {
Lic();
}
public DocGen(string Connectionstring)
{
this.connectionstring = Connectionstring;
this.DocData = DocData;
db.connectionstring = this.connectionstring;
Lic();
}
public DocGen(string Connectionstring, string RestURI, string ApiKey)
{
this.connectionstring = Connectionstring;
this.DocData = DocData;
db.connectionstring = this.connectionstring;
Lic();
this.resturi = RestURI;
this.apikey = ApiKey;
}
public string GenDocID(clsDocData docdata, bool editdoc, string dokumentid)
{
this.DocData = docdata;
if (DocData.UseEDOKA_Values.ToUpper() == "TRUE")
{
DokumentID=db.Create_EDOKA_Doc(this.DocData,editdoc,dokumentid);
Logging.DocLog.Info("Dokument erstellt", "DocGen", DokumentID, docdata.PartnerNr.ToString(), docdata.Ersteller.ToString());
}
else { DokumentID = ""; };
return DokumentID;
}
public string Barcodetest(string dokumentid)
{
return "";
}
public string generate_pdf(string dokumentid)
{
return "";
}
public string geneate_dummy_pdf(string inhalt)
{
using (PdfDocument document = new PdfDocument())
{
// Set the page size.
document.PageSettings.Size = PdfPageSize.A4;
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//create the PDF font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
//Draw the text.
graphics.DrawString(inhalt, font, PdfBrushes.Black, new System.Drawing.PointF(0, 0));
// Write the PDF document to file
MemoryStream outputStream = new MemoryStream();
document.Save(outputStream);
byte[] bytes;
bytes = outputStream.ToArray();
outputStream.Close();
outputStream = null;
document.Close();
return Convert.ToBase64String(bytes);
}
}
public string generate_serienbrief(string vorlage,serienbrief sb, string dokumentid, string resturi, string apikey)
{
SyncFWord sfword = new SyncFWord(resturi,apikey);
clsdok dok = new clsdok("", "", "","");
clsDocData dd = new clsDocData();
dd.DocMacros = new List<clsDocMacro>();
dd.Dokumentid = dokumentid;
dd.DokumentDatum = sb.dokumentdatum.ToString();
dd.Unterschrift_Links=sb.unterschriftlinks.ToString();
dd.Unterschrift_Rechts = sb.unterschriftrechts.ToString();
dd.DocValues = sb.DocValues;
dd.As_Faksimile = sb.faksimile_unterschrfit.ToString();
dd.Barcode = sb.vertrag == 1;
dd.VorlageNr = sb.officevorlagenr.ToString();
dd.barcode_height = sb.barcode_height;
dd.barcode_width = sb.barcode_width;
dd.barcode_top = sb.barcode_top;
dd.barcode_left = sb.barcode_left;
dd.barcode_horizontal = sb.barcode_horizontal;
dd.barcode_font=sb.barcode_font;
dd.barcode_fontsize = Convert.ToInt32(sb.barcode_fontsize);
dd.barcode_textposition=sb.barcode_textposition;
dd.barcode_zusatz = sb.barcode_zusatz;
dd.barcode_type=sb.barcode_type;
dd.barcode_content = sb.barcode_content;
dd.barcode_text = sb.barcode_text;
dok.dokument = sfword.Generate_Word(vorlage,dd, sb.img_unterschriftlinks,sb.img_unterschrfitrechts,sb.img_faktura,true);
DocGet dget = new DocGet(this.connectionstring);
string pdfdoc = dget.Convert_Word_To_PDF(dok.dokument);
if (dd.Barcode)
{
System.Drawing.Image barcode = sfword.Get_Barcodeimage(dd);
var stream = new MemoryStream(Convert.FromBase64String(pdfdoc));
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);
PdfBitmap image = new PdfBitmap(barcode);
for (int i = 0; i < loadedDocument.Pages.Count; i++)
{
PdfLoadedPage loadedPage = loadedDocument.Pages[i] as PdfLoadedPage;
PdfGraphics graphics = loadedPage.Graphics;
if (dd.barcode_horizontal == 1)
{
graphics.DrawImage(image, dd.barcode_left, dd.barcode_top, dd.barcode_width, dd.barcode_height);
}
else
{
graphics.DrawImage(image, dd.barcode_left, dd.barcode_top, dd.barcode_width, dd.barcode_height);
}
}
loadedDocument.ConvertToPDFA(PdfConformanceLevel.Pdf_A1B);
MemoryStream outputStream = new MemoryStream();
loadedDocument.Save(outputStream);
byte[] bytes;
bytes = outputStream.ToArray();
dok.dokument = Convert.ToBase64String(bytes);
dget = null;
outputStream = null;
} else
{
dok.dokument = pdfdoc;
}
db = null;
dok.doktype = "P";
sfword = null;
return dok.dokument;
}
public bool signdoc(string dokumentid, string tempdir)
{
DB db1 = new DB(connectionstring);
try
{
db1.Get_Tabledata("Select * from dokument where dokumentid = '" + dokumentid + "'", false, true);
string unterschriftlinks = db1.dsdaten.Tables[0].Rows[0]["unterschriftlinks"].ToString();
string unterschriftrechts = db1.dsdaten.Tables[0].Rows[0]["unterschriftrechts"].ToString();
string dokumenttypnr = db1.dsdaten.Tables[0].Rows[0]["dokumenttypnr"].ToString();
OnDocOffice.clsWordEdit we = new OnDocOffice.clsWordEdit(connectionstring, "", "", resturi, apikey);
if (we.insert_signature(dokumentid, unterschriftlinks, unterschriftrechts, tempdir,dokumenttypnr))
{
return true;
}
}
catch {
return false;
}
finally { db1 = null; }
return true;
}
//public void createpdf(string filename)
//{
// WordDocument document = new WordDocument(filename, FormatType.Automatic);
// CompatibilityMode compatibilityMode = document.Settings.CompatibilityMode;
// //document.UpdateDocumentFields();
// //document.UpdateDocumentFields();
// //TextSelection textSelection = document.Find("den Kunden", false, true);
// //WTextRange textRange = textSelection.GetAsOneRange();
// //Modifies the text
// //textRange.Text = "Replaced text";
// using (Syncfusion.DocToPDFConverter.DocToPDFConverter converter = new Syncfusion.DocToPDFConverter.DocToPDFConverter())
// {
// converter.Settings.EmbedFonts = true;
// //converter.Settings.UpdateDocumentFields = true;
// //converter.Settings.EnableAlternateChunks = true;
// //converter.Settings.AutoDetectComplexScript = true;
// //Converts Word document into PDF document
// using (PdfDocument pdfDocument = converter.ConvertToPDF(document))
// {
// pdfDocument.Save(filename + ".pdf");
// }
// };
//}
}
}