Esempio n. 1
0
        private void ShowBorrowedBooks()
        {
            listBox3.Items.Clear();
            List <string> borrowedBooks = new List <string>();
            int           clientID = 0;
            int           i = 0, stop = 0;

            foreach (Person client in personList)
            {
                if (label3.Text == client.Nume)
                {
                    if (label4.Text == client.Prenume)
                    {
                        clientID = client.Id;
                        break;
                    }
                }
            }
            borrowedBooks = Book.ShowBorrowedBooks(Person.GetPerson(clientID));
            Console.WriteLine("borrowedBooks=" + borrowedBooks.Count());
            if (borrowedBooks.Count() == 0)
            {
                MessageBox.Show("Nu aveti carti imprumutate!");
            }
            else
            {
                foreach (Book book in bookList)
                {
                    for (i = 0; i < borrowedBooks.Count(); i++)
                    {
                        if (book.Id == Convert.ToInt32(borrowedBooks[i]))
                        {
                            listBox3.Items.Add("Titlu: " + book.Title);
                            stop++;
                            if (stop == borrowedBooks.Count())
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex >= 0)
            {
                int bookID   = 0;
                int clientID = 0;
                try
                {
                    string book = listBox1.Items[listBox1.SelectedIndex].ToString();
                    book = book.Substring(7);
                    foreach (Book _book in bookList)
                    {
                        if (_book.Title == book)
                        {
                            bookID = _book.Id;
                            break;
                        }
                    }
                }
                catch (System.Exception exc) { MessageBox.Show(exc.Message); }
                foreach (Person client in personList)
                {
                    if (label3.Text == client.Nume)
                    {
                        if (label4.Text == client.Prenume)
                        {
                            clientID = client.Id;
                            break;
                        }
                    }
                }

                Book.Borrow(Book.GetBook(bookID), Person.GetPerson(clientID));
                listBox3.Items.Clear();
                ShowBorrowedBooks();
            }
            else
            {
                MessageBox.Show("Selectati o carte!");
            }
        }