public DailyItem FindFreeTime(Time needTime, Time startTime, Time endTime)
        {
            int         timeTheNeed = needTime.TranslateToSec();
            List <Time> timeStart   = new List <Time>();
            List <Time> timeEnd     = new List <Time>();

            foreach (DailyItem daily in dailyItems)
            {
                if (daily.StartTime > startTime && daily.StartTime < endTime)
                {
                    timeStart.Add(daily.StartTime);
                }
                if (daily.EndTime > startTime && daily.EndTime < endTime)
                {
                    timeStart.Add(daily.EndTime);
                }
            }

            if (timeStart.Count == 0 && timeEnd.Count == 0 && timeTheNeed <= endTime - startTime)
            {
                DailyItem di = new DailyItem(new Time(startTime.TranslateToSec()), new Time(startTime.TranslateToSec() + timeTheNeed), "", false);
                return(di);
            }
            foreach (Time time1 in timeEnd)
            {
                foreach (Time time2 in timeStart)
                {
                    if (time2 - startTime >= timeTheNeed)
                    {
                        DailyItem di = new DailyItem(new Time(startTime.TranslateToSec()), new Time(startTime.TranslateToSec() + timeTheNeed), "", false);
                        return(di);
                    }
                    if (endTime - time1 >= timeTheNeed)
                    {
                        DailyItem di = new DailyItem(new Time(time1.TranslateToSec()), new Time(time1.TranslateToSec() + timeTheNeed), "", false);
                        return(di);
                    }
                    if ((time2 - time1) >= timeTheNeed)
                    {
                        DailyItem di = new DailyItem(new Time(time1.TranslateToSec()), new Time(time1.TranslateToSec() + timeTheNeed), "", false);
                        return(di);
                    }
                }
            }
            DailyItem di1 = new DailyItem(new Time(0), new Time(0), "Мы не можем вернуть null, как могли бы в С++", false);

            return(di1);
        }
        public void AddDailyItem(DailyItem dailyItem)
        {
            bool exit = true;

            foreach (DailyItem daily in dailyItems)
            {
                if ((dailyItem.StartTime > daily.StartTime && dailyItem.StartTime < daily.EndTime) || (dailyItem.EndTime > daily.StartTime && dailyItem.EndTime < daily.EndTime))
                {
                    exit = false;
                    break;
                }
            }
            if (exit)
            {
                dailyItems.Add(dailyItem);
            }
            else
            {
                Console.WriteLine("Добавить нельзя");
            }
        }
        public void EditRemoveDailyItem(string info, string infoNew, bool readyness)
        {
            bool      exit = false;
            DailyItem di;

            foreach (DailyItem item in dailyItems)
            {
                if (item.Info == info)
                {
                    di = new DailyItem(item.StartTime, item.EndTime, infoNew, readyness);
                    dailyItems.Remove(item);
                    dailyItems.Add(di);
                    Console.WriteLine("\n Успешно изменено");
                    exit = true;
                    break;
                }
            }
            if (!exit)
            {
                Console.WriteLine("\n Такого задания нету");
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            DailySchedule ds = new DailySchedule()
            {
                Day = "Monday"
            };

            ds.AddDailyItem(new DailyItem(new Time("6:00:00"), new Time("6:15:00"), "Проснуться", false));
            ds.AddDailyItem(new DailyItem(new Time("6:14:00"), new Time("6:40:00"), "Приговить и поесть", false));
            ds.AddDailyItem(new DailyItem(new Time("6:15:00"), new Time("6:40:00"), "Приговить и поесть", false));
            ds.Display();

            ds.RemoveDailyItem("Проснуться");
            ds.Display();

            ds.EditRemoveDailyItem("Приговить и поесть", "Почистить зубы", false);
            ds.Display();

            DailyItem di = ds.FindFreeTime(new Time("2:00:00"), new Time("8:00:00"), new Time("10:00:00"));

            di.Display();

            Console.WriteLine("\n\n\n\n\n             Redo");
            ds.DoRedo().Display();

            DailySchedule ds1 = new DailySchedule()
            {
                Day = "Monday"
            };

            ds.AddDailyItem(new DailyItem(new Time("6:00:00"), new Time("6:15:00"), "Проснуться", false));
            ds1.AddDailyItem(new DailyItem(new Time("6:00:00"), new Time("6:15:00"), "Проснуться", false));
            ds1.AddDailyItem(new DailyItem(new Time("6:15:00"), new Time("6:30:00"), "Приговить", false));
            ds1.AddDailyItem(new DailyItem(new Time("6:15:00"), new Time("6:40:00"), "Поесть", false));
            ds1.AddDailyItem(new DailyItem(new Time("6:40:00"), new Time("6:50:00"), "Почистить зубы", false));
            (ds + ds1).Display();
        }
Exemple #5
0
 public void AddNotReadyItems(DailyItem dailyItem)
 {
     notReadyItems.Add(dailyItem);
 }