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;

namespace JuSNS.Web.system.help
{
    public partial class add : JuSNS.UI.Page.ManagePage
    {
        protected string sort = "help";
        JuSNS.Home.Help help = new JuSNS.Home.Help();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (JuSNS.Common.Input.IsInteger(Request.QueryString["ID"]))
                {
                    DataTable dt = help.getHelp(Request.QueryString["ID"]);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        this.txtID.Text = dt.Rows[0]["SN"].ToString().Trim();
                        this.txtTitle.Text = dt.Rows[0]["Title"].ToString();
                        this.txtContent.Value = dt.Rows[0]["Content"].ToString();
                        this.helpID.Value = dt.Rows[0]["ID"].ToString();
                    }
                    dt.Clear(); dt.Dispose();
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                JuSNS.Model.helpInfo hp = new JuSNS.Model.helpInfo();
                hp.ID = Convert.ToInt32(this.helpID.Value);
                hp.SN = this.txtID.Text.Trim();
                hp.Title = this.txtTitle.Text;
                hp.Content = this.txtContent.Value;
                int n = 0;
                if (Convert.ToInt32(this.helpID.Value) > 0)
                {
                    n = help.UpdateAdd(hp, 1);
                }
                else
                {
                    n = help.UpdateAdd(hp, 0);
                }
                if (n == 1)
                {
                    Response.Redirect("index.aspx");
                }
                else if (n == 0)
                {
                    PageError("添加帮助信息失败!", "index.aspx");
                }
                else if (n == 2)
                {
                    PageError("添加失败,编号重复!", "index.aspx");
                }
            }
        }

    }
}
