以下为后台代码
public partial class ProductManage : System.Web.UI.Page
{
string imagename;
bool updatesuc;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//加载商品大类名称
DataBase db = new DataBase();
string sql = "select * from producttype";
DataTable dt = db.GetDataTable(sql);
DDLbigtype.DataSource = dt;
DDLbigtype.DataValueField = "pt_id";
DDLbigtype.DataTextField = "pt_name";
DDLbigtype.DataBind();
//加载产品小类列表
DataBase dbxiao = new DataBase();
string sqlxiao = "select * from productt";
DataTable dtxiao = db.GetDataTable(sqlxiao);
DDLsmalltype.DataSource = dtxiao;
DDLsmalltype.DataValueField = "pt_sid";
DDLsmalltype.DataTextField = "pts_name";
DDLsmalltype.DataBind();
//加载默认图片
Imgproduct.ImageUrl = "~/productimage/moren.jpg";
}
//根据商品大类加载商品小类
JIAZAIxl(Convert.ToInt32(DDLbigtype.SelectedValue));
//根据商品小类加载产品
if (Session["pmtid"] != null)
{
JIAZAIchanpin(Convert.ToInt32(Session["pmtid"]));
}
}
//加载产品小类信息
private void JIAZAIxl(int dalei)
{
DataBase dbtype = new DataBase();
string sqltype = "select * from productt where pts_b=" + dalei;
DataTable dttype = dbtype.GetDataTable(sqltype);
if (dttype.Rows.Count > 0)
{
RadioButton[] rdb = new RadioButton[dttype.Rows.Count];
for (int i = 0; i < dttype.Rows.Count; i++)
{
rdb = new RadioButton();
rdb.Text = dttype.Rows["pts_name"].ToString();
rdb.ID = dttype.Rows["pt_sid"].ToString();
rdb.GroupName = "type";
rdb.AutoPostBack = true;
rdb.CheckedChanged += new EventHandler(rdb_CheckedChanged);
Panelsmalltype.Controls.Add(rdb);
}
}
}
//加载产品信息
private void JIAZAIchanpin(int xiaolei)
{
this.PanelPINFO.Controls.Clear();
DataBase db = new DataBase();
string sql = "select * from product where product_t=" + xiaolei;
DataTable dt = db.GetDataTable(sql);
if (dt.Rows.Count > 0)
{
this.PanelPINFO.Controls.Clear();
RadioButton[] rpn = new RadioButton[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
rpn = new RadioButton();
rpn.Text = dt.Rows["product_n"].ToString();
rpn.ID = "p" + dt.Rows["product_id"].ToString();
rpn.GroupName = "pro";
rpn.AutoPostBack = true;
rpn.CheckedChanged += new EventHandler(rpn_CheckedChanged);
PanelPINFO.Controls.Add(rpn);
}
}
}
//点击商品小类别选项
private void rdb_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
Session["pmtid"] = rb.ID;
JIAZAIchanpin(Convert.ToInt32(Session["pmtid"]));
}
//点击商品名称
private void rpn_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
Session["pmpid"] = rb.ID.ToString().Substring(1);
DataBase db = new DataBase();
string sql = "select * from product_info where product_id=" + Convert.ToInt32(Session["pmpid"]);
DataTable dt = db.GetDataTable(sql);
DDLsmalltype.SelectedValue = dt.Rows[0]["product_t"].ToString();
Txtcount.Text = dt.Rows[0]["product_count"].ToString();
Txtpdescribe.Text = dt.Rows[0]["product_d"].ToString();
Txtpname.Text = dt.Rows[0]["product_n"].ToString();
Txtsellprice.Text = dt.Rows[0]["product_sell_price"].ToString();
Imgproduct.ImageUrl = dt.Rows[0]["product_i"].ToString();
Txtyjcount.Text = dt.Rows[0]["product_yjcount"].ToString();
}
protected void DDLbigtype_SelectedIndexChanged(object sender, EventArgs e)
{
Session["pmtid"] = null;
Session["pmpid"] = null;
Panelsmalltype.Controls.Clear();
PanelPINFO.Controls.Clear();
JIAZAIxl(Convert.ToInt32(DDLbigtype.SelectedValue));
}
//上传添加图片
protected void UpdateImage()
{
}
//对产品信息进行更新
protected void BtnUpdate_Click(object sender, EventArgs e)
{
Productcs pcs = new Productcs();
pcs.productname = Txtpname.Text.ToString();
pcs.productid = Convert.ToInt32(Session["pmpid"]);
pcs.productt =Convert .ToInt32 (DDLsmalltype .SelectedValue );
pcs.product_sellp =Convert .ToInt32 (Txtsellprice .Text.ToString ());
pcs.product_yj = Convert.ToInt32(Txtyjcount.Text.ToString());
pcs.producti = "~/productimage/" + Session["pmpid"].ToString() + ".jpg";
pcs.productd = Txtpdescribe.Text.ToString();
if (FUimage.FileName != "")
{
try
{
string fileadress = Server.MapPath("~//productimage//") + Session["pmpid"].ToString() + ".jpg";
File.Delete(fileadress);
}
catch { }
imagename = Session["pmpid"].ToString();
UpdateImage();
}
bool suc = pcs.UpdateProduct(pcs);
if (suc)
{
Session["pmpid"] = null;
Session["pmtid"] = null;
Response.Write("<script>alert('商品信息更新成功!');window.location.href ='productmanage.aspx'</script>");
}
else
{
}
}
}