void CHomeViewDlg::OnClickedBtGuke()
{
// TODO: 在此添加控件通知处理程序代码
CUserLoginDlg dlg;//注册窗框口类对象
User user;
user.m_UserType = _T("顾客");
dlg.SetUser(user);
dlg.DoModal();//进入注册窗口窗口
}
void CHomeViewDlg::OnClickedBtShangjia()
{
// TODO: 在此添加控件通知处理程序代码
CUserLoginDlg dlg; //注册窗框口类对象
User user;
user.m_UserType = _T("商家");
dlg.SetUser(user);
dlg.DoModal();//进入注册窗口窗口
}
//注意: CUserLoginDlg dlg为局部对象,上述函数执行完则对象释放。
BOOL CUserLoginDlg::SetUser(User user)
{
m_CurrentUser.m_UserType= user.m_UserType;
return TRUE;
}
//新用户注册按钮响应函数
void CUserLoginDlg::OnClickedRegister()
{
// TODO: 在此添加控件通知处理程序代码
CRegisterDlg dlg;//注册界面
if (dlg.DoModal() == IDOK)
{
m_CurrentUser.m_Pwd = dlg.m_zcPwd;
m_CurrentUser.m_TelNum = dlg.m_zcTel;
for (UINT i = 0; i < m_User.GetSize(); i++)
{
if (m_User[i].m_UserType == m_CurrentUser.m_UserType&&m_CurrentUser.m_UserType != _T(""))
{
if (m_User[i].m_TelNum == m_CurrentUser.m_TelNum)
{
MessageBox(_T("该号码已注册!"));
return;
}
}
}
m_User.Add(m_CurrentUser);//注册用户存储在数组m_User中
//用户数据序列化存储在文件中
CString count;
count.Format(_T("%d"),m_User.GetSize());
CFile o;
if (o.Open(_T("userdata.txt"), CFile::modeWrite))
{
o.SeekToEnd();
CArchive ar(&o, CArchive::store);
CString save = _T("");
CString s = _T(",");
CString l = _T("\r\n");
save += count+s+m_CurrentUser.m_TelNum +s+ m_CurrentUser.m_Pwd +s+ m_CurrentUser.m_UserType+l;
ar <<save;
ar.Close();
o.Close();
}
MessageBox(_T("注册成功!"));
}
}
//登录按钮响应函数
void CUserLoginDlg::OnClickedLogin()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(TRUE);
//用于将输入编辑框的数据更新到编辑框绑定的变量中,即更新m_logTel和m_LogPwd的值
//保存当前注册用户
m_CurrentUser.m_TelNum = m_logTel;
m_CurrentUser.m_Pwd = m_LogPwd;
if (m_CurrentUser.m_TelNum == _T(""))
{
MessageBox(_T("请输入密码账号密码!"));
return;
}
UINT i = 0;
for (i; i < m_User.GetSize(); i++)
{
if (m_User[i].m_TelNum == m_logTel&&m_User[i].m_Pwd == m_LogPwd)
{
//账号密码匹配,进入主页界面
CMainGUIDlg dlg;
dlg.SetUser(m_CurrentUser);
dlg.DoModal();
break;
}
else if (m_User[i].m_TelNum == m_logTel&&m_User[i].m_Pwd != m_LogPwd)
{
MessageBox(_T("密码错误!"));
return;
}
}
if(i== m_User.GetSize())
MessageBox(_T("请先注册!"));
}
BOOL CUserLoginDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: 在此添加额外的初始化
CFile o;
if (o.Open(_T("userdata.txt"), CFile::modeRead))
{
CArchive ar(&o, CArchive::load);
CString line=NULL;
do
{
ar.ReadString(line); //读出一行数据
line.TrimRight();
line.TrimLeft(); //去除左右空格
if (line == _T(""))
break;
//数据项拆分,构造数据对象
User u;
AfxExtractSubString(u.m_TelNum, line,1, ',');
AfxExtractSubString(u.m_Pwd, line,2, ',');
AfxExtractSubString(u.m_UserType, line,3, ',');
m_User.Add(u);
} while (TRUE);
ar.Close();
o.Close();
}
return TRUE;
}
BOOL CMainGUIDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: 在此添加额外的初始化
//设置标签页页头,根据用户类型动态设置
m_tablctrl.InsertItem(0, _T("首页"));
if (m_user.m_UserType== _T("商家"))
{
m_tablctrl.InsertItem(1, _T("我的店铺"));
m_tablctrl.InsertItem(2, _T("我的订单"));
}
else if (m_user.m_UserType == _T("顾客"))
{
m_tablctrl.InsertItem(1, _T("我的房间"));
m_tablctrl.InsertItem(2, _T("购物车"));
}
//标签控件位置设置
CRect si;
m_tablctrl.GetClientRect(&si);
CRect it;
m_tablctrl.GetItemRect(0, it);
si.top += it.top + 20;
si.left += 5;
si.bottom -= 5;
si.right -= 5;
m_FirstPage.Create(IDD_FIRST_PAGE, &m_tablctrl);
m_FirstPage.MoveWindow(&si);
if (m_user.m_UserType == _T("商家"))
{
//子对话框创建,根据对话框ID将标签对象和首页对话框绑定
m_Shop.Create(IDD_DIALOG_SHOP, &m_tablctrl);
m_Shop.SetShopId(m_user.m_TelNum);
//子对话框移动到正确位置
m_Shop.MoveWindow(&si);//
}
else if (m_user.m_UserType == _T("顾客"))
{
//子对话框创建,根据对话框ID将标签对象和首页对话框绑定
m_ShoppingCart.Create(IDD_SHOPPING_CART, &m_tablctrl);
m_ShoppingCart.MoveWindow(&si);
}
m_FirstPage.ShowWindow(SW_SHOW);
m_tablctrl.SetCurFocus(0);
return TRUE;
}
void CMainGUIDlg::OnSelchangeTabPage(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
switch (m_tablctrl.GetCurSel())//根据鼠标选择的焦点,动态设置标签页
{
case 0:
if (m_user.m_UserType == _T("商家"))
{
m_FirstPage.ShowWindow(SW_SHOW);
m_Shop.ShowWindow(SW_HIDE);
}
else if (m_user.m_UserType == _T("顾客"))
{
m_FirstPage.ShowWindow(SW_SHOW);
m_ShoppingCart.ShowWindow(SW_HIDE);
m_FirstPage.SetFocus();
}
break;
case 1:
if (m_user.m_UserType == _T("商家"))
{
m_FirstPage.ShowWindow(SW_HIDE);
m_Shop.ShowWindow(SW_SHOW);
m_Shop.SetFocus();
m_Shop.m_treectrl.Invalidate();
}
else if (m_user.m_UserType == _T("顾客"))
{
m_FirstPage.ShowWindow(SW_HIDE);
m_ShoppingCart.ShowWindow(SW_HIDE);
}
break;
case 2:
if (m_user.m_UserType == _T("商家"))
{
m_FirstPage.ShowWindow(SW_HIDE);
m_Shop.ShowWindow(SW_HIDE);
}
else if (m_user.m_UserType == _T("顾客"))
{
m_FirstPage.ShowWindow(SW_HIDE);
m_ShoppingCart.ShowWindow(SW_SHOW);
m_ShoppingCart.SetFocus();
}
break;
default:
break;
}
*pResult = 0;
}
BOOL CFirstPageDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: 在此添加额外的初始化
m_comboBox.AddString(_T("产品类别"));
m_ProductTypeArray.Add(_T("现代家具"));
m_ProductTypeArray.Add(_T("后现在家具"));
m_ProductTypeArray.Add(_T("欧式古典家具"));
m_ProductTypeArray.Add(_T("美式家具"));
m_ProductTypeArray.Add(_T("中式古典家具"));
m_ProductTypeArray.Add(_T("新古典家具"));
m_ProductTypeArray.Add(_T("新装饰家具"));
for (UINT i = 0; i < m_ProductTypeArray.GetSize(); i++)
{
m_comboBox.InsertString(i+1, m_ProductTypeArray[i]);
}
m_comboBox.SetCurSel(0);
return TRUE;
}
void CFirstPageDlg::OnSelchangeCombo()
{
// TODO: 在此添加控件通知处理程序代码
//设置选择的项目为选中状态
m_comboBox.SetCurSel(m_comboBox.GetCurSel());
}
//查找商品函数代码
void CFirstPageDlg::OnClickedBtFind()
{
// TODO: 在此添加控件通知处理程序代码
CString Type;
if (CB_ERR != m_comboBox.GetCurSel())//判段显示项目是否在组合框中
{
m_comboBox.GetLBText(pos, Type);//获取选中项目的文本
MessageBox(Type);
}
else
{
//若为输入的文本,则通过该方式获取输入的文本
m_comboBox.GetWindowText(Type);
MessageBox(Type);
}
}
BOOL CShopDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: 在此添加额外的初始化
HTREEITEM hRoot; // 根节点
HTREEITEM hgood;
HTREEITEM h;
hRoot = m_treectrl.InsertItem(_T("产品分类"), 0, 0);
hgood = m_treectrl.InsertItem(_T("现代家具"), 1, 1, hRoot, TVI_LAST);
h = m_treectrl.InsertItem(_T("床"), 1, 1, hgood, TVI_LAST);
h = m_treectrl.InsertItem(_T("床头柜"), 1, 1, hgood, TVI_LAST);
h = m_treectrl.InsertItem(_T("化妆台"), 1, 1, hgood, TVI_LAST);
h = m_treectrl.InsertItem(_T("妆凳"), 1, 1, hgood, TVI_LAST);
h = m_treectrl.InsertItem(_T("衣柜"), 1, 1, hgood, TVI_LAST);
h = m_treectrl.InsertItem(_T("床尾凳"), 1, 1, hgood, TVI_LAST);
h = m_treectrl.InsertItem(_T("穿衣镜"), 1, 1, hgood, TVI_LAST);
hgood = m_treectrl.InsertItem(_T("新装饰家具"), 1, 1, hRoot, TVI_LAST);
h = m_treectrl.InsertItem(_T("沙发"), 1, 1, hgood, TVI_LAST);
h = m_treectrl.InsertItem(_T("茶几"), 1, 1, hgood, TVI_LAST);
h = m_treectrl.InsertItem(_T("边几(角几)"), 1, 1, hgood, TVI_LAST);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CShopDlg::OnClickedBtAddProduct()
{
// TODO: 在此添加控件通知处理程序代码
CInsertProductDlg dlg;
CommodityInfo g;
if (dlg.DoModal() == IDOK)
{
UpdateData(TRUE);
g.m_Title = dlg.m_Title;
g.m_Id = dlg.m_Id;
g.m_Price = dlg.m_Price;
//g.m_MainPic = dlg.m_MainFigure;
g.m_Host = m_UserId;
if (dlg.m_Type_One != _T(""))
{
g.m_Type_One = dlg.m_Type_One;
}
if (dlg.m_Type_Two != _T(""))
{
g.m_Type_Two = dlg.m_Type_Two;
}
else
{
g.m_Type_One =_T("null");
g.m_Type_Two = _T("null");
}
m_shopCommodity.Add(g);
}
}
BOOL CShopDlg::SetShopId(CString id)
{
m_UserId = id;
return TRUE;
}
BOOL CShoppingCartDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: 在此添加额外的初始化
m_listctrl.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
LONG lStyle;
lStyle = GetWindowLong(m_listctrl.m_hWnd, GWL_STYLE);//获取当前窗口style
lStyle &= ~LVS_TYPEMASK; //清除显示方式位
lStyle |= LVS_REPORT; //设置style
SetWindowLong(m_listctrl.m_hWnd, GWL_STYLE, lStyle);//设置style
DWORD dwStyle = m_listctrl.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT; //选中某行使整行高亮(只适用与report风格的listctrl)
dwStyle |= LVS_EX_GRIDLINES; //网格线(只适用与report风格的listctrl)
dwStyle |= LVS_EX_CHECKBOXES; //item前生成checkbox控件
m_listctrl.SetExtendedStyle(dwStyle); //设置扩展风格
m_listctrl.InsertColumn(0, _T("商品名称"), LVCFMT_LEFT, 150, 40);
m_listctrl.InsertColumn(1, _T("价格"), LVCFMT_LEFT, 150, 40);
m_listctrl.InsertColumn(2, _T("参数"), LVCFMT_LEFT, 150, 40);
m_listctrl.InsertColumn(3, _T("参数"), LVCFMT_LEFT, 150, 40);
m_listctrl.InsertColumn(4, _T("参数"), LVCFMT_LEFT, 150, 40);
m_listctrl.InsertColumn(5, _T("参数"), LVCFMT_LEFT, 150, 40);
m_listctrl.InsertColumn(6, _T("参数"), LVCFMT_LEFT, 150, 40);
for (UINT i = 0; i < 20; i++)
{
m_listctrl.InsertItem(i,_T("null"));
for (UINT j = 0; j < 7; j++)
{
m_listctrl.SetItemText(i, j,_T("null"));
}
}
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CShoppingCartDlg::OnClickList(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
POSITION pos = m_listctrl.GetFirstSelectedItemPosition();
if (pos != NULL)
{
while (pos)
{
int nItem = m_listctrl.GetNextSelectedItem(pos);
}
}
*pResult = 0;
}
BOOL CInsertProductDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: 在此添加额外的初始化
m_ProductOneTypeArray.Add(_T("现代家具"));
m_ProductOneTypeArray.Add(_T("后现在家具"));
m_ProductOneTypeArray.Add(_T("欧式古典家具"));
m_ProductOneTypeArray.Add(_T("美式家具"));
m_ProductOneTypeArray.Add(_T("中式古典家具"));
m_ProductOneTypeArray.Add(_T("新古典家具"));
m_ProductOneTypeArray.Add(_T("新装饰家具"));
m_ProductTwoTypeArray.Add(_T("沙发"));
m_ProductTwoTypeArray.Add(_T("茶几"));
m_ProductTwoTypeArray.Add(_T("边几(角几)"));
m_ProductTwoTypeArray.Add(_T("床头柜"));
m_ProductTwoTypeArray.Add(_T("化妆台"));
m_ProductTwoTypeArray.Add(_T("妆凳"));
m_ProductTwoTypeArray.Add(_T("衣柜"));
m_ProductTwoTypeArray.Add(_T("床尾凳"));
m_ProductTwoTypeArray.Add(_T("穿衣镜"));
for (UINT i = 0; i < m_ProductOneTypeArray.GetSize(); i++)
{
m_combox_One.InsertString(i , m_ProductOneTypeArray[i]);
}
for (UINT i = 0; i < m_ProductTwoTypeArray.GetSize(); i++)
{
m_combox_Two.InsertString(i, m_ProductTwoTypeArray[i]);
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CInsertProductDlg::OnSelchangeComboCategoryOne()
{
// TODO: 在此添加控件通知处理程序代码
m_combox_One.SetCurSel(m_combox_One.GetCurSel());
CString Type= _T("");
if (CB_ERR == m_combox_One.GetCurSel())
{
MessageBox(_T("选择产品一级分类!"));
return;
}
else
{
int pos = m_combox_One.GetCurSel();
m_combox_One.GetLBText(pos, Type);
if (Type!=_T(""))
{
m_Type_One = Type;
}
}
}
void CInsertProductDlg::OnSelchangeComboCategoryTwo()
{
// TODO: 在此添加控件通知处理程序代码
m_combox_One.SetCurSel(m_combox_Two.GetCurSel());
CString Type = _T("");
if (CB_ERR == m_combox_Two.GetCurSel())
{
MessageBox(_T("选择产品一级分类!"));
return;
}
else
{
int pos = m_combox_Two.GetCurSel();
m_combox_Two.GetLBText(pos, Type);
if (Type != _T(""))
{
m_Type_Two = Type;
}
}
}