/* * 说明: * 删除台号信息 * 参数: * hwnd [in] 主窗口句柄 * 返回值 * 成功返回true */ bool DeleteTable(HWND hwnd) { CListView table_list(hwnd, IDC_L_TABLE_INFO); int select = table_list.GetSelectionMark(); if (-1 == select) { MessageBox(hwnd, TEXT("请在左侧列表款选择要删除的房间编号!"), TEXT("基础信息管理"), MB_ICONINFORMATION); return false; } std::string floor, room, table_no; CComboBox combo(hwnd, IDC_TABLE_FLOOR_COMBO); combo.GetComboBoxText(floor); // 获取楼层名 room = table_list.GetItem(select, 0); // 获取房间名 table_no = table_list.GetItem(select, 1); // 获取台号 CTableInfo table; table.DeleteTable(floor.c_str(), room.c_str(), table_no.c_str()); CComboBox combox; //清空显示 combox.Initialization(hwnd,IDC_C_FLOOR_NAME); combox.DeleteAllString(); combox.Initialization(hwnd,IDC_C_ROOM_NAME); combox.DeleteAllString(); CEdit edit; edit.Initialization(hwnd,IDC_E_TABLE_NO); edit.Empty(); edit.Initialization(hwnd,IDC_E_TABLE_NUM); edit.Empty(); InitTableList(hwnd, IDC_L_TABLE_INFO, floor.c_str(), 0); // 更新 return true; }
bool AddTable(HWND hwnd) { std::string floor, room, table_no, sum_str; CComboBox floor_combox(hwnd, IDC_C_FLOOR_NAME); CComboBox room_combox(hwnd, IDC_C_ROOM_NAME); floor_combox.GetComboBoxText(floor); room_combox.GetComboBoxText(room); CEdit edit; edit.Initialization(hwnd, IDC_E_TABLE_NO); edit.GetEditText(table_no); edit.Initialization(hwnd, IDC_E_TABLE_NUM); edit.GetEditText(sum_str); CTableInfo table; table.AddTable(floor.c_str(), room.c_str(), table_no.c_str(), atoi(sum_str.c_str())); //显示添加的台号信息 CComboBox left_combox_floor(hwnd,IDC_TABLE_FLOOR_COMBO); left_combox_floor.SetCurSel(left_combox_floor.FindString(floor.c_str())); InitTableList(hwnd, IDC_L_TABLE_INFO, floor.c_str(), 0); // 更新 return true; }
/* * @ brief: 台号信息处理函数 * @ param: hwnd [in] 窗口句柄 * @ param: msg [in] 消息类型 **/ BOOL CALLBACK ChildTableInfoProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_INITDIALOG: { CListView table_list(hwnd, IDC_L_TABLE_INFO); table_list.SetSelectAndGrid(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); table_list.InsertColumn(1,80,"房间名称"); table_list.InsertColumn(2,100,"台 号"); table_list.InsertColumn(2,60,"人 数"); try { InitFloorName(hwnd, IDC_TABLE_FLOOR_COMBO);//初始化左边第一个“楼层”下拉列表 InitFloorName(hwnd, IDC_C_FLOOR_NAME);//初始化游标第二个“楼层”下拉列表 CComboBox floor_combo(hwnd, IDC_TABLE_FLOOR_COMBO); std::string floor_name; floor_combo.GetComboBoxText(floor_name); InitTableList(hwnd, IDC_L_TABLE_INFO, floor_name.c_str(), 0); InitRoomCombo(hwnd,floor_name.c_str(),IDC_C_ROOM_NAME);//根据楼层名,初始化房间下拉列表 } catch (Err &err) { MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR); return FALSE; } return TRUE; } case WM_NOTIFY: { switch(LOWORD(wParam)) { case IDC_L_TABLE_INFO: { if (((LPNMHDR)lParam)->code == NM_CLICK){ // 点击列表中的一项 int index = -1; CEdit num, no; CComboBox room_name, floor_name; CListView table_list; table_list.Initialization(hwnd, IDC_L_TABLE_INFO); index = table_list.GetSelectionMark(); if (-1 == index) { MessageBox(hwnd, TEXT("请先在左侧选择一个台号!"), TEXT("基础信息管理"), MB_ICONINFORMATION); break; } room_name.Initialization(hwnd, IDC_C_ROOM_NAME); no.Initialization(hwnd, IDC_E_TABLE_NO); num.Initialization(hwnd, IDC_E_TABLE_NUM); CComboBox combo(hwnd, IDC_TABLE_FLOOR_COMBO); std::string name; combo.GetComboBoxText(name); floor_name.Initialization(hwnd, IDC_C_FLOOR_NAME); floor_name.DeleteAllString(); InitFloorName(hwnd,IDC_C_FLOOR_NAME); floor_name.SetCurSel(floor_name.FindString(name.c_str())); InitRoomCombo(hwnd,name.c_str(),IDC_C_ROOM_NAME); room_name.SetCurSel(room_name.FindString(table_list.GetItem(index, 0).c_str())); no.SetEditText(table_list.GetItem(index, 1).c_str()); num.SetEditText(table_list.GetItem(index, 2).c_str()); } break; } } return TRUE; } case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_B_ADD_TABLE: { try { if(AddTable(hwnd)) { MessageBox(hwnd, TEXT("添加台号信息成功"), TEXT("基础信息管理 "), MB_ICONINFORMATION); } } catch (Err &err) { MessageBox(hwnd, err.what(), TEXT("基础信息管理 "), MB_ICONERROR); return FALSE; } break; } case IDC_B_DISHPATCH_TABLE: { try { if (UpdateTable(hwnd)) { MessageBox(hwnd, TEXT("修改台号信息成功"), TEXT("基础信息管理"), MB_OK); } } catch (Err &err) { MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR); } break; } case IDC_B_DELETE_TABLE: { try { if (DeleteTable(hwnd)) { MessageBox(hwnd, TEXT("删除台号信息成功"), TEXT("基础信息管理"), MB_OK); } } catch (Err &err) { MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR); } break; } case IDC_TABLE_FLOOR_COMBO://点击左边第一个”楼层“下拉列表 { if (HIWORD(wParam) == CBN_SELCHANGE) { try { CComboBox combo(hwnd, IDC_TABLE_FLOOR_COMBO); std::string floor_name; combo.GetComboBoxText(floor_name); CComboBox room(hwnd, IDC_C_ROOM_NAME); room.DeleteAllString();//清空“房间”下拉列表,然后在插入新的数据 InitTableList(hwnd, IDC_L_TABLE_INFO, floor_name.c_str(), 0); } catch (Err &err) { MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR); return FALSE; } CEdit edit; // 清空右侧编辑框数据 edit.Initialization(hwnd, IDC_E_TABLE_NO); edit.Empty(); edit.Initialization(hwnd, IDC_E_TABLE_NUM); edit.Empty(); } break; } case IDC_C_FLOOR_NAME://点击第二个“楼层”下拉列表 { if (HIWORD(wParam) == CBN_SELCHANGE) { try { CComboBox combo(hwnd, IDC_C_FLOOR_NAME); std::string floor_name_str; combo.GetComboBoxText(floor_name_str); CComboBox room_name(hwnd, IDC_C_ROOM_NAME); RoomInfo room_info; room_info.GetRoomName(floor_name_str.c_str()); // 获取楼层下的房间名称记录集 room_name.DeleteAllString(); while (!room_info.IsEOF()) { room_name.AddString(room_info.room_name()); } } catch (Err &err) { MessageBox(hwnd, err.what(), TEXT("基础信息管理"), MB_ICONERROR); return FALSE; } } break; } case IDC_B_TABLE_CANCLE: { EndDialog(hwnd,0); break; } } return TRUE; } case WM_CLOSE: { EndDialog(hwnd,0); return TRUE; } } return FALSE; }