出货功能。出货时,先输入商品类别,然后输入商品名称,并在库存中查找该商品的相关信息。如果有库存量,输入出货的数量、出货日期,计算销售额和利润。如果库存量不够,给出提示信息,结束出货。功能的代码
时间: 2024-04-01 17:35:11 浏览: 13
好的,以下是一个简单的出货功能的示例代码,仅供参考:
```csharp
using System;
using System.Collections.Generic;
namespace Shipment
{
class Program
{
static void Main(string[] args)
{
// 初始化商品库存信息
Dictionary<string, int> inventory = new Dictionary<string, int>()
{
{"面包", 10},
{"牛奶", 5},
{"饮料", 3}
};
// 输入商品类别
Console.WriteLine("请输入商品类别:");
string category = Console.ReadLine();
// 输入商品名称
Console.WriteLine("请输入商品名称:");
string name = Console.ReadLine();
// 查找商品库存信息
int quantity;
if (inventory.TryGetValue(name, out quantity))
{
// 输入出货数量
Console.WriteLine("请输入出货数量:");
int shippedQuantity = int.Parse(Console.ReadLine());
// 判断库存量是否足够
if (shippedQuantity > quantity)
{
Console.WriteLine($"库存不足,当前库存为{quantity},无法出货{shippedQuantity}个商品。");
}
else
{
// 更新库存信息
inventory[name] = quantity - shippedQuantity;
// 输入出货日期
Console.WriteLine("请输入出货日期:");
DateTime shippedDate = DateTime.Parse(Console.ReadLine());
// 计算销售额和利润
double price = 10; // 假设商品单价为10元
double revenue = shippedQuantity * price;
double cost = shippedQuantity * (price / 2); // 假设成本为单价的一半
double profit = revenue - cost;
// 输出销售信息
Console.WriteLine($"已出货{name} {shippedQuantity}个,销售额为{revenue}元,利润为{profit}元。");
// 更新库存文件
// ...
}
}
else
{
Console.WriteLine($"未找到{name}商品。");
}
}
}
}
```
请注意,此代码仅供参考,实际应用中可能需要根据具体需求进行修改和调整。例如,库存信息可以从文件或数据库中读取,销售信息可以写入到日志文件或数据库中等。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)