仓库管理系统项目(三层架构实现简单的数据删除)

在仓库管理系统项目中,我负责的是“出库”——可以理解为数据的删除
首先我们先搭建好三层架构:DALBLLModle并增加管理好三者之间的引用。

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的数据已经被删除!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值