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;

public partial class admin_Edit_New_Pic : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BLL.UserInfo user = new BLL.UserInfo();
        if (user.IsLogin() == true && user.getUserRole() == 2)
        {
            if (!this.IsPostBack)
            {
                this.Bind();
            }
        }
        else
        {
            this.Response.Redirect("Admin_Login.aspx");
        }
    }
    /// <summary>
    /// 绑定图片
    /// </summary>
    private void Bind()
    {
        this.pic.ImageUrl = "../images/uploadfiles/" + this.Request.QueryString["path"].ToString();
    }

    protected void uploadBt_Click(object sender, EventArgs e)
    {
        if (this.picupload.HasFile)
        {
            if (this.Request.QueryString["path"].ToString() != "nopic.gif")
            {
                string savePath = @"../images/uploadfiles/" + this.Request.QueryString["path"].ToString();
                string savePath1 = @"../images/uploadfiles/smallPic/" + this.Request.QueryString["path"].ToString();
                savePath = Server.MapPath(savePath);
                savePath1 = Server.MapPath(savePath1);
                this.picupload.SaveAs(savePath);
                Tools.ImageClass imageClass = new Tools.ImageClass();
                imageClass.ShowThumbnail(savePath, savePath1, 200, 153);
            }
            else
            {
                string savePath = @"../images/uploadfiles/";
                string savePath1 = @"../images/uploadfiles/smallPic/";
                string fileName = Server.HtmlEncode(this.Request.QueryString["path"].ToString());
                string extension = System.IO.Path.GetExtension(fileName);
                string ImageName = null;

                if ((extension == ".jpg") | (extension == ".gif"))
                {
                    ImageName = DateTime.Now.ToString("yyyyMMddhhmmssfff") + extension;
                    savePath += ImageName;
                    savePath1 += ImageName;
                    savePath = Server.MapPath(savePath);
                    savePath1 = Server.MapPath(savePath1);

                    BLL.News news = new BLL.News();
                    if (news.updatepic(ImageName, int.Parse(this.Request.QueryString["pid"].ToString())) == 1)
                    {
                        this.picupload.SaveAs(savePath);
                        //生成小图
                        Tools.ImageClass imageClass = new Tools.ImageClass();
                        imageClass.ShowThumbnail(savePath, savePath1, 200, 153);
                    }
                }
                else
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('图片格式错误')</script>", false);
                }
            }
            this.Response.Redirect("Edit_New.aspx?pid=" + this.Request.QueryString["pid"].ToString());
        }
        else
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('请选择商品图片')</script>", false);
        }
    }
}
