private void ArtistArtwork(object sender, RoutedEventArgs e) { // Creates a new artwork instance var loadArtwork = new Artwork(); List <Artwork> ARTWORKSBYARTIST = new List <Artwork>(); int ID = int.Parse(ArtistID1textBOX.Text); loadArtwork.loadArtist(ArtistList, ArtworkList, ID, ARTWORKSBYARTIST); ArtworkByArtistdisplay.Items.Clear(); foreach (var art in ARTWORKSBYARTIST) { ArtworkByArtistdisplay.Items.Add("Artwork Description: " + art.ThisArtworkDescription); ArtworkByArtistdisplay.Items.Add("Artwork Price: " + "£" + art.ThisArtworkPrice); } }
private void Load_Click(object sender, RoutedEventArgs e) { try { /// Loads Artwork and artist List if (File.Exists("ArtworkList.xml")) { XmlSerializer deserializer = new XmlSerializer(typeof(List <Artwork>)); StreamReader textReader = new StreamReader("ArtworkList.xml"); ArtworkList = (List <Artwork>)deserializer.Deserialize(textReader); textReader.Close(); } if (File.Exists("ArtistList.xml")) { XmlSerializer deserializer = new XmlSerializer(typeof(List <Artist>)); StreamReader textReader = new StreamReader("ArtistList.xml"); ArtistList = (List <Artist>)deserializer.Deserialize(textReader); textReader.Close(); } // Create a new artwork instance var loadArtwork = new Artwork(); // New artwork list intialised List <Artwork> ARTWORKSBYARTIST = new List <Artwork>(); // Input by user changed into useable variable int ID = int.Parse(ArtistID1textBOX.Text); /// Calls method contained in class loadArtwork.loadArtist(ArtistList, ArtworkList, ID, ARTWORKSBYARTIST); // Clears the display ArtworkByArtistdisplay.Items.Clear(); foreach (var art in ARTWORKSBYARTIST) { /// All of the artist artwork is displayed ArtworkByArtistdisplay.Items.Add("Artwork Description: " + art.ThisArtworkDescription); ArtworkByArtistdisplay.Items.Add("Artwork Price: " + "£" + art.ThisArtworkPrice); } } catch (Exception ex) { MessageBox.Show("Artist ID has to be a number"); } }
private void SaveArtwork(object sender, RoutedEventArgs e) { try { /// Load the artwork list if (File.Exists("ArtworkList.xml")) { XmlSerializer deserializer = new XmlSerializer(typeof(List <Artwork>)); StreamReader textReader = new StreamReader("ArtworkList.xml"); ArtworkList = (List <Artwork>)deserializer.Deserialize(textReader); textReader.Close(); } /// User input of the artist ID int ArtistID = int.Parse(ArtistID1textBOX.Text); /// Sends artistlist to array Artist[] artistx = ArtistList.ToArray(); var array = artistx; var artwork = new Artwork(); var artistt = ArtistList.Any(p => p.ThisArtistID == ArtistID); artwork.HoldArtistID = ArtistID; artwork.ThisArtworkDescription = DescriptionTextBox.Text; artwork.ThisArtworkPrice = decimal.Parse(PriceTextBox.Text); ArtworkList.Add(artwork); /// Search through list for (int i = 0; i < ArtworkList.Count(); i++) { foreach (var Artwork in ArtworkList) { /// sets the ID value if (ArtworkList.Count() == 1) { Artwork.ThisArtworkID = ArtworkList.Count(); } else { artwork.ThisArtworkID = ArtworkList.Count() - 1; } } } /// Save artwork Data Savexml.SaveArtworkData(ArtworkList, "ArtworkList.xml"); ///assign to the artist if (File.Exists("ArtistList.xml")) { XmlSerializer deserializer = new XmlSerializer(typeof(List <Artist>)); TextReader textReader = new StreamReader("ArtistList.xml"); ArtistList = (List <Artist>)deserializer.Deserialize(textReader); textReader.Close(); } Artist a = new Artist(); a.AssignArtworkToArtist(ArtistList, ArtworkList); } catch (Exception ex) { MessageBox.Show("Artist ID and price are numbers"); } }