public Book(string name, string uDK, string publishing, int sizeFile, int countPages, string format, string releaseDate, ContenerAuthors authors) { Name = name; UDK = uDK; Publishing = publishing; SizeFile = sizeFile; CountPages = countPages; Format = format; ReleaseDate = releaseDate; Authors = authors; }
}// Function - add author in collection private void button_Save_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtBox_Name_book.Text) && !string.IsNullOrEmpty(comBox_format_file.Text) && !string.IsNullOrEmpty(txtBox_UDK.Text) && !string.IsNullOrEmpty(txtBox_Count_pages.Text) && !string.IsNullOrEmpty(comBox_publishing.Text) && collectionAuthors.authors.Count > 0 && trBar_size_file.Value > 0) // проверка на заполнение полей { #region ChecksDesserialize if (succesDesserializ) // добавляем в дессир. коллекцию ещё один обьект { bool checkUDK = false; foreach (var item in infoFromFile.books) { if (item.UDK.ToString() == txtBox_UDK.Text.ToString()) { checkUDK = true; } } if (!checkUDK) // проверка на UDK { #region CreateNewBook book = new Book(txtBox_Name_book.Text, txtBox_UDK.Text, comBox_publishing.Text, trBar_size_file.Value, int.Parse(txtBox_Count_pages.Text), comBox_format_file.Text, dateTimePicker1.Text, collectionAuthors); var copy = book.Clone(); #endregion infoFromFile.books.Add(book); // добавляем книгу в коллекцию SerializateInfo.Serialize <CollectionBooks>(infoFromFile, "books.xml"); // сериализуем коллекцию collectionAuthors = new ContenerAuthors(); // clearing MessageBox.Show("Сохранено!"); toolStripStatusLabel_Last_do.Text = "Последние действие: Сохранение в файл"; } else { MessageBox.Show("Такой UDK уже используется"); } }// Успешно дессириализовано else if (!succesDesserializ && !exepDesserializ) { MessageBox.Show("Проведите Дессериализацию"); }// Дессириализация не была проведена else if (!succesDesserializ && exepDesserializ) // { DialogResult dialogResult = MessageBox.Show("Будет создана новая коллекция в сериализуемом файле!\n" + " Желаете продолжить?", "Exception Dessialiaze", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { #region CreateNewBook book = new Book(txtBox_Name_book.Text, txtBox_UDK.Text, comBox_publishing.Text, trBar_size_file.Value, int.Parse(txtBox_Count_pages.Text), comBox_format_file.Text, dateTimePicker1.Text, collectionAuthors); #endregion collectionBooks.books.Add(book); // добавляем книгу в коллекцию SerializateInfo.Serialize <CollectionBooks>(collectionBooks, "books.xml"); // сериализуем коллекцию MessageBox.Show("Сохранено!"); toolStripStatusLabel_Last_do.Text = "Последние действие: Сохранение в файл"; } if (dialogResult == DialogResult.No) { MessageBox.Show("Закрыто!"); } }// Ошибка дессириализации #endregion } else { MessageBox.Show("Заполните все поля"); } } // save in file