From 9370dd2497683084f8c0ae958f8be5dec34bd2f1 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期一, 01 九月 2025 21:53:51 +0800
Subject: [PATCH] 1. JobDataS多了一次Last Glass Flag

---
 SourceCode/Bond/Servo/PageRecipe.cpp |  173 +++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 142 insertions(+), 31 deletions(-)

diff --git a/SourceCode/Bond/Servo/PageRecipe.cpp b/SourceCode/Bond/Servo/PageRecipe.cpp
index a625647..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 瀵硅瘽妗�
@@ -20,6 +21,52 @@
 
 CPageRecipe::~CPageRecipe()
 {
+}
+
+void CPageRecipe::InitListCtrlHeaderForMaster()
+{
+	m_listPPID.DeleteAllItems();
+	while (m_listPPID.DeleteColumn(0));
+
+	CString strIniFile, strItem;
+	strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+	int width[12] = { 0, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 180 };
+	for (int i = 0; i < 12; i++) {
+		strItem.Format(_T("Col_%d_Width"), i);
+		width[i] = GetPrivateProfileInt("PageRecipeListCtrl", strItem, width[i], strIniFile);
+	}
+
+	m_listPPID.InsertColumn(0, _T(""), LVCFMT_RIGHT, 0); // 闅愯棌鍒�
+	m_listPPID.InsertColumn(1, _T("No."), LVCFMT_LEFT, width[1]);
+	m_listPPID.InsertColumn(2, _T("PPID"), LVCFMT_LEFT, width[2]);
+	m_listPPID.InsertColumn(3, _T("鐪熺┖鐑樼儰"), LVCFMT_LEFT, width[6]);
+	m_listPPID.InsertColumn(4, _T("Bonder1"), LVCFMT_LEFT, width[4]);
+	m_listPPID.InsertColumn(5, _T("Bonder2"), LVCFMT_LEFT, width[5]);
+	m_listPPID.InsertColumn(6, _T("鍚庣儤鍐峰嵈"), LVCFMT_LEFT, width[7]);
+	m_listPPID.InsertColumn(7, _T("绮惧害妫�鏌�"), LVCFMT_LEFT, width[8]);
+	m_listPPID.InsertColumn(8, _T("EFEM"), LVCFMT_LEFT, width[3]);
+	m_listPPID.InsertColumn(9, _T("鍒涘缓鏃堕棿"), LVCFMT_LEFT, width[9]);
+	m_listPPID.InsertColumn(10, _T("鎻忚堪"), LVCFMT_LEFT, width[10]);
+}
+
+void CPageRecipe::InitListCtrlHeaderForDevice()
+{
+	m_listPPID.DeleteAllItems();
+	while (m_listPPID.DeleteColumn(0));
+
+	CString strIniFile, strItem;
+	strIniFile.Format(_T("%s\\configuration.ini"), (LPCTSTR)theApp.m_strAppDir);
+	int width[] = { 0, 60, 150, 150 };
+
+	for (int i = 0; i < 4; i++) {
+		strItem.Format(_T("Col_Device_%d_Width"), i);
+		width[i] = GetPrivateProfileInt(_T("PageRecipeListCtrl"), strItem, width[i], strIniFile);
+	}
+
+	m_listPPID.InsertColumn(0, _T(""), LVCFMT_RIGHT, width[0]);
+	m_listPPID.InsertColumn(1, _T("No."), LVCFMT_CENTER, width[1]);
+	m_listPPID.InsertColumn(2, _T("Recipe ID"), LVCFMT_CENTER, width[2]);
+	m_listPPID.InsertColumn(3, _T("Recipe 鍚嶇О"), LVCFMT_CENTER, width[3]);
 }
 
 void CPageRecipe::UpdateRecipeByPPID(const CString& strPPID)
@@ -100,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);
 		}
 
@@ -121,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) {
@@ -133,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());
 	}
 
 	// 鑾峰彇鍒楁暟
@@ -168,15 +248,6 @@
 {
 	CDialogEx::OnInitDialog();
 
-	// 璇诲嚭鍒楀
-	CString strIniFile, strItem;
-	strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
-	int width[12] = { 0, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 180 };
-	for (int i = 0; i < 12; i++) {
-		strItem.Format(_T("Col_%d_Width"), i);
-		width[i] = GetPrivateProfileInt("PageRecipeListCtrl", strItem, width[i], strIniFile);
-	}
-
 	// TODO:  鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
 	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_PPID);
 	DWORD dwStyle = pListCtrl->GetExtendedStyle();
@@ -186,18 +257,7 @@
 
 	HIMAGELIST imageList = ImageList_Create(24, 24, ILC_COLOR24, 1, 1);
 	ListView_SetImageList(pListCtrl->GetSafeHwnd(), imageList, LVSIL_SMALL);
-	pListCtrl->InsertColumn(0, _T(""), LVCFMT_RIGHT, 0); // 闅愯棌鍒�
-	pListCtrl->InsertColumn(1, _T("No."), LVCFMT_LEFT, width[1]);
-	pListCtrl->InsertColumn(2, _T("PPID/Recipe ID"), LVCFMT_LEFT, width[2]);
-	pListCtrl->InsertColumn(3, _T("鐪熺┖鐑樼儰"), LVCFMT_LEFT, width[6]);
-	pListCtrl->InsertColumn(4, _T("Bonder1"), LVCFMT_LEFT, width[4]);
-	pListCtrl->InsertColumn(5, _T("Bonder2"), LVCFMT_LEFT, width[5]);
-	pListCtrl->InsertColumn(6, _T("鍚庣儤鍐峰嵈"), LVCFMT_LEFT, width[7]);
-	pListCtrl->InsertColumn(7, _T("绮惧害妫�鏌�"), LVCFMT_LEFT, width[8]);
-	pListCtrl->InsertColumn(8, _T("EFEM"), LVCFMT_LEFT, width[3]);
-	pListCtrl->InsertColumn(9, _T("鍒涘缓鏃堕棿"), LVCFMT_LEFT, width[9]);
-	pListCtrl->InsertColumn(10, _T("鎻忚堪"), LVCFMT_LEFT, width[10]);
-	pListCtrl->SetColumnWidth(10, LVSCW_AUTOSIZE_USEHEADER);
+	InitListCtrlHeaderForMaster();
 
 	// 鑾峰彇鎵�鏈夋暟鎹�
 	auto vecData = RecipeManager::getInstance().getAllRecipes();
@@ -255,19 +315,37 @@
 
 void CPageRecipe::OnDestroy()
 {
-	CDialogEx::OnDestroy();
+	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
+	int nSel = pComboBox->GetCurSel();
+	SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nSel);
 
 	// 淇濆瓨鍒楀
 	CString strIniFile, strItem, strTemp;
-	strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+	strIniFile.Format(_T("%s\\configuration.ini"), (LPCTSTR)theApp.m_strAppDir);
 	CHeaderCtrl* pHeader = m_listPPID.GetHeaderCtrl();
+
+	if (!pHeader || pHeader->GetItemCount() == 0) {
+		return;
+	}
+
 	for (int i = 0; i < pHeader->GetItemCount(); i++) {
 		RECT rect;
-		pHeader->GetItemRect(i, &rect);
-		strItem.Format(_T("Col_%d_Width"), i);
+		if (!pHeader->GetItemRect(i, &rect)) { 
+			continue;
+		}
+
+		if (pEq == nullptr) {
+			strItem.Format(_T("Col_%d_Width"), i);
+		}
+		else {
+			strItem.Format(_T("Col_Device_%d_Width"), i);
+		}
+
 		strTemp.Format(_T("%d"), rect.right - rect.left);
-		WritePrivateProfileString("PageRecipeListCtrl", strItem, strTemp, strIniFile);
+		WritePrivateProfileString(_T("PageRecipeListCtrl"), strItem, strTemp, strIniFile);
 	}
+
+	CDialogEx::OnDestroy();
 }
 
 void CPageRecipe::OnShowWindow(BOOL bShow, UINT nStatus)
@@ -293,6 +371,10 @@
 				pComboBox->InsertString(i,
 					pEq[i] == nullptr ? _T("Master") : pEq[i]->getName().c_str());
 				pComboBox->SetItemDataPtr(i, pEq[i]);
+
+				if (pEq[i]) {
+					pEq[i]->masterRecipeListRequest(0, nullptr);
+				}
 			}
 			pComboBox->SetCurSel(0);
 		}
@@ -368,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()
@@ -477,7 +584,8 @@
 	int nEqSel = pComboBox->GetCurSel();
 	int selectedCount = ListView_GetSelectedCount(m_listPPID.GetSafeHwnd());
 
-	GetDlgItem(IDC_BUTTON_MODIFY)->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);
 }
@@ -488,6 +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_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);
@@ -496,10 +605,12 @@
 
 	SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nEqSel);
 	if (pEq == nullptr) {
+		InitListCtrlHeaderForMaster();
 		auto vecData = RecipeManager::getInstance().getAllRecipes();
 		FillDataToListCtrl(vecData);
 	}
 	else {
+		InitListCtrlHeaderForDevice();
 		SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0);
 		FillRecipeListToListCtrl(pRecipeList);
 	}

--
Gitblit v1.9.3