Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="query"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public static IQueryable <WorkOrder> filterDateTimeOfWork(IQueryable <WorkOrder> query, string search)
        {
            //Using DateTime.TryParse as determiner of date/string
            DateTime parsedTime;

            if (DateTime.TryParse(search, out parsedTime))
            {
                if (isMonthSpecific.IsMatch(search))  //Regex for month/year
                {
                    return(query.Where(p => SqlServerDbFunctionsExtensions
                                       .DateDiffMonth(null, p.dateTimeofWork, parsedTime) == 0 ? true : false));
                }
                if (isDaySpecific.IsMatch(search))  //Regex for day/month/year
                {
                    return(query.Where(p => SqlServerDbFunctionsExtensions
                                       .DateDiffDay(null, p.dateTimeofWork, parsedTime) == 0 ? true : false));
                }
                if (isTimeSpecific.IsMatch(search)) //Regex for day/month/year time
                {
                    return(query.Where(p => SqlServerDbFunctionsExtensions
                                       .DateDiffHour(null, p.dateTimeofWork, parsedTime) == 0 ? true : false));
                }
            }
            return(query);
        }
Exemple #2
0
        public static void search(viewOptions o, ref IQueryable <WorkOrder> q)
        {
            bool     isDateTime = false;
            DateTime parsedTime;

            if (isDateTime = DateTime.TryParse(o.sSearch, out parsedTime))
            {
                if (isMonthSpecific.IsMatch(o.sSearch))  //Regex for month/year
                {
                    q = q.Where(p => SqlServerDbFunctionsExtensions
                                .DateDiffMonth(null, p.dateTimeofWork, parsedTime) == 0 ? true : false);
                }
                if (isDaySpecific.IsMatch(o.sSearch))  //Regex for day/month/year
                {
                    q = q.Where(p => SqlServerDbFunctionsExtensions
                                .DateDiffDay(null, p.dateTimeofWork, parsedTime) == 0 ? true : false);
                }
                if (isTimeSpecific.IsMatch(o.sSearch)) //Regex for day/month/year time
                {
                    q = q.Where(p => SqlServerDbFunctionsExtensions
                                .DateDiffHour(null, p.dateTimeofWork, parsedTime) == 0 ? true : false);
                }
            }
            else
            {
                q = q
                    .Where(p => p.ID.ToString().Contains(o.sSearch) ||
                           p.paperOrderNum.ToString().Contains(o.sSearch) ||
                           p.contactName.Contains(o.sSearch) ||
                           p.workSiteAddress1.Contains(o.sSearch) ||
                           p.updatedby.Contains(o.sSearch));
            }
        }
Exemple #3
0
 /// <summary>
 /// Filter WA queryable on a partial date string
 /// </summary>
 /// <param name="search">string that is part of a date</param>
 /// <param name="parsedTime">datetime.parse of the same string</param>
 /// <param name="query">WorkAssignment queryable</param>
 public static void filterOnDatePart(string search, DateTime parsedTime, ref IQueryable <WorkAssignment> query)
 {
     if (isMonthSpecific.IsMatch(search))  //Regex for month/year
     {
         query = query.Where(p => SqlServerDbFunctionsExtensions
                             .DateDiffMonth(null, p.workOrder.dateTimeofWork, parsedTime) == 0 ? true : false);
     }
     if (isDaySpecific.IsMatch(search))  //Regex for day/month/year
     {
         query = query.Where(p => SqlServerDbFunctionsExtensions
                             .DateDiffDay(null, p.workOrder.dateTimeofWork, parsedTime) == 0 ? true : false);
     }
     if (isTimeSpecific.IsMatch(search)) //Regex for day/month/year time
     {
         query = query.Where(p => SqlServerDbFunctionsExtensions
                             .DateDiffHour(null, p.workOrder.dateTimeofWork, parsedTime) == 0 ? true : false);
     }
     //throw new ArgumentException("Date string not valid for Month,Day, or Hour pattern");
 }
Exemple #4
0
        public static void search(viewOptions o, TimeZoneInfo clientTimeZoneInfo, ref IQueryable <WorkOrder> q)
        {
            bool     isDateTime = false;
            DateTime parsedTime;

            if (isDateTime = DateTime.TryParse(o.sSearch, out parsedTime))
            {
                var searchDateStartUtc = parsedTime.ToUtcFrom(clientTimeZoneInfo); // some date at midnight time + {offset} hours
                var searchDateEndUtc   = searchDateStartUtc.AddHours(24);          // UTC end search dateTime

                if (isMonthSpecific.IsMatch(o.sSearch))                            //Regex for month/year
                {
                    q = q.Where(p => SqlServerDbFunctionsExtensions
                                .DateDiffMonth(null, p.dateTimeofWork, searchDateStartUtc) == 0 ? true : false);
                }
                if (isDaySpecific.IsMatch(o.sSearch))  //Regex for day/month/year
                {
                    q = q.Where(p =>
                                p.dateTimeofWork >= searchDateStartUtc &&
                                p.dateTimeofWork < searchDateEndUtc);
                }
                if (isTimeSpecific.IsMatch(o.sSearch)) //Regex for day/month/year time
                {
                    q = q.Where(p => SqlServerDbFunctionsExtensions
                                .DateDiffHour(null, p.dateTimeofWork, searchDateStartUtc) == 0 ? true : false);
                }
            }
            else
            {
                q = q
                    .Where(p => p.ID.ToString().Contains(o.sSearch) ||
                           p.paperOrderNum.ToString().Contains(o.sSearch) ||
                           p.contactName.Contains(o.sSearch) ||
                           p.workSiteAddress1.Contains(o.sSearch) ||
                           p.updatedby.Contains(o.sSearch));
            }
        }