📄 st_productadd.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;
namespace STGROUP.ST_WebBook
{
/// <summary>
/// ST_QuestionAdd 的摘要说明。
/// </summary>
public partial class ST_ProductAdd : System.Web.UI.Page
{
ST_BookBiz.ST_ProductEntity st_entity = new STGROUP.ST_BookBiz.ST_ProductEntity();
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Response.Cache.SetCacheability(HttpCacheability.NoCache);//去掉页面缓存
if(!IsPostBack)
{
//绑定商品信息
ST_BookBiz.ST_Product st_product = new STGROUP.ST_BookBiz.ST_Product();
if(Request["Action"]=="Edit" && Request["id"]!=null)
{
st_entity = st_product.GetProductInfoByID(int.Parse(Request["id"]));
txtNumber.Text = st_entity.ST_ProductID.ToString();
txtName.Text = st_entity.ST_ProductName;
txtPrice.Text = st_entity.ST_Price.ToString("F2");
txtSoldPrice.Text = st_entity.ST_SoldPrice.ToString("F2");
txtPublisher.Text = st_entity.ST_Publisher;
txtISBN.Text = st_entity.ST_ISBN;
txtPage.Text = st_entity.ST_Page.ToString();
txtPublishDate.Text = st_entity.ST_PublishDate.ToString("yyyy-MM-dd");
txtAuthor.Text = st_entity.ST_Author;
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void btnOK_Click(object sender, System.EventArgs e)
{
ST_BookBiz.ST_Product st_product = new STGROUP.ST_BookBiz.ST_Product();
st_entity.ST_ProductName = txtName.Text;
st_entity.ST_Price = float.Parse(txtPrice.Text.Trim());
st_entity.ST_SoldPrice = float.Parse(txtSoldPrice.Text.Trim());
st_entity.ST_Publisher = txtPublisher.Text.Trim();
st_entity.ST_ISBN = txtISBN.Text.Trim();
st_entity.ST_Page = int.Parse(txtPage.Text.Trim());
st_entity.ST_PublishDate = DateTime.Parse(txtPublishDate.Text.Trim());
st_entity.ST_ClassID = int.Parse(Request.QueryString["st_classid"]);
st_entity.ST_Author = txtAuthor.Text.Trim();
if(Request["Action"]=="add")//添加商品
{
st_entity.ST_IsSelling = true;
st_entity.ST_ProductID = st_product.InsertProduct(st_entity);
if (txtFile.PostedFile.ContentLength > 0)
{
txtFile.PostedFile.SaveAs(ST_BookBiz.ST_Utility.ST_ImagePhyPath + st_entity.ST_ProductID + ".jpg");
}
st_product.UpdateProductImg(st_entity.ST_ProductID + ".jpg", st_entity.ST_ProductID);
}
else//更新商品
{
st_entity.ST_ProductID = int.Parse(Request["id"]);
st_entity.ST_Image = st_entity.ST_ProductID + ".jpg";
if (txtFile.PostedFile.ContentLength > 0)
{
txtFile.PostedFile.SaveAs(ST_BookBiz.ST_Utility.ST_ImagePhyPath + st_entity.ST_ProductID + ".jpg");
}
st_product.UpdateProduct(st_entity);
}
string str = "<script language='javascript'>alert('更新成功');window.close();</script>";
Response.Write(str);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -