Example #1
0
 private void button_Save_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(textBox_name_book.Text) || string.IsNullOrEmpty(textBox_Id_Book.Text) || string.IsNullOrEmpty(textBox_from_born.Text) ||
         string.IsNullOrEmpty(comboBox_Countre.Text) || checkedListBox1.CheckedItems.Count <= 0 || string.IsNullOrEmpty(selectedRb))
     {
         MessageBox.Show("Заполните все поля!");
     }
     else
     {
         bool canCont = true;
         foreach (var item in collectionBooks.books)
         {
             if (textBox_Id_Book.Text == item.Id)
             {
                 MessageBox.Show("Книга с таким Id уже есть!\n Попробуйте другой :)");
                 canCont = false;
                 break;
             }
         }
         if (canCont)
         {
             Author author = new Author
             {
                 SN = form2.SN
             };
             Book book = new Book(textBox_name_book.Text, textBox_Id_Book.Text, textBox_from_born.Text,
                                  comboBox_Countre.Text, ginere, dateTimePicker1.Value.Year.ToString(), selectedRb, author);
             var collection = SerializateInfo.Deserialize <MyClassCollection>("books.xml");
             collection.books.Add(book);
             SerializateInfo.Serialize(collection, "books.xml");
             MessageBox.Show("Сохранено!");
         }
     }
 }
Example #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                StringBuilder outputLine = new StringBuilder();
                var           desBooks   = SerializateInfo.Deserialize <MyClassCollection>("books.xml");
                foreach (var desInfo in desBooks.books)
                {
                    outputLine.AppendLine($"Название книги: {desInfo.Name}");
                    outputLine.AppendLine($"ID книги: {desInfo.Id}");
                    outputLine.AppendLine($"ФИО автора: {desInfo.author.SN}");
                    outputLine.AppendLine($"Название издательства: {desInfo.From}");
                    outputLine.AppendLine($"Страна производства: {desInfo.Countre}");
                    outputLine.AppendLine($"Жанр: {desInfo.Genre}");
                    outputLine.AppendLine($"Дата выхода книги: {desInfo.ReleaseDate}");
                    outputLine.AppendLine($"Переплёт: {desInfo.Binding}");
                    outputLine.AppendLine($"--------------------------------");
                }

                textBox_info_from_file.Text = outputLine.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"{ex.Message}");
            }
        }