示例#1
0
        public static bool AddDeadCard(string[] com)
        {
            if (com.Length < 8)
            {
                return(false);
            }
            if (com[0] != "add")
            {
                return(false);
            }
            if (com[1] != "deadcard")
            {
                return(false);
            }
            DateTime startDt, endDt;
            string   firstPart;

            if (com[2] == "null")
            {
                firstPart = "0:0:0";
            }
            else
            {
                firstPart = com[2];
            }
            bool ok = Schedule.DateTimeFromString(firstPart + "-" + com[3], out startDt);

            if (!ok)
            {
                Conzole.PrintLine("Your date/time is incorrect!", ConsoleColor.Red);
                return(false);
            }
            if (com[4] == "null")
            {
                firstPart = "0:0:0";
            }
            else
            {
                firstPart = com[4];
            }
            ok = Schedule.DateTimeFromString(firstPart + "-" + com[5], out endDt);
            if (!ok)
            {
                Conzole.PrintLine("Your date/time is incorrect!", ConsoleColor.Red);
                return(false);
            }
            Card card = new Card();

            card.start    = startDt;
            card.end      = endDt;
            card.title    = com[6];
            card.content  = "";
            card.category = com[7];
            Schedule.cards.Add(card);
            Schedule.cards.Write();
            Deadline deadline = new Deadline();

            deadline.deadline = startDt;
            deadline.title    = com[6];
            deadline.category = com[7];
            Schedule.deadlines.Add(deadline);
            Schedule.deadlines.Write();
            Conzole.PrintLine("Succes", ConsoleColor.Magenta);
            return(true);
        }
示例#2
0
        public static bool ListDeadlines(string[] com)
        {
            if (com.Length < 2)
            {
                return(false);
            }
            if (com[0] != "list")
            {
                return(false);
            }
            if (com[1] != "deadlines")
            {
                return(false);
            }
            DeadlineFile df    = Schedule.deadlines;
            DateTime     limit = DateTime.MaxValue;

            if (com.Length >= 3 && com[2] == "archive")
            {
                df = Schedule.deadlinesArchive;
            }
            else if (com.Length >= 3 && com[2] == "past")
            {
                limit = DateTime.Now.AddSeconds(-1);
            }
            else if (com.Length >= 3)
            {
                limit = Logic.Limit(com[2]);
            }
            if (df.Size() == 0)
            {
                Conzole.PrintLine("No deadlines to show!", ConsoleColor.Magenta);
                return(false);
            }
            Conzole.PrintLine("Deadlines: ", ConsoleColor.Magenta);
            List <Deadline> dls = new List <Deadline>();

            for (int i = 0; i < df.Size(); i++)
            {
                Deadline d = df.Get(i);
                if (d.deadline <= limit)
                {
                    dls.Add(d);
                }
            }
            dls.Sort((p, q) => p.SecondsLeft().CompareTo(q.SecondsLeft()));
            for (int i = 0; i < dls.Count; i++)
            {
                Deadline l = dls[i];
                Conzole.Print(Schedule.StrDateTime(l.deadline) + " - ", ConsoleColor.Yellow);
                string msg  = "";
                int    left = l.SecondsLeft();
                int    abs  = Math.Abs(left);
                int    min  = 60;
                int    hour = min * 60;
                int    day  = hour * 24;
                if (abs < min * 5)
                {
                    msg = Conzole.PadBefore(abs + "", 4) + " seconds - ";
                }
                else if (abs < hour)
                {
                    msg = Conzole.PadBefore("" + (abs / min), 4) + " minutes - ";
                }
                else if (abs < day * 2)
                {
                    msg = Conzole.PadBefore("" + (abs / hour), 4) + " hours   - ";
                }
                else
                {
                    msg = Conzole.PadBefore("" + (abs / day), 4) + " days    - ";
                }
                if (left > 0)
                {
                    msg = "Left: " + msg;
                }
                else
                {
                    msg = "Past: " + msg;
                }
                ConsoleColor colour;
                if (left > 0)
                {
                    colour = ConsoleColor.White;
                }
                else
                {
                    colour = ConsoleColor.Red;
                }
                Conzole.Print(msg, colour);
                Conzole.Print(Conzole.PadAfter(l.title, 50) + " - ", ConsoleColor.Green);
                Conzole.Print(Conzole.PadAfter(l.category, 20) + "\n", ConsoleColor.Green);
            }
            return(true);
        }