Exemplo n.º 1
0
        static public void SearchListClients(List <int> list, Client searchClient, PhoneBook phoneBook, Func <Client, Client, bool> compare)
        {
            int i;

            if (list.Count > 0)
            {
                for (i = 0; i < phoneBook.Count; i++)
                {
                    if (compare(phoneBook.PhonesBook[i], searchClient))
                    {
                        list.Add(i);
                    }
                }
            }
        }
Exemplo n.º 2
0
        static public int SearchBy(Client searchClient, PhoneBook phoneBook, Func <Client, Client, bool> compare)
        {
            bool equally = false;
            int  i;

            for (i = 0; i < phoneBook.Count; i++)
            {
                if (compare(phoneBook.PhonesBook[i], searchClient))
                {
                    equally = true;
                    break;
                }
            }
            return(equally ? i : -1);
        }
Exemplo n.º 3
0
 static public void SaveSerialization(PhoneBook phoneBook)
 {
     try
     {
         using (FileStream fileStream = new FileStream("obj.dat", FileMode.Create))
         {
             BinaryFormatter bf = new BinaryFormatter();
             bf.Serialize(fileStream, phoneBook);
         }
     }
     catch (IOException exc)
     {
         Console.WriteLine("Error Writing SaveBook File");
         Console.WriteLine("Reason: " + exc.Message);
     }
 }
Exemplo n.º 4
0
        // Реализуем обобщенный метод сортировки
        static public void Sort(PhoneBook phoneBook, Func <Client, Client, bool> compare)
        {
            bool mySort = true;

            do
            {
                mySort = false;
                for (int i = 0; i < phoneBook.Count - 1; i++)
                {
                    if (compare(phoneBook.PhonesBook[i + 1], phoneBook.PhonesBook[i]))
                    {
                        Client j = phoneBook.PhonesBook[i];
                        phoneBook.PhonesBook[i]     = phoneBook.PhonesBook[i + 1];
                        phoneBook.PhonesBook[i + 1] = j;
                        mySort = true;
                    }
                }
            } while (mySort);
        }
Exemplo n.º 5
0
        static public void Load(PhoneBook phoneBook)
        {
            BinaryReader dataIn;

            try
            {
                dataIn = new BinaryReader(
                    new FileStream("SaveBook.dat", FileMode.Open));
            }
            catch (IOException exc)
            {
                Console.WriteLine("Cannot Open SaveBook File For Input");
                Console.WriteLine("Reason: " + exc.Message);
                return;
            }
            try
            {
                phoneBook.Count = dataIn.ReadInt32();

                Client client = new Client();

                for (int i = 0; i < phoneBook.Count; i++)
                {
                    client.firstName  = dataIn.ReadString();
                    client.lastName   = dataIn.ReadString();
                    client.foneNumber = dataIn.ReadInt32();
                    client.adress     = dataIn.ReadString();
                    phoneBook.Add(client);
                    phoneBook.Count--;
                }
            }
            catch (IOException exc)
            {
                Console.WriteLine("Error Reading Inventory File");
                Console.WriteLine("Reason: " + exc.Message);
            }
            finally
            {
                dataIn.Close();
            }
        }
Exemplo n.º 6
0
        static public void Save(PhoneBook phoneBook)
        {
            BinaryWriter dataOut;

            try
            {
                dataOut = new BinaryWriter(
                    new FileStream("SaveBook.dat", FileMode.Create));
            }
            catch (IOException exc)
            {
                Console.WriteLine("Cannot Open SaveBook File For Output");
                Console.WriteLine("Reason: " + exc.Message);
                return;
            }

            try
            {
                dataOut.Write(phoneBook.Count);

                for (int i = 0; i < phoneBook.Count; i++)
                {
                    dataOut.Write(phoneBook.PhonesBook[i].firstName);
                    dataOut.Write(phoneBook.PhonesBook[i].lastName);
                    dataOut.Write(phoneBook.PhonesBook[i].foneNumber);
                    dataOut.Write(phoneBook.PhonesBook[i].adress);
                }
            }
            catch (IOException exc)
            {
                Console.WriteLine("Error Writing SaveBook File");
                Console.WriteLine("Reason: " + exc.Message);
            }
            finally
            {
                dataOut.Close();
            }
        }
Exemplo n.º 7
0
 static public void SearchByFhone(List <int> list, Client searchClient, PhoneBook book)
 {
     SearchListClients(list, searchClient, book, (client1, client2) => client1.foneNumber == client2.foneNumber);
 }
Exemplo n.º 8
0
 static public int SearchByFhone(Client searchClient, PhoneBook book)
 {
     return(SearchBy(searchClient, book, (client1, client2) => client1.foneNumber == client2.foneNumber));
 }
Exemplo n.º 9
0
 static public void SearchByLastName(List <int> list, Client searchClient, PhoneBook book)
 {
     SearchListClients(list, searchClient, book, (client1, client2) => string.Compare(client1.lastName, client2.lastName) == 0);
 }
Exemplo n.º 10
0
 static public int SearchByLastName(Client searchClient, PhoneBook book)
 {
     return(SearchBy(searchClient, book, (client1, client2) => string.Compare(client1.lastName, client2.lastName) == 0));
 }
Exemplo n.º 11
0
 static public void SortByadress(PhoneBook book)
 {
     ListSort.Sort(book, (client1, client2) => string.Compare(client1.adress, client2.adress) < 0);
 }
Exemplo n.º 12
0
 static public void SortByFhone(PhoneBook book)
 {
     ListSort.Sort(book, (client1, client2)
                   => client1.foneNumber > client2.foneNumber);
 }
Exemplo n.º 13
0
 static public void SortByLastName(PhoneBook book)
 {
     ListSort.Sort(book, (client1, client2) => string.Compare(client1.lastName, client2.lastName) < 0);
 }