mrDarker
2025-09-01 d78ab86af696b7b762823db10ba0f126e697ae2d
SourceCode/Bond/Servo/PageRecipe.cpp
@@ -6,6 +6,7 @@
#include "afxdialogex.h"
#include "PageRecipe.h"
#include "MsgDlg.h"
#include "InputDialog.h"
#include "RecipeDeviceBindDlg.h"
// CPageRecipe 对话框
@@ -146,8 +147,18 @@
      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;
         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);
      }
@@ -167,6 +178,22 @@
      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) {
@@ -179,6 +206,13 @@
      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());
   }
   // 获取列数
@@ -416,15 +450,40 @@
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()
@@ -526,7 +585,7 @@
   int selectedCount = ListView_GetSelectedCount(m_listPPID.GetSafeHwnd());
   GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(nEqSel == 0 && selectedCount > 0);
   GetDlgItem(IDC_BUTTON_MODIFY)->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);
}
@@ -537,7 +596,7 @@
   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);