C++ Commodity Management System

1. Brief introduction of the system

Using C++ language, this paper designs and implements an inbound and outbound commodity management system suitable for supermarkets, which implements functions such as commodity purchase, sales, commodity classification, revenue management, order management, administrator and so on.

2. Systematic Hierarchical Data Flow Diagram

3. System Structure Diagram

IV. Database Design

According to the conceptual design of commodity management system, relationship model is used. The system has three entity object tables and uses stored procedures, functions and triggers to operate on the database. They are the users table, the goods table, and the index table.

According to the user's attributes, the users table contains four fields, whose field names, attributes, types, and constraints are as follows. In the user object, the isAdmin field with the user number id as the primary key indicates whether the user is an administrator or not. It can only take two values, one for an administrator and zero for an ordinary customer.

Field nameattributetypeconstraint
IdUser NumberintPrimary key
usernameUser nameVarchar(30)not null
passwordPasswordVarchar(30)not null
isAdminIs AdministratorintCheck(isAdmin in(0,1))

According to the attributes of goods, the goods merchandise information table contains nine fields, whose field names, attributes, types and constraints are as follows. The commodity number id is used as the primary key.

Field nameattributetypeconstraint
idCommodity NumberIntPrimary key
nameCommodity Namevarchar(255)not null
brandManufacturervarchar(255)not null
purpriceInput Pricedouble(10)not null
salepricepricedouble(10)not null
typeCommodity typevarchar(255)not null
numCommodity Inventoryintnot null
salesnumSales of Goodsintnot null
dateWarehousing Timevarchar(255)not null

According to the properties of the order, the indent order information table contains seven fields, whose field names, attributes, types, and constraints are as follows. Where the order number id is the primary key, the commodity number and the commodity name can only take the data already in the goods table. username can only take data from the users table.

Field nameattributetypeconstraint
idOrder Numbervarchar(20)Primary key
usernameNext Single Namevarchar(255)not null
goodidCommodity Numberintnot null
goodnameCommodity Namevarchar(255)not null
priceSale Pricedouble(10)not null
numPurchase Quantityintnot null
sum_priceTotal Order Pricedouble(20)not null
V. Key Code Display
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<Windows.h>
#include<WinSock.h>
#include<mysql.h>
#include<string.h>
#include<conio.h>
#include<ctime>
#include<stdio.h>
#include<iomanip>
#include "menu.h"

using namespace std;
#pragma comment(lib,"libmysql.lib")
#pragma comment(lib,"wsock32.lib")
MYSQL* mysql = new MYSQL; //mysql connection  
MYSQL_FIELD* fd;    //Field Column Array  
char field[32][32];    //Two-dimensional array of stored field names  
MYSQL_RES* res; //This structure represents a query result set of returned rows  
MYSQL_ROW column; //A type-safe representation of row data, representing columns of data rows  
char query[150]; //Query Statement  
//Define user name and password
string username = "";
string password = "";
// Defines whether it is an administrator's flag, not by default
bool isAdmin = false;
//Define commodity type
enum GoodsType//Categories
{
    Food = 1,  //food
    Cosmetic,  //Cosmetics
    Commodity,  //Daily Necessities
    Drink,  //Drinks
    Stationery  //Stationery
};

//Basic types of goods
struct Goods//Basic commodity information
{
    int code;//Commodity Number
    string name;//Commodity Name
    string brand;//Manufacturer
    double pur_price;//Sale Price
    double price;//Sale Price
    int num;//Commodity Inventory
    int salenum;//Sales volume
    string type;//Categories
    string date;//Warehousing Time
};

//Basic types of commodity orders
struct OrderGoods//Basic commodity information
{
    string code;//Order Number
    string username; //Player
    string goodname; //Commodity Name
    int goodid;//Commodity Number
    int num; //The quantity purchased for this item
    double price;//price
    double sum_mony;//Total price per unit
    int salesum;//Sales volume, used to update sales
    string date;//Warehousing Time
    double sum_price;//Total Order Price
};


//Functions to connect to databases
bool ConnectDatabase();
//Customer's main menu is to show goods, purchase goods and other functions
void CustomerMenu();
//Warehouse Administrator's Main Menu
void AdministratorMenu();
//Select Login Roles
void ChooseLoginCharacter(string &,bool &);
//Customer Login Page
string CustormerLogin(void);
//Main function of customer selection operation
void CustormerOperation();
//Customer Browse Commodity Function
void BrowseGoods();
//Customer Purchase Commodity Function
void BuyGoods();

//Administrator's login page
string AdministratorLogin(void);
//Primary function for administrator selection operation
void AdministratorOperation();
//Functions for Administrators to Add Commodities
void AddGoodsInfo();
//Functions for Administrators to Modify Commodity Information
void EditGoodsInfo();
//Functions for Administrators to Delete Goods
void DeleteGoodsInfo();
//Administrator queries the main function of a commodity
void SelectGoodsMain();
//Administrator Select Order Operation Mode Function
void SelectOrderOperation();
//Administrator Query Order Function
void SelectOrder();
//Administrator Delete Order Function
void DeleteOrder();
//Functions to choose how to query
void SelectMethod();
//Query commodities via id
void SelectGoodsById();
//Query commodities by commodity name
void SelectGoodsByName();
//Query commodities through manufacturer
void SelectGoodsByBrand();
//Query commodities by commodity type
void SelectGoodsByType();
//Query commodities sorted by price
void SelectGoodsByPriceSort();
//Query commodities sorted by sales
void SelectGoodsBySaleSort();
//Revenue Statistics Menu
void RevenueMenu();
//Select revenue statistics
void SelectRevenue();
//Individual commodity revenue statistics
void RevenueById();
//All Commodity Revenue Statistics
void RevenueAll();
//Administrator Order Management Function
void OrderManagementMenu();
//Modify user's password function
void ChangePassword();

Partial functions:

6. Getting Codes

The project is open source to GitHub, welcome to star.

https://github.com/weiyuexin/CMS

Keywords: C++ Database MySQL CentOS

Added by Hiro on Thu, 18 Nov 2021 19:53:44 +0200