按周查询报表,获取开始和截止时间
aspx页面
按周查询: <asp:DropDownList ID="drpYear2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="drpYear2_SelectedIndexChanged"></asp:DropDownList> <asp:DropDownList ID="drpWeek" runat="server"></asp:DropDownList>
<asp:Button ID="btnAdvancedSearchConfirm2" runat="server" OnClick="btnAdvancedSearchConfirm2_Click"
Text="【查询】" CssClass="submit"/>
//获取开始和截止时间
DateTime beginTime ;
DateTime endTime ;
string[] arr = StringHelper.SplitString(drpWeek.SelectedValue, "#");
beginTime = DataConverter.StrToDateTime(arr[0], DateTime.Now);
endTime = DataConverter.StrToDateTime(arr[1], DateTime.Now);
private void drpYear_DataBind()
{
for (int min = DateTime.Now.Year - 10; min <= DateTime.Now.Year; min++)
{
ListItem item = new ListItem(min.ToString());
drpYear.Items.Add(item);
drpYear2.Items.Add(item);
}
drpYear.SelectedValue = DateTime.Now.Year.ToString();
drpYear2.SelectedValue = DateTime.Now.Year.ToString();
}
private void drpWeek_DataBind()
{
drpWeek.Items.Clear();
DateTime beginTime = DataConverter.StrToDateTime(string.Format("{0}-1-1", drpYear2.SelectedValue), DateTime.Now.Date);
DateTime endTime = beginTime.AddYears(1).AddSeconds(-1).Date;
int dayOfWeek = (int) beginTime.DayOfWeek;
if(dayOfWeek == 0)
dayOfWeek = 7;
beginTime = beginTime.AddDays((8 - dayOfWeek) % 7);
dayOfWeek = (int)endTime.DayOfWeek;
if (dayOfWeek == 0)
dayOfWeek = 7;
endTime = endTime.AddDays(7 - dayOfWeek);
for (DateTime i = beginTime; i <= endTime;)
{
DateTime endOfWeek = i.Date.AddDays(6);
ListItem item = new ListItem(string.Format("{0}至{1}", i.Date.ToString("MM-dd"), endOfWeek.Date.ToString("MM-dd")), string.Format("{0}#{1}", i.Date.ToString("yyyy-MM-dd"), endOfWeek.Date.ToString("yyyy-MM-dd")));
drpWeek.Items.Add(item);
i = endOfWeek.Date.AddDays(1);
}
}
protected void drpYear2_SelectedIndexChanged(object sender, EventArgs e)
{
drpWeek_DataBind();
}