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


namespace free.bbs
{
	/// <summary>
	/// Summary description for xinxifasong.
	/// </summary>
	public class xinxifasong : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox TextBox1;
		string UserName;
		protected System.Web.UI.WebControls.TextBox zhuti;
		protected System.Web.UI.WebControls.LinkButton fasong;
		protected System.Web.UI.WebControls.LinkButton quxiao;
		protected System.Web.UI.WebControls.Panel p2;
		protected System.Web.UI.WebControls.TextBox jieshouzhe;
		SqlConnection myconn;
		SqlCommand mycomm;
		void  GetName(string LogName)
		{
			UserName= LogName;
			
		}
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			
			myconn=new SqlConnection(Session["str_connection"].ToString());
			try
			{
				string ss=Request.Cookies["free_huiyuan"].Value.ToString();
			}
			catch
			{
				Response.Redirect("error.aspx");
			}
			if(!Page.IsPostBack)
			{
				try
				{
					jieshouzhe.Text=Request.Params["jieshouren"].ToString();
				}
				catch
				{
					jieshouzhe.Text="";
				}
			}


		}

		#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.fasong.Click += new System.EventHandler(this.fasong_Click);
			this.quxiao.Click += new System.EventHandler(this.quxiao_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void quxiao_Click(object sender, System.EventArgs e)
		{
			Response.Write("<script>window.close()</script>");
		}
        
		
		private void fasong_Click(object sender, System.EventArgs e)
		{
			try
			{
				if(jieshouzhe.Text=="")
					Response.Write("<script>alert('您必须指定一个接收人！')</script>");
				else if(zhuti.Text=="")
					Response.Write("<script>alert('发送主题不能为空！')</script>");
				else if(TextBox1.Text=="")
					Response.Write("<script>alert('发送内容不能为空！')</script>");
				else
				{
					
					DateTime DeT = DateTime.Now;
					myconn.Open();
					//string sqlins="INSERT INTO duanxiaoxi(neirong,faqiren,jieshoufang,shijian,zhuti) VALUES( '"+TextBox1.Text+"','"+Request.Cookies["free_huiyuan"].Value+"','"+SelName+"','"+DeT.ToString()+"', '"+zhuti.Text+"')";
					string sqlins="INSERT INTO duanxiaoxi(neirong,faqiren,jieshoufang,shijian,zhuti) VALUES(@neirong,@faqiren,@jieshoufang,@time,@zhuti)";
					mycomm= new SqlCommand(sqlins,myconn);
					mycomm.Parameters.Add(new SqlParameter("@neirong",SqlDbType.NText,16));
					mycomm.Parameters["@neirong"].Value=TextBox1.Text;
					mycomm.Parameters.Add(new SqlParameter("@faqiren",SqlDbType.Char,12));
					mycomm.Parameters["@faqiren"].Value=Request.Cookies["free_huiyuan"].Value;
					mycomm.Parameters.Add(new SqlParameter("@jieshoufang",SqlDbType.Char,12));
					mycomm.Parameters["@jieshoufang"].Value=jieshouzhe.Text.Trim();
					mycomm.Parameters.Add(new SqlParameter("@time",SqlDbType.DateTime));
					mycomm.Parameters["@time"].Value=DeT;
					mycomm.Parameters.Add(new SqlParameter("@zhuti",SqlDbType.Char,100));
					mycomm.Parameters["@zhuti"].Value=zhuti.Text;
					try
					{
						mycomm.ExecuteNonQuery();
						myconn.Close();
						Response.Write("<script>alert('短消息发送成功！')</script>");
						Response.Write("<script>window.close()</script>");
					}
					catch
					{
						myconn.Close();
						Response.Write("<script>alert('短消息发送失败！')</script>");
						Response.Write("<script>window.close()</script>");
					}
			
				}
			}
			catch
			{}

		}


	}
}
