private void Display() { AppointmentList li = ReadXML(); dataGrids = new List <DataGridAppointment>(); foreach (Appointment ap in li) { DataGridAppointment dg = new DataGridAppointment(); dg.Paitent = ap.Paitent.FirstName + " " + ap.Paitent.LastName; dg.Doctor = ap.Doctor.FirstName + " " + ap.Doctor.LastName; dg.Date = ap.Date; dg.Time = ap.Time; dg.Problem = ap.Problem; dataGrids.Add(dg); } appointmentGrid.ItemsSource = dataGrids; }
private AppointmentList ReadXML() { AppointmentList appList = null; //XML Deserialization,reading the xml file saved on disk and putting it in c# object which is later set to datagrid try { using (var reader = XmlReader.Create(@"Appointments.xml")) { XmlSerializer deserializer = new XmlSerializer(typeof(AppointmentList)); appList = (AppointmentList)deserializer.Deserialize(reader); } } catch (Exception e) { MessageBox.Show("Error in reading file"); } return(appList); }
private void SaveData(Appointment appointment) { AppointmentList appointmentList = MainWindow.AppointmentList; appointmentList.Add(appointment); try { //XML serialization,converting c# object to XML and saving it in a file XmlSerializer serializer = new XmlSerializer(typeof(AppointmentList)); TextWriter writer = new StreamWriter("Appointments.xml"); serializer.Serialize(writer, appointmentList); writer.Close(); MessageBox.Show("Data saved successfully"); } catch (Exception e) { MessageBox.Show("Error in writing to XML file"); } }
public MainWindow() { InitializeComponent(); Loaded += MainWindow_Loaded; AppointmentList = new AppointmentList(); }