代码实现图形化界面的智能微型超市管理系统

开发环境:VS2019

技术点:C/C++Sqlite3

实现的功能:该系统基于Windows平台,使用C/C++,sqlite3技术点,利用面向对象的封装,继承,多态以及STL内的向量容器实现程序设计,在运行时以图形化设计通过键盘键入值,对系统进行操作。系统分为管理员与普通用户两角色、管理用可通过登录普通用户进入商品管理界面对商品进行增、删、改、查以及分页显示全部商品的功能,或者登录Boss账号进行注册添加管理员。普通用户可以实现分页显示商品、购买商品存入购物车内一起支付购买以及根据是否使用商品判断是否可以退还商品的功能。使用单例模式封装提示框,根据不同操作提示不同内容。

部分代码显示:

        一、将封装的多个窗口加入向量容器内,根据不同的返回值选择进入不同的窗口

vector<WinBase*> baseArry;
	ChooseWin *chw = new ChooseWin(1, 1, 17, 16); //主界面
	Control* con = new Control(1, 1, 14, 14); //管理界面
	LoginWin *login = new LoginWin(1, 1, 24, 15); //登录界面
	RegisterWin *reg = new RegisterWin(1, 1, 24, 20); //注册界面
	ManageMenu* mag = new ManageMenu(1, 1, 17, 16); //管理商品界面
	OrdinaryUser* ord = new OrdinaryUser(1, 1, 15, 17); //普通用户界面
	ShowGoods* show = new ShowGoods(0, 0, 25, 16); //商品显示窗口
	DeleteGoods* del = new DeleteGoods(0, 0, 25, 16);//删除商品窗口
	InsertGoods* ins = new InsertGoods(0, 0, 20, 16); //添加商品窗口
	BossLogin* bos = new BossLogin(1, 1, 24, 15); //boss登录界面
	SearchGoods* sea = new SearchGoods(0, 0, 24, 16); //查找商品界面
	ModifyGoods* mod = new ModifyGoods(0, 0, 24, 18); //修改商品界面
	UseGoods* use = new UseGoods(1, 1, 14, 14); //是否使用商品界面
	RefundGoods* ref = new RefundGoods(0, 0, 25, 19); //退还商品界面
	BuyGoods* buy = new BuyGoods(0, 0, 25, 21); //购买商品
	TipBox* p = TipBox::Tip(); //提示框
	//将窗口加入到一个容器内 根据对应的位置执行对应的变量的操作
	baseArry.push_back(chw); //0
	baseArry.push_back(login); //1
	baseArry.push_back(reg); //2
	baseArry.push_back(mag);//3
	baseArry.push_back(ord); //4
	baseArry.push_back(con); //5
	baseArry.push_back(p); //6
	baseArry.push_back(show); //7
	baseArry.push_back(del); //8
	baseArry.push_back(ins); //9
	baseArry.push_back(bos); //10
	baseArry.push_back(sea); //11
	baseArry.push_back(mod); //12
	baseArry.push_back(use); //13
	baseArry.push_back(ref); //14
	baseArry.push_back(buy); //15
	int ret = 0;
	while (1)
	{
		system("cls");
		if (ret == QUIT) break;
		baseArry[ret]->show(); //显示界面
		baseArry[ret]->winRun(); //窗口内光标可以移动 编辑框可以输入 按钮可以按下回车
		ret = baseArry[ret]->doAction(); //执行对应的操作 根据返回值跳转想要跳转的窗口
	}
	for (int i = 0; i < baseArry.size(); i++)
	{
		delete baseArry[i]; //释放容器内每一个数据的空间
	}

        二、单例模式封装数据库与提示框

        数据库

#include "Sqlite.h"
#include <iostream>
using namespace std;
Sqlite* Sqlite::singleDemo = nullptr;//饿汉模式

Sqlite* Sqlite::getSingleDemo()
{
	//现判断唯一的对象是否存在
	//如果存在直接返回
	//如果不存在创建并返回
	if (Sqlite::singleDemo == nullptr)//懒汉模式
	{
		Sqlite::singleDemo = new Sqlite;
	}
	return Sqlite::singleDemo;
}

Sqlite::Sqlite()
{
	sql = nullptr;
	qresult = nullptr;
	row = 0;
	col = 0;
	//数据库打开
	int res = sqlite3_open("data/SQL.db", &this->db);
	if (res == SQLITE_OK)
	{
		return;
	}
	else
	{
		cout << sqlite3_errmsg(this->db) << endl;
	}
}

Sqlite::~Sqlite()
{
	//关闭数据库
	sqlite3_close(this->db);
}

//增删改、创建表---执行完sql语句是没有结果返回
int Sqlite::noResultExec()
{
	char* errmsg;
	int res = sqlite3_exec(this->db, this->sql, nullptr, nullptr, &errmsg);
	return res;
}

//查询
int Sqlite::getDataExec()
{
	char* errmsg;
	if (this->qresult != nullptr) //释放之前二级指针指向的那片空间内的字符串
	{
		sqlite3_free_table(this->qresult);
		this->qresult = nullptr;
	}
	// row表示查询到的数据有几条
	// col表示查询到的数据有几列
	// qresult保存查询到的数据:和二维数组的存储是一样
	// 如果有数据查询到,结果集中会先保存 字段名称,然后才开始存储真正的数据
	int ret = sqlite3_get_table(this->db, this->sql, &(this->qresult), &(this->row), &(this->col), &errmsg);
	return ret;
}

        提示框根据不同内容显示提示框

#include "TipBox.h"
#include "Tool.h"
#include <string.h>
#include <iostream>
using namespace std;
#pragma warning(disable:4996)
TipBox* TipBox::tipBox = nullptr; //静态变量全局 初始化为空
TipBox* TipBox::Tip()
{
	//现判断唯一的对象是否存在
	//如果存在直接返回
	//如果不存在创建并返回
	if (TipBox::tipBox == nullptr)//懒汉模式
	{
		TipBox::tipBox = new TipBox; //创建对象 此后类外只需创建指针通过tip类的此成语函数指向这个创建好的对象
	}
	return TipBox::tipBox;
}

TipBox::TipBox(int x, int y, int w, int h, int Previous)
	:WinBase(x, y, w, h),tip(nullptr) //初始化值 将获取到的x y w h传给父类 画最外框用
{
	this->Previous = Previous;
	this->label_1 = new Label(5, 3, 0, 0, "");
	this->but_1 = new Button(27, 7, 3, 2, "关闭"); //1 关闭

	this->ctrlArry.push_back(this->label_1);
	this->ctrlArry.push_back(this->but_1); //1 关闭
}
TipBox::~TipBox()
{
	//释放容器内的控件 空间
	for (int i = 0; i < ctrlArry.size(); i++)
	{
		delete ctrlArry[i];
	}
}
int TipBox::doAction() //因主函数内按照顺序加入到容器 返回传入数值可跳转到对应的容器内数据(即跳转窗口)
{
	if (this->focux_index == 1)
	{
		return this->Previous;
	}
}
void TipBox::setMsg(const char* tip, int Previous)
{
	this->tip = tip; //获取显示的字符串
	this->Previous = Previous; //返回哪个界面
}
//重写show函数
void TipBox::show()
{
	//显示外框
	Tool::paintWindow(this->x, this->y, this->w, this->h);
	//显示窗口里面的所有的控件
	for (int i = 0; i <  ctrlArry.size(); i++)
	{
		//光标定位
		Tool::gotoxy(18, 2);
		cout << "提示窗口" << endl;
		if (ctrlArry[i] == this->but_1) //编辑框或者是按钮
		{
			Tool::paintWindow(27, 7, 3, 2);
			Tool::gotoxy(29, 8);
			cout << "关闭" << endl;
		}
		else if(ctrlArry[i] == this->label_1)
		{
			//显示提示的内容
			Tool::gotoxy(6, 5);
			cout << this->tip << endl;
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值