0

可能重复:
根据日期,从 XML 获取今天和接下来两天的值?

我之前问过一些问题,感谢 stackoverflow 的出色帮助,我已经解决了很多主要问题。谢谢你们!如果我的问题很愚蠢,我感到非常抱歉,但在 stackoverflow 上提问之前,我已经尽可能多地使用谷歌搜索。

我还有一个工作页面,我可以在其中获取特定的祈祷时间并填充文本块。请参阅此链接和我标记的问题以及解决方案。我在课堂上使用公共时间跨度和 var 查询:

如何根据当前时间制作 if 语句以显示 xml 属性

我仍在开发穆斯林祈祷时间应用程序,并希望用今天+接下来的 3 天祈祷时间填充列表框。

    DateTime myDay = DateTime.Now;
    XDocument loadedCustomData = XDocument.Load("WimPrayerTime.xml");
    var filteredData = from c in loadedCustomData.Descendants("PrayerTime")
                       where c.Attribute("Day").Value == myDay.Day.ToString()
                       && c.Attribute("Month").Value == myDay.Month.ToString()

                       select new PrayerTime()
                       {
                           Fajr = c.Attribute("Fajr").Value,
                           Soloppgang = c.Attribute("Soloppgang").Value,
                           Zohr = c.Attribute("Zohr").Value,
                       };

    listBox1.ItemsSource = filteredData;

我的班级是:

public class Prayertime
{

   public string Fajr { get; set; }
   public string Sunrise { get; set; }
   public string Zohr { get; set; }

}

我的本地 XML 文件(始终包含在它自己的应用程序中)

<PrayerTime
    Day ="30" 
    Month="4" 
    Fajr="07:00" 
    Sunrise="09:00"
    Zuhr="14:00"
/>
<PrayerTime
    Day ="1" 
    Month="5" 
    Fajr="07:05" 
    Sunrise="09:05"
    Zuhr="14:05"
/>
<PrayerTime
    Day ="2" 
    Month="5" 
    Fajr="07:10" 
    Sunrise="09:10"
    Zuhr="14:10"
/>

首先,如何更改此代码以显示今天加上接下来三天的列表?

where c.Attribute("Day").Value == myDay.Day.ToString()

或者我应该每天做一个查询, DateTime NextDay = DateTime.Now.AddDays(1)等等?我如何用三个或四个这样的不同查询填充同一个列表框?我可以重复一下吗:

listBox1.ItemsSource = filteredData1;
listBox1.ItemsSource = filteredData2;
listBox1.ItemsSource = filteredData3;

另外,当月份变化时该怎么办?例如,如果日期为 30,月份为 4,那么第二天的值为 1,月份应显示为 5?

最后但并非最不重要的......当显示我希望列表框显示的信息时,如下所示:

Monday 30.04.2012
Fajr        07:00
Sunrise     09:00
Zuhr        14:00

Tuesday 01.05.2012
Fajr        07:05
Sunrise     09:10
Zuhr        14:10

我在属性名称和值以及上面的日期/日期之间有一个固定的间距。

非常感谢所有花时间阅读的人,也非常感谢所有回答的人:)

4

1 回答 1

0

试试这个:

where int.Parse(c.Attribute("Day").Value) >= myDay.Day && int.Parse(c.Attribute("Day").Value) < (myDay.Day + 3)
于 2012-05-08T11:56:58.520 回答