In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use C#commodity management system simple version", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "how to use C#commodity management system simple version"!
Here, wrote a huge simple commodity management system, only one to add and view, just to give themselves hands-on!
Product id Name Quantity Price
Apple 100 1
1002 Lay's Potato Chips 20 2
Simple version of the commodity management system:
* Tip: Up to 5 items (fruit, cookware, cookies, etc.)
* Input 1 to add commodities;
* Input the information of each commodity through keyboard and store it.
* Enter 2 to enter the operation of querying commodities (displaying basic information of commodities);
This is the function of this project implementation, the following is the code implementation part.
The first part is to define a Goods class, give id, name, price and quantity, and construct
private int G_id; private string G_name; private int G_num; private float G_Price; //structure public Goods(int g_id, string g_name, int g_num, float g_Price) { G_id = g_id; G_name = g_name; G_num = g_num; G_Price = g_Price; } public int ID { get => G_id; set => G_id = value; } public string Name { get => G_name; set => G_name = value; } public int Num { get => G_num; set {//Determine whether the input value is greater than 0 and less than zero, and the parameter is directly defined as 0 if (value
< 0) { G_num = 0; } else G_num = value; } } public float Price { get =>G_Price; set { if (value
< 0) { G_Price = 0; } else G_Price = value; } } public override string ToString() { return $"{ID}\t{Name}\t{Num}\t{Price}";//ToString方法的改写,从而得到4个参数 } 这一部分就是,代码的主要实现部分,因为一开始想用二维数组,然后试了一下,发现不可行,就改用了List的方法,发现这种非常简单,简易这样使用。 public static List GoodsList = new List(); public static void Login()//初始界面 { Console.WriteLine("输入1,进行添加商品的操作"); Console.WriteLine("输入2,进入查询商品的操作(显示商品的基本信息)"); P_Login();//调用P_login中的对1,2的判定 } public static void P_Login() { int n = Convert.ToInt32(Console.ReadLine()); switch (n) { case 1: AddLogin(); break; case 2: Show(); break; default: Console.WriteLine("你的输入错误"); Login(); break; } } public static void AddLogin() { //输入一定的商品后,调用查询中的Show //这里是用二维数组写入,和输出它,并不能存储,一定的数据 Console.WriteLine("总商品数:"); int num = Convert.ToInt32(Console.ReadLine()); if (num == 0) { Console.WriteLine("你的输入为0,故返回初始界面"); Login(); } else if (num 0)//不能大于5 { //通过商品总数简历一个二维数组 //因为,定义的二维数组是string类型的所有会有BUG在 //储存不了 //string[,] good = new string[num, 4];//数组为四项分别为ID,名字,数量,价格 //for (int i = 0; i < num; i++)//建立一个表格 //{ // Console.Write("请输入ID:", i + 1); // good[i, 0] = Convert.ToString(Console.ReadLine()); // Console.Write("请输入名字:"); // good[i, 1] = Convert.ToString(Console.ReadLine()); // Console.Write("请输入数量:"); // good[i, 2] = Convert.ToString(Console.ReadLine()); // Console.Write("请输入价格:"); // good[i, 3] = Convert.ToString(Console.ReadLine()); //} int a = 0,c=0; string b = ""; float d = 0; for (int i = 0; i < num; i++)//建立一个表格 { //对输入的数据不能判断,只会退出程序 Console.Write("请输入ID:", i + 1); a = Convert.ToInt32(Console.ReadLine()); Console.Write("请输入名字:"); b = Convert.ToString(Console.ReadLine()); Console.Write("请输入数量:"); c = Convert.ToInt32(Console.ReadLine()); Console.Write("请输入价格:"); d = float.Parse(Console.ReadLine()); GoodsList.Add(new Goods(a, b, c, d)); } if (a >= 0 && c >= 0 && d >= 0) { Console.WriteLine("按任意键查看商品列表"); Show();//调用展示的 } else { Console.WriteLine("输入有误,请重新输入"); AddLogin(); } //for (int i = 0; i < good.GetLength(0); i++) //{ // // for (int j = 0; j < good.GetLength(1); j++) // { // Console.Write(good[i, j] + "\t");//使其对齐,输出学生成绩 // } //} } else { Console.WriteLine("按任意键返回初始界面,按0退出程序,按1重新输入"); string e = Convert.ToString(Console.ReadLine()); if (e != "0" && e != "1") { Login(); } else if(e == "1") { P_Login();//重新开始 } else { Environment.Exit(0);//强制退出 } } } public static void Show() { Console.WriteLine(); Console.WriteLine(" 简易版商品管理系统"); Console.WriteLine("--------------------------"); Console.WriteLine("ID\t名字\t数量\t价格\t"); //这里用List储存了一个 GoodsList.Add(new Goods(12, "苹果", 123, 675)); foreach (var te in GoodsList) { Console.WriteLine(te+"\t"); } Console.WriteLine("按任意键返回初始界面,按0退出程序"); string e = Convert.ToString(Console.ReadLine()); if (e != "0") { Login();//返回初始界面 } else { Environment.Exit(0); }
只要在main函数中调用login()就可以对项目就行测试,下面是测试结果:
到此,相信大家对"怎么用C#商品管理系统简易版"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.