using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Data.OleDb;

public partial class system_Message_messageAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 过期和权限

        PageFunc.IfSystemLogin(this.Page);
        //PubPageFunc.PageHavePurview(this.Page, "2001");

        StringBuilder strSql = new StringBuilder();
        strSql.Append("select [Name]  from NT_Member " );
        strSql.Append(" where NT_Member.ID=@ID");
        OleDbParameter[] parameters = { new OleDbParameter("@ID", OleDbType.Integer, 4) };
        parameters[0].Value = Session["ID1"];

        OleDbDataReader sdr = DbHelperOleDb.ExecuteDataReader(CommandType.Text, strSql.ToString(), parameters);
        if (sdr.HasRows)
        {
            while (sdr.Read())
            {
                this.lab_name.Text = sdr["name"].ToString();
            }
        }
        sdr.Close();
        #endregion
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string str_Content = this.FileContent.Text.Trim();
        string str_AddTime = this.txt_AddTime.Text.Trim();
        string str_Title = this.txt_Title.Text.Trim();
        if (str_AddTime == "") {
            str_AddTime = DateTime.Now.ToString();
        }

        #region 操作数据库
        //执行语句

        StringBuilder strSql = new StringBuilder();
        strSql.Append("insert into NT_Message(");
        strSql.Append("[MemberId],[Content],[AddTime],[Fujian],[ParentId],[title])");
        strSql.Append(" values (");
        strSql.Append("@MemberId,@Content,@AddTime,@Fujian,@ParentId,@title)");
        OleDbParameter[] parameters = 
        {
            new OleDbParameter("@MemberId", OleDbType.Integer,4),
            new OleDbParameter("@Content", OleDbType.VarChar),
            new OleDbParameter("@AddTime", OleDbType.VarChar),
            new OleDbParameter("@Fujian", OleDbType.VarChar),
            new OleDbParameter("@ParentId", OleDbType.Integer,4),
            new OleDbParameter("@title", OleDbType.VarChar)
        };
        parameters[0].Value = Session["ID1"];
        parameters[1].Value = str_Content;
        parameters[2].Value = str_AddTime;
        parameters[3].Value = "";
        parameters[4].Value = "0";
        parameters[5].Value = str_Title;


        DbHelperOleDb.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);


        #endregion

        JavaScriptFunc.AlertAndRedirect(this.Page, "添加成功", "message.aspx");
    }

}
