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;
using System.Text;
using System.Data.SqlClient;

public partial class manage_Remima : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Loginjudge();
    }

   
    protected void surbtn_Click(object sender, EventArgs e)
    {
        string oname = oldname.Text.Trim().ToString();
        string opass = oldpass.Text.Trim().ToString();
        string nname = newname.Text.Trim().ToString();
        string npass = newpass.Text.Trim().ToString();
        string rname = rename.Text.Trim().ToString();
        string rpass = repass.Text.Trim().ToString();
        if(oname.Length<1||opass.Length<1||nname.Length<1||npass.Length<1||rname.Length<1||rpass.Length<1)
        {
            lblError.Text="所有字段不能为空！";
            return;
        }
        INews shownews = new Mynews();
        SqlDataReader dr = Getmima(shownews.Myencode(oname),shownews.Myencode(opass));
        if (dr.Read())
        {
            Remima(shownews.Myencode(nname), shownews.Myencode(npass));
            lblError.Text = "密码修改成功！";
        }
        else
        {
            lblError.Text = "输入密码错误！";
        }
    }
    //取密码
    public SqlDataReader Getmima(string sName, string sPass)
    {
        INews shownews = new Mynews();
        SqlDataReader dr = shownews.SqlGetinfo("SELECT * FROM Myuser WHERE Username='" + sName + "' AND Userpass='" + sPass + "'");
        return dr;
    }
    //修改密码
    public int Remima(string sName, string sPass)
    {
        int nResult = -1;
        INews shownews = new Mynews();
        nResult = shownews.Executeinfo("UPDATE Myuser SET Username='" + sName + "',Userpass='" + sPass + "'");
        return nResult;
    }
    private void Loginjudge()
    {
        if (Session["Login"] == null)
        {
            Response.Redirect("Error.aspx");
        }
        else
        {
            if (Session["Login"] != "pass")
            {
                Response.Redirect("Error.aspx");
            }

        }
    }
}
