private void button4_Click(object sender, EventArgs e) { listDataType = 3; if (PublichersManager.Publichers.Count() != 0) { listBox1.DataSource = null; listBox1.Items.Clear(); publichersList.Clear(); for (int i = 0; i < PublichersManager.Publichers.Count(); i++) { publichersList.Add(new Publicher(PublichersManager.Publichers[i], PublichersManager.Publichers[i].Title)); //listBox1.Items.Add(PublichersManager.Publichers[i].Title); } listBox1.DataSource = publichersList; listBox1.DisplayMember = "Title"; listBox1.ValueMember = "PublicherFromList"; } else { if (DataBase.GetStateConnection()) { listBox1.DataSource = null; listBox1.Items.Clear(); publichersList.Clear(); string query = "select * from Publichers"; //SqlConnection connection = DataBase.GetSqlConnection(); SqlCommand command = new SqlCommand(query, DataBase.Sql); SqlDataReader reader = command.ExecuteReader(); //PublichersManager publichersMng = new PublichersManager(); PublichersManager.LoadPublicher(reader); for (int i = 0; i < PublichersManager.Publichers.Count(); i++) { publichersList.Add(new Publicher(PublichersManager.Publichers[i], PublichersManager.Publichers[i].Title)); //listBox1.Items.Add(PublichersManager.Publichers[i].Title); } listBox1.DataSource = publichersList; listBox1.DisplayMember = "Title"; listBox1.ValueMember = "PublicherFromList"; reader.Close(); } } }
private void button1_Click(object sender, EventArgs e) { listBox1.Items.Clear(); List <int> checkListWriters = new List <int>(); List <int> checkListpublishers = new List <int>(); switch (choice) { case 1: if (BooksManager.SearchConnect()) { ((Form1)(this.Owner)).Label1.BackColor = Color.Green; foreach (Books book in BooksManager.Books) { if (book.Title == textBox1.Text) { listBox1.Items.Add(string.Format("{0} {1} {2} {3} {4}", book.BookID.ToString(), book.Title, WritersManager.GetWriter(book.WriterID).FirstName.ToString(), WritersManager.GetWriter(book.WriterID).LastName.ToString(), PublichersManager.GetPublicher(book.PublicherID).Title.ToString())); } } } break; case 2: if (BooksManager.SearchConnect()) { ((Form1)(this.Owner)).Label1.BackColor = Color.Green; foreach (Writers writer in WritersManager.Writers) { if (writer.FirstName == textBox2.Text || writer.LastName == textBox2.Text) { checkListWriters.Add(writer.WriterID); } } foreach (Books book in BooksManager.Books) { if (checkListWriters.Contains(book.WriterID)) { listBox1.Items.Add(string.Format("{0} {1} {2} {3} {4}", book.BookID.ToString(), book.Title, WritersManager.GetWriter(book.WriterID).FirstName.ToString(), WritersManager.GetWriter(book.WriterID).LastName.ToString(), PublichersManager.GetPublicher(book.PublicherID).Title.ToString())); } } } break; case 3: if (BooksManager.SearchConnect()) { foreach (Writers writer in WritersManager.Writers) { if (writer.FirstName == textBox2.Text || writer.LastName == textBox2.Text) { checkListWriters.Add(writer.WriterID); } } foreach (Books book in BooksManager.Books) { if (book.Title == textBox1.Text && checkListWriters.Contains(book.WriterID)) { listBox1.Items.Add(string.Format("{0} {1} {2} {3} {4}", book.BookID.ToString(), book.Title, WritersManager.GetWriter(book.WriterID).FirstName.ToString(), WritersManager.GetWriter(book.WriterID).LastName.ToString(), PublichersManager.GetPublicher(book.PublicherID).Title.ToString())); } } } break; case 4: if (BooksManager.SearchConnect()) { foreach (Publichers publicher in PublichersManager.Publichers) { if (publicher.Title == textBox3.Text) { checkListpublishers.Add(publicher.PublicherID); } } foreach (Books book in BooksManager.Books) { if (checkListpublishers.Contains(book.PublicherID)) { listBox1.Items.Add(string.Format("{0} {1} {2} {3} {4}", book.BookID.ToString(), book.Title, WritersManager.GetWriter(book.WriterID).FirstName.ToString(), WritersManager.GetWriter(book.WriterID).LastName.ToString(), PublichersManager.GetPublicher(book.PublicherID).Title.ToString())); } } } break; case 5: if (BooksManager.SearchConnect()) { //MessageBox.Show("5"); foreach (Publichers publicher in PublichersManager.Publichers) { if (publicher.Title == textBox3.Text) { checkListpublishers.Add(publicher.PublicherID); } } foreach (Books book in BooksManager.Books) { if (book.Title == textBox1.Text && checkListpublishers.Contains(book.PublicherID)) { listBox1.Items.Add(string.Format("{0} {1} {2} {3} {4}", book.BookID.ToString(), book.Title, WritersManager.GetWriter(book.WriterID).FirstName.ToString(), WritersManager.GetWriter(book.WriterID).LastName.ToString(), PublichersManager.GetPublicher(book.PublicherID).Title.ToString())); } } } break; case 6: if (BooksManager.SearchConnect()) { foreach (Writers writer in WritersManager.Writers) { if (writer.FirstName == textBox2.Text || writer.LastName == textBox2.Text) { checkListWriters.Add(writer.WriterID); } } foreach (Publichers publicher in PublichersManager.Publichers) { if (publicher.Title == textBox3.Text) { checkListpublishers.Add(publicher.PublicherID); } } foreach (Books book in BooksManager.Books) { if (checkListpublishers.Contains(book.PublicherID) && checkListWriters.Contains(book.WriterID)) { listBox1.Items.Add(string.Format("{0} {1} {2} {3} {4}", book.BookID.ToString(), book.Title, WritersManager.GetWriter(book.WriterID).FirstName.ToString(), WritersManager.GetWriter(book.WriterID).LastName.ToString(), PublichersManager.GetPublicher(book.PublicherID).Title.ToString())); } } } break; case 7: if (BooksManager.SearchConnect()) { foreach (Writers writer in WritersManager.Writers) { if (writer.FirstName == textBox2.Text || writer.LastName == textBox2.Text) { checkListWriters.Add(writer.WriterID); } } foreach (Publichers publicher in PublichersManager.Publichers) { if (publicher.Title == textBox3.Text) { checkListpublishers.Add(publicher.PublicherID); } } foreach (Books book in BooksManager.Books) { if (book.Title == textBox1.Text && checkListpublishers.Contains(book.PublicherID) && checkListWriters.Contains(book.WriterID)) { listBox1.Items.Add(string.Format("{0} {1} {2} {3} {4}", book.BookID.ToString(), book.Title, WritersManager.GetWriter(book.WriterID).FirstName.ToString(), WritersManager.GetWriter(book.WriterID).LastName.ToString(), PublichersManager.GetPublicher(book.PublicherID).Title.ToString())); } } } break; default: break; } }