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;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace free.bbs
{
	/// <summary>
	/// Summary description for kongzhiye.
	/// </summary>
	public class kongzhiye : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.HyperLink HyperLink8;
		protected System.Web.UI.WebControls.Label Label12;
		protected System.Web.UI.HtmlControls.HtmlTableCell TD1;
		protected System.Web.UI.WebControls.HyperLink HyperLink9;
		protected System.Web.UI.WebControls.HyperLink HyperLink10;
		protected System.Web.UI.WebControls.Label Label6;
		protected System.Web.UI.WebControls.HyperLink HyperLink11;
		protected System.Web.UI.WebControls.Label Label5;
		protected System.Web.UI.WebControls.Label liu;
		protected System.Data.SqlClient.SqlConnection myconn;
		protected System.Web.UI.WebControls.Image touxiang;
		protected System.Web.UI.WebControls.Image fatie;
		protected System.Web.UI.WebControls.Image wenzhang;
		protected System.Web.UI.WebControls.Image jifen;
		protected System.Web.UI.WebControls.Image jinqian;
		protected System.Web.UI.WebControls.Image meili;
		protected System.Data.SqlClient.SqlCommand mycomm;
		protected System.Web.UI.WebControls.Image qianming_pic;
		protected System.Web.UI.WebControls.Literal jiguan;
		protected System.Web.UI.WebControls.Literal name;
		protected System.Web.UI.WebControls.Literal xingbie;
		protected System.Web.UI.WebControls.Literal shengri;
		protected System.Web.UI.WebControls.Literal touxian;
		protected System.Web.UI.WebControls.Literal dengji;
		protected System.Web.UI.WebControls.Literal zhuce;
		protected System.Web.UI.WebControls.Literal denglu;
		protected System.Web.UI.HtmlControls.HtmlTable peter1;
		protected System.Web.UI.HtmlControls.HtmlTable peter2;
		string parth;
		SqlDataAdapter myada;
		DataSet myset,mst;
		HtmlTableRow myrow;
		HtmlTableCell mycell;
		int ncount1;
		int ncount2;
		string jiaru;
		


		private void databind1()  
		{
			int page,pagecount=10,k=1,count;
			try
			{
				ncount1=Convert.ToInt32(Request.Params["xiaoxi_page"].ToString());
				ncount2=Convert.ToInt32(Request.Params["wenzhang_page"].ToString());
			}
			catch
			{
				ncount1=1;
				ncount2=1;
			}
//			string systime ;
//			systime=Request.Params["lastlogtime"];			
			myconn.Open();
			myada= new SqlDataAdapter("SELECT xiaoxi_id,faqiren,zhuti,shijian FROM duanxiaoxi WHERE jieshoufang='"+Request.Cookies["free_huiyuan"].Value+"'",myconn);
		    myset=new DataSet();
			myada.Fill(myset,"haina");
			 count=myset.Tables["haina"].Rows.Count/pagecount;
				if(myset.Tables["haina"].Rows.Count%pagecount==0) count=count;
				else
					count+=1;
				page=count;
				myrow=new HtmlTableRow();
				mycell=new HtmlTableCell();
				if(myset.Tables["haina"].Rows.Count>0)
				{
					if(page==1)
					{
						for(int i=0;i<myset.Tables["haina"].Rows.Count;i++)
						{
							mycell.Controls.Add(new LiteralControl("<tr height='22'><td height='22' class='tableBody1'><a href='chakanxiaoxi.aspx?id="+myset.Tables["haina"].Rows[i]["xiaoxi_id"]+"' target='_blank'>"+myset.Tables["haina"].Rows[i]["zhuti"].ToString().Trim()+"</a></td><td height='20' class='tableBody1'>"+myset.Tables["haina"].Rows[i]["faqiren"].ToString()+"</td><td height='20' class='tableBody1'>"+myset.Tables["haina"].Rows[i]["shijian"].ToString()+"</td></tr>"));
							myrow.Cells.Add(mycell);
							peter1.Rows.Add(myrow);
						}
						mycell.Controls.Add(new LiteralControl("<tr height='23'><td height='23' align='right' colspan='3' class='tableBody1'><a href='kongzhiye.aspx?xiaoxi_page=1&amp;wenzhang_page=1'>首页</a>&nbsp;&nbsp;上一页&nbsp;&nbsp;下一页&nbsp;&nbsp;末页</td></tr>"));
						myrow.Cells.Add(mycell);
						peter1.Rows.Add(myrow);
					}
					else
					{
						if(page>=2)
						{
							jiaru="<tr height='23'><td height='23' align='right' colspan='3' class='tableBody1'><a href='kongzhiye.aspx?xiaoxi_page=1&amp;wenzhang_page=1'>首页</a>&nbsp;&nbsp;<a href='kongzhiye.aspx?xiaoxi_page="+(ncount1-1)+"&amp;wenzhang_page="+ncount2+"'>上一页</a>&nbsp;&nbsp;<a href='kongzhiye.aspx?xiaoxi_page="+(ncount1+1)+"&amp;wenzhang_page="+ncount2+"'>下一页</a>&nbsp;&nbsp;<a href='kongzhiye.aspx?xiaoxi_page="+ncount1+"&amp;wenzhang_page="+ncount2+"'>末页</td></tr>";
						}
						else
							jiaru="<tr height='23'><td height='23' align='right' colspan='3' class='tableBody1'><a href='kongzhiye.aspx?xiaoxi_page=1&amp;wenzhang_page=1'>首页</a>&nbsp;&nbsp;上一页&nbsp;&nbsp;下一页&nbsp;&nbsp;末页</td></tr>";
				
									
						ncount1=Convert.ToInt32(Request.Params["xiaoxi_page"].ToString());
						pagecount*=(k*ncount1-1);
						for(int i=pagecount;i<pagecount+10;i++)
						{
							try
							{
								mycell.Controls.Add(new LiteralControl("<tr height='22'><td height='23' class='tableBody1'><a href='chakanxiaoxi.aspx?id="+myset.Tables["haina"].Rows[i]["xiaoxi_id"]+"' target='_blank'>"+myset.Tables["haina"].Rows[i]["zhuti"].ToString().Trim()+"</a></td><td height='20' class='tableBody1'>"+myset.Tables["haina"].Rows[i]["faqiren"].ToString()+"</td><td height='20' class='tableBody1'>"+myset.Tables["haina"].Rows[i]["shijian"].ToString()+"</td></tr>"));
								myrow.Cells.Add(mycell);
								peter1.Rows.Add(myrow);
							}
							catch
							{
								jiaru="<tr height='23'><td height='23' align='right' colspan='3' class='tableBody1'><a href='kongzhiye.aspx?xiaoxi_page=1&amp;wenzhang_page=1'>首页</a>&nbsp;&nbsp;<a href='kongzhiye.aspx?xiaoxi_page="+(ncount1-1)+"&amp;wenzhang_page="+ncount2+"'>上一页</a>&nbsp;&nbsp;下一页&nbsp;&nbsp;末页</td></tr>";
							}
						}
						if(ncount1==1)
							jiaru="<tr height='23'><td height='23' align='right' colspan='3' class='tableBody1'><a href='kongzhiye.aspx?xiaoxi_page=1&amp;wenzhang_page=1'>首页</a>&nbsp;&nbsp;上一页&nbsp;&nbsp;<a href='kongzhiye.aspx?xiaoxi_page="+(ncount1+1)+"&amp;wenzhang_page="+ncount2+"'>下一页</a>&nbsp;&nbsp;<a href='kongzhiye.aspx?xiaoxi_page="+page+"&amp;wenzhang_page="+ncount2+"'>末页</a></td></tr>";
						mycell.Controls.Add(new LiteralControl(""+jiaru+""));
						myrow.Cells.Add(mycell);
						peter1.Rows.Add(myrow);
					}
				}
				else
				{
					mycell.Controls.Add(new LiteralControl("<tr height='25'><td colspan='3' align='center' height='25' class='tableBody1'><font color='red'>★</font>暂时没有您的短信<font color='red'>★</font></td></tr>"));
					myrow.Cells.Add(mycell);
					peter1.Rows.Add(myrow);
				}
				myconn.Close();
			
		}
		

		private void databind2()
		{
			int page,pagecount=10,k=1,count;
			try
			{
				ncount1=Convert.ToInt32(Request.Params["xiaoxi_page"].ToString());
				ncount2=Convert.ToInt32(Request.Params["wenzhang_page"].ToString());
			}
			catch
			{
				ncount1=1;
				ncount2=1;
			}
			myconn.Open();
			string sql="SELECT biaoti,shijian,counter FROM article WHERE chuqu='"+Request.Cookies["free_huiyuan"].Value+"'";
			myada=new SqlDataAdapter(sql,myconn);
			mst=new DataSet();
			myada.Fill(mst,"haina");
            count=mst.Tables["haina"].Rows.Count/pagecount;
			if(mst.Tables["haina"].Rows.Count%pagecount==0) 
				count=count;
			else
				count=count+1;
			page=count;
			myrow=new HtmlTableRow();
			mycell=new HtmlTableCell();
			if(mst.Tables["haina"].Rows.Count>0)
			{
				if(page==1)
				{
					for(int i=0;i<mst.Tables["haina"].Rows.Count;i++)
					{
						mycell.Controls.Add(new LiteralControl("<tr height='22'><td height='22' class='tableBody1'>"+mst.Tables["haina"].Rows[i]["biaoti"].ToString().Trim()+"</td><td height='20' class='tableBody1'>"+mst.Tables["haina"].Rows[i]["shijian"].ToString()+"</td><td height='20' class='tableBody1'>"+mst.Tables["haina"].Rows[i]["counter"].ToString()+"</td></tr>"));
						myrow.Cells.Add(mycell);
						peter2.Rows.Add(myrow);
					}
					mycell.Controls.Add(new LiteralControl("<tr height='23'><td height='23' align='right' colspan='3' class='tableBody1'><a href='kongzhiye.aspx?xiaoxi_page=1&amp;wenzhang_page=1'>首页</a>&nbsp;&nbsp;上一页&nbsp;&nbsp;下一页&nbsp;&nbsp;末页</td></tr>"));
					myrow.Cells.Add(mycell);
					peter2.Rows.Add(myrow);
				}
									else
									{
										if(page>=2)
										{
											jiaru="<tr height='23'><td height='23' align='right' colspan='3' class='tableBody1'><a href='kongzhiye.aspx?xiaoxi_page=1&amp;wenzhang_page=1'>首页</a>&nbsp;&nbsp;<a href='kongzhiye.aspx?xiaoxi_page="+ncount1+"&amp;wenzhang_page="+(ncount2-1)+"'>上一页</a>&nbsp;&nbsp;<a href='kongzhiye.aspx?xiaoxi_page="+ncount1+"&amp;wenzhang_page="+(ncount2+1)+"'>下一页</a>&nbsp;&nbsp;<a href='kongzhiye.aspx?xiaoxi_page="+ncount1+"&amp;wenzhang_page="+ncount2+"'>末页</td></tr>";
										}
										else
											jiaru="<tr height='23'><td height='23' align='right' colspan='3' class='tableBody1'><a href='kongzhiye.aspx?xiaoxi_page=1&amp;wenzhang_page=1'>首页</a>&nbsp;&nbsp;上一页&nbsp;&nbsp;下一页&nbsp;&nbsp;末页</td></tr>";
									
														
										ncount1=Convert.ToInt32(Request.Params["xiaoxi_page"].ToString());
										ncount2=Convert.ToInt32(Request.Params["wenzhang_page"].ToString());
										pagecount*=(k*ncount2-1);
										for(int i=pagecount;i<pagecount+10;i++)
										{
											try
											{
												mycell.Controls.Add(new LiteralControl("<tr height='22'><td height='23' class='tableBody1'>"+myset.Tables["haina"].Rows[i]["zhuti"].ToString().Trim()+"</td><td height='20' class='tableBody1'>"+myset.Tables["haina"].Rows[i]["faqiren"].ToString()+"</td><td height='20' class='tableBody1'>"+myset.Tables["haina"].Rows[i]["shijian"].ToString()+"</td></tr>"));
												myrow.Cells.Add(mycell);
												peter2.Rows.Add(myrow);
											}
											catch
											{
												jiaru="<tr height='23'><td height='23' align='right' colspan='3' class='tableBody1'><a href='kongzhiye.aspx?xiaoxi_page=1&amp;wenzhang_page=1'>首页</a>&nbsp;&nbsp;<a href='kongzhiye.aspx?xiaoxi_page="+ncount1+"&amp;wenzhang_page="+ncount2+"'>上一页</a>&nbsp;&nbsp;下一页&nbsp;&nbsp;末页</td></tr>";
											}
										}
										if(ncount2==1)
											jiaru="<tr height='23'><td height='23' align='right' colspan='3' class='tableBody1'><a href='kongzhiye.aspx?xiaoxi_page=1&amp;wenzhang_page=1'>首页</a>&nbsp;&nbsp;上一页&nbsp;&nbsp;<a href='kongzhiye.aspx?xiaoxi_page="+ncount1+"&amp;wenzhang_page="+(ncount2+1)+"'>下一页</a>&nbsp;&nbsp;<a href='kongzhiye.aspx?xiaoxi_page="+ncount1+"&amp;wenzhang_page="+page+"'>末页</a></td></tr>";
										mycell.Controls.Add(new LiteralControl(""+jiaru+""));
										myrow.Cells.Add(mycell);
										peter2.Rows.Add(myrow);
									}
								}
				else
				{
					mycell.Controls.Add(new LiteralControl("<tr height='25'><td colspan='3' align='center' height='25' class='tableBody1'><font color='red'>★</font>暂时没有您的文章<font color='red'>★</font></td></tr>"));
					myrow.Cells.Add(mycell);
					peter2.Rows.Add(myrow);
				}
				myconn.Close();
			}

        

		private void Page_Load(object sender, System.EventArgs e)
		{
			try
			{
				liu.Text=Request.Cookies["free_huiyuan"].Value;
				parth="SELECT * FROM huiyuan WHERE yonghuming= '"+Request.Cookies["free_huiyuan"].Value+"'";
			}
			catch
			{
			    
				Response.Redirect("error.aspx");
			}
			myconn=new SqlConnection(Session["str_connection"].ToString());
			myconn.Open();
			duoxiaoxi();
			mycomm = new SqlCommand(parth,myconn);
			SqlDataReader DR2;
			DR2=mycomm.ExecuteReader();
			if(DR2.Read())
			{
				
				touxiang.ImageUrl=DR2["face"].ToString();
				name.Text=DR2.GetValue(0).ToString();
				Session["name"]=DR2["yonghuming"].ToString();
				shengri.Text=DR2.GetValue(6).ToString();
				xingbie.Text=DR2.GetValue(7).ToString();
				jiguan.Text=DR2["sheng"].ToString()+DR2["shi"].ToString();;
				touxian.Text=DR2.GetValue(14).ToString();
				//					fatieshu.Text=DR2.GetValue(15).ToString();
				dengji.Text=DR2.GetValue(17).ToString();
				//					wenzhangshu.Text=DR2.GetValue(19).ToString();

				int fatieshu=(int)DR2["fatieshu"]+5;
				int wenzhangshu=(int)DR2["wenzhangshu"]+5;
				int jifen1=(int)DR2["jifen"]/10+5;
				int jinqian1=(int)DR2["jinqian"]/10+5;
				int meili1=(int)DR2["meili"]/10+5;
				if(fatieshu>100)
					fatieshu=100;
				if(wenzhangshu>100)
					wenzhangshu=100;
				if(jifen1>100)
					jifen1=100;
				if(jinqian1>100)
					jinqian1=100;
				if(meili1>100)
					meili1=100;
				fatie.Width=fatieshu;
				wenzhang.Width=wenzhangshu;
				jifen.Width=jifen1;
				jinqian.Width=jinqian1;
				meili.Width=meili1;
				Session["qianming"]=DR2["qianming"].ToString();
				qianming_pic.ImageUrl=DR2["qianming_pic"].ToString();
					
				zhuce.Text=DR2["zhuceshijian"].ToString();
				denglu.Text=DR2["lastlogin"].ToString();
				DR2.Close();
				myconn.Close();
				databind1();
     			databind2();
           
			}
		}

		private void duoxiaoxi()
		{
			string sql1="select count(xiaoxi_id) as zong from duanxiaoxi where jieshoufang='"+Request.Cookies["free_huiyuan"].Value+"' and islook='0' ";
			SqlCommand comm=new SqlCommand(sql1,myconn);
			SqlDataReader read=comm.ExecuteReader();
			try
			{
				
				read.Read();
				Label5.Text="["+read["zong"].ToString()+"]";
				read.Close();
			}
			catch
			{
				Label5.Text="[0]";
				read.Close();
			}
			string sql2="select count(xiaoxi_id) as zong from duanxiaoxi where faqiren='"+Request.Cookies["free_huiyuan"].Value+"'";
			SqlCommand comm2=new SqlCommand(sql2,myconn);
			SqlDataReader read2=comm2.ExecuteReader();
			try
			{
				
				read2.Read();
				Label6.Text="["+read2["zong"].ToString()+"]";
				read2.Close();
			}
			catch
			{
				Label6.Text="[0]";
                read2.Close();
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}
