Hi KP,
You can add a XML file in your project and read scheduled time from it when need.
Add a XML file like below:
<?xml version="1.0" encoding="utf-8" ?>
<ScheduledTime>
<Time>
<DayOfWeek>Monday</DayOfWeek>
<Hour>2</Hour>
<Minute>20</Minute>
</Time>
<Time>
<DayOfWeek>Tuseday</DayOfWeek>
<Hour>13</Hour>
<Minute>30</Minute>
</Time>
<Time>
<DayOfWeek>Sunday</DayOfWeek>
<Hour>18</Hour>
<Minute>40</Minute>
</Time>
</ScheduledTime>
When you need the scheduled time, use the following code:
static void Main(string[] args)
{
XDocument doc = new XDocument();
doc = XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + "\\datetimesample.xml");
var scheduledtimes = doc.Root.Elements().Select(s => new ScheduledTime()
{
DayOfWeek = s.Element("DayOfWeek").Value,
Hour = Int32.Parse(s.Element("Hour").Value),
Minute = Int32.Parse(s.Element("Minute").Value)
}).ToList();
System.IO.FileInfo fi = new System.IO.FileInfo("");
CheckDateTimeAvailable(scheduledtimes, fi.CreationTime);
Console.Read();
}
public static bool CheckDateTimeAvailable(List<ScheduledTime> listtime, DateTime time)
{
bool flag = false;
int count = listtime.Count(w => w.DayOfWeek == time.DayOfWeek.ToString() && w.Hour == time.Hour && w.Minute == time.Minute);
if (count > 0)
{
flag = true;
}
return flag;
}
public class ScheduledTime
{
public string DayOfWeek { get; set; }
public int Hour { get; set; }
public int Minute { get; set; }
}
You should make some changes to fit your project.
Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
No comments:
Post a Comment