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.Net;
using System.Data.SqlClient;

namespace free.bbs
{
	/// <summary>
	/// Summary description for _default.
	/// </summary>
	public class _default : System.Web.UI.Page
	{
		protected System.Web.UI.HtmlControls.HtmlForm Form1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.Label Label5;
		protected System.Web.UI.WebControls.Label Label6;
		protected System.Web.UI.WebControls.Label Label7;
		protected System.Web.UI.WebControls.Label Label8;
		protected System.Web.UI.WebControls.Label zuori;

		protected System.Web.UI.WebControls.Label shijian1;
		protected System.Web.UI.WebControls.Label time1;
		protected System.Web.HttpBrowserCapabilities bc;

		protected System.Data.SqlClient.SqlConnection myconn;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.HtmlControls.HtmlInputText xingming;
		protected System.Web.UI.HtmlControls.HtmlInputText password;		
		protected System.Data.SqlClient.SqlCommand mycomm;
		protected System.Web.UI.WebControls.Image Image1;
		protected System.Web.UI.WebControls.Image Image19;
		protected System.Web.UI.WebControls.Image Image20;
		protected System.Web.UI.WebControls.Image Image21;
		protected System.Web.UI.WebControls.Image Image22;
		protected System.Web.UI.WebControls.Image Image23;
		protected System.Web.UI.WebControls.Image Image24;
		protected System.Web.UI.WebControls.Image Image25;
		protected System.Web.UI.WebControls.Image Image26;
		protected System.Web.UI.WebControls.Image Image27;
		protected System.Web.UI.WebControls.Image Image28;
		protected System.Web.UI.WebControls.Image Image29;
		protected System.Web.UI.WebControls.Image Image30;
		protected System.Web.UI.WebControls.Image Image31;
		protected System.Web.UI.WebControls.Image Image32;
		protected System.Web.UI.WebControls.Image Image33;
		protected System.Web.UI.WebControls.Image Image34;
		protected System.Web.UI.WebControls.Image Image2;
		protected System.Web.UI.WebControls.Image Image3;
		protected System.Web.UI.WebControls.Image Image4;
		protected System.Web.UI.WebControls.Image Image5;
		protected System.Web.UI.WebControls.Image Image6;
		protected System.Web.UI.HtmlControls.HtmlTable table;
		protected System.Web.UI.HtmlControls.HtmlTable Table111;
		protected System.Web.UI.HtmlControls.HtmlTable Table112;
		protected System.Web.UI.HtmlControls.HtmlTable Table113;
		protected System.Web.UI.HtmlControls.HtmlTable Table3;
		protected System.Web.UI.WebControls.Panel Panel1;
		protected System.Web.UI.WebControls.Label jr;
		protected System.Web.UI.WebControls.Label zgt;
		protected System.Web.UI.WebControls.Panel Panel2;
		protected System.Web.UI.HtmlControls.HtmlImage touxiang;
		protected System.Web.UI.WebControls.Label huiyuan;
		protected System.Web.UI.WebControls.Label duanxin;
		protected System.Web.UI.WebControls.HyperLink myzhuti;
		protected System.Web.UI.WebControls.HyperLink myhuifu;
		string hostname;
		DataSet mydataset=new DataSet();
		DateTime now=DateTime.Now;
		string mysql;
		protected System.Web.UI.WebControls.Label huifu;
		protected System.Web.UI.WebControls.Label zts;
		SqlDataAdapter mydada;
		SqlDataReader read;
		//int jirifatie=0;
		private void Page_Load(object sender, System.EventArgs e)
		{
			myconn=new SqlConnection(Session["str_connection"].ToString());
			shijian1.Text=now.ToString("yyyy-MM-dd");
			time1.Text=now.DayOfWeek.ToString();
			SqlDataReader reader;
			myconn.Open();
			bool flag1;
			try 
			{
				huiyuan.Text=Request.Cookies["free_huiyuan"].Value.ToString();
				myzhuti.NavigateUrl="myzhuti.aspx?name="+Request.Cookies["free_huiyuan"].Value.ToString()+"&amp;Page=1";	
				myhuifu.NavigateUrl="myhuifu.aspx?name="+Request.Cookies["free_huiyuan"].Value.ToString()+"&amp;Page=1";	
				Application["count"]=(Int32)Application["count"]+1;
				
				if(huiyuan.Text=="dengchu")
				{
					Panel1.Visible=true;
					Panel1.Enabled=true;
					Panel2.Visible=false;
					Panel2.Enabled=false;
					flag1=false;
				}
				else
				{
					flag1=true;
					Panel2.Visible=true;
					Panel2.Enabled=true;
					Panel1.Visible=false;
					Panel1.Enabled=false;
				}

			}
			catch 
			{
				Panel1.Visible=true;
				Panel1.Enabled=true;
				Panel2.Visible=false;
				Panel2.Enabled=false;
				flag1=false;
			}
			if(flag1==true)
			{
				//论坛图象
				mysql="SELECT face FROM huiyuan where yonghuming='"+Request.Cookies["free_huiyuan"].Value.ToString()+"'";			
				mycomm=new SqlCommand(mysql,myconn);
				reader=mycomm.ExecuteReader();
				if(reader.Read())
				{
					touxiang.Src=reader.GetString(0).ToString();
					reader.Close();
				}
				else
					reader.Close();
				mysql="SELECT COUNT(jieshoufang) FROM duanxiaoxi where jieshoufang='"+Request.Cookies["free_huiyuan"].Value.ToString()+"' and islook='0' ";		
				mycomm=new SqlCommand(mysql,myconn);
				reader=mycomm.ExecuteReader();
				if(reader.Read())
				{
					duanxin.Text=reader.GetInt32(0).ToString();
					reader.Close();
				}
				else
					reader.Close();
			}
			mysql="SELECT top 1 yonghuming FROM huiyuan order by zhuceshijian desc";			
			mycomm=new SqlCommand(mysql,myconn);
			reader=mycomm.ExecuteReader();
			if(reader.Read())
			{
				Session["xinhuiyuan"]=reader.GetString(0).ToString().Trim();
				reader.Close();
			}
			else
				reader.Close();
			
			DateTime mytime=new DateTime();
			mytime=Convert.ToDateTime(now.Date);

			mysql="SELECT COUNT(huifu_id) FROM huifu WHERE shijian<'"+mytime+"'and shijian>'"+now.Date.AddDays(-1)+"'";
			mycomm=new SqlCommand(mysql,myconn);
			reader=mycomm.ExecuteReader();
			if(reader.Read())
			{
				zuori.Text=reader.GetInt32(0).ToString();
				reader.Close();
			}
			else
				reader.Close();
			try
			{

				mysql="SELECT COUNT(postid) FROM posts WHERE shijian<'"+mytime+"'and shijian>'"+now.Date.AddDays(-1)+"'";
				mycomm=new SqlCommand(mysql,myconn);
				reader=mycomm.ExecuteReader();
				int n=0;
				if(reader.Read())
				{
					n=Convert.ToInt32((Convert.ToInt32(zuori.Text.ToString())+reader.GetInt32(0)));
					reader.Close();
				}
				else
				{
					reader.Close();
				}
				mysql="SELECT COUNT(huifu_id) FROM huifu WHERE shijian<'"+mytime+"'and shijian>'"+now.Date.AddDays(-1)+"'";
				mycomm=new SqlCommand(mysql,myconn);
				reader=mycomm.ExecuteReader();
				if(reader.Read())
				{
					zuori.Text=Convert.ToString(n+(Convert.ToInt32(zuori.Text.ToString())+reader.GetInt32(0)));
					reader.Close();
				}
				else
				{
					reader.Close();
				}
			}
			catch{}
			Application.Lock();//锁定应用程序
			mydataset.ReadXml(Server.MapPath("count.xml"));//读xml文件
			zgt.Text=mydataset.Tables["MyCount"].Rows[0]["Maxtie"].ToString();
			Session["shijian"]=mydataset.Tables["MyCount"].Rows[0]["tie_shijian"].ToString();
			Label7.Text=mydataset.Tables["MyCount"].Rows[0]["MaxCount"].ToString();
			Label8.Text=mydataset.Tables["MyCount"].Rows[0]["shijian"].ToString();
			Application.UnLock();

			try
			{
				myconn=new SqlConnection(Session["str_connection"].ToString());
				myconn.Open();
			}
			catch{}
			mydataset=new DataSet();
			//今日发贴
			//DateTime now=DateTime.Now;
			//			try
			//			{

			mycomm=new SqlCommand("SELECT COUNT(*) FROM posts WHERE shijian>='"+now.ToString("yyyy-MM-dd")+"'",myconn);
			read=mycomm.ExecuteReader();
			if(read.Read())
			{
				Application["jinritieshu"]="0";
				Application["jinritieshu"]=Convert.ToInt64(Application["jinritieshu"].ToString())+read.GetInt32(0);
				read.Close();
			}
			else
			{
				read.Close();
			}
			mycomm=new SqlCommand("SELECT COUNT(*) FROM huifu  WHERE shijian>='"+now.ToString("yyyy-MM-dd")+"'",myconn);
			read=mycomm.ExecuteReader();
			if(read.Read())
			{
				Application["jinritieshu"]=Convert.ToInt64(Application["jinritieshu"].ToString())+read.GetInt32(0);
				read.Close();
			}
			else
			{
				read.Close();
			}
			//			}
			//			catch{}

			try
			{
				//					HttpCookie CkeCount=new HttpCookie("Count");
				//					if(Request.Cookies["Count"]==null)//如果cookie为空，说明第一次载入您的页面
				//					{
						
				Response.Cookies["Count"].Value="true";
				Application.Lock();
				mydataset.ReadXml(Server.MapPath("count.xml"));
				Application["all"]=int.Parse(mydataset.Tables["MyCount"].Rows[0]["AllCount"].ToString());
				int all;
				all=int.Parse(mydataset.Tables["MyCount"].Rows[0]["AllCount"].ToString());
				mydataset.Tables["MyCount"].Rows[0]["AllCount"]=all+1;
				mydataset.WriteXml(Server.MapPath("count.xml"));
						
				if(Convert.ToInt64(mydataset.Tables["MyCount"].Rows[0]["MaxCount"])<(int)Application["user_sessions"])//如果MaxCount标签里面的值小于当前在线人数的值，就存入，不小于则什么都不做。
				{
					mydataset.Tables["MyCount"].Rows[0]["MaxCount"]=(int)Application["user_sessions"];
					mydataset.Tables["MyCount"].Rows[0]["shijian"]=now.ToString();
					mydataset.WriteXml(Server.MapPath("count.xml"));
				}
				if(Convert.ToInt64(mydataset.Tables["MyCount"].Rows[0]["Maxtie"])<(int)Application["jinritieshu"])//如果MaxCount标签里面的值小于今日发帖数数的值，就存入，不小于则什么都不做。
				{
					mydataset.Tables["MyCount"].Rows[0]["Maxtie"]=Application["jinritieshu"];
					mydataset.Tables["MyCount"].Rows[0]["tie_shijian"]=now.ToString();
					mydataset.WriteXml(Server.MapPath("count.xml"));
				}
				Application.UnLock();
				//					}
				
			}
			catch{}			
					
			try
			{
				mycomm=new SqlCommand("select count(yonghuming) 数量 from huiyuan",myconn);
				read=mycomm.ExecuteReader();
				if(read.Read())
				{
					//string huiyuanshuliang=read["数量"].ToString();
					Application["huiyuanshuliang"]=read["数量"].ToString();
					read.Close();
				}
			}
			catch{}
			try
			{
				mycomm=new SqlCommand("select count(postid) 问题总数 from posts",myconn);
				read=mycomm.ExecuteReader();
				if(read.Read())
				{
					Application["wentizongshu"]=read["问题总数"];
					read.Close();
				}
			}
			catch{}
			try
			{
				mycomm=new SqlCommand("select count(*) 回复总数 from huifu",myconn);
				read=mycomm.ExecuteReader();
				if(read.Read())
				{
					Application["huifuzongshu"]=read["回复总数"];
					read.Close();
				}
			}
			catch{}	
				
						
			
			
			//Label6.Text=Convert.ToString((int)Application["user_sessions"]-(int)Application["huiyuan_sessions"]);
  
			HttpBrowserCapabilities bc= Request.Browser; 
			Label3.Text=bc.Browser+" "+bc.Version;
			Label2.Text=bc.Platform;
			hostname=Dns.GetHostName();
			IPHostEntry jj=Dns.GetHostByName(hostname);
			//IPAddress ip=Dns.Resolve(hostname);
			Label1.Text=jj.AddressList[0].ToString();


			//主体
			mysql="SELECT  * FROM ancestor  ORDER BY ancestor_id";
			//Try
			
			mydada=new SqlDataAdapter(mysql,myconn);
			DataTable mytable;
			DataTable mytable1;
			DataTable mytable2;
			DataTable mytable3;
			DataTable mytable4;
			DataTable mytable5;
			mytable=new DataTable();
			mydada.Fill(mytable);
			
			//
			HtmlTableRow myrow;
			HtmlTableCell mycell;
			if(mytable.Rows.Count>0)
			{
				for(int i=0;i<=mytable.Rows.Count-1;i++)
				{
					mysql="SELECT  top 1 postid,zhuti,yonghuming,shijian  FROM posts where ancestor_id='"+mytable.Rows[i]["ancestor_id"]+"'  ORDER BY postid desc";
					mydada=new SqlDataAdapter(mysql,myconn);
					mytable1=new DataTable();
					mydada.Fill(mytable1);
					string zhuti;
					string name;
					string time;
					try
					{
						if(mytable1.Rows[0]["zhuti"].ToString().Length>=15)
							zhuti=mytable1.Rows[0]["zhuti"].ToString().Trim().Substring(0,15)+"<FONT color='gray'>…</font>";
						else
							zhuti=mytable1.Rows[0]["zhuti"].ToString().Trim();
						zhuti="<A href='huifu.aspx?post_id="+mytable1.Rows[0]["postid"].ToString()+"&amp;ancestor_id="+mytable.Rows[i]["ancestor_id"]+"&amp;Page=1'><font face='宋体' color='#0066ff'>"+zhuti+"</font></A>";
						name=mytable1.Rows[0]["yonghuming"].ToString().Trim();
						name="<A title='点击查看作者资料' href='hyziliaochakan.aspx?UserId="+name+"' target='_blank'><font face='宋体'><font color=#BB865E>※</font>"+name+"<font color=#BB865E>※</font></font></a>";
						time=Convert.ToDateTime(mytable1.Rows[0]["shijian"]).ToLongDateString().ToString();

					}
					catch
					{
						zhuti="<font color=#ff00ff>暂无新主题</font>";
						name="";
						time="";
					}

					mysql="SELECT  count(*)  FROM posts where ancestor_id='"+mytable.Rows[i]["ancestor_id"]+"' ";
					mydada=new SqlDataAdapter(mysql,myconn);
					//mytable1.Clear();
					mytable2=new DataTable();
					mydada.Fill(mytable2);
					string top="";
					try
					{
						top=mytable2.Rows[0][0].ToString().Trim();
					}
					catch
					{}
					////////////////////
					DateTime now1=DateTime.Now;
					mysql="SELECT  count(postid)   FROM posts where ancestor_id='"+mytable.Rows[i]["ancestor_id"]+"' and shijian>='"+now1.ToString("yyyy-MM-dd")+"'";
					mydada=new SqlDataAdapter(mysql,myconn);
					//mytable1.Clear();
					mytable3=new DataTable();
					mydada.Fill(mytable3);
					string today="0";
					int today1=0;
					try
					{
						today1=Convert.ToInt32(mytable3.Rows[0][0].ToString());
					}
					catch
					{}
					mysql="SELECT  distinct count(huifu_id)  FROM huifu,posts where posts.ancestor_id='"+mytable.Rows[i]["ancestor_id"]+"' and posts.postid=huifu.post_id and huifu.shijian>='"+now1.ToString("yyyy-MM-dd")+"'";
					mydada=new SqlDataAdapter(mysql,myconn);
					//mytable1.Clear();
					mytable5=new DataTable();
					mydada.Fill(mytable5);
					try
					{
						today=Convert.ToString(today1+Convert.ToInt32(mytable5.Rows[0][0].ToString()));
					}
					catch
					{}
					//////////////////////
					mysql="SELECT  distinct count(huifu_id)  FROM huifu,posts where posts.ancestor_id='"+mytable.Rows[i]["ancestor_id"]+"' and posts.postid=huifu.post_id";
					mydada=new SqlDataAdapter(mysql,myconn);
					//mytable4.Clear();
					mytable4=new DataTable();
					mydada.Fill(mytable4);
					string huifu="";
					try
					{
						huifu=mytable4.Rows[0][0].ToString().Trim();
					}
					catch
					{}

					string banzhu="";
					if(mytable.Rows[i]["banzhu"].ToString().Trim()=="")
						banzhu="<A  href='../ader/zhaoping.aspx'target='_blank'>诚聘版主</a>";
					else
						banzhu="<font color=#BB865E>|</font><A title='点击查看版主资料' href='hyziliaochakan.aspx?UserId="+mytable.Rows[i]["banzhu"].ToString().Trim()+"' target='_blank'><font face='宋体' color=red>"+mytable.Rows[i]["banzhu"].ToString().Trim()+"</font></A><font color=#BB865E>|</font>";
					string banzhu1="";
					if(mytable.Rows[i]["banzhu1"].ToString().Trim()=="")
						banzhu1="";
					else
						banzhu1="<font color=#BB865E>|</font><A title='点击查看版主资料' href='hyziliaochakan.aspx?UserId="+mytable.Rows[i]["banzhu1"].ToString().Trim()+"' target='_blank'><font face='宋体' color=#800000>"+mytable.Rows[i]["banzhu1"].ToString().Trim()+"</font></A><font color=#BB865E>|</font>";

					string banzhu2="";
					if(mytable.Rows[i]["banzhu2"].ToString().Trim()=="")
						banzhu2="";
					else
						banzhu2="<font color=#BB865E>|</font><A title='点击查看版主资料' href='hyziliaochakan.aspx?UserId="+mytable.Rows[i]["banzhu2"].ToString().Trim()+"' target='_blank'><font face='宋体' color=#800000>"+mytable.Rows[i]["banzhu2"].ToString().Trim()+"</font></A><font color=#BB865E>|</font>";

					string banzhu3="";
					if(mytable.Rows[i]["banzhu3"].ToString().Trim()=="")
						banzhu3="";
					else
						banzhu3="<font color=#BB865E>|</font><A title='点击查看版主资料' href='hyziliaochakan.aspx?UserId="+mytable.Rows[i]["banzhu3"].ToString().Trim()+"' target='_blank'><font face='宋体' color=#800000>"+mytable.Rows[i]["banzhu3"].ToString().Trim()+"</font></A><font color=#BB865E>|</font>";

					string banzhu4="";
					if(mytable.Rows[i]["banzhu4"].ToString().Trim()=="")
						banzhu4="";
					else
						banzhu4="<font color=#BB865E>|</font><A title='点击查看版主资料' href='hyziliaochakan.aspx?UserId="+mytable.Rows[i]["banzhu4"].ToString().Trim()+"' target='_blank'><font face='宋体' color=#800000>"+mytable.Rows[i]["banzhu4"].ToString().Trim()+"</font></A><font color=#BB865E>|</font>";

					string lujing="";

					mycomm=new SqlCommand("SELECT COUNT(huifu_id) FROM huifu,posts WHERE (   "+
						"posts.postid=huifu.post_id and posts.ancestor_id="+mytable.Rows[i]["ancestor_id"]+" and huifu.shijian>='"+DateTime.Now.ToString("yyyy-MM-dd")+"')",myconn);
					 read=mycomm.ExecuteReader();
					if(read.Read())
					{
						if(read.GetInt32(0)>0)
						{
							lujing="<IMG alt='有新的帖子' src='./images/forum_isnews.gif'>";
							read.Close();
						}
						else
						{
							read.Close();
							mycomm=new SqlCommand("SELECT COUNT(postid) FROM posts WHERE (   "+
								"ancestor_id="+mytable.Rows[i]["ancestor_id"]+" and shijian>='"+DateTime.Now.ToString("yyyy-MM-dd")+"')",myconn);
							read=mycomm.ExecuteReader();
							if(read.Read())
							{
								if(read.GetInt32(0)>0)
								{
									lujing="<IMG alt='有新的帖子' src='./images/forum_isnews.gif'>";
									read.Close();
								}
								else
								{								
									lujing="<font face='宋体'><IMG alt='没有新的帖子' src='./images/forum_nonews.gif'></font>";
									read.Close();
								}
							}
							else
							{
								lujing="<IMG alt='没有新的帖子' src='./images/forum_nonews.gif'>";
								reader.Close();
							}
						}
					}
					else
					{
						lujing="<IMG alt='没有新的帖子' src='./images/forum_nonews.gif'>";
						reader.Close();
					}
					if(mytable.Rows[i]["islock"].ToString()=="1")
						lujing="<IMG alt='被锁定的论坛' src='./images/forum_lock.gif'>";
					myrow=new HtmlTableRow();
					//cell1
					mycell=new HtmlTableCell();
					mycell.Controls.Add(new LiteralControl ("<TABLE class=tableBorder1  cellSpacing='1'  cellPadding='0' width='760' align='center' border='0'>"+
						"<TR>"+
						"<TD class='tablebody1' width=60px style='WIDTH: 60px' height='90' rowSpan='2' align='center' valign='middle'>"+
						"<P>"+lujing+"</P>"+
						"</TD>"+
						"<TD class='tableBody1' rowSpan='1'  height='70'>"+
						       "<TABLE id='Table3' cellSpacing='0' cellPadding='0' width='100%' border='0'>"+
								"<TR><td width='380'>〖<A href='zhuti.aspx?ancestor_id="+mytable.Rows[i]["ancestor_id"]+"&amp;Page=1'><FONT color='blue'>"+mytable.Rows[i]["neirong"]+"</FONT></FONT></A>〗<br>"+
								"&nbsp;<A title="+mytable.Rows[i]["neirong"]+" href='zhuti.aspx?ancestor_id="+mytable.Rows[i]["ancestor_id"]+"&amp;Page=1'><IMG src='./images/Forum_readme.gif' border='0'></A>&nbsp; "+
								"		"+mytable.Rows[i]["shuoming"]+""+
								"	</TD>"+	
						        "<td width=80 ><A href='zhuti.aspx?ancestor_id="+mytable.Rows[i]["ancestor_id"]+"&amp;Page=1' title='"+mytable.Rows[i]["shuoming"]+"'><IMG  width='65' height='65' border=0  src='"+mytable.Rows[i]["face"]+"'></a></td> "+	
								"<TD class='tableBody1' width=240  height='60'>"+
									"<FONT face='宋体'>主题："+zhuti+"</FONT><br>"+
									"<FONT face='宋体'>作者："+name+"</FONT><br>"+
						            "<FONT face='宋体'>日期："+time+"</FONT>"+
                                "</TR></table>"+						
						"</td></TR>"+						
						"<TR><td><TABLE id='Table3' cellSpacing='0' cellPadding='0' width='100%' border='0'>"+
						"<tr>	<TD class='tablebody2' height='20'>版主："+banzhu+" "+banzhu1+" "+banzhu2+" "+banzhu3+" "+banzhu4+""+
						"	</TD>"+
						"	<TD class='tablebody2' width='240' height='20'><FONT face='宋体' color=#000000><b>Today：</b><font color=red>"+today+"</font></FONT>&nbsp;&nbsp;&nbsp;<FONT face='宋体'><FONT face='宋体' color=#000000><b>Topics：</b></font>"+top+"</FONT>&nbsp;&nbsp;&nbsp;<FONT face='宋体'><FONT face='宋体' color=#000000><b>Posts：</b></font>"+huifu+"</FONT></TD></tr></table></td>"+
						"</TR>"+
						"</TABLE>	<table cellSpacing='0'  cellPadding='0'  border='0'><tr><td height=1></td></tr></table>"));
					myrow.Cells.Add(mycell);
					if(Convert.ToInt32(mytable.Rows[i]["ancestor_id"])<10)
						table.Rows.Add(myrow);
					else if( Convert.ToInt32(mytable.Rows[i]["ancestor_id"])<20)
						Table111.Rows.Add(myrow);
					else if( Convert.ToInt32(mytable.Rows[i]["ancestor_id"])<30)
						Table112.Rows.Add(myrow);
					else 
						Table113.Rows.Add(myrow);
				}
			}
			myconn.Close();
		}
		private void Button1_Click(object sender, System.EventArgs e)
		{
			if(xingming.Value.Trim()==""||password.Value.Trim()=="")
			{
				Response.Redirect("error.aspx");
				
			}
			else
			{
				string sql="select* from huiyuan where yonghuming=@name and mima=@mima";
				mycomm= new SqlCommand(sql,myconn);
				mycomm.Parameters.Add(new SqlParameter("@name", SqlDbType.Char, 20));
				mycomm.Parameters["@name"].Value =xingming.Value.Trim();

				mycomm.Parameters.Add(new SqlParameter("@mima", SqlDbType.Char, 20));
				mycomm.Parameters["@mima"].Value =password.Value.Trim();
				myconn.Open();	
				
				SqlDataReader dr;
				dr=mycomm.ExecuteReader();
				if(dr.Read())
				{
					Response.Cookies["free_huiyuan"].Value=xingming.Value.ToString().Trim();
					dr.Close();
					myconn.Close(); 
					myconn.Open();
					mycomm=new SqlCommand("update huiyuan set lastlogin='"+DateTime.Now+"'where yonghuming='"+xingming.Value.Trim()+"'",myconn);
					mycomm.ExecuteNonQuery();				
					Response.Redirect("default.aspx");
				}
				else
				{
					dr.Close();
					Response.Redirect("error.aspx");
				}			
				myconn.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.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}
