update 20251210

This commit is contained in:
Stefan Hutter
2025-12-10 17:42:12 +01:00
parent 10ed1e6087
commit 6ac2108d40
303 changed files with 2207203 additions and 1040 deletions

View File

@@ -31,6 +31,7 @@ using Helper;
using Microsoft.VisualBasic.Logging;
using System.Data.Common;
using static System.Net.WebRequestMethods;
using System.Windows.Forms;
@@ -1631,6 +1632,77 @@ namespace OnDocOffice
document = null;
return;
}
public bool insert_signaturesf(string dokumentid, string unterschriftlinks, string unterschriftrechts, string tempdir, string dokumenttypnr, int pages)
{
DB db = new DB(this.connectstring);
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataTable dt2 = new System.Data.DataTable();
string Apptype = "";
string Extension = "";
dt = db.Get_Vorlage_By_DokumentID(dokumentid, true, 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();
switch (Apptype.ToUpper())
{
case "DOCX":
case "DOCM":
case "DOC":
case "DOT":
case "WORD":
case "DOTM":
string filename = tempdir + dokumentid +"."+Extension;
Helper.clsFileHelper fh = new Helper.clsFileHelper();
fh.SaveBase64ToFile(dt.Rows[0][0].ToString(), filename);
WordDocument document = new WordDocument();
document.Open(filename, FormatType.Automatic);
string path_unterschriftlinks = "";
string path_unterschriftrechts = "";
if (unterschriftlinks != "-1")
{
unterschriftlinks = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(get_unterschrift(unterschriftlinks));
Helper.clsFileHelper clsFileHelper = new Helper.clsFileHelper();
path_unterschriftlinks = tempdir + dokumentid + "UL.png";
clsFileHelper.SaveBase64ToFile(unterschriftlinks, path_unterschriftlinks);
}
if (unterschriftrechts != "-1")
{
unterschriftrechts = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(get_unterschrift(unterschriftrechts));
Helper.clsFileHelper clsFileHelper = new Helper.clsFileHelper();
path_unterschriftrechts = tempdir + dokumentid + "UR.png";
clsFileHelper.SaveBase64ToFile(unterschriftrechts, path_unterschriftrechts);
}
word_signaturesf word_Signature = new word_signaturesf(this.connectstring);
word_Signature.sign_docsf(ref document, path_unterschriftlinks, path_unterschriftrechts, dokumentid, dokumenttypnr, pages);
word_Signature = null;
document.Save(filename,FormatType.Automatic);
document.Close();
db.Save_To_DB(dokumentid, filename, "", 0);
System.IO.File.Delete(filename);
document = null;
try
{
if (System.IO.File.Exists(path_unterschriftlinks)) { System.IO.File.Delete(tempdir + dokumentid + "UL.png"); };
}
catch { }
try
{
if (System.IO.File.Exists(path_unterschriftrechts)) { System.IO.File.Delete(tempdir + dokumentid + "UR.png"); }
}
catch { }
return true;
break;
default:
break;
}
return false;
}
public bool insert_signature(string dokumentid, string unterschriftlinks, string unterschriftrechts, string tempdir, string dokumenttypnr , int pages)
{
@@ -1679,8 +1751,16 @@ namespace OnDocOffice
}
word_signature word_Signature = new word_signature(this.connectstring);
word_Signature.sign_doc(ref word, path_unterschriftlinks, path_unterschriftrechts, dokumentid,dokumenttypnr,pages);
if (System.IO.File.Exists(path_unterschriftlinks)) { System.IO.File.Delete(tempdir + dokumentid + "UL.png"); };
if (System.IO.File.Exists(path_unterschriftrechts)) { System.IO.File.Delete(tempdir + dokumentid + "UR.png"); }
try
{
if (System.IO.File.Exists(path_unterschriftlinks)) { System.IO.File.Delete(tempdir + dokumentid + "UL.png"); };
}
catch { }
try
{
if (System.IO.File.Exists(path_unterschriftrechts)) { System.IO.File.Delete(tempdir + dokumentid + "UR.png"); }
}
catch { }
word.ActiveDocument.Save();
word.ActiveDocument.Close();
@@ -1693,13 +1773,164 @@ namespace OnDocOffice
default:
break;
}
return true;
return false;
}
}
public class word_signaturesf
{
private string ConnectionString = "";
public word_signaturesf(string connectionstring)
{
this.ConnectionString = connectionstring;
}
public bool sign_docsf(ref Syncfusion.DocIO.DLS.WordDocument document, string imagepath_ul, string imagepath_ur, string dokumentid, string dokumenttypnr, int pages = 0)
{
Logging.Logging.Debug("Sign_Doc", "OnDoc", dokumentid);
DB db = new DB(this.ConnectionString);
db.clear_parameter();
db.add_parameter("@dokumenttypnr", dokumenttypnr.ToString());
db.add_parameter("@officeversion", "2016");
db.add_parameter("@machinname", System.Environment.MachineName);
db.add_parameter("dokumentid", dokumentid);
db.add_parameter("pages", pages.ToString());
db.Get_Tabledata("sp_signatureposition", true, false);
System.Data.DataTable position = db.dsdaten.Tables[0];
db = null;
//Thread.Sleep(1000);
int w = 0;
int h = 0;
int l = 0;
int t = 0;
int type = 1;
try
{
List<string> list = new List<string>();
foreach (Syncfusion.DocIO.DLS.Bookmark bm in document.Bookmarks)
{
if (bm.Name.Contains("VornameNameLinks") || bm.Name.Contains("UnterschriftLinks") || bm.Name == "TGEDKVornameNameL")
{
list.Add(bm.Name);
}
if (bm.Name.Contains("VornameNameRechts") || bm.Name.Contains("UnterschriftRechts") || bm.Name == "TGEDKVornameNameR")
{
list.Add(bm.Name);
}
}
list.Sort();
foreach (string bm in list)
{
if (bm.Contains("VornameNameLinks") || bm.Contains("UnterschriftLinks") || bm == "TGEDKVornameNameL")
{
foreach (System.Data.DataRow dr in position.Rows)
{
if (bm.ToUpper() == dr["bookmark"].ToString().ToUpper())
{
l = Convert.ToInt32(dr["posleft"]);
t = Convert.ToInt32(dr["postop"]);
w = Convert.ToInt32(dr["width"]);
h = Convert.ToInt32(dr["height"]);
type = Convert.ToInt32(dr["type"]);
}
}
try
{
insert_unterschriftsf(ref document, bm, imagepath_ul, l, t, w, h, type);
}
catch { }
}
if (bm.Contains("VornameNameRechts") || bm.Contains("UnterschriftRechts") || bm == "TGEDKVornameNameR")
{
foreach (System.Data.DataRow dr in position.Rows)
{
if (bm.ToUpper() == dr["bookmark"].ToString().ToUpper())
{
Logging.Logging.Debug(bm.ToUpper() + "," + dr["bookmark"].ToString().ToUpper(), "OnDoc", "");
l = Convert.ToInt32(dr["posleft"]);
t = Convert.ToInt32(dr["postop"]);
w = Convert.ToInt32(dr["width"]);
h = Convert.ToInt32(dr["height"]);
type = Convert.ToInt32(dr["type"]);
}
}
try
{
insert_unterschriftsf(ref document, bm, imagepath_ur, l, t, w, h, type);
}
catch (Exception ex) {
int a = 0;
}
}
}
//docword = docWord; ;
Logging.Logging.Debug("Ende Sign_Doc", "OnDoc", dokumentid);
return true;
}
catch (Exception ex)
{
Logging.DocLog.Error("Signaturen konnten nicht eingefügt werden", "OnDocOffe", dokumentid, "", ex.Message);
return false;
}
}
public void insert_unterschriftsf(ref Syncfusion.DocIO.DLS.WordDocument document, string bookmark, string imagepath, int l, int t, int w, int h, int type)
{
if (imagepath == "") { return; }
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
Syncfusion.DocIO.DLS.Bookmark bm = document.Bookmarks[bookmark];
//System.Drawing.Image img;// = System.Drawing.Image.FromFile(imagepath);
//using (FileStream stream = new FileStream(imagepath, FileMode.Open, FileAccess.Read))
//{
// img = Image.FromStream(stream);
//}
Syncfusion.DocIO.DLS.Shape signature = bm.BookmarkStart.OwnerParagraph.AppendShape(Syncfusion.DocIO.DLS.AutoShapeType.Rectangle, w, h);
signature.TextFrame.InternalMargin.Top = 0;
signature.TextFrame.InternalMargin.Left = 0;
signature.TextFrame.InternalMargin.Bottom = 0;
signature.TextFrame.InternalMargin.Right = 0;
//IWParagraph p = bm.BookmarkStart.OwnerParagraph;
//IWPicture u = p.AppendPicture(img);
IWParagraph sigparagraph = signature.TextBody.AddParagraph();
signature.WrapFormat.TextWrappingStyle = TextWrappingStyle.Behind;
signature.LineFormat.DashStyle = LineDashing.Solid;
signature.LineFormat.Color = Color.White;
signature.WrapFormat.AllowOverlap = true;
signature.VerticalPosition = signature.VerticalPosition - (t * -1);
signature.HorizontalPosition = signature.HorizontalPosition + l;
signature.WrapFormat.TextWrappingStyle = TextWrappingStyle.Behind;
//Logging.Logging.Debug(signature.VerticalPosition.ToString() + "," + signature.HorizontalPosition.ToString(), "OnDOc", "");
//signature.HorizontalPosition = signature.HorizontalPosition + 200;
IWPicture p = sigparagraph.AppendPicture(Image.FromFile(imagepath));
p.Width = w;
p.Height = h;
signature.Name = "Unterschrift_" + bookmark;
p = null;
// signature.OwnerParagraph.AppendPicture(img);
}
}
public class word_signature
{
@@ -1707,7 +1938,7 @@ namespace OnDocOffice
public string MachinName { get; set; } = "";
public bool O365 { get; set; } = false;
public word_signature(string connectionstring)
{
@@ -1717,6 +1948,7 @@ namespace OnDocOffice
Microsoft.Office.Interop.Word.Document docWord;
Microsoft.Office.Interop.Word.Application word;
public bool sign_doc(ref Microsoft.Office.Interop.Word.Application word, string imagepath_ul, string imagepath_ur, string dokumentid, string dokumenttypnr, int pages=0)
@@ -1790,6 +2022,7 @@ namespace OnDocOffice
type = Convert.ToInt32(dr["type"]);
}
}
insert_unterschrift(bm, imagepath_ul,l,t,w,h,type);
}
if (bm.Contains("VornameNameRechts") || bm.Contains("UnterschriftRechts") || bm == "TGEDKVornameNameR")
@@ -1805,7 +2038,9 @@ namespace OnDocOffice
type = Convert.ToInt32(dr["type"]);
}
}
insert_unterschrift(bm, imagepath_ur,l,t,w,h,type);
}
}
@@ -1831,6 +2066,7 @@ namespace OnDocOffice
}
public void insert_unterschrift(string bookmark, string imagepath, int l, int t, int w, int h, int type)
{
@@ -2080,11 +2316,11 @@ namespace OnDocOffice
clsdok dok = new clsdok("", "", "", "");
dok = db.GetDocumentAsBase64(dokumentid);
string SQL = "SELECT dbo.dokumenttyp.ErstellungInOffice FROM dbo.dokument INNER JOIN dbo.dokumenttyp ON dbo.dokument.dokumenttypnr = dbo.dokumenttyp.dokumenttypnr where dbo.dokument.dokumentid=@dokumentid";
string SQL = "SELECT dbo.dokumenttyp.ErstellungInOffice, isnull(vsconvertsf,0) as vsconvertsf FROM dbo.dokument INNER JOIN dbo.dokumenttyp ON dbo.dokument.dokumenttypnr = dbo.dokumenttyp.dokumenttypnr where dbo.dokument.dokumentid=@dokumentid";
db.clear_parameter();
db.add_parameter("@dokumentid", dokumentid);
db.Get_Tabledata_Addvar(SQL, false, true);
if (Convert.ToBoolean(db.dsdaten.Tables[0].Rows[0]["Erstellunginoffice"]))
if (Convert.ToBoolean(db.dsdaten.Tables[0].Rows[0]["erstellunginoffice"])==true)
{
return convert_word_to_pdf(ref dok,tempdir,dokumentid);
}
@@ -2134,7 +2370,6 @@ namespace OnDocOffice
}
catch { };
}
}