MFC基于对话框的商场交易软件实现
生活随笔
收集整理的這篇文章主要介紹了
MFC基于对话框的商场交易软件实现
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?
? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
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為局部對象,上述函數(shù)執(zhí)行完則對象釋放。? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
BOOL CUserLoginDlg::SetUser(User user) {m_CurrentUser.m_UserType= user.m_UserType;return TRUE; } //新用戶注冊按鈕響應函數(shù) 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);//注冊用戶存儲在數(shù)組m_User中//用戶數(shù)據(jù)序列化存儲在文件中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("注冊成功!"));} }//登錄按鈕響應函數(shù) void CUserLoginDlg::OnClickedLogin() {// TODO: 在此添加控件通知處理程序代碼UpdateData(TRUE); //用于將輸入編輯框的數(shù)據(jù)更新到編輯框綁定的變量中,即更新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); //讀出一行數(shù)據(jù)line.TrimRight();line.TrimLeft(); //去除左右空格if (line == _T(""))break;//數(shù)據(jù)項拆分,構(gòu)造數(shù)據(jù)對象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: 在此添加額外的初始化//設(shè)置標簽頁頁頭,根據(jù)用戶類型動態(tài)設(shè)置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("購物車"));}//標簽控件位置設(shè)置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("商家")){ //子對話框創(chuàng)建,根據(jù)對話框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("顧客")){ //子對話框創(chuàng)建,根據(jù)對話框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())//根據(jù)鼠標選擇的焦點,動態(tài)設(shè)置標簽頁{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("產(chǎn)品類別"));m_ProductTypeArray.Add(_T("現(xiàn)代家具"));m_ProductTypeArray.Add(_T("后現(xiàn)在家具"));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: 在此添加控件通知處理程序代碼 //設(shè)置選擇的項目為選中狀態(tài)m_comboBox.SetCurSel(m_comboBox.GetCurSel()); }//查找商品函數(shù)代碼 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; // 根節(jié)點HTREEITEM hgood;HTREEITEM h;hRoot = m_treectrl.InsertItem(_T("產(chǎn)品分類"), 0, 0);hgood = m_treectrl.InsertItem(_T("現(xiàn)代家具"), 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("沙發(fā)"), 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);//獲取當前窗口stylelStyle &= ~LVS_TYPEMASK; //清除顯示方式位lStyle |= LVS_REPORT; //設(shè)置styleSetWindowLong(m_listctrl.m_hWnd, GWL_STYLE, lStyle);//設(shè)置styleDWORD dwStyle = m_listctrl.GetExtendedStyle();dwStyle |= LVS_EX_FULLROWSELECT; //選中某行使整行高亮(只適用與report風格的listctrl)dwStyle |= LVS_EX_GRIDLINES; //網(wǎng)格線(只適用與report風格的listctrl)dwStyle |= LVS_EX_CHECKBOXES; //item前生成checkbox控件m_listctrl.SetExtendedStyle(dwStyle); //設(shè)置擴展風格m_listctrl.InsertColumn(0, _T("商品名稱"), LVCFMT_LEFT, 150, 40);m_listctrl.InsertColumn(1, _T("價格"), LVCFMT_LEFT, 150, 40);m_listctrl.InsertColumn(2, _T("參數(shù)"), LVCFMT_LEFT, 150, 40);m_listctrl.InsertColumn(3, _T("參數(shù)"), LVCFMT_LEFT, 150, 40);m_listctrl.InsertColumn(4, _T("參數(shù)"), LVCFMT_LEFT, 150, 40);m_listctrl.InsertColumn(5, _T("參數(shù)"), LVCFMT_LEFT, 150, 40);m_listctrl.InsertColumn(6, _T("參數(shù)"), 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("現(xiàn)代家具"));m_ProductOneTypeArray.Add(_T("后現(xiàn)在家具"));m_ProductOneTypeArray.Add(_T("歐式古典家具"));m_ProductOneTypeArray.Add(_T("美式家具"));m_ProductOneTypeArray.Add(_T("中式古典家具"));m_ProductOneTypeArray.Add(_T("新古典家具"));m_ProductOneTypeArray.Add(_T("新裝飾家具"));m_ProductTwoTypeArray.Add(_T("沙發(fā)"));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("選擇產(chǎn)品一級分類!"));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("選擇產(chǎn)品一級分類!"));return;}else{int pos = m_combox_Two.GetCurSel();m_combox_Two.GetLBText(pos, Type);if (Type != _T("")){m_Type_Two = Type;}}} 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的MFC基于对话框的商场交易软件实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux的常用操作——压缩和解压缩
- 下一篇: linux基础知识——进程相关概念