C #, a simple inventory management system,

Source: Internet
Author: User

C #, a simple inventory management system,

I am very happy today, because today I am going to share with you an inventory management project.

I personally feel that we must sort out the logic before doing a project. It is a bad habit to keep hitting it without getting the project. When you do a big project, you will not develop a habit of clarifying the logic before doing so, and it will be too complicated to consider in the next project. therefore, it is a good habit to clarify the logic before doing so ..

 

Next, let's analyze this difficult inventory management system.

Since it is inventory management, there is obviously a Goods management class (Adm)

The product category includes (product name, product location, product price, and product evaluation)

The repository class includes some methods.

Initialize item information Input ()

Output Goods List Inputshow ()

Welcome menu Welcom ()

GetHome ()

GetHeightGoods ()

Output the most satisfactory goods InputHeightGoods ()

Finally, call the method in the program's entry class.

The following describes in detail the class, method, and calling code in the Main method.

First, add a product Goods class to the project.

 

Public class Adm {Goods [] goods = new Goods [3]; // instantiate an object Array

 

How to initialize Product Information

Public void Input () {Goods goods1 = new Goods (); // instantiate a goods1 object goods1.Name = ""; goods1.Home = "Emei"; goods1.Satisfy = 99; goods1.Money = 9.9; goods [0] = goods1; // assign each item of the object to the object array Goods goods2 = new Goods (); // instantiate a goods2 object goods2.Name = "tu longdao "; goods2.Home = "unknown"; goods2.Satisfy = 99.9; goods2.Money = 90.9; goods [1] = goods2; // assign each object value to the object array Goods goods3 = new Goods (); // instantiate a goods3 object goods3.Name = "peacock"; goods3.Home = "xx place "; goods3.Satisfy = 100; goods3.Money = 90; goods [2] = goods3; // assign each object value to an object array}

 

Output goods list

Public void Inputshow () {Console. writeLine ("inventory item List"); Console. writeLine ("=================="); foreach (Goods item in goods) // use foreach to traverse the array) {if (item! = Null) // if the value in the current array is not null {Console. writeLine ("item name: \ t {0}", item. name); // print the product Name to the screen} Console. writeLine ("==================== ");}

 

Welcome menu

 

Public void Welcom () {Console. writeLine ("================================ welcome to use the inventory management system ============ ============== "); console. writeLine ("1: Get goods location based on goods name 2: Get the most satisfied goods 3: Exit"); Console. writeLine ("================================ welcome to use the inventory management system ============ ============== "); console. writeLine ("select:"); int choice = int. parse (Console. readLine (); // The input content to the screen itself is a string type, which uses int. parse to int type switch (choice) // select the corresponding function based on the input Array {case 1: GetHome (); br Eak; case 2: InputHeightGoods (GettHeightGoods (); break; case 3: Console. WriteLine ("exited successfully! "); Break; default: Console. WriteLine (" Sorry! No corresponding module "); break ;}}

Obtain the product location based on the product name

 

Public void GetHome () {Console. writeLine ("enter the name of the item to be queried:"); string name = Console. readLine (); foreach (Goods item in goods) {if (item! = Null) // if the value in the current array is not null {if (name. equals (item. name) // If the input Name matches the Name in the array, the corresponding product location {Console. writeLine (item. home); // output goods location Welcom (); break ;}}}}

 

Products with the highest satisfaction

Public Goods GettHeightGoods () {// use the Bubble Sorting Algorithm to sort satisfaction from large to small for (int I = 0; I <goods. length-1; I ++) {for (int j = 0; j <goods. length-1-I; j ++) {if (goods [I]. satisfy <goods [I + 1]. satisfy) // if the first satisfaction in the array is less than the satisfaction in the second satisfaction in the array, then the exchange {// The exchange process Goods a = goods [I]; goods [I] = goods [I + 1]; goods [I + 1] = a ;}} return goods [0]; // return the item with the array subscript 0. The item saved here is the item with the highest satisfaction in the largest array}

 

Output goods with the highest satisfaction

Public void InputHeightGoods (Goods happy) {Console. writeLine ("items with the highest customer satisfaction: {0}; placed at: {1}; Satisfaction: {2}; Price: {3}", happy. name, happy. home, happy. satisfy, happy. money); // output information}

 

 

This inventory system is almost ready.

Finally, call the program entry class (in the Main method ).

Static void Main (string [] args) {Adm adm = new Adm (); // instantiate a repository Class Object adm. input (); // ensure that the first three items have values adm. inputshow (); // call adm to output the item information. welcom (); // call the Console of the welcome menu. readLine ();}

 

This simple inventory management system is OK.

Thank you for taking the time to look at it. I hope it will help you after reading it.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.