This commit is contained in:
Husky
2018-07-01 22:39:05 +02:00
parent aad486e11f
commit d01e8474ac
11 changed files with 464 additions and 18 deletions

115
BerichtGen/Bericht.cs Normal file
View File

@@ -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<Image> _listImages;
/// <summary>
/// Erstellt
/// </summary>
/// <param name="vorlage">Die zuverwendete Vorlagenname</param>
/// <param name="documentname">Die name zum Speichern der Datei</param>
/// <param name="savepath">Pfad zum Speichern</param>
/// <param name="daten">Inhalt vom Dokument </param>
/// <param name="erzeugeDoc">Ein doc datei soll erzeugt werden</param>
/// <param name="erzeugePDF">Ein Pdf datei soll erzeugt werden</param>
public void Erzeuge(string firma, string vorlage, string savepath, Hashtable daten,List<BilderObject> bilderObjects, bool erzeugeDOC = false , bool erzeugePDF = true)
{
_listImages = new List<Image>();
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)
{
}
}
}

View File

@@ -30,8 +30,37 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Syncfusion.Compression.Base, Version=16.1460.0.37, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\3rdPackage\Syncfusion.Compression.Base.dll</HintPath>
</Reference>
<Reference Include="Syncfusion.Core">
<HintPath>..\3rdPackage\Syncfusion.Core.dll</HintPath>
</Reference>
<Reference Include="Syncfusion.DocIO.Base, Version=16.1460.0.37, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\3rdPackage\Syncfusion.DocIO.Base.dll</HintPath>
</Reference>
<Reference Include="Syncfusion.DocToPDFConverter.Base, Version=16.1460.0.37, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\3rdPackage\Syncfusion.DocToPDFConverter.Base.dll</HintPath>
</Reference>
<Reference Include="Syncfusion.OfficeChart.Base, Version=16.1460.0.37, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\3rdPackage\Syncfusion.OfficeChart.Base.dll</HintPath>
</Reference>
<Reference Include="Syncfusion.Pdf.Base, Version=16.1460.0.37, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\3rdPackage\Syncfusion.Pdf.Base.dll</HintPath>
</Reference>
<Reference Include="Syncfusion.PdfViewer.Windows, Version=16.1460.0.37, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\3rdPackage\Syncfusion.PdfViewer.Windows.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@@ -40,7 +69,25 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Bericht.cs" />
<Compile Include="Options.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Options.Designer.cs">
<DependentUpon>Options.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Options.resx">
<DependentUpon>Options.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SanShared\SanShared.csproj">
<Project>{C949087E-20E1-4A17-B021-FAEAD363C1D8}</Project>
<Name>SanShared</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

60
BerichtGen/Options.Designer.cs generated Normal file
View File

@@ -0,0 +1,60 @@
namespace BerichtGen
{
partial class Options
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

53
BerichtGen/Options.cs Normal file
View File

@@ -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<BilderObject> bilderObjects;
public Options(string firma, string vorlage, string speicherpfad, Hashtable grunddaten, List<BilderObject> 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();
}
}
}

120
BerichtGen/Options.resx Normal file
View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

15
SanShared/BilderObject.cs Normal file
View File

@@ -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; }
}
}

View File

@@ -40,6 +40,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BilderObject.cs" />
<Compile Include="Exceptions\LangNotFoundException.cs" />
<Compile Include="ILanguage.cs" />
<Compile Include="ITemperature.cs" />

View File

@@ -127,7 +127,7 @@
<EmbeddedResource Include="UCSchachtanbindung.resx">
<DependentUpon>UCSchachtanbindung.cs</DependentUpon>
</EmbeddedResource>
<None Include="documents\JUME\klp_vorlage.docx">
<None Include="documents\JUME\liner_einbau.docx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
@@ -146,6 +146,10 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BerichtGen\BerichtGen.csproj">
<Project>{3022da07-fd06-4aea-9fc8-00d318e95a82}</Project>
<Name>BerichtGen</Name>
</ProjectReference>
<ProjectReference Include="..\Database\Database.csproj">
<Project>{b0227727-6cf9-4e2e-9afe-5dd76deaa9db}</Project>
<Name>Database</Name>

View File

@@ -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;
}
}

View File

@@ -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<BilderObject> bilderO = new List<BilderObject>();
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();
}
}
}