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_Goods : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                Boolean fileOK = false;
                string path = Server.MapPath("~/images/");
                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;
                        Label1.Text = "文件上传成功！";
                    }
                    catch (Exception ex)
                    {
                        Label1.Text = "文件不能上传！";
                    }

                }
                else
                {
                    Label1.Text = "不能接收这种文件类型！";
                }
            }
            else
            {
                //Response.Write("<script>alert('添加文章失败！')</script>");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Goods goods = new Goods();
            goods.Goodsname = btnTitle.Text.Trim();
            goods.Introduce = FCKeditor1.Value;
            goods.Author = (string)Session["username"];
            goods.Goodstime = System.DateTime.Now;
            goods.GoodsImage = "~/images/" + FileUpload1.FileName;
            GoodsManager.AddGoods(goods);
            //Response.Write("<script>alert('添加物品成功！');</script>");
            Response.Write(" <script language=javascript> if  (window.confirm( '添加物品成功！ ')){window.location.href='User_Goods.aspx';}</script>");
           // Response.Redirect("User_Goods.aspx");
        }
    }
}
