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.admin
{
    public partial class add : JuSNS.UI.Page.ManagePage
    {
        protected string sort = "admin";
        JuSNS.Manage.Manager MG = new JuSNS.Manage.Manager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string ID = Request.QueryString["ID"];
                if (JuSNS.Common.Input.IsInteger(ID))
                {
                    DataTable dt = MG.GetAdminInfo(Convert.ToInt32(ID));
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        this.TxtUserName.Text = dt.Rows[0]["LoginName"].ToString();
                        this.TxtTrueName.Text=dt.Rows[0]["TrueName"].ToString();
                    }
                    dt.Clear(); dt.Dispose();
                }
            }
        }

        protected void BtnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string UserName = this.TxtUserName.Text;
                string uPass = this.TxtPassword.Text;
                string uTrueName = this.TxtTrueName.Text;
                int ID = Convert.ToInt32(this.AdminID.Value);
                int State = 5;
                if (this.isLock.Checked)
                {
                    State = 1;
                }
                int n = MG.AddAdmin(UserName, uPass, uTrueName, State);
                if (n == 2)
                {
                    Response.Redirect("list.aspx");
                }
                else if (n == 1)
                {
                    PageRight("添加管理员成功。", "add.aspx");
                }
                else
                {
                    PageError("添加失败。", "add.aspx");
                }
            }
        }
    }
}
