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.Admin
{
    public partial class showManagerView : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           if (IsPostBack)
            {
               // FileUpload1.PostedFile = (FileUpload)Session["url"];
                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)
        {
            //string name = FileUpload1.FileName;       //获取文件名
            //string type = name.Substring(name.LastIndexOf(".") + 1);    //获取文件类型
            //string ipath = Server.MapPath("image") + "\\" + name;    //获取文件路径
            //string wpath = "image\\" + name;        //[color=red]设置文件保存相对路径(这里的路径起始就是我们存放图片的文件夹名)[/color]



            Goods goods = new Goods();
            goods.Goodsname = btnTitle.Text.Trim();
            goods.Introduce = FCKeditor1.Value;
            goods.Author = btnAuthor.Text.Trim();
            goods.Goodstime = System.DateTime.Now ;
            goods.GoodsImage ="~/images/"+ FileUpload1.FileName;
            GoodsManager.AddGoods(goods);
            Response.Write("<script>alert('添加物品成功！');</script>");
            Response.Write("showManagerView.aspx");
           
        }
        protected void Button2_Click1(object sender, EventArgs e)
        {
            
        }
    }
}
