using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Models;
using LoveBLL;

namespace LoveWeb.Login
{
    public partial class User_Admin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                Boolean fileOK = false;
                string path = Server.MapPath("~/images/userimage/");
                if (FileUpload1.HasFile)
                {
                    string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
                    string[] allowedExtensions = { ".gif", "png", ".jpeg", ".jpg" };
                    for (int i = 0; i < allowedExtensions.Length; i++)
                    {
                        if (fileExtension == allowedExtensions[i])
                        {
                            fileOK = true;
                        }
                    }
                }
                if (fileOK)
                {
                    try
                    {
                        FileUpload1.PostedFile.SaveAs(path + FileUpload1.FileName);
                        //HiddenField1.Value = path + FileUpload1.FileName;

                    }
                    catch (Exception ex)
                    {

                    }

                }

            }
            else
            {
                //Response.Write("<script>alert('添加文章失败！')</script>");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            User user = new User();
            user.Pwd = textpwd1.Text.Trim();
            string username = (string)Session["username"];
            user.Userid = UserManager.GetIdByUsername(username).Userid;
            if (UserManager.UpPwd(user))
            {
                Response.Write("<script>alert('修改成功！')</script>");
                textpwd1.Text = "";
                textpwd.Text = "";
                
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            User user = new User();
            user.Userimage = "~/images/userimage/"+FileUpload1.FileName;
            string username = (string)Session["username"];
            user.Userid = UserManager.GetIdByUsername(username).Userid;
            if (UserManager.UpUserImage(user))
            {
                Response.Write("<script>alert('修改成功！')</script>");
                textpwd1.Text = "";
                textpwd.Text = "";
                Response.Redirect("User_Admin.aspx");

            }

        }

        protected void Button4_Click(object sender, EventArgs e)
        {
           
        }
    }
}
