Update 20260123

This commit is contained in:
Stefan Hutter
2026-01-23 08:09:23 +01:00
parent 49155d898f
commit 2d1525575b
358 changed files with 123777 additions and 73 deletions

View File

@@ -39,6 +39,12 @@ using System.Diagnostics;
using Database;
using System.Drawing.Drawing2D;
using Syncfusion.Drawing;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Syncfusion.Windows.Forms.Chart;
using Microsoft.SqlServer.Server;
using Syncfusion.Windows.Forms.Chart.SvgBase;
using System.Drawing.Imaging;
@@ -196,6 +202,642 @@ namespace DOCGEN.Klassen
}
}
private void Insert_CLMValue(CLMDocItem item, ref WordDocument document)
{
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
try
{
switch (item.type.ToString())
{
case "4":
case "7":
case "8":
case "9":
case "10":
case "13":
case "14":
case "15":
case "16":
try
{
ReplaceBookmarkContent(ref document, item.itemname, "", item.itemvalue, false);
}
catch
{
Insert_CLMField(item, ref document);
}
break;
//bookmarkNavigator.MoveToBookmark(bookmark);
//bookmarkNavigator.ReplaceBookmarkContent(item.itemvalue.ToString(), true);
//break;
case "3": // Neu Checkbox
foreach (WSection section in document.Sections)
foreach (WTextBody textBody in section.ChildEntities)
{
foreach (WFormField formField in textBody.FormFields)
{
if (formField.Name == item.field.ToString())
{
string type = formField.FieldType.ToString();
if (type == "FieldFormCheckBox")
{
WCheckBox cb = (WCheckBox)formField;
if (item.itemvalue.ToString().ToUpper() != "")
{
cb.Checked = true;
}
}
break;
}
}
}
break;
case "5":
Insert_CLMImage(item, ref document);
break;
case "6":
Insert_CLMImages(item, ref document, true);
break;
case "11":
insert_Logo(document, null);
break;
case "12":
Insert_CLMTable(item, ref document);
break;
case "17": //Datamatrix
break;
case "18": //Pruefziffer
break;
}
}
catch { }
finally { bookmarkNavigator = null; }
}
private void Insert_CLMField(CLMDocItem item, ref WordDocument document)
{
foreach (WSection section in document.Sections)
//Iterates through section child elements
foreach (WTextBody textBody in section.ChildEntities)
{
//Iterates through form fields
foreach (WFormField formField in textBody.FormFields)
{
if (formField.Name.ToString().ToUpper() == item.field.ToString().ToUpper() || formField.Name.ToString().ToUpper() == item.bmstart.ToString().ToUpper())
{
formField.Text = item.itemvalue;
break;
}
}
}
}
private void Insert_CLMTable(CLMDocItem item, ref WordDocument document)
{
string tablestyle = "";
List<string> cellwidth = null;
List<string> cellpadding = null;
List<string> headers = null;
List<string> stringList = null;
string s = "";
DataTable dt = (DataTable)JsonConvert.DeserializeObject(item.itemvalue, (typeof(DataTable)));
try
{
dynamic myObject = JValue.Parse(item.format);
foreach (dynamic formats in myObject)
{
if (formats.Tag == "TableStyle") { tablestyle = formats.Value; }
if (formats.Tag == "CellWidth") { s = formats.Value.ToString(); cellwidth = s.Split(';').ToList(); }
if (formats.Tag == "CellPadding") { s = formats.Value.ToString(); cellpadding = s.Split(';').ToList(); }
if (formats.Tag == "Headers") { s = formats.Value.ToString(); headers = s.Split(';').ToList(); }
//Console.WriteLine(questions.Question.QuestionId + "." + questions.Question.QuestionText.ToString());
}
}
catch { }
if (cellpadding.Count == 0)
{
cellpadding.Add("0");
cellpadding.Add("0");
cellpadding.Add("0");
cellpadding.Add("0");
}
if (cellwidth.Count == 0)
{
for (int i1 = 0; i1 < dt.Columns.Count; i1++)
{
cellwidth.Add("0");
}
}
int maxwith = 0;
foreach (string w in cellwidth)
{
maxwith = maxwith + Convert.ToInt32(w);
}
string bm = item.field.ToString();
if (bm == "") { bm = item.bmstart.ToString(); }
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
bookmarkNavigator.MoveToBookmark(bm);
//Bookmark bookmark = document.Bookmarks.FindByName(bm);
//WSection section = GetOwnerEntity(bookmark.BookmarkStart) as WSection;
IWTable table = new WTable(document);
//IWTable table = section.AddTable();
if (headers.Count > 0 && headers.Count == dt.Columns.Count)
{
DataRow dr = dt.NewRow();
for (int i = 0; i < headers.Count; i++)
{
dr[i] = headers[i];
}
dt.Rows.InsertAt(dr, 0);
dt.AcceptChanges();
}
table.ResetCells(dt.Rows.Count, dt.Columns.Count);
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
table[i, j].AddParagraph().AppendText(dt.Rows[i][dt.Columns[j]].ToString());
WTableCell cell = table.Rows[i].Cells[j];
try
{
if (cellpadding.Count > 0)
{
cell.CellFormat.SamePaddingsAsTable = false;
cell.CellFormat.Paddings.Left = Convert.ToInt32(cellpadding[0]); //in terms of points
cell.CellFormat.Paddings.Right = Convert.ToInt32(cellpadding[1]); //in terms of points
cell.CellFormat.Paddings.Top = Convert.ToInt32(cellpadding[2]); //in terms of points
cell.CellFormat.Paddings.Bottom = Convert.ToInt32(cellpadding[3]); //in terms of points
}
}
catch { }
try
{
int wi = Convert.ToInt32(cellwidth[j]);
if (wi > 0)
{
cell.Width = wi;
}
else
{
{
cell.Width = table.Width - maxwith;
}
}
}
catch { }
//This line Defines whether to use same paddings as table has.
//cell.CellFormat.SamePaddingsAsTable = false;
//cell.CellFormat.Paddings.Left =0; //in terms of points
//cell.CellFormat.Paddings.Right = 0;//in terms of points
//cell.CellFormat.Paddings.Top = 0;//in terms of points
//cell.CellFormat.Paddings.Bottom = 15f;//in terms of points
// if (j==0) { cell.Width = 150; } else { cell.Width = table.Width - 150; }
}
}
try
{
if (tablestyle == "None" || tablestyle == "")
{
table.ApplyStyle(BuiltinTableStyle.LightShading);
//Enables special formatting for banded columns of the table.
table.ApplyStyleForBandedColumns = false;
//Enables special formatting for banded rows of the table.
table.ApplyStyleForBandedRows = false;
//Disables special formatting for first column of the table.
table.ApplyStyleForFirstColumn = false;
//Enables special formatting for header row of the table.
table.ApplyStyleForHeaderRow = false;
//Enables special formatting for last column of the table.
table.ApplyStyleForLastColumn = false;
//Disables special formatting for last row of the table.
table.ApplyStyleForLastRow = false;
table.TableFormat.Borders.BorderType = BorderStyle.None;
}
if (tablestyle == "default") { }
//tablestyle = "LightShadingAccent1";
if (Enum.IsDefined(typeof(BuiltinTableStyle), tablestyle))
{
ApplyBuiltInTableStyleFromIStyle(ref table, tablestyle);
}
}
catch { }
bookmarkNavigator.InsertTable(table);
//bookmark = null;
//section = null;
table = null;
cellwidth = null;
cellpadding = null;
headers = null;
stringList = null;
}
private void ApplyBuiltInTableStyleFromIStyle(ref IWTable table, string style)
{
if (style == null || string.IsNullOrEmpty(style))
return;
switch (style)
{
case "None":
//table.ApplyStyle(BuiltinTableStyle.None);
break;
case "TableNormal":
table.ApplyStyle(BuiltinTableStyle.TableNormal);
break;
case "TableGrid":
table.ApplyStyle(BuiltinTableStyle.TableGrid);
break;
// Light Shading
case "LightShading":
table.ApplyStyle(BuiltinTableStyle.LightShading);
break;
case "LightShadingAccent1":
table.ApplyStyle(BuiltinTableStyle.LightShadingAccent1);
break;
case "LightShadingAccent2":
table.ApplyStyle(BuiltinTableStyle.LightShadingAccent2);
break;
case "LightShadingAccent3":
table.ApplyStyle(BuiltinTableStyle.LightShadingAccent3);
break;
case "LightShadingAccent4":
table.ApplyStyle(BuiltinTableStyle.LightShadingAccent4);
break;
case "LightShadingAccent5":
table.ApplyStyle(BuiltinTableStyle.LightShadingAccent5);
break;
case "LightShadingAccent6":
table.ApplyStyle(BuiltinTableStyle.LightShadingAccent6);
break;
// Light Grid
case "LightGrid":
table.ApplyStyle(BuiltinTableStyle.LightGrid);
break;
case "LightGridAccent1":
table.ApplyStyle(BuiltinTableStyle.LightGridAccent1);
break;
case "LightGridAccent2":
table.ApplyStyle(BuiltinTableStyle.LightGridAccent2);
break;
case "LightGridAccent3":
table.ApplyStyle(BuiltinTableStyle.LightGridAccent3);
break;
case "LightGridAccent4":
table.ApplyStyle(BuiltinTableStyle.LightGridAccent4);
break;
case "LightGridAccent5":
table.ApplyStyle(BuiltinTableStyle.LightGridAccent5);
break;
case "LightGridAccent6":
table.ApplyStyle(BuiltinTableStyle.LightGridAccent6);
break;
// Medium Shading
case "MediumShading1":
table.ApplyStyle(BuiltinTableStyle.MediumShading1);
break;
case "MediumShading1Accent1":
table.ApplyStyle(BuiltinTableStyle.MediumShading1Accent1);
break;
case "MediumShading1Accent2":
table.ApplyStyle(BuiltinTableStyle.MediumShading1Accent2);
break;
case "MediumShading1Accent3":
table.ApplyStyle(BuiltinTableStyle.MediumShading1Accent3);
break;
case "MediumShading1Accent4":
table.ApplyStyle(BuiltinTableStyle.MediumShading1Accent4);
break;
case "MediumShading1Accent5":
table.ApplyStyle(BuiltinTableStyle.MediumShading1Accent5);
break;
case "MediumShading1Accent6":
table.ApplyStyle(BuiltinTableStyle.MediumShading1Accent6);
break;
// Medium Grid
case "MediumGrid1":
table.ApplyStyle(BuiltinTableStyle.MediumGrid1);
break;
case "MediumGrid1Accent1":
table.ApplyStyle(BuiltinTableStyle.MediumGrid1Accent1);
break;
case "MediumGrid1Accent2":
table.ApplyStyle(BuiltinTableStyle.MediumGrid1Accent2);
break;
case "MediumGrid1Accent3":
table.ApplyStyle(BuiltinTableStyle.MediumGrid1Accent3);
break;
case "MediumGrid1Accent4":
table.ApplyStyle(BuiltinTableStyle.MediumGrid1Accent4);
break;
case "MediumGrid1Accent5":
table.ApplyStyle(BuiltinTableStyle.MediumGrid1Accent5);
break;
case "MediumGrid1Accent6":
table.ApplyStyle(BuiltinTableStyle.MediumGrid1Accent6);
break;
// Medium List
case "MediumList1":
table.ApplyStyle(BuiltinTableStyle.MediumList1);
break;
case "MediumList1Accent1":
table.ApplyStyle(BuiltinTableStyle.MediumList1Accent1);
break;
case "MediumList1Accent2":
table.ApplyStyle(BuiltinTableStyle.MediumList1Accent2);
break;
case "MediumList1Accent3":
table.ApplyStyle(BuiltinTableStyle.MediumList1Accent3);
break;
case "MediumList1Accent4":
table.ApplyStyle(BuiltinTableStyle.MediumList1Accent4);
break;
case "MediumList1Accent5":
table.ApplyStyle(BuiltinTableStyle.MediumList1Accent5);
break;
case "MediumList1Accent6":
table.ApplyStyle(BuiltinTableStyle.MediumList1Accent6);
break;
// Dark List
case "DarkList":
table.ApplyStyle(BuiltinTableStyle.DarkList);
break;
case "DarkListAccent1":
table.ApplyStyle(BuiltinTableStyle.DarkListAccent1);
break;
case "DarkListAccent2":
table.ApplyStyle(BuiltinTableStyle.DarkListAccent2);
break;
case "DarkListAccent3":
table.ApplyStyle(BuiltinTableStyle.DarkListAccent3);
break;
case "DarkListAccent4":
table.ApplyStyle(BuiltinTableStyle.DarkListAccent4);
break;
case "DarkListAccent5":
table.ApplyStyle(BuiltinTableStyle.DarkListAccent5);
break;
case "DarkListAccent6":
table.ApplyStyle(BuiltinTableStyle.DarkListAccent6);
break;
// Colorful Grid
case "ColorfulGrid":
table.ApplyStyle(BuiltinTableStyle.ColorfulGrid);
break;
case "ColorfulGridAccent1":
table.ApplyStyle(BuiltinTableStyle.ColorfulGridAccent1);
break;
case "ColorfulGridAccent2":
table.ApplyStyle(BuiltinTableStyle.ColorfulGridAccent2);
break;
case "ColorfulGridAccent3":
table.ApplyStyle(BuiltinTableStyle.ColorfulGridAccent3);
break;
case "ColorfulGridAccent4":
table.ApplyStyle(BuiltinTableStyle.ColorfulGridAccent4);
break;
case "ColorfulGridAccent5":
table.ApplyStyle(BuiltinTableStyle.ColorfulGridAccent5);
break;
case "ColorfulGridAccent6":
table.ApplyStyle(BuiltinTableStyle.ColorfulGridAccent6);
break;
default:
// Custom table style fallback
//table.ApplyStyle(style.Name);
break;
}
}
public Bitmap Resize(System.Drawing.Image image, int width, int height, bool keepAspectRatio, bool enlargeSmallerImages)
{
if (!enlargeSmallerImages && image.Width <= width && image.Height <= height)
{
return new Bitmap(image);
}
if (!keepAspectRatio)
{
return new Bitmap(image, width, height);
}
int originalWidth = image.Width;
int originalHeight = image.Height;
int newWidth = 0;
int newHeight = 0;
double aspectRatio = (double)originalWidth / originalHeight;
if (width > 0)
{
newWidth = width;
newHeight = (int)Math.Round(width / aspectRatio);
}
else
{
newHeight = height;
newWidth = (int)Math.Round(height * aspectRatio);
}
return new Bitmap(image, newWidth, newHeight);
}
public System.Drawing.Image Resize1(System.Drawing.Image src, string outputPath, int maxWidth, int maxHeight)
{
double ratio = 0;
int width = 0;
int height = 0;
if (maxHeight == 0)
{
ratio = (double)maxWidth / src.Width;
width = maxWidth;
height = (int)(src.Height * ratio);
}
else
{
ratio = (double)maxHeight / src.Height;
height = maxHeight;
width = (int)(src.Width * ratio);
}
var dest = new Bitmap(width, height);
dest.SetResolution(
src.HorizontalResolution,
src.VerticalResolution);
using (var g = Graphics.FromImage(dest))
{
g.CompositingMode = CompositingMode.SourceCopy;
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
using (var wrap = new ImageAttributes())
{
wrap.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);
g.DrawImage(
src,
new Rectangle(0, 0, width, height),
0, 0,
src.Width, src.Height,
GraphicsUnit.Pixel,
wrap);
}
return dest;// bmp.Save(outputPath, jpgEncoder, encParams);
}
}
private void Insert_CLMImages(CLMDocItem item, ref WordDocument document, Boolean inline = false)
{
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
try
{
bookmarkNavigator.MoveToBookmark(item.bmstart);
}
catch
{
bookmarkNavigator.MoveToBookmark(item.field);
}
bookmarkNavigator.DeleteBookmarkContent(true);
IWParagraph paragraph = new WParagraph(document);
DataTable dt = new DataTable();
try
{
dt = (DataTable)JsonConvert.DeserializeObject(item.itemvalue, (typeof(DataTable)));
foreach (DataRow dr in dt.Rows)
{
MemoryStream mssign = new MemoryStream(Convert.FromBase64String(dr[0].ToString()));
System.Drawing.Image img = System.Drawing.Image.FromStream(mssign);
if (Convert.ToInt32(item.width) != 0 || Convert.ToInt32(item.height) != 0)
{
// img = Resize(img, Convert.ToInt32(item.width), Convert.ToInt32(item.width)), true, true);
img = Resize1(img, "", Convert.ToInt32(item.width), Convert.ToInt32(item.height));
}
paragraph.AppendPicture(img);
mssign = null;
img = null;
}
bookmarkNavigator.InsertParagraph(paragraph);
paragraph = null;
bookmarkNavigator = null;
dt = null;
}
catch (Exception ex)
{
string s= ex.Message;
}
}
private void Insert_CLMImage(CLMDocItem item, ref WordDocument document, Boolean inline = false, Boolean multiimages = false)
{
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
Syncfusion.DocIO.DLS.Bookmark bm = document.Bookmarks[item.bmstart];
if (bm is null)
{
bm = document.Bookmarks[item.field];
}
MemoryStream mssign = new MemoryStream(Convert.FromBase64String(item.itemvalue));
System.Drawing.Image img = System.Drawing.Image.FromStream(mssign);
System.Drawing.Image img1 = Resize(img, Convert.ToInt32(item.width), Convert.ToInt32(item.height), true, true);
int itop = Convert.ToInt32(item.top) * -1;
int top = Convert.ToInt32(Convert.ToInt32(itop) + Convert.ToInt32(img1.Height));
top = Convert.ToInt32(Convert.ToInt32(itop));
int height = Convert.ToInt32(Convert.ToInt32(img1.Height));
int left = Convert.ToInt32(Convert.ToInt32(item.left));
int width = Convert.ToInt32(Convert.ToInt32(img1.Width));
Shape signature = bm.BookmarkStart.OwnerParagraph.AppendShape(Syncfusion.DocIO.DLS.AutoShapeType.Rectangle, Convert.ToInt32(img1.Width), Convert.ToInt32(img1.Height));
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.WrapFormat.TextWrappingStyle = TextWrappingStyle.Behind;
signature.HorizontalPosition = signature.HorizontalPosition + left;
signature.VerticalPosition = signature.VerticalPosition - top;
IWPicture p = sigparagraph.AppendPicture(img);
p.Width = Convert.ToInt32(img1.Width);
p.Height = Convert.ToInt32(img1.Height); ;
//signature.Name = "Unterschrift_" + bookmark;
img = null;
img1 = null;
bm = null;
mssign = null;
signature = null;
}
private void insert_signature(string bookmark, string unterschrift, ref WordDocument document)
{
@@ -205,7 +847,6 @@ namespace DOCGEN.Klassen
MemoryStream mssign = new MemoryStream(Convert.FromBase64String(unterschrift));
System.Drawing.Image img = System.Drawing.Image.FromStream(mssign);
Shape signature = bm.BookmarkStart.OwnerParagraph.AppendShape(Syncfusion.DocIO.DLS.AutoShapeType.Rectangle, 124, 52);
signature.TextFrame.InternalMargin.Top = 0;
signature.TextFrame.InternalMargin.Left = 0;
@@ -629,45 +1270,26 @@ namespace DOCGEN.Klassen
catch { }
try
{
foreach (CLMDocItem item in docdata.CLMDocItems)
{
if (item.itemvalue.ToString() != "" && item.type != null)
{
foreach (WSection section in document.Sections)
//Iterates through section child elements
foreach (WTextBody textBody in section.ChildEntities)
{
//Iterates through form fields
foreach (WFormField formField in textBody.FormFields)
{
if (formField.Name == item.field.ToString())
{
switch (item.type.ToString())
{
case "4": //Text and CheckBox
string type = formField.FieldType.ToString();
if (type == "FieldFormCheckBox")
{
WCheckBox cb = (WCheckBox)formField;
if (item.itemvalue.ToString().ToUpper() == "X")
{
cb.Checked = true;
}
}
else
{
formField.Text = item.itemvalue.ToString();
Insert_CLMValue(item, ref document);
//BookmarkCollection bookmarks = document.Bookmarks;
//foreach (Bookmark bm in bookmarks)
//{
// if (bm.Name.ToUpper() == item.field.ToString().ToUpper() || bm.Name.ToUpper() == item.bmstart.ToString().ToUpper())
// {
// Insert_CLMValue(item, bm.Name, ref document);
// }
//}
}
break;
case "5": //Image
break;
}
}
}
}
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.