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 System.Data.SqlClient;
public partial class CalendarManage_AddMessage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
        
        if (Request["NotepaperID"] != null)
        {
            int id = Convert.ToInt32(Request["NotepaperID"].ToString());
            this.Label3.Visible= true;
            this.Label2.Visible= true;
            this.cmdDel.Visible = true;
            SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
            con.Open();
            string sql = "select * from Notepaper where NotepaperID="+id+"";
            SqlCommand com = new SqlCommand(sql,con);
            SqlDataReader dr = com.ExecuteReader();
            if (dr.Read())
            {
                this.Label3.Text = dr["AddTime"].ToString();
                this.TextBox1.Text = dr["Message"].ToString();

            }
        }
      
    }
    protected void cmdSaveExi_Click(object sender, ImageClickEventArgs e)
    {

    }
  
    protected void cmdExit_Click1(object sender, ImageClickEventArgs e)
    {
        Response.Write("<script>window.close();</script>");
    }
    protected void cmdSaveExi_Click1(object sender, ImageClickEventArgs e)
    {
        string Message = this.TextBox1.Text;
        string Time = DateTime.Now.ToString();
        string UsernName = Session["UserName"].ToString();
        if (this.TextBox1.Text.Trim() == "")
        {
            Response.Write("<script>alert('请输入内容！！')</script>");
        }
        else
        {
            SqlInsert sl = new SqlInsert();
            sl.InsertNotepaper(Message,Time,UsernName);
            Response.Write("<script>alert('保存成功！！');window.close();</script>");
        }
    }
    protected void cmdDel_Click(object sender, ImageClickEventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
        con.Open();
        int id = Convert.ToInt32(Request["NotepaperID"].ToString());
        string sql = "delete Notepaper where NotepaperID="+id+"";
        SqlCommand com = new SqlCommand(sql,con);
        com.ExecuteNonQuery();
        Response.Write("<script>alert('删除成功！！')</script>");
        Response.Redirect("MyNotepaper.aspx");

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (Request["NotepaperID"]==null)
        {
            Response.Write("<script>window.close();</script>");
        }
        else
        {
            Response.Redirect("MyNotepaper.aspx");
        }
    }
}
