| | |
| | | #include "afxdialogex.h" |
| | | #include "PageRecipe.h" |
| | | #include "MsgDlg.h" |
| | | #include "InputDialog.h" |
| | | #include "RecipeDeviceBindDlg.h" |
| | | |
| | | // CPageRecipe 对话框 |
| | |
| | | m_listPPID.SetItemText(i, 2, CA2T(recipe.strPPID.c_str())); |
| | | |
| | | for (int j = 0; j < recipe.vecDeviceList.size(); j++){ |
| | | int nRecipeID = recipe.vecDeviceList.at(j).nRecipeID; |
| | | std::string strDeviceName = recipe.vecDeviceList.at(j).strDeviceName; |
| | | std::string strRecipeName = RecipeManager::getInstance().getDeviceRecipeName(strDeviceName, nRecipeID); |
| | | |
| | | CString str; |
| | | str.Format(_T("%d"), recipe.vecDeviceList.at(j).nRecipeID); |
| | | if (strRecipeName.empty()) { |
| | | str.Format(_T("%d"), recipe.vecDeviceList.at(j).nRecipeID); |
| | | } |
| | | else { |
| | | str.Format(_T("%s"), CA2T(strRecipeName.c_str())); |
| | | } |
| | | |
| | | m_listPPID.SetItemText(i, j + 3, str); |
| | | } |
| | | |
| | |
| | | return; |
| | | } |
| | | |
| | | CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT); |
| | | if (pComboBox == nullptr || !::IsWindow(pComboBox->m_hWnd)) { |
| | | return; |
| | | } |
| | | |
| | | int nEqSel = pComboBox->GetCurSel(); |
| | | if (nEqSel == CB_ERR) { |
| | | return; |
| | | } |
| | | |
| | | auto& mgr = RecipeManager::getInstance(); |
| | | SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nEqSel); |
| | | if (pEq == nullptr) { |
| | | return; |
| | | } |
| | | |
| | | // 清空当前CListCtrl中的所有项 |
| | | pListCtrl->DeleteAllItems(); |
| | | if (pList == nullptr) { |
| | |
| | | int index = m_listPPID.InsertItem(m_listPPID.GetItemCount(), _T("")); |
| | | m_listPPID.SetItemText(index, 1, std::to_string(item.first).c_str()); |
| | | m_listPPID.SetItemText(index, 2, std::to_string(item.second).c_str()); |
| | | |
| | | std::string strRecipeName = mgr.getDeviceRecipeName(pEq->getName(), item.second); |
| | | if (strRecipeName.empty()) { |
| | | strRecipeName = std::to_string(item.second); |
| | | mgr.addDeviceRecipe(pEq->getName(), item.second, strRecipeName); |
| | | } |
| | | m_listPPID.SetItemText(index, 3, strRecipeName.c_str()); |
| | | } |
| | | |
| | | // 获取列数 |
| | |
| | | ON_BN_CLICKED(IDC_BUTTON_DELETE, &CPageRecipe::OnBnClickedButtonDelete) |
| | | ON_BN_CLICKED(IDC_BUTTON_DELETE_ALL, &CPageRecipe::OnBnClickedButtonDeleteAll) |
| | | ON_BN_CLICKED(IDC_BUTTON_REFRESH, &CPageRecipe::OnBnClickedButtonRefresh) |
| | | ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_PPID, &CPageRecipe::OnLvnItemChangedListPPID) |
| | | ON_NOTIFY(NM_CLICK, IDC_LIST_PPID, &CPageRecipe::OnClickListPPID) |
| | | ON_NOTIFY(NM_DBLCLK, IDC_LIST_PPID, &CPageRecipe::OnDblclkListPPID) |
| | | ON_CBN_SELCHANGE(IDC_COMBO_EQUIPMENT, &CPageRecipe::OnCbnSelchangeComboEquipment) |
| | | END_MESSAGE_MAP() |
| | | |
| | |
| | | void CPageRecipe::OnBnClickedButtonModify() |
| | | { |
| | | // TODO: 在此添加控件通知处理程序代码 |
| | | CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT); |
| | | if (pComboBox == nullptr || !::IsWindow(pComboBox->m_hWnd)) { |
| | | return; |
| | | } |
| | | |
| | | POSITION pos = m_listPPID.GetFirstSelectedItemPosition(); |
| | | if (!pos) { |
| | | AfxMessageBox(_T("请先选择一条配方记录进行修改!")); |
| | | return; |
| | | } |
| | | |
| | | int nSel = m_listPPID.GetNextSelectedItem(pos); |
| | | CString strPPID = m_listPPID.GetItemText(nSel, 2); |
| | | UpdateRecipeByPPID(strPPID); |
| | | int nLine = m_listPPID.GetNextSelectedItem(pos); |
| | | CString strID = m_listPPID.GetItemText(nLine, 2); |
| | | |
| | | int nSel = pComboBox->GetCurSel(); |
| | | SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nSel); |
| | | if (pEq == nullptr) { |
| | | UpdateRecipeByPPID(strID); |
| | | } |
| | | else { |
| | | CInputDialog dlg(_T("修改配方名称"), _T("请输入配方名称:")); |
| | | if (dlg.DoModal() != IDOK) { |
| | | return; |
| | | } |
| | | |
| | | CString strText = dlg.GetInputText(); |
| | | if (strText.IsEmpty()) { |
| | | AfxMessageBox(_T("配方名称不能为空!")); |
| | | return; |
| | | } |
| | | if (RecipeManager::getInstance().updateDeviceRecipe(pEq->getName(), _ttoi(strID), std::string(CT2A(strText)))) { |
| | | m_listPPID.SetItemText(nLine, 3, strText); |
| | | } |
| | | } |
| | | } |
| | | |
| | | void CPageRecipe::OnBnClickedButtonDelete() |
| | |
| | | } |
| | | } |
| | | |
| | | void CPageRecipe::OnLvnItemChangedListPPID(NMHDR* pNMHDR, LRESULT* pResult) |
| | | void CPageRecipe::OnClickListPPID(NMHDR* pNMHDR, LRESULT* pResult) |
| | | { |
| | | LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR); |
| | | LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR); |
| | | // TODO: 在此添加控件通知处理程序代码 |
| | | *pResult = 0; |
| | | |
| | | CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT); |
| | | int nEqSel = pComboBox->GetCurSel(); |
| | | int selectedCount = ListView_GetSelectedCount(m_listPPID.GetSafeHwnd()); |
| | | if (pComboBox == nullptr) { |
| | | return; |
| | | } |
| | | |
| | | GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(nEqSel == 0 && selectedCount > 0); |
| | | GetDlgItem(IDC_BUTTON_MODIFY)->EnableWindow(nEqSel == 0 && selectedCount > 0); |
| | | GetDlgItem(IDC_BUTTON_DELETE)->EnableWindow(nEqSel == 0 && selectedCount > 0); |
| | | GetDlgItem(IDC_BUTTON_DELETE_ALL)->EnableWindow(nEqSel == 0 && selectedCount > 0); |
| | | int nItem = pNMItemActivate->iItem; |
| | | int nEqSel = pComboBox->GetCurSel(); |
| | | |
| | | GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(nEqSel == 0); |
| | | GetDlgItem(IDC_BUTTON_MODIFY)->EnableWindow(nItem > 0); |
| | | GetDlgItem(IDC_BUTTON_DELETE)->EnableWindow(nEqSel == 0 && nItem > 0); |
| | | GetDlgItem(IDC_BUTTON_DELETE_ALL)->EnableWindow(nEqSel == 0 && nItem > 0); |
| | | } |
| | | |
| | | void CPageRecipe::OnDblclkListPPID(NMHDR* pNMHDR, LRESULT* pResult) |
| | | { |
| | | LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR); |
| | | // TODO: 在此添加控件通知处理程序代码 |
| | | *pResult = 0; |
| | | |
| | | int nItem = pNMItemActivate->iItem; |
| | | if (nItem < 0) { |
| | | return; |
| | | } |
| | | |
| | | CString strText = m_listPPID.GetItemText(nItem, 2); |
| | | CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT); |
| | | int nEqSel = pComboBox->GetCurSel(); |
| | | if (nEqSel == CB_ERR) { |
| | | return; |
| | | } |
| | | |
| | | SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nEqSel); |
| | | if (pEq == nullptr) { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | void CPageRecipe::OnCbnSelchangeComboEquipment() |
| | |
| | | int nEqSel = pComboBox->GetCurSel(); |
| | | int selectedCount = ListView_GetSelectedCount(m_listPPID.GetSafeHwnd()); |
| | | |
| | | GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(nEqSel == 0 && selectedCount > 0); |
| | | GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(nEqSel == 0/* && selectedCount > 0*/); |
| | | GetDlgItem(IDC_BUTTON_MODIFY)->EnableWindow(nEqSel == 0 && selectedCount > 0); |
| | | GetDlgItem(IDC_BUTTON_DELETE)->EnableWindow(nEqSel == 0 && selectedCount > 0); |
| | | GetDlgItem(IDC_BUTTON_DELETE_ALL)->EnableWindow(nEqSel == 0 && selectedCount > 0); |
| | |
| | | SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0); |
| | | FillRecipeListToListCtrl(pRecipeList); |
| | | } |
| | | } |
| | | } |