Move signature annotations to DetailBand

Updated `AddSignatureAtAnnotation` to use `DetailBand` instead of `BottomMarginBand` for managing signature annotations. Adjusted logic to ensure signatures are placed in the detail section and only displayed on the specified page using the `BeforePrint` event. Reformatted constants for readability and updated `RemoveExistingSignatureById` to operate on `DetailBand`. Removed reliance on bottom margin height for positioning and introduced `annotation?.Y` for vertical placement.
This commit is contained in:
2026-06-01 15:37:03 +02:00
parent 0ea7386cb6
commit b4353cd9ff

View File

@@ -654,66 +654,69 @@ Shown="OnPopupShownAsync">
var imageBytes = Convert.FromBase64String(signatureDataUrl[(signatureDataUrl.IndexOf(',') + 1)..]);
using var imageStream = new MemoryStream(imageBytes);
var imageSource = new ImageSource(DXImage.FromStream(imageStream));
var bottomMargin = report.Bands.OfType<BottomMarginBand>().FirstOrDefault();
if (bottomMargin is null) {
bottomMargin = new BottomMarginBand();
report.Bands.Add(bottomMargin);
}
var detail = report.Bands.OfType<DevExpress.XtraReports.UI.DetailBand>().FirstOrDefault();
if (detail is null) return;
var annotId = annotation?.Id.ToString() ?? "0";
RemoveExistingSignatureById(bottomMargin, annotId);
RemoveExistingSignatureById(detail, annotId);
const float sigWidth = 230F;
const float sigImgHeight = 70F;
const float infoHeight = 48.75F;
const float innerGap = 5F;
const float bottomPad = 6F;
const float defaultTopPad = 8F;
const float maxBandHeight = 210F;
const float sigWidth = 230F;
const float sigImgHeight = 70F;
const float infoHeight = 48.75F;
const float innerGap = 5F;
float sigX = (float)(annotation?.X ?? 390.0);
float requiredHeight = defaultTopPad + sigImgHeight + innerGap + infoHeight + bottomPad;
bottomMargin.HeightF = Math.Min(maxBandHeight, Math.Max(bottomMargin.HeightF, requiredHeight));
float topPad = Math.Max(0F, bottomMargin.HeightF - bottomPad - infoHeight - innerGap - sigImgHeight);
float imageY = topPad;
float sigX = (float)(annotation?.X ?? 390.0);
float imageY = (float)(annotation?.Y ?? 900.0);
float labelY = imageY + sigImgHeight + innerGap;
int targetPage = annotation?.Page ?? 1;
var signatureInformation = string.IsNullOrWhiteSpace(signerPosition)
? $"{signerFullName}\n{signaturePlace}, {DateTime.Now:d}"
: $"{signerFullName}\n{signerPosition}\n{signaturePlace}, {DateTime.Now:d}";
var signature = new XRPictureBox {
Name = $"receiverSignatureImage_{annotId}",
Name = $"receiverSignatureImage_{annotId}",
ImageSource = imageSource,
BoundsF = new RectangleF(sigX, imageY, sigWidth, sigImgHeight),
Sizing = ImageSizeMode.ZoomImage,
Borders = BorderSide.Bottom,
BoundsF = new RectangleF(sigX, imageY, sigWidth, sigImgHeight),
Sizing = ImageSizeMode.ZoomImage,
Borders = BorderSide.Bottom,
BorderColor = System.Drawing.Color.FromArgb(73, 80, 87),
BackColor = Color.FromArgb(219, 219, 219),
};
var signatureLabel = new XRLabel {
Name = $"receiverSignatureLabel_{annotId}",
Text = signatureInformation,
Multiline = true,
BoundsF = new RectangleF(sigX, labelY - 5, sigWidth, infoHeight),
Font = new DXFont("Open Sans", 8F, DXFontStyle.Regular),
ForeColor = System.Drawing.Color.FromArgb(73, 80, 87),
Name = $"receiverSignatureLabel_{annotId}",
Text = signatureInformation,
Multiline = true,
BoundsF = new RectangleF(sigX, labelY, sigWidth, infoHeight),
Font = new DXFont("Open Sans", 8F, DXFontStyle.Regular),
ForeColor = System.Drawing.Color.FromArgb(73, 80, 87),
TextAlignment = TextAlignment.TopCenter,
BackColor = Color.FromArgb(219, 219, 219)
};
bottomMargin.Controls.AddRange(new XRControl[] { signature, signatureLabel });
// Show each control only on the target page using an independent print counter
int sigPrintCount = 0;
signature.BeforePrint += (_, e) => {
sigPrintCount++;
e.Cancel = sigPrintCount != targetPage;
};
int lblPrintCount = 0;
signatureLabel.BeforePrint += (_, e) => {
lblPrintCount++;
e.Cancel = lblPrintCount != targetPage;
};
detail.Controls.AddRange(new XRControl[] { signature, signatureLabel });
}
static void RemoveExistingSignatureById(BottomMarginBand bottomMargin, string annotId) {
var controls = bottomMargin.Controls
static void RemoveExistingSignatureById(DevExpress.XtraReports.UI.DetailBand detail, string annotId) {
var controls = detail.Controls
.Cast<XRControl>()
.Where(c => c.Name == $"receiverSignatureImage_{annotId}" || c.Name == $"receiverSignatureLabel_{annotId}")
.ToArray();
foreach (var c in controls)
bottomMargin.Controls.Remove(c);
detail.Controls.Remove(c);
}
public void Dispose() {