using System.Collections.Generic; using Microsoft.Extensions.Localization; using Sozsoft.Platform; using Sozsoft.Platform.Entities; using Sozsoft.Platform.Enums; using Sozsoft.Platform.ListForms; using Sozsoft.Platform.Localization; 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); /// phoneCountry biçimli telefon kolonunda satırın ülke değerini taşıyan kolon. public string PhoneCountryBindingName { get; init; } /// Biçim ifadesine verilecek ülke operandı; telefon kolonu değilse null. public string PhoneCountryExpression => string.IsNullOrWhiteSpace(PhoneCountryBindingName) ? null : $"[{PhoneCountryBindingName}]"; public bool HasBindingName => !string.IsNullOrWhiteSpace(BindingName) && BindingName != "undefined"; } internal static class DynamicReportColumnFactory { public static DynamicReportColumn Create( ListFormField field, IReadOnlyDictionary selectFieldsByName, DefaultValueHelper defaultValueHelper, string editorType, IStringLocalizer localizer) { var column = CreateColumn(field, selectFieldsByName[field.FieldName], defaultValueHelper, editorType, localizer); var phoneCountryField = DynamicReportImageHelper.GetPhoneCountryFieldName(field); return phoneCountryField != null && selectFieldsByName.TryGetValue(phoneCountryField, out var countrySelectField) ? column with { PhoneCountryBindingName = DynamicReportImageHelper.GetReportFieldName(countrySelectField) } : column; } private static DynamicReportColumn CreateColumn( 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?.IsJoined == true) { 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"; } }