Skip to content

Commit

Permalink
Added table columns
Browse files Browse the repository at this point in the history
Added additional checks
Added left margin
  • Loading branch information
Wulfheart committed Jan 4, 2021
1 parent 54ae428 commit 6f5f9ce
Show file tree
Hide file tree
Showing 29 changed files with 386 additions and 26 deletions.
Binary file added DesktopIcon.ico
Binary file not shown.
Binary file added DesktopIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TestRun/Mitarbeiter - Kopie.xlsx
Binary file not shown.
Binary file modified TestRun/Mitarbeiter.xlsx
Binary file not shown.
Binary file removed TestRun/Reihentestung_generiert_2021_01_03_14_44.pdf
Binary file not shown.
Binary file not shown.
Binary file removed TestRun/Reihentestung_generiert_2021_01_03_14_49.pdf
Binary file not shown.
Binary file removed TestRun/Reihentestung_generiert_2021_01_03_14_52.pdf
Binary file not shown.
Binary file removed TestRun/Reihentestung_generiert_2021_01_03_14_54.pdf
Binary file not shown.
Binary file not shown.
Binary file removed TestRun/Reihentestung_generiert_2021_01_03_14_57.pdf
Binary file not shown.
Binary file removed TestRun/Reihentestung_generiert_2021_01_03_15_00.pdf
Binary file not shown.
Binary file removed TestRun/Reihentestung_generiert_2021_01_03_15_10.pdf
Binary file not shown.
Binary file removed TestRun/Reihentestung_generiert_2021_01_03_15_14.pdf
Binary file not shown.
Binary file removed TestRun/Reihentestung_generiert_2021_01_03_15_15.pdf
Binary file not shown.
Binary file removed TestRun/Reihentestung_generiert_2021_01_03_15_16.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions UserInterfaceDesktop/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
Binary file added UserInterfaceDesktop/DesktopIcon.ico
Binary file not shown.
10 changes: 2 additions & 8 deletions UserInterfaceDesktop/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task GetID()
form.Add(new StringContent(Testee.Birthday.Day.ToString()), "birstday1");
form.Add(new StringContent(Testee.Birthday.Month.ToString()), "birstday2");
form.Add(new StringContent(Testee.Birthday.Year.ToString()), "birstday3");
form.Add(new StringContent(Testee.Gender == GenderEnum.MALE ? "M" : "W"), "geschlecht");
form.Add(new StringContent(Testee.Gender), "geschlecht");
form.Add(new StringContent(Testee.Forename), "vorname");
form.Add(new StringContent(Testee.Surname), "nachname");
form.Add(new StringContent(Testee.Email), "email1");
Expand All @@ -60,13 +60,7 @@ public async Task GetID()

public void CreatePdf(PdfDocument pdfDocument, Document document, bool isLast)
{
//string[] paths = { outputFolder, String.Format("{0}_{1}_{2}_{3}.pdf", Testee.Surname, Testee.Forename, RunNumber, ID),};
//string fullPath = Path.Combine(paths);
//PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new FileStream(fullPath, FileMode.Create, FileAccess.Write)));
//Document document = new Document(pdfDocument);

//String line = "Hello! Welcome to iTextPdf";
//document.Add(new Paragraph(line));
document.SetLeftMargin(100);
Barcode128 b = new Barcode128(pdfDocument);
b.SetCodeType(Barcode128.CODE128);
b.SetCode(ID);
Expand Down
63 changes: 56 additions & 7 deletions UserInterfaceDesktop/ExcelParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,80 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace UserInterfaceDesktop
{
public class ExcelParser
{
public static string[] AllowedCountries = { "DE", "AF", "EG", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "GQ", "AR", "AM", "AW", "AZ", "ET", "AU", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "CL", "CN", "CK", "CR", "CW", "DK", "CD", "DE", "DM", "DO", "DJ", "EC", "SV", "CI", "ER", "EE", "SZ", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "GH", "GI", "GD", "GR", "GL", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "HN", "HK", "IN", "ID", "IM", "IQ", "IR", "IE", "IS", "IL", "IT", "JM", "JP", "YE", "JE", "JO", "VG", "VI", "KY", "KH", "CM", "CA", "CV", "KZ", "QA", "KE", "KG", "KI", "CC", "CO", "KM", "XK", "HR", "CU", "KW", "LA", "LS", "LV", "LB", "LR", "LY", "LI", "LT", "LU", "MO", "MG", "MW", "MY", "MV", "ML", "MT", "MA", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MZ", "MM", "NA", "NR", "NP", "NC", "NZ", "NI", "NL", "NE", "NG", "NU", "KP", "MP", "MK", "NF", "NO", "OM", "AT", "TL", "PK", "PS", "PW", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "CG", "RE", "RW", "RO", "RU", "MF", "SB", "ZM", "WS", "SM", "BL", "ST", "SA", "SE", "CH", "SN", "RS", "SC", "SL", "ZW", "SG", "SX", "SK", "SI", "SO", "ES", "LK", "SH", "KN", "LC", "PM", "VC", "ZA", "SD", "GS", "KR", "SS", "SR", "SJ", "SY", "TJ", "TW", "TZ", "TH", "TG", "TK", "TO", "TT", "TD", "CZ", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "HU", "UY", "UZ", "VU", "VA", "VE", "AE", "US", "GB", "VN", "WF", "CX", "EH", "CF", "CY", };

public static string[] AllowedGenders = { "M", "W" };

public static List<Testee> Parse(string path)
{
var fi = new FileInfo(path);
var p = new ExcelPackage(fi);
var ws = p.Workbook.Worksheets["Personen"];
List<Testee> persons = new List<Testee>();
for(int i = ws.Dimension.Start.Row + 1; i <= ws.Dimension.End.Row; i++)
for (int i = ws.Dimension.Start.Row + 1; i <= ws.Dimension.End.Row; i++)
{
string gender = ws.Cells[i, 3].Text;
if (!Array.Exists(AllowedGenders, e => String.Equals(gender, e, StringComparison.OrdinalIgnoreCase)))
{
throw new Exception($"Fehler in Zeile {i}: Das Geschlecht wurde nicht erkannt. Es wird nur M und W unterstützt.");
}
string country = ws.Cells[i, 10].Text;
if (!Array.Exists(AllowedCountries, e => String.Equals(country, e, StringComparison.OrdinalIgnoreCase)))
{
throw new Exception($"Fehler in Zeile {i}: Das Herkunftsland wurde nicht erkannt. Bitte benutze eines der folgenden Kürzel: {String.Join(", ", AllowedCountries)}");
}
string gsa = ws.Cells[i, 11].Text;
if (!Array.Exists(new string[] { "0", "1" }, e => String.Equals(gsa, e, StringComparison.OrdinalIgnoreCase)))
{
throw new Exception($"Fehler in Zeile {i}: Die Übermittelung an das Gesundheitsamt muss entweder 0 oder 1 sein.");
}
string first = ws.Cells[i, 12].Text;
if (!Array.Exists(new string[] { "0", "1" }, e => String.Equals(first, e, StringComparison.OrdinalIgnoreCase)))
{
throw new Exception($"Fehler in Zeile {i}: Die Angabe ob Ersttestung muss entweder 0 oder 1 sein.");
}
string symptoms = ws.Cells[i, 13].Text;
if (!Array.Exists(new string[] { "0", "1" }, e => String.Equals(symptoms, e, StringComparison.OrdinalIgnoreCase)))
{
throw new Exception($"Fehler in Zeile {i}: Die Angabe ob Symptome muss entweder 0 oder 1 sein.");
}
string surname = ws.Cells[i, 1].Text;
if (String.IsNullOrWhiteSpace(surname))
{
throw new Exception($"Fehler in Zeile {i}: Nachname nicht gesetzt");
}
string forename = ws.Cells[i, 2].Text;
if (String.IsNullOrWhiteSpace(forename))
{
throw new Exception($"Fehler in Zeile {i}: Vorname nicht gesetzt");
}
DateTime birthday = DateTime.Parse(ws.Cells[i, 4].Text);
if (birthday > DateTime.Now || birthday < DateTime.Now.AddYears(-150))
{
throw new Exception($"Fehler in Zeile {i}: Bitte überprüfe den Geburtstag");
}
persons.Add(new Testee
{
Surname = ws.Cells[i, 1].Text,
Forename = ws.Cells[i, 2].Text,
Gender = ws.Cells[i, 3].Text == "M" ? GenderEnum.MALE : GenderEnum.FEMALE,
Birthday = DateTime.Parse(ws.Cells[i, 4].Text),
Surname = surname,
Forename = forename,
Gender = gender,
Birthday = DateTime.Parse(ws.Cells[i, 4].Text ?? throw new Exception($"Fehler in Zeile {i}: Geburtstag nicht gesetzt")),
Address = ws.Cells[i, 5].Text,
ZIPCode = ws.Cells[i, 6].Text,
City = ws.Cells[i, 7].Text,
Email = ws.Cells[i, 8].Text,
Phone = ws.Cells[i, 9].Text,
Email = ws.Cells[i, 8].Text ?? throw new Exception($"Fehler in Zeile {i}: Email nicht gesetzt"),
Phone = ws.Cells[i, 9].Text ?? throw new Exception($"Fehler in Zeile {i}: Telefonnummer nicht gesetzt"),
Country = country,
GSA = gsa,
Symptoms = symptoms,
FirstTest = first,
Line = i,
});
}
Expand Down
8 changes: 7 additions & 1 deletion UserInterfaceDesktop/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace UserInterfaceDesktop
/// </summary>
public partial class MainWindow : Window
{
protected string output {get; set;}
public MainWindow()
{
InitializeComponent();
Expand Down Expand Up @@ -87,6 +88,7 @@ private async void Generate_Button_Click(object sender, RoutedEventArgs e)
{
// Save document
string outPutPath = dlg.FileName;
output = outPutPath;
AddToLog($"Einlesen der Exceldatei von {excelPath}");
List<Testee> persons = ExcelParser.Parse(excelPath);
AddToLog("Exceldatei erfolgreich eingelesen");
Expand Down Expand Up @@ -126,7 +128,11 @@ private async void Generate_Button_Click(object sender, RoutedEventArgs e)
}
catch (Exception ex)
{

Progress.Value = 0;
Progress.IsIndeterminate = false;
AddToLog(ex.Message);
AddToLog($"Löschen der beschädigten PDF-Datei unter {output}");
File.Delete(output);
MessageBox.Show(ex.Message + "\r");
}
}
Expand Down
Loading

0 comments on commit 6f5f9ce

Please sign in to comment.