<%@ 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="C#" runat="server">
	void Page_load(Object sender,EventArgs e){
		if(IsPostBack!=true){
			Calendar1.Visible=false;//隐藏月历
		}
	}
	void BtnClick(Object sender,CommandEventArgs e){
		ErrDate.Visible=false;//隐藏日期错误的标签
		QueryResault.Visible=false;//隐藏DataGrid
		hi.Value=e.CommandName;//将目前按钮的执行参数保存至隐藏栏
		Calendar1.Visible=true;//显示月历
	}
	void DateOK(Object sender,EventArgs e){
		if(Calendar1.SelectedDates.Count==1){ //选择一天
			if(hi.Value=="1"){ //输入至起
				startDate.Text=Calendar1.SelectedDate.ToString("yyyy/MM/dd");
			}
			else{ //输入至迄
				endDate.Text=Calendar1.SelectedDate.ToString("yyyy/MM/dd");
			}
		}
		else if(Calendar1.SelectedDates.Count>1){ //选择周或月
			int x =Calendar1.SelectedDates.Count;//取得选取天数
			startDate.Text=Calendar1.SelectedDate.ToString("yyyy/MM/dd");
			DateTime v=Convert.ToDateTime(startDate.Text);
			DateTime v1=v.AddDays(x-1);//以v加上选取天数
			endDate.Text=v1.ToString("yyyy/MM/dd");
		}
		Calendar1.Visible=false;//隐藏月历
	}
	void OKClick(Object sender,EventArgs e){
		DataSet DS=new DataSet();
		try{
			 string x=Request.PhysicalPath; //取得路径及文件名
			 string u=x.Remove(x.Length-8,8);
			 string h = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + u + "stock.mdb";
			OleDbConnection NowConn = new OleDbConnection(h);
			NowConn.Open();
			OleDbDataAdapter NComm = new OleDbDataAdapter("select * from orders where ShippedDate between #" + startDate.Text + "# and #" + endDate.Text + "#", NowConn);
		       NComm.Fill(DS, "orders");
     		      NowConn.Close();
		      QueryResault.DataSource=DS.Tables["orders"].DefaultView; //设定来源
		      QueryResault.DataBind(); //结合
		      QueryResault.Visible=true; //显示在网页上
			
		}
		catch(Exception ex){ //日期错误
			ErrDate.Visible=true;
			ErrDate.Text="日期输入错误";
		}
	}
	</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" />
       <p> <asp:Label id=ftest runat="server" />
</form>
</body>