Foxtable(狐表)用户栏目专家坐堂 → 求助:如何用消费明细中的数据,写入入库出库表中的出库数量后自动计算库存。


  共有6132人关注过本帖平板打印复制链接

主题:求助:如何用消费明细中的数据,写入入库出库表中的出库数量后自动计算库存。

帅哥哟,离线,有人找我吗?
李孝春
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:九尾狐 帖子:2472 积分:17346 威望:0 精华:0 注册:2013/1/31 0:03:00
求助:如何用消费明细中的数据,写入入库出库表中的出库数量后自动计算库存。  发帖心情 Post By:2014/7/8 23:33:00 [只看该作者]

按照帮助中做的现金流水账 改成了入库出库及库存计算
现在项目中有一消费明细表、入库出库表。
期待在消费明细表中
 一旦选择了某个物品后 输入 数量  自动计算价格后  
及时将这个数据写入入库出库表中的商品名及出库数量 同时自动计算库存数

入库出库表中字段依次为:
物品名称 物品编码 物品规格 入库  入库时间 出库 出库时间 库存
消费明细表中字段依次为:
餐桌编号 订单编号 消费物品 物品规格 消费数量  物品单价 累计消费  消费时间


期待消费明细每增加一行记录就对应在入库出库中写入一行数据
将【消费明细】中的【消费物品】等于【入库出库】中的【物品名称】
将【消费明细】中的【消费数量】等于【入库出库】中的【出库】
将【消费明细】中的【消费时间】等于【入库出库】中的【出库时间】

经过摸索:在消费明细表中DATACOLCHANGED事件中加入如下代码:
Select Case e.DataCol.Name
    Case "消费数量"
        Tables("入库出库").AddNew
        Dim a As Row = Tables("入库出库").Current
        a("物品名称")=e.DataRow("消费物品")
        a("出库")=e.DataRow("消费数量")
        a("出库时间")=e.DataRow("消费时间")        
End Select

运行测试达到初步效果。



图片点击可在新窗口打开查看此主题相关图片如下:221.jpg
图片点击可在新窗口打开查看
入库出库表
代码如下:
Select Case e.DataCol.Name
    Case "物品名称","入库","出库"
        If e.DataCol.Name = "物品名称" Then
            If e.NewValue Is Nothing Then
                e.DataRow("物品编码") = Nothing
                e.DataRow("入库") = Nothing
                e.DataRow("物品规格") = Nothing
                e.DataRow("出库")=Nothing
            Else
                
Dim dr1 As DataRow
dr1 = DataTables("物品信息").Find("[物品名称] = '" & e.NewValue & "'")
                If dr1 IsNot Nothing
                    e.DataRow("物品编码") = dr1("物品编码")
                    e.DataRow("物品规格") = dr1("规格")
                End If
            End If
        End If
        
        Dim dr As DataRow
        Dim mr As DataRow = e.DataRow
        Dim drs As List(of DataRow)
        dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [物品名称] = '" & mr("物品名称") & "'", "[_SortKey] Desc")
        If dr Is Nothing Then
            mr("库存") = mr("入库") - mr("出库")
            dr = mr
        End If
        drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [物品名称] = '" & dr("物品名称") & "'", "[_SortKey]")
        For i As Integer = 1 To drs.Count - 1
            drs(i)("库存") = drs(i-1)("库存") + drs(i)("入库") - drs(i)("出库")
        Next
        If e.DataCol.Name = "物品名称" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
            dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [物品名称] = '" & e.OldValue & "'", "[_SortKey] Desc")
            If dr Is Nothing Then
                dr = e.DataTable.Find("[物品名称] = '" & e.OldValue & "'", "[_SortKey]")
                If dr IsNot Nothing Then
                    dr("库存") = dr("入库") - dr("出库")
                End If
            End If
            If dr IsNot Nothing Then
                drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [物品名称] = '" & dr("物品名称") & "'", "[_SortKey]")
                For i As Integer = 1 To drs.Count - 1
                    drs(i)("库存") = drs(i-1)("库存") + drs(i)("入库") - drs(i)("出库")
                Next
            End If
        End If
End Select


图片点击可在新窗口打开查看此主题相关图片如下:222.jpg
图片点击可在新窗口打开查看
物品入库表 代码如下:
Select Case e.DataCol.Name
    Case "物品名称"
        If e.DataCol.Name = "物品名称" Then
            If e.NewValue Is Nothing Then
                e.DataRow("物品编码") = Nothing
                e.DataRow("物品名称") = Nothing
                e.DataRow("助记码") = Nothing
                e.DataRow("入库日期")=Nothing
            Else
                Dim a1 As DataRow = DataTables("入库出库").Find("[物品名称] = '" & e.NewValue & "'")
                Dim dr As DataRow
                dr = DataTables("物品信息").Find("[物品名称] = '" & e.NewValue & "'")
                If dr IsNot Nothing
                    e.DataRow("物品名称") = dr("物品名称")
                    e.DataRow("物品编码") = dr("物品编码")
                    e.DataRow("助记码") = dr("助记码")
                    e.DataRow("入库日期") = Date.now()
                    e.DataRow("当前库存")=DataTables("入库出库").Compute("sum(库存)","[物品名称] = '" & e.NewValue & "'")
                    'a1("库存")
                End If
            End If
        End If
End Select

Select Case e.DataCol.Name
    Case "数量"
        Tables("入库出库").AddNew
        Dim a As Row = Tables("入库出库").Current
        a("物品名称")=e.DataRow("物品名称")
        a("入库")=e.DataRow("数量")
        a("入库时间")=e.DataRow("入库日期")
        e.DataRow("当前库存")=DataTables("入库出库").Compute("sum(库存)","[物品名称] = '" & e.NewValue & "'")
End Select

 红色部分代码错误 求纠正为只显示当前物品名称末尾库存数,而不是所有的库存数相加。

图片点击可在新窗口打开查看此主题相关图片如下:223.jpg
图片点击可在新窗口打开查看

消费明细图  代码如下:
If e.DataCol.Name = "消费物品" Then
    If e.NewValue Is Nothing Then
        e.DataRow("消费数量") = Nothing
        e.DataRow("物品单价") = Nothing
        e.DataRow("物品规格") = Nothing
        e.DataRow("消费时间")=Nothing
    Else       
        Dim dr As DataRow
        dr = DataTables("物品信息").Find("[物品名称] = '" & e.NewValue & "'")
        If dr IsNot Nothing
            e.DataRow("物品单价") = dr("物品单价")
            e.DataRow("物品规格") = dr("规格")
            'e.DataRow("消费数量") = 1           
        End If
    End If   
End If


Select Case e.DataCol.Name
    Case "消费数量"
        e.DataRow("累计消费")=e.DataRow("消费数量")*e.DataRow("物品单价")
        Dim 变量名 As WinForm.Label = Forms("餐桌管理").Controls("Label16")
        变量名.Text = "当前桌号为:【" & Vars("桌号") & "】   共消费【" & Tables("订单表.消费明细").Compute("sum(累计消费)") & "】元"
       ‘以下红色代码写法合理不?求指导
        Tables("入库出库").AddNew
        Dim a As Row = Tables("入库出库").Current
        a("物品名称")=e.DataRow("消费物品")
        a("出库")=e.DataRow("消费数量")
        a("出库时间")=e.DataRow("消费时间")
End Select

[此贴子已经被作者于2014-7-9 1:05:49编辑过]

 回到顶部
总数 17 1 2 下一页