private void btn_SaveBook_Click(object sender, EventArgs e) { List <Film> parse = FileOPs.ParseFilmXmlToList(form_Catalog.filmFileName); Film film = parse.Find(f => f.filmProducer == txtbox_Producer.Text && f.filmTitle == txtbox_Title.Text); if (film == null) { List <string> filePath = new List <string>(); int count = 1; foreach (string file in fileNames) { try { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"Pics\Films" + txtbox_Producer.Text + @"\" + txtbox_Title.Text); string extension = Path.GetExtension(file); string path = string.Format(@".\Pics\Films\" + txtbox_Producer.Text + @"\" + txtbox_Title.Text + @"\"); string tempFileName = string.Format("{0}-{1}", txtbox_Title.Text, count++); string fullPath = Path.Combine(path, tempFileName + extension); File.Copy(file, fullPath); filePath.Add(fullPath); } catch (Exception ex) { MessageBox.Show(ex.Message); } } Film filmAppend = new Film(int.Parse(txtbox_ID.Text), txtbox_Title.Text, txtbox_Genre.Text, txtbox_Producer.Text, txtbox_Actors.Text, int.Parse(txtbox_Length.Text), txtbox_Country.Text, DateTime.Parse(txtbox_Premiere.Text), cmbbox_MPAA.Text, txtbox_CriticsRating.Text, int.Parse(txtbox_Grosses.Text), txtbox_Notes.Text, filePath); try { FileOPs.AppendToXmlFile(filmAppend, form_Catalog.filmFileName); txtbox_ID.Clear(); txtbox_Title.Clear(); txtbox_Genre.Clear(); txtbox_Producer.Clear(); txtbox_Actors.Clear(); txtbox_Length.Clear(); txtbox_Country.Clear(); txtbox_Premiere.Clear(); cmbbox_MPAA.SelectedIndex = -1; txtbox_CriticsRating.Clear(); txtbox_Grosses.Clear(); txtbox_Notes.Clear(); flp_FileSelector.Controls.Clear(); tssl_StatusFilmCreate.Text = "Success!"; form_Catalog.lastfilmID++; txtbox_ID.Text = form_Catalog.lastfilmID.ToString(); } catch (FileNotFoundException ex) { MessageBox.Show(ex.Message); tssl_StatusFilmCreate.Text = "Error!"; } } else { MessageBox.Show(string.Format("Producers {0} film '{1}' already exist, please edit filminfo", txtbox_Producer.Text, txtbox_Title.Text)); } }
private void btn_SaveBook_Click(object sender, EventArgs e) { List <Book> parse = FileOPs.ParseBookXmlToList(form_Catalog.bookFileName); Book book = parse.Find(b => b.bookAuthor == txtbox_Author.Text && b.bookTitle == txtbox_Title.Text); if (book == null) { List <string> filePath = new List <string>(); int count = 1; foreach (string file in fileNames) { try { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"Pics\Books" + txtbox_Author.Text + @"\" + txtbox_Title.Text); string extension = Path.GetExtension(file); string path = string.Format(@".\Pics\Books\" + txtbox_Author.Text + @"\" + txtbox_Title.Text + @"\"); string tempFileName = string.Format("{0}-{1}", txtbox_Title.Text, count++); string fullPath = Path.Combine(path, tempFileName + extension); File.Copy(file, fullPath); filePath.Add(fullPath); } catch (Exception ex) { MessageBox.Show(ex.Message); } } Book bookAppend = new Book(int.Parse(txtbox_ID.Text), txtbox_MajorSeries.Text, txtbox_Author.Text, txtbox_Title.Text, txtbox_Series.Text, int.Parse(txtbox_NumberInSeries.Text), txtbox_Genre.Text, int.Parse(txtbox_PagesCount.Text), txtbox_Publisher.Text, int.Parse(txtbox_PrintYear.Text), txtbox_PrintCity.Text, long.Parse(txtbox_ISBN.Text), txtbox_Translator.Text, txtbox_Artist.Text, txtbox_Notes.Text, filePath); try { FileOPs.AppendToXmlFile(bookAppend, form_Catalog.bookFileName); txtbox_ID.Clear(); txtbox_MajorSeries.Clear(); txtbox_Author.Clear(); txtbox_Title.Clear(); txtbox_Series.Clear(); txtbox_NumberInSeries.Clear(); txtbox_Genre.Clear(); txtbox_PagesCount.Clear(); txtbox_Publisher.Clear(); txtbox_PrintYear.Clear(); txtbox_PrintCity.Clear(); txtbox_ISBN.Clear(); txtbox_Translator.Clear(); txtbox_Artist.Clear(); txtbox_Notes.Clear(); flp_FileSelector.Controls.Clear(); tssl_StatusBookCreate.Text = "Success!"; form_Catalog.lastbookID++; txtbox_ID.Text = form_Catalog.lastbookID.ToString(); } catch (FileNotFoundException ex) { MessageBox.Show(ex.Message); tssl_StatusBookCreate.Text = "Error!"; } } else { MessageBox.Show(string.Format("Authors {0} book '{1}' already exist, please edit bookinfo", txtbox_Author.Text, txtbox_Title.Text)); } }