protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { /*判断员工是否已经登陆了系统*/ if (Session["employeeFlag"] == null) { Response.Write("<script>top.location.href='../login.aspx';</script>"); return; } /*取得更新商品的商品编号*/ string goodNo = Request.QueryString["goodNo"]; /*调用业务层根据商品编号得到商品的信息并保存在模型中*/ GoodInfoModel goodInfoModel = GoodLogic.GetGoodInfoByNo(goodNo); /*显示该商品的各个信息*/ this.GoodNo.Text = goodInfoModel.GoodNo; this.GoodClassName.Text = GoodClassLogic.GetGoodClassNameById(goodInfoModel.GoodClassId); this.GoodName.Text = goodInfoModel.GoodName; this.GoodUnit.Text = goodInfoModel.GoodUnit; this.GoodModel.Text = goodInfoModel.GoodModel; this.GoodSpecs.Text = goodInfoModel.GoodSpecs; this.GoodPrice.Text = goodInfoModel.GoodPrice.ToString(); this.GoodPlace.Text = goodInfoModel.GoodPlace; this.GoodMemo.Text = goodInfoModel.GoodMemo; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { /*判断管理员是否已经登陆了系统*/ if (Session["adminFlag"] == null) { Response.Write("<script>top.location.href='../login.aspx';</script>"); return; } DataSet goodClassDs = GoodClassLogic.QueryAllGoodClassInfo(); for (int i = 0; i < goodClassDs.Tables[0].Rows.Count; i++) { DataRow dr = goodClassDs.Tables[0].Rows[i]; this.GoodClassId.Items.Add(new ListItem(dr["goodClassName"].ToString(), dr["goodClassId"].ToString())); } /*取得更新商品的商品编号*/ string goodNo = Request.QueryString["goodNo"]; /*调用业务层根据商品编号得到商品的信息并保存在模型中*/ GoodInfoModel goodInfoModel = GoodLogic.GetGoodInfoByNo(goodNo); /*显示该商品的各个信息*/ this.GoodNo.Text = goodInfoModel.GoodNo; this.GoodClassId.SelectedValue = goodInfoModel.GoodClassId.ToString(); this.GoodName.Text = goodInfoModel.GoodName; this.GoodUnit.Text = goodInfoModel.GoodUnit; this.GoodModel.Text = goodInfoModel.GoodModel; this.GoodSpecs.Text = goodInfoModel.GoodSpecs; this.GoodPrice.Text = goodInfoModel.GoodPrice.ToString(); this.GoodPlace.Text = goodInfoModel.GoodPlace; this.GoodMemo.Text = goodInfoModel.GoodMemo; } }
protected void Btn_GetGoodInfo_Click(object sender, EventArgs e) { /*根据商品编号查询商品信息*/ string goodNo = this.GoodNo.Text; if (goodNo == "") { Response.Write("<script>alert('请输入商品编号信息!');</script>"); return; } GoodInfoModel goodInfoModel = GoodLogic.GetGoodInfoByNo(goodNo); if (goodInfoModel == null) { Response.Write("<script>alert('不存在该商品的信息!');</script>"); } else { /*将该商品的详细信息显示在界面上供管理员确认无错误*/ this.GoodName.Text = goodInfoModel.GoodName; this.GoodModel.Text = goodInfoModel.GoodModel; this.GoodSpecs.Text = goodInfoModel.GoodSpecs; this.GoodPlace.Text = goodInfoModel.GoodPlace; this.GoodInfoPanel.Visible = true; } }
/*根据商品编号得到该商品的信息并保存在模型对象中返回*/ public static GoodInfoModel GetGoodInfoByNo(string goodNo) { string sqlString = "select * from [goodInfo] where goodNo='" + goodNo + "'"; DataSet goodInfoDs = DBOperation.GetDataSet(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null); if (goodInfoDs.Tables[0].Rows.Count == 0) { return(null); } DataRow dr = goodInfoDs.Tables[0].Rows[0]; /*取得该商品记录所在行*/ GoodInfoModel goodInfoModel = new GoodInfoModel(); goodInfoModel.GoodNo = goodNo; goodInfoModel.GoodClassId = Convert.ToInt32(dr["goodClassId"]); goodInfoModel.GoodName = dr["goodName"].ToString(); goodInfoModel.GoodUnit = dr["goodUnit"].ToString(); goodInfoModel.GoodModel = dr["goodModel"].ToString(); goodInfoModel.GoodSpecs = dr["goodSpecs"].ToString(); goodInfoModel.GoodPrice = Convert.ToSingle(dr["goodPrice"]); goodInfoModel.GoodPlace = dr["goodPlace"].ToString(); goodInfoModel.GoodMemo = dr["goodMemo"].ToString(); goodInfoModel.GoodAddTime = Convert.ToDateTime(dr["goodAddTime"]); return(goodInfoModel); }
protected void Btn_Add_Click(object sender, EventArgs e) { /*建立商品信息模型并从界面中搜集管理员输入的商品信息*/ GoodInfoModel goodInfoModel = new GoodInfoModel(); goodInfoModel.GoodNo = this.GoodNo.Text; goodInfoModel.GoodClassId = Int32.Parse(this.GoodClassId.SelectedValue); goodInfoModel.GoodName = this.GoodName.Text; goodInfoModel.GoodUnit = this.GoodUnit.Text; goodInfoModel.GoodModel = this.GoodModel.Text; goodInfoModel.GoodSpecs = this.GoodSpecs.Text; goodInfoModel.GoodPrice = Convert.ToSingle(this.GoodPrice.Text); goodInfoModel.GoodPlace = this.GoodPlace.Text; goodInfoModel.GoodMemo = this.GoodMemo.Text; goodInfoModel.GoodAddTime = DateTime.Now; /*调用业务层执行商品信息的加入操作*/ GoodLogic goodLogic = new GoodLogic(); if (goodLogic.AddGoodInfo(goodInfoModel)) { Response.Write("<script>alert('商品信息添加成功!');location.href='GoodInfoAdd.aspx';</script>"); } else { Response.Write("<script>alert('" + goodLogic.ErrMessage + "');location.href='GoodInfoAdd.aspx';</script>"); } }
/*根据商品信息模型对象执行新商品信息的加入操作*/ public bool AddGoodInfo(GoodInfoModel goodInfoModel) { /*查询该商品编号是否已经存在*/ string sqlString = "select * from [goodInfo] where goodNo='" + goodInfoModel.GoodNo + "'"; if (DBOperation.ExecuteReader(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null).Read()) { this.errMessage = "你输入的商品编号已经存在!"; return(false); } /*商品信息表 * CREATE TABLE [dbo].[goodInfo] ( * [goodNo] [varchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL , //商品编号 * [goodClassId] [int] NULL , //商品类别编号 * [goodName] [nvarchar] (30) COLLATE Chinese_PRC_CI_AS NOT NULL , //商品名称 * [goodUnit] [nvarchar] (2) COLLATE Chinese_PRC_CI_AS NULL , //商品单位 * [goodModel] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL , //商品型号 * [goodSpecs] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL , //商品规格 * [goodPrice] [float] NULL , //商品出售单价 * [goodPlace] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL , //商品生产地 * [goodMemo] [char] (10) COLLATE Chinese_PRC_CI_AS NULL , //商品附加信息 * [goodAddTime] [datetime] NULL //商品加入时间 * ) ON [PRIMARY]*/ /*下面构造添加商品信息的sql语句*/ sqlString = "insert into [goodInfo] (goodNo,goodClassId,goodName,goodUnit,goodModel,goodSpecs,goodPrice,goodPlace,goodMemo,goodAddTime) values ('"; sqlString += goodInfoModel.GoodNo + "',"; sqlString += goodInfoModel.GoodClassId + ",'"; sqlString += goodInfoModel.GoodName + "','"; sqlString += goodInfoModel.GoodUnit + "','"; sqlString += goodInfoModel.GoodModel + "','"; sqlString += goodInfoModel.GoodSpecs + "',"; sqlString += goodInfoModel.GoodPrice + ",'"; sqlString += goodInfoModel.GoodPlace + "','"; sqlString += goodInfoModel.GoodMemo + "','"; sqlString += goodInfoModel.GoodAddTime + "')"; /*调用数据层执行加入操作,成功返回一个大于0的数*/ if (DBOperation.ExecuteNonQuery(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null) <= 0) { this.errMessage = "添加商品信息时发生了错误!"; return(false); } /*下面将新商品的库存设置为0并加入到库存信息表中*/ sqlString = "insert into [goodStockInfo] (goodNo,goodCount) values ('" + goodInfoModel.GoodNo + "',0)"; if (DBOperation.ExecuteNonQuery(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null) <= 0) { this.errMessage = "设置新商品的库存时发生了错误!"; return(false); } return(true); }
/*传入商品信息模型对象,根据该对象中的商品编号实现更新操作*/ public static bool UpdateGoodInfo(GoodInfoModel goodInfoModel) { /*构造更新的sql语句*/ string sqlString = "update [goodInfo] set goodClassId="; sqlString += goodInfoModel.GoodClassId + ",goodName='"; sqlString += goodInfoModel.GoodName + "',goodUnit='"; sqlString += goodInfoModel.GoodUnit + "',goodModel='"; sqlString += goodInfoModel.GoodModel + "',goodSpecs='"; sqlString += goodInfoModel.GoodSpecs + "',goodPrice="; sqlString += goodInfoModel.GoodPrice + ",goodPlace='"; sqlString += goodInfoModel.GoodPlace + "',goodMemo='"; sqlString += goodInfoModel.GoodMemo + "' where goodNo='" + goodInfoModel.GoodNo + "'"; /*调用数据层执行更新操作*/ if (DBOperation.ExecuteNonQuery(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null) <= 0) { return(false); } return(true); }
protected void Btn_Update_Click(object sender, EventArgs e) { /*建立商品信息模型,搜集该商品的各个信息*/ GoodInfoModel goodInfoModel = new GoodInfoModel(); goodInfoModel.GoodNo = Request.QueryString["goodNo"]; goodInfoModel.GoodClassId = Int32.Parse(this.GoodClassId.SelectedValue); goodInfoModel.GoodName = this.GoodName.Text; goodInfoModel.GoodUnit = this.GoodUnit.Text; goodInfoModel.GoodModel = this.GoodModel.Text; goodInfoModel.GoodSpecs = this.GoodSpecs.Text; goodInfoModel.GoodPrice = Convert.ToSingle(this.GoodPrice.Text); goodInfoModel.GoodPlace = this.GoodPlace.Text; goodInfoModel.GoodMemo = this.GoodMemo.Text; /*调用业务层执行该商品信息的更新操作*/ if (GoodLogic.UpdateGoodInfo(goodInfoModel)) { Response.Write("<script>alert('商品信息更新成功!');location.href='GoodInfoUpdate.aspx?goodNo=" + goodInfoModel.GoodNo + "';</script>"); } else { Response.Write("<script>alert('商品信息更新失败!');location.href='GoodInfoUpdate.aspx?goodNo=" + goodInfoModel.GoodNo + "';</script>"); } }