Hi, this is going to be a very broad question and any info or suggestions are welcome!

I am writing an application which uses a Mon-Sunday approach with times slots from 9.30am till 7.30pm. These time slots can be filled in with data (a single string). Currently this data is saved to an string array (fixed size, each position in the array is a time). I then save this via XML Serialization and de-serialize ir when loading the program.

The problem is.. I want this program to enter data for any day/date, currently it only supports the current day and the next 6 days. (Monday-Tue-Wed-Thu-Fri-Sat-Sun) string arrays..

What would be the best way to approach this problem? I was thinking of using the selected dtaes string as a filename (i.e. 16/02/2010) (16022010) and saving the information inside this file. The same would be done with any other date which has data entered via the UI. The only issue here is the clutter it would create, although I guess I could handle the file deletion also...

However, what would people's vies be on this? any better methods? I am not saying my method's are great at all, just what I can come up with :)


I'm open to any suggestions at all! Just need a few good ideas or solutions to this problem. Thanks :)

Personally I would use a database. As you can use arbitrary time slots though, your method of using XML is a good one.

However, you will need to jig around your XML format a little.

So rather than a string array, make an object that contains your appointments (I have no idea what they actually represent but I'm sure you'll get the idea) a timetable and a user object also.

So let's start with a description of your appointment object. From your requirements I'm guessing that you simply need to hold a DateTime and a String describing what is happening at that time. That's pretty much it done.

public class Appointment
   public DateTime AppointmentTime;
   public String Description;

Ok so now we have somewhere to store our appointment. You can no go one of two ways. You can store an array of Appointments inside your User object, or, you can store them inside a single TimeTable class. Then the user can hold an array of TimeTables.

Let's go with option two as this allows more flexibility later in the software design, if it's needed.

The job of the TimeTable object for now, is to simply store the list of Appointments.

public class TimeTable
   private List<Appointment> _appointmentList = new List<Appointment>();
   public IList<Appointment> AppointmentList { get return _appointmentList; }

As you can see I'm holding a private List and returning an IList. IList is read only (as it's an interface) and shouldn't allow you to save any new records to the AppointmentList. I'll leave it to you to add a method which allows you to add appointments (It should perform validation and error checking).

Finally, there's the user object. A timetable by itself with no means of identification really doesn't mean anything. But a User doesn't have to be a person. It could be a class, or a hospital or a meeting room.

For this reason, it's probably a good idea to leave it as "User" but to also add a String as what the User is.

public class User
   private List<TimeTable> _timeTableList = new List<TimeTable>();

   public IList<TimeTable> TimeTableList { get { return _timeTableList; } }

   public String UserType = String.Empty;
   public String Description = String.Empty;

   public Boolean AddTimeTable(TimeTable newTimeTable)
   { /* Do Error check and stuff */ }

That's pretty much it. As a starting point for saving your files, I suggest you create a Singleton or static class. This class will have a "SaveUsers" method which takes an array of the User object.

The SaveUsers method will then make use of the XmlDocument class to create the XmlDocument and write the User objects and their properties to the file.

To make it more advanced, you could create an Update and Delete method which searches through the XML file and performs the respective operation.

Hope this helped.

commented: serialised list is a good approach :) +1

Thankyou very much for taking the time to write out the code examples and detailed explanations, I really appreciate that. This has definitely helped me in understanding how I should proceed and solve this issue now.

Thank you very much. :)