userControl/addproduct.ascx.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.SqlClient;
namespace MyPetShop.Admin.usercontrol
{
    public partial class addproduct : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        static string goodsPicUrl;
        protected void Button3_Click(object sender, EventArgs e)
        {
            DB db = new DB();
            db.GetCon();
           
            string str = "insert into Product(CategoryId,ListPrice,SuppId,Name,Descn,Image,Qty) values('" + int.Parse(ddlCategory.SelectedValue) + "','" + txtPrice.Text + "','" + int.Parse(ddlSupplier.SelectedValue) + "','" + txtname.Text + "','" + txtDes.Text + "','" + goodsPicUrl.ToString()+ "','"+int.Parse(txtNum.Text)+"')";
           
            db.sqlEx(str);
            Page.ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('添加成功!');</script>");
           
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)//判断里FileUpload是否有此文件地址
            {
                string[] strSpil = FileUpload1.FileName.Split('.');//将此地址用.号进行分割(img/1.jpg) 
                string strEnd = strSpil[strSpil.Length - 1].ToLower();//得到后面得jpg 
                string[] strPic = new string[] { "jpg", "gif", "bmp", "png" };//定义一个数组里面放文件格式 
                ArrayList arry = new ArrayList();
                arry.AddRange(strPic);  //定义一个可变数组,用于放文件格式
                if (arry.Contains(strEnd))//判断这个数组中是否有(jpg) 
                {
                    Random rand = new Random();//定义义个随机数,为了防止你要上传得图片重名 
                    Session["strName1"] = DateTime.Now.ToString("yyyymmmddhhss") + rand.Next(100, 9999).ToString() + "." + strEnd;//得到不同得名字 
                    string strFile = Server.MapPath("~/images/Prod_Images/");//获取其相对地址 
                    FileUpload1.SaveAs(strFile + Session["strName1"]);//保存 
                    Image1.Visible = true;
                    Image1.ImageUrl = "~/images/Prod_Images/" + Session["strName1"];//显示此图片 
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('不是标准的图片格式');</script>");

                   // Response.Write(" <script>alert('不是标准的图片格式') </script>");
                }
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('不存在此文件');</script>");

               // Response.Write(" <script>alert('不存在此文件') </script>");
            }
后面还有 9 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读 AI

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。