在仓库管理系统项目中,我负责的是“出库”——可以理解为数据的删除
首先我们先搭建好三层架构:DAL,BLL,Modle并增加管理好三者之间的引用。
UL层代码:
<div>
<asp:Label ID="Label_chuku" runat="server" Text="Label">出库</asp:Label>
<table>
<tr>
<td>
仓库号:
</td>
<td>
<asp:TextBox ID="TextBox_OStorID" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
产品号:
</td>
<td>
<asp:TextBox ID="TextBox_OProID" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
数量:
</td>
<td>
<asp:TextBox ID="TextBox_OutlayCount" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
出库时间:
</td>
<td>
<asp:TextBox ID="TextBox_OutlayTime" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<asp:Button ID="Button1" runat="server" Text="出库" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Button" />
</div>
显示的效果:
数据库中的数据:
出库是根据商品ID删除(OProID)
DAL层:在这一层写入删除语句
public static int delete(Model.Outlay model)
{
string sql = string.Format("delete from Outlay where OProID={0}",model.OProID);
int num = DBhelper.ExcuteNonQuery(sql);
return num;
}
BLL层:用于定义删除
public static int delete(Outlay model)
{
return OutlayDAL.delete(model);
}
Model层:用于放置数据库模型
public class Outlay
{
public int OStorID{ get; set; } //仓库号 外键 链接仓库表
public int OProID { get; set; } //产品号 外键 链接产品表
public int OutlayCount { get; set; } //数量
public string OutlayTime { get; set; } //出库时间
}
UI层:给按钮添加单击事件:
protected void Button1_Click(object sender, EventArgs e)
{
Outlay model = new Outlay();
model.OStorID = Convert.ToInt32(this.TextBox_OStorID.Text);
model.OProID= Convert.ToInt32(this.TextBox_OProID.Text);
model.OutlayCount= Convert.ToInt32(this.TextBox_OutlayCount.Text);
model.OutlayTime = this.TextBox_OutlayTime.Text;
int num = OutlayBLL.delete(model);
if (num > 0)
{
Response.Write("<script>alert('删除成功')</script>");
}
else
{
Response.Write("<script>alert('出库失败')<script>");
}
}
运行效果:根据 产品号1002删除该条数据
出库成功即代表数据删除成功
再来重新查询数据库中是否删除成功:
我们发现OProID为1002的数据已经被删除!