<%@Page Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Register TagPrefix="Diss_Cate" Namespace="Diss_cs" Assembly="Diss_cs" %>
<%@ Import Namespace="DissData_cs" %>
<html>
<head>
<style type="text/css">
<!--
A:link {color: blue; text-decoration: none}
A:hover {color:red; text-decoration: none}
A:Visited {text-decoration: none}
-->
<!--
table { font-size: 11 pt;    		
	font-family: 新细明体, 细明体, Mingli, Verdana, Arial, Helvetica  }
-->
<!--
body { font-size: 11 pt;    		
	font-family: 新细明体, 细明体, Mingli, Verdana, Arial, Helvetica  }
-->
</style>
	<script language="C#" runat="server">
	void Page_load(Object sender, EventArgs e){
		GetCate.ServerName=Session["NowSQLServer"].ToString();
		GetCate.Uid=Session["Nowuid"].ToString();
		GetCate.Pass=Session["NowPassword"].ToString();
		GetCate.DBName=Session["NowDBName"].ToString();
		if(IsPostBack==false){
			if(Session["Lg_ok"]!="-1"){//若尚未登陆
				Session["NowFile"]=Request.RawUrl;//记住本次网址
				lg.Visible=true;//显示登录按钮
				go.Visible=true;
			}			
			else{
				lg.Visible=false;
				go.Visible=false;
			}
			GetCate.FirstLoad=true;//第一次加载
			string x1;
			x1=Request.QueryString["NowCateID"];
			if(x1== ""){
				x1="1";
			}
			GetCate.NowSelect=Convert.ToInt32(x1);//设定目前类别ID
			DateTime t = Convert.ToDateTime("2002/03/18");//DateTime.Now;
			int y = Convert.ToInt32(t.DayOfWeek);
			DateTime StartDate,EndDate;
			if(Request.QueryString["StartDate"] != null ){
				DateTime g=Convert.ToDateTime(Request.QueryString["StartDate"]);
				StartDate = g.AddDays(0-y+1);
				EndDate = StartDate.AddDays(6);//加六天
			}
			else{
				StartDate = t.AddDays(0 - y + 1);//取得起始日
				EndDate = StartDate.AddDays(6);//加六天
			}
			GetCate.StartDate=StartDate;
			GetCate.EndDate=EndDate;
			if(Request.QueryString["GetSession"]=="True"){
				bindNew(false);
			}
			else{
				bindNew(true);
			}
		}
	}
	void ViewDetail(Object sender, CommandEventArgs e) {
		Response.Redirect("View.aspx?StartDate=" + GetCate.StartDate.ToString() + "&CID=" + e.CommandArgument + "&NowCateID=" + GetCate.NowSelect + "&NowCate=" + GetCate.NowCate);
	}
	void Full_Click(Object sender, EventArgs e){
		Response.Redirect("Search.aspx");
	}
	void ToNew_Click(Object sender, EventArgs e){
		Response.Redirect("WriteNew.aspx");
	}
	void moveweek(Object sender, CommandEventArgs e){
		if(e.CommandArgument=="PrevWeek"){
			GetCate.StartDate=GetCate.StartDate.AddDays(-7);
			GetCate.EndDate=GetCate.EndDate.AddDays(-7);
		}
		else{
			GetCate.StartDate=GetCate.StartDate.AddDays(7);
			GetCate.EndDate=GetCate.EndDate.AddDays(7);
		}
		GetCate.FirstLoad=true;
		bindNew(true);
	}
	void bindNew(Boolean tag){
		DataTable NowTable=null;
		if(tag == true){
			DissSql NewDiss = (DissSql)Session["NowDissSql"];
			string c=GetCate.StartDate.ToString("yyyy/MM/dd");
			string d=GetCate.EndDate.ToString("yyyy/MM/dd");
			NowTable = NewDiss.GetDataTable(GetCate.NowSelect,c,d);
			Session["NowDiss"]=NowTable;
		}
		else{
			if(Session["NowDiss"] == null){//若为空值，回至首页
				Response.Redirect("Default.aspx");
			}
			NowTable = (DataTable)Session["NowDiss"];
		}
		Re0.DataSource=NowTable.DefaultView;
		Re0.DataBind();
		if(Session["Lg_ok"]=="-1"){
			Re0.Columns[0].Visible = true;
			Re0.Columns[1].Visible = false;
			ToNew.Visible=true;
			Full.Visible=true;
		}
		else{
			Re0.Columns[0].Visible = false;
			Re0.Columns[1].Visible = true;
			ToNew.Visible=false;
			Full.Visible=false;
		}
	}
	void Get_Click(Object sender, CommandEventArgs e){
		bindNew(true);
	}
	</script>
</head>
<body background="../../../images/winback.gif">
<form runat="server">
<img runat="server" id="go" src="go.gif" align="middle"><asp:hyperlink text="登录" navigateurl="Login.aspx" runat="server" id="lg" />
<p><Diss_Cate:GetCate ID="GetCate" onCommand="Get_Click" Runat="server" />
<asp:LinkButton Text="前一周" id="prev" oncommand="moveweek" commandargument="PrevWeek" runat="server" />　<asp:LinkButton Text="下一周" id="next" oncommand="moveweek" commandargument="NextWeek" runat="server" /><p>
<p><asp:LinkButton Text="发表新意见" id="ToNew" onclick="ToNew_Click" runat="server" />　<asp:LinkButton Text="全文检索" id="Full" onclick="Full_Click" runat="server" />
<asp:DataGrid ID="Re0" Runat="server"
        BorderWidth="0"
        CellPadding="3"
        CellSpacing="0"
	width="600"
        Font-Name="Verdana"
        Font-Size="9pt"
        HeaderStyle-BackColor="Blue"
        HeaderStyle-ForeColor="White"
	DataKeyfield="id"
	AutoGenerateColumns="false"
 >

      <Columns>
<asp:TemplateColumn HeaderText="主题" itemstyle-width="300">
          <ItemTemplate>
<asp:LinkButton runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "subject") %> CommandArgument=<%# DataBinder.Eval(Container.DataItem, "id") %> Oncommand="ViewDetail" id="d1"/>
          </ItemTemplate>
        </asp:TemplateColumn>
<asp:TemplateColumn HeaderText="主题" itemstyle-width="300">
          <ItemTemplate>
<asp:Label runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "subject") %> id="ld1"/>
          </ItemTemplate>
        </asp:TemplateColumn>
        <asp:BoundColumn HeaderText="发送人" DataField="send"/>
        <asp:BoundColumn HeaderText="发送时间" DataField="nowtime"/>
     </Columns>
</asp:Datagrid>


</form>
</body>