项目介绍:利用Duilib库设计前端界面,包括,登陆界面,管理员操作界面和售货员操作界面,相对应的需要使用MySQL数据库设计职工 表,商品表,售货记录表和会员表。实现前端界面和数据库交互,完成商品信息,售货情况,人员管理的需求。
登陆模块:用户输入用户名以及密码后,根据不同的身份,显示不同的界面,用户进行相应操作。分为管理员界面和售货员界面。
部分代码:
CDuiString LoginWnd::GetSkinFolder(){
return _T("");
}
CDuiString LoginWnd::GetSkinFile(){
return _T("login.xml"); //登陆界面的xml文件
}
LPCTSTR LoginWnd::GetWindowClassName() const{
return _T("LogInWnd");
}
void LoginWnd::Notify(TNotifyUI& msg){
if (msg.sType == _T("click")){
if (msg.pSender->GetName() == _T("Button_CLOSE")){ //关闭按键
PostQuitMessage(0); }
else if (msg.pSender->GetName() == _T("Button_MIN")){ //最小化
::SendMessage(m_hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
}
else if (msg.pSender->GetName() == _T("Button_LOGIN")){
Login(); //登陆
}
}
}
void LoginWnd::Login(){
CEditUI* pEdituserName = (CEditUI*)m_PaintManager.FindControl(_T("Edit_Uer"));
CDuiString strUserName = pEdituserName->GetText();
CEditUI* pEdituserPassword = (CEditUI*)m_PaintManager.FindControl(_T("Edit_MI"));
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='");
strSQL += UnicodeToANSI(strUserName);
strSQL += "';";
vector <vector<string >> vRet = p_mysql->SelectDB(strSQL);
if (vRet.empty()) {
MessageBox(m_hWnd, _T("用户名错误"), _T("Cashier"), IDOK);
return;
}
string userpassword = UnicodeToANSI(strUserPassword);
if (userpassword != vRet[0][4]) {
MessageBox(m_hWnd, _T("用户名密码错误"), _T("Cashier"), IDOK);
return;
}
if (vRet[0][5] == "售货员") { //售货员界面
DestroyWindow(m_hWnd);//进入之后就关闭界面
Cashier cashier;
cashier.p_mysql = p_mysql;
cashier.Create(NULL, _T("Cashier"), UI_WNDSTYLE_EX_FRAME, WS_EX_WINDOWEDGE);
cashier.CenterWindow();
cashier.ShowModal();
}
else{ //管理员界面 DestroyWindow(m_hWnd);
MainWnd mainwnd;
mainwnd.p_mysql = p_mysql;
mainwnd.Create(NULL, _T("MainWnd"), UI_WNDSTYLE_EX_FRAME, WS_EX_WINDOWEDGE);
mainwnd.CenterWindow();
mainwnd.ShowModal();
}
}
后台管理员模块:对员工和商品信息进行管理。
员工操作
1. 查询员工基本信息
2.添加新员工
3.员工离职后,删除员工信息
4.员工信息变更时,更新员工信息
CDuiString MainWnd::GetSkinFolder(){
return _T("");
}
CDuiString MainWnd::GetSkinFile(){
//return _T("Cashier.xml");
return _T("MainWnd.xml");
}
LPCTSTR MainWnd::GetWindowClassName() const{
return _T("DUIMainFrame");
}
//窗口类中重写Notify函数,主要响应Duilib自己定义的消息
void MainWnd:: Notify(TNotifyUI& msg) {
if (msg.sType == _T("click")){
if (msg.pSender->GetName() == _T("BTN_CLOSE")) //获取空间名称
PostQuitMessage(0); //关闭窗口
else if (msg.pSender->GetName() == _T("BTN_MIN")){ //最小化
//向win32程序发送系统命令,窗口最小化
::SendMessage(m_hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
}
else if (msg.pSender->GetName() == _T("Button_SELECT")) {
Button_SELECT(); //查询
}
else if (msg.pSender->GetName() == _T("Button_INSERT")) {
Button_INSERT(); //增加新员工信息
}
else if (msg.pSender->GetName() == _T("Button_DROP")) {
Button_Delete(); //删除
else if (msg.pSender->GetName() == _T("Button_UPDATE")) {
Button_Update(); //更新员工信息
}
}
else if (msg.sType == _T("selectchanged")) {
CTabLayoutUI *pTab = (CTabLayoutUI*)m_PaintManager.FindControl(_T("TABLAYOUT"));
if (msg.pSender->GetName() == _T("BTN_EMP")) {
//设置选择项,加载不同的页面
//员工的操作是0
pTab->SelectItem(0);
}
else {
//商品界面操作
DestroyWindow(m_hWnd);
Cashier cashier;
cashier.Create(NULL, _T("Cashier"), UI_WNDSTYLE_EX_FRAME, WS_EX_WINDOWEDGE);
cashier.CenterWindow();
cashier.ShowModal();
}
}
售货员模块:提供售货管理。
商品操作
1.按照条件查询商品的信息
2.商品入库和过期商品的删除
3.商品信息更新
4.按照日期查询商品销售情况
CDuiString Cashier::GetSkinFolder(){
return _T("");
}
CDuiString Cashier::GetSkinFile(){
return _T("Cashier.xml");
}
LPCTSTR Cashier::GetWindowClassName() const{
return _T("DUIMainFrame");
}
void Cashier:: Notify(TNotifyUI& msg){
//psender 在哪一个控件上所做的单击,获取一下名称
CDuiString strName = msg.pSender->GetName();
//msg.pSender->GetText() //获取到的是文本
if (msg.sType ==_T("click")) {
if (strName == _T("BTN_CLOSE")) {
PostQuitMessage(0);
}
else if (strName == _T("BTN_MIN")) {
//win32 系统命令的消息
::SendMessage(m_hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
}
else if (strName == _T("Button_ADD")) {
MessageBox(m_hWnd, _T("ADD"), _T("cashier"), IDOK);
}
else if (strName == _T("Button_SUB")) {
MessageBox(m_hWnd, _T("ADD"), _T("cashier"), IDOK);
}
else if (strName == _T("Button_ENQUIRY")) {
Button_SELECT();
}
else if (strName == _T("Button_CANCEL")) {
MessageBox(m_hWnd, _T("ADD"), _T("cashier"), IDOK);
}
else if (strName == _T("Button_SELL")) {
MessageBox(m_hWnd, _T("ADD"), _T("cashier"), IDOK);
}
else if (strName == _T("Button_ADDGOODS")) {
Button_ADDGOODS();
}
}
}
数据库操作类封装
class Mysql{
public:
Mysql();
bool Connection(const char*host, //连接函数
const char* user,
const char*passwd,
const char*db_name,
unsigned int port
);
bool Add(const string& cmd); //增加
bool Delete(const string& cmd); //删除
bool Update(const string& cmd); //修改
bool Enquiry(const string& str); //查询某一个表中的数据,并打印出来
bool Insert(const string& cmd);
//选择表将表中的数据赋值给_table
vector<vector<string>> SelectDB(const string& db_name);
~Mysql();
private:
MYSQL *_mysql; //mysql 实体连接所返回的一个对象
vector<string> _tables; //一个表,表中的信息被存储在这个二维字符串中
};
完整代码:https://github.com/LTXER/imageservr/tree/master/Cashier