⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fbproduct.aspx.cs

📁 大家一起研究研究,全部都是开源的CSHARP代码.带数据库的
💻 CS
字号:
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 System.Data.OleDb;

public partial class admin_FbProduct : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["adminAccount"] != null)
        {
            if (Session["adminAccount"] != "")
            {

            }
            else
            {
                Response.Redirect("adminErr.aspx?errMsg=没有登陆或者登陆超时.<a href='adminlogin.aspx'>现在登陆</a>");
            }
        }
        else
        {
            Response.Redirect("adminErr.aspx?errMsg=没有登陆或者登陆超时.<a href='adminlogin.aspx'>现在登陆</a>");
        }
        int classId = Convert.ToInt32(Request.QueryString["ClassId"]);
        string sql = "Select * from [NcClass] Where [CLassId]="+classId;
        WebConfig.CreateCon();
        OleDbDataAdapter da = new OleDbDataAdapter(sql, WebConfig.con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataTable dt = ds.Tables[0];
        if (dt.Rows.Count < 1)
        {

        }
        else
        {
            this.Label1.Text = dt.Rows[0]["ClassName"].ToString();
            this.HiddenField1.Value = dt.Rows[0]["ClassId"].ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string picPath = "";
        //定义一个变量,取全部文件名
        string fileFullname = this.FileUpload1.FileName;
        //取出当前日期
        string dataName = DateTime.Now.ToString("yyyyMMddhhmmss");
        //取文件扩展名
        string fileName = fileFullname.Substring(fileFullname.LastIndexOf("\\") + 1);
        //截取上传文件的扩展名既"."后面的字母所以+1
        string type = fileFullname.Substring(fileFullname.LastIndexOf(".") + 1);
        //类型控制,想上传什么类型,可以在这里类似添加
        if (type == "jpg" || type == "gif" || type == "bmp")
        {
            this.FileUpload1.SaveAs(Server.MapPath("/upload") + "\\" + dataName + fileName);
            picPath = dataName + fileName;
            //image1输出上传图片,可以在这里控制图片大小
            //this.Image1.ImageUrl = "../upload/" + picPath;
        }
        else
        {
            picPath = "";
        }
        string sql = "Insert into [NcProducts] ([ProductName],[ProductClassId],[ProductNumber],[ProductGG],[ProductDGG],[productZGG],[ProductIntro],[ProductPic]) Values ('" + this.TextBox1.Text.Trim() + "'," + Convert.ToInt32(this.HiddenField1.Value) + ",'" + this.TextBox2.Text + "','" + this.TextBox3.Text.Trim() + "','" + this.TextBox4.Text.Trim() + "','" + this.TextBox5.Text.Trim() + "','" + this.TextBox6.Text.Trim() + "','" + picPath + "')";
        WebConfig.CreateCon();
        OleDbCommand cmd = new OleDbCommand(sql, WebConfig.con);
        cmd.ExecuteNonQuery();
        Response.Redirect("adminErr.aspx?errMsg=发布成功!<a href='ManageProduct.aspx?ClassId=" + this.HiddenField1.Value + "'>返回</a>");
    }
}

⌨️ 快捷键说明

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