<%@ Register TagPrefix="Title" TagName="TitleShow" Src="/aspnetdata/Title.ascx" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System" %>
<html>
<head>
	<script language="VB" runat="server">
	SUB Page_load(sender as object,e as EventArgs)
		if IsPostBack<>true then
			Calendar1.Visible=false'隐藏月历
		end if
	end sub
	SUB BtnClick(sender as Object,e as CommandEventArgs)
		ErrDate.Visible=false'隐藏日期错误之标签
		QueryResault.Visible=false'隐藏DataGrid
		hi.Value=e.CommandName'将目前按钮的执行参数储存至隐藏栏位
		Calendar1.Visible=true'显示月历
	end sub
	SUB DateOK(sender as Object,e as EventArgs)
		if Calendar1.SelectedDates.Count=1 then '选择一天
			if hi.Value="1" then '输入至起
				startDate.Text=Calendar1.SelectedDate.ToString("yyy/MM/dd")
			else '输入至迄
				endDate.Text=Calendar1.SelectedDate.ToString("yyy/MM/dd")
			end if
		elseif Calendar1.SelectedDates.Count>1 then '选择周或月
			dim x as integer =Calendar1.SelectedDates.Count '取得选取天数
			startDate.Text=Calendar1.SelectedDate.ToString("yyyy/MM/dd")
			dim v as DateTime = Convert.ToDateTime(startDate.Text)
			dim v1 as DateTime = v.AddDays(x-1) '以v加上选取天数
			endDate.Text=v1.ToString("yyyy/MM/dd")
		end if
		Calendar1.Visible=false '隐藏月历
	end sub
	SUB OKClick(sender as Object,e as EventArgs)
		dim DS as DataSet=new DataSet()
		try
			dim x as string=Request.PhysicalPath '取得路径及档名
			dim u as string =x.Remove(x.Length-8,8)
			dim h as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + u + "stock.mdb"
			dim NowConn as OleDbConnection = new OleDbConnection(h)
			dim NComm as OleDbDataAdapter = new OleDbDataAdapter("select * from orders where ShippedDate between #" + startDate.Text + "# and #" + endDate.Text + "#", NowConn)
			NComm.Fill(DS, "orders")
			QueryResault.DataSource=DS.Tables("orders").DefaultView '设定来源
			QueryResault.DataBind() '结合
			QueryResault.Visible=true '显示在网页上
		catch ex as Exception '日期错误
			ErrDate.Visible=true
			ErrDate.Text="日期输入错误"
		end try
	end sub
	</script>
</head>
<body background="/aspnetdata/images/winback.gif">
<Title:TitleShow id="BookT" Runat="server" />
<form runat="server">
<input id="hi" type=hidden value="" runat=server>
输入或指定起始日期<asp:TextBox id="startDate" Width="90" runat="server"/><asp:Button OnCommand="BtnClick" CommandName="1" Text="..." Runat="server"/>
至<asp:TextBox id="endDate" Width="90" runat="server"/>
<asp:Button OnCommand="BtnClick" CommandName="2" Text="..." Runat="server"/>
<asp:Button OnClick="OKClick" Text="确定" Runat="server"/>
        <asp:Calendar id=Calendar1 runat="server"
	    onselectionchanged="DateOK"
            DayNameFormat="Short"
            SelectionMode="DayWeekMonth"
            Font-Name="Verdana;Arial" Font-Size="12px"
            Height="180px" Width="230px"
            TodayDayStyle-Font-Bold="True"
            DayHeaderStyle-Font-Bold="True"
            OtherMonthDayStyle-ForeColor="gray"
            TitleStyle-BackColor="#3366ff"
            TitleStyle-ForeColor="white"
            TitleStyle-Font-Bold="True"
            SelectedDayStyle-BackColor="#ffcc66"
            SelectedDayStyle-Font-Bold="True"
            NextMonthText = "<img src='monthright.gif' border=0>"
            PrevMonthText = "<img src='monthleft.gif' border=0>"
            SelectorStyle-BackColor="#99ccff"
            SelectWeekText = "<img src='selweek.gif' border=0 onmouseover=this.style.backgroundColor='#ffcc66' onmouseout=this.style.backgroundColor='#99ccff'>"
            SelectMonthText = "<img src='selmonth.gif' border=0 onmouseover=this.style.backgroundColor='#ffcc66' onmouseout=this.style.backgroundColor='#99ccff'>"
            />

      <ASP:DataGrid id="QueryResault" runat="server"
        BorderColor="black"
        BorderWidth="1"
        GridLines="Both"
        CellPadding="3"
        CellSpacing="0"
        Font-Name="Verdana"
        Font-Size="8pt"
        HeaderStyle-BackColor="#aaaadd"
      />

       <p> <asp:Label id=ErrDate runat="server" />
</form>
</body>