示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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());
        }
示例#4
0
        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);
        }
示例#5
0
        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());
            }
        }