Example #1
0
        private void Book_add_Click(object sender, EventArgs e)
        {
            if (code.Text.Split(';').Count() == Convert.ToInt32(num.Text))
            {
                string Surname_author = "Surname";
                if (author.Text.Split(' ').Count() > 1)
                {
                    Surname_author = author.Text.Split(' ')[1];
                }

                Form1 main = this.Owner as Form1;
                Book  b    = new Book(new List <Person>(), Convert.ToInt32(year.Text), nameb.Text, name_iz.Text, place_pub.Text, code.Text);
                b.Authors_book.Add(new Person(author.Text.Split(' ')[0], "author", Surname_author));
                List <string> buff = new List <string>();
                buff.AddRange(code.Text.Split(';'));
                b.Libray_code = buff[0];
                main.L.Codes.AddRange(buff);

                if (main.L.In_catalog(nameb.Text) && main.L.Search_book_by_name(nameb.Text).BookL[0].Authors_book[0].Surname == Surname_author)
                {
                    BookInLibrary lib = main.L.Search_book_by_name(nameb.Text);
                    //lib.BookL.Add(lib.);
                    int i     = lib.Total_number_copies;
                    int index = i;
                    lib.Total_number_copies        += Convert.ToInt32(num.Text);
                    lib.Number_of_available_copies += Convert.ToInt32(num.Text);
                    lib.Add_Books(i);
                    while (i < lib.Total_number_copies)
                    {
                        lib.BookL[i].Libray_code = buff[i - index];
                        i++;
                    }
                }
                else
                {
                    main.L.Catalog.Add(new BookInLibrary(Convert.ToInt32(num.Text)));
                    main.L.Catalog[main.L.Catalog.Count - 1].BookL.Add(b);
                    main.L.Catalog[main.L.Catalog.Count - 1].Add_Books(1);
                    int i = 1;
                    while (i < Convert.ToInt32(num.Text))
                    {
                        main.L.Catalog[main.L.Catalog.Count - 1].BookL[i].Libray_code = buff[i];
                        i++;
                    }
                }
                num.Clear();
                nameb.Clear();
                author.Clear();
                name_iz.Clear();
                place_pub.Clear();
                code.Clear();
                year.Clear();
                pictureBox1.Visible = true;
            }
            else
            {
                MessageBox.Show("Количество библиотечных шифров не совпадает с количеством книг!");
            }
        }