Пример #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 TopicPrism(DataBase db)
        {
            Console.Clear();
            Console.WriteLine("1 - Add new prism into the table:");
            Console.WriteLine("2 - Show all prisms from the table");
            Console.WriteLine("3 - Edit prism by Id");
            Console.WriteLine("4 - Delete prism 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();
                Prism prsm = SetPrism(out name, out type, out a, out b, out c, out h, out area, out volume, out tops, out edges, out sides);
                try
                {
                    result = db.Add($"Insert into Prisms([Name],[Type],[A],[B],[C],[H],[Volume],[Area],[Tops],[Edges],[Sides])" +
                                    $"values('{name}','{type}','{a}','{b}','{c}','{h}','{volume}','{area}','{tops}','{edges}','{sides}')");

                    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 <Prism> list = ReadFiguresFromDB.ReadAllPrisms(conn);
                for (int i = 0; i < list.Count; i++)
                {
                    Console.WriteLine(new string('-', 120));
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine($"\n{i + 1} Prism:\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 prism to Update: ");
                int editId = int.Parse(Console.ReadLine());

                Prism  editPrsm  = SetPrism(out name, out type, out a, out b, out c, out h, out area, out volume, out tops, out edges, out sides);
                string editQuery = $"Update Prisms SET Name='{name}',Type='{type}',A='{a}', B='{b}', C='{c}', H='{h}', Volume='{volume}', Area='{area}' 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("\nPrism has updated successfull!!!");
                    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 prism to Delete from the table: ");
                int    deleteId = int.Parse(Console.ReadLine());
                string delQuery = $"Delete from Prisms 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("\nPrism 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;

            case 5: break;
            }
        }