protected void Btn_Add_Click(object sender, EventArgs e) { GoodClassModel goodClassModel = new GoodClassModel(); /*构建商品类型模型*/ goodClassModel.GoodClassName = this.GoodClassName.Text; /*取得商品类别名称*/ GoodClassLogic goodClassLogic = new GoodClassLogic(); if (goodClassLogic.AddGoodClassInfo(goodClassModel)) { Response.Write("<script>alert('商品类别信息添加成功!');location.href='GoodClassAdd.aspx';</script>"); } else { Response.Write("<script>alert('" + goodClassLogic.ErrMessage + "');location.href='GoodClassAdd.aspx';</script>"); } }
/*根据商品类型模型对象执行添加操作*/ public bool AddGoodClassInfo(GoodClassModel goodClassModel) { /*首先查询该商品类别名称在系统中是否已经存在*/ string sqlString = "select * from [goodClassInfo] where goodClassName='" + goodClassModel.GoodClassName + "'"; if (DBOperation.ExecuteReader(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null).Read()) { this.errMessage = "该商品类别名称已经存在!"; return(false); } /*执行新的商品类别信息的加入操作*/ sqlString = "insert into [goodClassInfo] (goodClassName) values ('" + goodClassModel.GoodClassName + "')"; if (DBOperation.ExecuteNonQuery(DBOperation.CONN_STRING_NON_DTC, CommandType.Text, sqlString, null) <= 0) { this.errMessage = "添加商品类别时发生了错误!"; return(false); } return(true); }