即使另一列为空,有没有可能在datagridview中显示所有材料名称的方法?

时间:2019-04-05 05:30:29

标签: vb.net datagridview

在我的清单程序中,数据库中有3个表。 1.输入    列(id,材料,数量) 2.输出    列(id,材料,数量) 3. MaterialList(表)我可以在其中输入材料名称的地方    列(id,材料)

在我的剩余库存表格中,我想显示所有MaterialList的剩余库存,包括没有库存的物料。

例如: 从物料清单从输入和输出数量 物料清单剩余库存 项目1 150 item2
item3
item4 200

我尝试过,但是没有希望。

   conn.Open()
        conn = New MySqlConnection
        conn.ConnectionString = "server=localhost;userid=root;password=SOUTHEAST;database=reportingsystem"
        Dim searchquery As String = "select reportingsystem.rawmaterialswarehouseandrawmaterials.Rawmaterials, reportingsystem.rawmaterialswarehouseandrawmaterials.safetystocks, (Sum(reportingsystem.rawmaterialsinput.Quantity) - sum(reportingsystem.rawmaterialsoutput.Quantity)) as 'Remaining Stocks' from reportingsystem.rawmaterialsinput, reportingsystem.rawmaterialsoutput, reportingsystem.rawmaterialswarehouseandrawmaterials where reportingsystem.rawmaterialsinput.RawMaterial = reportingsystem.rawmaterialswarehouseandrawmaterials.Rawmaterials" ' JOIN reportingsystem.rawmaterialsinput.RawMaterial ON reportingsystem.rawmaterialswarehouseandrawmaterials.Rawmaterials = reportingsystem.rawmaterialsinput.RawMaterial ORDER BY reportingsystem.rawmaterialswarehouseandrawmaterials.Rawmaterials"
        'Select rawmaterialsinput.DeliveryDate as 'Delivery Date', rawmaterialswarehouseandrawmaterials.Rawmaterials, (sum(rawmaterialsinput.Quantity) - sum(rawmaterialsoutput.Quantity)) as 'Quantity' , rawmaterialswarehouseandrawmaterials.safetystocks from reportingsystem.rawmaterialsinput, reportingsystem.rawmaterialsoutput, reportingsystem.rawmaterialswarehouseandrawmaterials where rawmaterialsinput.RawMaterial = rawmaterialsoutput.RawMaterial
        '"Select rawmaterialswarehouseandrawmaterials.Rawmaterials as 'Raw Materials', rawmaterialswarehouseandrawmaterials.safetystocks as 'Safety Stock', (sum(rawmaterialsinput.Quantity) - sum(rawmaterialsoutput.Quantity)) as 'Remaining Stocks' where rawmaterialsinput.RawMaterial = rawmaterialswarehouseandrawmaterials.Rawmaterials FROM reportingsystem.rawmaterialswarehouseandrawmaterials, reportingsystem.rawmaterialsinput, reportingsystem.rawmaterialsoutput"
        'Select rawmaterialswarehouseandmaterials.Rawmaterials, (sum(rawmaterialsinput.Quantity) - sum(rawmaterialsoutput.Quantity)) as 'Remaining Stocks', rawmaterialswarehouseandrawmaterials.safetystocks FROM reportingsystem.rawmaterialswarehouseandrawmaterials, reportingsystem.rawmaterialsinput, reportingsystem.rawmaterialsoutput JOIN input ON rawmaterialsinput.RawMaterial = rawmaterialswarehouseandrawmaterials.Rawmaterials
        Dim commander As New MySqlCommand(searchquery, conn)
        Dim adapter As New MySqlDataAdapter(commander)

        monitoringdata.Clear()

        adapter.Fill(monitoringdata)

        MonitoringDGV.DataSource = monitoringdata

        For Each row As DataGridViewRow In MonitoringDGV.Rows
            Dim quantity As Integer = Val(row.Cells(1).Value)
            Dim safetystocks As Integer = Val(row.Cells(2).Value)
            If safetystocks < quantity Then
                row.DefaultCellStyle.BackColor = Color.Red

            ElseIf safetystocks < (quantity * 1.2) Then

                row.DefaultCellStyle.BackColor = Color.Green


            ElseIf safetystocks > (quantity * 1.2) Then
                row.DefaultCellStyle.BackColor = Color.Green

            End If
        Next
        conn.Close()   

我真正需要的是在第1列中显示所有物料名称,并在第2列中显示剩余库存。

示例:

材料剩余库存 项目1 1 第2项4 Item3
项目4 项目5 18 第6项30 Item7

0 个答案:

没有答案