예제 #1
0
        private static void workingWithXml()
        {
            var contact1 = new Phone("1234", "4321");
            var contact2 = new Mail("dada", "netnet");

            var card1 = new Card(123,345,"cardName");
            card1.addMail("dada", "netnet");
            card1.addPhone("1234", "4321");

            Console.WriteLine(card1.ToXml());
        }
예제 #2
0
파일: Main.cs 프로젝트: NidentalEgor/CSharp
        static void Main(string[] args)
        {
            string input = null;
            Card newCard = new Card();
            // Чтобы нельзя было ввести весь номер только в одном поле при удалении.
            string phoneOrEmail = "a";
            string phoneZoneOrAlias = "b";

            do
            {
                Console.WriteLine("Enter what do you want to do:");
                Console.WriteLine("1 - add contact");
                Console.WriteLine("2 - print all contacts");
                Console.WriteLine("3 - delete contact");
                Console.WriteLine("4 - exit\n");

                input = Console.ReadLine();
                switch (input)
                {

                    case "1":
                        {

                            Console.WriteLine("Enter '1' to add phone\nEnter '2' to add email");

                            input = Console.ReadLine();
                            if (input == "1")
                            {
                                Console.WriteLine("Enter phone:");
                                phoneOrEmail = Console.ReadLine();
                                Console.WriteLine("Enter phone zone:");
                                phoneZoneOrAlias = Console.ReadLine();
                                Console.WriteLine("\n");
                                newCard.addPhone(phoneOrEmail, phoneZoneOrAlias);
                            }
                            else
                                if (input == "2")
                            {
                                Console.WriteLine("\nEnter email:");
                                phoneOrEmail = Console.ReadLine();
                                Console.WriteLine("Enter alias:");
                                phoneZoneOrAlias = Console.ReadLine();
                                Console.WriteLine("\n");
                                newCard.addMail(phoneOrEmail, phoneZoneOrAlias);
                            }
                            else
                            {
                                Console.WriteLine("\nInvalid input data!\n");
                            }
                        }
                        break;
                    case "2":
                        {
                            newCard.getContacts();
                        }
                        break;
                    case "3":
                        {
                            if (newCard.size > 0)
                            {

                                Console.WriteLine("Enter '1' to delete phone\nEnter '2' to delete email");
                                input = Console.ReadLine();
                                if (input == "1")
                                {
                                    Console.WriteLine("Enter phone:");
                                    phoneOrEmail = Console.ReadLine();
                                    Console.WriteLine("Enter phone zone:");
                                    phoneZoneOrAlias = Console.ReadLine();
                                    Console.WriteLine("\n");
                                    newCard.deleteContact(phoneOrEmail, phoneZoneOrAlias);
                                }
                                else
                                    if (input == "2")
                                {
                                    Console.WriteLine("\nEnter email:");
                                    phoneOrEmail = Console.ReadLine();
                                    Console.WriteLine("Enter alias:");
                                    phoneZoneOrAlias = Console.ReadLine();
                                    Console.WriteLine("\n");
                                    newCard.deleteContact(phoneOrEmail, phoneZoneOrAlias);
                                }
                                else
                                {
                                    Console.WriteLine("\nInvalid input data!\n");
                                }
                            }
                            else
                            {
                                Console.WriteLine("\nNo contacts!\n");
                            }
                        }
                        break;
                    case "4":
                        {
                            Environment.Exit(0);
                        }
                        break;
                    default:
                        {
                            Console.WriteLine("Invalid input data!");
                        }
                        break;
                }

                phoneOrEmail = "a";
                phoneZoneOrAlias = "b";
            }
            while (true);
        }
예제 #3
0
        static void Main(string[] args)
        {
            string input = null;
            Card newCard = null;
            // Чтобы нельзя было ввести весь номер только в одном поле при удалении.
            var phoneOrEmail = "a";
            var phoneZoneOrAlias = "b";

            try
            {

                do
                {
                    Console.WriteLine("Enter what do you want to do:");
                    Console.WriteLine("1 - add card");
                    Console.WriteLine("2 - add contact to card");
                    Console.WriteLine("3 - print all contacts as string");
                    Console.WriteLine("4 - print content of card as Xml");
                    Console.WriteLine("5 - delete contact");
                    Console.WriteLine("6 - delete card");
                    Console.WriteLine("7 - exit\n");

                    input = Console.ReadLine();

                    switch (input)
                    {
                        case "1":
                        {
                            newCard = new Card();
                            Console.WriteLine("Enter Id:");
                            newCard.ProjectId = Convert.ToInt32(Console.ReadLine());
                            Console.WriteLine("Enter Name:");
                            newCard.Name = Console.ReadLine();
                            Console.WriteLine("Enter SynCode:");
                            newCard.SynCode = Convert.ToInt32(Console.ReadLine());
                            Console.WriteLine("\n");
                        }
                            break;
                        case "2":
                        {
                            if (newCard == null)
                                throw new Exception("Card does not exist!");

                            Console.WriteLine("Enter '1' to add phone\nEnter '2' to add email");

                            input = Console.ReadLine();
                            switch (input)
                            {
                                case "1":
                                    Console.WriteLine("Enter phone:");
                                    phoneOrEmail = Console.ReadLine();
                                    Console.WriteLine("Enter phone zone:");
                                    phoneZoneOrAlias = Console.ReadLine();
                                    Console.WriteLine("\n");
                                    newCard.addPhone(phoneOrEmail, phoneZoneOrAlias);
                                    break;
                                case "2":
                                    Console.WriteLine("\nEnter email:");
                                    phoneOrEmail = Console.ReadLine();
                                    Console.WriteLine("Enter alias:");
                                    phoneZoneOrAlias = Console.ReadLine();
                                    Console.WriteLine("\n");
                                    newCard.addMail(phoneOrEmail, phoneZoneOrAlias);
                                    break;
                                default:
                                    Console.WriteLine("\nInvalid input data!\n");
                                    break;
                            }
                        }
                            break;
                        case "3":
                        {
                            if (newCard == null)
                            {
                                throw new Exception("Card does not exist!");
                            }
                            Console.WriteLine(newCard.GetContacts());
                        }
                            break;

                        case "4":
                        {
                            if (newCard == null)
                            {
                                throw new Exception("Card does not exist!");
                            }
                            Console.WriteLine(newCard.ToXml());
                        }
                            break;
                        case "5":
                        {
                            if (newCard == null)
                                throw new Exception("Card does not exist!");

                            if (newCard.Size > 0)
                            {

                                Console.WriteLine("Enter '1' to delete phone\nEnter '2' to delete email");
                                input = Console.ReadLine();
                                switch (input)
                                {
                                    case "1":
                                        Console.WriteLine("Enter phone:");
                                        phoneOrEmail = Console.ReadLine();
                                        Console.WriteLine("Enter phone zone:");
                                        phoneZoneOrAlias = Console.ReadLine();
                                        Console.WriteLine("\n");
                                        newCard.DeleteContact(phoneOrEmail, phoneZoneOrAlias);
                                        break;
                                    case "2":
                                        Console.WriteLine("\nEnter email:");
                                        phoneOrEmail = Console.ReadLine();
                                        Console.WriteLine("Enter alias:");
                                        phoneZoneOrAlias = Console.ReadLine();
                                        Console.WriteLine("\n");
                                        newCard.DeleteContact(phoneOrEmail, phoneZoneOrAlias);
                                        break;
                                    default:
                                        Console.WriteLine("\nInvalid input data!\n");
                                        break;
                                }
                            }
                            else
                            {
                                Console.WriteLine("\nNo contacts!\n");
                            }
                        }
                            break;

                        case "6":
                        {
                             if (newCard == null)
                                throw new Exception("Card does not exist!");
                            newCard = null;
                        }
                            break;
                        case "7":
                        {
                            Environment.Exit(0);
                        }
                            break;
                        default:
                        {
                            Console.WriteLine("Invalid input data!");
                        }
                            break;
                    }

                    phoneOrEmail = "a";
                    phoneZoneOrAlias = "b";
                } while (true);
            }
            catch (Exception exep)
            {
                Console.WriteLine(exep.Message);
            }
            finally
            {
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
            }
        }