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,10 @@ using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Syncfusion.WinForms.ListView;
using Syncfusion.Windows.Forms.Tools;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Database;
using System.Xml;
namespace DocIO_Demo_SHU
{
@@ -210,8 +214,8 @@ namespace DocIO_Demo_SHU
private void button2_Click(object sender, EventArgs e)
{
OnDocOffice.clsWordEdit wh = new OnDocOffice.clsWordEdit("Data Source=shu01\\shu00;Initial Catalog=edoka_dms;Persist Security Info=True;User ID=sa;Password=*shu29", textBox2.Text, "");
wh.Edit_Document();
//OnDocOffice.clsWordEdit wh = new OnDocOffice.clsWordEdit("Data Source=shu01\\shu00;Initial Catalog=edoka_dms;Persist Security Info=True;User ID=sa;Password=*shu29", textBox2.Text, "");
//wh.Edit_Document();
//wh.exec_macros(textBox2.Text, Convert.ToInt32(textBox3.Text), "Data Source=shu01\\shu00;Initial Catalog=edoka_dms;Persist Security Info=True;User ID=sa;Password=*shu29");
}
@@ -221,6 +225,190 @@ namespace DocIO_Demo_SHU
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
}
public class docitem
{
public string itemname;
public string itemtag;
public string itemvalue;
public string doclinkname;
}
private IEnumerable<(string path, string key, string value)> GetNodes(JToken token)
{
foreach (var jt in token.Children())
{
if (!jt.Children().Any())
{
yield return (
path: jt.Path,
key: jt.Path.Split('.').Last(),
value: jt.ToString()
);
}
foreach (var (path, key, value) in GetNodes(jt))
{
yield return (path, key, value);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
string jsonstring = System.IO.File.ReadAllText(textBox4.Text);
dynamic data = JsonConvert.DeserializeObject(jsonstring);
List<docitem> docitemlist = new List<docitem>();
var jo = JObject.Parse(jsonstring);
var valueTuples = GetNodes(jo).ToList();
foreach (var valueTuple in valueTuples)
{
docitem d = new docitem();
d.itemname = valueTuple.Item1;
d.itemtag = valueTuple.Item2;
d.itemvalue = valueTuple.Item3;
d.doclinkname = "";
docitemlist.Add(d);
}
DB db = new DB(this.textBox6.Text);
if (VerifyInput(data.Dokumenttyp.ToString(), "Dokumenttypnr", ref db) == false)
{
Console.WriteLine("Dokumenttypnr ist ungültigt:" + data.Dokumenttypnr.ToString());
return;
}
if (VerifyInput(data.Bp.Partnernummer.ToString(), "Partner", ref db) == false)
{
Console.WriteLine("Partnernummer ist ungültigt:" + data.Bp.Partnernummer.ToString());
return;
}
Console.WriteLine("Verify OK");
WordDocument document = new WordDocument();
document.Open(textBox5.Text, FormatType.Docx); // Or create a new document
BookmarksNavigator bk = new BookmarksNavigator(document);
bk.MoveToBookmark("Tabelle");
int maxcol = 0;
int maxrow = 0;
foreach (docitem di in docitemlist)
{
if (di.itemname.Contains("].th"))
{
string s = di.itemname.Substring(0, di.itemname.Length - 1);
s = s.Substring(s.Length-1, 1);
maxcol = Convert.ToInt32(s);
}
if (di.itemname.Contains(".tr[")){
string s = di.itemname.Substring(9, 1);
maxrow = Convert.ToInt32(s);
}
}
IWTable table = new WTable(document);
int irow = 0;
int icol = 0;
// Set the number of rows and columns
table.ResetCells(maxrow + 1, maxcol + 1);
for (int i = 0; i<maxcol+1; i++)
{
foreach (docitem di in docitemlist)
{
if (di.itemname == "table.tr[0].th[" + i.ToString() + "]")
{
table.Rows[0].Cells[i].AddParagraph().AppendText(di.itemvalue);
}
}
}
for (int i = 1; i < maxrow + 1; i++)
for (int j = 0; j< maxcol + 1; j++) {
foreach (docitem di in docitemlist)
{
if (di.itemname == "table.tr[" + i.ToString() + "].td[" + (j).ToString() + "]")
{
table.Rows[i].Cells[j].AddParagraph().AppendText(di.itemvalue);
}
}
}
// Add content to the table cells
//table.Rows[0].Cells[0].AddParagraph().AppendText("Header 1");
//table.Rows[0].Cells[1].AddParagraph().AppendText("Header 2");
//table.Rows[0].IsHeader = true;
//table.Rows[1].Cells[0].AddParagraph().AppendText("Data 1");
//table.Rows[1].Cells[1].AddParagraph().AppendText("Data 2");
// Insert the table at the bookmark's location
bk.InsertTable(table);
string fontname = "";
string fontsize = "";
foreach (docitem di in docitemlist)
{
if (di.itemname == "table.Font") { fontname = di.itemvalue; }
if (di.itemname =="table.FontSize") { fontsize = di.itemvalue; }
}
foreach (WTableRow row in table.Rows)
{
// Iterate through each cell in the row.
foreach (WTableCell cell in row.Cells)
{
// Iterate through each paragraph in the cell.
foreach (WParagraph paragraph in cell.Paragraphs)
{
// Iterate through the child entities of the paragraph.
foreach (Entity entity in paragraph.ChildEntities)
{
// Check if the child entity is a text range.
if (entity is WTextRange)
{
// Change the font to Algerian for the text range.
(entity as WTextRange).CharacterFormat.FontName =fontname;
(entity as WTextRange).CharacterFormat.FontSize = Convert.ToInt32(fontsize); ;
}
}
}
}
}
bk.MoveToBookmark("bmlist");
string value = bk.CurrentBookmark.BookmarkStart.OwnerParagraph.Text;
bk.InsertText("Hallo ich bin der Text"+Environment.NewLine+"Ich bin die Zeile 2");
document.Save(textBox5.Text+".docx", FormatType.Docx);
}
public Boolean VerifyInput(string inputstring, string vtyp, ref DB db)
{
switch(vtyp) {
case "Dokumenttypnr":
db.Get_Tabledata("Select count(*) from dokumenttyp where aktiv = 1 and dokumenttypnr=" + inputstring, false, true);
if (db.dsdaten.Tables[0].Rows.Count > 0) { return true; } else { return false; }
break;
case "Partner":
db.Get_Tabledata("Select count (*) from partner where nrpar00=" + inputstring, false, true);
if (db.dsdaten.Tables[0].Rows.Count > 0) { return true; } else { return false; }
break;
default:
return false;
}
}
private void textBox6_TextChanged(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
}
//private void button1_Click(object sender, EventArgs e)
//{