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.

488 lines
21 KiB

using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Shape = Syncfusion.DocIO.DLS.Shape;
using Syncfusion.DocIO.ReaderWriter;
using System.IO;
using Syncfusion.Pdf;
using Syncfusion.OfficeChart;
using Syncfusion.DocToPDFConverter;
using Syncfusion.OfficeChartToImageConverter;
using static System.Net.WebRequestMethods;
using System.Net.WebSockets;
using Database;
using System.Runtime.Hosting;
using System.Data.SqlClient;
using System.Security.Cryptography;
namespace ZZ_Signature_C
{
public partial class Form1 : Form
{
Microsoft.Office.Interop.Word.Application word;
Microsoft.Office.Interop.Word.Document docWord;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connectionstring = this.txtconnectionstring.Text;
OnDocOffice.word_signature ws = new OnDocOffice.word_signature(connectionstring);
word = new Microsoft.Office.Interop.Word.Application();
word.Visible = true;
docWord = word.Documents.Open(txtfilename.Text);
word.Activate();
string ul = txtunterschriftlinks.Text;
string ur = txtunterschriftrechts.Text;
ws.sign_doc(ref word, ul, ur, "", txtdoktypnr.Text);
docWord.Activate();
word.Visible = true;
docWord = null;
word = null;
}
private void remove_unterschriften()
{
bool found = true;
MessageBox.Show(word.ActiveDocument.Shapes.Count.ToString());
int i = 1;
while (word.ActiveDocument.Shapes.Count > 0 && found==true)
{
found = false;
if (word.ActiveDocument.Shapes[i].Name.Contains("Unterschrift_"))
{
word.ActiveDocument.Shapes[i].Delete();
found= true;
}
}
//foreach (Microsoft.Office.Interop.Word.Shape sh in docWord.Shapes) {
// if (sh.Name.Contains("Unterschrift_")){
// sh.Delete();
// }
//}
}
private void insert_unterschrift(string tmn) {
object missing = Type.Missing;
Microsoft.Office.Interop.Word.Range myRange = docWord.Bookmarks[tmn].Range;
Microsoft.Office.Interop.Word.Bookmark bm = docWord.Bookmarks[tmn];
float vertical = bm.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdVerticalPositionRelativeToPage];
float horizontal = bm.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdHorizontalPositionRelativeToPage];
docWord.Activate();
Microsoft.Office.Interop.Word.Range myRange3 = bm.Range;
Microsoft.Office.Interop.Word.Range myRange4 = bm.Range.GoTo();
Microsoft.Office.Interop.Word.Shape myShape = docWord.Shapes.AddPicture(@"E:\Software-Projekte\OnDoc\Unterschriften\1.jpg", false, true, 0, 0, 120, 50, myRange);
myShape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapTight;
myShape.RelativeHorizontalPosition = Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;
myShape.Left = horizontal;
myShape.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
myShape.Top = vertical - myShape.Height;
//myShape.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue;
myShape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapBehind;
myShape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBackward);
myShape.Select();
return;
//vertical = vertical - 50;
//word.ActiveDocument.Bookmarks[tmn].Select();
//Microsoft.Office.Interop.Word.Shape myshape1 = docWord.Shapes.AddShape(1, horizontal, vertical, 120, 50);
//myshape1.Fill.UserPicture(@"E:\Software-Projekte\OnDoc\Unterschriften\1.jpg");
////myshape1.Line.Weight = -2;
//myshape1.Name = "Unterschrift" + "_" + tmn;
//myshape1.Line.Visible= Microsoft.Office.Core.MsoTriState.msoFalse;
////Microsoft.Office.Interop.Word.InlineShape myshape3 = word.Selection.InlineShapes.AddPicture(@"E:\Software-Projekte\OnDoc\Unterschriften\1.jpg",false,true,myRange,);
Microsoft.Office.Interop.Word.Shape myshape = docWord.Shapes.AddTextbox(Microsoft.Office.Core
.MsoTextOrientation.msoTextOrientationHorizontal, (float)horizontal,
(float)vertical, 120, 56, ref missing);
myshape.Name = "Unterschrift" + "_" + tmn;
myshape.TextFrame.ContainingRange.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleNone;
myshape.TextFrame.ContainingRange.Borders.InsideLineStyle = WdLineStyle.wdLineStyleNone;
myshape.Fill.UserPicture(@"E:\Software-Projekte\OnDoc\Unterschriften\1.jpg");
myshape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare;
myshape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
}
public void Lic()
{
// 25. string lickey = "Ngo9BigBOggjHTQxAR8/V1NCaF5cXmZCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdnWXdecXRdQ2heUU13XUI="
//string lickey = "Ngo9BigBOggjHTQxAR8/V1NCaF5cXmZCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdnWXZeeXRQR2NZUEZ2WkE=";
string lickey = "MzYzODg2NkAzMjM4MmUzMDJlMzBTOWljRmxNelA1d1VGOHpGR0lxQzB6UTAwKzIxK2VBNEhBZFp5alcxb1NVPQ==";
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(lickey);
}
private void button2_Click(object sender, EventArgs e)
{
Lic();
WordDocument document = new WordDocument();
document.Open(@"E:\Software-Projekte\OnDoc\Excel_Dateien\Signature.docx");
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
bookmarkNavigator.MoveToBookmark("Unterschrift2");
Syncfusion.DocIO.DLS.Bookmark bm = document.Bookmarks["Unterschrift2"];
Shape signature = bm.BookmarkStart.OwnerParagraph.AppendShape(AutoShapeType.Rectangle, 120, 59);
//signature.WrapFormat.AllowOverlap = true;
signature.VerticalPosition = signature.VerticalPosition -50;
signature.LineFormat.DashStyle = LineDashing.Solid;
signature.LineFormat.Color = Color.White;
IWParagraph p = signature.TextBody.AddParagraph();
System.Drawing.Image sfimage = Image.FromFile(@"E:\Software-Projekte\OnDoc\Unterschriften\1.jpg");
IWPicture pi = p.AppendPicture(sfimage);
pi.Width = 120;
pi.Height = 50;
//Shape signature = bm.BookmarkStart.OwnerParagraph.AppendShape(Syncfusion.DocIO.DLS.AutoShapeType.Rectangle, 120, 50);
////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 - 50;
////signature.HorizontalPosition = signature.HorizontalPosition + 200;
//sigparagraph.AppendPicture(img);
//signature.Name = "Unterschrift_" + bookmark;
//// signature.OwnerParagraph.AppendPicture(img);
//mssign = null;
//Shape signature2 = bm.BookmarkStart.OwnerParagraph.AppendShape(AutoShapeType.Rectangle, 50, 50);
//signature2.WrapFormat.AllowOverlap = true;
//int index = bm.BookmarkStart.OwnerParagraph.ChildEntities.IndexOf(bm.BookmarkStart);
//bm.BookmarkStart.OwnerParagraph.ChildEntities.Insert(index, signature2);
//Syncfusion.DocIO.DLS.Bookmark x = document.Bookmarks.FindByName("Unterschrift2");
//IWParagraph p = x.BookmarkStart.Document.CreateParagraph();
//p.AppendShape(AutoShapeType.CircularArrow, 50, 50);
//bookmarkNavigator.InsertParagraph(p);
//IWParagraph paragraph = document.Sections[0].Paragraphs[0];
//if (document.Sections.Count < 1)
//{
// document.AddSection();
//}
//IWParagraph footerparagraph;
//if (document.Sections[0].HeadersFooters.Footer.Paragraphs.Count < 1)
//{
// footerparagraph = document.Sections[0].HeadersFooters.Footer.AddParagraph();
//}
//footerparagraph = document.Sections[0].HeadersFooters.Footer.Paragraphs[0];
//System.Drawing.Image sfimage = Image.FromFile(@"x:\gaga.png");
////sfimage = AutoSizeImage(sfimage, Convert.ToInt32(this.width), Convert.ToInt32(this.height), false);
////sfimage = ScaleImage(sfimage, Convert.ToInt32(this.width), Convert.ToInt32(this.height));
//Shape rectangle = footerparagraph.AppendShape(AutoShapeType.Rectangle, Convert.ToInt32(this.width), Convert.ToInt32(this.height));
//paragraph = rectangle.TextBody.AddParagraph() as WParagraph;
//rectangle.LineFormat.Line = false;
//IWPicture pic = paragraph.AppendPicture(sfimage);
//pic.Width = 160;
//pic.Height = 28;
//rectangle.VerticalPosition = (Convert.ToInt32(this.top) / 150 * 2.83465f);
//rectangle.HorizontalPosition = Convert.ToInt32(this.left);
////rectangle.LineFormat.DashStyle = LineDashing.Dot;
////rectangle.LineFormat.Color = Color.DarkGray;
////IWParagraph rectangleparagraph = rectangle.TextBody.AddParagraph();
////IWPicture picture = rectangleparagraph.AppendPicture(sfimage);
////footerparagraph.AppendShape
document.Save(@"x:\gaga.docx");
document.Close();
System.Diagnostics.Process.Start("winword.exe", "/w " + @"x:\gaga.docx");
return;
//WordDocument document = new WordDocument();
//document.Open(@"E:\Software-Projekte\OnDoc\Excel_Dateien\empty.docx");
////Add a new section to the document.
//IWSection section = document.AddSection();
////Add a new paragraph to the section.
//IWParagraph paragraph = section.AddParagraph() as WParagraph;
//Shape rectangle = paragraph.AppendShape(AutoShapeType.RoundedRectangle, 150, 100);
//rectangle.VerticalPosition = 72;
//rectangle.HorizontalPosition = 72;
//paragraph = section.AddParagraph() as WParagraph;
//paragraph = rectangle.TextBody.AddParagraph() as WParagraph;
//System.Drawing.Image sfimage = Image.FromFile(@"x:\gaga.png");
//paragraph.AppendPicture(sfimage);
//IWTextRange text = paragraph.AppendText("This text is in rounded rectangle shape");
//text.CharacterFormat.TextColor = Color.Green;
//text.CharacterFormat.Bold = true;
////Apply fill color for shape.
//rectangle.FillFormat.Fill = true;
//rectangle.FillFormat.Color = Color.LightGray;
////Set transparency (opacity) to the shape fill color.
//rectangle.FillFormat.Transparency = 75;
////Apply wrap formats.
//rectangle.WrapFormat.TextWrappingStyle = TextWrappingStyle.Square;
//rectangle.WrapFormat.TextWrappingType = TextWrappingType.Right;
////Set horizontal and vertical origin.
//rectangle.HorizontalOrigin = HorizontalOrigin.Margin;
//rectangle.VerticalOrigin = VerticalOrigin.Page;
////Set line format.
//rectangle.LineFormat.DashStyle = LineDashing.Dot;
//rectangle.LineFormat.Color = Color.DarkGray;
////Set the left internal margin for the shape.
//rectangle.TextFrame.InternalMargin.Left = 30;
////Set the right internal margin for the shape.
//rectangle.TextFrame.InternalMargin.Right = 24;
////Set the bottom internal margin for the shape.
//rectangle.TextFrame.InternalMargin.Bottom = 18;
////Set the top internal margin for the shape.
//rectangle.TextFrame.InternalMargin.Top = 6;
////Saves the Word document to MemoryStream
//document.Save(@"x:\gaga.docx", FormatType.Docx);
////Closes the Word document
//document.Close();
}
public string connectionstring;
public DataSet dsdaten = new DataSet();
private static System.Data.DataTable SP_Parameters = new System.Data.DataTable();
private void button3_Click(object sender, EventArgs e)
{
connectionstring= @"data source=shu01\shu00;initial catalog=edoka_dms;;workstation id=;packet size=4096;user id=sa;password=*shu29";
SP_Parameters.Columns.Clear();
SP_Parameters.Rows.Clear();
SP_Parameters.Clear();
SP_Parameters.Columns.Add("Paramname");
SP_Parameters.Columns.Add("Paramvalue");
DataRow r = SP_Parameters.NewRow();
r[0] = "@dokumentid";
r[1] = "'1' UNION SELECT 1 as dokumenttypnr, name as doumentname from SYSOBJECTS WHERE xtype = 'U'";
SP_Parameters.Rows.Add(r);
Get_Tabledata("Select * from dokument where dokumentid=@dokumentid", false, true);
}
public System.Data.DataTable Get_Tabledata(string Tablename, bool StoredProc = false, bool is_SQL_String = false, System.Data.DataTable sp_params = null)
{
try
{
if (sp_params == null && SP_Parameters.Rows.Count > 0)
{
sp_params = SP_Parameters.Copy();
}
SqlConnection sqlconnect = new SqlConnection();
DataSet ds = new DataSet();
ds.Tables.Clear();
dsdaten.Tables.Clear();
sqlconnect.ConnectionString = connectionstring;
SqlDataAdapter da = new SqlDataAdapter("", sqlconnect);
SqlCommand sqlcmd = new SqlCommand();
sqlcmd.Connection = sqlconnect;
if (StoredProc == true)
{
sqlcmd.CommandType = CommandType.StoredProcedure;
if (Tablename.IndexOf("@@Mandantnr@@") > 0)
Tablename = Tablename.Replace("@@Mandantnr@@", "");
sqlcmd.CommandText = Tablename;
try
{
foreach (DataRow r in sp_params.Rows)
{
sqlcmd.Parameters.Add(r["Paramname"].ToString(), SqlDbType.VarChar);
sqlcmd.Parameters[sqlcmd.Parameters.Count - 1].Value = r["Paramvalue"].ToString();
}
}
catch { };
}
else
{
sqlcmd.CommandType = CommandType.Text;
sqlcmd.CommandText = "Select * from " + Tablename;
}
if (is_SQL_String == true)
sqlcmd.CommandText = Tablename;
foreach (DataRow r in sp_params.Rows)
{
sqlcmd.Parameters.AddWithValue(r["Paramname"].ToString(), r["Paramvalue"].ToString());
}
da.SelectCommand = sqlcmd;
sqlconnect.Open();
da.Fill(dsdaten, "Daten1");
sqlconnect.Close();
return dsdaten.Tables[0];
}
catch (Exception ex)
{
return null;
}
}
private void button4_Click(object sender, EventArgs e)
{
WordDocument wordDocument = new WordDocument(@"E:\Software-Projekte\OnDoc\Excel_Dateien\SignatureSigned.docx", Syncfusion.DocIO.FormatType.Automatic);
wordDocument.ChartToImageConverter = new ChartToImageConverter();
wordDocument.ChartToImageConverter.ScalingMode = ScalingMode.Normal;
Syncfusion.DocToPDFConverter.DocToPDFConverter converter = new Syncfusion.DocToPDFConverter.DocToPDFConverter();
converter.Settings.EmbedFonts = true;
converter.Settings.UpdateDocumentFields = false;
converter.Settings.EnableAlternateChunks = true;
converter.Settings.AutoDetectComplexScript = true;
converter.Settings.ImageResolution = 1280;
converter.Settings.ImageQuality = 100;
using (PdfDocument pdfDocument = converter.ConvertToPDF(wordDocument))
{
pdfDocument.Save(Path.GetFullPath(@"E:\Software-Projekte\OnDoc\Excel_Dateien\SignatureSigned.pdf"));
this.pdfViewerControl1.Load(@"E:\Software-Projekte\OnDoc\Excel_Dateien\SignatureSigned.pdf");
}
}
private void Form1_Load(object sender, EventArgs e)
{
string[] lines = System.IO.File.ReadAllLines(System.Windows.Forms.Application.StartupPath + "\\params.txt");
int i = -1;
foreach (string line in lines)
{
i = i + 1;
switch (i)
{
case 0: this.txtconnectionstring.Text = line;break;
case 1: this.txtdoktypnr.Text = line;break;
case 2: this.txtfilename.Text = line;break;
case 3: this.txtunterschriftlinks.Text= line;break;
case 4: this.txtunterschriftrechts.Text = line; break;
default:break;
}
}
}
private void button5_Click(object sender, EventArgs e)
{
Lic();
FileStream inputFileStream = new FileStream(Path.GetFullPath(@"E:\Software-Projekte\OnDoc\Excel_Dateien\20250225074324_OFFEDK0082025000066663.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
WordDocument document = new WordDocument(inputFileStream, FormatType.Automatic);
WPicture picture = new WPicture(document);
Image img = Image.FromFile(@"x:\gaga1.png");
picture.LoadImage(img);
IWPicture pic = picture;
foreach (WSection section in document.Sections)
{
////picture.Height = docData.barcode_height;
////picture.Width = docData.barcode_width;
picture.VerticalPosition = 500;
//picture.HorizontalPosition = 500;
//picture.HorizontalOrigin = HorizontalOrigin.Page;
//picture.VerticalOrigin = VerticalOrigin.Page;
picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText;
picture.TextWrappingType = TextWrappingType.Both;
////picture.Width = barcodeimage.Width;
////picture.Height = barcodeimage.Height;
//picture.Rotation = 0;
//picture.Height = 40;
//picture.Width = 120;
WPicture picture2 = new WPicture(document);
picture2.LoadImage(img);
IWParagraph footerPar = section.HeadersFooters.FirstPageFooter.Paragraphs[0];
footerPar.ChildEntities.Add(picture);
IWParagraph footerPar1 = section.HeadersFooters.Footer.Paragraphs[0];
footerPar1.ChildEntities.Add(picture2);
//section.HeadersFooters.Footer.AddParagraph().ChildEntities.Add(picture);
//section.HeadersFooters.FirstPageFooter.AddParagraph().ChildEntities.Add(picture2);
////if (section.HeadersFooters.FirstPageFooter.Paragraphs.Count < 1)
////{
//section.HeadersFooters.FirstPageFooter.AddParagraph();
//section.HeadersFooters.FirstPageFooter.Paragraphs[0].ChildEntities.Add(picture);
//}
//Syncfusion.DocIO.DLS.IWParagraph paragraph = section.Body.LastParagraph;
//if (paragraph != null)
// paragraph.ChildEntities.Add(picture);
}
document.Save(@"E:\Software-Projekte\OnDoc\Excel_Dateien\20250225074324_OFFEDK0082025000066663.docx.docx");
document.Close(); ;
}
}
}