Imports System.Collections.Generic Public Class Product Public Property Name As String Public Property Quantity As Integer Public Property Price As Double End Class Public Class Inventory Private products As New List(Of Product)() Public Sub AddProduct(ByVal product As Product) products.Add(product) End Sub Public Function GetProduct(ByVal name As String) As Product Return products.Find(Function(p) p.Name = name) End Function Public Sub SellProduct(ByVal name As String, ByVal quantity As Integer) Dim product = GetProduct(name) If product IsNot Nothing AndAlso product.Quantity >= quantity Then product.Quantity = quantity Else Console.WriteLine("库存不足或商品不存在") End If End Sub Public Function GetInventory() As List(Of Product) Return products End Function End Class Sub Main() Dim inventory As New Inventory() ' 添加商品 Dim product1 As New Product With {.Name = "商品1", .Quantity = 10, .Price = 50.0} Dim product2 As New Product With {.Name = "商品2", .Quantity = 20, .Price = 100.0} inventory.AddProduct(product1) inventory.AddProduct(product2) ' 销售商品 inventory.SellProduct("商品1", 3) ' 查看库存 Dim products = inventory.GetInventory() For Each product In products Console.WriteLine($"商品名称: {product.Name}, 库存数量: {product.Quantity}, 价格: {product.Price}") Next End Sub
这个示例中,我们定义了一个Product
类来表示商品,包含名称、数量和价格属性,我们创建了一个Inventory
类来管理商品的库存,包括添加商品、获取商品、销售商品和查看库存等功能,在Main
方法中,我们创建了一个Inventory
实例,并添加了一些商品,然后进行了销售操作,最后查看了库存情况。
以上内容就是解答有关“vb 进销存源码”的详细内容了,我相信这篇文章可以为您解决一些疑惑,有任何问题欢迎留言反馈,谢谢阅读。
原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/1128503.html
本网站发布或转载的文章及图片均来自网络,其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。
发表回复