📄 product_modify.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Text.RegularExpressions;
using System.IO;
namespace B2Bsite
{
/// <summary>
/// 商品资料修改
/// </summary>
public class product_modify : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.RadioButton RadioButton18;
protected System.Web.UI.WebControls.RadioButton RadioButton16;
protected System.Web.UI.WebControls.RadioButton RadioButton15;
protected System.Web.UI.WebControls.RadioButton RadioButton14;
protected System.Web.UI.WebControls.RadioButton RadioButton13;
protected System.Web.UI.WebControls.RadioButton RadioButton12;
protected System.Web.UI.WebControls.RadioButton RadioButton10;
protected System.Web.UI.WebControls.RadioButton RadioButton11;
protected System.Web.UI.WebControls.RadioButton RadioButton17;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.TextBox TextBox6;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator3;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator4;
protected System.Web.UI.HtmlControls.HtmlInputButton Reset1;
protected System.Web.UI.HtmlControls.HtmlImage myimg;
public int payment;
public string Payment;
public int isubb=1;
public int isscript=0;
public int isflash=1;
public int isimg=1;
public SqlDataReader dr;
public string strID;
public string Store;//所属商店
public string Name;//商品名
public string Type;//商品类型
public string Price;//商品单价
public string Quantity;//库存量
public string Post;//平邮邮费
public string Fax;//快递邮费
public string Picture;//商品图片
public string Detail;//商品详细
public string State;//商品状态
public int state;
public string Repair;//有无保修
public int repair;
public string Invoice;
protected System.Web.UI.HtmlControls.HtmlInputFile uploadFile;
public int invoice;
public string back;//返回
private void Page_Load(object sender, System.EventArgs e)
{
if( Request.QueryString["msg"] == null )
{
back="";
}
else
{
back= "<a href='";
back+= Server.UrlDecode( Request.QueryString["msg"].ToString() ) ;
back+= "'>返回</a>";
}
if(!IsPostBack)
{
if( Session["username"] == null )
{
Response.Write ("<script language='JavaScript'>");
Response.Write ("alert('请先登录!')");
Response.Write ("</script>");
Response.End();
return;
}
if( Request.QueryString["id"]!=null )
{
SqlConnection connection=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
string id=Request.QueryString["id"].ToString();
String sql="SELECT * FROM Products where ProductId="+id;
SqlCommand command=new SqlCommand(sql,connection);
connection.Open();
dr=command.ExecuteReader();
if( dr.Read() )
{
strID = dr["ProductId"].ToString();
Store=dr["UserName"].ToString();
Name=dr["ProductName"].ToString();
Type=dr["ProductType"].ToString();
Price=dr["ProductPrice"].ToString();
Quantity=dr["ProductQuantity"].ToString();
Post=dr["ProductPost"].ToString();
Fax=dr["ProductFax"].ToString();
Picture=dr["ProductPicture"].ToString();
Detail=dr["ProductDetail"].ToString();
State=dr["ProductState"].ToString();
state=Int32.Parse(State);
Repair=dr["ProductRepair"].ToString();
repair=Int32.Parse(Repair);
Invoice=dr["ProductInvoice"].ToString();
invoice=Int32.Parse(Invoice);
Payment=dr["ProductPayment"].ToString();
payment=Int32.Parse(Payment);
}
myimg.Src = "showProductPicture.aspx?id=" + strID;
Label1.Text=Store + " 的店铺";
Label2.Text=Name;
TextBox2.Text=Detail;
TextBox3.Text = Price;
TextBox4.Text=Quantity;
TextBox5.Text=Post;
TextBox6.Text=Fax;
/*判断商品状态*/
if(state==1)/*已上架*/
{ RadioButton18.Checked=true; }
else/*库存*/
{ RadioButton17.Checked=true; }
/*判断保修情况*/
if(repair==1)
{ RadioButton16.Checked=true; }
else
{ RadioButton15.Checked=true; }
/*判断发票情况*/
if(invoice==1)
{ RadioButton14.Checked=true; }
else
{ RadioButton13.Checked=true; }
/*判断付款方式*/
if(payment==0)
{ RadioButton12.Checked=true; }
else if(payment==1)
{ RadioButton11.Checked=true; }
else
{ RadioButton10.Checked=true; }
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Reset1.ServerClick += new System.EventHandler(this.Reset1_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
if( Request.QueryString["id"]!=null )
{
string price=TextBox3.Text;
//验证
//Response.Write("<script language=javascript>window.alert('请输入数字价格!')</script>");
string quantity=TextBox4.Text;
string post=TextBox5.Text;
string fax=TextBox6.Text;
string detail=TextBox2.Text;
//detail=TextBox2.Text.Replace("'","''");
//detail =texttohtml(detail);
//detail=changechr(detail);
int payment;
int repair;
int invoice;
int state;
string imgPath=uploadFile.PostedFile.FileName;
System.Drawing.Image imgupload=null;
try
{
imgupload=System.Drawing.Image.FromFile(imgPath);
}
catch
{
//Response.Write("请注意:因为系统桌面上以及我的文档里面的文件具有特殊权限,所以在选择图片时请选择其他地方的图片。");
}
if(RadioButton12.Checked)
{ payment=0; }
else if(RadioButton11.Checked)
{ payment=1; }
else
{ payment=2; }
if(RadioButton16.Checked)
{ repair=1; }
else
{ repair=0; }
if(RadioButton14.Checked)
{ invoice=1; }
else
{ invoice=0; }
if(RadioButton18.Checked)/*已上架*/
{ state=1; }
else/*库存*/
{ state=0; }
if(uploadFile.PostedFile.FileName!="" && (Path.GetExtension(uploadFile.PostedFile.FileName)!=".gif" && Path.GetExtension(uploadFile.PostedFile.FileName)!=".jpg"))
{
Response.Write("<Script>alert('上传的图片格式必须为gif或jpg!!')</Script>");
}/*
else if(uploadFile.PostedFile.FileName!="" && imgupload.Height>200 && imgupload.Width>200)
{
Response.Write("<script>alert('上传的图片的高不的超过200 宽不的超过200!!')</script>");
}*/
else
{
SqlConnection connection=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);//调用Web.config连接数据库
string id=Request.QueryString["id"].ToString();
String sql="UPDATE Products set ProductPrice='"+price+"',ProductQuantity='"
+quantity+"',ProductPost='"+post+"',ProductFax='"+fax+"',ProductDetail='"+detail+
"',ProductState="+state+",ProductRepair="+repair+",ProductInvoice="+invoice+",ProductPayment="+payment+" where ProductId="+id;
SqlCommand command=new SqlCommand(sql,connection);//构件执行数据命令
connection.Open();//打开数据库
command.ExecuteReader();//保存从数据库里面返回的一条记录
if( uploadFile.PostedFile.FileName!="" )
{
//----------- update图片
Stream imagedatastream;
SqlConnection myConn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
imagedatastream = Request.Files["uploadFile"].InputStream ;
int imagedatalen = Request.Files["uploadFile"].ContentLength ;
string imagedatatype = Request.Files["uploadFile"].ContentType ;
byte[] image = new byte[imagedatalen];
imagedatastream.Read(image,0,imagedatalen);
//String sql="insert into image(image) values(@imgdata)";
String Psql="update [Products] set [ProductPicture]=@imgdata where ProductId="+Request.QueryString["id"].ToString();
SqlCommand Pcommand=new SqlCommand(Psql,myConn);
SqlParameter imgdata = new SqlParameter("@imgdata",SqlDbType.Image);
imgdata.Value=image;
Pcommand.Parameters.Add (imgdata);
myConn.Open();
Pcommand.ExecuteReader();
myConn.Close();
}
//-----------
Response.Write("<script language=javascript>window.alert('保存成功!')</script>");
//Response.Redirect("DeleteProduct.aspx");
}
}
}
private void Reset1_ServerClick(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -