public static void UpdatePatient(AirwayPatient patient) { AirwayPatients airwayPatients = Deserialize(); int idx = airwayPatients.IndexOf(airwayPatients.FirstOrDefault(item => item.PatientId == patient.PatientId)); airwayPatients[idx] = patient; AirwayPatients.Serialize(airwayPatients); }
public void Save() { AirwayPatients airwayPatients = AirwayPatients.Deserialize(); for (int index = 0; index < airwayPatients.Count; index++) { AirwayPatient patient = airwayPatients[index]; if (patient.PatientId == this.PatientId) { airwayPatients[index] = this; } } AirwayPatients.Serialize(airwayPatients); }
public static void Serialize(AirwayPatients entity) { TestSave(entity); return; TextWriter tw = new StringWriter(); var formatter = new XmlSerializer(typeof(AirwayPatients)); formatter.Serialize(tw, entity); if (!Directory.Exists(Path.GetDirectoryName(Filename))) { Directory.CreateDirectory(Path.GetDirectoryName(Filename)); } File.WriteAllText(Filename, tw.ToString()); }
public static AirwayPatients TestLoad() { if (!File.Exists(Filename)) { MessageBox.Show("ûÓÐÊý¾Ý"); return(null); //TestSave(new AirwayPatients()); } var serializer = new DataContractSerializer(typeof(AirwayPatients)); AirwayPatients o = null; using (var stream = new MemoryStream(File.ReadAllBytes(Filename))) { o = serializer.ReadObject(stream) as AirwayPatients; } return(o); }
public static void TestSave(AirwayPatients patients) { if (!Directory.Exists(BaseFolder)) { Directory.CreateDirectory(BaseFolder); if (!File.Exists(Filename)) { //File.Create(Filename); File.Copy("AirwayPatients.xml", Filename, true); //File.WriteAllText(Filename,"<ArrayOfAirwayPatient></ArrayOfAirwayPatient>"); } } var serializer = new DataContractSerializer(typeof(AirwayPatients)); using (var stream = new MemoryStream()) { serializer.WriteObject(stream, patients); File.WriteAllBytes(Filename, stream.ToArray()); } }