using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
//author:Angel_asp
//QQ：709047174
//website:www.angelasp.com
public partial class Admin_Message_EditMessage : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack){

            int id=int.Parse(Request.QueryString["id"].ToString());

            if (id > 0)
            {
                DataSet ds = new DataSet();
                string sql = "select * from A_Message where id=" + id + "";

                if (ISDatabase.SelectDatebase() == 1)
                    ds = DbHelp.Query(sql);
                else
                    ds = DbHelperOleDb.Query(sql);

                this.id.Text = id.ToString();
                this.Title.Text = ds.Tables[0].Rows[0]["Title"].ToString();
                this.M_user.Text = ds.Tables[0].Rows[0]["M_user"].ToString();
                this.M_Ip.Text = ds.Tables[0].Rows[0]["M_Ip"].ToString();
                this.Contents.InnerText = ds.Tables[0].Rows[0]["Contents"].ToString();
                this.AddTime.Text = ds.Tables[0].Rows[0]["AddTime"].ToString();
                this.ReyContent.InnerText = ds.Tables[0].Rows[0]["Rey_Contents"].ToString();
                this.ReyTime.Text = ds.Tables[0].Rows[0]["ReyTime"].ToString();

            }
            else
            {
                string sb = "<script>$(function () { $.ligerDialog.alert(\"无法回复该留言！！\", \"提示\", \"error\", function (result) { window.location.href ='main.aspx'; }); });</script>";
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "Messager", sb.ToString());

            }
        }

    }


    protected void btnSubmit_Click(object sender, EventArgs e)
    {
      int id=Convert.ToInt32(this.id.Text);
      string Title=this.Title.Text;
      string M_user=this.M_user.Text;
      string Contents =this.Contents.InnerText;
      string ReyContent= this.ReyContent.InnerText ;
      string time = DateTime.Now.ToString("yyyy-MM-dd");
      string sql = "update A_Message set Title='" + Title + "', Contents='" + Contents + "' , M_user='" + M_user + "' , Rey_Contents='" + ReyContent + "', ReyTime='" + time + "' where id=" + id + " ";
      int result;
      if (ISDatabase.SelectDatebase() == 1)
          result = DbHelp.ExecuteSql(sql);
      else
          result = DbHelperOleDb.ExecuteSql(sql);

      if (result > 0)
      {
             string sb = "<script>$(function () { $.ligerDialog.alert(\"修改成功\", \"提示\",\"success\",function (result) { window.location.href ='main.aspx'; }); });</script>";
             Page.ClientScript.RegisterStartupScript(Page.GetType(), "Messager", sb.ToString());

      }
      else 
      {
          string sb="<script>$(function () { $.ligerDialog.alert(\"修改失败\", \"提示\",\"error\", function (result) { window.location.href ='main.aspx'; }); });</script>";
          Page.ClientScript.RegisterStartupScript(Page.GetType(), "Messager", sb.ToString());
      }


    }
}
//author:Angel_asp
//QQ：709047174
//website:www.angelasp.com