Ejemplo n.º 1
0
        public static bool ListTimeSlots(string[] com)
        {
            if (com.Length < 2)
            {
                return(false);
            }
            if (com[0] != "list")
            {
                return(false);
            }
            if (com[1] != "timeslots")
            {
                return(false);
            }
            TimeSlotFile cf = Schedule.timeslots;

            if (com.Length >= 3 && com[2] == "archive")
            {
                cf = Schedule.timeslotsArchive;
            }
            Conzole.PrintLine("Found " + cf.Size() + " timeslots.", ConsoleColor.Magenta);
            for (int i = 0; i < cf.Size(); i++)
            {
                TimeSlot ts = cf.Get(i);
                Conzole.Print(Conzole.PadBefore(ts.startSec + ":" + ts.startMin + ":" + ts.startHou + " >> ", 12), ConsoleColor.Yellow);
                Conzole.Print(Conzole.PadBefore(ts.endSec + ":" + ts.endMin + ":" + ts.endHou, 8), ConsoleColor.Yellow);
                Conzole.Print(" - " + Conzole.PadAfter(ts.name, 50));
                Conzole.Print("\n");
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static bool AddDeadline(string[] com)
        {
            if (com.Length < 6)
            {
                return(false);
            }
            if (com[0] != "add")
            {
                return(false);
            }
            if (com[1] != "deadline")
            {
                return(false);
            }
            DateTime dt;
            bool     ok = Schedule.DateTimeFromString(com[2] + "-" + com[3], out dt);

            if (!ok)
            {
                Conzole.PrintLine("Your date/time is incorrect!", ConsoleColor.Red);
                return(false);
            }
            Deadline dl = new Deadline();

            dl.deadline = dt;
            dl.title    = com[4];
            dl.category = com[5];
            Schedule.deadlines.Add(dl);
            Schedule.deadlines.Write();
            Conzole.PrintLine("Succes!", ConsoleColor.Magenta);
            return(true);
        }
Ejemplo n.º 3
0
 private void PrintCommand(string[] command)
 {
     for (int i = 0; i < command.Length; i++)
     {
         Conzole.Print("\"" + command[i] + "\" ");
     }
     Conzole.PrintLine("");
 }
Ejemplo n.º 4
0
        //add card startTime startDate endTime endDate title category
        public static bool AddCard(string[] com)
        {
            if (com.Length < 8)
            {
                return(false);
            }
            if (com[0] != "add")
            {
                return(false);
            }
            if (com[1] != "card")
            {
                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();
            Conzole.PrintLine("Succes", ConsoleColor.Magenta);
            return(true);
        }
Ejemplo n.º 5
0
 public static bool Time(string[] com)
 {
     if (com[0] != "time")
     {
         return(false);
     }
     Conzole.PrintLine(Schedule.StrTime(DateTime.Now));
     return(true);
 }
Ejemplo n.º 6
0
        public static bool DeleteCard(string[] com)
        {
            if (com.Length < 4)
            {
                return(false);
            }
            if (com[0] != "delete")
            {
                return(false);
            }
            if (com[1] != "card")
            {
                return(false);
            }
            DateTime origDt;
            Card     card;
            int      deadlineIndex;
            bool     found = false;
            string   firstPart;

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

            if (!ok)
            {
                Conzole.PrintLine("Your date/time is incorrect!", ConsoleColor.Red);
                return(false);
            }
            found = Schedule.cards.Get(origDt, com[2] == "null", out card, out deadlineIndex);
            if (!found)
            {
                Conzole.PrintLine("Could not find card!", ConsoleColor.Red);
                return(false);
            }
            Conzole.PrintLine("Deleting card " + card.title + ".", ConsoleColor.Magenta);
            bool sure = Conzole.AreYouSure();

            if (!sure)
            {
                Conzole.PrintLine("Did not delete anything.", ConsoleColor.Magenta);
                return(false);
            }
            Schedule.cardsArchive.Add(card);
            Schedule.cardsArchive.Write();
            Schedule.cards.Delete(card);
            Schedule.cards.Write();
            Conzole.PrintLine("Succes!", ConsoleColor.Magenta);
            return(true);
        }
Ejemplo n.º 7
0
 public static bool Now(string[] com)
 {
     if (com[0] != "now")
     {
         return(false);
     }
     Conzole.PrintLine(Schedule.StrDateTime(DateTime.Now));
     Schedule.deadlines.Write();
     return(true);
 }
Ejemplo n.º 8
0
        public static bool HelpMe(string[] com)
        {
            if (com.Length < 1)
            {
                return(false);
            }
            if (com[0] != "help")
            {
                return(false);
            }
            if (com.Length == 1)
            {
                Conzole.PrintLine("Help: ", ConsoleColor.Magenta);
                Conzole.PrintLine("Type in \"help [command]\" to find help about a command.");
                Conzole.PrintLine("Type in \"help syntax\" to find help about the syntax in help.");
                Conzole.PrintLine("Commands: ");
                Conzole.Enlist(commands);
                return(true);
            }
            if (com[1] == "syntax")
            {
                Conzole.PrintLine("Syntax help: ", ConsoleColor.Magenta);
                Conzole.PrintLine(syntaxmsg);
                return(true);
            }
            int    index   = 0;
            bool   found   = false;
            string command = com[1];

            if (command.Length >= 3)
            {
                for (int i = 2; i < com.Length; i++)
                {
                    command += " " + com[i];
                }
            }
            for (int i = 0; i < commands.Length; i++)
            {
                if (commands[i] == command)
                {
                    index = i;
                    found = true;
                    break;
                }
            }
            if (found && index < syntax.Length)
            {
                Conzole.PrintLine("Syntax: ", ConsoleColor.Magenta);
                Conzole.PrintLine(syntax[index]);
            }
            return(true);
        }
Ejemplo n.º 9
0
        public static bool CleanCards(string[] com)
        {
            if (com.Length < 2)
            {
                return(false);
            }
            if (com[0] != "clean")
            {
                return(false);
            }
            if (com[1] != "cards")
            {
                return(false);
            }
            Conzole.PrintLine("Deleting all cards that are past.");
            bool ok = Conzole.AreYouSure();

            if (!ok)
            {
                Conzole.PrintLine("Did not delete anything.", ConsoleColor.Magenta);
                return(true);
            }
            DateTime    limit = DateTime.Now.AddSeconds(-1);
            CardFile    cf    = Schedule.cards;
            List <Card> dls   = new List <Card>();

            for (int i = 0; i < cf.Size(); i++)
            {
                Card c = cf.Get(i);
                if (c.end <= limit)
                {
                    dls.Add(c);
                }
            }
            for (int i = 0; i < dls.Count; i++)
            {
                Schedule.cardsArchive.Add(dls[i]);
                cf.Delete(dls[i]);
            }
            Schedule.cardsArchive.Write();
            cf.Write();
            Conzole.PrintLine("Succes!", ConsoleColor.Magenta);
            return(false);
        }
Ejemplo n.º 10
0
        public static bool CleanDeadlines(string[] com)
        {
            if (com.Length < 2)
            {
                return(false);
            }
            if (com[0] != "clean")
            {
                return(false);
            }
            if (com[1] != "deadlines")
            {
                return(false);
            }
            Conzole.PrintLine("Deleting all deadlines that are past.");
            bool ok = Conzole.AreYouSure();

            if (!ok)
            {
                Conzole.PrintLine("Did not delete anything.", ConsoleColor.Magenta);
                return(true);
            }
            DateTime        limit = DateTime.Now.AddSeconds(-1);
            DeadlineFile    df    = Schedule.deadlines;
            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);
                }
            }
            for (int i = 0; i < dls.Count; i++)
            {
                Schedule.deadlinesArchive.Add(dls[i]);
                df.Delete(dls[i]);
            }
            Schedule.deadlinesArchive.Write();
            df.Write();
            Conzole.PrintLine("Succes!", ConsoleColor.Magenta);
            return(false);
        }
Ejemplo n.º 11
0
        public static bool AddTimeSlot(string[] com)
        {
            if (com.Length < 5)
            {
                return(false);
            }
            if (com[0] != "add")
            {
                return(false);
            }
            if (com[1] != "timeslot")
            {
                return(false);
            }
            DateTime startDt, endDt;
            bool     ok = Schedule.TimeFromString(com[2], out startDt);

            if (!ok)
            {
                Conzole.PrintLine("Your date/time is incorrect!", ConsoleColor.Red);
                return(false);
            }
            ok = Schedule.TimeFromString(com[3], out endDt);
            if (!ok)
            {
                Conzole.PrintLine("Your date/time is incorrect!", ConsoleColor.Red);
                return(false);
            }
            TimeSlot slot = new TimeSlot();

            slot.startSec = startDt.Second;
            slot.startMin = startDt.Minute;
            slot.startHou = startDt.Hour;
            slot.endSec   = endDt.Second;
            slot.endMin   = endDt.Minute;
            slot.endHou   = endDt.Hour;
            slot.name     = com[4];
            Schedule.timeslots.Add(slot);
            Schedule.timeslots.Write();
            Conzole.PrintLine("Succes", ConsoleColor.Magenta);
            return(true);
        }
Ejemplo n.º 12
0
        public static bool ShowDay(string[] com)
        {
            if (com.Length < 2)
            {
                return(false);
            }
            if (com[0] != "show")
            {
                return(false);
            }
            if (com[1] != "day")
            {
                return(false);
            }
            int w = 120, h = 50;

            char[,] view = new char[w, h];
            for (int i = 0; i < w; i++)
            {
                view[i, 0] = '#';
            }
            for (int i = 0; i < w; i++)
            {
                view[i, h - 1] = '#';
            }
            for (int i = 1; i < h; i++)
            {
                view[0, i] = '#';
            }
            for (int i = 1; i < h; i++)
            {
                view[w - 1, i] = '#';
            }

            Conzole.PrintGrid(view);
            return(true);
        }
Ejemplo n.º 13
0
        public static bool DeleteTimeSlot(string[] com)
        {
            if (com.Length < 3)
            {
                return(false);
            }
            if (com[0] != "delete")
            {
                return(false);
            }
            if (com[1] != "timeslot")
            {
                return(false);
            }
            TimeSlot slot;
            bool     found = Schedule.timeslots.Get(com[2], out slot);

            if (!found)
            {
                Conzole.PrintLine("Could not find timeslot!", ConsoleColor.Red);
                return(false);
            }
            Conzole.PrintLine("Deleting timeslot " + slot.name + ".", ConsoleColor.Magenta);
            bool sure = Conzole.AreYouSure();

            if (!sure)
            {
                Conzole.PrintLine("Did not delete anything.", ConsoleColor.Magenta);
                return(false);
            }
            Schedule.timeslotsArchive.Add(slot);
            Schedule.timeslotsArchive.Write();
            Schedule.timeslots.Delete(slot);
            Schedule.timeslots.Write();
            Conzole.PrintLine("Succes!", ConsoleColor.Magenta);
            return(true);
        }
Ejemplo n.º 14
0
        private void AskCommand()
        {
            Conzole.Print("[CONSOLE]:: ", ConsoleColor.Cyan);
            byte[] inputBuffer = new byte[2048];
            Stream inputStream = Console.OpenStandardInput(inputBuffer.Length);

            Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length));
            string raw = Console.ReadLine();

            raw = raw.ToLower();
            if (raw == "exit")
            {
                return;
            }
            if (raw == "clear")
            {
                Console.Clear();
                Introduce();
                AskCommand();
                return;
            }
            if (raw == "")
            {
                AskCommand();
                return;
            }
            string[] command = ExtractCommand(raw);
            for (int i = 0; i < executes.Count; i++)
            {
                if (executes[i](command))
                {
                    break;
                }
            }
            AskCommand();
        }
Ejemplo n.º 15
0
        public Interperter()
        {
            executes = new List <Func <string[], bool> >();
            executes.Add(Help.HelpMe);
            executes.Add(Executes.Now);
            executes.Add(Executes.Date);
            executes.Add(Executes.Time);
            executes.Add(Executes.ShowDay);

            executes.Add(Executes.ListDeadlines);
            executes.Add(Executes.AddDeadline);
            executes.Add(Executes.DeleteDeadline);
            executes.Add(Executes.EditDeadline);
            executes.Add(Executes.CleanDeadlines);

            executes.Add(Executes.ListCards);
            executes.Add(Executes.AddCard);
            executes.Add(Executes.DeleteCard);
            executes.Add(Executes.EditCard);
            executes.Add(Executes.InspectCard);
            executes.Add(Executes.CleanCards);

            executes.Add(Executes.AddDeadCard);
            executes.Add(Executes.DeleteDeadCard);

            executes.Add(Executes.ListTimeSlots);
            executes.Add(Executes.AddTimeSlot);
            executes.Add(Executes.DeleteTimeSlot);

            executes.Add(SequentialPlannerWizard.Run);
            //run the app
            Conzole.SetDimensions(120, 2000);
            Conzole.SetColour(ConsoleColor.Green);
            Introduce();
            AskCommand();
        }
Ejemplo n.º 16
0
        public static bool Run(string[] com)
        {
            if (com[0] != "run")
            {
                return(false);
            }
            if (com[1] != "sequentialplanner")
            {
                return(false);
            }
            Conzole.PrintLine("Welcome to the Sequential Planner Wizard.", ConsoleColor.Magenta);
            Conzole.PrintLine("Type \"exit\" to quit this wizard.", ConsoleColor.Magenta);
            string   s;
            DateTime dt;
            bool     ok = false;

            while (true)
            {
                Conzole.PrintLine("Enter the first day: ", ConsoleColor.Magenta);
                Conzole.Print("[SequentialPlanner]:: ", ConsoleColor.Cyan);
                s = Console.ReadLine();
                if (s == "exit")
                {
                    return(true);
                }
                ok = Schedule.DateFromString(s, out dt);
                if (ok)
                {
                    break;
                }
                Conzole.PrintLine("Could not convert to correct datetime!", ConsoleColor.Red);
            }
            Conzole.PrintLine("You can use the commands: ", ConsoleColor.Magenta);
            Conzole.PrintLine("exit // exit this wizard.", ConsoleColor.Magenta);
            Conzole.PrintLine("add <s:timeslotname> <s:name> <s:category> // add a event on current day at timeslot.", ConsoleColor.Magenta);
            Conzole.PrintLine("next // increment day.", ConsoleColor.Magenta);
            Conzole.PrintLine("skip <n:x> // increment x days.", ConsoleColor.Magenta);
            Conzole.PrintLine("save // save the planned events and exit.");
            while (true)
            {
                Conzole.PrintLine("Current date: " + Schedule.StrDateTime(dt), ConsoleColor.Yellow);
                Conzole.Print("[SequentialPlanner]:: ", ConsoleColor.Cyan);
                s = Console.ReadLine();
                if (s == "exit")
                {
                    return(true);
                }
                if (s == "save")
                {
                    break;
                }
                if (s == "next")
                {
                    dt = dt.AddDays(1);
                }
                else
                {
                    string[] lcoms = Interperter.ExtractCommand(s);
                    if (lcoms.Length == 0)
                    {
                        continue;
                    }
                    if (lcoms[0] == "skip" && lcoms.Length == 2)
                    {
                        int i = 0;
                        int.TryParse(lcoms[1], out i);
                        if (i <= 1)
                        {
                            continue;
                        }
                        dt = dt.AddDays(i);
                    }
                    else if (lcoms[0] == "add" && lcoms.Length == 4)
                    {
                        TimeSlot ts;
                        ok = Schedule.timeslots.Get(lcoms[1], out ts);
                        if (!ok)
                        {
                            Conzole.PrintLine("Could not find timeslot: " + lcoms[1], ConsoleColor.Red);
                            continue;
                        }
                        DateTime start = ts.StartToDateTime(dt);
                        DateTime end   = ts.EndToDateTime(dt);
                        Card     card  = new Card();
                        card.start    = start;
                        card.end      = end;
                        card.title    = lcoms[2];
                        card.category = lcoms[3];
                        card.content  = "";
                        Schedule.cards.Add(card);
                        Conzole.PrintLine("Card added.", ConsoleColor.Magenta);
                    }
                }
            }
            Schedule.cards.Write();
            Conzole.PrintLine("All cards saved!", ConsoleColor.Yellow);
            return(true);
        }
Ejemplo n.º 17
0
 private void Introduce()
 {
     Conzole.PrintLine("Personal Planner.", ConsoleColor.Cyan);
     Conzole.PrintLine("Made by Cody Bloemhard.", ConsoleColor.Cyan);
     Conzole.PrintLine("type \"help\" and press enter for help.", ConsoleColor.Cyan);
 }
Ejemplo n.º 18
0
        //edit deadline oTime oDate atribute nVal/nTime (nDate)
        public static bool EditDeadline(string[] com)
        {
            if (com.Length < 6)
            {
                return(false);
            }
            if (com[0] != "edit")
            {
                return(false);
            }
            if (com[1] != "deadline")
            {
                return(false);
            }
            DateTime origDt;
            Deadline deadline;
            int      deadlineIndex;
            bool     found = false;
            string   firstPart;

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

            if (!ok)
            {
                Conzole.PrintLine("Your date/time is incorrect!", ConsoleColor.Red);
                return(false);
            }
            found = Schedule.deadlines.Get(origDt, com[2] == "null", out deadline, out deadlineIndex);
            if (!found)
            {
                Conzole.PrintLine("Deadline not found!", ConsoleColor.Red);
                return(false);
            }
            if (!(com[4] == "deadline" || com[4] == "title" ||
                  com[4] == "category"))
            {
                Conzole.PrintLine("Atribute not found!", ConsoleColor.Red);
                Conzole.PrintLine("Atributes: deadline, title, category.", ConsoleColor.Red);
                return(false);
            }
            if (com[4] == "deadline")
            {
                if (com.Length < 7)
                {
                    Conzole.PrintLine("Not enough arguments! Give a new time and date!", ConsoleColor.Red);
                    return(false);
                }
                DateTime dt;
                ok = Schedule.DateTimeFromString(com[5] + "-" + com[6], out dt);
                if (!ok)
                {
                    Conzole.PrintLine("Your date/time is incorrect!", ConsoleColor.Red);
                    return(false);
                }
                deadline.deadline = dt;
            }
            else if (com[4] == "title")
            {
                deadline.title = com[5];
            }
            else if (com[4] == "category")
            {
                deadline.category = com[5];
            }
            Schedule.deadlines.Edit(deadlineIndex, deadline);
            Schedule.deadlines.Write();
            Conzole.PrintLine("Succes!", ConsoleColor.Magenta);
            return(true);
        }
Ejemplo n.º 19
0
        public static bool ListCards(string[] com)
        {
            if (com.Length < 2)
            {
                return(false);
            }
            if (com[0] != "list")
            {
                return(false);
            }
            if (com[1] != "cards")
            {
                return(false);
            }
            CardFile cf       = Schedule.cards;
            DateTime limit    = DateTime.MaxValue;
            int      argIndex = 2;

            if (com.Length >= 3)
            {
                if (com[2] == "archive")
                {
                    cf       = Schedule.cardsArchive;
                    argIndex = 3;
                }
                else if (com[2] == "past")
                {
                    limit    = DateTime.Now.AddSeconds(-1);
                    argIndex = 3;
                }
                else
                {
                    limit = Logic.Limit(com[2]);
                }
            }
            uint count;

            if (com.Length == argIndex + 1 && limit == DateTime.MaxValue)
            {
                bool ok = uint.TryParse(com[argIndex], out count);
                if (!ok)
                {
                    Conzole.PrintLine("Could not convert \"" + com[argIndex] + "\" to a uint.", ConsoleColor.Red);
                    return(false);
                }
            }
            else
            {
                count = 0;
            }
            List <Card> cards = new List <Card>();

            for (int i = 0; i < cf.Size(); i++)
            {
                Card c = cf.Get(i);
                if (c.start <= limit)
                {
                    cards.Add(c);
                }
            }
            cards.Sort((p, q) => p.start.CompareTo(q.end));
            int max = cards.Count;

            if (count == 0)
            {
                count = (uint)max;
            }
            if (count > max)
            {
                count = (uint)max;
            }
            Conzole.PrintLine("Found " + count + " cards.", ConsoleColor.Magenta);
            for (int i = 0; i < count; i++)
            {
                Card c = cards[i];
                Conzole.Print(Schedule.StrDateTime(c.start) + " >> ", ConsoleColor.Yellow);
                Conzole.Print(Schedule.StrDateTime(c.end) + " - ", ConsoleColor.Yellow);
                string       msg;
                bool         notPast = Logic.GetDayMessage(c.start, out msg);
                ConsoleColor col     = notPast ? ConsoleColor.White : ConsoleColor.Red;
                Conzole.Print(msg + " - ", col);
                Conzole.Print(Conzole.PadAfter(c.title, 30) + " - ");
                Conzole.Print(Conzole.PadAfter(c.category, 20));
                Conzole.Print("\n");
            }
            return(true);
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        public static bool EditCard(string[] com)
        {
            if (com.Length < 6)
            {
                return(false);
            }
            if (com[0] != "edit")
            {
                return(false);
            }
            if (com[1] != "card")
            {
                return(false);
            }
            DateTime origDt;
            Card     card;
            int      deadlineIndex;
            bool     found = false;
            string   firstPart;

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

            if (!ok)
            {
                Conzole.PrintLine("Your date/time is incorrect!", ConsoleColor.Red);
                return(false);
            }
            found = Schedule.cards.Get(origDt, com[2] == "null", out card, out deadlineIndex);
            if (!found)
            {
                Conzole.PrintLine("Card not found!", ConsoleColor.Red);
                return(false);
            }
            if (!(com[4] == "start" || com[4] == "end" ||
                  com[4] == "title" || com[4] == "category" ||
                  com[4] == "content"))
            {
                Conzole.PrintLine("Atribute not found!", ConsoleColor.Red);
                Conzole.PrintLine("Atributes: start, end, title, category, content.", ConsoleColor.Red);
                return(false);
            }
            if (com[4] == "start" || com[4] == "end")
            {
                if (com.Length < 7)
                {
                    Conzole.PrintLine("Not enough arguments! Give a new time and date!", ConsoleColor.Red);
                    return(false);
                }
                DateTime dt;
                ok = Schedule.DateTimeFromString(com[5] + "-" + com[6], out dt);
                if (!ok)
                {
                    Conzole.PrintLine("Your date/time is incorrect!", ConsoleColor.Red);
                    return(false);
                }
                if (com[4] == "start")
                {
                    card.start = dt;
                }
                else
                {
                    card.end = dt;
                }
            }
            else if (com[4] == "title")
            {
                card.title = com[5];
            }
            else if (com[4] == "category")
            {
                card.category = com[5];
            }
            else if (com[4] == "content")
            {
                card.content  = "";
                card.content += com[5];
                if (com.Length >= 7)
                {
                    for (int i = 6; i < com.Length; i++)
                    {
                        card.content += " " + com[i];
                    }
                }
            }
            Schedule.cards.Edit(deadlineIndex, card);
            Schedule.cards.Write();
            Conzole.PrintLine("Succes", ConsoleColor.Magenta);
            return(true);
        }
Ejemplo n.º 22
0
        public static bool InspectCard(string[] com)
        {
            if (com.Length < 3)
            {
                return(false);
            }
            if (com[0] != "inspect")
            {
                return(false);
            }
            if (com[1] != "card")
            {
                return(false);
            }
            DateTime dt;
            string   firstPart;

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

            if (!ok)
            {
                Conzole.PrintLine("Your date/time is incorrect!", ConsoleColor.Red);
                return(false);
            }
            Card card;
            int  index = 0;
            bool found = Schedule.cards.Get(dt, com[2] == "null", out card, out index);

            if (!found)
            {
                Conzole.PrintLine("Card not found", ConsoleColor.Red);
                return(false);
            }
            Conzole.Print("Title: ", ConsoleColor.Magenta);
            Conzole.PrintLine(Conzole.PadAfter(card.title, 100));
            Conzole.Print("Category: ", ConsoleColor.Magenta);
            Conzole.PrintLine(Conzole.PadAfter(card.category, 97));
            Conzole.Print("Start: ", ConsoleColor.Magenta);
            Conzole.PrintLine(Schedule.StrDateTime(card.start), ConsoleColor.Yellow);
            Conzole.Print("End: ", ConsoleColor.Magenta);
            Conzole.PrintLine(Schedule.StrDateTime(card.end), ConsoleColor.Yellow);
            Conzole.Print("Day: ", ConsoleColor.Magenta);
            Conzole.PrintLine(card.start.DayOfWeek.ToString());
            Conzole.Print("Relativeness: ", ConsoleColor.Magenta);
            string       msg;
            bool         notPast = Logic.GetDayMessage(card.start, out msg);
            ConsoleColor col     = notPast ? ConsoleColor.White : ConsoleColor.Red;

            Conzole.PrintLine(msg, col);
            TimeSpan res = card.end - card.start;

            Conzole.Print("Duration: ", ConsoleColor.Magenta);
            Conzole.PrintLine(res.Hours + " hours, " + res.Minutes + " minutes and " + res.Seconds + " seconds.", ConsoleColor.Yellow);
            Conzole.PrintLine("Content: ", ConsoleColor.Magenta);
            Conzole.PrintLine(card.content);
            return(true);
        }