8 Sales Management Window
8.1 UI design
1) Add a dialog box resource (change the ID to DIALOG_SELL) and add the required controls.
In the window properties, change Border to None and Style to Child:
2) Select the dialog box -> right-click -> Add class -> Class name: CSellDlg, select CFormView as the base class
3) According to the requirements, the control associates the required variables
The product name combo box is associated with CComboBox m_combo, and the unit price edit box is associated with int m_price.
The quantity edit box is associated with int m_num, and the sales information edit box is associated with CString m_sellInfo.
8.2 Interface mounting
In the OnMyChange function in the CMainFrame class, add the following code:
case NM_B:
{
//CSellDlg class needs to include the header file #include “SellDlg.h”
Context.m_pNewViewClass = RUNTIME_CLASS(CSellDlg);
Context.m_pCurrentFrame = this;
Context.m_pLastView = (CFormView *)m_spliter.GetPane(0, 1);
m_spliter.DeleteView(0, 1);
m_spliter.CreateView(0, 1, RUNTIME_CLASS(CSellDlg), CSize(600, 0), & amp;Context);
CSellDlg *pNewView = (CSellDlg *)m_spliter.GetPane(0, 1);
m_spliter.RecalcLayout();
pNewView->OnInitialUpdate();
m_spliter.SetActivePane(0, 1);
}
break;
Program running effect diagram:
8.3 Function Implementation
1) In the dialog class, rewrite the OnInitDialog function to initialize it.
void CSellDlg::OnInitialUpdate() {<!-- --> CFormView::OnInitialUpdate(); // TODO: Add specialized code here and/or call the base class //Read the file, get the product name, and add a string to the combo box //Need to include #include "InfoFile.h" CInfoFile file; file.ReadDocline(); //Read product information for (list<msg>::iterator it = file.ls.begin(); it != file.ls.end(); it + + ) {<!-- --> m_combo.AddString((CString)it->name.c_str()); } file.ls.clear(); //Clear the contents of the list //Set the first product name as the default selected item m_combo.SetCurSel(0); }
2) Handle the control events required by the combo box
void CSellDlg::OnCbnSelchangeCombo1() {<!-- --> // TODO: Add control notification handler code here CString text; //Get the currently selected item int index = m_combo.GetCurSel(); //Get the current content m_combo.GetLBText(index, text); //Need to include #include "InfoFile.h" CInfoFile file; file.ReadDocline(); //Read product information for (list<msg>::iterator it = file.ls.begin(); it != file.ls.end(); it + + ) {<!-- --> if (text == it->name.c_str()) {<!-- --> m_price = it->price; m_num = 0; UpdateData(FALSE); //The content is updated to the corresponding control } } file.ls.clear(); //Clear the contents of the list }
3) Implementation of purchase button function
void CSellDlg::OnBnClickedButton1() {<!-- --> // TODO: Add control notification handler code here \t //Get the content on the control and update it to the corresponding associated variable UpdateData(TRUE); if (m_num == 0) {<!-- --> MessageBox(TEXT("The number cannot be 0")); return; } CString type; //Get the currently selected item int index = m_combo.GetCurSel(); //Get the current content of the combo box m_combo.GetLBText(index, type); CString str; str.Format(_T("Item: %s \r\\ Unit price: %d \r\\ Quantity: %d \r\\ Total price: %d"), type, m_price, m_num, m_price*m_num); m_sellInfo = str; //Sales information UpdateData(FALSE); MessageBox(str); //Need to include #include "InfoFile.h" CInfoFile file; file.ReadDocline(); //Read product information for (list<msg>::iterator it = file.ls.begin(); it != file.ls.end(); it + + ) {<!-- --> if (type == it->name.c_str()) {<!-- --> it->num = it->num - m_num; } } file.WirteDocline(); //Update file content file.ls.clear(); //Clear the contents of the list m_sellInfo.Empty(); m_num = 0; UpdateData(FALSE); //Update to the corresponding control }
4) Implementation of cancel button function
void CSellDlg::OnBnClickedButton3() {<!-- --> // TODO: Add control notification handler code here m_combo.SetCurSel(0); //Select the 0th item m_sellInfo = ""; m_num = 0; OnCbnSelchangeCombo1(); }
9 Inventory information window
9.1 UI design
1) Add a dialog box resource (change the ID to DIALOG_INFO) and add the required controls.
In the window properties, change Border to None and Style to Child:
The View property is Report (report table mode):
2) Select the dialog box -> right-click -> Add class -> Class name: CInfoDlg, select CFormView as the base class
3) According to the requirements, the control associates the required variables
List control associated CListCtrl m_list:
9.2 Interface mounting
In the OnMyChange function in the CMainFrame class, add the following code:
case NM_C: {<!-- --> //The CInfoDlg class needs to include the header file #include "InfoDlg.h" Context.m_pNewViewClass = RUNTIME_CLASS(CInfoDlg); Context.m_pCurrentFrame = this; Context.m_pLastView = (CFormView *)m_spliter.GetPane(0, 1); m_spliter.DeleteView(0, 1); m_spliter.CreateView(0, 1, RUNTIME_CLASS(CInfoDlg), CSize(600, 0), & amp;Context); CInfoDlg *pNewView = (CInfoDlg *)m_spliter.GetPane(0, 1); m_spliter.RecalcLayout(); pNewView->OnInitialUpdate(); m_spliter.SetActivePane(0, 1); } break;
Program running effect diagram:
9.3 Function Implementation
In the dialog class, rewrite the OnInitDialog function to initialize product information:
void CInfoDlg::OnInitialUpdate() {<!-- --> CFormView::OnInitialUpdate(); // TODO: Add specialized code here and/or call the base class //Set extension style //LVS_EX_FULLROWSELECT selects the entire row, LVS_EX_GRIDLINES grid m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); //Initialize header CString field[] = {<!-- --> _T("Product ID"), _T("Product name"), _T("Product price"), _T("Inventory quantity\ ") }; for (int i = 0; i < sizeof(field) / sizeof(field[0]); + + i) {<!-- --> m_list.InsertColumn(i, field[i], LVCFMT_CENTER, 90); } //Need to include #include "InfoFile.h" CInfoFile file; file.ReadDocline(); //Read product information \t//adding data int i = 0; CString str; for (list<msg>::iterator it = file.ls.begin(); it != file.ls.end(); it + + ) {<!-- --> str.Format(_T("%d"), it->id); m_list.InsertItem(i, str); int column = 1; m_list.SetItemText(i, column + + , (CString)it->name.c_str()); str.Format(_T("%d"), it->price); m_list.SetItemText(i, column + +, str); str.Format(_T("%d"), it->num); m_list.SetItemText(i, column + +, str); i + + ; } \t }
10 Inventory Add Window
10.1 UI design
1) Add a dialog box resource (change the ID to DIALOG_ADD) and add the required controls.
In the window properties, change Border to None and Style to Child:
2) Select the dialog box -> right-click -> Add class -> Class name: CAddDlg, select CFormView as the base class
3) According to the requirements, the control associates the required variables
Add number:
The product combo box is associated with CComboBox m_combo, and the unit price edit box is associated with int m_price1.
The number edit box is associated with int m_num1.
Add new product:
The product combo box is associated with CString m_name2, and the unit price edit box is associated with int m_price2.
The number edit box is associated with int m_num2.
10.2 Interface mounting
In the OnMyChange function in the CMainFrame class, add the following code:
10.3 function implementation
1) In the dialog class, rewrite the OnInitDialog function to initialize product information:
void CAddDlg::OnInitialUpdate() {<!-- --> CFormView::OnInitialUpdate(); // TODO: Add specialized code here and/or call the base class //Read the file, get the product name, and add a string to the combo box //Need to include #include "InfoFile.h" CInfoFile file; file.ReadDocline(); //Read product information for (list<msg>::iterator it = file.ls.begin(); it != file.ls.end(); it + + ) {<!-- --> m_combo.AddString((CString)it->name.c_str()); } file.ls.clear(); //Clear the contents of the list //Set the first product name as the default selected item m_combo.SetCurSel(0); }
2) Handle the control events required by the combo box
void CAddDlg::OnCbnSelchangeCombo2() {<!-- --> // TODO: Add control notification handler code here CString text; //Get the currently selected item int index = m_combo.GetCurSel(); //Get the current content m_combo.GetLBText(index, text); //Need to include #include "InfoFile.h" CInfoFile file; file.ReadDocline(); //Read product information for (list<msg>::iterator it = file.ls.begin(); it != file.ls.end(); it + + ) {<!-- --> if (text == it->name.c_str()) {<!-- --> m_price1 = it->price; m_num1 = 0; UpdateData(FALSE); //The content is updated to the corresponding control } } file.ls.clear(); //Clear the contents of the list }
3) Add number button implementation
void CAddDlg::OnBnClickedButton1() {<!-- --> // TODO: Add control notification handler code here //Get the content on the control and update it to the corresponding associated variable UpdateData(TRUE); if (m_num1 == 0) {<!-- --> MessageBox(TEXT("The number cannot be 0")); return; } CString type; //Get the currently selected item int index = m_combo.GetCurSel(); //Get the current content of the combo box m_combo.GetLBText(index, type); CString str; str.Format(_T("Added product: %s \r\\ Unit price: %d \r\\ Quantity: %d"), type, m_price1, m_num1); MessageBox(str); //Need to include #include "InfoFile.h" CInfoFile file; file.ReadDocline(); //Read product information for (list<msg>::iterator it = file.ls.begin(); it != file.ls.end(); it + + ) {<!-- --> if (type == it->name.c_str()) {<!-- --> it->num + = m_num1; } } file.WirteDocline(); //Update file content file.ls.clear(); //Clear the contents of the list m_num1 = 0; UpdateData(FALSE); //Update to the corresponding control }
4) Add a number of cancel buttons to implement
void CAddDlg::OnBnClickedButton2() {<!-- --> // TODO: Add control notification handler code here m_combo.SetCurSel(0); m_num1 = 0; OnCbnSelchangeCombo2(); }
5) Add new product button implementation
void CAddDlg::OnBnClickedButton4() {<!-- --> // TODO: Add control notification handler code here UpdateData(TRUE); //Get the control content if (m_num2 <= 0 || m_price2 <= 0 || m_name2.IsEmpty()) {<!-- --> MessageBox(TEXT("The input information is incorrect")); return; } //Need to include #include "InfoFile.h" CInfoFile file; file.ReadDocline(); //Read product information file.Addline(m_name2, m_num2, m_price2); //Add product file.WirteDocline(); //Write file file.ls.clear(); //Clear the contents of the list MessageBox(_T("Added successfully")); m_name2.Empty(); m_num2 = 0; m_price2 = 0; UpdateData(FALSE); }
6) Add new product cancellation button implementation
void CAddDlg::OnBnClickedButton5() {<!-- --> // TODO: Add control notification handler code here m_name2.Empty(); m_num2 = 0; m_price2 = 0; UpdateData(FALSE); }
11 Inventory deletion window
11.1 ui design
1) Add a dialog box resource (change the ID to DIALOG_DEL) and add the required controls.
In the window properties, change Border to None and Style to Child:
2) Select the dialog box -> right-click -> Add class -> Class name: CDelDlg, select CFormView as the base class
3) According to the requirements, the control associates the required variables
The product name combo box is associated with CComboBox m_combo, and the unit price edit box is associated with int m_price.
The number edit box is associated with int m_num.
11.2 Interface mounting
In the OnMyChange function in the CMainFrame class, add the following code:
case NM_E: {<!-- --> //The CDelDlg class needs to include the header file #include "DelDlg.h" Context.m_pNewViewClass = RUNTIME_CLASS(CDelDlg); Context.m_pCurrentFrame = this; Context.m_pLastView = (CFormView *)m_spliter.GetPane(0, 1); m_spliter.DeleteView(0, 1); m_spliter.CreateView(0, 1, RUNTIME_CLASS(CDelDlg), CSize(600, 0), & amp;Context); CDelDlg *pNewView = (CDelDlg *)m_spliter.GetPane(0, 1); m_spliter.RecalcLayout(); pNewView->OnInitialUpdate(); m_spliter.SetActivePane(0, 1); } break;
Program running effect diagram:
11.3 Function Implementation
1) In the dialog class, rewrite the OnInitDialog function to initialize it.
void CDelDlg::OnInitialUpdate() {<!-- --> CFormView::OnInitialUpdate(); //Read the file, get the product name, and add a string to the combo box //Need to include #include "InfoFile.h" CInfoFile file; file.ReadDocline(); //Read product information for (list<msg>::iterator it = file.ls.begin(); it != file.ls.end(); it + + ) {<!-- --> m_combo.AddString((CString)it->name.c_str()); } //Set the first product name as the default selected item m_combo.SetCurSel(0); }
2) Handle the control events required by the combo box
void CDelDlg::OnCbnSelchangeCombo1() {<!-- --> // TODO: Add control notification handler code here CString text; //Get the currently selected item int index = m_combo.GetCurSel(); //Get the current content m_combo.GetLBText(index, text); //Need to include #include "InfoFile.h" CInfoFile file; file.ReadDocline(); //Read product information for (list<msg>::iterator it = file.ls.begin(); it != file.ls.end(); it + + ) {<!-- --> if (text == it->name.c_str()) {<!-- --> m_price = it->price; m_num = 0; UpdateData(FALSE); //The content is updated to the corresponding control } } \t }
3) Confirm button function implementation
void CDelDlg::OnBnClickedButton1() {<!-- --> // TODO: Add control notification handler code here //Get the content on the control and update it to the corresponding associated variable UpdateData(TRUE); if (m_num == 0) {<!-- --> MessageBox(TEXT("The number cannot be 0")); return; } CString type; //Get the currently selected item int index = m_combo.GetCurSel(); //Get the current content of the combo box m_combo.GetLBText(index, type); CString str; str.Format(_T("Delete product: %s \r\\ Unit price: %d \r\\ Quantity: %d "), type, m_price, m_num); MessageBox(str); //Need to include #include "InfoFile.h" CInfoFile file; file.ReadDocline(); //Read product information for (list<msg>::iterator it = file.ls.begin(); it != file.ls.end(); it + + ) {<!-- --> if (type == it->name.c_str()) {<!-- --> it->num = it->num - m_num; } } file.WirteDocline(); //Update file content \t m_num = 0; UpdateData(FALSE); //Update to the corresponding control }
4) Implementation of cancel button function
void CDelDlg::OnBnClickedButton2() {<!-- --> // TODO: Add control notification handler code here m_combo.SetCurSel(0); //Select the 0th item m_num = 0; OnCbnSelchangeCombo1(); }
12 Menu bar
1) Switch to the Menu of the resource view and delete all defaults (except help):
2) Right-click the menu bar item, add an event handler, select the COMMAND message type, and add it to the CMainFrame framework class.
3) Send a custom signal in the event handling function, and other menu operations are similar.
//Personal information menu
void CMainFrame::On32772() {<!-- --> // TODO: add command handler code here ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), NM_A, (WPARAM)NM_A, (LPARAM)0); }