Skip to content

Commit

Permalink
RDL - code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
k0st1x committed Jan 17, 2021
1 parent bb9ed6e commit 2d241ef
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions DevExpress.XtraReports.Import.csproj
Expand Up @@ -11,6 +11,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>DevExpress.XtraReports.Import</RootNamespace>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\Debug\</OutputPath>
Expand Down
25 changes: 13 additions & 12 deletions Import/ReportingServices/DataSources/DataSourceConverter.cs
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}

Expand Down
15 changes: 12 additions & 3 deletions Import/ReportingServices/Expressions/ExpressionParser.cs
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using DevExpress.Data.Filtering;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]);
Expand Down
1 change: 1 addition & 0 deletions Import/ReportingServices/Messages.cs
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion Import/ReportingServicesConverter.cs
Expand Up @@ -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;
Expand Down

0 comments on commit 2d241ef

Please sign in to comment.