For number of days calculation, total days and total number of working days. Do the following steps :
1. Design the form like below
2. Add the below code in the button events
public void WorkingDays_Clicked(object sender, ClickedEventArgs e)
{
int CalculateDays = 1;
XPathNavigator Main = MainDataSource.CreateNavigator();
DateTime startDate = DateTime.Parse(Main.SelectSingleNode("/my:myFields/my:StartDate",NamespaceManager).Value);
DateTime endDate = DateTime.Parse(Main.SelectSingleNode("/my:myFields/my:EndDate", NamespaceManager).Value);
TimeSpan span =endDate.Subtract(startDate);
for(int i= 1;i<=span.Days;i++)
{
startDate = startDate.AddDays(1);
if(startDate.DayOfWeek !=DayOfWeek.Sunday && startDate.DayOfWeek !=DayOfWeek.Saturday)
{
CalculateDays++;
}
}
Main.SelectSingleNode("/my:myFields/my:WorkingDays",NamespaceManager).SetValue(CalculateDays.ToString());
}
public void TotalDays_Clicked(object sender, ClickedEventArgs e)
{
int CalculateDays = 1;
XPathNavigator Main = MainDataSource.CreateNavigator();
DateTime startDate = DateTime.Parse(Main.SelectSingleNode("/my:myFields/my:StartDate", NamespaceManager).Value);
DateTime endDate = DateTime.Parse(Main.SelectSingleNode("/my:myFields/my:EndDate", NamespaceManager).Value);
TimeSpan span = endDate.Subtract(startDate);
for (int i = 1; i <= span.Days; i++)
{
startDate = startDate.AddDays(1);
CalculateDays++;
}
Main.SelectSingleNode("/my:myFields/my:TotalDays", NamespaceManager).SetValue(CalculateDays.ToString());
}
No comments:
Post a Comment