Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            string temp = textBox8.Text;

            if (temp == null)
            {
                MessageBox.Show("Write search criteria!");
            }
            else
            {
                bool found = false;
                List <LibraryItem> myItems = parent.getLibraryItems();
                foreach (LibraryItem libitem in myItems)
                {
                    if (libitem.PrintData().Contains(temp))
                    {
                        Book book = new Book(0, "", "", "", "", "", "", "", "");
                        book                   = (Book)libitem;
                        textBox1.Text          = book.getId().ToString();
                        comboBox1.SelectedItem = book.getState();
                        textBox2.Text          = book.getPublisher();
                        textBox3.Text          = book.getIsbn();
                        textBox4.Text          = book.getAuthor();
                        textBox5.Text          = book.getTitle();
                        textBox6.Text          = book.getGenre();
                        textBox7.Text          = book.getShelfClassification();
                        found                  = true;
                    }
                }
                if (!found)
                {
                    MessageBox.Show("Book matching search criteria not found!");
                }
            }
        }
        private void Form3_Load(object sender, EventArgs e)
        {
            listView1.View          = View.Details;
            listView1.GridLines     = true;
            listView1.FullRowSelect = true;

            //Add column header
            listView1.Columns.Add("ID", 40);
            listView1.Columns.Add("Type", 50);
            listView1.Columns.Add("State", 70);
            listView1.Columns.Add("Publisher", 70);
            listView1.Columns.Add("ISBN", 70);
            listView1.Columns.Add("Author", 70);
            listView1.Columns.Add("Title", 70);
            listView1.Columns.Add("Genre", 70);
            listView1.Columns.Add("Shelf", 70);

            //Add items in the listview
            string[]           arr = new string[10];
            ListViewItem       itm;
            List <LibraryItem> myItems = parent.getLibraryItems();

            foreach (LibraryItem libitem in myItems)
            {
                if (libitem.getType().Equals("book"))
                {
                    Book book = new Book(0, "", "", "", "", "", "", "", "");
                    book   = (Book)libitem;
                    arr[0] = book.getId().ToString();
                    arr[1] = book.getType();
                    arr[2] = book.getState();
                    arr[3] = book.getPublisher();
                    arr[4] = book.getIsbn();
                    arr[5] = book.getAuthor();
                    arr[6] = book.getTitle();
                    arr[7] = book.getGenre();
                    arr[8] = book.getShelfClassification();
                    itm    = new ListViewItem(arr);
                    listView1.Items.Add(itm);
                }
            }
        }