Ejemplo n.º 1
0
        public static void FindState()
        {
            Design.Draw();
            var menu = new ConsoleTables.ConsoleTable($"<{buttons["Home"].ToString()}>:Home", $"<{buttons["Read"].ToString()}>:Read note",
                                                      $"<{buttons["Find"].ToString()}>:Find");

            Console.ForegroundColor = menuColor;
            menu.Write();
            Console.SetCursorPosition(0, Console.CursorTop - 1);
            Console.ForegroundColor = Design.textColor;
            Console.WriteLine();
        }
Ejemplo n.º 2
0
        public static void HomeState()
        {
            Design.Draw();
            var menu = new ConsoleTables.ConsoleTable($"<{buttons["Create"].ToString()}>:Create new note", $"<{buttons["ShowAll"].ToString()}>:All notes",
                                                      $"<{buttons["ShowSimple"].ToString()}>:SimpleNotes", $"<{buttons["Find"].ToString()}>:Find", $"<{buttons["Settings"].ToString()}>:Settings");

            Console.ForegroundColor = menuColor;
            menu.Write();
            Console.SetCursorPosition(0, Console.CursorTop - 1);
            Console.ForegroundColor = Design.textColor;
            Console.WriteLine();
        }
Ejemplo n.º 3
0
        //public static void EditState()
        //{
        //    Design.Draw();
        //    Console.ForegroundColor = menuColor;
        //    var menu = new ConsoleTables.ConsoleTable($"<{buttons["Home"].ToString()}>:Home", $"<{buttons["Edit"].ToString()}>:Edit row",
        //        $"<{buttons["Delete"].ToString()}>:Delete row");
        //    menu.Write();
        //    Console.ForegroundColor = Design.textColor;
        //}
        public static void Settings()
        {
            Design.Draw();
            var menu = new ConsoleTables.ConsoleTable($"<{buttons["Home"].ToString()}>:Home",
                                                      $"<{buttons["NextBackColor"].ToString()}>:Next backround color",
                                                      $"<{buttons["PrevBackColor"].ToString()}>:Previous background color",
                                                      $"<{buttons["NextTextColor"].ToString()}>:Next foreground color",
                                                      $"<{buttons["PrevTextColor"].ToString()}>:Previous foreground color");

            Console.ForegroundColor = menuColor;
            menu.Write();
            Console.ForegroundColor = Design.textColor;
        }
Ejemplo n.º 4
0
 public static void CreateNewNote(out int id)
 {
     Design.Draw();
     Console.WriteLine();
     notes.Add(new Note());
     id = notes.Count - 1;
     Console.Write("Name: ");
     notes[id].FirstName = Console.ReadLine();
     Console.Write("LastName: ");
     notes[id].LastName = Console.ReadLine();
     Console.Write("Number: ");
     notes[id].Number = Console.ReadLine();
     Console.Write("Country: ");
     notes[id].Country = Console.ReadLine();
 }
Ejemplo n.º 5
0
        public static void Start()
        {
            Console.BackgroundColor = Design.background;
            Console.ForegroundColor = Design.textColor;
            Console.Clear();
            string decision;

            while (true)
            {
                Console.Write("Enter fullscreen mode: y / n ?" + Environment.NewLine);
                decision = Console.ReadLine().ToLower();
                if (decision == "y" || decision == "yes")
                {
                    Console.Clear();
                    FullScreenMode.Fullscreen();
                    break;
                }
                else if (decision == "n" || decision == "no")
                {
                    if (!sudo)
                    {
                        if (Console.WindowWidth < defaultWidth)
                        {
                            Console.SetWindowSize(defaultWidth, Console.WindowHeight);
                        }
                        if (Console.WindowHeight < defaultHeight)
                        {
                            Console.SetWindowSize(Console.WindowWidth, defaultHeight);
                        }
                    }
                    Console.Clear();
                    break;
                }
                Console.Clear();
            }
            maxLength = (sudo) ? int.MaxValue : Console.WindowWidth / 3 - 9;
            if (!sudo)
            {
                ForbidResize.PleaseDoNotResize();
            }
            Design.Draw();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Initialization.Start();
            //Console.WriteLine("\nLet's create your first note! Press <Enter> and have fun...\n");
            //while (Console.ReadKey().Key != ConsoleKey.Enter) { ClearCurrentConsoleLine(0); }
            currentState = MachineState.Home;
            while (true)
            {
                switch (currentState)
                {
                case MachineState.Home:
                {
                    currentState = MachineState.Home;
                    Menu.HomeState();
                    Console.WriteLine($"You have {notes.Count} notes.\n");
                    MachineState state = currentState;
                    while (true)
                    {
                        ConsoleKey key = Console.ReadKey().Key;
                        ClearCurrentConsoleLine(0);
                        if (key == ConsoleKey.C)
                        {
                            goto case MachineState.Create;
                        }
                        if (key == ConsoleKey.S)
                        {
                            goto case MachineState.ShowAll;
                        }
                        if (key == ConsoleKey.Q)
                        {
                            goto case MachineState.ShowSimple;
                        }
                        if (key == ConsoleKey.F)
                        {
                            goto case MachineState.Find;
                        }
                        if (key == ConsoleKey.P)
                        {
                            goto case MachineState.Settings;
                        }
                    }
                }

                case MachineState.Create:
                {
                    currentState = MachineState.Create;
                    CreateNewNote(out int id);
                    readId = id;
                    goto case MachineState.Read;
                }

                case MachineState.ShowAll:
                {
                    currentState = MachineState.ShowAll;
                    ShowAllNotes();
                    while (true)
                    {
                        ConsoleKey key = Console.ReadKey().Key;
                        if (key == ConsoleKey.Escape)
                        {
                            goto case MachineState.Home;
                        }
                        else if (key == ConsoleKey.R)
                        {
                            if (notes.Count == 0)
                            {
                                Console.Beep();
                                goto case MachineState.Home;
                            }
                            while (true)
                            {
                                Console.Write("Enter note id: ");
                                if (int.TryParse(Console.ReadLine(), out readId))
                                {
                                    if (readId >= 0 && readId < notes.Count)
                                    {
                                        goto case MachineState.Read;
                                    }
                                    else
                                    {
                                        Console.Beep();
                                        ClearCurrentConsoleLine(1);
                                        Console.SetCursorPosition(0, Console.CursorTop - 1);
                                        continue;
                                    }
                                }
                                else
                                {
                                    Console.Beep();
                                    ClearCurrentConsoleLine(1);
                                    Console.SetCursorPosition(0, Console.CursorTop - 1);
                                    continue;
                                }
                            }
                        }
                    }
                }

                case MachineState.ShowSimple:
                {
                    currentState = MachineState.ShowSimple;
                    ShowSimplifiedNotes();
                    while (true)
                    {
                        ConsoleKey key = Console.ReadKey().Key;
                        if (key == ConsoleKey.Escape)
                        {
                            goto case MachineState.Home;
                        }
                        if (key == ConsoleKey.R)
                        {
                            ClearCurrentConsoleLine(1);
                            ClearCurrentConsoleLine(0);
                            if (notes.Count == 0)
                            {
                                Console.Beep();
                                goto case MachineState.Home;
                            }
                            Console.Write("Enter id: ");
                            while (true)
                            {
                                while (!int.TryParse(Console.ReadLine(), out readId))
                                {
                                    ClearCurrentConsoleLine(1);
                                    Console.SetCursorPosition(0, Console.CursorTop - 1);
                                    Console.Write("Enter id: ");
                                    Console.Beep();
                                }
                                if (readId >= 0 && readId < notes.Count)
                                {
                                    goto case MachineState.Read;
                                }
                                Console.Beep();
                                Console.SetCursorPosition(0, Console.CursorTop - 1);
                                ClearCurrentConsoleLine(0);
                                Console.Write("Enter id: ");
                            }
                        }
                    }
                }

                case MachineState.Find:
                {
                    currentState = MachineState.Find;
                    Menu.FindState();
                    Find(out int results);
                    while (true)
                    {
                        ConsoleKey key = Console.ReadKey().Key;
                        if (key == ConsoleKey.Escape)
                        {
                            goto case MachineState.Home;
                        }
                        if (key == ConsoleKey.F)
                        {
                            goto case MachineState.Find;
                        }
                        if (key == ConsoleKey.R)
                        {
                            if (results == 0)
                            {
                                Console.Beep();
                                goto case MachineState.Home;
                            }
                            ClearCurrentConsoleLine(1);
                            ClearCurrentConsoleLine(0);
                            Console.Write("Enter id: ");
                            while (true)
                            {
                                while (!int.TryParse(Console.ReadLine(), out readId))
                                {
                                    ClearCurrentConsoleLine(1);
                                    Console.SetCursorPosition(0, Console.CursorTop - 1);
                                    Console.Write("Enter id: ");
                                    Console.Beep();
                                }
                                if (readId >= 0 && readId < notes.Count)
                                {
                                    goto case MachineState.Read;
                                }
                                Console.Beep();
                                Console.SetCursorPosition(0, Console.CursorTop - 1);
                                ClearCurrentConsoleLine(0);
                                Console.Write("Enter id: ");
                            }
                        }
                    }
                }

                case MachineState.Read:
                {
ReadMarker:
                    currentState = MachineState.Read;
                    ReadNote(notes[readId]);
                    while (true)
                    {
                        ConsoleKey key = Console.ReadKey().Key;
                        ClearCurrentConsoleLine(0);
                        if (key == ConsoleKey.Escape)
                        {
                            goto case MachineState.Home;
                        }
                        if (key == ConsoleKey.E)         // Edit row
                        {
                            Console.Write("Enter row name:");
                            string row     = Console.ReadLine();
                            string rowCopy = row.Trim().ToLower();
                            var    array   = rowCopy.Split(' ');
                            rowCopy = string.Join("", array);
                            switch (rowCopy)
                            {
                            case ("firstname"):
                                notes[readId].FirstName = Console.ReadLine();
                                goto ReadMarker;

                            case ("lastname"):
                                notes[readId].LastName = Console.ReadLine();
                                goto ReadMarker;

                            case ("middlename"):
                                notes[readId].MiddleName = Console.ReadLine();
                                goto ReadMarker;

                            case ("number"):
                                notes[readId].Number = Console.ReadLine();
                                goto ReadMarker;

                            case ("country"):
                                notes[readId].Country = Console.ReadLine();
                                goto ReadMarker;

                            case ("organization"):
                                notes[readId].Organization = Console.ReadLine();
                                goto ReadMarker;

                            case ("job"):
                                notes[readId].Job = Console.ReadLine();
                                goto ReadMarker;

                            case ("birthdate"):
                                notes[readId].Birthday = Console.ReadLine();
                                goto ReadMarker;

                            default:
                                break;
                            }
                            switch (row)
                            {
                            default:
                                try
                                {
                                    notes[readId].additionalNotes[row] = Console.ReadLine();
                                }
                                catch (KeyNotFoundException)
                                {
                                }
                                catch (NullReferenceException)
                                { }
                                goto ReadMarker;
                            }
                        }
                        if (key == ConsoleKey.A)         // Add row
                        {
                            Console.Write("Enter row name: ");
                            string row = Console.ReadLine();
                            try
                            {
                                notes[readId].additionalNotes.Add(row, "");
                            }
                            catch (NullReferenceException)
                            {
                            }
                            catch (ArgumentException)
                            {
                                ClearCurrentConsoleLine(1);
                                Console.ForegroundColor = ConsoleColor.Cyan;
                                Console.WriteLine($"{row} - Such row already exist");
                                Console.ForegroundColor = Design.textColor;
                                System.Threading.Thread.Sleep(2000);
                            }
                        }
                        if (key == ConsoleKey.X)         // Remove row
                        {
                            Console.Write("Enter row name:");
                            string row = Console.ReadLine().Trim().ToLower();
                            if (Note.lockedFields.Contains(row))
                            {
                                Design.Draw();
                                Console.Beep();
                                Console.ForegroundColor = ConsoleColor.Cyan;
                                Console.Write("You can't remove default rows");
                                Console.ForegroundColor = Design.textColor;
                                System.Threading.Thread.Sleep(4000);
                                goto case MachineState.Read;
                            }
                            else
                            {
                                try
                                {
                                    notes[readId].additionalNotes.Remove(row);
                                }
                                catch (Exception)
                                {
                                    Console.Beep();
                                }
                                goto case MachineState.Read;
                            }
                        }
                        if (key == ConsoleKey.D)         // Delete note
                        {
                            goto case MachineState.Delete;
                        }
                        break;
                    }
                    goto case MachineState.Read;
                }

                case MachineState.Delete:
                {
                    currentState = MachineState.Delete;
                    DeleteNote(readId, out bool deleted);
                    if (deleted)
                    {
                        goto case MachineState.Home;
                    }
                    goto case MachineState.Read;
                }

                case MachineState.Settings:
                {
                    currentState = MachineState.Settings;
                    int frontColorNumber = 0;
                    int backColorNumber  = 0;
                    while (true)
                    {
                        if (Design.textColor == Design.background)
                        {
                            Design.background = ConsoleColor.Black;
                            Design.textColor  = ConsoleColor.White;
                        }
                        Menu.Settings();
                        var key = Console.ReadKey().Key;
                        ClearCurrentConsoleLine(0);
                        if (key == ConsoleKey.UpArrow)
                        {
                            backColorNumber = (backColorNumber == 0) ? 16 : backColorNumber;
                            backColorNumber--;
                            Design.background       = Design.colors[backColorNumber];
                            Console.BackgroundColor = Design.colors[backColorNumber];
                        }
                        if (key == ConsoleKey.DownArrow)
                        {
                            backColorNumber = (backColorNumber == 15) ? 0 : backColorNumber;
                            backColorNumber++;
                            Design.background       = Design.colors[backColorNumber];
                            Console.BackgroundColor = Design.colors[backColorNumber];
                        }
                        if (key == ConsoleKey.LeftArrow)
                        {
                            frontColorNumber = (frontColorNumber == 0) ? 16 : frontColorNumber;
                            frontColorNumber--;
                            Design.textColor        = Design.colors[frontColorNumber];
                            Console.ForegroundColor = Design.colors[frontColorNumber];
                        }
                        if (key == ConsoleKey.RightArrow)
                        {
                            frontColorNumber = (frontColorNumber == 15) ? 0 : frontColorNumber;
                            frontColorNumber++;
                            Design.textColor        = Design.colors[frontColorNumber];
                            Console.ForegroundColor = Design.colors[frontColorNumber];
                        }
                        if (key == ConsoleKey.Escape)
                        {
                            goto case MachineState.Home;
                        }
                    }
                }

                default:
                    Console.Clear();
                    goto case MachineState.Home;
                }
            }
        }