From 34829559c4c1eeea2ec1c81884d171bde55c5573 Mon Sep 17 00:00:00 2001 From: primo-ppcg Date: Mon, 13 May 2024 09:55:07 +0700 Subject: [PATCH] Apply RecallFieldNumber to current template (#235) --- .../Test/{Format.zpl2 => Format-54x86.zpl2} | 0 .../Labels/Test/Format2-54x86.zpl2 | 11 ++++++++++ src/BinaryKits.Zpl.Viewer/FormatMerger.cs | 21 ++++++++++++++----- 3 files changed, 27 insertions(+), 5 deletions(-) rename src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/{Format.zpl2 => Format-54x86.zpl2} (100%) create mode 100644 src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/Format2-54x86.zpl2 diff --git a/src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/Format.zpl2 b/src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/Format-54x86.zpl2 similarity index 100% rename from src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/Format.zpl2 rename to src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/Format-54x86.zpl2 diff --git a/src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/Format2-54x86.zpl2 b/src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/Format2-54x86.zpl2 new file mode 100644 index 00000000..05f853fa --- /dev/null +++ b/src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/Format2-54x86.zpl2 @@ -0,0 +1,11 @@ +^XA +^DFFORMAT^FS +^BY2,3.0^FO40,40^BCN,80,Y,,,A^FR^FN1^FS +^BY2,3.0^FO40,160^BCN,80,Y,,,A^FR^FN2^FS +^FN1^FD12345^FS +^XZ + +^XA +^XFFORMAT.ZPL +^FN2^FDABC12345^FS +^XZ \ No newline at end of file diff --git a/src/BinaryKits.Zpl.Viewer/FormatMerger.cs b/src/BinaryKits.Zpl.Viewer/FormatMerger.cs index a667058b..d601217f 100644 --- a/src/BinaryKits.Zpl.Viewer/FormatMerger.cs +++ b/src/BinaryKits.Zpl.Viewer/FormatMerger.cs @@ -43,16 +43,27 @@ private static List GetMergedElements( { var elements = new List(); - foreach (ZplElementBase element in rawLabelInfo.ZplElements) + foreach (ZplElementBase zplElement in rawLabelInfo.ZplElements) { - if (element is ZplRecallFormat recallFormat) + if (zplElement is ZplRecallFormat recallFormat) { LabelInfo formatLabelInfo = GetFormatLabelInfo(recallFormat, templateFormats); elements.AddRange(GetMergedElements(rawLabelInfo, formatLabelInfo)); } - else if (element is not ZplRecallFieldNumber) + else if (zplElement is ZplRecallFieldNumber recallFieldNumber) { - elements.Add(element); + for(int i = 0; i < elements.Count; i++) + { + if (elements[i] is ZplFieldNumber fieldNumber && fieldNumber.Number == recallFieldNumber.Number) + { + ((IFormatElement)fieldNumber.FormatElement).SetTemplateContent(recallFieldNumber.Text); + elements[i] = fieldNumber.FormatElement; + } + } + } + else + { + elements.Add(zplElement); } } @@ -103,4 +114,4 @@ private static IEnumerable GetMergedElements( } } } -} \ No newline at end of file +}