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_LetterToTourimAuthourityReport : DevExpress.XtraReports.UI.XtraReport { public NPTR_LetterToTourimAuthourityReport() { InitializeComponent(); // Match dynamic header image behavior with Planning report this.xrPictureBox1.BeforePrint += XrPictureBox1_BeforePrint; } private void XrPictureBox1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { try { var locationProvince = GetCurrentColumnValue("LocationProvince")?.ToString(); if (!string.IsNullOrEmpty(locationProvince)) { var provinceKey = locationProvince.ToUpper().Replace(" ", "_").Replace("-", ""); var resourceKey = $"xrPictureBox1.ImageSource_{provinceKey}"; var imageSource = GetResourceString(resourceKey) ?? GetPlanningResourceString(resourceKey); if (!string.IsNullOrEmpty(imageSource)) { this.xrPictureBox1.ImageSource = new ImageSource("img", imageSource); } else { var fallback = GetResourceString("xrPictureBox1.ImageSource") ?? GetPlanningResourceString("xrPictureBox1.ImageSource"); if (!string.IsNullOrEmpty(fallback)) { this.xrPictureBox1.ImageSource = new ImageSource("img", fallback); } } } } catch { var fallback = GetResourceString("xrPictureBox1.ImageSource") ?? GetPlanningResourceString("xrPictureBox1.ImageSource"); if (!string.IsNullOrEmpty(fallback)) { this.xrPictureBox1.ImageSource = new ImageSource("img", fallback); } } } private string GetResourceString(string resourceKey) { try { var resourceManager = new ComponentResourceManager(typeof(NPTR_LetterToTourimAuthourityReport)); return resourceManager.GetString(resourceKey); } catch { return null; } } private string GetPlanningResourceString(string resourceKey) { try { var resourceManager = new ComponentResourceManager(typeof(NPTR_LetterToPlanningAuthourityReport)); return resourceManager.GetString(resourceKey); } catch { return null; } } } }