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.

426 lines
15 KiB

using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.IO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using System.Text.RegularExpressions;
//using DOCGEN.Klassen;
using System.Security.Cryptography;
using SkiaSharp;
using System.Web;
using Syncfusion.Pdf;
using System.Diagnostics.Eventing.Reader;
using Syncfusion.DocToPDFConverter;
using Syncfusion.OfficeChart;
using System.Drawing.Imaging;
using Syncfusion.OfficeChart;
using Syncfusion.OfficeChartToImageConverter;
using Syncfusion.XPS;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Syncfusion.WinForms.ListView;
using Syncfusion.Windows.Forms.Tools;
namespace DocIO_Demo_SHU
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void Lic()
{
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Ngo9BigBOggjHTQxAR8/V1NCaF5cXmZCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdnWXdecXRdQ2heUU13XUI=");
}
private void Form1_Load(object sender, EventArgs e)
{
Lic();
ImageList imageList = new ImageList { ImageSize = new Size(32, 32) };
Image img = new Bitmap(Properties.Resources.Word_32x32_32);
imageList.Images.Add(img);
img = new Bitmap(Properties.Resources.Excel_32x32_32);
imageList.Images.Add(img);
img = new Bitmap(Properties.Resources.PDF_32x32_32);
imageList.Images.Add(img);
//listView1.LargeImageList = imageList;
////listView1.View = View.Tile;
//listView1.Items.Add("Mahesh Chand");
//listView1.Items.Add("Mike Gold");
//listView1.Items.Add("Praveen Kumar");
//listView1.Items.Add("Raj Beniwal");
//listView1.AllowDrop = true;
//listView1.AllowDrop = true;
//listView1.ItemDrag += new ItemDragEventHandler(myListView_ItemDrag);
//listView1.DragEnter += new DragEventHandler(myListView_DragEnter);
//listView1.DragOver += new DragEventHandler(myListView_DragOver);
//listView1.DragLeave += new EventHandler(myListView_DragLeave);
//listView1.DragDrop += new DragEventHandler(myListView_DragDrop);
}
private void myListView_ItemDrag(object sender, ItemDragEventArgs e)
{
//listView1.DoDragDrop(e.Item, DragDropEffects.Move);
}
// Sets the target drop effect.
private void myListView_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.AllowedEffect;
}
// Moves the insertion mark as the item is dragged.
// Sorts ListViewItem objects by index.
private class ListViewIndexComparer : System.Collections.IComparer
{
public int Compare(object x, object y)
{
return ((ListViewItem)x).Index - ((ListViewItem)y).Index;
}
}
private void split_doc(ref WordDocument wordDocument, ref WordDocument target, int Part, int sectionnr)
{
if (Part == 1)
{
target.Sections.Add(wordDocument.Sections[0].Clone());
}
else
{
int i = 0;
foreach (WSection section in wordDocument.Sections)
{
if (i != sectionnr)
{
target.Sections.Add(wordDocument.Sections[i].Clone());
}
i = i + 1;
}
}
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void treeViewAdv1_ItemDrag(object sender, ItemDragEventArgs e)
{
DoDragDrop(e.Item, DragDropEffects.Move);
}
private void treeViewAdv1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void treeView1_DragDrop(object sender, DragEventArgs e)
{
}
private void treeViewAdv1_ItemDrag_1(object sender, ItemDragEventArgs e)
{
TreeViewAdv treeViewAdv = sender as TreeViewAdv;
// The TreeViewAdv always provides an array of selected nodes.
TreeNodeAdv[] nodes = e.Item as TreeNodeAdv[];
// Let us get only the first selected node.
TreeNodeAdv node = nodes[0];
DragDropEffects result = treeViewAdv.DoDragDrop(node, DragDropEffects.Move);
}
private TreeNodeAdv currentSourceNode;
private void treeViewAdv1_DragOver(object sender, DragEventArgs e)
{
bool droppable = true;
TreeNodeAdv destinationNode = null;
TreeViewAdv treeView = sender as TreeViewAdv;
Point ptInTree = treeView.PointToClient(new Point(e.X, e.Y));
this.currentSourceNode = null;
// Looking for a single tree node.
if (e.Data.GetDataPresent(typeof(TreeNodeAdv)))
{
// Get the destination and source node.
destinationNode = treeView.GetNodeAtPoint(ptInTree);
TreeNodeAdv sourceNode = (TreeNodeAdv)e.Data.GetData(typeof(TreeNodeAdv));
this.currentSourceNode = sourceNode;
droppable = true;
}
else
droppable = false;
if (droppable)
// If Moving is allowed:
e.Effect = DragDropEffects.Move;
else
e.Effect = DragDropEffects.None;
Point pt = this.treeViewAdv1.PointToClient(new Point(e.X, e.Y));
this.treeViewAdv1.SelectedNode = this.treeViewAdv1.GetNodeAtPoint(pt);
Console.WriteLine(this.treeViewAdv1.SelectedNode.Text);
}
private void treeViewAdv1_DragDrop(object sender, DragEventArgs e)
{
TreeViewAdv treeView = sender as TreeViewAdv;
// Get the destination and source node.
TreeNodeAdv sourceNode = (TreeNodeAdv)e.Data.GetData(typeof(TreeNodeAdv));
Point pt = this.treeViewAdv1.PointToClient(new Point(e.X, e.Y));
TreeNodeAdv destinationNode = this.treeViewAdv1.GetNodeAtPoint(pt);
sourceNode.Move(destinationNode, NodePositions.Next);
this.currentSourceNode = null;
treeView.SelectedNode = sourceNode;
}
private void treeViewAdv1_DragLeave(object sender, EventArgs e)
{
//this.treeViewDragHighlightTracker.ClearHighlightNode();
}
private void treeViewAdv1_QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
{
if (e.EscapePressed)
{
e.Action = DragAction.Cancel;
}
}
private void treeViewAdv1_DragEnter_1(object sender, DragEventArgs e)
{
}
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();
//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");
}
private void button1_Click(object sender, EventArgs e)
{
}
//private void button1_Click(object sender, EventArgs e)
//{
// string filename = @"x:\docdemo\FIN_VER_Kredit_OV928_019.dotm";
// using (WordDocument wordDocument = new WordDocument(filename, FormatType.Docx))
// {
// //Initialize the ChartToImageConverter for converting charts during Word to image conversion.
// wordDocument.ChartToImageConverter = new ChartToImageConverter();
// //Set the scaling mode for charts (Normal mode reduces the file size).
// wordDocument.ChartToImageConverter.ScalingMode = ScalingMode.Normal;
// //Convert the entire Word document to images.
// Image[] images = wordDocument.RenderAsImages(ImageType.Bitmap);
// int i = 0;
// foreach (Image image in images)
// {
// //Save the image as jpeg.
// image.Save(@"x:\docdemo\WordToImage_" + i + ".jpeg", ImageFormat.Jpeg);
// i++;
// }
// }
// return;
// byte[] bytes = File.ReadAllBytes(textBox1.Text);
// string dokument = Convert.ToBase64String(bytes);
// var streamword = new MemoryStream(Convert.FromBase64String(dokument));
// WordDocument document = new WordDocument(streamword, Syncfusion.DocIO.FormatType.Automatic);
// WordDocument newDocument = new WordDocument();
// WordDocument newDocument2 = new WordDocument();
// WordDocument newDocument3 = new WordDocument();
// string pdf = "";
// SynFWord sf = new SynFWord();
// DOCGEN.DocGet dg = new DOCGEN.DocGet("");
// pdf = dg.Convert_Word_To_PDF(dokument, null);
// File.WriteAllBytes(textBox1.Text + "_3_" + ".pdf", Convert.FromBase64String(pdf));
// split_doc(ref document, ref newDocument, 1, 0);
// sf.Replace_Text(ref newDocument, "Bausteine", "");
// sf.Replace_Fieldtext(ref newDocument, "BesBest", "");
// MemoryStream outputStream = new MemoryStream();
// newDocument.Save(outputStream,FormatType.Dotm);
// bytes = outputStream.ToArray();
// dokument= Convert.ToBase64String(bytes);
// //DOCGEN.DocGet dg = new DOCGEN.DocGet("");
// pdf = dg.Convert_Word_To_PDF(dokument, null);
// File.WriteAllBytes(textBox1.Text + "_1_" + ".pdf", Convert.FromBase64String(pdf));
// return;
// //Vertrag Kunde
// split_doc(ref document, ref newDocument2, 2, 0);
// sf.Replace_Fieldtext(ref newDocument2, "BesBest", "");
// sf.Replace_Fieldtext(ref newDocument2, "txtDruckenExemplar", "den Kunden");
// newDocument2.UpdateDocumentFields();
// newDocument2.Save(outputStream, FormatType.Dotm);
// bytes = outputStream.ToArray();
// dokument = Convert.ToBase64String(bytes);
// pdf = dg.Convert_Word_To_PDF(dokument, null);
// File.WriteAllBytes(textBox1.Text + "_2_" + ".pdf", Convert.FromBase64String(pdf));
// //Vertrag Kunde
// split_doc(ref document, ref newDocument3, 2, 0);
// sf.Replace_Fieldtext(ref newDocument3, "BesBest", "");
// sf.Replace_Fieldtext(ref newDocument3, "txtDruckenExemplar", "den Kunden");
// newDocument3.UpdateDocumentFields();
// newDocument3.Save(outputStream, FormatType.Dotm);
// bytes = outputStream.ToArray();
// dokument = Convert.ToBase64String(bytes);
// pdf = dg.Convert_Word_To_PDF(dokument, null);
// File.WriteAllBytes(textBox1.Text + "_3_" + ".pdf", Convert.FromBase64String(pdf));
// //using (FileStream outputStream = new FileStream(textBox1.Text + "_1_" + ".dotm", FileMode.OpenOrCreate, FileAccess.ReadWrite))
// //{
// // newDocument.Save(outputStream, FormatType.Dotm);
// //}
// //int i = 0;
// //foreach (WSection section in document.Sections)
// //{
// // if (i != 0)
// // {
// // newDocument1.Sections.Add(document.Sections[i].Clone());
// // }
// // i = i + 1;
// //}
// //sf.Replace_Fieldtext(ref newDocument1, "txtDruckenExemplar", "den Kunden");
// //sf.Replace_Text(ref newDocument1, "Bausteine", "");
// //newDocument1.UpdateDocumentFields();
// //using (FileStream outputStream = new FileStream(textBox1.Text + "_2_" + ".dotm", FileMode.OpenOrCreate, FileAccess.ReadWrite))
// //{
// // newDocument1.Save(outputStream, FormatType.Dotm);
// //}
// //sf.Replace_Fieldtext(ref newDocument1, "txtDruckenExemplar", "die Bank");
// //newDocument1.UpdateDocumentFields();
// //using (FileStream outputStream = new FileStream(textBox1.Text + "_3_" + ".dotm", FileMode.OpenOrCreate, FileAccess.ReadWrite))
// //{
// // newDocument1.Save(outputStream, FormatType.Dotm);
// //}
//}
//foreach (WSection section in document.Sections)
//{
// int fileId = 0;
// //Create new Word document
// using (WordDocument newDocument = new WordDocument())
// {
// //Add cloned section into new Word document
// newDocument.Sections.Add(section.Clone());
// //Saves the Word document to MemoryStream
// using (FileStream outputStream = new FileStream(textBox1.Text + fileId + ".docx", FileMode.OpenOrCreate, FileAccess.ReadWrite))
// {
// newDocument.Save(outputStream, FormatType.Dotm);
// }
// }
// fileId++;
//}
//return;
//document.Open(textBox1.Text);
//document.UpdateDocumentFields();
//document.Save(textBox1.Text + ".dotm");
//try
//{
// 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 == "txtDruckenExemplar")
// {
// formField.Text = "für die Bank";
// break;
// }
// }
// }
//}
//catch { }
//try
//{
// 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 == "BesBest")
// {
// formField.Text = "";
// break;
// }
// }
// }
//}
//catch { }
////BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
////bookmarkNavigator.MoveToBookmark("txtDruckenExemplar");
////bookmarkNavigator.InsertText("für die anderen");
//document.UpdateDocumentFields();
//document.Save(textBox1.Text + ".dotm.dotm");
}
}