C#实现商品信息的显示异常处理

 

实验四:C#实现商品信息的显示异常处理

任务要求:

在进销存管理系统中,商品的库存信息有很多种类,比如商品型号、商品名称、商品库存量等。在面向对象编程中,这些商品的信息可以存储到属性中,然后当需要使用这些信息时,再从对应的属性中读取出来。这里要求定义库存商品结构,并输出库存商品的信息

C#实现商品信息的显示异常处理_第1张图片

 整体框架:

C#实现商品信息的显示异常处理_第2张图片

实现步骤:

第一步:创建cstockInfo类,并设置如下变量:

 C#实现商品信息的显示异常处理_第3张图片

 第二步:按照如下内容定义商品的13个属性。

 C#实现商品信息的显示异常处理_第4张图片

 C#实现商品信息的显示异常处理_第5张图片

C#实现商品信息的显示异常处理_第6张图片 

 C#实现商品信息的显示异常处理_第7张图片

 C#实现商品信息的显示异常处理_第8张图片

 C#实现商品信息的显示异常处理_第9张图片

 第三步:创建cstockInfo类构造函数,并对商品属性进行初始化

 C#实现商品信息的显示异常处理_第10张图片

 第四步:创建显示商品信息函数

C#实现商品信息的显示异常处理_第11张图片

 第五步:Main函数中输出标题

 第六步:创建商品对象,从键盘输入商品编号、单位全称、商品型号、库存数量四个数据,并显示商品信息(自行补充)

 第九步:实现对商品输入内容的约束并进行异常处理。(自行补充)

1、库存数量:数字,区间范围:1-1000

2、商品规格:“字符”+“-”+“数字”组成。如:TYPE-3

第九步:实现对商品信息多次输入,并进行判断,输入“q”退出程序。(自行补充)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("库存盘点信息如下:");
            cStockInfo csi1 = new cStockInfo();
            csi1.TradeCode = "TJRA001";
            csi1.FullName = "空调";
            csi1.TradeType = "TYPE-1";
            csi1.Standard = "2匹";
            csi1.Unit = "台";
            csi1.Produce = "天津";
            csi1.Qty = 200;
            csi1.Price = 2000;
            csi1.AveragePrice = 2500;
            csi1.SalePrice = 3000;
            csi1.Check = 200;
            csi1.UpperLimit = 800;
            csi1.LowerLimit = 200;
            csi1.ShowInfo();

            cStockInfo csi2 = new cStockInfo();
            csi2.TradeCode = "TJRA002";
            csi2.FullName = "空调";
            csi2.TradeType = "TYPE-2";
            csi2.Standard = "1.5匹";
            csi2.Unit = "台";
            csi2.Produce = "天津";
            csi2.Qty = 300;
            csi2.Price = 3000;
            csi2.AveragePrice = 3500;
            csi2.SalePrice = 4000;
            csi2.Check = 290;
            csi2.ShowInfo();

            cStockInfo csi3 = new cStockInfo();
            csi3.TradeCode = "TJRA003";
            csi3.TradeType = "TYPE-3";
            csi3.ShowInfo();
            Console.ReadLine();     
            ConsoleKey Key;
            do
            {
                Key = Console.ReadKey().Key;
            } while (Key != ConsoleKey.Q
            );
        }
    }

    public class cStockInfo
    {
        private string tradecode = "";
        private string fullname = "";
        private string tradetype = "";
        private string standard = "";
        private string tradeunit = "";
        private string produce = "";
        private float qty = 0;
        private float price = 0;
        private float averageprice = 0;
        private float saleprice = 0;
        private float check = 0;
        private float upperlimit = 0;
        private float lowerlimit = 0;


        public string TradeCode
        {
            get { return tradecode; }
            set { tradecode = value; }
        }
        public string FullName
        {
            get { return fullname; }
            set { fullname = value; }
        }
        public string TradeType
        {
            get { return tradetype; }
            set { tradetype = value; }
        }
        public string Standard
        {
            get { return standard; }
            set { standard = value; }
        }
        public string Unit
        {
            get { return tradeunit; }
            set { tradeunit = value; }
        }
        public string Produce
        {
            get { return produce; }
            set { produce = value; }
        }
        public float Qty
        {
            get { return qty; }
            set { qty = value; }
        }
        public float Price
        {
            get { return price; }
            set { price = value; }
        }
        public float AveragePrice
        {
            get { return averageprice; }
            set { averageprice = value; }
        }
        public float SalePrice
        {
            get { return saleprice; }
            set { saleprice = value; }
        }
        public float Check
        {
            get { return check; }
            set { check = value; }
        }
        public float UpperLimit
        {
            get { return upperlimit; }
            set { upperlimit = value; }
        }
        public float LowerLimit
        {
            get { return lowerlimit; }
            set { lowerlimit = value; }
        }
        public cStockInfo()
        {
            this.TradeCode = "TJRA001";
            this.FullName = "空调";
            this.TradeType = "TYPE-2";
            this.Standard = "2匹";
            this.Unit = "台";
            this.Produce = "天津";
            this.Qty = 200;
            this.Price = 2000;
            this.AveragePrice = 2500;
            this.SalePrice = 3000;
            this.Check = 200;
            this.UpperLimit = 900;
            this.LowerLimit = 100;
        }
        public void ShowInfo()
        {
            Console.WriteLine("------------------------------------------");
            Console.WriteLine("显示商品信息");
            Console.WriteLine("");
            Console.Write("商品编号:{0,-15}", TradeCode);
            Console.Write("单位全称:{0,-15}", FullName);
            Console.Write("商品型号:{0,-15}", TradeType);
            Console.WriteLine("");
            Console.Write("商品规格:{0,-15}", Standard);
            Console.Write("商品单位:{0,-15}", Unit);
            Console.Write("商品产地:{0,-15}", Produce);
            Console.Write("库存数量:{0,-15}", Qty);
            Console.WriteLine("");
            Console.Write("最后一次价格:{0,-15:C}", Price);
            Console.Write("加权平均价格:{0,-15:C}", AveragePrice);
            Console.Write("最后一次销售:{0,-15:C}", SalePrice);
            Console.WriteLine("");
            Console.Write("盘点数量:{0,-15}", Check);
            Console.Write("库存报警上限:{0,-15}", UpperLimit);
            Console.Write("库存报警下限:{0,-15}", LowerLimit);
            Console.WriteLine("");
            Console.WriteLine("商品信息显示完毕");
            Console.WriteLine("------------------------------------------");
        }
    }
     
    }
   

你可能感兴趣的:(c#)