From 2d241ef46a2a6cad21c0f1d097cc842c04b20716 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Sun, 17 Jan 2021 18:07:08 +0300 Subject: [PATCH] RDL - code clean --- DevExpress.XtraReports.Import.csproj | 1 + .../DataSources/DataSourceConverter.cs | 25 ++++++++++--------- .../Expressions/ExpressionParser.cs | 15 ++++++++--- Import/ReportingServices/Messages.cs | 1 + Import/ReportingServicesConverter.cs | 2 +- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/DevExpress.XtraReports.Import.csproj b/DevExpress.XtraReports.Import.csproj index c1ea023..6a5cbd3 100644 --- a/DevExpress.XtraReports.Import.csproj +++ b/DevExpress.XtraReports.Import.csproj @@ -11,6 +11,7 @@ Exe DevExpress.XtraReports.Import v4.5.2 + 6 bin\Debug\ diff --git a/Import/ReportingServices/DataSources/DataSourceConverter.cs b/Import/ReportingServices/DataSources/DataSourceConverter.cs index 7154fcb..47c4c1d 100644 --- a/Import/ReportingServices/DataSources/DataSourceConverter.cs +++ b/Import/ReportingServices/DataSources/DataSourceConverter.cs @@ -116,7 +116,8 @@ public class DataSetConversionState { ProcessDataSetCore(dataSetElement, conversionState, dataSetName); var queryName = conversionState.Query?.Name ?? conversionState.DataSetName; - dataSetToDataSourceMap[dataSetName] = new DataPair(conversionState.DataSource, queryName); + if(conversionState.DataSource != null) + dataSetToDataSourceMap[dataSetName] = new DataPair(conversionState.DataSource, queryName); } void ProcessDataSetCore(XElement dataSetElement, DataSetConversionState conversionState, string componentName) { @@ -141,7 +142,8 @@ public class DataSetConversionState { return; } } - + if(conversionState.DataSource == null) + return; var fieldsElement = dataSetElement.Element(ns + "Fields"); if(fieldsElement != null) ProcessDataSetFields(fieldsElement, conversionState); @@ -260,7 +262,6 @@ public class DataSetConversionState { return; ProcessDataSetParameters(queryElement.Element(ns + "DataSetParameters"), state); ProcessQueryParameters(queryElement.Element(ns + "QueryParameters"), state, componentName); - } void ProcessQueryParameters(XElement queryParameters, DataSetConversionState state, string componentName) { @@ -273,10 +274,13 @@ public class DataSetConversionState { var value = queryParameterElement.Element(ns + "Value").Value; ExpressionParserResult expressionResult; - queryParameter.Value = converter.TryGetExpression(value, $"{componentName}.{queryParameter.Name}", out expressionResult) - ? expressionResult.ToDataAccessExpression() - : (object)value; - queryParameter.Type = queryParameter.Value.GetType(); + if(converter.TryGetExpression(value, $"{componentName}.{queryParameter.Name}", out expressionResult)) { + queryParameter.Value = expressionResult.ToDataAccessExpression(typeof(string)); + queryParameter.Type = typeof(DataAccess.Expression); + } else { + queryParameter.Value = value; + queryParameter.Type = typeof(string); + } } } @@ -315,12 +319,9 @@ public class DataSetConversionState { if(query == null) { var commandTypeEnum = (CommandType)Enum.Parse(typeof(CommandType), commandType); var command = new SqlCommand() { CommandType = commandTypeEnum, CommandText = commandText }; - if (converter.IgnoreQueryValidation && commandTypeEnum == CommandType.Text) - { + if(converter.IgnoreQueryValidation && commandTypeEnum == CommandType.Text) { query = new CustomSqlQuery(state.DataSetName, command.CommandText.Trim()); - } - else - { + } else { query = DataSetToSqlDataSourceConverter.CreateSqlQuery(state.DataSetName, command); } diff --git a/Import/ReportingServices/Expressions/ExpressionParser.cs b/Import/ReportingServices/Expressions/ExpressionParser.cs index 8863ec7..7f0550e 100644 --- a/Import/ReportingServices/Expressions/ExpressionParser.cs +++ b/Import/ReportingServices/Expressions/ExpressionParser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using DevExpress.Data.Filtering; @@ -39,8 +39,8 @@ public class ExpressionParserResult { public BasicExpressionBinding ToBasicExpressionBinding() { return new BasicExpressionBinding("Value", Expression); } - public Expression ToDataAccessExpression() { - return new Expression(Expression); + public Expression ToDataAccessExpression(Type type) { + return new Expression(Expression, type); } } public partial class ExpressionParser { @@ -203,6 +203,15 @@ public partial class ExpressionParser { case "len": Assert(parameters.Count == 1, "Len"); return new FunctionOperator(FunctionOperatorType.Len, parameters[0]); + case "now": + Assert(parameters.Count == 0, "Now"); + return new FunctionOperator(FunctionOperatorType.Now); + case "today": + Assert(parameters.Count == 0, "Today"); + return new FunctionOperator(FunctionOperatorType.Today); + case "minute": + Assert(parameters.Count == 1, "Minute"); + return new FunctionOperator(FunctionOperatorType.GetMinute, parameters[0]); case "isnothing": Assert(parameters.Count == 1, "IsNothing"); return new FunctionOperator(FunctionOperatorType.IsNullOrEmpty, parameters[0]); diff --git a/Import/ReportingServices/Messages.cs b/Import/ReportingServices/Messages.cs index ae560c1..bc989a3 100644 --- a/Import/ReportingServices/Messages.cs +++ b/Import/ReportingServices/Messages.cs @@ -37,6 +37,7 @@ public const string RichTextRunStyle_NotSupported_Format = "RichText Run style '{0}' is not supported.", RichTextParagraphElement_NotSupported_Format = "RichText Paragraph element '{0}' is not supported.", RichTextRunExpression_NotSupported_Format = "Cannot convert the '{0}' RichText with the following Run Expression: '{1}'.", + TextBoxWithMultipleTextRunsToXRLabel_NotSupported = "TextBox '{0}' should contain only one TextRun to be converted to an XRLabel.", LineElement_NotSupported_Format = "Cannot convert the '{0}' Line's '{1}' element.", ImageSourceType_NotSupported_Format = "ImageControl SourceType '{0}' is not supported.", VisibilityProperty_NotSupported_Format = "The '{0}' property visibility is not supported for the '{1}' control.", diff --git a/Import/ReportingServicesConverter.cs b/Import/ReportingServicesConverter.cs index 1381c70..bd0970a 100644 --- a/Import/ReportingServicesConverter.cs +++ b/Import/ReportingServicesConverter.cs @@ -361,7 +361,7 @@ public class ReportingServicesConverter : ExternalConverterBase, IReportingServi public void ProcessTextBoxAsLabel(XElement textBoxElement, XRLabel control, float yBodyOffset) { var runs = textBoxElement.Descendants(xmlns + "TextRun"); if(runs.Count() > 1) { - throw new NotSupportedException("Label can be converted from single TextRun."); + throw new NotSupportedException(string.Format(Messages.TextBoxWithMultipleTextRunsToXRLabel_NotSupported, control.Name)); } this.SetComponentName(control, textBoxElement); control.TextAlignment = TextAlignment.TopLeft;