构建网站图片上传不上去

来源:互联网 发布:高超音速 知乎 编辑:程序博客网 时间:2024/05/01 02:32

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Colo.BLL;
using Colo.Entity;
using Web.PageBase.Utility;



using Colo.Web.code;
using System.Text;
namespace Colo.Web.admin.Products
{
    public partial class ProPicAdmin : AdminPage
    {
        public string colorhtml = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {


            if (this.IsHttpPost)
            {

                if (!string.IsNullOrEmpty(Request.Form["id"]))
                {
                    UpFileImg.DeleteImg(Request.Form["imgurl"].ToString());

                  
                    ColoProPicBLL.DeleteProPicByID(Convert.ToInt32(Request.Form["id"]));


                    Page.ClientScript.RegisterStartupScript(this.GetType(), "m", "alert('删除成功');location.href='propicadmin.aspx?id=" + this.pid.Value + "'", true);


                }

                if (!string.IsNullOrEmpty(Request.Form["op"]))
                {
                    if (Request.Form["op"].ToString() == "1")//设置产品封面
                    {
                        int proid = Convert.ToInt32(Request.Form["proid"]);
                        int picid = Convert.ToInt32(Request.Form["picid"]);
                        ColoProPicBLL.SetTopPic(proid, picid);

                        Page.ClientScript.RegisterStartupScript(this.GetType(), "m", "alert('产品封面设置成功!');location.href='propicadmin.aspx?id=" + this.pid.Value + "'", true);

                    }

              

                }

            }
            else
            {

                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    int id = Convert.ToInt32(Request.QueryString["id"]);

                    ProPicBind(id, 0);
                  //  ProColorBind(id);
                }
            }

 

 

 

        }

        protected void ProPicBind(int id, int colorid)
        {
            ColoProModel p = ColoProBLL.GetProByID(id);
            this.txtProName.Text = p.F_ProName;
            this.pid.Value = id.ToString();
            List<ColoProPicModel> list = ColoProPicBLL.GetProPicList(id, colorid);

            PhotoList.DataSource = list;
            PhotoList.DataBind();


        }

 

        protected void btnUpload_Click(object sender, EventArgs e)
        {

         
            string[] filePath = new string[5];
            string[] samllpic = new string[5];

            int count = 0;
            if (!string.IsNullOrEmpty(this.File1.Value))
            {
                filePath[0] = "Upload/" + UpFileImg.UpLoad(this.File1, Server.MapPath("/UpLoad"));
                samllpic[0] = "Upload/small/" + UpFileImg.MakeThumbnail(File1.PostedFile.FileName, Server.MapPath("/UpLoad//small"), 110, 80, "Cut");
                //  PhotoBLL.ADD(Convert.ToInt32(this.classid.Value), filePath[0]);
                count++;
            }
            if (!string.IsNullOrEmpty(this.File2.Value))
            {
                filePath[1] = "Upload/" + UpFileImg.UpLoad(this.File2, Server.MapPath("/UpLoad"));
                samllpic[1] = "Upload/small/" + UpFileImg.MakeThumbnail(File2.PostedFile.FileName, Server.MapPath("/UpLoad//small"), 110, 80, "Cut");
                //  PhotoBLL.ADD(Convert.ToInt32(this.classid.Value), filePath[1]);
                count++;
            }
            if (!string.IsNullOrEmpty(this.File3.Value))
            {
                filePath[2] = "Upload/" + UpFileImg.UpLoad(this.File3, Server.MapPath("/UpLoad"));
                samllpic[2] = "Upload/small/" + UpFileImg.MakeThumbnail(File3.PostedFile.FileName, Server.MapPath("/UpLoad//small"), 110, 80, "Cut");
                //  PhotoBLL.ADD(Convert.ToInt32(this.classid.Value), filePath[2]);
                count++;
            }
            if (!string.IsNullOrEmpty(this.File4.Value))
            {
                filePath[3] = "Upload/" + UpFileImg.UpLoad(this.File4, Server.MapPath("/UpLoad"));
                samllpic[3] = "Upload/small/" + UpFileImg.MakeThumbnail(File4.PostedFile.FileName, Server.MapPath("/UpLoad//small"), 110, 80, "Cut");
                //  PhotoBLL.ADD(Convert.ToInt32(this.classid.Value), filePath[3]);
                count++;
            }
            if (!string.IsNullOrEmpty(this.File5.Value))
            {
                filePath[4] = "Upload/" + UpFileImg.UpLoad(this.File5, Server.MapPath("/UpLoad"));
                samllpic[4] = "Upload/small/" + UpFileImg.MakeThumbnail(File5.PostedFile.FileName, Server.MapPath("/UpLoad//small"), 110, 80, "Cut");
                //  PhotoBLL.ADD(Convert.ToInt32(this.classid.Value), filePath[4]);
                count++;
            }

            if (count == 0)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "alert('至少选择一张图片!')", true);
              
                return;
            }

           

            ColoProPicModel p = null;

 

            for (int i = 0; i < filePath.Length; i++)
            {
                if (!string.IsNullOrEmpty(filePath[i]))
                {
                    p = new ColoProPicModel();
                    p.F_Pic = filePath[i].ToString();
                    p.ColorID = 0;
                    p.ProID = int.Parse(Request.Form["id"]);//Convert.ToInt32(this.pid.Value);这块提示有错误:

确保方法参数的正确,将一个字符串转化为datetime时,先分析该字符串以获取日期,然后将每个变量放到datetime对象中
                    p.F_SmallPic =samllpic[i].ToString();
                    ColoProPicBLL.AddProPic(p);
                }

            }


            ProPicBind(Convert.ToInt32(this.pid.Value), 0);
          

        }

    }
}