From bc7f1c4e028e69be51079b59dae4ae5c4d43f5bb Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期六, 31 一月 2026 21:54:56 +0800
Subject: [PATCH] 1.状态指示图,目前灰色表示掉线,绿色表示在线。增加Slot的小点表示有没有料,及加工状态 。 2.增加图示

---
 SourceCode/Bond/Servo/PageRecipe.cpp |  749 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 625 insertions(+), 124 deletions(-)

diff --git a/SourceCode/Bond/Servo/PageRecipe.cpp b/SourceCode/Bond/Servo/PageRecipe.cpp
index 468bc34..841a96f 100644
--- a/SourceCode/Bond/Servo/PageRecipe.cpp
+++ b/SourceCode/Bond/Servo/PageRecipe.cpp
@@ -5,6 +5,11 @@
 #include "Servo.h"
 #include "afxdialogex.h"
 #include "PageRecipe.h"
+#include "MsgDlg.h"
+#include "InputDialog.h"
+#include "RecipeDeviceBindDlg.h"
+#include "DeviceRecipeParamDlg.h"
+
 
 // CPageRecipe 瀵硅瘽妗�
 
@@ -20,9 +25,110 @@
 {
 }
 
+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_CENTER, 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, 100, 100, 150 };
+
+	for (int i = 0; i < 5; 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_LEFT, width[2]);
+	m_listPPID.InsertColumn(3, _T("Recipe 鍚嶇О"), LVCFMT_LEFT, width[3]);
+	m_listPPID.InsertColumn(4, _T("Recipe 鍙傛暟"), LVCFMT_LEFT, width[4]);
+}
+
+void CPageRecipe::UpdateRecipeByPPID(const CString& strPPID)
+{
+	if (strPPID.IsEmpty()) {
+		AfxMessageBox(_T("璇烽�夋嫨涓�涓厤鏂癸紒"));
+		return;
+	}
+
+	auto& mgr = RecipeManager::getInstance();
+
+	// 鏌ヨ閫変腑閰嶆柟鐨勮缁嗘暟鎹�
+	std::string oldPPID = CT2A(strPPID);
+	RecipeInfo oldRecipe = mgr.getRecipeByPPID(oldPPID);
+	if (oldRecipe.strPPID.empty()) {
+		AfxMessageBox(_T("鑾峰彇閰嶆柟鏁版嵁澶辫触锛�"));
+		return;
+	}
+
+	// 寮瑰嚭缂栬緫瀵硅瘽妗嗭紝骞跺垵濮嬪寲涓哄綋鍓嶅唴瀹�
+	CRecipeDeviceBindDlg dlg(this);
+	dlg.SetRecipeInfo(oldRecipe);
+
+	if (dlg.DoModal() == IDOK) {
+		const RecipeInfo& newRecipe = dlg.GetRecipeInfo();
+
+		bool success = false;
+		// 鍒ゆ柇PPID鏄惁鏈夋敼鍔�
+		if (oldRecipe.strPPID != newRecipe.strPPID) {
+			// 鍏堟洿鏂癙PID锛屽啀鏁翠綋鏇存柊鍐呭
+			if (mgr.updatePPID(oldRecipe.strPPID, newRecipe.strPPID)) {
+				success = mgr.updateRecipe(newRecipe);
+				if (!success) {
+					AfxMessageBox(_T("宸叉洿鏀筆PID锛屼絾鏇存柊閰嶆柟鍐呭澶辫触锛岃妫�鏌ユ棩蹇�"));
+				}
+			}
+			else {
+				AfxMessageBox(_T("鏇存柊PPID澶辫触锛岃妫�鏌ユ棩蹇�"));
+				return;
+			}
+		}
+		else {
+			// 鍙洿鏂板唴瀹�
+			success = mgr.updateRecipe(newRecipe);
+			if (!success) {
+				AfxMessageBox(_T("鏇存柊閰嶆柟澶辫触锛岃妫�鏌ユ棩蹇�"));
+			}
+		}
+
+		if (success) {
+			auto vecData = mgr.getAllRecipes();
+			FillDataToListCtrl(vecData);
+		}
+	}
+}
+
 void CPageRecipe::FillDataToListCtrl(const std::vector<RecipeInfo>& vecRecipe) {
 	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_PPID);
-	if (pListCtrl == nullptr || pListCtrl->m_hWnd == nullptr) {
+	if (pListCtrl == nullptr || !::IsWindow(pListCtrl->m_hWnd)) {
 		return;
 	}
 
@@ -32,16 +138,82 @@
 	// 閬嶅巻鏁版嵁骞舵彃鍏ュ埌CListCtrl涓�
 	for (int i = 0; i < static_cast<int>(vecRecipe.size()); ++i) {
 		const RecipeInfo& recipe = vecRecipe[i];
+		// 鍘熺▼搴忚姹侾PID鏈夊瓙閰嶆柟锛屽厛娉ㄩ噴
+		/*
+		if (recipe.vecDeviceList.empty() || recipe.vecDeviceList.size() > 6){
+			continue;
+		}
+		*/
 
 		m_listPPID.InsertItem(i, _T("")); // 绗�0鍒楃┖鐧�
 
 		CString strNo;
 		strNo.Format(_T("%d"), i + 1);
 		m_listPPID.SetItemText(i, 1, strNo);
-
 		m_listPPID.SetItemText(i, 2, CA2T(recipe.strPPID.c_str()));
-		m_listPPID.SetItemText(i, 3, CA2T(recipe.strDescription.c_str()));
-		m_listPPID.SetItemText(i, 4, CA2T(recipe.strCreateTime.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"), strRecipeName.c_str());
+			}
+	
+			m_listPPID.SetItemText(i, j + 3, str);
+		}
+
+		m_listPPID.SetItemText(i, 9, CA2T(recipe.strCreateTime.c_str()));
+		m_listPPID.SetItemText(i, 10, CA2T(recipe.strDescription.c_str()));
+	}
+
+	// 鑾峰彇鍒楁暟
+	int nColCount = m_listPPID.GetHeaderCtrl()->GetItemCount();
+	m_listPPID.SetColumnWidth(nColCount - 1, LVSCW_AUTOSIZE_USEHEADER);
+}
+
+void CPageRecipe::FillRecipeListToListCtrl(SERVO::CEquipment* pEq)
+{
+	SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0);
+	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_PPID);
+	if (pListCtrl == nullptr || !::IsWindow(pListCtrl->m_hWnd)) {
+		return;
+	}
+
+	// 娓呯┖褰撳墠CListCtrl涓殑鎵�鏈夐」
+	pListCtrl->DeleteAllItems();
+	if (pRecipeList == nullptr) {
+		return;
+	}
+
+	// 閬嶅巻鏁版嵁骞舵彃鍏ュ埌CListCtrl涓�
+	auto& mgr = RecipeManager::getInstance();
+	std::map<int, short>& ids = pRecipeList->getIds();
+	auto rawDatas = pRecipeList->getParamsRawData();
+	for (auto item : ids) {
+		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(SanitizeName(pEq->getName()), item.second);
+		m_listPPID.SetItemText(index, 3, strRecipeName.c_str());
+
+		std::string strDescription;
+		auto iter = rawDatas.find(item.second);
+		if (iter != rawDatas.end()) {
+			pEq->parsingParams((const char*)iter->second.data(), iter->second.size(), strDescription);
+			m_listPPID.SetItemText(index, 4, strDescription.c_str());
+		}
+
+		if (strRecipeName.empty()) {
+			strRecipeName = std::to_string(item.second);
+			mgr.addDeviceRecipe(SanitizeName(pEq->getName()), item.second, strRecipeName, strDescription);
+		}
 	}
 
 	// 鑾峰彇鍒楁暟
@@ -53,19 +225,22 @@
 {
 	CDialogEx::DoDataExchange(pDX);
 	DDX_Control(pDX, IDC_LIST_PPID, m_listPPID);
-	DDX_Control(pDX, IDC_EDIT_PPID, m_editPPID);
-	DDX_Control(pDX, IDC_EDIT_DESC, m_editDesc);
 }
 
 
 BEGIN_MESSAGE_MAP(CPageRecipe, CDialogEx)
 	ON_WM_SIZE()
+	ON_WM_DESTROY()
+	ON_WM_SHOWWINDOW()
+	ON_BN_CLICKED(IDC_BUTTON_NEW, &CPageRecipe::OnBnClickedButtonNew)
 	ON_BN_CLICKED(IDC_BUTTON_SEARCH, &CPageRecipe::OnBnClickedButtonSearch)
 	ON_BN_CLICKED(IDC_BUTTON_MODIFY, &CPageRecipe::OnBnClickedButtonModify)
 	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()
 
 
@@ -84,12 +259,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, 80);
-	pListCtrl->InsertColumn(2, _T("PPID"), LVCFMT_LEFT, 120);
-	pListCtrl->InsertColumn(3, _T("鎻忚堪"), LVCFMT_LEFT, 180);
-	pListCtrl->InsertColumn(4, _T("鍒涘缓鏃堕棿"), LVCFMT_LEFT, 160);
-	pListCtrl->SetColumnWidth(4, LVSCW_AUTOSIZE_USEHEADER);
+	InitListCtrlHeaderForMaster();
 
 	// 鑾峰彇鎵�鏈夋暟鎹�
 	auto vecData = RecipeManager::getInstance().getAllRecipes();
@@ -103,145 +273,241 @@
 {
 	CDialogEx::OnSize(nType, cx, cy);
 
-	if (m_listPPID.GetSafeHwnd()) {
-		// 宸︿晶鍒楄〃瀹介珮鑷�傚簲
-		int margin = 10;
-		int buttonWidth = 80;
-		int buttonHeight = 30;
-		int buttonSpacing = 10;
+	if (!m_listPPID.GetSafeHwnd())
+		return;
 
-		CRect rect;
-		GetClientRect(&rect);
 
-		int listWidth = rect.Width() - buttonWidth - 3 * margin;
-		int listHeight = rect.Height() - 2 * margin;
+	// 宸︿晶鍒楄〃瀹介珮鑷�傚簲
+	int margin = 12;
+	int buttonWidth = 80;
+	int buttonHeight = 30;
+	int buttonSpacing = 10;
 
-		m_listPPID.MoveWindow(margin, margin + 80, listWidth, listHeight - 80);
+	CWnd* pItem;
+	CRect rect, rcItem;
+	GetClientRect(&rect);
 
-		// 缂栬緫妗嗚皟鏁翠綅缃細鍙宠竟瀵归綈鍒楄〃锛屽乏杈瑰浐瀹氳捣濮�
-		int labelWidth = 60;
-		int rightEdge = rect.right - buttonWidth - 2 * margin;
+	pItem = GetDlgItem(IDC_EDIT_KEYWORD);
+	ASSERT(pItem);
+	pItem->GetWindowRect(rcItem);
+	ScreenToClient(&rcItem);
 
-		if (m_editPPID.GetSafeHwnd()) {
-			m_editPPID.MoveWindow(labelWidth, margin, rightEdge - labelWidth, 25);
+	int y = rcItem.bottom;
+	y += 12;
+	int listWidth = rect.Width() - buttonWidth - 3 * margin;
+	m_listPPID.MoveWindow(margin, y, listWidth, rect.bottom - 12 - y);
+
+
+	// 鎸夐挳绔栫洿鎺掑垪鍦ㄥ彸渚�
+	CWnd* buttons[] = {
+		GetDlgItem(IDC_BUTTON_REFRESH),
+		GetDlgItem(IDC_BUTTON_NEW),
+		GetDlgItem(IDC_BUTTON_MODIFY),
+		GetDlgItem(IDC_BUTTON_DELETE),
+		GetDlgItem(IDC_BUTTON_DELETE_ALL)
+	};
+
+	for (auto pBtn : buttons) {
+		if (pBtn && pBtn->GetSafeHwnd()) {
+			pBtn->MoveWindow(rect.right - buttonWidth - margin, y, buttonWidth, buttonHeight);
+			y += buttonHeight + buttonSpacing;
 		}
-		if (m_editDesc.GetSafeHwnd()) {
-			m_editDesc.MoveWindow(labelWidth, margin + 35, rightEdge - labelWidth, 25);
+	}
+}
+
+void CPageRecipe::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"), (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;
+		if (!pHeader->GetItemRect(i, &rect)) { 
+			continue;
 		}
 
-		// 鎸夐挳绔栫洿鎺掑垪鍦ㄥ彸渚�
-		CWnd* buttons[] = {
-			GetDlgItem(IDC_BUTTON_SEARCH),
-			GetDlgItem(IDC_BUTTON_MODIFY),
-			GetDlgItem(IDC_BUTTON_DELETE),
-			GetDlgItem(IDC_BUTTON_DELETE_ALL),
-			GetDlgItem(IDC_BUTTON_REFRESH)
-		};
+		if (pEq == nullptr) {
+			strItem.Format(_T("Col_%d_Width"), i);
+		}
+		else {
+			strItem.Format(_T("Col_Device_%d_Width"), i);
+		}
 
-		int y = margin;
-		for (auto pBtn : buttons) {
-			if (pBtn && pBtn->GetSafeHwnd()) {
-				pBtn->MoveWindow(rect.right - buttonWidth - margin, y, buttonWidth, buttonHeight);
-				y += buttonHeight + buttonSpacing;
+		strTemp.Format(_T("%d"), rect.right - rect.left);
+		WritePrivateProfileString(_T("PageRecipeListCtrl"), strItem, strTemp, strIniFile);
+	}
+
+	CDialogEx::OnDestroy();
+}
+
+void CPageRecipe::OnShowWindow(BOOL bShow, UINT nStatus)
+{
+	CDialogEx::OnShowWindow(bShow, nStatus);
+
+	if (bShow) {
+		CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
+		if (pComboBox->GetCount() == 0) {
+			SERVO::CMaster& master = theApp.m_model.getMaster();
+			SERVO::CEquipment* pEq[] = {
+				nullptr,
+				master.getEquipment(EQ_ID_EFEM),
+				master.getEquipment(EQ_ID_Bonder1),
+				master.getEquipment(EQ_ID_Bonder2),
+				master.getEquipment(EQ_ID_BAKE_COOLING),
+				master.getEquipment(EQ_ID_VACUUMBAKE),
+				master.getEquipment(EQ_ID_MEASUREMENT),
+			};
+
+			CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
+			for (int i = 0; i < sizeof(pEq) / sizeof(pEq[0]); i++) {
+				pComboBox->InsertString(i,
+					pEq[i] == nullptr ? _T("Master") : pEq[i]->getName().c_str());
+				pComboBox->SetItemDataPtr(i, pEq[i]);
+
+				// 璇诲彇鍥炴潵
+				char szBuffer[_MAX_PATH];
+				if (pEq[i]) {
+					sprintf_s(szBuffer, _MAX_PATH, "%s\\Recipe\\EQ%d_Unit0.recipelist", (LPTSTR)(LPCTSTR)theApp.m_strAppDir, pEq[i]->getID());
+					std::string strFilepath(szBuffer);
+					pEq[i]->readRecipeList(0, strFilepath);
+				}
+			}
+			pComboBox->SetCurSel(0);
+		}
+	}
+}
+
+void CPageRecipe::OnBnClickedButtonNew()
+{
+	int rc = UX_CanExecute(L"recipe");
+	if (rc != 1) {
+		AfxMessageBox("鎿嶄綔鏉冮檺涓嶈冻锛岃鑱旂郴绠$悊浜哄憳锛�");
+		return;
+	}
+	UX_RecordAction(L"recipe");
+
+	CRecipeDeviceBindDlg dlg(this);
+	if (dlg.DoModal() == IDOK) {
+		const RecipeInfo& newRecipe = dlg.GetRecipeInfo();
+
+		auto& mgr = RecipeManager::getInstance();
+		if (mgr.ppidExists(newRecipe.strPPID)) {
+			// 宸插瓨鍦紝璇㈤棶鏄惁瑕嗙洊
+			int ret = AfxMessageBox(_T("璇� PPID 宸插瓨鍦紝鏄惁瑕嗙洊鍘熼厤鏂癸紵"), MB_YESNO | MB_ICONQUESTION);
+			if (ret == IDYES) {
+				if (mgr.updateRecipe(newRecipe)) {
+					auto vecData = mgr.getAllRecipes();
+					FillDataToListCtrl(vecData);
+				}
+				else {
+					AfxMessageBox(_T("鏇存柊閰嶆柟澶辫触锛岃妫�鏌ユ棩蹇�"));
+				}
 			}
 		}
-
-		// 鍒楀閲嶈
-		int col0 = 50;  // No.
-		int col1 = 120; // PPID
-		int col3 = 160; // 鍒涘缓鏃堕棿鑷姩濉厖
-		int col2 = listWidth - col0 - col1 - col3 - 2;  // 鎻忚堪鑷姩濉厖
-		if (col2 < 80) { 
-			col2 = 80;
+		else {
+			// 涓嶅瓨鍦紝鐩存帴鏂板
+			if (mgr.addRecipe(newRecipe)) {
+				auto vecData = mgr.getAllRecipes();
+				FillDataToListCtrl(vecData);
+			}
+			else {
+				AfxMessageBox(_T("娣诲姞閰嶆柟澶辫触锛岃妫�鏌ユ棩蹇�"));
+			}
 		}
-
-		m_listPPID.SetColumnWidth(1, col0);
-		m_listPPID.SetColumnWidth(2, col1);
-		m_listPPID.SetColumnWidth(3, col2);
-		m_listPPID.SetColumnWidth(4, col3);
 	}
 }
 
 void CPageRecipe::OnBnClickedButtonSearch()
 {
-	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
-	CString strInput;
-	m_editPPID.GetWindowText(strInput);
+	CString strKeyword;
+	GetDlgItemText(IDC_EDIT_KEYWORD, strKeyword);
+	strKeyword.Trim();
 
-	int nCount = m_listPPID.GetItemCount();
-	for (int i = 0; i < nCount; ++i) {
-		CString strItemText = m_listPPID.GetItemText(i, 2); // 绗�2鍒椾负PPID
-		if (strItemText == strInput) {
-			m_listPPID.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
-			m_listPPID.EnsureVisible(i, FALSE);
-			break;
-		}
+	std::vector<RecipeInfo> vecData;
+	if (strKeyword.IsEmpty()) {
+		// 鍏抽敭璇嶄负绌猴紝鏄剧ず鍏ㄩ儴閰嶆柟
+		vecData = RecipeManager::getInstance().getAllRecipes();
 	}
+	else {
+		// 鏍规嵁鍏抽敭璇嶆悳绱㈤厤鏂�
+		vecData = RecipeManager::getInstance().getRecipesByKeyword(std::string(CT2A(strKeyword)));
+	}
+
+	// 濡傛灉娌℃湁鏁版嵁锛屽脊鍑烘彁绀�
+	if (vecData.empty()) {
+		AfxMessageBox(_T("鏈壘鍒板尮閰嶇殑閰嶆柟锛�"));
+		return;
+	}
+
+	FillDataToListCtrl(vecData);
 }
 
 void CPageRecipe::OnBnClickedButtonModify()
 {
+	int rc = UX_CanExecute(L"recipe");
+	if (rc != 1) {
+		AfxMessageBox("鎿嶄綔鏉冮檺涓嶈冻锛岃鑱旂郴绠$悊浜哄憳锛�");
+		return;
+	}
+	UX_RecordAction(L"recipe");
+
 	// 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("璇烽�夋嫨瑕佷慨鏀圭殑閰嶆柟"));
+		AfxMessageBox(_T("璇峰厛閫夋嫨涓�鏉¢厤鏂硅褰曡繘琛屼慨鏀癸紒"));
 		return;
 	}
 
-	int nSel = m_listPPID.GetNextSelectedItem(pos);
-	CString strOldPPID = m_listPPID.GetItemText(nSel, 2);
-	CString strOldDesc = m_listPPID.GetItemText(nSel, 3);
+	int nLine = m_listPPID.GetNextSelectedItem(pos);
+	CString strID = m_listPPID.GetItemText(nLine, 2);
 
-	CString strNewPPID, strNewDesc;
-	m_editPPID.GetWindowText(strNewPPID);
-	m_editDesc.GetWindowText(strNewDesc);
-
-	// 鍒ょ┖
-	if (strOldPPID.IsEmpty() || strNewPPID.IsEmpty()) {
-		AfxMessageBox(_T("PPID 涓嶈兘涓虹┖"));
-		return;
+	int nSel = pComboBox->GetCurSel();
+	SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nSel);
+	if (pEq == nullptr) {
+		UpdateRecipeByPPID(strID);
 	}
-
-	std::string oldPPID = CT2A(strOldPPID);
-	std::string newPPID = CT2A(strNewPPID);
-	std::string newDesc = CT2A(strNewDesc);
-
-	bool bPPIDChanged = (strOldPPID.Compare(strNewPPID) != 0);
-	bool bDescChanged = (strOldDesc.Compare(strNewDesc) != 0);
-
-	if (!bPPIDChanged && !bDescChanged) {
-		return;
-	}
-
-	if (bPPIDChanged) {
-		// 鏂� PPID 涓嶅彲閲嶅
-		if (RecipeManager::getInstance().ppidExists(newPPID)) {
-			AfxMessageBox(_T("鏂� PPID 宸插瓨鍦紝璇蜂娇鐢ㄥ叾浠栧��"));
+	else {
+		CInputDialog dlg(_T("淇敼閰嶆柟鍚嶇О"), _T("璇疯緭鍏ラ厤鏂瑰悕绉帮細"));
+		if (dlg.DoModal() != IDOK) {
 			return;
 		}
 
-		// 璋冪敤 updatePPID锛屽悓鏃舵洿鏂版弿杩�
-		if (RecipeManager::getInstance().updatePPID(oldPPID, newPPID)) {
-			m_listPPID.SetItemText(nSel, 2, strNewPPID);
+		CString strText = dlg.GetInputText();
+		if (strText.IsEmpty()) {
+			AfxMessageBox(_T("閰嶆柟鍚嶇О涓嶈兘涓虹┖锛�"));
+			return;
 		}
-		else {
-			AfxMessageBox(_T("鏇存柊澶辫触锛岃妫�鏌ユ棩蹇�"));
-		}
-	}
 
-	if (bDescChanged) {
-		// 鏇存柊鎻忚堪
-		if (RecipeManager::getInstance().updateDescription(oldPPID, newDesc)) {
-			m_listPPID.SetItemText(nSel, 3, strNewDesc);
-		}
-		else {
-			AfxMessageBox(_T("鎻忚堪鏇存柊澶辫触"));
+		if (RecipeManager::getInstance().updateDeviceRecipeName(SanitizeName(pEq->getName()), _ttoi(strID), std::string(CT2A(strText)))) {
+			m_listPPID.SetItemText(nLine, 3, strText);
 		}
 	}
 }
 
 void CPageRecipe::OnBnClickedButtonDelete()
 {
+	int rc = UX_CanExecute(L"recipe");
+	if (rc != 1) {
+		AfxMessageBox("鎿嶄綔鏉冮檺涓嶈冻锛岃鑱旂郴绠$悊浜哄憳锛�");
+		return;
+	}
+	UX_RecordAction(L"recipe");
+
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
 	POSITION pos = m_listPPID.GetFirstSelectedItemPosition();
 	if (!pos) { 
@@ -268,6 +534,13 @@
 
 void CPageRecipe::OnBnClickedButtonDeleteAll()
 {
+	int rc = UX_CanExecute(L"recipe");
+	if (rc != 1) {
+		AfxMessageBox("鎿嶄綔鏉冮檺涓嶈冻锛岃鑱旂郴绠$悊浜哄憳锛�");
+		return;
+	}
+	UX_RecordAction(L"recipe");
+
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
 	if (IDYES != AfxMessageBox(_T("纭畾瑕佸垹闄ゅ叏閮ㄩ厤鏂硅褰曞悧锛�"), MB_YESNO | MB_ICONWARNING)) {
 		return;
@@ -289,24 +562,252 @@
 
 void CPageRecipe::OnBnClickedButtonRefresh()
 {
-	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
-	auto vecData = RecipeManager::getInstance().getAllRecipes();
-	FillDataToListCtrl(vecData);
+	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
+	int nSel = pComboBox->GetCurSel();
+	SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nSel);
+
+	if (pEq == nullptr) {
+		// 鑾峰彇master閰嶆柟(鏈湴)
+		auto vecData = RecipeManager::getInstance().getAllRecipes();
+		FillDataToListCtrl(vecData);
+	}
+	else {
+		// 鑾峰彇閰嶆柟鍒楄〃
+		CMsgDlg msgDlg("璇风瓑寰�", "姝e湪鑾峰彇閰嶆柟鍒楄〃...");
+		msgDlg.SetData((DWORD_PTR)this);
+		msgDlg.SetDataEx((DWORD_PTR)pEq);
+		msgDlg.BeginThread(SyncThreadFunction);
+		msgDlg.DoModal();
+	}
 }
 
-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: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
 	*pResult = 0;
 
-	if ((pNMLV->uChanged & LVIF_STATE) &&
-		(pNMLV->uNewState & LVIS_SELECTED)) {
-
-		int nItem = pNMLV->iItem;
-		CString strPPID = m_listPPID.GetItemText(nItem, 2);
-		m_editPPID.SetWindowText(strPPID);
-
-		CString strDesc = m_listPPID.GetItemText(nItem, 3);
-		m_editDesc.SetWindowText(strDesc);
+	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
+	if (pComboBox == nullptr) {
+		return;
 	}
+
+	int nItem = pNMItemActivate->iItem;
+	int nEqSel = pComboBox->GetCurSel();
+
+	GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(nEqSel == 0);
+	GetDlgItem(IDC_BUTTON_MODIFY)->EnableWindow(nItem != -1);
+	GetDlgItem(IDC_BUTTON_DELETE)->EnableWindow(nEqSel == 0 && nItem != -1);
+	GetDlgItem(IDC_BUTTON_DELETE_ALL)->EnableWindow(nEqSel == 0 && nItem != -1);
+}
+
+void CPageRecipe::OnDblclkListPPID(NMHDR* pNMHDR, LRESULT* pResult)
+{
+	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	*pResult = 0;
+
+	int nItem = pNMItemActivate->iItem;
+	if (nItem < 0) {
+		return;
+	}
+
+	CString strRecipeID = m_listPPID.GetItemText(nItem, 2);
+	CString strRecipeName = m_listPPID.GetItemText(nItem, 3);
+	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
+	int nEqSel = pComboBox->GetCurSel();
+	if (nEqSel == CB_ERR) {
+		return;
+	}
+
+	int nRecipeID = _ttoi(strRecipeID);
+	SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nEqSel);
+	if (pEq == nullptr) {
+		return;
+	}
+
+	CDeviceRecipeParamDlg dlg(this);
+	dlg.setDeviceRecipeID(nRecipeID);
+	dlg.setDeviceRecipeName(strRecipeName);
+	dlg.setEquipment(pEq);
+	dlg.DoModal();
+}
+
+void CPageRecipe::OnCbnSelchangeComboEquipment()
+{
+	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
+	int nEqSel = pComboBox->GetCurSel();
+	int nItem = ListView_GetSelectedCount(m_listPPID.GetSafeHwnd());
+
+	GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(nEqSel == 0);
+	GetDlgItem(IDC_BUTTON_MODIFY)->EnableWindow(nEqSel == 0 && nItem != -1);
+	GetDlgItem(IDC_BUTTON_DELETE)->EnableWindow(nEqSel == 0 && nItem != -1);
+	GetDlgItem(IDC_BUTTON_DELETE_ALL)->EnableWindow(nEqSel == 0 && nItem != -1);
+	GetDlgItem(IDC_EDIT_KEYWORD)->EnableWindow(nEqSel == 0);
+	GetDlgItem(IDC_BUTTON_SEARCH)->EnableWindow(nEqSel == 0);
+
+	SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nEqSel);
+	if (pEq == nullptr) {
+		InitListCtrlHeaderForMaster();
+		auto vecData = RecipeManager::getInstance().getAllRecipes();
+		FillDataToListCtrl(vecData);
+	}
+	else {
+		InitListCtrlHeaderForDevice();
+		FillRecipeListToListCtrl(pEq);
+	}
+}
+
+UINT CPageRecipe::SyncThreadFunction(LPVOID lpvData)
+{
+	CMsgDlg* pMsgDlg = (CMsgDlg*)lpvData;
+	CPageRecipe* pPageRecipe = (CPageRecipe*)pMsgDlg->GetData();
+	return pPageRecipe->SyncThreadFunctionInner(pMsgDlg);
+}
+
+UINT CPageRecipe::SyncThreadFunctionInner(CMsgDlg* pMsgDlg)
+{
+	SERVO::CEquipment* pEq = (SERVO::CEquipment*)pMsgDlg->GetDataEx();
+	HANDLE hEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
+	int nStep = 0;
+
+	// 鍑嗗閰嶆柟璺緞
+	char szBuffer[_MAX_PATH];
+	sprintf_s(szBuffer, _MAX_PATH, "%s\\Recipe\\EQ%d_Unit0.recipelist", (LPTSTR)(LPCTSTR)theApp.m_strAppDir, pEq->getID());
+	std::string strFilepath(szBuffer);
+
+	pEq->masterRecipeListRequest(0, [&, pEq, pMsgDlg, hEvent](int status) -> void {
+		Sleep(300);
+		if (status == SS_FAILED || status == SS_TIMEOUT) {
+			CString strMsg;
+			strMsg.Format(status == SS_FAILED ? _T("鑾峰彇閰嶆柟鍒楄〃澶辫触锛�") : _T("鑾峰彇閰嶆柟鍒楄〃瓒呮椂锛�"));
+			pMsgDlg->SetIcon(MSG_BOX_ERROR);
+			pMsgDlg->SetTitle(_T("鎿嶄綔澶辫触"));
+			pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg);
+			SetEvent(hEvent);
+		}
+		else if (status == SS_LIST_COMPLETE) {
+			CString strMsg;
+			strMsg.Format(_T("鑾峰彇閰嶆柟鍒楄〃瀹屾垚锛�"));
+			pMsgDlg->SetTitle(_T("鎿嶄綔鎴愬姛"));
+			pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg);
+			SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0);
+			if (pRecipeList != nullptr && !pRecipeList->getIds().empty()) {
+				nStep = 1;
+			}
+			SetEvent(hEvent);
+		}
+	});
+	::WaitForSingleObject(hEvent, INFINITE);
+	if (nStep != 1) {
+		pEq->saveRecipeList(0, strFilepath);
+		pMsgDlg->SetIcon(MSG_BOX_SUCCEED);
+		pMsgDlg->SetMarquee(FALSE, 0);
+		pMsgDlg->SetCompleteCode(-1);
+		pMsgDlg->DelayClose(3000);
+	}
+	ResetEvent(hEvent);
+
+
+	// 鍙傛暟鍒楄〃
+	if (nStep == 1) {
+		SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0);
+		ASSERT(pRecipeList);
+		auto& ids = pRecipeList->getIds();
+		pMsgDlg->SetTitle(_T("姝e湪鑾峰彇鍙傛暟"));
+		for (auto item : ids) {
+			int recipeId = item.second;
+			CString strMsg;
+			strMsg.Format(_T("姝e湪鑾峰彇閰嶆柟 %d 鍙傛暟..."), item.second);
+			pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg);
+			pEq->recipeParameterRequest(0, recipeId, 0, [&, pEq, pMsgDlg, recipeId, hEvent](int status) -> void {
+				Sleep(500);
+				if (status == SS_FAILED || status == SS_TIMEOUT) {
+					CString strMsg;
+					strMsg.Format(status == SS_FAILED ? _T("鑾峰彇閰嶆柟 %d 鍙傛暟澶辫触锛�") : _T("鑾峰彇閰嶆柟 %d 鍙傛暟瓒呮椂锛�"), recipeId);
+					pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg);
+
+					Sleep(30);
+					SetEvent(hEvent);
+				}
+				else if (status == SS_PARAMS_COMPLETE) {
+					CString strMsg;
+					strMsg.Format(_T("鑾峰彇閰嶆柟 %d 鍙傛暟瀹屾垚锛�"), item.second);
+					pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg);
+
+					Sleep(30);
+					SetEvent(hEvent);
+				}
+				});
+			::WaitForSingleObject(hEvent, INFINITE);
+			ResetEvent(hEvent);
+		}
+		
+
+		pEq->saveRecipeList(0, strFilepath);
+		pMsgDlg->SetIcon(MSG_BOX_SUCCEED);
+		pMsgDlg->SetTitle(_T("鎿嶄綔瀹屾垚"));
+		pMsgDlg->SetCompleteCode(0);
+		pMsgDlg->SetMarquee(FALSE, 0);
+		pMsgDlg->DelayClose(3000);
+	};
+
+	FillRecipeListToListCtrl(pEq);
+	CloseHandle(hEvent);
+
+
+	// 鍦ㄦ鎵撳嵃閰嶆柟鍙傛暟浠ヤ究鏍稿鏁版嵁
+	SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0);
+	ASSERT(pRecipeList);
+	auto rawDatas = pRecipeList->getParamsRawData();
+	for (auto item : rawDatas) {
+		TRACE("================= 閰嶆柟 %d\n", item.first);
+
+		std::vector<CParam> params;
+		pEq->parsingParams((const char*)item.second.data(), item.second.size(), params);
+		for (auto p : params) {
+			if (p.getValueType() == PVT_INT) {
+				TRACE("%s: %d\n", p.getName().c_str(), p.getIntValue());
+			}
+			else if (p.getValueType() == PVT_DOUBLE) {
+				TRACE("%s: %f\n", p.getName().c_str(), p.getDoubleValue());
+			}
+		}
+
+	}
+
+	return 0;
+}
+
+std::string CPageRecipe::SanitizeName(const std::string& name)
+{
+	std::string result;
+	result.reserve(name.size());
+
+	for (char c : name) {
+		if (c == '(' || c == '锛�') {
+			break;
+		}
+
+		unsigned char uc = static_cast<unsigned char>(c);
+		if (std::isalnum(uc) || c == '_') {
+			result.push_back(c);
+		}
+		else if (std::isspace(uc)) {
+			continue;
+		}
+		else {
+			result.push_back('_');
+		}
+	}
+	return result;
+}
+
+BOOL CPageRecipe::PreTranslateMessage(MSG* pMsg)
+{
+	if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE) {
+		return TRUE;
+	}
+
+	return CDialogEx::PreTranslateMessage(pMsg);
 }
\ No newline at end of file

--
Gitblit v1.9.3