diff --git a/BerichtGen/Bericht.cs b/BerichtGen/Bericht.cs new file mode 100644 index 0000000..7e9465e --- /dev/null +++ b/BerichtGen/Bericht.cs @@ -0,0 +1,115 @@ +using SanShared; +using Syncfusion.DocIO.DLS; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BerichtGen +{ + public class Bericht + { + private List _listImages; + /// + /// Erstellt + /// + /// Die zuverwendete Vorlagenname + /// Die name zum Speichern der Datei + /// Pfad zum Speichern + /// Inhalt vom Dokument + /// Ein doc datei soll erzeugt werden + /// Ein Pdf datei soll erzeugt werden + public void Erzeuge(string firma, string vorlage, string savepath, Hashtable daten,List bilderObjects, bool erzeugeDOC = false , bool erzeugePDF = true) + { + _listImages = new List(); + foreach(BilderObject current in bilderObjects) + { + Image image = Image.FromFile(current.Path); + _listImages.Add(ResizeImage(image, CalculateImageSizeForDocument(image.Height, image.Width))); + image.Dispose(); + } + + WordDocument wordDocument = new WordDocument("./documents/JUME/liner_einbau.docx"); + + string[] fieldnames = null; + string[] fieldvalues = null; + + if(fieldnames == null || fieldvalues == null) + { + fieldnames = new string[daten.Count]; + fieldvalues = new string[daten.Count]; + } + + uint counter = 0; + foreach(DictionaryEntry hashtable in daten) + { + fieldnames[counter] = hashtable.Key.ToString(); + if (hashtable.Value == null) + { + fieldvalues[counter] = ""; + } + else + { + fieldvalues[counter] = hashtable.Value.ToString(); + } + counter++; + } + wordDocument.MailMerge.Execute(fieldnames, fieldvalues); + wordDocument.MailMerge.MergeImageField += new MergeImageFieldEventHandler(this.MailMerge_MergeImageField); + + } + private readonly double _cmPixel = 0.393700787; + private readonly int _dpi = 120; + private readonly double _imgWidthCmMax = 8.0; + + private Size CalculateImageSizeForDocument(int height, int width) + { + double num = (double)height / (double)width; + double num2 = this._imgWidthCmMax * num; + int h = (int)(num2 * _cmPixel * (double)_dpi); + int w = (int)(_imgWidthCmMax * _cmPixel * (double)_dpi); + return new Size(w, h); + } + + private Image ResizeImage(Image image, Size size) + { + int width = image.Width; + int height = image.Height; + float num = (float)size.Width / (float)width; + float num2 = (float)size.Height / (float)height; + float num3 = (num2 < num) ? num2 : num; + int width2 = (int)((float)width * num3); + int height2 = (int)((float)height * num3); + Bitmap bitmap = new Bitmap(width2, height2); + try + { + bitmap.SetResolution(120f, 120f); + Graphics graphics = Graphics.FromImage(bitmap); + graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; + graphics.DrawImage(image, 0, 0, width2, height2); + graphics.Dispose(); + + } + catch(Exception ex) + { + + } + finally + { + System.GC.Collect(); + } + return bitmap; + } + + private void MailMerge_MergeImageField(object sender, MergeImageFieldEventArgs args) + { + + } + + + + } +} diff --git a/BerichtGen/BerichtGen.csproj b/BerichtGen/BerichtGen.csproj index 4ee8843..0a50aaa 100644 --- a/BerichtGen/BerichtGen.csproj +++ b/BerichtGen/BerichtGen.csproj @@ -30,8 +30,37 @@ 4 + + False + ..\3rdPackage\Syncfusion.Compression.Base.dll + + + ..\3rdPackage\Syncfusion.Core.dll + + + False + ..\3rdPackage\Syncfusion.DocIO.Base.dll + + + False + ..\3rdPackage\Syncfusion.DocToPDFConverter.Base.dll + + + False + ..\3rdPackage\Syncfusion.OfficeChart.Base.dll + + + False + ..\3rdPackage\Syncfusion.Pdf.Base.dll + + + False + ..\3rdPackage\Syncfusion.PdfViewer.Windows.dll + + + @@ -40,7 +69,25 @@ + + + Form + + + Options.cs + + + + Options.cs + + + + + {C949087E-20E1-4A17-B021-FAEAD363C1D8} + SanShared + + \ No newline at end of file diff --git a/BerichtGen/Options.Designer.cs b/BerichtGen/Options.Designer.cs new file mode 100644 index 0000000..b5ff1d9 --- /dev/null +++ b/BerichtGen/Options.Designer.cs @@ -0,0 +1,60 @@ +namespace BerichtGen +{ + partial class Options + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.btn_start = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // btn_start + // + this.btn_start.Location = new System.Drawing.Point(176, 249); + this.btn_start.Name = "btn_start"; + this.btn_start.Size = new System.Drawing.Size(75, 67); + this.btn_start.TabIndex = 0; + this.btn_start.Text = "button1"; + this.btn_start.UseVisualStyleBackColor = true; + this.btn_start.Click += new System.EventHandler(this.btn_start_Click); + // + // Options + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.btn_start); + this.Name = "Options"; + this.Text = "Options"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button btn_start; + } +} \ No newline at end of file diff --git a/BerichtGen/Options.cs b/BerichtGen/Options.cs new file mode 100644 index 0000000..b55c2c9 --- /dev/null +++ b/BerichtGen/Options.cs @@ -0,0 +1,53 @@ +using SanShared; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BerichtGen +{ + public partial class Options : Form + { + Thread generateProtokollThread; + Hashtable grundDaten; + string firma; + string vorlage; + string speicherpfad; + List bilderObjects; + + + public Options(string firma, string vorlage, string speicherpfad, Hashtable grunddaten, List bilderObjects) + { + InitializeComponent(); + this.firma = firma; + this.vorlage = vorlage; + this.speicherpfad = speicherpfad; + this.grundDaten = grunddaten; + this.bilderObjects = bilderObjects; + } + + void Gen() + { + Bericht bericht = new Bericht(); + bericht.Erzeuge("", "", "", grundDaten,bilderObjects); + } + + private void btn_start_Click(object sender, EventArgs e) + { + generateProtokollThread = new Thread(Gen); + generateProtokollThread.IsBackground = true; + generateProtokollThread.Start(); + + while (generateProtokollThread.IsAlive) ; + + this.Close(); + } + } +} diff --git a/BerichtGen/Options.resx b/BerichtGen/Options.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BerichtGen/Options.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SanShared/BilderObject.cs b/SanShared/BilderObject.cs new file mode 100644 index 0000000..c37a13b --- /dev/null +++ b/SanShared/BilderObject.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SanShared +{ + public class BilderObject + { + public string Kommentar { get; set; } + public string Path { get; set; } + public int ImgID { get; set; } + } +} diff --git a/SanShared/SanShared.csproj b/SanShared/SanShared.csproj index 414c886..b21b308 100644 --- a/SanShared/SanShared.csproj +++ b/SanShared/SanShared.csproj @@ -40,6 +40,7 @@ + diff --git a/SanSystem/SanSystem.csproj b/SanSystem/SanSystem.csproj index 0f84536..c59cb54 100644 --- a/SanSystem/SanSystem.csproj +++ b/SanSystem/SanSystem.csproj @@ -127,7 +127,7 @@ UCSchachtanbindung.cs - + PreserveNewest @@ -146,6 +146,10 @@ + + {3022da07-fd06-4aea-9fc8-00d318e95a82} + BerichtGen + {b0227727-6cf9-4e2e-9afe-5dd76deaa9db} Database diff --git a/SanSystem/UCInliner.Designer.cs b/SanSystem/UCInliner.Designer.cs index cc75f5a..3be2f1d 100644 --- a/SanSystem/UCInliner.Designer.cs +++ b/SanSystem/UCInliner.Designer.cs @@ -30,6 +30,8 @@ { this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage2 = new System.Windows.Forms.TabPage(); + this.ftpProgress = new System.Windows.Forms.ProgressBar(); + this.btn_transfer_ftp = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.dt_eingebaut = new System.Windows.Forms.DateTimePicker(); this.cb_fertig = new System.Windows.Forms.CheckBox(); @@ -67,8 +69,7 @@ this.label11 = new System.Windows.Forms.Label(); this.label10 = new System.Windows.Forms.Label(); this.label9 = new System.Windows.Forms.Label(); - this.btn_transfer_ftp = new System.Windows.Forms.Button(); - this.ftpProgress = new System.Windows.Forms.ProgressBar(); + this.button1 = new System.Windows.Forms.Button(); this.tabControl1.SuspendLayout(); this.tabPage2.SuspendLayout(); this.groupBox3.SuspendLayout(); @@ -90,6 +91,7 @@ // // tabPage2 // + this.tabPage2.Controls.Add(this.button1); this.tabPage2.Controls.Add(this.ftpProgress); this.tabPage2.Controls.Add(this.btn_transfer_ftp); this.tabPage2.Controls.Add(this.label1); @@ -113,6 +115,23 @@ this.tabPage2.Text = "Vorraussetzungen"; this.tabPage2.UseVisualStyleBackColor = true; // + // ftpProgress + // + this.ftpProgress.Location = new System.Drawing.Point(782, 487); + this.ftpProgress.Name = "ftpProgress"; + this.ftpProgress.Size = new System.Drawing.Size(280, 37); + this.ftpProgress.TabIndex = 29; + // + // btn_transfer_ftp + // + this.btn_transfer_ftp.Location = new System.Drawing.Point(820, 317); + this.btn_transfer_ftp.Name = "btn_transfer_ftp"; + this.btn_transfer_ftp.Size = new System.Drawing.Size(224, 126); + this.btn_transfer_ftp.TabIndex = 28; + this.btn_transfer_ftp.Text = "button1"; + this.btn_transfer_ftp.UseVisualStyleBackColor = true; + this.btn_transfer_ftp.Click += new System.EventHandler(this.btn_transfer_ftp_Click); + // // label1 // this.label1.AutoSize = true; @@ -515,22 +534,15 @@ this.label9.TabIndex = 0; this.label9.Text = "Harz"; // - // btn_transfer_ftp + // button1 // - this.btn_transfer_ftp.Location = new System.Drawing.Point(820, 317); - this.btn_transfer_ftp.Name = "btn_transfer_ftp"; - this.btn_transfer_ftp.Size = new System.Drawing.Size(224, 126); - this.btn_transfer_ftp.TabIndex = 28; - this.btn_transfer_ftp.Text = "button1"; - this.btn_transfer_ftp.UseVisualStyleBackColor = true; - this.btn_transfer_ftp.Click += new System.EventHandler(this.btn_transfer_ftp_Click); - // - // ftpProgress - // - this.ftpProgress.Location = new System.Drawing.Point(782, 487); - this.ftpProgress.Name = "ftpProgress"; - this.ftpProgress.Size = new System.Drawing.Size(280, 37); - this.ftpProgress.TabIndex = 29; + this.button1.Location = new System.Drawing.Point(829, 197); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(199, 66); + this.button1.TabIndex = 30; + this.button1.Text = "button1"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); // // UCInliner // @@ -598,5 +610,6 @@ private System.Windows.Forms.DateTimePicker dt_eingebaut; private System.Windows.Forms.Button btn_transfer_ftp; private System.Windows.Forms.ProgressBar ftpProgress; + private System.Windows.Forms.Button button1; } } diff --git a/SanSystem/UCInliner.cs b/SanSystem/UCInliner.cs index 233c8ae..d9061f7 100644 --- a/SanSystem/UCInliner.cs +++ b/SanSystem/UCInliner.cs @@ -12,6 +12,7 @@ using System.Diagnostics; using System.IO; using SanShared; using FluentFTP; +using System.Collections; namespace SanSystem { @@ -181,5 +182,22 @@ namespace SanSystem } } } + + private void button1_Click(object sender, EventArgs e) + { + Hashtable grunddaten = new Hashtable() + { + {"KL_Wetter","Trocken" } + }; + List bilderO = new List(); + bilderO.Add(new BilderObject() + { + ImgID = 1, + Kommentar = "TestBild", + Path = @"C:\Users\Damian\Desktop\SanVerwaltung\SanSystem\bin\Debug\projekte\18-850\SW01-SW02\Schachtanbindung\4d0a1627-bd51-48d6-a27e-a4c6691b02d2.jpg" + }); + BerichtGen.Options options = new BerichtGen.Options("", "", "", grunddaten,bilderO); + options.ShowDialog(); + } } } diff --git a/SanSystem/documents/JUME/klp_vorlage.docx b/SanSystem/documents/JUME/liner_einbau.docx similarity index 51% rename from SanSystem/documents/JUME/klp_vorlage.docx rename to SanSystem/documents/JUME/liner_einbau.docx index 72a8b10..762a821 100644 Binary files a/SanSystem/documents/JUME/klp_vorlage.docx and b/SanSystem/documents/JUME/liner_einbau.docx differ