using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace DTable_App.DTableBBS
{
	/// <summary>
	/// userclub 的摘要说明。
	/// </summary>
	public class list : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label L_list;
		protected System.Web.UI.WebControls.Image Img_addnew;
		//protected System.Web.UI.WebControls.Image Img_search;
		protected System.Web.UI.WebControls.Label L_user;
		protected System.Web.UI.WebControls.Label L_info;
		protected System.Web.UI.WebControls.Label L_link;
		protected System.Web.UI.WebControls.Label L_bz;
		protected System.Web.UI.WebControls.Label L_hideinput;
		protected System.Web.UI.WebControls.Label L_jh;
		protected System.Web.UI.WebControls.Label L_bbsname;
		protected System.Web.UI.WebControls.Label L_searchme;
		protected dtable.dTable DTable1;
		
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			L_bbsname.Text=sharecode.strBBSName;
			string strb=sharecode.GetQueryStringValue("DTable_b");//获取传入的栏目
			if(!sharecode.IsNumeric(strb))
			{
              Page.Response.Write("没有这个栏目！");
			  Page.Response.End();
			}
//赋值搜索所需的隐含控件
			L_hideinput.Text="<input type=\"hidden\" name=\"DTable_b\" value=\"" + strb + "\">";
			//开始处理用户显示
			string stryhm=sharecode.GetCookieValue(sharecode.strUserNameCookieName);//获取历史的用户迷宫那
			if(stryhm!="")
			{
				L_user.Text=stryhm;
				L_searchme.Text="<a href=list.aspx?DTable_BBS_kw=" + stryhm + "&DTable_BBS_Se=%D7%F7%D5%DF&DTable_b=" + strb + "&Submit=GO>" + L_searchme.Text + "</a>";

			}
			else
			{
				L_searchme.Text="";
			}
			//开始处理发贴的链接
			Img_addnew.Attributes.Add("onclick","window.open('add.aspx?addnew=true&DTable_b=" + strb + "','_self','')");
			
//开始获得当前栏目的信息
System.Data.SqlClient.SqlConnection oconn=new System.Data.SqlClient.SqlConnection(sharecode.ConnStr);
			oconn.Open();
			System.Data.SqlClient.SqlCommand mycmd=new System.Data.SqlClient.SqlCommand("select 栏目名称,栏目介绍,栏目图标,版主,(select top 1 b.栏目名称 from DTable_BBS_Board b where b.id=a.父栏目) as 父栏目名称 from DTable_BBS_Board a where id=" + strb,oconn);
			System.Data.SqlClient.SqlDataReader myreader=mycmd.ExecuteReader();
			string strlmmc="";//栏目名称
			string strlmjs="";//栏目介绍
			string strlmtb="";//图标
			string strbz="";//版主
			string strflmmc="";//父栏目名称
			if(myreader.Read())
			{
				if(!myreader.IsDBNull(4))
				{
					strflmmc=myreader.GetValue(4).ToString();
				}
				if(!myreader.IsDBNull(3))
				{
					strbz=myreader.GetValue(3).ToString();
				}
				if(!myreader.IsDBNull(2))
				{
					strlmtb=myreader.GetValue(2).ToString();
				}
				if(!myreader.IsDBNull(1))
				{
					strlmjs=myreader.GetValue(1).ToString();
				}
				if(!myreader.IsDBNull(0))
				{
					strlmmc=myreader.GetValue(0).ToString();
				}
                
			}
            myreader.Close();
			
L_bz.Text=strbz;
			//开始广播
mycmd.CommandText ="select id,广播主题 from DTable_BBS_info where '" + System.DateTime.Now + "' between 开始时间 and 结束时间 and (所属栏目=0 or 所属栏目=" + strb + ")";
			myreader=mycmd.ExecuteReader();
			System.Text.StringBuilder strinfo=new System.Text.StringBuilder();

			while(myreader.Read())
			{
               strinfo.Append("<a href=showinfo.aspx?id=" + myreader.GetValue(0).ToString() + ">" + myreader.GetValue(1).ToString() + "</a>&nbsp;&nbsp;&nbsp;");   

			}
			myreader.Close();
            //end info
			
			L_info.Text =strinfo.ToString();

//开始输出链接
			L_link.Text="<a href=\"list.aspx?DTable_BBS_JH=true&DTable_b=" + strb + "\"><font color=#FF0000>精华贴</font></a> | <a href=\"../register/usermg1.aspx\">个人资料管理</a> | <a href=\"../admin/default.html\">管理</a>";
//?PageNo=1&MEditID=3&Furl=/ae005.aspx?PageNo=1

			
			if(strflmmc!="")
			{
				L_list.Text=strflmmc + " → ";
			}
			if(strlmmc!="")
			{
				L_list.Text+="<a href=\"list.aspx?DTable_b=" + strb + "\">" + strlmmc + "</a>";
			}

//开始捕获传入的查询参数
			
			string strkeyword=sharecode.GetQueryStringValue("DTable_BBS_kw");
			string strse=sharecode.GetQueryStringValue("DTable_BBS_Se");
			string strjh=sharecode.GetQueryStringValue("DTable_BBS_JH");
			string strsql="";
			strkeyword=Page.Server.HtmlEncode(strkeyword);//html编码 
		
			if(strkeyword!="")
			{
				
			
				if(strse=="主题")
				{
					strsql="主题 like '%" + strkeyword + "%'";
				}
				else if(strse=="作者")
				{
					strsql="发布人 like '%" + strkeyword + "%'";
				}
				else if(strse=="内容")
				{
					strsql="内容 like '%" + strkeyword + "%'";
				}
				else if(strse=="模糊")
				{
					strsql="主题 like '%" + strkeyword + "%' or 发布人 like '%" + strkeyword + "%' or 内容 like '%" + strkeyword + "%'";
				}
                
			}
			else if(strjh=="true")
			{
				strsql="点击率>=50";
				L_jh.Text="精华";

			}

			if(strsql!="")//如果存在查询参数,就进行预先搜索
			{
mycmd.CommandText="select id,父id from DTable_BBS where 删除=0 and 栏目=" + strb + " and (" + strsql + ")";
				strsql="";
				myreader=mycmd.ExecuteReader();
				while(myreader.Read())
				{string strtmpid1=myreader.GetValue(0).ToString();
				 string strtmpfid1=myreader.GetValue(1).ToString();
					if(int.Parse(strtmpfid1)>0)//如果父id大于0,则表明该帖子是回复贴,则需要加入的是主题贴
					{
						strsql+=strtmpfid1 + ",";
					}
					else
					{
						strsql+=strtmpid1 + ","; 
					}
				}
				myreader.Close();
				if(strsql.Length>0)
				{
					strsql=strsql.Substring(0,strsql.Length-1);//去掉最后一个,
				}

			}
	
			mycmd.Dispose();
			oconn.Close();
			oconn.Dispose();
			
			DTable1.TableName="DTable_bbs";
			DTable1.ConnStr =sharecode.ConnStr;
			if(strsql!="")
			{
				DTable1.List_SQL="select a.id,a.主题 as [主 题(点击+可展开贴子列表)],a.发布人 as 作者,cast((select count(*) from DTable_BBS b where b.父id= a.id ) as nvarchar(20)) + '/' + cast(a.点击率 as nvarchar(20)) as [回复/人气],(select top 1 convert(nvarchar(30),发布时间,120) + '|' + 发布人 from DTable_BBS b where a.删除=0 and b.父id=a.id or b.id=a.id order by b.id desc) as [最后更新|回复人],replace(replace(replace(cast(内容 as nvarchar(200)),'<','〈'),'>','〉'),'''','') as 内容,置顶  from DTable_BBS a where (父id=0 or 父id is null) and 栏目=" + strb + " and 删除=0 and a.id in(" + strsql + ") order by 置顶 desc,排序 desc, id desc";
		
			}
			else
			{
				DTable1.List_SQL="select a.id,a.主题 as [主 题(点击+可展开贴子列表)],a.发布人 as 作者,cast((select count(*) from DTable_BBS b where a.删除=0 and  b.父id= a.id ) as nvarchar(20)) + '/' + cast(a.点击率 as nvarchar(20)) as [回复/人气],(select top 1 convert(nvarchar(30),发布时间,120) + ' | ' + 发布人 from DTable_BBS b where a.删除=0 and  b.父id=a.id or b.id=a.id order by b.id desc) as [最后更新|回复人],replace(replace(replace(cast(内容 as nvarchar(200)),'<','〈'),'>','〉'),'''','') as 内容,置顶  from DTable_BBS a where (父id=0 or 父id is null) and 栏目=" + strb + " and 删除=0 order by 置顶 desc,排序 desc, id desc";
			}
			DTable1.Page_Pos=1; 
				DTable1.List_NumCol="condition||6|true@@boolean|=|<img src=img_bbsset/istop.gif>|<img src=img_bbsset/folder.gif>||"; 
			DTable1.List_FieldFormat="5||hiddenfield|||||^1||text|100|5|||^6||hiddenfield||||||^2|align=center||||||^3|align=center||||||";
			DTable1.List_Sty_Title="align=center style='color:#FFFFFF;background-image:url(img_bbs/bg1.gif)'"; 
			DTable1.List_Sty_Table=" width='100%' border=\"1\" cellpadding=\"3\" cellspacing='0' bordercolor='#111111' bordercolorlight='#666688' bordercolordark='#666688' style='border-collapse: collapse' align='center'"; 
			DTable1.List_Child="select id,主题,发布人 as 回复人,发布时间,父id from DTable_BBS where 父id |||"; //设置子表显示。此属性是一个数组属性，后三个参数被省略（不能省略分隔符号|)



			DTable1.List_mf_url="show.aspx?keyword=" + Page.Server.UrlEncode (strkeyword) + "&addnew=true&r"; 
			DTable1.Show_Enable=false;
		
			Page.Response.Cookies[sharecode.strFromUrlSName].Value=Page.Request.Url.AbsoluteUri.ToString();Page.Response.Cookies[sharecode.strFromUrlSName].Expires=System.DateTime.Now.AddMinutes(20);
			
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			
			InitializeComponent();
			base.OnInit(e);
			
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}
