13 Commits
7 changed files with 248 additions and 33 deletions
+1
View File
@@ -42,6 +42,7 @@ public class KasAddressList //Address-Set
if(customer.patch != null && expAsAdpac)
{
string header = customer.patch.GetCSVHeader(sep);
result += header + "\n";
} else
{
result = $"refsid{sep} anrede{sep} titel{sep} vorname{sep} adel{sep} name{sep} namezus{sep} anredzus{sep} strasse{sep} strasse2{sep} plz{sep} ort{sep} land{sep} pplz{sep} postfach{sep} name1{sep} name2{sep} name3{sep} name4{sep} name5{sep} funktion{sep} funktion2{sep} abteilung{sep} funktionad{sep} lastupdate\n";
+15
View File
@@ -112,6 +112,21 @@ public static class SchemaMigration
{
obj["expLabEnable"] = JToken.FromObject(new PdfExportSettings().expLabEnable);
}
if (!obj.ContainsKey("expInt"))
{
obj["expInt"] = JToken.FromObject(new PdfExportSettings().expInt);
}
if (!obj.ContainsKey("expNat"))
{
obj["expNat"] = JToken.FromObject(new PdfExportSettings().expNat);
}
if (!obj.ContainsKey("rsGrupTol"))
{
obj["rsGrupTol"] = JToken.FromObject(new PdfExportSettings().rsGrupTol);
}
return obj;
}
+4
View File
@@ -118,6 +118,9 @@ public class PdfExportSettings
public int rsNumGrouped { get; set; } = 25;
public bool rsPvSt { get; set; } = true;
public bool expInt { get; set; } = true;
public bool expNat { get; set; } = true;
public string rsKNrAbs { get; set; } = "";
public string rsKNrEmp { get; set; } = "";
public string rsZKZ { get; set; } = "";
@@ -128,6 +131,7 @@ public class PdfExportSettings
public string rsBundGew { get; set; } = "";
public int rsPalNr { get; set; } = 1;
public int rsBundNrPal { get; set; } = 20;
public int rsGrupTol { get; set; } = 0;
}
+23 -4
View File
@@ -331,7 +331,23 @@
<Grid Grid.Row="2" Margin="20" ColumnDefinitions="*,5*,*" IsVisible="False" x:Name="GrdExportMarginOptions">
<ScrollViewer Grid.Column="1">
<StackPanel Margin="5,5,5,5" Orientation="Vertical" Spacing="20" Background="AliceBlue" >
<CheckBox Content="Versandetiketten erstellen" x:Name="CbExpLabEnable" Margin="10,10,10,0"></CheckBox>
<Grid ColumnDefinitions="*,*,*" ColumnSpacing="20" Margin="10,10,10,0">
<StackPanel Orientation="Vertical" Spacing="10">
<Label Content="Was soll exportiert werden?" FontWeight="Bold"></Label>
<CheckBox Content="National exportieren" IsChecked="True" x:Name="CbExpNat"></CheckBox>
<CheckBox Content="International exportieren" IsChecked="True" x:Name="CbExpInt"></CheckBox>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical" Spacing="10">
<Label Content="Versandetiketten-Export" FontWeight="Bold"></Label>
<CheckBox Content="Versandetiketten erstellen" x:Name="CbExpLabEnable"></CheckBox>
<CheckBox Content="PvSt" IsChecked="True" x:Name="CbExpRnsPvSt"></CheckBox>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Vertical" Spacing="10">
<Label Content="Leitzettel-Export" FontWeight="Bold"></Label>
<CheckBox Content="Bundleitzettel erstellen" x:Name="CbExpRnsEnable"></CheckBox>
</StackPanel>
</Grid>
<Grid Height="1" MaxHeight="1" MinHeight="1" Background="DarkGray" Margin="10,10,10,0"></Grid>
<Grid ColumnDefinitions="*,*,*" ColumnSpacing="20" Margin="10,10,10,0">
<StackPanel Orientation="Vertical" Spacing="10">
<Grid ColumnDefinitions="*,*">
@@ -350,9 +366,8 @@
<Label Grid.Column="0" Content="Zellenrand rechts (mm)"></Label>
<NumericUpDown Grid.Column="1" x:Name="NudExpMargCellPaddingRight" Minimum="0" Maximum="20" Value="5"></NumericUpDown>
</Grid>
<CheckBox Content="Bundleitzettel erstellen" x:Name="CbExpRnsEnable"></CheckBox>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical" Spacing="10">
<Grid ColumnDefinitions="*,*">
<Label Content="Zellenabstand oben"></Label>
@@ -393,9 +408,9 @@
<Label Grid.Column="0" Content="Schriftgröße (klein)"></Label>
<NumericUpDown Grid.Column="1" x:Name="NudExpMargSmallFontSize" Minimum="3" Maximum="30" Value="6"></NumericUpDown>
</Grid>
<CheckBox Content="PvSt" IsChecked="True" x:Name="CbExpRnsPvSt"></CheckBox>
</StackPanel>
</Grid>
<Grid Height="1" MaxHeight="1" MinHeight="1" Background="DarkGray" Margin="10,10,10,0"></Grid>
<Grid ColumnDefinitions="*,*" ColumnSpacing="20" Margin="10,10,10,0">
<StackPanel Grid.Column="0" Orientation="Vertical" Spacing="10">
<Grid ColumnDefinitions="*,2*">
@@ -418,6 +433,10 @@
<Label Grid.Column="0" Content="Laufzeit" />
<TextBox Grid.Column="1" x:Name="TbExpRnsLaufz" />
</Grid>
<Grid ColumnDefinitions="*,2*">
<Label Grid.Column="0" Content="Gruppiertoleranz (Ende)" />
<NumericUpDown Grid.Column="1" Minimum="0" Value="0" x:Name="NudExpRnsGrupTol" />
</Grid>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical" Spacing="10">
<Grid ColumnDefinitions="*,2*">
+27 -16
View File
@@ -997,6 +997,9 @@ public partial class MainWindow : Window
NudExpMargSmallFontSize.Value = (decimal)options.smallFontSize;
CbExpRnsPvSt.IsChecked = options.rsPvSt;
CbExpRnsEnable.IsChecked = options.exportRunningSheets;
CbExpNat.IsChecked = options.expNat;
CbExpInt.IsChecked = options.expInt;
TbExpRnsKNrAbs.Text = options.rsKNrAbs;
TbExpRnsKNrEmp.Text = options.rsKNrEmp;
@@ -1008,6 +1011,7 @@ public partial class MainWindow : Window
TbExpRnsBundGew.Text = options.rsBundGew;
NudExpRnsPalNr.Value = options.rsPalNr;
NudExpRnsBundNrPal.Value = options.rsBundNrPal;
NudExpRnsGrupTol.Value = options.rsGrupTol;
}
catch (Exception ex)
{
@@ -1046,6 +1050,9 @@ public partial class MainWindow : Window
rsPalNr = ReadInt(NudExpRnsPalNr, 1),
rsBundNrPal = ReadInt(NudExpRnsBundNrPal, 20),
rsNumGrouped = ReadInt(NudExpRnsPlzcount, 25),
expNat = CbExpNat.IsChecked.Value,
expInt = CbExpInt.IsChecked.Value,
rsGrupTol = ReadInt(NudExpRnsGrupTol, 0),
rsPvSt = CbExpRnsPvSt.IsChecked.Value,
exportRunningSheets = CbExpRnsEnable.IsChecked.Value
@@ -1482,7 +1489,7 @@ public partial class MainWindow : Window
private async void MnIAdSetExp_OnClick(object? sender, RoutedEventArgs e)
{
var topLevel = TopLevel.GetTopLevel(this);
Logger.Log("Exporting as CSV without address patch...");
var folders = await topLevel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
{
Title = "Select a Folder",
@@ -1492,15 +1499,17 @@ public partial class MainWindow : Window
if (folders.Count > 0)
{
var folderPath = folders[0].Path.LocalPath;
Logger.Log($"using ${folderPath} as export destination");
if (LstCustomerAdressSets.SelectedItems.Count > 0)
{
foreach (var set in LstCustomerAdressSets.SelectedItems)
{
string output = await ((KasAddressList)set).GenerateCSV(false);
File.WriteAllText(Path.Combine(folderPath,((KasAddressList)set).Name + ".csv"), output);
}
}
foreach (var set in LstCustomerAdressSets.SelectedItems)
{
string output = await ((KasAddressList)set).GenerateCSV(false);
File.WriteAllText(Path.Combine(folderPath,((KasAddressList)set).Name + ".csv"), output);
Logger.Log($"exported ${((KasAddressList)set).Name} successfully!");
}
}
}
@@ -1509,7 +1518,7 @@ public partial class MainWindow : Window
private async void MnIAdSetExpAdpac_OnClick(object? sender, RoutedEventArgs e)
{
var topLevel = TopLevel.GetTopLevel(this);
Logger.Log("Exporting as CSV with address patch...");
var folders = await topLevel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
{
Title = "Select a Folder",
@@ -1519,15 +1528,17 @@ public partial class MainWindow : Window
if (folders.Count > 0)
{
var folderPath = folders[0].Path.LocalPath;
Logger.Log($"using ${folderPath} as export destination");
if (LstCustomerAdressSets.SelectedItems.Count > 0)
{
foreach (var set in LstCustomerAdressSets.SelectedItems)
{
string output = await ((KasAddressList)set).GenerateCSV(true);
File.WriteAllText(Path.Combine(folderPath,((KasAddressList)set).Name + ".csv"), output);
}
}
foreach (var set in LstCustomerAdressSets.SelectedItems)
{
string output = await ((KasAddressList)set).GenerateCSV(true);
File.WriteAllText(Path.Combine(folderPath,((KasAddressList)set).Name + ".csv"), output);
Logger.Log($"exported ${((KasAddressList)set).Name} successfully!");
}
}
}
+1 -1
View File
@@ -212,7 +212,7 @@ public class AddressPatch
if(has_funktionad){
output += funktionad_is + sep + " ";
}
Logger.Log($"Generated CSV header ist ${output}");
return output;
}
}
+177 -12
View File
@@ -11,6 +11,8 @@ namespace Logof_Client;
public class PdfBuilder
{
private const char RecipientTextMarker = '\u001f';
private readonly PdfExportSettings _settings;
private readonly XFont _boldFont;
private readonly XFont _regularFont;
@@ -140,9 +142,9 @@ public class PdfBuilder
else
senderLineID += "\n</font6>";
if (!string.IsNullOrEmpty(senderLineID))
addresses_german.Add(senderLineID + (addr ?? ""));
addresses_german.Add(senderLineID + RecipientTextMarker + (addr ?? ""));
else
addresses_german.Add(addr);
addresses_german.Add(RecipientTextMarker + (addr ?? ""));
}
// international addresses
@@ -163,9 +165,9 @@ public class PdfBuilder
else
senderLineID += "\n</font6>";
if (!string.IsNullOrEmpty(senderLineID))
addresses_inter.Add(senderLineID + (addr ?? ""));
addresses_inter.Add(senderLineID + RecipientTextMarker + (addr ?? ""));
else
addresses_inter.Add(addr);
addresses_inter.Add(RecipientTextMarker + (addr ?? ""));
}
if (addresses_german.Count == 0 && addresses_inter.Count == 0)
@@ -181,8 +183,8 @@ public class PdfBuilder
Logger.Log("Skipping label pdf generation cause it was disabled by user");
} else
{
if(addresses_german.Count > 0) CreateAddressLabelPdfWithPlaceholder(addresses_german, placeholderText, outputPath, pvst);
if(addresses_inter.Count > 0) CreateAddressLabelPdfWithPlaceholder(addresses_inter, placeholderText, output_inter, pvst);
if(addresses_german.Count > 0 && Settings._instance.pdfExport.expNat) CreateAddressLabelPdfWithPlaceholder(addresses_german, placeholderText, outputPath, pvst);
if(addresses_inter.Count > 0 && Settings._instance.pdfExport.expInt) CreateAddressLabelPdfWithPlaceholder(addresses_inter, placeholderText, output_inter, pvst);
}
@@ -359,12 +361,14 @@ public class PdfBuilder
public string Text { get; }
public TextStyle Style { get; }
public bool LineBreak { get; }
public bool WrapAtWords { get; }
public TextToken(string text, TextStyle style, bool lineBreak = false)
public TextToken(string text, TextStyle style, bool lineBreak = false, bool wrapAtWords = false)
{
Text = text;
Style = style;
LineBreak = lineBreak;
WrapAtWords = wrapAtWords;
}
}
@@ -418,19 +422,28 @@ public class PdfBuilder
var i = 0;
var style = TextStyle.Regular;
var wrapAtWords = false;
var buffer = new System.Text.StringBuilder();
void FlushBuffer()
{
if (buffer.Length > 0)
{
tokens.Add(new TextToken(buffer.ToString(), style));
tokens.Add(new TextToken(buffer.ToString(), style, wrapAtWords: wrapAtWords));
buffer.Clear();
}
}
while (i < text.Length)
{
if (text[i] == RecipientTextMarker)
{
FlushBuffer();
wrapAtWords = true;
i++;
continue;
}
if (text[i] == '\r')
{
i++;
@@ -547,6 +560,39 @@ public class PdfBuilder
available = maxWidth;
}
if (token.WrapAtWords)
{
var wordParts = System.Text.RegularExpressions.Regex.Split(remaining, @"(\s+)");
foreach (var wordPart in wordParts)
{
if (wordPart.Length == 0)
continue;
var wordWidth = gfx.MeasureString(wordPart, font).Width;
if (string.IsNullOrWhiteSpace(wordPart))
{
if (currentLine.Count == 0)
continue;
if (currentWidth + wordWidth > maxWidth)
{
PushLine();
continue;
}
}
else if (currentLine.Count > 0 && currentWidth + wordWidth > maxWidth)
{
PushLine();
}
currentLine.Add(new TextRun { Text = wordPart, Font = font });
currentWidth += wordWidth;
}
remaining = "";
continue;
}
var fit = FitTextToWidth(gfx, remaining, font, available);
if (string.IsNullOrEmpty(fit))
{
@@ -703,6 +749,7 @@ public class PdfBuilder
document.Info.Author = "logofclient";
var grouped_nums = GroupAddresses(setID).ToList();
DrawPostalCodeOverview(document, grouped_nums);
// Zwei Tabellen pro A4-Seite
int sheets = (grouped_nums.Count + 1) / 2;
@@ -794,6 +841,106 @@ public class PdfBuilder
document.Save(path);
}
private void DrawPostalCodeOverview(PdfDocument document, List<(int, string, string, string, int)> groupedNumbers)
{
if (groupedNumbers.Count == 0)
return;
var summaries = groupedNumbers
.GroupBy(item => item.Item2)
.OrderBy(group => group.Key, StringComparer.Ordinal)
.Select(group => new
{
Prefix = group.Key,
AddressCount = group.Sum(item => item.Item5),
GroupCount = group.Count(),
StartPostalCode = group.First().Item3,
EndPostalCode = group.Last().Item4
})
.ToList();
const double tableTop = 58;
const double headerHeight = 16;
const double rowHeight = 14;
const double tableGap = 12;
double[] columnWidths = { 40, 50, 36, 55, 55 };
string[] headers = { "PLZ-Gr.", "Anz.", "Anz.Gr.", "Start", "Ende" };
var titleFont = new XFont("Arial", 13, XFontStyleEx.Bold);
var headerFont = new XFont("Arial", 7.5, XFontStyleEx.Bold);
var textFont = new XFont("Arial", 7.5, XFontStyleEx.Regular);
var groupCountFont = new XFont("Arial", 7.5, XFontStyleEx.Bold);
int leftCount = (summaries.Count + 1) / 2;
double tableWidth = columnWidths.Sum();
double allTablesWidth = tableWidth * 2 + tableGap;
var page = document.AddPage();
page.Size = PageSize.A4;
using var gfx = XGraphics.FromPdfPage(page);
gfx.DrawString("Übersicht PLZ-Gruppen", titleFont, XBrushes.Black,
new XRect(28, 16, page.Width.Point - 56, 20), XStringFormats.TopLeft);
var metadataFont = new XFont("Arial", 9, XFontStyleEx.Regular);
double metadataWidth = (page.Width.Point - 56) / 3;
gfx.DrawString($"ZKZ: {_settings.rsZKZ}", metadataFont, XBrushes.Black,
new XRect(28, 38, metadataWidth, 16), XStringFormats.TopLeft);
gfx.DrawString($"Datum: {DateTime.Now:dd.MM.yyyy}", metadataFont, XBrushes.Black,
new XRect(28 + metadataWidth, 38, metadataWidth, 16), XStringFormats.TopLeft);
gfx.DrawString("Projekt: ____________________", metadataFont, XBrushes.Black,
new XRect(28 + 2 * metadataWidth, 38, metadataWidth, 16), XStringFormats.TopLeft);
double firstTableX = (page.Width.Point - allTablesWidth) / 2;
for (int tableIndex = 0; tableIndex < 2; tableIndex++)
{
int startIndex = tableIndex == 0 ? 0 : leftCount;
int itemCount = tableIndex == 0 ? leftCount : summaries.Count - leftCount;
if (itemCount == 0)
continue;
double tableX = firstTableX + tableIndex * (tableWidth + tableGap);
gfx.DrawRectangle(XBrushes.LightGray, tableX, tableTop, tableWidth, headerHeight);
gfx.DrawRectangle(XPens.Black, tableX, tableTop, tableWidth, headerHeight);
double columnX = tableX;
for (int columnIndex = 0; columnIndex < headers.Length; columnIndex++)
{
gfx.DrawString(headers[columnIndex], headerFont, XBrushes.Black,
new XRect(columnX + 2, tableTop, columnWidths[columnIndex] - 4, headerHeight),
XStringFormats.Center);
columnX += columnWidths[columnIndex];
if (columnIndex < headers.Length - 1)
gfx.DrawLine(XPens.Black, columnX, tableTop, columnX, tableTop + headerHeight);
}
for (int rowIndex = 0; rowIndex < itemCount; rowIndex++)
{
var summary = summaries[startIndex + rowIndex];
string[] values =
{
summary.Prefix,
summary.AddressCount.ToString(),
summary.GroupCount.ToString(),
summary.StartPostalCode,
summary.EndPostalCode
};
double rowY = tableTop + headerHeight + rowIndex * rowHeight;
gfx.DrawRectangle(XPens.Black, tableX, rowY, tableWidth, rowHeight);
columnX = tableX;
for (int columnIndex = 0; columnIndex < values.Length; columnIndex++)
{
gfx.DrawString(values[columnIndex], columnIndex == 2 ? groupCountFont : textFont,
XBrushes.Black,
new XRect(columnX + 2, rowY, columnWidths[columnIndex] - 4, rowHeight),
XStringFormats.Center);
columnX += columnWidths[columnIndex];
if (columnIndex < values.Length - 1)
gfx.DrawLine(XPens.Black, columnX, rowY, columnX, rowY + rowHeight);
}
}
}
}
private void DrawGermanyRunningSheet(XGraphics gfx, double x, double y, double w, double h, KasAddressList list, dynamic result, List<(int,string,string,string,int)> grouped_nums, XFont fontLabel, XFont fontText, XFont fontBig, int? pal_nr, int? bundleOnPallet, int totalBundleNumber)
{
double line = 1.0;
@@ -1262,6 +1409,7 @@ public class PdfBuilder
public List<(int, string, string, string, int)> GroupAddresses(int setID)
{
int grpcount = Settings._instance.pdfExport.rsNumGrouped; // Amount of addresses per group
int grptol = Settings._instance.pdfExport.rsGrupTol; // Amount of addresses per group
int stpoint = 2; // group starting point (first n characters of the plz)
KasAddressList list = Settings._instance.addressSets.GetAddressSetByID(setID);
if (list == null)
@@ -1280,12 +1428,20 @@ public class PdfBuilder
{
string start = group.Key;
int fraktion = 0;
int addressCount = group.Count();
int remainder = addressCount % grpcount;
int groupCount = (addressCount - 1) / grpcount + 1;
bool mergeLastGroup = groupCount > 1 && remainder > 0 && remainder <= grptol;
int effectiveGroupCount = groupCount - (mergeLastGroup ? 1 : 0);
for (int count = 0; count < group.Count(); count += grpcount)
for (int groupIndex = 0; groupIndex < effectiveGroupCount; groupIndex++)
{
fraktion++;
int currentGroupSize = Math.Min(grpcount, group.Count() - count);
int count = groupIndex * grpcount;
int currentGroupSize = mergeLastGroup && groupIndex == effectiveGroupCount - 1
? addressCount - count
: Math.Min(grpcount, addressCount - count);
string first = group.ElementAt(count).used_plz;
string last = group.ElementAt(count + currentGroupSize - 1).used_plz;
@@ -1300,6 +1456,7 @@ public class PdfBuilder
public List<(int, string, string, string, int)> GroupAddressesInternational(int setID)
{
int grpcount = Settings._instance.pdfExport.rsNumGrouped; // Amount of addresses per group
int grptol = Settings._instance.pdfExport.rsGrupTol; // Amount of addresses per group
KasAddressList list = Settings._instance.addressSets.GetAddressSetByID(setID);
if (list == null)
throw new Exception("AddressSet nicht gefunden");
@@ -1316,12 +1473,20 @@ public class PdfBuilder
{
string start = group.Key;
int fraktion = 0;
int addressCount = group.Count();
int remainder = addressCount % grpcount;
int groupCount = (addressCount - 1) / grpcount + 1;
bool mergeLastGroup = groupCount > 1 && remainder > 0 && remainder <= grptol;
int effectiveGroupCount = groupCount - (mergeLastGroup ? 1 : 0);
for (int count = 0; count < group.Count(); count += grpcount)
for (int groupIndex = 0; groupIndex < effectiveGroupCount; groupIndex++)
{
fraktion++;
int currentGroupSize = Math.Min(grpcount, group.Count() - count);
int count = groupIndex * grpcount;
int currentGroupSize = mergeLastGroup && groupIndex == effectiveGroupCount - 1
? addressCount - count
: Math.Min(grpcount, addressCount - count);
string first = group.ElementAt(count).used_plz;
string last = group.ElementAt(count + currentGroupSize - 1).used_plz;