Friday, 2 January 2015

Searching (Filtering) XML by week in C#



Here is my code for filtering part. I am trying to filter appointments by week. I want my output to be like, when i am selecting a certain date from DateTimePicker it is going to display appointments for seven days (which is a week) starting from the date I selected. Please, I need urgent help. Deadline for my project is in two days. Thank you in advance.



private void loadDatabyWeek()
{
listView1.Items.Clear();
XDocument appointxml = XDocument.Load("appointments.xml");

var appnt =
from appoint in appointxml.Descendants("appointRecord")
where DateTime.Parse(appoint.Element("date").Value) >= dateTimePicker1.Value.AddDays(-7)
select new
{
Date = appoint.Element("date").Value,
Time = appoint.Element("time").Value,
Client = appoint.Element("cliName").Value,
BMI = appoint.Element("bmi").Value,
BodyFat = appoint.Element("bFat").Value,
BodyWater = appoint.Element("bWater").Value,
FatMass = appoint.Element("fatMass").Value,
Waist = appoint.Element("waist").Value,
Hip = appoint.Element("hip").Value,
OtherNotes = appoint.Element("otherNotes").Value,
Income = appoint.Element("income").Value
};

bool format = false;

foreach (var app in appnt)
{
format = true;
ListViewItem lvi = new ListViewItem(app.Date);
lvi.SubItems.Add(app.Time);
lvi.SubItems.Add(app.Client);
lvi.SubItems.Add(app.BMI);
lvi.SubItems.Add(app.BodyFat);
lvi.SubItems.Add(app.BodyWater);
lvi.SubItems.Add(app.FatMass);
lvi.SubItems.Add(app.Waist);
lvi.SubItems.Add(app.Hip);
lvi.SubItems.Add(app.OtherNotes);
lvi.SubItems.Add(app.Income);
listView1.Items.Add(lvi);
}

if (format == false)
MessageBox.Show("Doesn't Exist!");
}

No comments:

Post a Comment