예제 #1
0
        private static Tuple <string, ParameterType> GetParameterData(string entityName, SearchParameter searchParameter, string paramName)
        {
            // UNION statements cases
            if (paramName.StartsWith("null") || paramName.StartsWith("#null"))
            {
                return(new Tuple <string, ParameterType>("null", ParameterType.Default));
            }
            if (paramName.EndsWith("_union"))
            {
                paramName = paramName.Substring(0, paramName.Length - "_union".Length);
            }

            var entity = MetadataProvider.Entity(entityName);

            paramName = paramName.Contains("___") ? paramName.Split(new[] { "___" }, StringSplitOptions.RemoveEmptyEntries)[0] : paramName;
            if (Char.IsNumber(paramName[0]))
            {
                //if the param was duplicated on the search for some reason
                paramName = paramName.Substring(1);
            }
            var baseResult          = paramName.Contains(".") ? paramName : entityName + "." + paramName;
            var attributeDefinition = entity.Attributes(EntityMetadata.AttributesMode.NoCollections).FirstOrDefault(f => f.Name == paramName);
            var resultType          = ParameterType.Default;

            var ignoreCoalesce = false;

            if (attributeDefinition != null)
            {
                if (attributeDefinition.Query != null)
                {
                    baseResult = attributeDefinition.GetQueryReplacingMarkers(entityName);
                }
                else if (attributeDefinition.IsDate)
                {
                    resultType = ParameterType.Date;
                }
                else if (attributeDefinition.IsNumber)
                {
                    resultType = ParameterType.Number;
                }
            }
            if (resultType == ParameterType.Date || resultType == ParameterType.Number)
            {
                return(new Tuple <string, ParameterType>(baseResult, resultType));
            }
            if (searchParameter.FilterSearch)
            {
                if (attributeDefinition != null && attributeDefinition.IgnoreCoalesce)
                {
                    //avoid coalesce workaround
                    return(new Tuple <string, ParameterType>(baseResult, resultType));
                }

                //if this is a filter search input lets make it case insensitive
                return(new Tuple <string, ParameterType>("UPPER(COALESCE(" + baseResult + ",''))", resultType));
            }
            return(new Tuple <string, ParameterType>(baseResult, resultType));
        }
예제 #2
0
        private static void HandleDateParameter(SearchParameter parameter, IDictionary <string, object> resultDictionary,
                                                KeyValuePair <string, SearchParameter> searchParameter, DateTime dt)
        {
            if (parameter.IsEqualOrNotEqual())
            {
                if (!parameter.HasHour)
                {
                    //this shall create a between interval
                    resultDictionary.Add(searchParameter.Key + DateSearchParamBegin, DateUtil.BeginOfDay(dt));
                    resultDictionary.Add(searchParameter.Key + DateSearchParamEnd, DateUtil.EndOfDay(dt));
                }
                else
                {
                    //EQ 16:46 should become BETWEEN 16:46:00 and 16:46:59.999
                    resultDictionary.Add(searchParameter.Key + DateSearchParamBegin, dt);
                    resultDictionary.Add(searchParameter.Key + DateSearchParamEnd, dt.AddSeconds(59).AddMilliseconds(999));

                    //resultDictionary.Add(searchParameter.Key, dt);
                }
            }
            else if (parameter.IsGtOrGte())
            {
                if (!parameter.HasHour)
                {
                    if (parameter.SearchOperator == SearchOperator.GT)
                    {
                        //if GT, then we need to exclude the current day from the search
                        dt = dt.AddDays(1);
                    }
                    resultDictionary.Add(searchParameter.Key + DateSearchParamBegin, DateUtil.BeginOfDay(dt));
                }
                else
                {
                    if (parameter.SearchOperator == SearchOperator.GT)
                    {
                        //if GT let's add one minute since screen doesn't show seconds --> so GT > 16:36 becomes actually GT > 16:36:59.999
                        dt = dt.AddSeconds(59).AddMilliseconds(999);
                    }
                    //if GTE: GTE>= 16:36 keep it as it is
                    resultDictionary.Add(searchParameter.Key + DateSearchParamBegin, dt.FromUserToMaximo(SecurityFacade.CurrentUser()));
                }
            }
            else if (parameter.IsLtOrLte())
            {
                if (!parameter.HasHour)
                {
                    if (parameter.SearchOperator == SearchOperator.LT)
                    {
                        //if GT, then we need to exclude the current day from the search, making the beggining of yesterday instead
                        dt = dt.AddDays(-1);
                    }
                    resultDictionary.Add(searchParameter.Key + DateSearchParamEnd, DateUtil.EndOfDay(dt));
                }
                else
                {
                    dt = dt.AddSeconds(59).AddMilliseconds(999);
                    if (parameter.SearchOperator == SearchOperator.LT)
                    {
                        //if LT let's subtract one minute since screen doesn't show seconds --> LT < 16:36 becomes LT <16:35.59.999
                        dt = dt.AddMinutes(-1);
                    }
                    resultDictionary.Add(searchParameter.Key + DateSearchParamEnd, dt.FromUserToMaximo(SecurityFacade.CurrentUser()));
                }
            }
        }