Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls
Imports System.Drawing
namespace Diss_vb
public class getCate : Inherits Control : Implements INamingContainer
	Public Property FirstLoad As Boolean'第一次加载
		Get
			Return ViewState("FirstLoad")
		End Get
		Set
			ViewState("FirstLoad")=value
		End Set
	End Property
	Public Property NowSelect As Integer'目前选择的类别ID
		Get
			Return ViewState("NowSelect")
		End Get
		Set
			ViewState("NowSelect")=value
		End Set
	End Property
	Public Property TotalRec As Integer'总个数
		Get
			Return ViewState("TotalRec")
		End Get
		Set
			ViewState("TotalRec")=value
		End Set
	End Property
	Public Property StartDate As DateTime'起始日
		Get
			Return ViewState("StartDate")
		End Get
		Set
			ViewState("StartDate")=value
		End Set
	End Property
	Public Property EndDate As DateTime'结束日
		Get
			Return ViewState("EndDate")
		End Get
		Set
			ViewState("EndDate")=value
		End Set
	End Property
	Public Property NowCate As String'目前选择类别名称
		Get
			Return ViewState("NowCate")
		End Get
		Set
			ViewState("NowCate")=value
		End Set
	End Property
	public Property ConnectSQL() as string'目前连至SQL的字串
		get
			return ViewState("ConnectSQL").ToString()
		end get
		set
			ViewState("ConnectSQL")=value
		end set
	end property
	public property ServerName() as string'SQL服务器名称
		get
			return ViewState("ServerName").ToString()
		end get
		set
			ViewState("ServerName")=value
		end set
	end property
	public property Uid() as string'登录SQL的ID
		get
			return ViewState("Uid").ToString()
		end get
		set
			ViewState("Uid")=value
		end set
	end property
	public Property Pass() as string'登录SQL的密码
		get
			return ViewState("Pass").ToString()
		end get
		set
			ViewState("Pass")=value
		end set
	end property
	public Property DBName() as string' 数据库名称
		get
			return ViewState("DBName").ToString()
		end get
		set
			ViewState("DBName")=value
		end set
	end property
	Public Event Command(Sender as Object, E as CommandEventArgs)
	protected overrides sub CreateChildControls()
		dim ConnectString as string ="server=" & me.ServerName & ";uid=" & me.Uid & ";pwd=" & me.Pass & ";database=" & me.DBName
		dim k as SqlConnection = new SqlConnection(ConnectString)
		dim Comm as SqlDataAdapter = new SqlDataAdapter("select * from Cate order by ID",k)
		Dim DS as DataSet = new DataSet()
		Comm.Fill(DS,"Cate")
		Dim Frow() as DataRow
		if me.NowSelect = 0 then
			me.NowSelect = 1
		end if
		Frow=DS.Tables("Cate").Select("id =" & me.NowSelect)
		me.NowCate = Frow(0)(2).ToString()'取得类别名称
		Dim Comm1 as SqlDataAdapter= new SqlDataAdapter("select * from Article",k)
		Comm1.Fill(DS,"Article")'取得文章总数
		me.TotalRec=DS.Tables("Article").Rows.Count
		dim i as integer=0
		for i=0 to DS.Tables("Cate").Rows.Count-1
			Dim lk as LinkButton = new LinkButton()
			lk.ID="lk" & DS.Tables("Cate").Rows(i)("ID")
			lk.Text=DS.Tables("Cate").Rows(i)("cate").ToString()
			Dim t as FontUnit'声明FontUnit对象
			lk.Font.Size=t.Point(10)
			lk.CommandArgument=DS.Tables("Cate").Rows(i)("id").ToString() & ";" & DS.Tables("Cate").Rows(i)("cate").ToString()
			AddHandler lk.Command, AddressOf Me.CateClick
			me.Controls.Add(lk)
			me.Controls.Add(new LiteralControl(" "))
		next
		if me.FirstLoad=true then
			me.Controls.Add(new LiteralControl("<p>"))
			me.Controls.Add(new LiteralControl("总个数："))
			me.Controls.Add(new LiteralControl(me.TotalRec.ToString()))
			me.Controls.Add(new LiteralControl("　"))
			me.Controls.Add(new LiteralControl("目前类别："))
			me.Controls.Add(new LiteralControl(me.NowCate))
			me.Controls.Add(new LiteralControl("　"))
			me.Controls.Add(new LiteralControl("目前范围："))
			me.Controls.Add(new LiteralControl(me.StartDate.ToString("yyyy/MM/dd")))
			me.Controls.Add(new LiteralControl("至"))
			me.Controls.Add(new LiteralControl(me.EndDate.ToString("yyyy/MM/dd")))
			me.FirstLoad=false
		end if

	end sub
        private sub CateClick(sender as Object,e as CommandEventArgs)
		dim h as string=e.CommandArgument.ToString()
		dim x as integer=h.IndexOf(";")
		me.NowSelect=Convert.ToInt32(h.Substring(0,x))
		me.NowCate=h.Substring(x+1,h.Length-x-1)
		me.Controls.Add(new LiteralControl("<p>"))
		me.Controls.Add(new LiteralControl("总个数："))
		me.Controls.Add(new LiteralControl(me.TotalRec.ToString()))
		me.Controls.Add(new LiteralControl("　"))
		me.Controls.Add(new LiteralControl("目前类别："))
		me.Controls.Add(new LiteralControl(me.NowCate.ToString()))
		me.Controls.Add(new LiteralControl("　"))
		me.Controls.Add(new LiteralControl("目前范围："))
		me.Controls.Add(new LiteralControl(me.StartDate.ToString("yyyy/MM/dd")))
		me.Controls.Add(new LiteralControl("至"))
		me.Controls.Add(new LiteralControl(me.EndDate.ToString("yyyy/MM/dd")))
		dim args as CommandEventArgs = new CommandEventArgs(e)
	        OnCommand(args)
	end sub
        protected sub OnCommand(e as CommandEventArgs)
           RaiseEvent Command(me,e)
	end sub
	end class
end namespace