private void Search(string str) { selectedDay = (FlagDayOfWeek) ~0; selectedRestaurant = (Restaurants) ~0; Display((dayMenu) => dayMenu.Contains(str)); }
/// <summary> /// Restart menu handler to default state - after each completed action. /// </summary> private void Init() { selectedOption = Options.None; IsFinished = false; selectedDay = 0; selectedRestaurant = 0; PrintHelp(); }
/// <summary> /// Set selectedDay bit to one (as only one) /// </summary> /// <param name="value">Index of bit to set to 1.</param> /// <returns>True if set was successful, false otherwise.</returns> private bool SetSelectedDay(int value) { if (1 <= value && value <= 5) { selectedDay = (FlagDayOfWeek)(1 << value); return(true); } Console.WriteLine("Neplatné číslo dne!"); return(false); }
//public static DayOfWeek ToWeekOfDay(this FlagDayOfWeek fdow) //{ // return DayOfWeek.Sunday; //} public static Boolean isExceptionDate(this DateTime date, FlagDayOfWeek week = FlagDayOfWeek.AllWeek, IEnumerable <DateTime> exceptions = null) { Boolean isException = false; isException = (week == FlagDayOfWeek.AllWeek) ? false : !date.DayOfWeek.IsInFlagDayOfWeek(week); //var test = date.DayOfWeek.IsInFlagDayOfWeek(week); if (exceptions != null && exceptions.Count() != 0) { isException |= exceptions.Where(x => x.Date == date.Date).Any(); } return(isException); }
private void SelectOption(int opt) { if (Enum.IsDefined(typeof(Options), opt) && opt != 0) { selectedOption = (Options)opt; } else { Error(); return; } switch (selectedOption) { case Options.WeekAllRestaurants: selectedRestaurant = (Restaurants) ~0; selectedDay = (FlagDayOfWeek) ~0; break; case Options.TodayAllRestaurants: selectedRestaurant = (Restaurants) ~0; SetSelectedDay(DateTime.Now.DayOfWeek); break; case Options.Search: Console.WriteLine("Napište hledaný řetězec:"); break; case Options.SelectedDayAllRestaurants: PrintDayOptions(); break; case Options.SelectedDaySelectedRestaurant: case Options.TodaySelectedRestaurant: PrintRestaurantOptions(); break; case Options.Quit: IsFinished = true; Console.WriteLine("Dobrou chuť!"); break; } }
public static List <dtoWorkingDayHour> GetDefaultWorkingDayHours(FlagDayOfWeek days, long idCalendar = 0) { List <dtoWorkingDayHour> items = new List <dtoWorkingDayHour>(); foreach (FlagDayOfWeek fEnum in (from e in Enum.GetValues(typeof(FlagDayOfWeek)).OfType <FlagDayOfWeek>() where e != FlagDayOfWeek.Weekend && e != FlagDayOfWeek.None && e != FlagDayOfWeek.WorkWeek && e != FlagDayOfWeek.AllWeek select e)) { if (days.HasFlag(fEnum)) { items.Add(new dtoWorkingDayHour(8, 0, 12, 0) { DayOfWeek = fEnum, IdCalendar = idCalendar }); items.Add(new dtoWorkingDayHour(13, 0, 17, 0) { DayOfWeek = fEnum, IdCalendar = idCalendar }); } } return(items); }
public CPMresult DefaultCPM(Boolean allowSummary, List <dtoCPMactivity> activities, DateTime?startdate = null, FlagDayOfWeek workweek = FlagDayOfWeek.WorkWeek, IEnumerable <DateTime> exceptions = null, Int32 dailyworkhours = 8) { foreach (var item in activities) { item.EarlyFinish = 0; item.EarlyStart = 0; item.LatestFinish = 0; item.LatestStart = 0; } if (allowSummary) { return(CPMWithSummary(activities, startdate, workweek, exceptions, dailyworkhours)); } else { return(CPM(activities, startdate, workweek, exceptions, dailyworkhours)); } }
private CPMresult CPMWithSummary(IEnumerable <dtoCPMactivity> activities, DateTime?startdate = null, FlagDayOfWeek workweek = FlagDayOfWeek.WorkWeek, IEnumerable <DateTime> exceptions = null, Int32 dailyworkhours = 8, IEnumerable <dtoCPMlink> links = null) { CPMresult result = new CPMresult(); Dictionary <Int64, dtoCPMactivity> dict = new Dictionary <long, dtoCPMactivity>(); // activities = PreprocessSummaryMilestones(activities.ToList()).AsEnumerable(); foreach (var act in activities) { dict.Add(act.Id, act); } result.Activities = activities.ToList(); if (!result.Activities.Where(x => x.Id == -1).Any()) { dtoCPMactivity vActivity = new dtoCPMactivity(-1, "end") { Duration = 0, IsVirtual = true }; result.Activities.Add(vActivity); dict.Add(-1, vActivity); CPMExtensions.ParseActivityLinks(-1, "*", dict); } result.Activities.Where(x => x.IsSummary == false).CriticalPathMethod(); //result.Activities.CriticalPathMethod(); if (result.Activities.Where(x => x.IsSummary).Any()) { var list = result.Activities.Reverse(); foreach (var item in list) { if (item.IsSummary) { item.EarlyStart = item.Children.Min(x => x.EarlyStart); item.EarlyFinish = item.Children.Max(x => x.EarlyFinish); item.LatestStart = item.Children.Min(x => x.LatestStart); item.LatestFinish = item.Children.Max(x => x.LatestFinish); item.Duration = item.EarlyFinish - item.EarlyStart; } } //result.Activities.Where(x => x.IsSummary == false).CriticalPathMethod(); } result.ProjectLength = activities.CriticalPathLength(); if (startdate != null && startdate.HasValue) { result.AvailableDates = startdate.Value.GenerateAvailableDates(result.ProjectLength, workweek, exceptions).ToList(); result.Activities.CalculateDate(result.AvailableDates, dailyworkhours); result.ProjectStartDate = startdate; result.ProjectEndDate = result.Activities.CriticalPathEnd(); result.isDeadlined = result.Activities.isDeadlined(); result.DeadlinedActivities = result.Activities.DeadlinedActivities().ToList(); } result.Critical = activities.CriticalPath().ToList(); result.Activities = result.Activities.Where(x => x.Id > 0).ToList(); foreach (var item in result.Activities) { //todo check if it's correct item.Successors = item.Successors.Where(x => x.isVirtual == false).ToList(); } //todo remove virtual links and activities return(result); }
public static IEnumerable <DateTime> GenerateAvailableDates(this DateTime startdate, double projectlenght, FlagDayOfWeek week = FlagDayOfWeek.AllWeek, IEnumerable <DateTime> exceptions = null) { List <DateTime> available = new List <DateTime>(); DateTime firstdate = startdate; while (firstdate.isExceptionDate(week, exceptions)) { firstdate = firstdate.AddDays(1); } available.Add(firstdate); while (available.Count() <= projectlenght) { DateTime next = available.Last().AddDays(1); while (next.isExceptionDate(week, exceptions)) { next = next.AddDays(1); } available.Add(next); } return(available); }
public static Boolean IsInFlagDayOfWeek(this DayOfWeek dow, FlagDayOfWeek week) { return((dow.ToFlagDayOfWeek() & week) != FlagDayOfWeek.None); }