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>
	/// show 的摘要说明。
	/// </summary>
	public class show : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label L_fbr;
		protected System.Web.UI.WebControls.Label L_fbsj;
		protected System.Web.UI.WebControls.Label L_xc;
		protected System.Web.UI.WebControls.Label L_sm;
		protected System.Web.UI.WebControls.Label L_dj;
		protected System.Web.UI.WebControls.Label L_img;
		protected System.Web.UI.WebControls.Label L_mg;
		protected System.Web.UI.WebControls.Label L_pl;
		protected System.Web.UI.WebControls.Label L_hideinput;
		protected System.Web.UI.WebControls.Label L_zt;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			string struser=sharecode.GetQueryStringValue("user");
			string stryhm=sharecode.GetSessionValue(sharecode.strUserSName);
			string strpid=sharecode.GetQueryStringValue("Pid");
			string strsql="";
			string strl="";
			string strpname="";

			if(!sharecode.IsNumeric(strpid) || struser=="")
			{
				sharecode.OutMsgBox("传入的参数有误",true);
			}



			//开始写入发表评论所需的隐含控件
L_hideinput.Text="<input type=\"hidden\" name=\"thisimgid\" value=\"" + strpid + "\">";
			
			
			//开始生成管理菜单

			if(stryhm!="")
			{
strsql="select top 1 a.id,a.照片主题,a.说明,a.照片地址,a.点击率,a.发布人,a.发布时间,b.照片类别,a.本类首页显示,a.公开,a.允许用户,b.id from DTable_Photo a inner join DTable_Photo_Kind b on a.类别=b.id where a.id=" + strpid + " and ( ',' + a.允许用户 + ',' like '%," + stryhm + ",%' or a.公开=1 or 发布人='" + stryhm + "' or ',' + b.允许用户 + ',' like '%," + stryhm + ",%')";
				

			}
			else
			{
strsql="select top 1 a.id,a.照片主题,a.说明,a.照片地址,a.点击率,a.发布人,a.发布时间,b.照片类别,a.本类首页显示,a.公开,a.允许用户,b.id from DTable_Photo a inner join DTable_Photo_Kind b on a.类别=b.id where a.id=" + strpid + " and a.公开=1";
			}
System.Data.SqlClient.SqlConnection oconn=new System.Data.SqlClient.SqlConnection(sharecode.ConnStr);
			oconn.Open();
			System.Data.SqlClient.SqlCommand mycmd=new System.Data.SqlClient.SqlCommand(strsql,oconn);
			System.Data.SqlClient.SqlDataReader myreader=mycmd.ExecuteReader();

			if(myreader.Read())
			{
				strpname=myreader.GetValue(7).ToString();
				strl=myreader.GetValue(11).ToString();
				L_fbr.Text=myreader.GetValue(5).ToString();
				L_dj.Text=myreader.GetValue(4).ToString() + "次";
				L_fbsj.Text=myreader.GetDateTime(6).ToString("yyyy年MM月dd日 HH时mm分"); 
				L_xc.Text=strpname;
				L_sm.Text=myreader.GetValue(2).ToString();
				L_zt.Text =myreader.GetValue(1).ToString();
				string strurl=myreader.GetValue(3).ToString();
				L_img.Text="<a href=img_user/" + struser + "/" + strurl + " target=_blank><img src=img_user/" + struser + "/" + strurl + " border=0 width=100% id=\"thisimg\"></a><script language=javascript>parent.document.all.showimg.height=document.all.thisimg.height+400;</script>";

			}
			myreader.Close();
             
			
			//开始写入评论
			if(sharecode.GetFormValue("Submitpl")!="")
			{

                string strpl=sharecode.GetFormValue("pl");
				string strfbr=stryhm;
				string strthisid=sharecode.GetFormValue("thisimgid");
				if(stryhm=="")
				{
					strfbr="过客";
				}
				mycmd.CommandText="insert into DTable_Photo_info(评论,评论人,IP地址,照片ID) values('" + strpl + "','" + strfbr + "','" + Page.Request.UserHostAddress.ToString() + "'," + strthisid + ")";
				try
				{
					mycmd.ExecuteNonQuery();
				}
				catch
				{
				}

			}


			//开始显示评论
			System.Text.StringBuilder strtext=new System.Text.StringBuilder();
			mycmd.CommandText="select id,评论,评论人,发布时间,IP地址 from DTable_Photo_info where 照片ID=" + strpid;
			myreader=mycmd.ExecuteReader();
			while(myreader.Read())
			{
              strtext.Append("<img src=img_photo/Forum_nav.gif> 来自<strong>" + myreader.GetValue(4).ToString() + "</strong>的[<strong>" + myreader.GetValue(2).ToString() +  "</strong>]于" + myreader.GetDateTime(3).ToString("yyyy年MM月dd日 HH时mm分") + "说：<br><br>" + myreader.GetValue(1).ToString() + "<br><br>");
			}
            myreader.Close();
			L_pl.Text=strtext.ToString();
			if(L_pl.Text=="")
			{
				L_pl.Text="暂无评论";
			}


		//开始写入点击率
			mycmd.CommandText="update DTable_Photo set 点击率=点击率+1 where id=" + strpid;
			try
			{
				mycmd.ExecuteNonQuery();
			}
			catch
			{
			}

			mycmd.Dispose();
			oconn.Close();
			oconn.Dispose();
			if(stryhm==struser)//如果用户是版主
			{
				L_mg.Text="<a href=\"add.aspx?type=update&meditid=" + strpid + "&PName=" + strpname + "&user=" + struser + "&lb=" + strl + "\" target=\"_parent\">更新</a> | <a href=\"add.aspx?type=del&delid=" + strpid + "&PName=" + strpname + "&user=" + struser + "&lb=" + strl + "\" onclick=\"{if(confirm('即将删除本图片并且不可恢复,是否继续(按取消放弃删除)?')){return true;}return false;}\" target=\"_parent\">删除</a> | <a href=\"add.aspx?addnew=true&type=tp&PName=" + strpname + "&user=" + struser + "&lb=" + strl + "\" target=\"_parent\">上传</a>";

			}

			
		}

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