C # practice supermarket cash register system,

Source: Internet
Author: User

C # practice supermarket cash register system,
Class Design

Category 1: product class. The parent class is an abstract class;
Type 2: discount class. The parent class is also an abstract class.
The class diagram is as follows;

Use skill source code

Warehouse

Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; // advantages of this program. When adding a cargo type, you do not need to modify the local code. You only need to call AddShelf to add a shelf. When adding a cargo, add an object based on the cargo name; the reflection mechanism is used when goods are added; namespace _ 33 _ supermarket cash register system {class Cangku {// goods are stored in the warehouse, which must meet the requirements of classification and sorting, therefore, shelves are required; public Dictionary <string, List <ProductFather> list = new Dictionary <string, List <ProductFather> (); // objects that can be operated on shelves, goods, operation Method: add or delete; // <summary> /// Add a shelf for the warehouse; /// </summary> /// <param name = "name"> name of the shelf to be added </param> /// <returns> If the shelf already exists, an error is returned., otherwise, the shelf is successfully added </returns> public bool AddShelf (string name) {if (list. containsKey (name) return false; list [name] = new List <ProductFather> (); return true ;}/// <summary> /// delete a shelf; /// </summary> /// <param name = "name"> name of the shelf to be deleted </param> /// <param name = "reason"> the value is successfully deleted, failure is the cause of failure returned, including the failure of the shelf and the failure of the goods that do not exist </para M> // <returns> indicates whether the deletion is successful </returns> public bool DelShelf (string name, out string reason) {if (list. containsKey (name) {if (list [name]. count = 0) {list. remove (name); reason = "deleted"; return true;} else {reason = "goods available on shelves"; return false ;}} else {reason = "this shelf does not exist"; return false ;}/// <summary> // Add count items of the proType to the shelf; /// </summary> /// <param name = "proType"> goods type. The constructor of the object is found through reflection of this string to implement the factory model. Formula </param> /// <param name = "count"> quantity of goods to be added </param> /// <param name = "price"> price of goods </param> // <returns> </returns> public bool AddProducts (string proType, int count, double price) {if (! List. containsKey (proType) {return false;} string str = "_ 33 _ supermarket cash register system. "+ proType; for (int I = 0; I <count; I ++) {// reflection mechanism is used here; list [proType]. add (ProductFather) Activator. createInstance (System. type. getType (str), price, proType, Guid. newGuid (). toString ();} return true;} // <summary> /// retrieve some items from the warehouse; /// </summary> /// <param name = "proType"> type of the product to be retrieved </param> /// <param name = "reqCount"> required amount removed </par Am> /// <param name = "getCount"> actual amount removed </param> /// <returns> returns the removed product array </returns> public ProductFather [] delProducts (string proType, int reqCount, out int getCount) {ProductFather [] pros = new ProductFather [reqCount]; // an array of determined sizes during runtime; if (! List. containsKey (proType) // There is no shelf for this cargo; {getCount = 0; return null;} for (int I = 0; I <reqCount; I ++) {if (list [proType]. count = 0) // If the goods have been obtained; {getCount = I; return pros;} pros [I] = list [proType] [0]; list [proType]. removeAt (0);} getCount = reqCount; return pros ;} /// <summary> /// obtain the product information in the warehouse /// </summary> /// <returns> returns a formatted string array with one product and one string, you can use the same protocol to parse public string [] GetInfo () {// store shelf information using formatted strings; string [] info = new string [list. count]; int I = 0; foreach (var item in list. keys) {info [I] = item. toString (); info [I] + = "|" + list [item]. count; info [I] + = "|" + list [item] [0]. price;} return info ;}}}

Commodities

Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; namespace _ 33 _ supermarket cash register system {class ProductFather {public double Price {get; set;} public string Name {get; set;} public string ID {get; set ;} public ProductFather (double price, string name, string id) {this. price = price; this. name = name; this. ID = id ;}}}

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.