📄 editproduct.aspx.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_EditProduct : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int productId = Convert.ToInt32(Request.QueryString["ProductId"]);
string sql = "Select * from [NcProducts] Where [ProductId]=" + productId;
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)
{
this.TextBox1.Text = dt.Rows[0]["ProductName"].ToString();
this.TextBox2.Text = dt.Rows[0]["ProductNumber"].ToString();
this.TextBox3.Text = dt.Rows[0]["ProductGG"].ToString();
this.TextBox4.Text = dt.Rows[0]["ProductDGG"].ToString();
this.TextBox5.Text = dt.Rows[0]["ProductZGG"].ToString();
this.TextBox6.Text = dt.Rows[0]["ProductIntro"].ToString();
this.HiddenField1.Value = dt.Rows[0]["ProductId"].ToString();
if (dt.Rows[0]["ProductPic"] != null)
{
if (dt.Rows[0]["ProductPic"].ToString() != "")
{
this.Image1.ImageUrl = "../upload/" + dt.Rows[0]["ProductPic"].ToString();
}
else
{
this.Image1.ImageUrl = "../images/no_pic.gif";
}
}
else
{
this.Image1.ImageUrl = "../images/no_pic.gif";
}
}
}
}
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 nameList = "";
string valueList = "";
if (picPath != "")
{
nameList = ", [NewsPic] ";
valueList = ",'" + picPath + "'";
}
int productId = Convert.ToInt32(this.HiddenField1.Value);
string productName = this.TextBox1.Text;
string productNumber = this.TextBox2.Text;
string productGG = this.TextBox3.Text;
string productDGG = this.TextBox4.Text;
string productZGG = this.TextBox5.Text;
string prodictPic = picPath;
string productIntro = this.TextBox6.Text;
string sql = "update [NcProducts] set [productName]='" + productName + "',[productNumber]='" + productNumber + "',[ProductGG]='" + productGG + "',[productDGG]='" + productDGG + "',[productZGG]='" + productZGG + "'";
if (prodictPic != "")
{
sql += ",[productPic]='" + prodictPic + "'";
}
sql+=" Where [productId]=" + productId;
WebConfig.CreateCon();
OleDbCommand cmd = new OleDbCommand(sql, WebConfig.con);
cmd.ExecuteNonQuery();
Response.Redirect("adminErr.aspx?errMsg=修改成功!<a href='EditProduct.aspx?productId="+productId.ToString()+"'>返回</a>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -