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_messageEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 过期和权限

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

        #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_ParentId = "";

        if (str_AddTime == "")
        {
            str_AddTime = DateTime.Now.ToString();
        }

        if (Request["vid"] != null && Request["vid"] != "")
        {
            #region 操作数据库
            //执行语句

            string sql_CountFirst = string.Empty;
            sql_CountFirst += " select * from NT_Message ";
            sql_CountFirst += " where ID=" + Request["vid"].ToString();

            DataTable dt = DbHelperOleDb.ExecuteDataSet(CommandType.Text, sql_CountFirst, null).Tables[0];
            if (dt != null && dt.Rows.Count > 0) {
                str_ParentId = dt.Rows[0]["MemberId"].ToString();
            }

            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into NT_Message(");
            strSql.Append("[MemberId],[Content],[AddTime],[Fujian],[ParentId])");
            strSql.Append(" values (");
            strSql.Append("@MemberId,@Content,@AddTime,@Fujian,@ParentId)");
            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)
                
            };
            parameters[0].Value = Session["ID1"];
            parameters[1].Value = str_Content;
            parameters[2].Value = str_AddTime;
            parameters[3].Value = "";
            parameters[4].Value = str_ParentId;
            

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


            #endregion

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

}
