Beispiel #1
0
        //Add
        public void Add(Contact contact)
        {
            if (FirstTime)
            {
                Value     = contact;
                FirstTime = false;
                Count++;

                string CommandInsert = $@"INSERT INTO ContactList ([Name], [SurName], [Email], [PNumber]) VALUES 
                                        ('{Value.Name}', '{Value.SurName}', '{Value.Email}', '{Value.PNumber}')";

                using (SqlConnection connection = new SqlConnection(strConnection))
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand(CommandInsert, connection);
                    numOfInserted += command.ExecuteNonQuery();
                }
            }
            else if (Next == null)
            {
                Next    = new PhoneBook(contact);
                Current = Next;
                Count++;

                string CommandInsert = $@"INSERT INTO ContactList ([Name], [SurName], [Email], [PNumber]) VALUES 
                                        ('{Current.Value.Name}', '{Current.Value.SurName}', '{Current.Value.Email}', '{Current.Value.PNumber}')";

                using (SqlConnection connection = new SqlConnection(strConnection))
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand(CommandInsert, connection);
                    numOfInserted += command.ExecuteNonQuery();
                }
            }
            else
            {
                Current.Next = new PhoneBook(contact);
                Current      = Current.Next;
                Count++;
                string CommandInsert = $@"INSERT INTO ContactList ([Name], [SurName], [Email], [PNumber]) VALUES 
                                        ('{Current.Value.Name}', '{Current.Value.SurName}', '{Current.Value.Email}', '{Current.Value.PNumber}')";


                using (SqlConnection connection = new SqlConnection(strConnection))
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand(CommandInsert, connection);
                    numOfInserted += command.ExecuteNonQuery();
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var    pb = new PhoneBook();
            Random r  = new Random();

            for (int i = 0; i < 10; i++)
            {
                pb.Add(new Contact($"A{i}", $"A{i}yan", $"A{i}@mail.ru", $"{r.Next(100000000, 999999999)}"));
            }

            //pb.Clear();

            for (int i = 0; i < pb.Count; i++)
            {
                Console.WriteLine(pb[i]);
            }

            pb[4] = new Contact("000000", "00000", "00000", "00000");
            Console.WriteLine(pb[4]);

            var a = pb.ToArray();
        }
Beispiel #3
0
 public Enumerator(PhoneBook pb)
 {
     Current = null;
     Pb      = pb;
 }