procductpic.aspx.cs

来自「天织在线购物网站完整源码及文档 本网站是一套基于Web2.0思想设计、采用」· CS 代码 · 共 137 行

CS
137
字号
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;
using background;
public partial class Manage_ProcductPic : System.Web.UI.Page
{
    uppic up = new uppic();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ImageButton1_Command(object sender, CommandEventArgs e)
    {
        Session["linklogo"] = e.CommandArgument.ToString();
    }
    protected void ImageButton2_Command(object sender, CommandEventArgs e)
    {
        Session["Brand"] = e.CommandArgument.ToString();
    }
    protected void ImageButton3_Command(object sender, CommandEventArgs e)
    {
        Session["Pic"] = e.CommandArgument.ToString();
    }
    protected void linkLogoup_Click(object sender, EventArgs e)
    {
        //Response.Write("<script>alert('" + Session["linklogo"].ToString() + "');</script>");
        if (Session["linklogo"] != null)
        {
            if (this.myFile.PostedFile != null)
            {
                string photoName1 = myFile.PostedFile.FileName; //获取初始文件名
                int i = photoName1.LastIndexOf("."); //取得文件名中最后一个"."的索引
                string newext = photoName1.Substring(i); //获取文件扩展名
                if (newext != ".gif" && newext != ".jpg" && newext != ".jpeg" && newext != ".bmp" && newext != ".png")
                {
                    Response.Write("<script>alert('文件格式不正确');</script>");
                    Response.End();
                }
                DateTime now = DateTime.Now; //获取系统时间
                string photoName2 = now.Millisecond.ToString() + "_" + myFile.PostedFile.ContentLength.ToString() + newext; //重新为文件命名,时间毫秒部分+文件大小+扩展名
                myFile.PostedFile.SaveAs(Server.MapPath("..\\Image\\" + photoName2)); // 保存文件到路径,用Server.MapPath()取当前文件的绝对目录.在asp.net里"\"必须用"\\"代替
                bool yes=up.uppicFile(Session["linklogo"].ToString(),photoName2,"linklogo");
                if (yes)
                {
                    Response.Write("<script>alert('文件上传成功');</script>");
                    Session.Remove("linklogo");
                }
                else {
                    Response.Write("<script>alert('文件上传失败');</script>");
                }
            }
        }
        else {
            Response.Write("<script>alert('没有找到与图片相关的商品信息');</script>");
        }
    }
    protected void Brandupbtn_Click(object sender, EventArgs e)
    {
        if (Session["Brand"] != null)
        {
            if (this.myFile1.PostedFile != null)
            {
                string photoName1 = myFile1.PostedFile.FileName; //获取初始文件名
                int i = photoName1.LastIndexOf("."); //取得文件名中最后一个"."的索引
                string newext = photoName1.Substring(i); //获取文件扩展名
                if (newext != ".gif" && newext != ".jpg" && newext != ".jpeg" && newext != ".bmp" && newext != ".png")
                {
                    Response.Write("<script>alert('文件格式不正确');</script>");
                    Response.End();
                }
                DateTime now = DateTime.Now; //获取系统时间
                string photoName2 = now.Millisecond.ToString() + "_" + myFile.PostedFile.ContentLength.ToString() + newext; //重新为文件命名,时间毫秒部分+文件大小+扩展名
                myFile1.PostedFile.SaveAs(Server.MapPath("..\\Image\\" + photoName2)); // 保存文件到路径,用Server.MapPath()取当前文件的绝对目录.在asp.net里"\"必须用"\\"代替
                bool yes = up.uppicFile(Session["Brand"].ToString(), photoName2, "Brand");
                if (yes)
                {
                    Response.Write("<script>alert('文件上传成功');</script>");
                    Session.Remove("Brand");
                }
                else
                {
                    Response.Write("<script>alert('文件上传失败');</script>");
                }
            }
        }
        else {
            Response.Write("<script>alert('没有找到与图片相关的商品信息');</script>");

        }
    }
    protected void picupbtn_Click(object sender, EventArgs e)
    {
        if (Session["Pic"] != null)
        {
            if (this.myFile2.PostedFile != null)
            {
                string photoName1 = myFile2.PostedFile.FileName; //获取初始文件名
                int i = photoName1.LastIndexOf("."); //取得文件名中最后一个"."的索引
                string newext = photoName1.Substring(i); //获取文件扩展名
                if (newext != ".gif" && newext != ".jpg" && newext != ".jpeg" && newext != ".bmp" && newext != ".png")
                {
                    Response.Write("<script>alert('文件格式不正确');</script>");
                    Response.End();
                }
                DateTime now = DateTime.Now; //获取系统时间
                string photoName2 = now.Millisecond.ToString() + "_" + myFile.PostedFile.ContentLength.ToString() + newext; //重新为文件命名,时间毫秒部分+文件大小+扩展名
                myFile2.PostedFile.SaveAs(Server.MapPath("..\\Image\\" + photoName2)); // 保存文件到路径,用Server.MapPath()取当前文件的绝对目录.在asp.net里"\"必须用"\\"代替
                bool yes = up.uppicFile(Session["Pic"].ToString(), photoName2, "Pic");
                if (yes)
                {
                    Response.Write("<script>alert('文件上传成功');</script>");
                    Session.Remove("Pic");
                }
                else
                {
                    Response.Write("<script>alert('文件上传失败');</script>");
                }
            }
        }
        else {
            Response.Write("<script>alert('没有找到与图片相关的商品信息');</script>");

        }
    }
    protected void LinkButton1_Command(object sender, CommandEventArgs e)
    {
        Response.Redirect("particular.aspx?id=" + e.CommandArgument + "");
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?