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:
@@ -654,30 +654,22 @@ Shown="OnPopupShownAsync">
|
|||||||
var imageBytes = Convert.FromBase64String(signatureDataUrl[(signatureDataUrl.IndexOf(',') + 1)..]);
|
var imageBytes = Convert.FromBase64String(signatureDataUrl[(signatureDataUrl.IndexOf(',') + 1)..]);
|
||||||
using var imageStream = new MemoryStream(imageBytes);
|
using var imageStream = new MemoryStream(imageBytes);
|
||||||
var imageSource = new ImageSource(DXImage.FromStream(imageStream));
|
var imageSource = new ImageSource(DXImage.FromStream(imageStream));
|
||||||
var bottomMargin = report.Bands.OfType<BottomMarginBand>().FirstOrDefault();
|
|
||||||
|
|
||||||
if (bottomMargin is null) {
|
var detail = report.Bands.OfType<DevExpress.XtraReports.UI.DetailBand>().FirstOrDefault();
|
||||||
bottomMargin = new BottomMarginBand();
|
if (detail is null) return;
|
||||||
report.Bands.Add(bottomMargin);
|
|
||||||
}
|
|
||||||
|
|
||||||
var annotId = annotation?.Id.ToString() ?? "0";
|
var annotId = annotation?.Id.ToString() ?? "0";
|
||||||
RemoveExistingSignatureById(bottomMargin, annotId);
|
RemoveExistingSignatureById(detail, annotId);
|
||||||
|
|
||||||
const float sigWidth = 230F;
|
const float sigWidth = 230F;
|
||||||
const float sigImgHeight = 70F;
|
const float sigImgHeight = 70F;
|
||||||
const float infoHeight = 48.75F;
|
const float infoHeight = 48.75F;
|
||||||
const float innerGap = 5F;
|
const float innerGap = 5F;
|
||||||
const float bottomPad = 6F;
|
|
||||||
const float defaultTopPad = 8F;
|
|
||||||
const float maxBandHeight = 210F;
|
|
||||||
|
|
||||||
float sigX = (float)(annotation?.X ?? 390.0);
|
float sigX = (float)(annotation?.X ?? 390.0);
|
||||||
float requiredHeight = defaultTopPad + sigImgHeight + innerGap + infoHeight + bottomPad;
|
float imageY = (float)(annotation?.Y ?? 900.0);
|
||||||
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 labelY = imageY + sigImgHeight + innerGap;
|
float labelY = imageY + sigImgHeight + innerGap;
|
||||||
|
int targetPage = annotation?.Page ?? 1;
|
||||||
|
|
||||||
var signatureInformation = string.IsNullOrWhiteSpace(signerPosition)
|
var signatureInformation = string.IsNullOrWhiteSpace(signerPosition)
|
||||||
? $"{signerFullName}\n{signaturePlace}, {DateTime.Now:d}"
|
? $"{signerFullName}\n{signaturePlace}, {DateTime.Now:d}"
|
||||||
@@ -690,30 +682,41 @@ Shown="OnPopupShownAsync">
|
|||||||
Sizing = ImageSizeMode.ZoomImage,
|
Sizing = ImageSizeMode.ZoomImage,
|
||||||
Borders = BorderSide.Bottom,
|
Borders = BorderSide.Bottom,
|
||||||
BorderColor = System.Drawing.Color.FromArgb(73, 80, 87),
|
BorderColor = System.Drawing.Color.FromArgb(73, 80, 87),
|
||||||
BackColor = Color.FromArgb(219, 219, 219),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var signatureLabel = new XRLabel {
|
var signatureLabel = new XRLabel {
|
||||||
Name = $"receiverSignatureLabel_{annotId}",
|
Name = $"receiverSignatureLabel_{annotId}",
|
||||||
Text = signatureInformation,
|
Text = signatureInformation,
|
||||||
Multiline = true,
|
Multiline = true,
|
||||||
BoundsF = new RectangleF(sigX, labelY - 5, sigWidth, infoHeight),
|
BoundsF = new RectangleF(sigX, labelY, sigWidth, infoHeight),
|
||||||
Font = new DXFont("Open Sans", 8F, DXFontStyle.Regular),
|
Font = new DXFont("Open Sans", 8F, DXFontStyle.Regular),
|
||||||
ForeColor = System.Drawing.Color.FromArgb(73, 80, 87),
|
ForeColor = System.Drawing.Color.FromArgb(73, 80, 87),
|
||||||
TextAlignment = TextAlignment.TopCenter,
|
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) {
|
static void RemoveExistingSignatureById(DevExpress.XtraReports.UI.DetailBand detail, string annotId) {
|
||||||
var controls = bottomMargin.Controls
|
var controls = detail.Controls
|
||||||
.Cast<XRControl>()
|
.Cast<XRControl>()
|
||||||
.Where(c => c.Name == $"receiverSignatureImage_{annotId}" || c.Name == $"receiverSignatureLabel_{annotId}")
|
.Where(c => c.Name == $"receiverSignatureImage_{annotId}" || c.Name == $"receiverSignatureLabel_{annotId}")
|
||||||
.ToArray();
|
.ToArray();
|
||||||
foreach (var c in controls)
|
foreach (var c in controls)
|
||||||
bottomMargin.Controls.Remove(c);
|
detail.Controls.Remove(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
|
|||||||
Reference in New Issue
Block a user