Update 20250204

This commit is contained in:
Stefan Hutter
2025-02-04 22:36:20 +01:00
parent 293b615547
commit 00eae8a837
2881 changed files with 1570876 additions and 300 deletions

View File

@@ -24,6 +24,7 @@ using System.Net.NetworkInformation;
using System.Net;
using Microsoft.VisualBasic.CompilerServices;
using Database;
using System.Runtime.InteropServices.ComTypes;
namespace OnDocOffice
@@ -347,14 +348,18 @@ namespace OnDocOffice
static bool IsDocumentClosed(Microsoft.Office.Interop.Word.Application wordApp, Document doc)
{
// Check if the document is still listed in the Documents collection
foreach (Document openDoc in wordApp.Documents)
try
{
if (openDoc.FullName == doc.FullName)
foreach (Document openDoc in wordApp.Documents)
{
return false; // Document is still open
if (openDoc.FullName == doc.FullName)
{
return false; // Document is still open
}
}
return true; // Document is closed
}
return true; // Document is closed
catch { return true; }
}
public void run_macros(ref clsDocData docdata, string connectionstring)
@@ -1553,7 +1558,7 @@ namespace OnDocOffice
Helper.clsFileHelper fh = new Helper.clsFileHelper();
fh.SaveBase64ToFile(dt.Rows[0][0].ToString(), filename);
Start_Application();
word.Visible = true;
//word.Visible = true;
word.Documents.Open(filename);
string path_unterschriftlinks = "";
@@ -1599,22 +1604,24 @@ namespace OnDocOffice
Microsoft.Office.Interop.Word.Document docWord;
public bool sign_doc(ref Microsoft.Office.Interop.Word.Application word, string imagepath_ul, string imagepath_ur, string dokumentid)
{
Logging.Logging.Debug("Sign_Doc", "OnDoc", dokumentid);
docWord = word.ActiveDocument;
try
{
foreach (Microsoft.Office.Interop.Word.Bookmark bm in docWord.Bookmarks)
{
if (bm.Name.Contains("TGEDKVornameNameLinks") || bm.Name.Contains("TGEDKUnterschriftLinks"))
if (bm.Name.Contains("VornameNameLinks") || bm.Name.Contains("UnterschriftLinks"))
{
insert_unterschrift(bm.Name, imagepath_ul);
}
if (bm.Name.Contains("TGEDKVornameNameRechts") || bm.Name.Contains("TGEDKUnterschriftRechts"))
if (bm.Name.Contains("VornameNameRechts") || bm.Name.Contains("UnterschriftRechts"))
{
insert_unterschrift(bm.Name, imagepath_ur);
}
}
//docword = docWord; ;
Logging.Logging.Debug("Ende Sign_Doc", "OnDoc", dokumentid);
return true;
}
catch (Exception ex)
@@ -1626,6 +1633,7 @@ namespace OnDocOffice
public void insert_unterschrift(string bookmark, string imagepath)
{
Logging.Logging.Debug("Insert Unterschrift :"+ bookmark, "OnDoc", imagepath);
if (imagepath == "") return;
object missing = Type.Missing;
@@ -1646,6 +1654,7 @@ namespace OnDocOffice
//myshape1.Line.Weight = -2;
myshape1.Name = "Unterschrift" + "_" + bookmark;
myshape1.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
Logging.Logging.Debug("Shapename", "OnDoc", myshape1.Name);
@@ -1672,22 +1681,46 @@ namespace OnDocOffice
}
public bool remove_unterschriften_synfusion(string filename)
{
Logging.Logging.Debug("Unterschriften entfernen (Syncfusion)", "OnDoc", filename);
bool is_protected = false;
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
word.NormalTemplate.Saved = true;
word.Documents.Open(filename);
if (word.ActiveDocument.ProtectionType != Microsoft.Office.Interop.Word.WdProtectionType.wdNoProtection)
{
word.ActiveDocument.Unprotect(Password: "Australia");
is_protected = true;
}
remove_unterschriften(ref word, filename);
if (is_protected)
{
try
{
word.ActiveDocument.Protect(Type: Microsoft.Office.Interop.Word.WdProtectionType.wdAllowOnlyFormFields, NoReset: true, Password: "Australia");
}
catch { }
}
word.ActiveDocument.Save();
word.ActiveDocument.Close();
Thread.Sleep(500);
word.Quit(false);
word = null;
Thread.Sleep(500);
Thread.Sleep(1000);
Logging.Logging.Debug("Ende Unterschriften entfernen (Syncfusion)", "OnDoc", filename);
return true;
}
public bool remove_unterschriften(ref Microsoft.Office.Interop.Word.Application word, string dokumentid)
{
Logging.Logging.Debug("Remove Unterschriften","OnDoc", dokumentid);
bool is_protected = false;
try
{
if (word.ActiveDocument.ProtectionType != Microsoft.Office.Interop.Word.WdProtectionType.wdNoProtection)
{
word.ActiveDocument.Unprotect(Password: "Australia");
is_protected = true;
}
bool found = true;
int i = 1;
while (word.ActiveDocument.Shapes.Count > 0 && found == true)
@@ -1700,6 +1733,16 @@ namespace OnDocOffice
}
}
if (is_protected)
{
try
{
word.ActiveDocument.Protect(Type: Microsoft.Office.Interop.Word.WdProtectionType.wdAllowOnlyFormFields, NoReset: true, Password: "Australia");
}
catch { }
}
Logging.Logging.Debug("Ende Remove Unterschriften", "OnDoc", dokumentid);
return true;
}
catch (Exception ex)