public static void LoadCustomers() { using (FileManager fm = new FileManager(customerListFilePath)) { string s = fm.Read(); using (StringReader sr = new StringReader(s)) { XmlSerializer xmls = new XmlSerializer(typeof(List<Customer>)); customerList = (List<Customer>)xmls.Deserialize(sr); } } }
public static void Save(Customer c) { int i = customerList.FindIndex(x => x.ID == c.ID); if (i.Equals(-1)) { customerList.Add(c); } else { // customer window should be limited to one at a time // otherwise this could lead to overriding since the customer constructor gets a new id // (or conjure some other solution) customerList[i] = c; } XmlSerializer xmls = new XmlSerializer(typeof(List<Customer>)); using (StringWriter sw = new StringWriter()) { xmls.Serialize(sw, customerList); using (FileManager fm = new FileManager(customerListFilePath)) { fm.Write(sw.ToString()); } } }