<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="DissData_cs" %>
<html>
<head>
	<script language="C#" runat="server">
	DissSql NowDissSQL=null;
	void Page_load(object sender,EventArgs e){
		if(IsPostBack==false){
			if(Session["NowDissSQL"]!=null){
				gData.Visible=false;
				diss.Visible=true;
			}
			else{
				gData.Visible=true;
				diss.Visible=false;
				return;
			}
		}
			if(Session["Lg_ok"]!="-1"){
				gData.Visible=true;
				diss.Visible=false;
				Session["NowFile"]=Request.RawUrl;
				lg.Visible=true;
				go.Visible=true;
				ToNew.Visible=false;
				Full.Visible=false;
			}
			else{
				gData.Visible=false;
				diss.Visible=true;
				lg.Visible=false;
				go.Visible=false;
				ToNew.Visible=true;
				Full.Visible=true;
				DissSql NowDissSQL=(DissSql)Session["NowDissSQL"];
				DataTable Cate =NowDissSQL.GetAllCate();
				AllcateBind(Cate);
			}
	}
	void cate_Click(object sender,CommandEventArgs e){
		Response.Redirect("Showsbj.aspx?NowCateID=" + e.CommandArgument.ToString());
	}
	void Full_Click(object sender,EventArgs e){
		Response.Redirect("Search.aspx");
	}
	void ToNew_Click(object sender,EventArgs e){
		Response.Redirect("WriteNew.aspx");
	}
	void OKClick(object sender,EventArgs e){
		if(SQLSeerver.Text!=""){
			NowDissSQL = new DissSql(SQLSeerver.Text,uid.Text,Password.Text,"EmploySQL");
			Session["NowSQLServer"]=SQLSeerver.Text;
			Session["Nowuid"]=uid.Text;
			Session["NowPassword"]=Password.Text;
			Session["NowDBName"]="EmploySQL";
			DataTable Cate =NowDissSQL.GetAllCate();
			Session["NowDissSql"]=NowDissSQL;
			gData.Visible=false;
			diss.Visible=true;
			AllcateBind(Cate);
		}
		else{
			err.Text="未输入SQL服务器名称";
		}
	}
	void AllcateBind(DataTable t){
		AllCate.DataSource=t.DefaultView;
		AllCate.DataBind();
		gData.Visible=false;
		diss.Visible=true;
	}
	</script>
</head>
<body background="/aspnetdata/images/winback.gif">
<form runat="server">
<asp:panel id="gData" runat="server" >
SQL服务器名称：<ASP:TEXTBOX Text="Localhost" runat="server" id="SQLSeerver" /><br>
登录ID：<ASP:TEXTBOX Text="sa" runat="server" id="uid" /><br>
密码：<ASP:TEXTBOX Runat="server" TextMode="Password" id="Password" /><ASP:button Text="OK" Runat="server" onclick="OKClick" /><br>
<asp:Label id="err" runat="server" />
</asp:panel>
<asp:panel id="diss" visible="false" runat="server" >
<p>
<img runat="server" id="go" src="go.gif" align="middle"><asp:hyperlink text="登录" navigateurl="Login.aspx" runat="server" id="lg" />
<br><asp:LinkButton Text="发表新意见" id="ToNew" onclick="ToNew_Click" runat="server" />　<asp:LinkButton Text="全文检索" id="Full" onclick="Full_Click" runat="server" />
<table align="center"><tr><td align="center"><ASP:DataGrid id="AllCate" runat="server"
        BorderColor="black"
        BorderWidth="1"
        GridLines="Both"
        CellPadding="3"
        CellSpacing="0"
        Font-Name="Verdana"
        Font-Size="9pt"
        HeaderStyle-BackColor="Blue"
        HeaderStyle-ForeColor="White"
AutoGenerateColumns="false"
>
      <Columns>
<asp:TemplateColumn HeaderText="类别" >
          <ItemTemplate>
<asp:LinkButton runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "id") %>' Text='<%# DataBinder.Eval(Container.DataItem, "cate") %>' onCommand="cate_Click" id="d1"/>
          </ItemTemplate>
        </asp:TemplateColumn>
        <asp:BoundColumn HeaderText="说明" DataField="Description"/>
        <asp:BoundColumn HeaderText="上次更新日期" DataField="nowtime"/>
        <asp:BoundColumn HeaderText="文章总数" DataField="total" ItemStyle-HorizontalAlign="right"/>
      </Columns>
</ASP:DataGrid>
</td></tr></table>
</asp:panel>
</form>
</body>