Пример #1
0
        private static string HandleDateAttribute(string param, SearchParameter searchParameter, string operatorPrefix)
        {
            var formatedParam = String.Format(HibernateUtil.ParameterPrefixPattern, param);

            if (searchParameter.SearchOperator == SearchOperator.BLANK)
            {
                return(" IS NULL");
            }
            else if (!searchParameter.IsEqualOrNotEqual())
            {
                var parameterName = param;
                if (searchParameter.SearchOperator == SearchOperator.GTE || searchParameter.SearchOperator == SearchOperator.GT)
                {
                    parameterName += DateSearchParamBegin;
                }
                if (searchParameter.SearchOperator == SearchOperator.LTE || searchParameter.SearchOperator == SearchOperator.LT)
                {
                    parameterName += DateSearchParamEnd;
                }
                return(operatorPrefix + String.Format(HibernateUtil.ParameterPrefixPattern, parameterName));
            }
            var prefix = searchParameter.SearchOperator == SearchOperator.EQ ? " BETWEEN " : " NOT BETWEEN ";
            var sb     = new StringBuilder();

            return(sb.Append(prefix)
                   .Append(formatedParam)
                   .Append(DateSearchParamBegin)
                   .Append(" AND ")
                   .Append(formatedParam)
                   .Append(DateSearchParamEnd).ToString());
        }
Пример #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()));
                }
            }
        }