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 baoge.chat
{
	/// <summary>
	/// ChatWin 的摘要说明。
	/// </summary>
	public class ChatWin : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox TB_ToSend;
		protected System.Web.UI.WebControls.Button BT_Send;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if ( Page.IsPostBack == false )
			{
				if ( Request.Params["Channel"] != null )
					Session["ChatChannel"] = Request.Params["Channel"].ToString();
				else
					Session["ChatChannel"] = "1";

				
			}
		}

		public string GetChatPage()
		{
			return("TheChatScreenWin.aspx");
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.BT_Send.Click += new System.EventHandler(this.BT_Send_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void BT_Send_Click(object sender, System.EventArgs e)
		{
			string sChannel = "";
			string sUser = "";

			if ( Request.Params["Channel"] != null )
				sChannel = Request.Params["Channel"].ToString();
			else
				sChannel = "1";

			if ( Request.Params["User"] != null )
				sUser = Request.Params["User"].ToString();
			else
			{
				Random pRan = new Random();
				int iNum = pRan.Next(9);
				sUser = "Annonymouse" + iNum;
			}

			
			if ( TB_ToSend.Text.Length > 0)
			{
				
				Chat.AddMessage(sChannel,
					sUser,
					TB_ToSend.Text);
				
				TB_ToSend.Text = "";		
			}
		}
	}
}
