示例#1
0
        public void SendSearchRequest(BookInServer searchingBook)
        {
            IPEndPoint    clientIp      = (IPEndPoint)(TcpSocket.LocalEndPoint);
            SearchRequest searchRequest = new SearchRequest(clientIp.Address.ToString(), clientIp.Port, ClientID, searchingBook);

            SendMessage(searchRequest);
        }
示例#2
0
 public bool CorrectName(BookInServer book, BookInServer searchingBook)
 {
     if (book.Name.ToUpper().Contains(searchingBook.Name.ToUpper()))
     {
         return(true);
     }
     return(false);
 }
示例#3
0
        private void buttonSendSearchRequest_Click(object sender, EventArgs e)
        {
            if (Main.Client == null)
            {
                MessageBox.Show("Для отправки поисковых запросов необходимо подключение к серверу!");
            }

            string name = "";

            if (NameTB.Text != null)
            {
                name = NameTB.Text;
            }

            string autor = "";

            if (AutorTB.Text != null)
            {
                autor = AutorTB.Text;
            }

            string type = "";

            if (TypeCB.Text != null)
            {
                type = TypeCB.Text;
            }

            string publishingHouse = "";

            if (NameTB.Text != null)
            {
                publishingHouse = PublishingHouseTB.Text;
            }

            int year = 0;

            if (YearTB.Text != "")
            {
                try
                {
                    year = int.Parse(YearTB.Text);
                }
                catch (Exception)
                {
                    year = 0;
                    MessageBox.Show("Некорректные данные");
                    return;
                }
            }

            BookInServer searchingBook = new BookInServer(name, autor, "", type, publishingHouse, year, 0, 0);

            Main.Client.SendSearchRequest(searchingBook);
        }
示例#4
0
 public bool CorrectYear(BookInServer book, BookInServer searchingBook)
 {
     if (searchingBook.Year == 0)
     {
         return(true);
     }
     if (searchingBook.Year == book.Year)
     {
         return(true);
     }
     return(false);
 }
示例#5
0
 public bool CorrectType(BookInServer book, BookInServer searchingBook)
 {
     if (searchingBook.Type == "")
     {
         return(true);
     }
     if (searchingBook.Type == book.Type)
     {
         return(true);
     }
     return(false);
 }
示例#6
0
 public bool CorrectPublishingHouse(BookInServer book, BookInServer searchingBook)
 {
     if (searchingBook.PublishingHouse == "")
     {
         return(true);
     }
     if (book.PublishingHouse.ToUpper().Contains(searchingBook.PublishingHouse.ToUpper()))
     {
         return(true);
     }
     return(false);
 }
示例#7
0
 public bool CorrectAutor(BookInServer book, BookInServer searchingBook)
 {
     if (searchingBook.Autor == "")
     {
         return(true);
     }
     if (book.Autor.ToUpper().Contains(searchingBook.Autor.ToUpper()))
     {
         return(true);
     }
     return(false);
 }
示例#8
0
 public bool CorrectBook(BookInServer book, BookInServer searchingBook)
 {
     if (CorrectName(book, searchingBook) &&
         CorrectAutor(book, searchingBook) &&
         CorrectPublishingHouse(book, searchingBook) &&
         CorrectType(book, searchingBook) &&
         CorrectYear(book, searchingBook))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#9
0
        public SearchResponse GetSearchResponse(SearchRequest searchRequest)
        {
            List <string> hitList       = new List <string>();
            BookInServer  searchingBook = searchRequest.SearchingBook;

            foreach (ConnectedClient connectedClient in clientsList)
            {
                foreach (BookInServer book in connectedClient.ClientBookList)
                {
                    if (CorrectBook(book, searchingBook))
                    {
                        hitList.Add("Торговое место № " + connectedClient.ClientID.ToString() + " :" + book.Name + " " + book.Autor + " " + book.Genre + " " + book.PublishingHouse + " " + book.Year.ToString() + " год " + book.Price.ToString() + " рублей " + book.Number.ToString() + " экземпляр(а).");
                    }
                }
            }

            SearchResponse searchResponse = new SearchResponse(NetworkInformation.GetCurrrentHostIp().ToString(), ServerPort, searchRequest.ClientID, hitList);

            return(searchResponse);
        }