本文介绍了如何在asp.net Web服务中使用日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的数据库中,有一个SchoolTerms表,该表具有term,start_date,End_date,Academic Year列.
我需要计算该期限内的总天数,注意,不包括周末和公共假期.
我使用以下查询,但不排除周末和公共假期.
In my database i''ve got a table SchoolTerms, which has the columns term,start_date, End_date, Academic year.
I need to calculate total number of days within that term, NB excluding weekends and public holidays.
I used the following query but it does not exclude weekends and public holidays.
SELECT distinct term,
DATEDIFF(DAY,StartDate,EndDate) TotalDays
FROM SchoolTerms
where EmisCode='500226884' and CurrentYear='2009';
我需要有关如何使用Web服务进行操作的指南.
i need guidelines on how to do this using a webservice.
推荐答案
<div id="TextBox1" runat="server"></div><br />
<asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" xmlns:asp="#unknown" />
和下面的代码一样
And code is like below
protected void Button1_Click(object sender, EventArgs e)
{
List<datetime> listholiday = new List<datetime>();
//Here you've to add public holiday list
listholiday.Add(new DateTime(2010, 1, 1));
//this is starting date
DateTime stdate = new DateTime(2010, 1, 1);
//this is end date
DateTime endate = new DateTime(2010, 2, 6);
int dys = endate.Subtract(stdate).Days;
int tdys = 0;
for (int i = 0; i < dys; i++)
{
if (stdate.AddDays(i).DayOfWeek.ToString().StartsWith("Satu") || stdate.AddDays(i).DayOfWeek.ToString().StartsWith("Sund"))
{
}
else
{
if (stdate.AddDays(i).Subtract(listholiday[0]).Days == 0)
{
}
else
{
tdys = tdys + 1;
}
}
}
TextBox1.InnerHtml = "total Days Excluding weekends and Holidays" + tdys.ToString()+"<br /> Total Holidays Including weekends"+dys.ToString ();
}
</datetime></datetime>
您可以改进此代码来满足您的要求.
您也可以在webservice中使用它
最好的
You can improve this code to achieve your requirement.
And you can use this in webservice also
All the Best
这篇关于如何在asp.net Web服务中使用日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!