using System.Collections.Generic; using Microsoft.Extensions.Localization; using Sozsoft.Platform; using Sozsoft.Platform.Localization; using Sozsoft.Platform.Entities; using Sozsoft.Platform.Enums; using Sozsoft.Platform.ListForms; using Sozsoft.Platform.Queries; namespace Sozsoft.Reports.PredefinedReports; /// /// Grid ve Tree raporlarının ortak kolon tanımı. /// internal sealed record DynamicReportColumn( ListFormField Field, string BindingName, LookupDto Lookup, Dictionary StaticLookupValues, bool IsMultiValue, bool IsImage, bool IsHtml, string EditorType, int ImageCount = 1) : DynamicReportSqlBuilder.IReportLookupColumn, DynamicReportGridStateHelper.IReportColumnWidth { public float ImageWidth => DynamicReportImageHelper.GetGridImageColumnWidth(ImageCount); public bool HasBindingName => !string.IsNullOrWhiteSpace(BindingName) && BindingName != "undefined"; } internal static class DynamicReportColumnFactory { public static DynamicReportColumn Create( ListFormField field, SelectField selectField, DefaultValueHelper defaultValueHelper, string editorType, IStringLocalizer localizer) { var bindingName = DynamicReportImageHelper.GetReportFieldName(selectField); var lookup = DynamicReportImageHelper.GetLookup(field); var isMultiValue = IsMultiValueLookupEditor(editorType); var isImage = DynamicReportImageHelper.IsImageEditor(editorType); var isHtml = editorType == PlatformConsts.EditorTypes.dxHtmlEditor; if (lookup == null || selectField?.JoinOptions != null) { return new DynamicReportColumn(field, bindingName, null, null, isMultiValue, isImage, isHtml, editorType); } if (DynamicReportSqlBuilder.IsReportQueryableLookup(lookup)) { return new DynamicReportColumn( field, DynamicReportSqlBuilder.GetLookupBindingName(field), lookup, null, isMultiValue, isImage, isHtml, editorType); } if (lookup.DataSourceType == UiLookupDataSourceTypeEnum.StaticData) { var staticLookupValues = DynamicReportImageHelper.GetStaticLookupValues( lookup, defaultValueHelper, localizer); return new DynamicReportColumn( field, staticLookupValues?.Count > 0 ? DynamicReportSqlBuilder.GetLookupBindingName(field) : bindingName, lookup, staticLookupValues, isMultiValue, isImage, isHtml, editorType); } return new DynamicReportColumn(field, bindingName, null, null, isMultiValue, isImage, isHtml, editorType); } public static bool IsMultiValueLookupEditor(string editorType) { return editorType is PlatformConsts.EditorTypes.dxTagBox or "dxGridBox"; } }