﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CraneAlert.Service;

namespace CraneAlert.User
{
    public partial class Password : System.Web.UI.Page
    {
        private UserInfoService service = new UserInfoService();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                if (Request.Form["action"] != null) {
                    this.updatePassword();
                }
            }
        }

        protected void updatePassword() {
            UserInfo user=(UserInfo)Session["user"];
            String oldPsw = Request.Form["OldPsw"];
            String newPsw = Request.Form["NewPsw"];
            if (!user.Password.Equals(service.MD5(oldPsw)))
            {
                Response.Write("<script>alert('输入密码错误！请确认');</script>");
               //Page.RegisterStartupScript("starup", "<script>alert('输入密码错误！请确认');</script>");

            }
            else {
                service.updatePassword(user.UserNo, service.MD5(newPsw));
                Response.Write("<script>alert('修改成功！');window.parent.location='../Login.aspx?action=loginOut';</script>");
                //Page.RegisterStartupScript("starup", "<script>alert('修改成功！');window.parent.location='../Login.aspx?action=loginOut'</script>");
            }
        }
    }
}