using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using xabaraCOM;

public partial class member_user_photo : System.Web.UI.Page
{
    user u = new user();
    sqlServer sql = new sqlServer();
    fileDocument f = new fileDocument();
    javasrcipt js = new javasrcipt();

    protected void Page_Load(object sender, EventArgs e)
    {
        u.check("", url.before);
        Page.Title = "头像设置　" + xml.read("xabara.config", "webName", 180) + xml.read("xabara.config", "titleMeta", 180);

        if (!IsPostBack)
        {
            DataTable dt = sql.getDataTable("select * from xabaraUser where userCardID='" + u.userCardID + "'");
            if (dt.Rows.Count > 0)
            {
                string img = dt.Rows[0]["userImg"].ToString().Trim();
                hidImg.Value = img;

                if (!string.IsNullOrEmpty(img as string))
                {
                    img += ".200.jpg";
                }
                myImg.ImageUrl = f.picDisplay(img);
            }
            else
            {
                js.div(false, "", "text", "您的操作有误！", 350, 0, "my.aspx", "top");
            }
            dt.Dispose();
        }
    }

    protected void postButton_Click(object sender, ImageClickEventArgs e)
    {
        string fileName = hidImg.Value;
        string uploadStr = f.upload(uploadImg, "Img", false);
        if (uploadStr.Equals("上传成功"))
        {
            f.del(fileName);   //删除旧头像

            fileName = Session["NewFile"].ToString();
            f.MakeThumbnail(fileName, 200, 0, "W");

            string[] strValue = new string[1];
            strValue[0] = fileName;
            sql.update("xabaraUser", "@userImg", strValue, "userCardID='" + u.userCardID + "'");

            sql.log(u.userCardID, "user", "设置头像");

            js.div(false, "", "text", "您的头像已上传！<br /><br /><img src='" + f.picDisplay(fileName) + ".200.jpg' />", 500, 0, "photo.aspx", "top");
        }
        else
        {
            js.div(false, "", "text", uploadStr, 350, 0, "photo.aspx", "top");
        }
    }
}