private void btn_SaveBook_Click(object sender, EventArgs e) { List <Film> parse = FileOPs.ParseFilmXmlToList(form_Catalog.filmFileName); 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); FileInfo newFile = new FileInfo(file).CopyTo(fullPath, true); filePath.Add(fullPath); } catch (Exception ex) { MessageBox.Show(ex.Message); } } Film filmToEdit = 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.EditXmlFile(filmToEdit, 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_StatusFilmEdit.Text = "Success!"; Close(); } catch (FileNotFoundException ex) { MessageBox.Show(ex.Message); tssl_StatusFilmEdit.Text = "Error!"; } }
public static void CreateFilmTree(TreeView tree) { XDocument xDoc = FileOPs.LoadXmlFile(form_Catalog.filmFileName); tree.Nodes.Clear(); tree.Nodes.Add(new TreeNode(xDoc.Root.Name.ToString())); List <Film> parse = FileOPs.ParseFilmXmlToList(form_Catalog.filmFileName); List <Film> noDupesProducer = parse.GroupBy(a => a.filmProducer).Select(grp => grp.FirstOrDefault()).OrderBy(a => a.filmProducer).ToList(); foreach (Film nDP in noDupesProducer) { tree.Nodes[0].Nodes.Add(nDP.filmProducer); List <Film> filmTitle = parse.FindAll(x => x.filmProducer.Equals(nDP.filmProducer)).OrderBy(s => s.filmTitle).ToList(); foreach (var ft in filmTitle) { tree.Nodes[0].Nodes[noDupesProducer.IndexOf(nDP)].Nodes.Add(ft.filmTitle); } } tree.ExpandAll(); FileOPs.SetFilmLastID(); }
private void EditToolStripMenuItem_Click(object sender, EventArgs e) { if (tc_Info.SelectedTab == tabPage_Book) { if ((tw_Book.SelectedNode != null) && (TreeViewOPs.GetDeepestChildNodeLevel(tw_Book.SelectedNode) == 1)) { try { List <Book> parse = FileOPs.ParseBookXmlToList(bookFileName); Book bookToEdit = parse.Find(b => b.bookTitle == tw_Book.SelectedNode.Text && b.bookSeries == tw_Book.SelectedNode.Parent.Text && b.bookAuthor == tw_Book.SelectedNode.Parent.Parent.Text); timer_Preview.Stop(); picBox_BookPreview.Image = null; form_EditBook formEdit = new form_EditBook(bookToEdit); formEdit.Show(); TreeViewOPs.CreateBookTree(tw_Book); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } else { MessageBox.Show("Необходимо выбрать 'Книгу'"); } } if (tc_Info.SelectedTab == tabPage_Film) { if ((tw_Film.SelectedNode != null) && (TreeViewOPs.GetDeepestChildNodeLevel(tw_Film.SelectedNode) == 1)) { try { List <Film> parse = FileOPs.ParseFilmXmlToList(filmFileName); Film filmToEdit = parse.Find(f => f.filmTitle == tw_Film.SelectedNode.Text && f.filmProducer == tw_Film.SelectedNode.Parent.Text); timer_Preview.Stop(); picBox_FilmPreview.Image = null; form_EditFilm formEdit = new form_EditFilm(filmToEdit); formEdit.Show(); TreeViewOPs.CreateFilmTree(tw_Film); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } else { MessageBox.Show("Необходимо выбрать 'Фильм'"); } } }
public static void LoadFilmNextImage(TreeNode node, ref PictureBox picBox) { List <Film> parse = FileOPs.ParseFilmXmlToList(form_Catalog.filmFileName); var item = parse.Find(a => a.filmTitle.Equals(node.Text)); if (form_Catalog.imageNumber == item.picturesPath.Count) { form_Catalog.imageNumber = 0; } picBox.ImageLocation = item.picturesPath[form_Catalog.imageNumber].ToString(); form_Catalog.imageNumber++; }
private void tw_Film_AfterSelect(object sender, TreeViewEventArgs e) { List <Film> parse = FileOPs.ParseFilmXmlToList(filmFileName); if ((tw_Film.SelectedNode != null) && (TreeViewOPs.GetDeepestChildNodeLevel(e.Node.TreeView.SelectedNode) == 1)) { try { imageNumber = 0; grpbox_FilmInfo.Show(); txtbox_FilmID.Text = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).filmID.ToString(); txtbox_FilmProducer.Text = e.Node.Parent.Text; txtbox_FilmTitle.Text = e.Node.Text; txtbox_FilmGenre.Text = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).filmGenre; txtbox_FilmActors.Text = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).filmActors; txtbox_FilmLength.Text = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).filmLengthInMinutes.ToString(); txtbox_FilmCountry.Text = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).filmCountry; txtbox_FilmPremiere.Text = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).filmPremiere.ToString(); txtbox_FilmMPAA.Text = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).filmMPAARating; txtbox_FilmCriticsRating.Text = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).filmCriticsRating; txtbox_FilmGrosses.Text = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).filmGrosses.ToString(); txtbox_FilmNotes.Text = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).filmNotes; picBox_FilmPreview.ImageLocation = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).picturesPath[0].ToString(); label11.Text = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).picturesPath[0]; label12.Text = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).picturesPath[1]; label13.Text = parse.Find(f => f.filmProducer == e.Node.Parent.Text && f.filmTitle == e.Node.Text).picturesPath[2]; timer_Preview.Start(); } catch (Exception) { } } else { grpbox_FilmInfo.Hide(); timer_Preview.Stop(); picBox_FilmPreview.Image = null; if (e.Node.IsExpanded) { e.Node.Collapse(); } else { e.Node.Expand(); } } }
private void RemoveToolStripMenuItem_Click(object sender, EventArgs e) { if (tc_Info.SelectedTab == tabPage_Book) { List <Book> parse = FileOPs.ParseBookXmlToList(bookFileName); if ((tw_Book.SelectedNode != null) && (TreeViewOPs.GetDeepestChildNodeLevel(tw_Book.SelectedNode) == 1)) { try { timer_Preview.Stop(); picBox_BookPreview.Image = null; grpbox_BookInfo.Hide(); FileOPs.RemoveFromXmlFile(parse.Find(b => b.bookAuthor == tw_Book.SelectedNode.Parent.Parent.Text && b.bookTitle == tw_Book.SelectedNode.Text), bookFileName); TreeViewOPs.CreateBookTree(tw_Book); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } if (tc_Info.SelectedTab == tabPage_Film) { List <Film> parse = FileOPs.ParseFilmXmlToList(filmFileName); if ((tw_Film.SelectedNode != null) && (TreeViewOPs.GetDeepestChildNodeLevel(tw_Film.SelectedNode) == 1)) { try { timer_Preview.Stop(); picBox_FilmPreview.Image = null; grpbox_FilmInfo.Hide(); FileOPs.RemoveFromXmlFile(parse.Find(f => f.filmProducer == tw_Film.SelectedNode.Parent.Text && f.filmTitle == tw_Film.SelectedNode.Text), filmFileName); TreeViewOPs.CreateFilmTree(tw_Film); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } }
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 print_Doc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { if (tc_Info.SelectedTab == tabPage_Book) { List <Book> parse = FileOPs.ParseBookXmlToList(bookFileName); Image image = Image.FromFile(parse.Find(b => b.bookAuthor == tw_Book.SelectedNode.Parent.Parent.Text && b.bookTitle == tw_Book.SelectedNode.Text).picturesPath[0]); PrivateFontCollection fontColl = new PrivateFontCollection(); fontColl.AddFontFile(AppDomain.CurrentDomain.BaseDirectory + @"\Fonts\Header.TTF"); fontColl.AddFontFile(AppDomain.CurrentDomain.BaseDirectory + @"\Fonts\Text.TTF"); Font myHeaderFont = new Font(fontColl.Families[0], 36f); Font myTextFont = new Font(fontColl.Families[1], 16f); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; e.Graphics.PageUnit = GraphicsUnit.Millimeter; e.Graphics.DrawString(txtbox_BookAuthor.Text, myHeaderFont, Brushes.Black, new Rectangle(0, 10, 205, 15), stringFormat); e.Graphics.DrawString(txtbox_BookTitle.Text, myHeaderFont, Brushes.Black, new Rectangle(0, 25, 205, 15), stringFormat); e.Graphics.DrawImage(image, 20, 40, 70, 100); e.Graphics.DrawString("Серия: " + txtbox_BookSeries.Text + " - " + txtbox_BookNumberInSeries.Text, myTextFont, Brushes.Black, 100, 50); e.Graphics.DrawString("Жанр: " + txtbox_BookGenre.Text, myTextFont, Brushes.Black, 100, 60); e.Graphics.DrawString("Кол-во страниц: " + txtbox_BookPagesCount.Text, myTextFont, Brushes.Black, 100, 70); e.Graphics.DrawString("Издание: " + txtbox_BookPublisher.Text + ", " + txtbox_BookPrintCity.Text + ", " + txtbox_BookPrintYear.Text, myTextFont, Brushes.Black, 100, 80); e.Graphics.DrawString("ISBN: " + msktxtbox_BookISBN.Text, myTextFont, Brushes.Black, 100, 90); e.Graphics.DrawString("Переводчик: " + txtbox_BookTranslator.Text, myTextFont, Brushes.Black, 100, 100); e.Graphics.DrawString("Художник: " + txtbox_BookArtist.Text, myTextFont, Brushes.Black, 100, 110); e.Graphics.DrawString("Заметки: " + txtbox_BookNotes.Text, myTextFont, Brushes.Black, 100, 120); } if (tc_Info.SelectedTab == tabPage_Film) { List <Film> parse = FileOPs.ParseFilmXmlToList(filmFileName); Image image = Image.FromFile(parse.Find(f => f.filmProducer == tw_Film.SelectedNode.Parent.Text && f.filmTitle == tw_Film.SelectedNode.Text).picturesPath[0]); PrivateFontCollection fontColl = new PrivateFontCollection(); fontColl.AddFontFile(AppDomain.CurrentDomain.BaseDirectory + @"\Fonts\Header.TTF"); fontColl.AddFontFile(AppDomain.CurrentDomain.BaseDirectory + @"\Fonts\Text.TTF"); Font myHeaderFont = new Font(fontColl.Families[0], 36f); Font myTextFont = new Font(fontColl.Families[1], 16f); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; e.Graphics.PageUnit = GraphicsUnit.Millimeter; e.Graphics.DrawString(txtbox_FilmProducer.Text, myHeaderFont, Brushes.Black, new Rectangle(0, 10, 205, 15), stringFormat); e.Graphics.DrawString(txtbox_FilmTitle.Text, myHeaderFont, Brushes.Black, new Rectangle(0, 25, 205, 15), stringFormat); e.Graphics.DrawImage(image, 20, 40, 70, 100); e.Graphics.DrawString("Жанр: " + txtbox_FilmGenre.Text, myTextFont, Brushes.Black, 100, 50); e.Graphics.DrawString("Актеры: " + txtbox_FilmActors.Text, myTextFont, Brushes.Black, 100, 60); e.Graphics.DrawString("Продолжительность: " + txtbox_FilmLength.Text + ", " + txtbox_BookPrintCity.Text + ", " + txtbox_BookPrintYear.Text, myTextFont, Brushes.Black, 100, 70); e.Graphics.DrawString("Страна: " + txtbox_FilmCountry.Text, myTextFont, Brushes.Black, 100, 80); e.Graphics.DrawString("Премьера: " + txtbox_FilmPremiere.Text, myTextFont, Brushes.Black, 100, 90); e.Graphics.DrawString("Рейтинг MPAA: " + txtbox_FilmMPAA.Text, myTextFont, Brushes.Black, 100, 100); e.Graphics.DrawString("Рейтинг критиков: " + txtbox_FilmCriticsRating.Text, myTextFont, Brushes.Black, 100, 110); e.Graphics.DrawString("Сборы ($): " + txtbox_FilmGrosses.Text, myTextFont, Brushes.Black, 100, 120); e.Graphics.DrawString("Заметки: " + txtbox_FilmNotes.Text, myTextFont, Brushes.Black, 100, 130); } }
private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e) { sfd_SaveXmlFile.InitialDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data"); sfd_SaveXmlFile.CreatePrompt = true; sfd_SaveXmlFile.OverwritePrompt = true; sfd_SaveXmlFile.RestoreDirectory = true; sfd_SaveXmlFile.Filter = "XML (*.Xml)|*.Xml|" + "All files (*.*)|*.*"; sfd_SaveXmlFile.SupportMultiDottedExtensions = true; sfd_SaveXmlFile.Title = "My Data file Browser"; //TBD refactor if (tc_Info.SelectedTab == tabPage_Book) { List <Book> parse = FileOPs.ParseBookXmlToList(bookFileName); if (sfd_SaveXmlFile.ShowDialog() == DialogResult.OK) { try { bookFileName = sfd_SaveXmlFile.FileName; FileOPs.SaveXmlFile(parse, bookFileName); } catch (SecurityException ex) { // The user lacks appropriate permissions to read files, discover paths, etc. MessageBox.Show("Security error. Please contact your administrator for details.\n\n" + "Error message: " + ex.Message + "\n\n" + "Details (send to Support):\n\n" + ex.StackTrace ); } catch (Exception ex) { // Could not load the image - probably related to Windows file system permissions. MessageBox.Show("Cannot open file: " + sfd_SaveXmlFile.FileName.Substring(sfd_SaveXmlFile.FileName.LastIndexOf('\\')) + ". You may not have permission to read the file, or " + "it may be corrupt.\n\nReported error: " + ex.Message); } } } if (tc_Info.SelectedTab == tabPage_Film) { List <Film> parse = FileOPs.ParseFilmXmlToList(filmFileName); if (sfd_SaveXmlFile.ShowDialog() == DialogResult.OK) { try { filmFileName = sfd_SaveXmlFile.FileName; FileOPs.SaveXmlFile(parse, filmFileName); } catch (SecurityException ex) { // The user lacks appropriate permissions to read files, discover paths, etc. MessageBox.Show("Security error. Please contact your administrator for details.\n\n" + "Error message: " + ex.Message + "\n\n" + "Details (send to Support):\n\n" + ex.StackTrace ); } catch (Exception ex) { // Could not load the image - probably related to Windows file system permissions. MessageBox.Show("Cannot open file: " + sfd_SaveXmlFile.FileName.Substring(sfd_SaveXmlFile.FileName.LastIndexOf('\\')) + ". You may not have permission to read the file, or " + "it may be corrupt.\n\nReported error: " + ex.Message); } } } }