From d78ab86af696b7b762823db10ba0f126e697ae2d Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期一, 01 九月 2025 17:30:44 +0800
Subject: [PATCH] 1. 添加手动输入配方名称

---
 SourceCode/Bond/Servo/PageRecipe.cpp |   71 ++++++++++++++++++++++++++++++++---
 1 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/SourceCode/Bond/Servo/PageRecipe.cpp b/SourceCode/Bond/Servo/PageRecipe.cpp
index 9d9d83c..ab54bcf 100644
--- a/SourceCode/Bond/Servo/PageRecipe.cpp
+++ b/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;
-			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);
 		}
 
@@ -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: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	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);

--
Gitblit v1.9.3