在这个飞速发展的信息时代,传统的商店、便利店采用的收银方式及员工管理方式,已经远远达不到要求。传统的具有以下缺点:
-
收款结算速度慢,容易出现营业差错,
-
不宜进行商品调价,盘点效率底
-
用户体验不好
而小型的收银系统拥有众多优点:
1.方便管理员对售货员及商品进行管理,节约大量人力成本。
2.方便顾客进行购物结算,系统会自动对顾客所选物品进行计算。不容易出现差错。
系统整体框架:
爱心便利店开发简介:
开发环境:Windows7
开发工具:VS2017、DuiDesigner_d.exe、MySQL、Duilib库。
开发概要:采用MySQL数据库对数据进行管理。整个系统总共创建了三张表,分别是://1.职工表 create table Employee( id int, -- 员工编号 name varchar(20), -- 员工名字 gender varchar(3), -- 员工性别 birthday Date, -- 生日 password varchar(20), -- 员工密码 position varchar(10), -- 员工职位 telphone varchar(11), -- 联系方式 salary double(9,2) -- 联系方式 ); 2.商品表 create table Goods( GoodsID int, -- 商品编号 GoodsName varchar(20), -- 商品名称 GoodsType varchar(20), -- 商品类别:水果、烟酒、日常用品、副食等 ProductDate DATE, -- 商品生产日期 DeadDate DATE, -- 商品过期日期 Price double(9,2), -- 商品价格 Unit varchar(3), -- 计量单位 Inventory int, -- 库存量:商品剩余数量 AlarmValye int -- 报警值:低于该值时,应提醒管理员进货 ); 3.售货记录表 create table SellRecord( GoodsName varchar(20), -- 商品名称 GoodsPrice double(9, 2), -- 商品价格 Amount int, -- 售出数量 Unit varchar(3), -- 计量单位 SellTime Date, -- 售出时间 Operator varchar(20) -- 售货员 );
采用Duilib库完成操作界面的制作。对Duilib库的了解,大家可以通过点击这里进行了解:Duilib入门简明教程
简明的说Duilib库就是基于win32的一套UI库。
待封装好数据库,完成界面制作后,在对界面的控件进行响应。整个项目就算完成了。
在完成这些操作前,首先要进行MySQL环境配置,Duilib库的编译及环境配置。
待环境配置好之后,首先对数据库进行封装:
MySQL.cpp
#include "pch.h"
#include"MySQL.h"
#include<iostream>
using namespace std;
MySQL::MySQL() {
_mySQL = mysql_init(nullptr);
}
bool MySQL::ConnectMySQL(const char* host, const char* user, const char* passward, const char* dbName) {
if (!mysql_real_connect(_mySQL, host, user, passward, dbName, 3306, nullptr, 0)) {
cout << "数据库连接失败" << endl;
return false;
}
mysql_query(_mySQL, "set names 'gbk' ");
return true;
}
vector<vector<string>> MySQL::Select(const string& strSQL) {
vector<vector<string>> vvRet;
if (mysql_query(_mySQL, strSQL.c_str())) {
//sql命令响应失败
cout << mysql_error(_mySQL) << endl;
return vvRet;
}
//获取查询的记录集
MYSQL_RES* mySQLRes = mysql_store_result(_mySQL);
if (nullptr == mySQLRes) {
cout << mysql_error(_mySQL) << endl;
return vvRet;
}
//获取记录中有多少个字段
int itemCount = mysql_num_fields(mySQLRes);
MYSQL_ROW mysqlRow;
while (mysqlRow = mysql_fetch_row(mySQLRes)) {
//获取到一条记录
vector<string> vItem;
for (size_t i = 0; i < itemCount; ++i) {
vItem.push_back(mysqlRow[i]);
}
vvRet.push_back(vItem);
}
mysql_free_result(mySQLRes);
return vvRet;
}
bool MySQL::Insert(const string& strSQL) {
if (mysql_query(_mySQL, strSQL.c_str())) {
//sql命令响应失败
cout << mysql_error(_mySQL) << endl;
return false;
}
return true;
}
bool MySQL::UpDate(const string& strSQL) {
if (mysql_query(_mySQL, strSQL.c_str())) {
//SQL命令响应失败
cout << mysql_error(_mySQL) << endl;
return false;
}
return true;
}
MySQL::~MySQL() {
mysql_close(_mySQL);
}
登录界面
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<Window size="487,307">
<VerticalLayout width="155" height="39" bkimage="登陆背景0.jpg">
<HorizontalLayout width="487" height="32">
<Button name="BTN_MIN" float="true" pos="422,4,0,0" width="28" height="26" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='skin\GameRes\frame_btn_min.bmp' source='78,0,104,18'" hotimage="file='skin\GameRes\frame_btn_min.bmp' source='52,0,78,14'" />
<Button name="BTN_CLOSE" float="true" pos="454,4,0,0" width="28" height="26" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="skin\GameRes\frame_btn_close_disable.bmp" hotimage="skin\GameRes\frame_btn_close_hot.bmp" pushedimage="skin\GameRes\frame_btn_close_down.bmp" />
</HorizontalLayout>
<Edit name="EDIT_USER_NAME" tooltip="输入用户名" float="true" pos="166,107,0,0" width="155" height="39" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Edit name="EDIT_USER_PASSWORD" tooltip="输入用户名密码" float="true" pos="166,166,0,0" width="155" height="39" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" password="true" />
<Button name="BTN_LOGIN" text="登录" float="true" pos="185,221,0,0" width="112" height="32" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" />
<Label float="true" pos="116,113,0,0" width="31" height="27" bkimage="skin\用户名.png" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Label float="true" pos="116,171,0,0" width="32" height="28" bkimage="skin\密码.png" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
</VerticalLayout>
</Window>
管理员界面
管理员可以对员工和商品进行管理;
对员工可以完成插入员工信息、查询员工信息、删除员工信息、更新员工信息。
对商品可以完成商品入库、删除过期商品、商品更新、查询商品、销售记录等功能。
*
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<Window size="941,649">
<VerticalLayout width="941" height="521" bkimage="登陆背景0.jpg">
<HorizontalLayout width="940" height="34" bkcolor="#FFA0A0A4">
<Button name="BTN_MIN" tooltip="最小化" float="true" pos="868,3,0,0" width="33" height="30" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='frame_btn_min.bmp' source='78,0,104,18'" hotimage="file='frame_btn_min.bmp' source='52,0,78,18'" />
<Button name="BTN_CLOSE" tooltip="关闭" float="true" pos="902,3,0,0" width="33" height="30" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='LogInWnd\frame_btn_close_disable.bmp' source='14,0,28,18'" hotimage="file='LogInWnd\frame_btn_close_hot.bmp' source='14,0,28,18'" pushedimage="file='LogInWnd\frame_btn_close_down.bmp' source='14,0,28,18'" />
</HorizontalLayout>
<HorizontalLayout width="937" height="41">
<Option name="OPTION_EMPLOYEE" text="员工操作" float="true" pos="3,2,0,0" width="61" height="33" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="skin\GameRes\headerctrl_normal.bmp" hotimage="skin\GameRes\headerctrl_hot.bmp" pushedimage="skin\GameRes\headerctrl_down.bmp" group="true" selected="true" />
<Option name="OPTION_GOODS" text="商品操作" float="true" pos="65,2,0,0" width="61" height="33" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="skin\GameRes\headerctrl_normal.bmp" hotimage="skin\GameRes\headerctrl_hot.bmp" pushedimage="skin\GameRes\headerctrl_down.bmp" group="true" />
</HorizontalLayout>
<TabLayout name="tablayout">
<VerticalLayout width="936" height="514">
<Edit name="username" text="姓名" width="80" height="30" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Combo name="usergender" float="true" pos="90,0,0,0" width="140" height="30" itemtextcolor="#FF000000" itemselectedtextcolor="#FF000000" itemselectedbkcolor="#FFC1E3FF" itemhottextcolor="#FF000000" itemhotbkcolor="#FFE9F5FF" itemdisabledtextcolor="#FFCCCCCC" itemdisabledbkcolor="#FFFFFFFF" normalimage="file='skin\GameRes\Combo_nor.bmp'" hotimage="file='skin\GameRes\Combo_over.bmp' " pushedimage="file='skin\GameRes/Combo_over.bmp' " dropboxsize="0,150">
<ListLabelElement text="男"/>
<ListLabelElement text="女"/>
</Combo>
<Edit name="userbirthday" text="birthday" float="true" pos="240,0,0,0" width="80" height="30" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Combo name="position" float="true" pos="330,0,0,0" width="140" height="30" itemtextcolor="#FF000000" itemselectedtextcolor="#FF000000" itemselectedbkcolor="#FFC1E3FF" itemhottextcolor="#FF000000" itemhotbkcolor="#FFE9F5FF" itemdisabledtextcolor="#FFCCCCCC" itemdisabledbkcolor="#FFFFFFFF" normalimage="file='skin\GameRes\Combo_nor.bmp'" hotimage="file='skin\GameRes\Combo_over.bmp' " pushedimage="file='skin\GameRes/Combo_over.bmp' " dropboxsize="0,150">
<ListLabelElement text="管理员"/>
<ListLabelElement text="售货员"/>
</Combo>
<Edit name="telphone" text="tel" float="true" pos="480,0,0,0" width="80" height="30" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Edit name="salary" text="$$$" float="true" pos="570,0,0,0" width="80" height="30" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<List name="ListEmployeeInfo" float="true" pos="10,40,0,0" width="700" height="500" bkcolor="#FFFFFFFF" itemtextcolor="#FF000000" itembkcolor="#FFE2DDDF" itemselectedtextcolor="#FF000000" itemselectedbkcolor="#FFC1E3FF" itemhottextcolor="#FF000000" itemhotbkcolor="#FFE9F5FF" itemdisabledtextcolor="#FFCCCCCC" itemdisabledbkcolor="#FFFFFFFF" headerbkimage="skin\ListRes/list_header_bg.png">
<ListHeader name="domain" bkimage="skin\ListRes/list_header_bg.png">
<ListHeaderItem text="姓名" width="100" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="性别" width="100" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="生日" width="100" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="职务" width="100" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="电话" width="100" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="薪资" width="100" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
</ListHeader>
</List>
<Button name="BTN_SELECT" text="查询" float="true" pos="746,82,0,0" width="153" height="40" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="skin\GameRes\button_nor.bmp" hotimage="skin\GameRes\button_over.bmp" pushedimage="skin\GameRes\button_down.bmp" />
<Button name="BTN_UPDATE" text="更新" float="true" pos="748,249,0,0" width="153" height="40" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="skin\GameRes\button_nor.bmp" hotimage="button_over.bmp" pushedimage="skin\GameRes\button_down.bmp" />
<Button name="BTN_DELETE" text="删除" float="true" pos="747,341,0,0" width="153" height="40" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="skin\GameRes\button_nor.bmp" hotimage="skin\GameRes\button_over.bmp" pushedimage="skin\GameRes\button_down.bmp" />
<Button name="BTN_INSERT" text="插入" float="true" pos="748,156,0,0" width="153" height="40" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="skin\GameRes\button_nor.bmp" hotimage="skin\GameRes\button_over.bmp" pushedimage="skin\GameRes\button_down.bmp" />
<Button name="BTN_SELL_RECORD" text="销售记录" float="true" pos="747,415,0,0" width="153" height="40" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="skin\GameRes\button_nor.bmp" hotimage="skin\GameRes\button_over.bmp" pushedimage="skin\GameRes\button_down.bmp" />
<Combo name="COMOB_SELECT" float="true" pos="747,40,0,0" width="151" height="34" itemtextcolor="#FF000000" itemselectedtextcolor="#FF000000" itemselectedbkcolor="#FFC1E3FF" itemhottextcolor="#FF000000" itemhotbkcolor="#FFE9F5FF" itemdisabledtextcolor="#FFCCCCCC" itemdisabledbkcolor="#FFFFFFFF" normalimage="skin\GameRes\Combo_nor.bmp" hotimage="skin\GameRes\Combo_over.bmp" pushedimage="skin\GameRes\Combo_over.bmp" dropboxsize="0,150">
<ListLabelElement text="姓名"/>
<ListLabelElement text="性别"/>
<ListLabelElement text="薪资"/>
</Combo>
</VerticalLayout>
<VerticalLayout width="936" height="514">
<Edit name="goodsname" text="商品名称" width="80" height="30" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Combo name="goodsgender" float="true" pos="90,0,0,0" width="80" height="30" itemtextcolor="#FF000000" itemselectedtextcolor="#FF000000" itemselectedbkcolor="#FFC1E3FF" itemhottextcolor="#FF000000" itemhotbkcolor="#FFE9F5FF" itemdisabledtextcolor="#FFCCCCCC" itemdisabledbkcolor="#FFFFFFFF" normalimage="file='skin\GameRes\Combo_nor.bmp'" hotimage="file='skin\GameRes\Combo_over.bmp' " pushedimage="file='skin\GameRes/Combo_over.bmp' " dropboxsize="0,150">
<ListLabelElement text="水果"/>
<ListLabelElement text="烟酒"/>
<ListLabelElement text="日常用品"/>
<ListLabelElement text="副食"/>
</Combo>
<Edit name="goodsproductionbirthday" text="生产日期" float="true" pos="180,0,0,0" width="80" height="30" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Edit name="goodsoverduebirthday" text="过期日期" float="true" pos="270,0,0,0" width="80" height="30" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Edit name="goodsprice" text="¥¥¥" float="true" pos="360,0,0,0" width="80" height="30" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Combo name="position" float="true" pos="450,0,0,0" width="80" height="30" itemtextcolor="#FF000000" itemselectedtextcolor="#FF000000" itemselectedbkcolor="#FFC1E3FF" itemhottextcolor="#FF000000" itemhotbkcolor="#FFE9F5FF" itemdisabledtextcolor="#FFCCCCCC" itemdisabledbkcolor="#FFFFFFFF" normalimage="file='skin\GameRes\Combo_nor.bmp'" hotimage="file='skin\GameRes\Combo_over.bmp' " pushedimage="file='skin\GameRes/Combo_over.bmp' " dropboxsize="0,150">
<ListLabelElement text="斤"/>
<ListLabelElement text="盒"/>
<ListLabelElement text="瓶"/>
<ListLabelElement text="袋"/>
</Combo>
<Edit name="inventory" text="库存量" float="true" pos="540,0,0,0" width="80" height="30" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Edit name="alarm" text="报警值" float="true" pos="630,0,0,0" width="80" height="30" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<List name="ListGoodsInfo" float="true" pos="10,40,0,0" width="700" height="500" bkcolor="#FFFFFFFF" itemtextcolor="#FF000000" itembkcolor="#FFE2DDDF" itemselectedtextcolor="#FF000000" itemselectedbkcolor="#FFC1E3FF" itemhottextcolor="#FF000000" itemhotbkcolor="#FFE9F5FF" itemdisabledtextcolor="#FFCCCCCC" itemdisabledbkcolor="#FFFFFFFF" header="hidden" headerbkimage="skin\ListRes/list_header_bg.png">
<ListHeader name="domain" bkimage="skin\ListRes/list_header_bg.png">
<ListHeaderItem text="商品名称" width="85" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="商品类别" width="85" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="生产日期" width="85" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="过期日期" width="85" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="价格" width="85" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="计量单位" width="85" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="库存量" width="85" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="报警值" width="85" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
</ListHeader>
</List>
<Button name="BTN_SELECT" text="查询商品" visible="true" float="true" pos="746,82,0,0" width="153" height="40" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="skin\GameRes\button_nor.bmp" hotimage="skin\GameRes\button_over.bmp" pushedimage="skin\GameRes\button_down.bmp" />
<Button name="BTN_UPDATE" text="商品入库" visible="true" float="true" pos="748,249,0,0" width="153" height="40" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="skin\GameRes\button_nor.bmp" hotimage="button_over.bmp" pushedimage="skin\GameRes\button_down.bmp" />
<Button name="DeleteBTN" text="过期商品删除" visible="true" float="true" pos="747,341,0,0" width="153" height="40" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="skin\GameRes\button_nor.bmp" hotimage="skin\GameRes\button_over.bmp" pushedimage="skin\GameRes\button_down.bmp" />
<Button name="BTN_INSERT" text="商品更新" visible="true" float="true" pos="748,156,0,0" width="153" height="40" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="skin\GameRes\button_nor.bmp" hotimage="skin\GameRes\button_over.bmp" pushedimage="skin\GameRes\button_down.bmp" />
<Button name="BTN_SELL_RECORD" text="销售记录" visible="true" float="true" pos="747,415,0,0" width="153" height="40" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="skin\GameRes\button_nor.bmp" hotimage="skin\GameRes\button_over.bmp" pushedimage="skin\GameRes\button_down.bmp" />
<Combo name="COMOB_SELECT" float="true" pos="747,40,0,0" width="151" height="34" itemtextcolor="#FF000000" itemselectedtextcolor="#FF000000" itemselectedbkcolor="#FFC1E3FF" itemhottextcolor="#FF000000" itemhotbkcolor="#FFE9F5FF" itemdisabledtextcolor="#FFCCCCCC" itemdisabledbkcolor="#FFFFFFFF" normalimage="skin\GameRes\Combo_nor.bmp" hotimage="skin\GameRes\Combo_over.bmp" pushedimage="skin\GameRes\Combo_over.bmp" dropboxsize="0,150">
<ListLabelElement text="水果"/>
<ListLabelElement text="烟酒"/>
<ListLabelElement text="日常用品"/>
<ListLabelElement text="副食"/>
</Combo>
</VerticalLayout>
</TabLayout>
</VerticalLayout>
</Window>
收银员界面
收银员界面实现了商品结算的功能。
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<Window size="941,649">
<VerticalLayout width="941" height="521" bkimage="登陆背景0.jpg">
<HorizontalLayout width="940" height="34" bkcolor="#FFA0A0A4">
<Button name="BTN_MIN" float="true" pos="868,3,0,0" width="33" height="30" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='frame_btn_min.bmp' source='78,0,104,18'" hotimage="file='frame_btn_min.bmp' source='52,0,78,18'" />
<Button name="BTN_CLOSE" float="true" pos="902,3,0,0" width="33" height="30" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='LogInWnd\frame_btn_close_disable.bmp' source='14,0,28,18'" hotimage="file='LogInWnd\frame_btn_close_hot.bmp' source='14,0,28,18'" pushedimage="file='LogInWnd\frame_btn_close_down.bmp' source='14,0,28,18'" />
</HorizontalLayout>
<Edit name="EDIT_GOODS_NAME" float="true" pos="80,65,0,0" width="131" height="31" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Edit name="EDIT_GOODS_LEFT" float="true" pos="293,66,0,0" width="131" height="31" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Edit name="EDIT_GOODS_COUNT" float="true" pos="556,67,0,0" width="131" height="31" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Button name="BTN_SUB" text="-" float="true" pos="704,67,0,0" width="34" height="30" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" />
<Button name="BTN_ADD" text="+" float="true" pos="510,66,0,0" width="34" height="30" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" />
<Label text="商品名称:" float="true" pos="13,67,0,0" width="59" height="25" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Label text="库存剩余:" float="true" pos="226,68,0,0" width="58" height="25" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Button name="BTN_SELECT" text="查询" float="true" pos="440,65,0,0" width="57" height="30" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="button_nor.bmp" hotimage="button_nor.bmp" pushedimage="button_down.bmp" />
<List name="OrderList" float="true" pos="6,98,0,0" width="875" height="397" itemtextcolor="#FF000000" itemselectedtextcolor="#FF000000" itemselectedbkcolor="#FFC1E3FF" itemhottextcolor="#FF000000" itemhotbkcolor="#FFE9F5FF" itemdisabledtextcolor="#FFCCCCCC" itemdisabledbkcolor="#FFFFFFFF" headerbkimage="skin\ListRes/list_header_bg.png">
<ListHeader name="domain" bkimage="skin\ListRes/list_header_bg.png">
<ListHeaderItem text="商品名称" width="160" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="价格" width="160" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="数量" width="160" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="单位" width="160" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
<ListHeaderItem text="总价" width="160" height="23" minwidth="16" textcolor="#FF000000" sepwidth="1" align="center" hotimage="List/list_header_hot.png" pushedimage="List/list_header_pushed.png" sepimage="List/list_header_sep.png" />
</ListHeader>
</List>
<Edit name="EDIT_TOTAL" float="true" pos="124,523,0,0" width="119" height="36" bkcolor="#FFFFFFFF" textpadding="4,3,4,3" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Button name="BTN_COMMIT" text="确认售出" float="true" pos="466,522,0,0" width="70" height="37" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="button_nor.bmp" hotimage="button_over.bmp" pushedimage="button_down.bmp" />
<Button name="BTN_CANCEL" text="取消" float="true" pos="569,522,0,0" width="70" height="37" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="button_nor.bmp" hotimage="button_over.bmp" pushedimage="button_down.bmp" />
<Label text="总价格:" float="true" pos="63,523,0,0" width="44" height="35" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" />
<Button name="BTN_OK" text="OK" float="true" pos="762,65,0,0" width="70" height="30" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="button_nor.bmp" hotimage="button_over.bmp" pushedimage="button_down.bmp" />
</VerticalLayout>
</Window>
接下来完成界面的响应:
登录界面响应
#include"LogIn.h"
#include"MainWnd.h"
#include"CashierWnd.h"
LogInWnd::LogInWnd(MySQL* pMySQL)
:m_pMySQL(pMySQL) {
}
//xml文件对应的目录
CDuiString LogInWnd::GetSkinFolder() {
return _T("");
}
//xml文件对应的名字
CDuiString LogInWnd::GetSkinFile() {
return _T("LogInWnd.xml");
}
//窗口类的名字:再注册窗口时必须提供
LPCTSTR LogInWnd::GetWindowClassName(void) const {
return _T("LogInWnd");
}
void LogInWnd::Notify(TNotifyUI& msg) {
CDuiString strName=msg.pSender->GetName();
if (msg.sType == _T("click")) {
if (strName == _T("BTN_MIN")) {
::SendMessage(m_hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
//SendMessage(WM_SYSCOMMAND, SW_MINIMIZE);
}
else if (strName == _T("BTN_CLOSE")) {
Close();
}
else if (strName == _T("BTN_LOGIN")) {
LogIn();
}
}
}
void LogInWnd:: LogIn() {
//从编辑框中获取用户名以及密码
CEditUI* pEditUserName = (CEditUI*)m_PaintManager.FindControl(_T("EDIT_USER_NAME"));
CDuiString strUserName = pEditUserName->GetText();
CEditUI* pEditUserPassWord= (CEditUI*)m_PaintManager.FindControl(_T("EDIT_USER_PASSWORD"));
CDuiString strUserPassWord = pEditUserPassWord->GetText();
if (strUserName.IsEmpty()) {
MessageBox(m_hWnd, _T("请输入用户名"), _T("Cashier"), IDOK);
return;
}
if (strUserPassWord.IsEmpty()) {
MessageBox(m_hWnd, _T("请输入密码"), _T("Cashier"), IDOK);
return;
}
//查询数据库,检测该用户是否存在
string strSQL("select* from employee where Name='");
//ascII UNICODE
strSQL += UnicodeToANSI(strUserName);
strSQL += "';";
vector <vector<string>> vRet = m_pMySQL->Select(strSQL);
if (vRet.empty()) {
MessageBox(m_hWnd, _T("用户名错误"), _T("Cashier"), IDOK);
return;
}
string userpassward = UnicodeToANSI(strUserPassWord);
if (userpassward != vRet[0][4]) {
MessageBox(m_hWnd, _T("用户密码错误"), _T("Cashier"), IDOK);
return;
}
//隐藏登录界面
//ShowWindow(false);
if (vRet[0][5] == "管理员") {
//创建主窗口
MainWnd mianWnd(m_pMySQL);
mianWnd.Create(NULL, _T("MainWnd"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
mianWnd.CenterWindow();
mianWnd.ShowModal();
}
else {
//创建售货员窗口
CCashierWnd mianWnd(m_pMySQL);
mianWnd.Create(NULL, _T("CashierWnd"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
mianWnd.CenterWindow();
mianWnd.ShowModal();
}
//tablayoue
}
管理员界面响应
#define _CRT_SECURE_NO_WARNINGS
#include"MainWnd.h"
MainWnd::MainWnd(MySQL* pMySQL)
:m_pMySQL(pMySQL){
}
MainWnd::~MainWnd() {
}
//xml文件对应的目录
CDuiString MainWnd:: GetSkinFolder() {
return _T("");
}
//xml文件对应的名字
CDuiString MainWnd:: GetSkinFile() {
return _T("MainWnd.xml");
}
//窗口类的名字:再注册窗口时必须提供
LPCTSTR MainWnd:: GetWindowClassName(void) const {
return _T("MainWnd");
}
void MainWnd::Notify(TNotifyUI& msg) {
CDuiString strName = msg.pSender->GetName();
if (msg.sType == _T("click")) {
/*if (strName == _T("BTN_CLOSE"))
Close();
else if (strName == _T("BTN_MIIN"))
::SendMessage(m_hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);*/
if (strName == _T("BTN_MIN")) {
::SendMessage(m_hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
//SendMessage(WM_SYSCOMMAND, SW_MINIMIZE);
}
else if (strName == _T("BTN_CLOSE")) {
Close();
}
else if (strName == _T("BTN_SELECT"))
SelectEmployeeInfo();
else if (strName == _T("BTN_INSERT"))
InsertEmployeeInfo();
//MessageBox(NULL, _T("InsertBTN"), _T("Cashier"), IDOK);
else if (strName == _T("BTN_UPDATE"))
MessageBox(NULL, _T("UpdateBTN"), _T("Cashier"), IDOK);
else if (strName == _T("BTN_DELETE"))
DeleteEmployeeInfo();
//MessageBox(NULL, _T("DeleteBTN"), _T("Cashier"), IDOK);
else if (strName == _T("BTN_SELL_RECORD"))
MessageBox(NULL, _T("SELLBTN"), _T("Cashier"), IDOK);
}
else if (msg.sType == _T("selectchanged")) {
CTabLayoutUI* pTab=(CTabLayoutUI*)m_PaintManager.FindControl(_T("tablayout"));
if (strName == _T("OPTION_EMPLOYEE") ){
pTab->SelectItem(0);
}
else {
pTab->SelectItem(1);
}
}
else if (msg.sType == _T("windowinit")) {
//窗口在创建期间,将一些空间初始化
CComboBoxUI* pGender = (CComboBoxUI*)m_PaintManager.FindControl(_T("usergender"));
pGender->SelectItem(0);
CComboBoxUI* position = (CComboBoxUI*)m_PaintManager.FindControl(_T("position"));
position->SelectItem(0);
CComboBoxUI* pSelect = (CComboBoxUI*)m_PaintManager.FindControl(_T("COMOB_SELECT"));
pSelect->SelectItem(0);
}
}
void MainWnd::SelectEmployeeInfo() {
string strSQL("select* from employee");
CComboBoxUI* pCombo = (CComboBoxUI*)m_PaintManager.FindControl(_T("COMOB_SELECT"));
CDuiString strStyle = pCombo->GetText();
if (strStyle == _T("无"))
strSQL += ";";
else if (strStyle == _T("名字")) {
strSQL += "where Name='";
CDuiString strName = ((CEditUI*)m_PaintManager.FindControl(_T("username")))->GetText();
if (strName.IsEmpty()) {
MessageBox(m_hWnd, _T("请输入查询用户的名字"), _T("Cashier"), IDOK);
return;
}
strSQL += UnicodeToANSI(strName);
strSQL += "';";
}
else if (strStyle == _T("性别"))
;
else if (strStyle == _T("薪资"))
;
vector<vector<string>> vRet = m_pMySQL->Select(strSQL);
if (vRet.empty())
return;
CListUI* pListUI = (CListUI*)m_PaintManager.FindControl(_T("ListEmployeeInfo"));
pListUI->RemoveAll();
for (size_t i = 0; i < vRet.size(); i++) {
vector<string>& strItem = vRet[i];
CListTextElementUI* pData = new CListTextElementUI;
pData->SetAttribute(_T("align"), _T("center") );
pListUI->Add(pData);
//名字
pData->SetText(0, ANSIToUnicode(strItem[1]));
pData->SetText(1, ANSIToUnicode(strItem[2]));
pData->SetText(2, ANSIToUnicode(strItem[3]));
pData->SetText(3, ANSIToUnicode(strItem[5]));
pData->SetText(4, ANSIToUnicode(strItem[6]));
pData->SetText(5, ANSIToUnicode(strItem[7]));
}
}
void MainWnd::DeleteEmployeeInfo() {
//获取当前选中
CListUI* pListUI = (CListUI*)m_PaintManager.FindControl(_T("ListEmployeeInfo"));
//pListUI->RemoveAll();
int lineNo = pListUI->GetCurSel();
CListTextElementUI* pRow =(CListTextElementUI*) pListUI->GetItemAt(lineNo);
//从数据库中将该员工的信息删除
//构造SQL命令;
string strSQL("delete ");
CDuiString strName=pRow->GetText(0);
//从数据库中将该条记录删除
//m_pMySQL->Delete(strSQL);
//从List中移除
pListUI->RemoveAt(lineNo);
}
void MainWnd::InsertEmployeeInfo() {
//从界面中获取员工的信息
CDuiString strName=( (CEditUI*)m_PaintManager.FindControl(_T("username")))->GetText();
CDuiString strGender=((CComboBoxUI*)m_PaintManager.FindControl(_T("usergender")))->GetText();
CDuiString strBirthday = ((CEditUI*)m_PaintManager.FindControl(_T("userbirthday")))->GetText();
CDuiString strPosition= ((CComboBoxUI*)m_PaintManager.FindControl(_T("position")))->GetText();
CDuiString strTel = ((CEditUI*)m_PaintManager.FindControl(_T("telphone")))->GetText();
CDuiString strSalary = ((CEditUI*)m_PaintManager.FindControl(_T("salary")))->GetText();
CListUI* pListUI = (CListUI*)m_PaintManager.FindControl(_T("ListEmployeeInfo"));
//pListUI->GetCount();
char szCount[32] = { 0 };
_itoa(pListUI->GetCount()+1, szCount,10);
//构造SQL命令
string strSQL("insert into employee values(");
strSQL += szCount;
strSQL += ",'";
strSQL+= UnicodeToANSI(strName);
strSQL += "', '";
strSQL+= UnicodeToANSI(strGender);
strSQL += "', '";
strSQL += UnicodeToANSI(strBirthday);
strSQL += "', '000000','";
strSQL += UnicodeToANSI(strPosition);
strSQL += "', '";
strSQL += UnicodeToANSI(strTel);
strSQL += "', '";
strSQL += UnicodeToANSI(strSalary);
strSQL += "');";
//响应SQL命令
m_pMySQL->Insert(strSQL);
//将该员工的信息插入到List
CListTextElementUI* pItem = new CListTextElementUI;
pListUI->Add(pItem);
pItem->SetText(0, strName);
pItem->SetText(1, strGender);
pItem->SetText(2, strBirthday);
pItem->SetText(3, strPosition);
pItem->SetText(4, strTel);
pItem->SetText(5, strSalary);
}
售货员界面响应
#include"CashierWnd.h"
CCashierWnd::CCashierWnd(MySQL* pMySQL)
:m_pMySQL(pMySQL)
{}
CCashierWnd::~CCashierWnd() {
}
//xml文件对应的目录
CDuiString CCashierWnd::GetSkinFolder() {
return _T("");
}
//xml文件对应的名字
CDuiString CCashierWnd::GetSkinFile() {
return _T("CashierManage.xml");
}
//窗口类的名字:再注册窗口时必须提供
LPCTSTR CCashierWnd::GetWindowClassName(void) const {
return _T("CashierWnd");
}
void CCashierWnd::Notify(TNotifyUI& msg) {
CDuiString strName=msg.pSender->GetName();
if (msg.sType == _T("click")) {
if (strName == _T("BTN_CLOSE"))
Close();
else if (strName == _T("BTN_MIN"))
::SendMessage(m_hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
else if (strName == _T("BTN_ADD"))
AddGoodsCount();
else if (strName == _T("BTN_SUB"))
SubGoodsCount();
else if (strName == _T("BTN_SELECT"))
SelectGoods();
//MessageBox(m_hWnd, _T("aaa"), _T("Cashier"), IDOK);
else if (strName == _T("BTN_COMMIT"))
CommitOrder();
else if (strName == _T("BTN_CANCEL"))
CancelOrder();
//MessageBox(m_hWnd, _T("aaa"), _T("Cashier"), IDOK);
else if (strName == _T("BTN_OK"))
InsertGoodsList();
}
}
void CCashierWnd::SelectGoods()
{
// 1. 获取商品名称
CDuiString strGoodsName = ((CEditUI*)m_PaintManager.FindControl(_T("EDIT_GOODS_NAME")))->GetText();
// 2. 构造SQL语句,到数据库中查此商品
string strSQL("select * from goods where GoodsName = '");
strSQL += UnicodeToANSI(strGoodsName);
strSQL += "';";
vector<vector<string>> vRet = m_pMySQL->Select(strSQL);
if (vRet.empty())
{
MessageBox(m_hWnd, _T("暂无此商品"), _T("Cashier"), IDOK);
return;
}
// 3. 将商品剩余个数显示到界面编辑框中
((CEditUI*)m_PaintManager.FindControl(_T("EDIT_GOODS_LEFT")))->SetText(ANSIToUnicode(vRet[0][7]));
}
void CCashierWnd::AddGoodsCount()
{
// 库存减1
CEditUI* pGoodsLeft = (CEditUI*)m_PaintManager.FindControl(_T("EDIT_GOODS_LEFT"));
CDuiString strLeft = pGoodsLeft->GetText();
if (strLeft == _T("0"))
{
MessageBox(m_hWnd, _T("库存量不足"), _T("Cashier"), IDOK);
return;
}
int count = 0;
count = atoi(UnicodeToANSI(strLeft).c_str());
--count;
strLeft.Format(_T("%d"), count);
pGoodsLeft->SetText(strLeft);
// 商品个数加1
CEditUI* pGoodsCount = (CEditUI*)m_PaintManager.FindControl(_T("EDIT_GOODS_COUNT"));
CDuiString strCount = pGoodsCount->GetText();
count = atoi(UnicodeToANSI(strCount).c_str());
++count;
strCount.Format(_T("%d"), count);
pGoodsCount->SetText(strCount);
}
void CCashierWnd::SubGoodsCount()
{
// 商品个数减去1
CEditUI* pGoodsCount = (CEditUI*)m_PaintManager.FindControl(_T("EDIT_GOODS_COUNT"));
CDuiString strCount = pGoodsCount->GetText();
if (strCount == _T("0"))
{
MessageBox(m_hWnd, _T("商品个数已经为0!!!"), _T("Cashier"), IDOK);
return;
}
int count = atoi(UnicodeToANSI(strCount).c_str());
--count;
strCount.Format(_T("%d"), count);
pGoodsCount->SetText(strCount);
// 库存加1
CEditUI* pGoodsLeft = (CEditUI*)m_PaintManager.FindControl(_T("EDIT_GOODS_LEFT"));
CDuiString strLeft = pGoodsLeft->GetText();
count = atoi(UnicodeToANSI(strLeft).c_str());
++count;
strLeft.Format(_T("%d"), count);
pGoodsLeft->SetText(strLeft);
}
void CCashierWnd::InsertGoodsList()
{
// 1. 从界面获取商品名称以及购买的数量
CDuiString strGoodsName = ((CEditUI*)m_PaintManager.FindControl(_T("EDIT_GOODS_NAME")))->GetText();
CEditUI* pGoodsCount = (CEditUI*)m_PaintManager.FindControl(_T("EDIT_GOODS_COUNT"));
CDuiString strCount = pGoodsCount->GetText();
// 2. 从数据库中获取商品的价格以及计量单位
string strSQL("select * from goods where GoodsName = '");
strSQL += UnicodeToANSI(strGoodsName);
strSQL += "';";
vector<vector<string>> vRet = m_pMySQL->Select(strSQL);
// 3. 合计价格
int count = atoi(UnicodeToANSI(strCount).c_str());
double price = atof(vRet[0][5].c_str());
price = count * price;
CDuiString strPrice;
strPrice.Format(_T("%lf"), price);
// 4. 将信息更新到list中
CListTextElementUI* pItem = new CListTextElementUI;
CListUI* pList = (CListUI*)m_PaintManager.FindControl(_T("OrderList"));
pList->Add(pItem);
pItem->SetText(0, strGoodsName);
pItem->SetText(1, ANSIToUnicode(vRet[0][5]));
pItem->SetText(2, strCount);
pItem->SetText(3, ANSIToUnicode(vRet[0][6]));
pItem->SetText(4, strPrice);
// 5. 将商品数量以及名称的编辑框清0
((CEditUI*)m_PaintManager.FindControl(_T("EDIT_GOODS_NAME")))->SetText(_T(""));
((CEditUI*)m_PaintManager.FindControl(_T("EDIT_GOODS_LEFT")))->SetText(_T(""));
((CEditUI*)m_PaintManager.FindControl(_T("EDIT_GOODS_COUNT")))->SetText(_T("0"));
}
void CCashierWnd::CancelOrder()
{
// 清空所有商品
CListUI* pList = (CListUI*)m_PaintManager.FindControl(_T("OrderList"));
pList->RemoveAll();
}
void CCashierWnd::CommitOrder()
{
// 1. 合计总价格
CListUI* pList = (CListUI*)m_PaintManager.FindControl(_T("OrderList"));
int count = pList->GetCount();
double totalPrice = 0;
for (int i = 0; i < count; ++i)
{
CListTextElementUI* pItem = (CListTextElementUI*)pList->GetItemAt(i);
CDuiString strPrice = pItem->GetText(4);
totalPrice += atof(UnicodeToANSI(strPrice).c_str());
}
CDuiString strTotalPrice;
strTotalPrice.Format(_T("%.02lf"), totalPrice);
((CEditUI*)m_PaintManager.FindControl(_T("EDIT_TOTAL")))->SetText(strTotalPrice);
// 2. 更新商品的数据库
for (int i = 0; i < count; ++i)
{
CListTextElementUI* pItem = (CListTextElementUI*)pList->GetItemAt(i);
CDuiString strCount = pItem->GetText(2);
string strSQL("update goods set Inventory='");
strSQL += UnicodeToANSI(strCount);
strSQL += "';";
m_pMySQL->UpDate(strSQL);
}
// 3. 插入本次销售记录
}
虽然最后项目完成了基本功能的实现,但是过程中还是遇到了大量的问题。例如:
1.环境搭建遇到的问题,如在我编译Duilib库的时候,刚开始按照32位的方式进行编译,后面一直报错,最后经过网上查阅资料,才发现Duilib库的编译要和你安装的MySQL的要对应,我电脑上安装得是64位版本的,因此Duilib也要采用64位的编译方式。
2.在封数据库操作的时候,对API不够了解,通过查阅MySQL官方文档来解决该问题。
3.在对数据库进行操作的时候,出现汉字乱码问题。经过查阅资料只需要在代码中添加mysql_query(_mySQL, "set names 'gbk' ");
就可完美解决!
这些只是我遇到问题的一部分,希望大家在遇到问题的时候不要心灰意乱,一个一个解决,因为黎明前总是黑暗的。
如果有对这个项目感兴趣的小伙伴,可以在下方链接获取项目源码
有什么问题可以和我讨论交流!