using System; using System.Drawing; using System.Collections; using System.ComponentModel; using DevExpress.XtraReports.UI; using DevExpress.XtraPrinting.Drawing; namespace Neo.LegitimateLicences.Reports.NPTR_Reports { public partial class NPTR_LetterToPlanningAuthourityReport : DevExpress.XtraReports.UI.XtraReport { public NPTR_LetterToPlanningAuthourityReport() { InitializeComponent(); // Add BeforePrint event handler for dynamic image selection this.xrPictureBox1.BeforePrint += XrPictureBox1_BeforePrint; } private void XrPictureBox1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { try { // Get the LocationProvince value from the current data row var locationProvince = GetCurrentColumnValue("LocationProvince")?.ToString(); if (!string.IsNullOrEmpty(locationProvince)) { // Convert province name to the format used in resources (uppercase with underscores) var provinceKey = locationProvince.ToUpper().Replace(" ", "_").Replace("-", ""); // Try to get the province-specific image resource var resourceKey = $"xrPictureBox1.ImageSource_{provinceKey}"; var imageSource = GetResourceString(resourceKey); if (!string.IsNullOrEmpty(imageSource)) { // Set the image source dynamically this.xrPictureBox1.ImageSource = new ImageSource("img", imageSource); } else { // Fallback to default image if province-specific image not found this.xrPictureBox1.ImageSource = new ImageSource("img", GetResourceString("xrPictureBox1.ImageSource")); } } else { // Fallback to default image if LocationProvince is null or empty this.xrPictureBox1.ImageSource = new ImageSource("img", GetResourceString("xrPictureBox1.ImageSource")); } } catch (Exception ex) { // In case of any error, fallback to default image this.xrPictureBox1.ImageSource = new ImageSource("img", GetResourceString("xrPictureBox1.ImageSource")); } } private string GetResourceString(string resourceKey) { try { // Use the ComponentResourceManager to access resources var resourceManager = new ComponentResourceManager(typeof(NPTR_LetterToPlanningAuthourityReport)); return resourceManager.GetString(resourceKey); } catch { return null; } } } }