Пример #1
0
        public static ArrayList FiguresInfo()
        {
            ArrayList all = new ArrayList();

            all.AddRange(ReadFiguresFromDB.ReadAllTriangles(connect));
            all.AddRange(ReadFiguresFromDB.ReadAllSquares(connect));
            all.AddRange(ReadFiguresFromDB.ReadAllRectangles(connect));
            all.AddRange(ReadFiguresFromDB.ReadAllRhombs(connect));
            all.AddRange(ReadFiguresFromDB.ReadAllParallelograms(connect));
            all.AddRange(ReadFiguresFromDB.ReadAllCubes(connect));
            all.AddRange(ReadFiguresFromDB.ReadAllPrisms(connect));
            all.AddRange(ReadFiguresFromDB.ReadAllParallelepipeds(connect));
            all.AddRange(ReadFiguresFromDB.ReadAllPyramids(connect));

            return(all);
        }
Пример #2
0
        public static void SelectFigure(DataBase db, int figure)
        {
            switch (figure)
            {
            case 1:
                string name, type;
                double a, area, perim;
                int    tops, edges;

                Console.Clear();
                Console.WriteLine("1 - Add new square in the table:");
                Console.WriteLine("2 - Show all squares from the table");
                Console.WriteLine("3 - Edit square by Id");
                Console.WriteLine("4 - Delete square by Id");
                Console.WriteLine("5 - Return back");
                Console.Write("\nPlease make your choice..");
                int choice1 = int.Parse(Console.ReadLine());
                switch (choice1)
                {
                case 1:
                    Console.Clear();
                    Square sq = SetSquare(out name, out type, out a, out area, out perim, out tops, out edges);
                    try
                    {
                        result = db.Add($"Insert into Squares([Name],[Type],[A],[Area],[Perimeter],[Tops],[Edges])" +
                                        $"values('{name}','{type}','{a}','{area}','{perim}','{tops}','{edges}')");

                        Console.ForegroundColor = (result == "Insert was Successfull!Congratulations!!!") ? ConsoleColor.Green : ConsoleColor.Red;
                        Console.WriteLine(result);
                        Console.ResetColor();
                        Pause();
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    break;

                case 2:
                    Console.Clear();
                    string        conn = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
                    List <Square> list = ReadFiguresFromDB.ReadAllSquares(conn);
                    for (int i = 0; i < list.Count; i++)
                    {
                        Console.WriteLine(new string('-', 120));
                        Console.ForegroundColor = ConsoleColor.DarkYellow;
                        Console.WriteLine($"\n{i + 1} Square:\n");
                        Console.ForegroundColor = RandColors()[rand.Next(0, 5)];
                        Console.WriteLine(list[i]);
                        Console.ResetColor();
                        Console.WriteLine("\n" + new string('-', 120));
                    }
                    Pause();
                    break;

                case 3:
                    Console.Write("Enter any id of square to Update: ");
                    int editId = int.Parse(Console.ReadLine());

                    Square editSq = SetSquare(out name, out type, out a, out area, out perim, out tops, out edges);

                    string editQuery = $"Update Squares SET Name='{name}',Type='{type}',A='{a}', Area='{area}', Perimeter='{perim}' where Id={editId}";
                    try
                    {
                        resultInt = db.Update(editQuery);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    if (resultInt == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nSquare has updated successfully!!!");
                        Console.ResetColor();
                        Pause();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"\nThe method of Update() return {resultInt}\nSomething went wrong...Try to fix this!");
                        Console.ResetColor();
                        Pause();
                    }
                    break;

                case 4:
                    Console.Write("Enter any id of square to Delete from the table: ");
                    int    deleteId = int.Parse(Console.ReadLine());
                    string delQuery = $"Delete from Squares where Id={deleteId}";
                    try
                    {
                        resultInt = db.Delete(delQuery);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    if (resultInt == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nSquare has deleted successfully!!!");
                        Console.ResetColor();
                        Pause();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"\nThe method of Delete() return {resultInt}\nSomething went wrong...Try to fix this!");
                        Console.ResetColor();
                        Pause();
                    }
                    break;

                case 5: break;
                }
                break;

            case 2:
                Console.Clear();
                Console.WriteLine("1 - Add new parallelogram into the table:");
                Console.WriteLine("2 - Show all parallelograms from the table");
                Console.WriteLine("3 - Edit parallelogram by Id");
                Console.WriteLine("4 - Delete parallelogram by Id");
                Console.WriteLine("5 - Return back");
                Console.Write("\nPlease make your choice..");
                choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    Console.Clear();
                    Parallelogram pr = SetParallelogram(out name, out type, out a, out b, out h, out area, out perim, out tops, out edges);
                    try
                    {
                        result = db.Add($"Insert into Parallelograms([Name], [Type], [A], [B], [H], [Area], [Perimeter], [Tops], [Edges]) " +
                                        $"values('{name}', '{type}', '{a}', '{b}', '{h}', '{area}', '{perim}', '{tops}', '{edges}')");

                        Console.WriteLine("Insert was Successful!Congratulations!!!");
                        Console.WriteLine(result);
                        Console.ResetColor();
                        Pause();
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    break;

                case 2:
                    Console.Clear();
                    string conn = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
                    List <Parallelogram> list = ReadFiguresFromDB.ReadAllParallelograms(conn);
                    for (int i = 0; i < list.Count; i++)
                    {
                        Console.WriteLine(new string('-', 120));
                        Console.ForegroundColor = ConsoleColor.DarkYellow;
                        Console.WriteLine($"\n{i + 1} Parallelogram:\n");
                        Console.ForegroundColor = RandColors()[rand.Next(0, 5)];
                        Console.WriteLine(list[i]);
                        Console.ResetColor();
                        Console.WriteLine("\n" + new string('-', 120));
                    }
                    Pause();
                    break;

                case 3:
                    Console.Write("Enter any id of parallelogram to Update: ");
                    int editId = int.Parse(Console.ReadLine());

                    Parallelogram editPar   = SetParallelogram(out name, out type, out a, out b, out h, out area, out perim, out tops, out edges);
                    string        editQuery = $"Update Parallelograms SET Name='{name}',Type='{type}', A='{a}', B='{b}', H='{h}', Area='{area}', Perimeter='{perim}' where Id={editId}";
                    try
                    {
                        resultInt = db.Update(editQuery);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }

                    if (resultInt == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nParallelogram has updated successfully!!!");
                        Console.ResetColor();
                        Pause();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"\nThe method of Update() return {resultInt}\nSomething went wrong...Try to fix this!");
                        Console.ResetColor();
                        Pause();
                    }
                    break;

                case 4:
                    Console.Write("Enter any id of parallelogram to Delete from the table: ");
                    int    deleteId = int.Parse(Console.ReadLine());
                    string delQuery = $"Delete from Parallelograms where Id={deleteId}";
                    try
                    {
                        resultInt = db.Delete(delQuery);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    if (resultInt == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nParallelogram has deleted successfully!!!");
                        Console.ResetColor();
                        Pause();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"\nThe method of Delete() return {resultInt}\nSomething went wrong...Try to fix this!");
                        Console.ResetColor();
                        Pause();
                    }
                    break;
                }
                break;

            case 3:
                Console.Clear();
                Console.WriteLine("1 - Add new rectangle into the table:");
                Console.WriteLine("2 - Show all rectangles from the table");
                Console.WriteLine("3 - Edit rectangle by Id");
                Console.WriteLine("4 - Delete rectangle by Id");
                Console.WriteLine("5 - Return back");
                Console.Write("\nPlease make your choice..");
                choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    Console.Clear();
                    Rectangle rct = SetRectangle(out name, out type, out a, out b, out area, out perim, out tops, out edges);
                    try
                    {
                        result = db.Add($"Insert into Rectangles([Name],[Type],[A],[B],[Area],[Perimeter],[Tops],[Edges])" +
                                        $"values('{name}','{type}','{a}','{b}','{area}','{perim}','{tops}','{edges}')");

                        Console.ForegroundColor = (result == "Insert was Successful!Congratulations!!!") ? ConsoleColor.Green : ConsoleColor.Red;
                        Console.WriteLine(result);
                        Console.ResetColor();
                        Pause();
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    break;

                case 2:
                    Console.Clear();
                    string           conn = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
                    List <Rectangle> list = ReadFiguresFromDB.ReadAllRectangles(conn);
                    for (int i = 0; i < list.Count; i++)
                    {
                        Console.WriteLine(new string('-', 120));
                        Console.ForegroundColor = ConsoleColor.DarkYellow;
                        Console.WriteLine($"\n{i + 1} Rectangle:\n");
                        Console.ForegroundColor = RandColors()[rand.Next(0, 5)];
                        Console.WriteLine(list[i]);
                        Console.ResetColor();
                        Console.WriteLine("\n" + new string('-', 120));
                    }
                    Pause();
                    break;

                case 3:
                    Console.Write("Enter any id of rectangle to Update: ");
                    int editId = int.Parse(Console.ReadLine());

                    Rectangle editRct   = SetRectangle(out name, out type, out a, out b, out area, out perim, out tops, out edges);
                    string    editQuery = $"Update Rectangles SET Name='{name}',Type='{type}',A='{a}', B='{b}',Area='{area}', Perimeter='{perim}' where Id={editId}";
                    try
                    {
                        resultInt = db.Update(editQuery);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    if (resultInt == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nRectangles has updated successfully!!!");
                        Console.ResetColor();
                        Pause();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"\nThe method of Update() return {resultInt}\nSomething went wrong...Try to fix this!");
                        Console.ResetColor();
                        Pause();
                    }
                    break;

                case 4:
                    Console.Write("Enter any id of rectangle to Delete from the table: ");
                    int    deleteId = int.Parse(Console.ReadLine());
                    string delQuery = $"Delete from Rectangles where Id={deleteId}";
                    try
                    {
                        resultInt = db.Delete(delQuery);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    if (resultInt == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nRectangle has deleted successfully!!!");
                        Console.ResetColor();
                        Pause();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"\nThe method of Delete() return {resultInt}\nSomething went wrong...Try to fix this!");
                        Console.ResetColor();
                        Pause();
                    }
                    break;
                }
                break;

            case 4:
                Console.Clear();
                Console.WriteLine("1 - Add new rhomb into the table:");
                Console.WriteLine("2 - Show all rhombs from the table");
                Console.WriteLine("3 - Edit rhomb by Id");
                Console.WriteLine("4 - Delete rhomb by Id");
                Console.WriteLine("5 - Return back");
                Console.Write("\nPlease make your choice..");
                choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    Console.Clear();
                    Rhomb rhmb = SetRhomb(out name, out type, out a, out h, out area, out perim, out tops, out edges);
                    try
                    {
                        result = db.Add($"Insert into Rhombs([Name],[Type],[A],[H],[Area],[Perimeter],[Tops],[Edges])" +
                                        $"values('{name}','{type}','{a}','{h}','{area}','{perim}','{tops}','{edges}')");

                        Console.ForegroundColor = (result == "Insert was Successful!Congratulations!!!") ? ConsoleColor.Green : ConsoleColor.Red;
                        Console.WriteLine(result);
                        Console.ResetColor();
                        Pause();
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    break;

                case 2:
                    Console.Clear();
                    List <Rhomb> list = ReadFiguresFromDB.ReadAllRhombs(AllFigures_Storage.connect);
                    for (int i = 0; i < list.Count; i++)
                    {
                        Console.WriteLine(new string('-', 120));
                        Console.ForegroundColor = ConsoleColor.DarkYellow;
                        Console.WriteLine($"\n{i + 1} Rhomb:\n");
                        Console.ForegroundColor = RandColors()[rand.Next(0, 5)];
                        Console.WriteLine(list[i]);
                        Console.ResetColor();
                        Console.WriteLine("\n" + new string('-', 120));
                    }
                    Pause();
                    break;

                case 3:
                    Console.Write("Enter any id of rhomb to Update: ");
                    int editId = int.Parse(Console.ReadLine());

                    Rhomb  editRhmb  = SetRhomb(out name, out type, out a, out h, out area, out perim, out tops, out edges);
                    string editQuery = $"Update Rhombs SET Name='{name}',Type='{type}',A='{a}', H='{h}',Area='{area}', Perimeter='{perim}' where Id={editId}";
                    try
                    {
                        resultInt = db.Update(editQuery);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    if (resultInt == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nRhombs has updated successfully!!!");
                        Console.ResetColor();
                        Pause();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"\nThe method of Update() return {resultInt}\nSomething went wrong...Try to fix this!");
                        Console.ResetColor();
                        Pause();
                    }
                    break;

                case 4:
                    Console.Write("Enter any id of rhomb to Delete from the table: ");
                    int    deleteId = int.Parse(Console.ReadLine());
                    string delQuery = $"Delete from Rhombs where Id={deleteId}";
                    try
                    {
                        resultInt = db.Delete(delQuery);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    if (resultInt == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nRhomb has deleted successfully!!!");
                        Console.ResetColor();
                        Pause();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"\nThe method of Delete() return {resultInt}\nSomething went wrong...Try to fix this!");
                        Console.ResetColor();
                        Pause();
                    }
                    break;
                }
                break;

            case 5:
                Console.Clear();
                Console.WriteLine("1 - Add new trapeze into the table:");
                Console.WriteLine("2 - Show all trapezes from the table");
                Console.WriteLine("3 - Edit trapeze by Id");
                Console.WriteLine("4 - Delete trapeze by Id");
                Console.WriteLine("5 - Return back");
                Console.Write("\nPlease make your choice..");
                choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    Console.Clear();
                    Trapeze trpz = SetTrapeze(out name, out type, out a, out b, out c, out d, out h, out area, out perim, out tops, out edges);
                    try
                    {
                        result = db.Add($"Insert into Trapezes([Name],[Type],[A],[B],[C],[D],[H],[Area],[Perimeter],[Tops],[Edges])" +
                                        $"values('{name}','{type}','{a}','{b}','{c}','{d}','{h}','{area}','{perim}','{tops}','{edges}')");

                        Console.ForegroundColor = (result == "Insert was Successful!Congratulations!!!") ? ConsoleColor.Green : ConsoleColor.Red;
                        Console.WriteLine(result);
                        Console.ResetColor();
                        Pause();
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    break;

                case 2:
                    Console.Clear();
                    string         conn = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
                    List <Trapeze> list = ReadFiguresFromDB.ReadAllTrapezes(conn);
                    for (int i = 0; i < list.Count; i++)
                    {
                        Console.WriteLine(new string('-', 120));
                        Console.ForegroundColor = ConsoleColor.DarkYellow;
                        Console.WriteLine($"\n{i + 1} Trapeze:\n");
                        Console.ForegroundColor = RandColors()[rand.Next(0, 5)];
                        Console.WriteLine(list[i]);
                        Console.ResetColor();
                        Console.WriteLine("\n" + new string('-', 120));
                    }
                    Pause();
                    break;

                case 3:
                    Console.Write("Enter any id of trapeze to Update: ");
                    int editId = int.Parse(Console.ReadLine());

                    Trapeze editTrpz  = SetTrapeze(out name, out type, out a, out b, out c, out d, out h, out area, out perim, out tops, out edges);
                    string  editQuery = $"Update Trapezes SET Name='{name}',Type='{type}',A='{a}', B='{b}', C='{c}', D='{d}', H='{h}', Area='{area}', Perimeter='{perim}' where Id={editId}";
                    try
                    {
                        resultInt = db.Update(editQuery);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    if (resultInt == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nTrapezes has updated successfully!!!");
                        Console.ResetColor();
                        Pause();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"\nThe method of Update() return {resultInt}\nSomething went wrong...Try to fix this!");
                        Console.ResetColor();
                        Pause();
                    }
                    break;

                case 4:
                    Console.Write("Enter any id of trapeze to Delete from the table: ");
                    int    deleteId = int.Parse(Console.ReadLine());
                    string delQuery = $"Delete from Trapezes where Id={deleteId}";
                    try
                    {
                        resultInt = db.Delete(delQuery);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Pause();
                    }
                    if (resultInt == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nTrapeze has deleted successfully!!!");
                        Console.ResetColor();
                        Pause();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"\nThe method of Delete() return {result}\nSomething went wrong...Try to fix this!");
                        Console.ResetColor();
                        Pause();
                    }
                    break;
                }
                break;
            }
        }