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 adminEdit : 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();
                        this.TxtUserName.ReadOnly=true;
                        this.Password.Value = dt.Rows[0]["Password"].ToString();
                        this.AdminID.Value = dt.Rows[0]["AdminID"].ToString();
                    }
                    dt.Clear(); dt.Dispose();
                }
            }
        }

        protected void BtnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string UserName = this.TxtUserName.Text;
                int AdminID = Convert.ToInt32(this.AdminID.Value);
                string uPass = string.Empty;
                if (!string.IsNullOrEmpty(this.TxtPassword.Text))
                {
                    uPass = JuSNS.Common.Input.MD5(this.TxtPassword.Text, false);
                }
                else
                {
                    uPass = this.Password.Value;
                }
                string uTrueName = this.TxtTrueName.Text;
                int ID = Convert.ToInt32(this.AdminID.Value);
                int State = 5;
                if (this.isLock.Checked)
                {
                    State = 1;
                }
                int n = MG.updateAdmin(UserName, uPass, uTrueName, State, AdminID);
                 if (n == 1)
                {
                    Response.Redirect("list.aspx");
                }
                else
                {
                    PageError("Ìí¼ÓÊ§°Ü¡£", "add.aspx");
                }
            }
        }
    }
}