Ejemplo n.º 1
0
        private static string GetColumnFilter <T>(RadzenGridColumn <T> column, bool second = false)
        {
            var property = PropertyAccess.GetProperty(column.GetFilterProperty());

            if (property.IndexOf(".") != -1)
            {
                property = $"({property})";
            }

            if (column.Type == "string" && string.IsNullOrEmpty(column.Format))
            {
                property = $@"({property} == null ? """" : {property})";
            }

            var columnFilterOperator = !second ? column.FilterOperator : column.SecondFilterOperator;

            var linqOperator = FilterOperators[columnFilterOperator];

            if (linqOperator == null)
            {
                linqOperator = "==";
            }

            var value = !second ? (string)Convert.ChangeType(column.FilterValue, typeof(string)) :
                        (string)Convert.ChangeType(column.SecondFilterValue, typeof(string));

            var columnType   = column.Type;
            var columnFormat = column.Format;

            if (columnType == "string")
            {
                string filterCaseSensitivityOperator = column.Grid.FilterCaseSensitivity == FilterCaseSensitivity.CaseInsensitive ? ".ToLower()" : "";

                if (columnFormat == "date-time" || columnFormat == "date")
                {
                    var dateTimeValue = DateTime.Parse(value, null, System.Globalization.DateTimeStyles.RoundtripKind);
                    var finalDate     = dateTimeValue.TimeOfDay == TimeSpan.Zero ? dateTimeValue.Date : dateTimeValue;
                    var dateFormat    = dateTimeValue.TimeOfDay == TimeSpan.Zero ? "yyyy-MM-dd" : "yyyy-MM-ddTHH:mm:ssZ";

                    return($@"{property} {linqOperator} DateTime(""{finalDate.ToString(dateFormat)}"")");
                }
                else if (columnFormat == "time")
                {
                    return($"{property} {linqOperator} duration'{value}'");
                }
                else if (columnFormat == "uuid")
                {
                    return($@"{property} {linqOperator} Guid(""{value}"")");
                }
                else if (!string.IsNullOrEmpty(value) && columnFilterOperator == "contains")
                {
                    return($@"({property} == null ? """" : {property}){filterCaseSensitivityOperator}.Contains(""{value}""{filterCaseSensitivityOperator})");
                }
                else if (!string.IsNullOrEmpty(value) && columnFilterOperator == "startswith")
                {
                    return($@"({property} == null ? """" : {property}){filterCaseSensitivityOperator}.StartsWith(""{value}""{filterCaseSensitivityOperator})");
                }
                else if (!string.IsNullOrEmpty(value) && columnFilterOperator == "endswith")
                {
                    return($@"({property} == null ? """" : {property}){filterCaseSensitivityOperator}.EndsWith(""{value}""{filterCaseSensitivityOperator})");
                }
                else if (!string.IsNullOrEmpty(value) && columnFilterOperator == "eq")
                {
                    return($@"{property} == null ? """" : {property}{filterCaseSensitivityOperator} == {value}{filterCaseSensitivityOperator}");
                }
            }
            else if (columnType == "number" || columnType == "integer")
            {
                return($"{property} {linqOperator} {value}");
            }
            else if (columnType == "boolean")
            {
                return($"{property} == {value}");
            }

            return("");
        }
Ejemplo n.º 2
0
        private static string GetColumnODataFilter <T>(RadzenGridColumn <T> column, bool second = false)
        {
            var columnType   = column.Type;
            var columnFormat = column.Format;

            var property = column.GetFilterProperty().Replace('.', '/');

            var columnFilterOperator = !second ? column.FilterOperator : column.SecondFilterOperator;

            var value = !second ? (string)Convert.ChangeType(column.FilterValue, typeof(string)) :
                        (string)Convert.ChangeType(column.SecondFilterValue, typeof(string));

            if (column.Grid.FilterCaseSensitivity == FilterCaseSensitivity.CaseInsensitive && columnType == "string" && string.IsNullOrEmpty(columnFormat))
            {
                property = $"tolower({property})";
            }

            if (columnType == "string")
            {
                if (columnFormat == "date-time" || columnFormat == "date")
                {
                    return($"{property} {columnFilterOperator} {DateTime.Parse(value, null, System.Globalization.DateTimeStyles.RoundtripKind).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")}");
                }
                else if (columnFormat == "time")
                {
                    return($"{property} {columnFilterOperator} duration'{value}'");
                }
                else if (columnFormat == "uuid")
                {
                    return($"{property} {columnFilterOperator} {value}");
                }
                else if (!string.IsNullOrEmpty(value) && columnFilterOperator == "contains")
                {
                    return(column.Grid.FilterCaseSensitivity == FilterCaseSensitivity.CaseInsensitive ?
                           $"contains({property}, tolower('{value}'))" :
                           $"contains({property}, '{value}')");
                }
                else if (!string.IsNullOrEmpty(value) && columnFilterOperator == "startswith")
                {
                    return(column.Grid.FilterCaseSensitivity == FilterCaseSensitivity.CaseInsensitive ?
                           $"startswith({property}, tolower('{value}'))" :
                           $"startswith({property}, '{value}')");
                }
                else if (!string.IsNullOrEmpty(value) && columnFilterOperator == "endswith")
                {
                    return(column.Grid.FilterCaseSensitivity == FilterCaseSensitivity.CaseInsensitive ?
                           $"endswith({property}, tolower('{value}'))" :
                           $"endswith({property}, '{value}')");
                }
                else if (!string.IsNullOrEmpty(value) && columnFilterOperator == "eq")
                {
                    return($"{property} eq {value}");
                }
            }
            else if (columnType == "number" || columnType == "integer")
            {
                return($"{property} {columnFilterOperator} {value}");
            }
            else if (columnType == "boolean")
            {
                return($"{property} eq {value.ToLower()}");
            }

            return("");
        }