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.DTablePhoto
{
	/// <summary>
	/// list 的摘要说明。
	/// </summary>
	public class list : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label L_bbsname;
		protected System.Web.UI.WebControls.Label L_loginInfo;
		protected System.Web.UI.WebControls.Label L_hys;
		protected System.Web.UI.WebControls.Label L_lastuser;
		protected System.Web.UI.WebControls.Label L_today;
		protected System.Web.UI.WebControls.Label L_zts;
		protected System.Web.UI.WebControls.Label L_yesday;
		protected dtable.dTable DTable1;
		protected System.Web.UI.WebControls.Label L_user;
		protected System.Web.UI.WebControls.Label L_hideinput;
		protected System.Web.UI.WebControls.Label L_addnew;
		protected System.Web.UI.WebControls.Label L_yhm;
		protected System.Web.UI.WebControls.Label L_top5;
		protected System.Web.UI.WebControls.Label L_gks;
		protected System.Web.UI.WebControls.Label L_wgks;
		protected System.Web.UI.WebControls.Label L_xcs;
		protected System.Web.UI.WebControls.Label L_zs;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			DTable1.ConnStr=sharecode.ConnStr;
			DTable1.TableName ="DTable_Photo_Kind";
			string struser=sharecode.GetQueryStringValue("user");
			string stryhm=sharecode.GetSessionValue(sharecode.strUserSName);

			
			if(struser=="")
			{
				sharecode.OutMsgBox("传入的参数错误",true);
			}
		


			L_user.Text="<a href=list.aspx?user=" + Page.Server.UrlEncode(struser) + ">" + struser + "</a>";
			L_addnew.Text="<a href=add.aspx?addnew=true&type=xc&user=" + Page.Server.UrlEncode(struser) + "&furl=list.aspx?user=" + struser + ">" + L_addnew.Text + "</a>";
//Page.Response.Cookies[sharecode.strFromUrlSName].Value=null;
			Page.Response.Cookies[sharecode.strFromUrlSName].Value=Page.Request.Url.AbsoluteUri.ToString();
			Page.Response.Cookies[sharecode.strFromUrlSName].Expires=System.DateTime.Now.AddMinutes(20); 
///////////////////////////

			//开始显示本相册信息
			string strtoday=System.DateTime.Now.ToString("yyyy-MM-dd");
			System.Data.SqlClient.SqlConnection oconn=new System.Data.SqlClient.SqlConnection(sharecode.ConnStr);
			System.Data.SqlClient.SqlCommand mycmd=new System.Data.SqlClient.SqlCommand("select top 1 (select count(*) from DTable_Photo b where 发布人='" + struser + "') as 照片总数,(select count(*) from DTable_Photo b where 发布人='" + struser + "' and 公开=1) as 公开数,(select count(*) from DTable_Photo b where 发布人='" + struser + "' and 发布时间 between '" + strtoday + " 0:00:00' and '" + strtoday + " 23:59:59') as 今日上传数,(select count(*) from DTable_Photo_Kind where 所有人='" + struser + "') as 相册总数 from DTable_Photo_kind a",oconn);
			oconn.Open();
			System.Data.SqlClient.SqlDataReader myreader=mycmd.ExecuteReader();

			if(myreader.Read())
			{
				L_zs.Text=myreader.GetValue(0).ToString();
				L_gks.Text=myreader.GetValue(1).ToString();
				L_today.Text=myreader.GetValue(2).ToString();
				L_wgks.Text=System.Convert.ToString(myreader.GetInt32(0)-myreader.GetInt32(1)); 
				L_xcs.Text=myreader.GetValue(3).ToString();

			}
			myreader.Close();
			//开始top5图片信息
			if(stryhm!="")
			{
				mycmd.CommandText="select top 5 a.id,a.照片主题,a.说明,a.照片地址,a.点击率,a.发布时间,b.照片类别 from DTable_Photo a inner join DTable_Photo_Kind b on a.类别=b.id where a.发布人='" + struser + "' and (a.公开=1 or a.发布人='" + stryhm + "' or ',' + a.允许用户 like '%," + stryhm + ",%') order by a.点击率 desc";
			}
			else
			{
				mycmd.CommandText="select top 5 a.id,a.照片主题,a.说明,a.照片地址,a.点击率,a.发布时间,b.照片类别 from DTable_Photo a inner join DTable_Photo_Kind b on a.类别=b.id where a.发布人='" + struser + "' and a.公开=1 order by a.点击率 desc";
				
			}
			myreader=mycmd.ExecuteReader();
			System.Text.StringBuilder strtext=new System.Text.StringBuilder();
			while(myreader.Read())
			{
				string strtitle=myreader.GetValue(2).ToString().Replace("<br>","").Replace("'","") + "\n发布：" + myreader.GetValue(5).ToString() + "\n点击：" + myreader.GetValue(4).ToString();
				strtext.Append("<td align=center><img src=\"img_user/" + struser + "/mini/" + myreader.GetValue(3).ToString() + "\" border=\"0\"><br>" + myreader.GetValue(1).ToString() + "[" + myreader.GetValue(6).ToString() + "]</td>");

			}
			myreader.Close();
			mycmd.Dispose();
			oconn.Close();
			oconn.Dispose();
			if(strtext.Length>0)
			{
				L_top5.Text="<table border=0><tr>" + strtext.ToString() + "</tr></table>";

			}
			///////////////////////////

			if(stryhm!="")//如果用户登录,允许显示公开的和该用户被允许察看的
			{
             	DTable1.List_SQL="select a.id,a.照片类别,(select count(*) from DTable_Photo b  where b.类别=a.id) as 照片数,(select top 1 c.照片地址 from DTable_Photo c where c.照片地址 is not null and c.类别=a.id   order by c.本类首页显示 desc,c.id desc) as 封面照片,a.id,a.本类说明 from DTable_Photo_Kind a where a.所有人 ='" + struser + "' and (a.公开=1 or (',' + a.允许用户 + ',') like '%," + stryhm + ",%' or 所有人='" + stryhm + "') order by a.id desc";
				L_yhm.Text=stryhm;
			}
			else//只能察看公开的
			{
				DTable1.List_SQL="select a.id,a.照片类别,(select count(*) from DTable_Photo b  where b.类别=a.id) as 照片数,(select top 1 c.照片地址 from DTable_Photo c where c.照片地址 is not null and c.类别=a.id  and c.公开=1 order by c.本类首页显示 desc,c.id desc) as 封面照片,a.id,a.本类说明 from DTable_Photo_Kind a where a.所有人 ='" + struser + "' and a.公开=1 order by a.id desc";
			}
			DTable1.Show_Enable =false;
			DTable1.List_Templ_Tr1="<tr><td width=\"149\" height=\"141\" align=\"center\" valign=\"top\" background=\"images/bg001.jpg\"><table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\"> <tr> <td align=\"center\">&nbsp;</td> </tr> <tr> <td align=\"center\"><a href=\"ImgList.aspx?user=" + struser + "&PID=@@fieldvalue4@@&PName=@@fieldvalue1@@\" title=\"@@fieldvalue5@@\">@@fieldvalue3@@</a></td> </tr> <tr> <td align=\"center\"><a href=\"ImgList.aspx?user=" + struser + "&PID=@@fieldvalue4@@&PName=@@fieldvalue1@@\" title=\"@@fieldvalue5@@\">[@@fieldvalue1@@]</a></td> </tr> <tr> <td align=\"center\">共@@fieldvalue2@@张图片[<a href=\"add.aspx?addnew=true&type=tp&user=" + struser + "&PName=@@fieldvalue1@@&furl=list.aspx?user=" + struser + "\">上传图片</a>]</td> </tr> </table> </td></tr>";
			DTable1.List_Templ_Tr2=DTable1.List_Templ_Tr1; //设置行模板2的样式
			

			DTable1.List_Templ_Col=3; //设置了每行包含2条记录 
			DTable1.List_Sty_Table="table height=\"145\" border=\"0\" cellpadding=\"0\" cellspacing=\"19\""; 
		    DTable1.Page_Pos=1; 
			DTable1.Page_Align ="center";
			DTable1.List_FieldFormat="3||urlimage|img_user/" + struser + "/mini/|||width=100|"; //设置列表的第2列为链接图像,并指定了宽度
			//写入Title
			Page.Response.Write("<script language=javascript>document.title='" + struser + "的相册';</script>"); 



		}

		#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
	}
}
