Compare commits
7
Commits
89a9a919e3
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a77967d57 | ||
|
|
094fa9e0f4 | ||
|
|
5909d57f47 | ||
|
|
e502aac843 | ||
|
|
5c391a3cc9 | ||
|
|
0bf93cf240 | ||
|
|
de97421914 |
@@ -122,6 +122,11 @@ public static class SchemaMigration
|
||||
{
|
||||
obj["expNat"] = JToken.FromObject(new PdfExportSettings().expNat);
|
||||
}
|
||||
|
||||
if (!obj.ContainsKey("rsGrupTol"))
|
||||
{
|
||||
obj["rsGrupTol"] = JToken.FromObject(new PdfExportSettings().rsGrupTol);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@@ -131,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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -433,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*">
|
||||
|
||||
@@ -1011,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)
|
||||
{
|
||||
@@ -1051,6 +1052,7 @@ public partial class MainWindow : Window
|
||||
rsNumGrouped = ReadInt(NudExpRnsPlzcount, 25),
|
||||
expNat = CbExpNat.IsChecked.Value,
|
||||
expInt = CbExpInt.IsChecked.Value,
|
||||
rsGrupTol = ReadInt(NudExpRnsGrupTol, 0),
|
||||
|
||||
rsPvSt = CbExpRnsPvSt.IsChecked.Value,
|
||||
exportRunningSheets = CbExpRnsEnable.IsChecked.Value
|
||||
|
||||
+175
-10
@@ -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)
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user