//Hae Viinit nappula private void btnGetData_Click(object sender, RoutedEventArgs e) { string filename = ConfigurationManager.AppSettings.Get("PathToGlory"); wines = wines.DeserializeXML(filename); if (cmbCountrySelect.Items.IsEmpty) { cmbCountrySelect.Items.Add("Kaikki"); } cmbCountrySelect.SelectedIndex = 0; foreach (Wine w in wines.Wines) { if (!cmbCountrySelect.Items.Contains(w.Maa)) cmbCountrySelect.Items.Add(w.Maa); } dtgData.ItemsSource = wines.Wines; }
public WineCellar DeserializeXML(string filename) { try { XmlSerializer serializer = new XmlSerializer(typeof(WineCellar)); StreamReader fs = new StreamReader(filename); WineCellar winecellar; winecellar = (WineCellar)serializer.Deserialize(fs); return winecellar; } catch (FileNotFoundException ef) { MessageBox.Show(ef.Message); WineCellar emptycellar = new WineCellar(); return emptycellar; } catch (Exception ex) { MessageBox.Show("you broke it :<" + ex.Message); WineCellar emptycellar = new WineCellar(); return emptycellar; } }