using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;
using System.Web.Configuration;
using System.Text.RegularExpressions; 
using System.Text;

public partial class viewClass : System.Web.UI.Page
{
	string ID = null;
	int currentPage = 0;
	DeepSoonHelp dh = null;
	string urlRule = "";
	string themeHtml = "";

	///处理评论标签
	public string replaceCommentTag(string themeHtml,string ID,string urlRule){
		string CommentStr = "";
		MysqlHelp mh = new MysqlHelp();
		if( themeHtml.Contains("{dp:Comment}") ){
			
			bool setOpen = false;
			bool setPass = false;
			int setSize = 200;
			string openArea = "all";
			DataTable settingDt=new DataTable();
			settingDt = mh.GetDatabysql("Select * From CommentSetting4DeepSoon");
			if(settingDt.Rows.Count > 0){
				setOpen = (bool)settingDt.Rows[0]["setOpen"];
				setPass = (bool)settingDt.Rows[0]["setPass"];
				setSize = Convert.ToInt32(settingDt.Rows[0]["setSize"]);
				openArea = settingDt.Rows[0]["openArea"].ToString();
			}
			
			///CommentStr += "<script language='javascript' type='text/javascript' src='js/jquery-latest.pack.js'></script>";
			CommentStr += "<script language='javascript' type='text/javascript' src='js/commentFunctions.js'></script>";
	
			if(setOpen){
				string infor = "";
				if(setPass){
					infor = "新评论审核后显示/"+"不超过"+setSize+"字";
				}
				else {
					infor = ""+"不超过"+setSize+"字";
				}
				CommentStr += "<div class='commentInfor'>#提示：" + infor +"</div>";
				CommentStr += "<form action='#' style='margin:0px;' method='post'>";
				CommentStr += "<textarea name='CommContent' id='CommContent' class='commentContent'></textarea><br>";
				CommentStr += "<input type='hidden' name='CommArticleID' id='CommArticleID'  value='"+ID+"'>";
				if(openArea == "all"){///允许匿名评论
					CommentStr += "<input type='hidden' name='CommAuthor' id='CommAuthor' class='commentAuthor' value='匿名用户'>";
					CommentStr += "<div id='CommSubmitButton' class='commentButton'>匿名评论</div>&nbsp;&nbsp;";
					Session["CommentSubmitAuthor"] = "匿名用户";
				}
				else{///注册会员评论
					///检验是否已登陆
					if (Request.Cookies["strUser4Deepsoon"] != null){
						HttpCookie userCookie = Request.Cookies["strUser4Deepsoon"];
						string loginName = HttpUtility.UrlDecode(HttpUtility.UrlDecode(userCookie.Value, Encoding.GetEncoding("UTF-8")));
						CommentStr += "<input type='hidden' name='Author' class='commentAuthor' value='"+loginName+"'>";
						CommentStr += "<input type='button' value='评论'  id='commSubmitButton' class='commentButton'>&nbsp;&nbsp;";
						CommentStr += "<span class='commentInfor'>当前登陆账户:"+loginName+"</span>";
						Session["CommentSubmitAuthor"] = loginName;
					}
					else {
						CommentStr += "<div class='commentLoginInfor'>";
						CommentStr += "<input type='buttom' value='评论' class='commentButtonGray'>&nbsp;&nbsp;";
						CommentStr += "不允许匿名评论，请<a href=''>登陆</a>后在评论；或者你还不是<a href=''>注册会员</a>";
						CommentStr += "</div>";
					}
					
				}
				CommentStr += "</form>";
			}
			else {
				CommentStr += "本文评论已被关闭！";
			}
			
			CommentStr += "<br><br>";
			
			
			CommentStr += "<div id='load' style='font-size:13px;'></div>";
			CommentStr += "<input type='hidden' id='pagecount' />";
			CommentStr += "<input type='hidden' id='articleID' value='"+ID+"'>";
			CommentStr += "<input type='hidden' id='setPass' value='"+setPass.ToString()+"'>";
			CommentStr += "<div id='datas' style='font-size:13px;padding:4px;width:560px;'></div>";
		
			CommentStr += "<div style='margin-top:10px;font-size:13px;'>";
				CommentStr += "<span id='first' class='commentPagerBox'>首页</span>&nbsp;";
				CommentStr += "<span id='previous' class='commentPagerBox'>上一页</span>&nbsp;";
				CommentStr += "<span id='pageinfo'></span>&nbsp;";
				CommentStr += "<span id='next' class='commentPagerBox'>下一页</span>&nbsp;";
				CommentStr += "<span id='last' class='commentPagerBox'>尾页</span> ";
			CommentStr += "</div>";
			
			themeHtml = themeHtml.Replace("{dp:Comment}", CommentStr);
		}
		return themeHtml;
	}
	
	protected void Page_Load(object sender, EventArgs e)
    {
		///创建函数库
		dh = new DeepSoonHelp();
		
		///获取文章ID
		ID = Request.QueryString["ID"];
		///获取合法的文章ID
		ID = dh.getValidateNumStr(ID);
		
		///获取文章当前页码
		string currentPageStr = Request.QueryString["Page"];
		///获取合法的文章ID
		currentPage = Convert.ToInt32(dh.getValidateNumStr(currentPageStr));
		
		///获取首选项的urlRule配置
		urlRule = dh.getUrlRule();
		
		///获取模板内容
		themeHtml = dh.getThemeHtml("T_view.html");
			
		///处理正文标签
		themeHtml = dh.replaceViewTag(themeHtml,urlRule,ID,currentPage);
		
		///处理上一篇文章标签
		themeHtml = dh.replacePreArticleTag(themeHtml,urlRule,ID);
		///处理下一篇文章标签
		themeHtml = dh.replaceNextArticleTag(themeHtml,urlRule,ID);
		
		///正文页标题以及当前位置：
		Page.Title = dh.getViewTitle(ID) + "</b> &gt; <b>正文</b>";
				
		///处理广告标签
		themeHtml = dh.replaceAdTag(themeHtml,"ViewRight");
		
		///处理最热文章标签
		themeHtml = dh.replaceHotListTag(themeHtml,urlRule);
		
		///处理最新发布标签
		themeHtml = dh.replaceNewListTag(themeHtml,urlRule);
		
		///处理随机文章标签
		themeHtml = dh.replaceRandListTag(themeHtml,urlRule);
		
		///处理评论标签
		themeHtml = replaceCommentTag(themeHtml,ID,urlRule);
		
		///将网页数据显示
		this.labelViewContent.Text = themeHtml;
    }
	
}