public virtual IEnumerable weekCodeDateRecords()
        {
            FSRoute       fsRouteRow    = RouteRecords.Current;
            List <object> returnList    = new List <object>();
            List <object> weekCodeArgs  = new List <object>();
            List <int>    dayOfWeekDays = new List <int>();

            BqlCommand commandFilter = new Select <FSWeekCodeDate>();

            Regex rgxP1 = new Regex(@"^[1-4]$");
            Regex rgxP2 = new Regex(@"^[a-bA-B]$");
            Regex rgxP3 = new Regex(@"^[c-fC-F]$");
            Regex rgxP4 = new Regex(@"^[s-zS-Z]$");

            if (fsRouteRow != null && string.IsNullOrEmpty(fsRouteRow.WeekCode) == false)
            {
                List <string> weekcodes = SharedFunctions.SplitWeekcodeByComma(fsRouteRow.WeekCode);

                foreach (string weekcode in weekcodes)
                {
                    List <string> charsInWeekCode = SharedFunctions.SplitWeekcodeInChars(weekcode);
                    string        p1, p2, p3, p4;
                    p1 = p2 = p3 = p4 = "%";

                    foreach (string letter in charsInWeekCode)
                    {
                        string letterAux = letter.ToUpper();

                        if (rgxP1.IsMatch(letterAux))
                        {
                            p1 = letterAux;
                        }
                        else if (rgxP2.IsMatch(letterAux))
                        {
                            p2 = letterAux;
                        }
                        else if (rgxP3.IsMatch(letterAux))
                        {
                            p3 = letterAux;
                        }
                        else if (rgxP4.IsMatch(letterAux))
                        {
                            p4 = letterAux;
                        }
                    }

                    commandFilter = commandFilter.WhereOr <
                        Where2 <
                            Where <
                                FSWeekCodeDate.weekCodeP1, Like <Required <FSWeekCodeDate.weekCodeP1> >,
                                Or <FSWeekCodeDate.weekCodeP1, Like <Required <FSWeekCodeDate.weekCodeP1> >,
                                    Or <FSWeekCodeDate.weekCodeP1, IsNull> > >,
                            And2 <
                                Where <
                                    FSWeekCodeDate.weekCodeP2, Like <Required <FSWeekCodeDate.weekCodeP2> >,
                                    Or <FSWeekCodeDate.weekCodeP2, Like <Required <FSWeekCodeDate.weekCodeP2> >,
                                        Or <FSWeekCodeDate.weekCodeP2, IsNull> > >,
                                And2 <
                                    Where <
                                        FSWeekCodeDate.weekCodeP3, Like <Required <FSWeekCodeDate.weekCodeP3> >,
                                        Or <FSWeekCodeDate.weekCodeP3, Like <Required <FSWeekCodeDate.weekCodeP3> >,
                                            Or <FSWeekCodeDate.weekCodeP3, IsNull> > >,
                                    And <
                                        Where <
                                            FSWeekCodeDate.weekCodeP4, Like <Required <FSWeekCodeDate.weekCodeP4> >,
                                            Or <FSWeekCodeDate.weekCodeP4, Like <Required <FSWeekCodeDate.weekCodeP4> >,
                                                Or <FSWeekCodeDate.weekCodeP4, IsNull> > > > > > >
                        >();

                    weekCodeArgs.Add(p1);
                    weekCodeArgs.Add(p1.ToLower());
                    weekCodeArgs.Add(p2);
                    weekCodeArgs.Add(p2.ToLower());
                    weekCodeArgs.Add(p3);
                    weekCodeArgs.Add(p3.ToLower());
                    weekCodeArgs.Add(p4);
                    weekCodeArgs.Add(p4.ToLower());
                }

                WeekCodeFilter filter = WeekCodeFilter.Current;

                if (filter != null)
                {
                    if (filter.DateBegin != null)
                    {
                        commandFilter = commandFilter.WhereAnd(typeof(Where <FSWeekCodeDate.weekCodeDate, GreaterEqual <Current <WeekCodeFilter.dateBegin> > >));
                    }

                    if (filter.DateEnd != null)
                    {
                        commandFilter = commandFilter.WhereAnd(typeof(Where <FSWeekCodeDate.weekCodeDate, LessEqual <Current <WeekCodeFilter.dateEnd> > >));
                    }
                }

                if (fsRouteRow.ActiveOnSunday == true)
                {
                    dayOfWeekDays.Add(ID.WeekDaysNumber.SUNDAY);
                }

                if (fsRouteRow.ActiveOnMonday == true)
                {
                    dayOfWeekDays.Add(ID.WeekDaysNumber.MONDAY);
                }

                if (fsRouteRow.ActiveOnTuesday == true)
                {
                    dayOfWeekDays.Add(ID.WeekDaysNumber.TUESDAY);
                }

                if (fsRouteRow.ActiveOnWednesday == true)
                {
                    dayOfWeekDays.Add(ID.WeekDaysNumber.WEDNESDAY);
                }

                if (fsRouteRow.ActiveOnThursday == true)
                {
                    dayOfWeekDays.Add(ID.WeekDaysNumber.THURSDAY);
                }

                if (fsRouteRow.ActiveOnFriday == true)
                {
                    dayOfWeekDays.Add(ID.WeekDaysNumber.FRIDAY);
                }

                if (fsRouteRow.ActiveOnSaturday == true)
                {
                    dayOfWeekDays.Add(ID.WeekDaysNumber.SATURDAY);
                }

                if (dayOfWeekDays != null && dayOfWeekDays.Count > 0)
                {
                    commandFilter = commandFilter.WhereAnd(InHelper <FSWeekCodeDate.dayOfWeek> .Create(dayOfWeekDays.Count));
                    foreach (int dayOfWeekDay in dayOfWeekDays)
                    {
                        weekCodeArgs.Add(dayOfWeekDay);
                    }
                }

                PXView weekCodeRecordsView = new PXView(this, true, commandFilter);
                var    startRow            = PXView.StartRow;
                int    totalRows           = 0;
                var    list = weekCodeRecordsView.Select(
                    PXView.Currents,
                    weekCodeArgs.ToArray(),
                    PXView.Searches,
                    PXView.SortColumns,
                    PXView.Descendings,
                    PXView.Filters,
                    ref startRow,
                    PXView.MaximumRows,
                    ref totalRows);
                PXView.StartRow = 0;
                return(list);
            }

            return(returnList);
        }
        public virtual IEnumerable weekCodeDateRecords()
        {
            FSRouteContractSchedule fsRouteContractScheduleRow = ContractScheduleRecords.Current;
            List <object>           returnList   = new List <object>();
            List <object>           weekCodeArgs = new List <object>();
            List <int> dayOfWeekDays             = new List <int>();

            BqlCommand commandFilter = new Select <FSWeekCodeDate>();

            Regex rgxP1 = new Regex(@"^[1-4]$");
            Regex rgxP2 = new Regex(@"^[a-bA-B]$");
            Regex rgxP3 = new Regex(@"^[c-fC-F]$");
            Regex rgxP4 = new Regex(@"^[s-zS-Z]$");

            if (fsRouteContractScheduleRow != null && string.IsNullOrEmpty(fsRouteContractScheduleRow.WeekCode) == false)
            {
                List <string> weekcodes = SharedFunctions.SplitWeekcodeByComma(fsRouteContractScheduleRow.WeekCode);

                foreach (string weekcode in weekcodes)
                {
                    List <string> charsInWeekCode = SharedFunctions.SplitWeekcodeInChars(weekcode);
                    string        p1, p2, p3, p4;
                    p1 = p2 = p3 = p4 = "%";

                    foreach (string letter in charsInWeekCode)
                    {
                        string letterAux = letter.ToUpper();

                        if (rgxP1.IsMatch(letterAux))
                        {
                            p1 = letterAux;
                        }
                        else if (rgxP2.IsMatch(letterAux))
                        {
                            p2 = letterAux;
                        }
                        else if (rgxP3.IsMatch(letterAux))
                        {
                            p3 = letterAux;
                        }
                        else if (rgxP4.IsMatch(letterAux))
                        {
                            p4 = letterAux;
                        }
                    }

                    commandFilter = commandFilter.WhereOr(typeof(
                                                              Where2 <
                                                                  Where <
                                                                      FSWeekCodeDate.weekCodeP1, Like <Required <FSWeekCodeDate.weekCodeP1> >,
                                                                      Or <FSWeekCodeDate.weekCodeP1, Like <Required <FSWeekCodeDate.weekCodeP1> >,
                                                                          Or <FSWeekCodeDate.weekCodeP1, IsNull> > >,
                                                                  And2 <
                                                                      Where <
                                                                          FSWeekCodeDate.weekCodeP2, Like <Required <FSWeekCodeDate.weekCodeP2> >,
                                                                          Or <FSWeekCodeDate.weekCodeP2, Like <Required <FSWeekCodeDate.weekCodeP2> >,
                                                                              Or <FSWeekCodeDate.weekCodeP2, IsNull> > >,
                                                                      And2 <
                                                                          Where <
                                                                              FSWeekCodeDate.weekCodeP3, Like <Required <FSWeekCodeDate.weekCodeP3> >,
                                                                              Or <FSWeekCodeDate.weekCodeP3, Like <Required <FSWeekCodeDate.weekCodeP3> >,
                                                                                  Or <FSWeekCodeDate.weekCodeP3, IsNull> > >,
                                                                          And <
                                                                              Where <
                                                                                  FSWeekCodeDate.weekCodeP4, Like <Required <FSWeekCodeDate.weekCodeP4> >,
                                                                                  Or <FSWeekCodeDate.weekCodeP4, Like <Required <FSWeekCodeDate.weekCodeP4> >,
                                                                                      Or <FSWeekCodeDate.weekCodeP4, IsNull> > > > > > >));

                    weekCodeArgs.Add(p1);
                    weekCodeArgs.Add(p1.ToLower());
                    weekCodeArgs.Add(p2);
                    weekCodeArgs.Add(p2.ToLower());
                    weekCodeArgs.Add(p3);
                    weekCodeArgs.Add(p3.ToLower());
                    weekCodeArgs.Add(p4);
                    weekCodeArgs.Add(p4.ToLower());
                }

                WeekCodeFilter filter = WeekCodeFilter.Current;

                if (filter != null)
                {
                    DateTime?dateBegin = filter.DateBegin;
                    DateTime?dateEnd   = null;

                    if (filter.DateEnd.HasValue)
                    {
                        dateEnd = filter.DateEnd;
                    }

                    if (dateBegin.HasValue == true && dateEnd.HasValue == false)
                    {
                        dateEnd = filter.DateEnd.HasValue ? filter.DateEnd : dateBegin.Value.AddYears(1);
                    }

                    if (dateBegin != null)
                    {
                        commandFilter = commandFilter.WhereAnd(typeof(Where <FSWeekCodeDate.weekCodeDate, GreaterEqual <Required <WeekCodeFilter.dateBegin> > >));
                        weekCodeArgs.Add(dateBegin);
                    }

                    if (dateEnd != null)
                    {
                        commandFilter = commandFilter.WhereAnd(typeof(Where <FSWeekCodeDate.weekCodeDate, LessEqual <Required <WeekCodeFilter.dateEnd> > >));
                        weekCodeArgs.Add(dateEnd);
                    }
                }

                if (fsRouteContractScheduleRow.FrequencyType == ID.Schedule_FrequencyType.WEEKLY)
                {
                    if (fsRouteContractScheduleRow.WeeklyOnSun == true)
                    {
                        dayOfWeekDays.Add(ID.WeekDaysNumber.SUNDAY);
                    }

                    if (fsRouteContractScheduleRow.WeeklyOnMon == true)
                    {
                        dayOfWeekDays.Add(ID.WeekDaysNumber.MONDAY);
                    }

                    if (fsRouteContractScheduleRow.WeeklyOnTue == true)
                    {
                        dayOfWeekDays.Add(ID.WeekDaysNumber.TUESDAY);
                    }

                    if (fsRouteContractScheduleRow.WeeklyOnWed == true)
                    {
                        dayOfWeekDays.Add(ID.WeekDaysNumber.WEDNESDAY);
                    }

                    if (fsRouteContractScheduleRow.WeeklyOnThu == true)
                    {
                        dayOfWeekDays.Add(ID.WeekDaysNumber.THURSDAY);
                    }

                    if (fsRouteContractScheduleRow.WeeklyOnFri == true)
                    {
                        dayOfWeekDays.Add(ID.WeekDaysNumber.FRIDAY);
                    }

                    if (fsRouteContractScheduleRow.WeeklyOnSat == true)
                    {
                        dayOfWeekDays.Add(ID.WeekDaysNumber.SATURDAY);
                    }

                    if (dayOfWeekDays != null && dayOfWeekDays.Count > 0)
                    {
                        commandFilter = commandFilter.WhereAnd(InHelper <FSWeekCodeDate.dayOfWeek> .Create(dayOfWeekDays.Count));
                        foreach (int dayOfWeekDay in dayOfWeekDays)
                        {
                            weekCodeArgs.Add(dayOfWeekDay);
                        }
                    }
                }

                PXView weekCodeRecordsView = new PXView(this, true, commandFilter);
                return(weekCodeRecordsView.SelectMulti(weekCodeArgs.ToArray()));
            }

            return(returnList);
        }
Esempio n. 3
0
        protected virtual IEnumerable emails(
            [PXString]
            string boxKey)
        {
            int?accountId;
            int?filterId;

            DecodeBoxKey(boxKey, out accountId, out filterId);

            var command    = Emails.View.BqlSelect;
            var parameters = new List <object>();

            List <int> classIds = new List <int>();

            foreach (Box Box in EnumerateBoxes())
            {
                int?val;
                int?val2;
                DecodeBoxKey(Box.Key, out val, out val2);
                classIds.Add((int)val);
            }
            if (classIds != null && classIds.Count > 0)
            {
                command = command.WhereAnd(InHelper <EPActivity.mailAccountID> .Create(classIds.Count));
                foreach (int classId in classIds)
                {
                    parameters.Add(classId);
                }
            }

            var account = accountId.With(_ => (EMailAccount)PXSelect <EMailAccount,
                                                                      Where <EMailAccount.emailAccountID, Equal <Required <EMailAccount.emailAccountID> > > > .
                                         Select(this, _.Value));

            if (account != null)
            {
                command = command.WhereAnd(typeof(Where <EPActivity.mailAccountID, Equal <Required <EMailAccount.emailAccountID> > >));
                parameters.Add(account.EmailAccountID);
            }

            if (filterId != null)
            {
                command = AppendEmailFilter((int)filterId, command);
            }

            if (boxKey != null)
            {
                string[] arr;
                if (!string.IsNullOrEmpty(boxKey) && (arr = boxKey.Split('$')).Length == 2)
                {
                    Boxes.Current = Boxes.Select(String.Concat(arr[0], "$"));
                    if (!String.IsNullOrEmpty(arr[1]))
                    {
                        Boxes.Current.Folder = Convert.ToInt32(arr[1]);
                    }
                    else
                    {
                        Boxes.Current.Folder = -1;
                    }
                    switch (Boxes.Current.Folder)
                    {
                    case _INBOX_FID:
                        PXUIFieldAttribute.SetVisible <EPActivity.mailFrom>(Caches[typeof(EPActivity)], null, true);
                        PXUIFieldAttribute.SetVisible <EPActivity.mailTo>(Caches[typeof(EPActivity)], null, false);
                        break;

                    case _DRAFT_FID:
                        PXUIFieldAttribute.SetVisible <EPActivity.mailFrom>(Caches[typeof(EPActivity)], null, false);
                        PXUIFieldAttribute.SetVisible <EPActivity.mailTo>(Caches[typeof(EPActivity)], null, true);
                        break;

                    case _SENT_FID:
                        PXUIFieldAttribute.SetVisible <EPActivity.mailFrom>(Caches[typeof(EPActivity)], null, false);
                        PXUIFieldAttribute.SetVisible <EPActivity.mailTo>(Caches[typeof(EPActivity)], null, true);
                        break;

                    case _OUTBOX_FID:
                        PXUIFieldAttribute.SetVisible <EPActivity.mailFrom>(Caches[typeof(EPActivity)], null, false);
                        PXUIFieldAttribute.SetVisible <EPActivity.mailTo>(Caches[typeof(EPActivity)], null, true);
                        break;

                    case _REMOVED_FID:
                        PXUIFieldAttribute.SetVisible <EPActivity.mailFrom>(Caches[typeof(EPActivity)], null, true);
                        PXUIFieldAttribute.SetVisible <EPActivity.mailTo>(Caches[typeof(EPActivity)], null, true);
                        break;

                    default:
                        PXUIFieldAttribute.SetVisible <EPActivity.mailFrom>(Caches[typeof(EPActivity)], null, true);
                        PXUIFieldAttribute.SetVisible <EPActivity.mailTo>(Caches[typeof(EPActivity)], null, true);
                        break;
                    }
                }
            }
            else
            {
                Boxes.Current = Boxes.Select(boxKey);
            }
            return(this.QuickSelect(command, parameters.ToArray()));
        }