From adf46e4da2f53d171cc5a0e95340d751ebacf763 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期四, 26 六月 2025 14:25:31 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang

---
 SourceCode/Bond/Servo/PageRecipe.cpp |  369 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 308 insertions(+), 61 deletions(-)

diff --git a/SourceCode/Bond/Servo/PageRecipe.cpp b/SourceCode/Bond/Servo/PageRecipe.cpp
index 85f369a..74ce16c 100644
--- a/SourceCode/Bond/Servo/PageRecipe.cpp
+++ b/SourceCode/Bond/Servo/PageRecipe.cpp
@@ -5,7 +5,7 @@
 #include "Servo.h"
 #include "afxdialogex.h"
 #include "PageRecipe.h"
-#include "SECSRuntimeManager.h"
+#include "MsgDlg.h"
 
 
 // CPageRecipe 瀵硅瘽妗�
@@ -22,9 +22,9 @@
 {
 }
 
-void CPageRecipe::FillDataToListCtrl(const std::vector<std::string>& 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,44 +32,70 @@
 	pListCtrl->DeleteAllItems();
 
 	// 閬嶅巻鏁版嵁骞舵彃鍏ュ埌CListCtrl涓�
-	for (int i = 0; i < static_cast<int>(vecData.size()); ++i) {
-		// 鎻掑叆琛�
-		pListCtrl->InsertItem(i, _T(""));
+	for (int i = 0; i < static_cast<int>(vecRecipe.size()); ++i) {
+		const RecipeInfo& recipe = vecRecipe[i];
 
-		// 璁剧疆 Recipe No锛堢1鍒楋級
-		CString strRecipeNo;
-		strRecipeNo.Format(_T("%d"), i);
-		pListCtrl->SetItemText(i, 1, strRecipeNo);
+		m_listPPID.InsertItem(i, _T("")); // 绗�0鍒楃┖鐧�
 
-		// 璁剧疆 PPID锛堢2鍒楋級
-		CString strPPID = CA2T(vecData[i].c_str());
-		if (strPPID.CompareNoCase(_T("NULL")) == 0) {
-			strPPID.Empty();
-		}
-		pListCtrl->SetItemText(i, 2, strPPID);
+		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()));
 	}
 
 	// 鑾峰彇鍒楁暟
-	int nColCount = pListCtrl->GetHeaderCtrl()->GetItemCount();
-	pListCtrl->SetColumnWidth(nColCount - 1, LVSCW_AUTOSIZE_USEHEADER);
+	int nColCount = m_listPPID.GetHeaderCtrl()->GetItemCount();
+	m_listPPID.SetColumnWidth(nColCount - 1, LVSCW_AUTOSIZE_USEHEADER);
+}
+
+void CPageRecipe::FillRecipeListToListCtrl(SERVO::CRecipeList* pList)
+{
+	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_PPID);
+	if (pListCtrl == nullptr || !::IsWindow(pListCtrl->m_hWnd)) {
+		return;
+	}
+
+	// 娓呯┖褰撳墠CListCtrl涓殑鎵�鏈夐」
+	pListCtrl->DeleteAllItems();
+	if (pList == nullptr) {
+		return;
+	}
+
+
+	// 閬嶅巻鏁版嵁骞舵彃鍏ュ埌CListCtrl涓�
+	std::map<int, short>& ids = pList->getIds();
+	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());
+	}
+
+	// 鑾峰彇鍒楁暟
+	int nColCount = m_listPPID.GetHeaderCtrl()->GetItemCount();
+	m_listPPID.SetColumnWidth(nColCount - 1, LVSCW_AUTOSIZE_USEHEADER);
 }
 
 void CPageRecipe::DoDataExchange(CDataExchange* pDX)
 {
 	CDialogEx::DoDataExchange(pDX);
 	DDX_Control(pDX, IDC_LIST_PPID, m_listPPID);
-	DDX_Control(pDX, IDC_EDIT_PPID, m_editPPID);
 }
 
 
 BEGIN_MESSAGE_MAP(CPageRecipe, CDialogEx)
+	ON_WM_SIZE()
 	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_SAVE, &CPageRecipe::OnBnClickedButtonSave)
 	ON_BN_CLICKED(IDC_BUTTON_REFRESH, &CPageRecipe::OnBnClickedButtonRefresh)
 	ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_PPID, &CPageRecipe::OnLvnItemChangedListPPID)
+	ON_WM_DESTROY()
+	ON_CBN_SELCHANGE(IDC_COMBO_EQUIPMENT, &CPageRecipe::OnCbnSelchangeComboEquipment)
+	ON_WM_SHOWWINDOW()
 END_MESSAGE_MAP()
 
 
@@ -78,6 +104,16 @@
 BOOL CPageRecipe::OnInitDialog()
 {
 	CDialogEx::OnInitDialog();
+
+	// 璇诲嚭鍒楀
+	CString strIniFile, strItem;
+	strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+	int width[8] = { 0, 80, 180, 80, 80, 100, 80, 180 };
+	for (int i = 0; i < 8; i++) {
+		strItem.Format(_T("Col_%d_Width"), i);
+		width[i] = GetPrivateProfileInt("PageRecipeListCtrl", strItem, width[i], strIniFile);
+	}
+
 
 	// TODO:  鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
 	CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST_PPID);
@@ -88,85 +124,222 @@
 
 	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("Recipe No"), LVCFMT_LEFT, 100);
-	pListCtrl->InsertColumn(2, _T("PPID"), LVCFMT_LEFT, 100);
-	pListCtrl->SetColumnWidth(2, LVSCW_AUTOSIZE_USEHEADER);
+	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[3]);
+	pListCtrl->InsertColumn(4, _T("鍒涘缓鏃堕棿"), LVCFMT_LEFT, width[4]);
+	pListCtrl->SetColumnWidth(4, LVSCW_AUTOSIZE_USEHEADER);
+
 
 	// 鑾峰彇鎵�鏈夋暟鎹�
-	auto vecData = SECSRuntimeManager::getInstance().getAllPPID();
+	auto vecData = RecipeManager::getInstance().getAllRecipes();
 	FillDataToListCtrl(vecData);
 
 	return TRUE;  // return TRUE unless you set the focus to a control
 	// 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
 }
 
-void CPageRecipe::OnBnClickedButtonSearch()
+void CPageRecipe::OnSize(UINT nType, int cx, int cy)
 {
-	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
-	CString strInput;
-	m_editPPID.GetWindowText(strInput);
+	CDialogEx::OnSize(nType, cx, cy);
 
-	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;
+	if (!m_listPPID.GetSafeHwnd())
+		return;
+
+
+	// 宸︿晶鍒楄〃瀹介珮鑷�傚簲
+	int margin = 12;
+	int buttonWidth = 80;
+	int buttonHeight = 30;
+	int buttonSpacing = 10;
+
+	CWnd* pItem;
+	CRect rect, rcItem;
+	GetClientRect(&rect);
+
+	pItem = GetDlgItem(IDC_EDIT_KEYWORD);
+	ASSERT(pItem);
+	pItem->GetWindowRect(rcItem);
+	ScreenToClient(&rcItem);
+
+	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_DELETE),
+		GetDlgItem(IDC_BUTTON_DELETE_ALL),
+		GetDlgItem(IDC_BUTTON_MODIFY)
+	};
+
+	for (auto pBtn : buttons) {
+		if (pBtn && pBtn->GetSafeHwnd()) {
+			pBtn->MoveWindow(rect.right - buttonWidth - margin, y, buttonWidth, buttonHeight);
+			y += buttonHeight + buttonSpacing;
 		}
 	}
+}
+
+void CPageRecipe::OnBnClickedButtonSearch()
+{
+	CString strKeyword;
+	GetDlgItemText(IDC_EDIT_KEYWORD, strKeyword);
+	AfxMessageBox(strKeyword);
 }
 
 void CPageRecipe::OnBnClickedButtonModify()
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	/*
 	POSITION pos = m_listPPID.GetFirstSelectedItemPosition();
-	if (!pos) return;
+	if (!pos) {
+		AfxMessageBox(_T("璇烽�夋嫨瑕佷慨鏀圭殑閰嶆柟"));
+		return;
+	}
 
 	int nSel = m_listPPID.GetNextSelectedItem(pos);
+	CString strOldPPID = m_listPPID.GetItemText(nSel, 2);
+	CString strOldDesc = m_listPPID.GetItemText(nSel, 3);
 
-	CString strNewPPID;
+	CString strNewPPID, strNewDesc;
 	m_editPPID.GetWindowText(strNewPPID);
-	m_listPPID.SetItemText(nSel, 2, strNewPPID);
+	m_editDesc.GetWindowText(strNewDesc);
+
+	// 鍒ょ┖
+	if (strOldPPID.IsEmpty() || strNewPPID.IsEmpty()) {
+		AfxMessageBox(_T("PPID 涓嶈兘涓虹┖"));
+		return;
+	}
+
+	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 宸插瓨鍦紝璇蜂娇鐢ㄥ叾浠栧��"));
+			return;
+		}
+
+		// 璋冪敤 updatePPID锛屽悓鏃舵洿鏂版弿杩�
+		if (RecipeManager::getInstance().updatePPID(oldPPID, newPPID)) {
+			m_listPPID.SetItemText(nSel, 2, strNewPPID);
+		}
+		else {
+			AfxMessageBox(_T("鏇存柊澶辫触锛岃妫�鏌ユ棩蹇�"));
+		}
+	}
+
+	if (bDescChanged) {
+		// 鏇存柊鎻忚堪
+		if (RecipeManager::getInstance().updateDescription(oldPPID, newDesc)) {
+			m_listPPID.SetItemText(nSel, 3, strNewDesc);
+		}
+		else {
+			AfxMessageBox(_T("鎻忚堪鏇存柊澶辫触"));
+		}
+	}
+	*/
 }
 
 void CPageRecipe::OnBnClickedButtonDelete()
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
 	POSITION pos = m_listPPID.GetFirstSelectedItemPosition();
-	if (!pos) return;
+	if (!pos) { 
+		return;
+	}
 
 	int nSel = m_listPPID.GetNextSelectedItem(pos);
-	m_listPPID.SetItemText(nSel, 2, _T(""));
+	CString strPPID = m_listPPID.GetItemText(nSel, 2);
+	std::string ppid = CT2A(strPPID);
+
+	if (!ppid.empty()) {
+		CString msg;
+		msg.Format(_T("纭畾瑕佸垹闄ら厤鏂� [%s] 鍚楋紵"), strPPID);
+		if (IDYES == AfxMessageBox(msg, MB_YESNO | MB_ICONQUESTION)) {
+			if (RecipeManager::getInstance().deleteRecipeByPPID(ppid)) {
+				m_listPPID.DeleteItem(nSel);
+			}
+			else {
+				AfxMessageBox(_T("鍒犻櫎澶辫触"));
+			}
+		}
+	}
 }
 
 void CPageRecipe::OnBnClickedButtonDeleteAll()
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
-	int nCount = m_listPPID.GetItemCount();
-	for (int i = 0; i < nCount; ++i) {
-		m_listPPID.SetItemText(i, 2, _T(""));
+	if (IDYES != AfxMessageBox(_T("纭畾瑕佸垹闄ゅ叏閮ㄩ厤鏂硅褰曞悧锛�"), MB_YESNO | MB_ICONWARNING)) {
+		return;
 	}
-}
 
-void CPageRecipe::OnBnClickedButtonSave()
-{
-	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
-	std::vector<std::string> vecPPID;
+	// 鑾峰彇鎵�鏈� PPID
 	int nCount = m_listPPID.GetItemCount();
 	for (int i = 0; i < nCount; ++i) {
-		CString str = m_listPPID.GetItemText(i, 2);
-		vecPPID.emplace_back(CT2A(str));
+		CString strPPID = m_listPPID.GetItemText(i, 2);
+		std::string ppid = CT2A(strPPID);
+		if (!ppid.empty()) {
+			RecipeManager::getInstance().deleteRecipeByPPID(ppid);
+		}
 	}
-	SECSRuntimeManager::getInstance().setAllPPID(vecPPID);
+
+	// 娓呯┖鍒楄〃鏄剧ず
+	m_listPPID.DeleteAllItems();
 }
 
 void CPageRecipe::OnBnClickedButtonRefresh()
 {
-	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
-	auto vecData = SECSRuntimeManager::getInstance().getAllPPID();
-	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 {
+		// enable port
+		CMsgDlg msgDlg("璇风瓑寰�", "姝e湪鑾峰彇閰嶆柟...");
+		pEq->masterRecipeListRequest(0, [&](int status) -> void {
+			if (status == SS_FAILED) {
+				CString strMsg;
+				strMsg.Format(_T("鑾峰彇閰嶆柟澶辫触锛�"));
+				msgDlg.DelayClose(3000);
+				msgDlg.SetIcon(MSG_BOX_ERROR);
+				msgDlg.SetTitle(_T("鎿嶄綔澶辫触"));
+				msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
+				msgDlg.SetMarquee(FALSE, 0);
+				msgDlg.SetCompleteCode(-1);
+			}
+			else if (status == SS_COMPLETE) {
+				CString strMsg;
+				strMsg.Format(_T("鑾峰彇閰嶆柟瀹屾垚锛�"));
+				msgDlg.DelayClose(3000);
+				msgDlg.SetIcon(MSG_BOX_SUCCEED);
+				msgDlg.SetTitle(_T("鎿嶄綔鎴愬姛"));
+				msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg);
+				msgDlg.SetMarquee(FALSE, 0);
+				msgDlg.SetCompleteCode(0);
+			}
+			});
+		msgDlg.DoModal();
+	}
 }
 
 void CPageRecipe::OnLvnItemChangedListPPID(NMHDR* pNMHDR, LRESULT* pResult)
@@ -174,11 +347,85 @@
 	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
 	*pResult = 0;
 
-	if ((pNMLV->uChanged & LVIF_STATE) &&
-		(pNMLV->uNewState & LVIS_SELECTED)) {
+	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
+	int nEqSel = pComboBox->GetCurSel();
+	int selectedCount = ListView_GetSelectedCount(m_listPPID.GetSafeHwnd());
 
-		int nItem = pNMLV->iItem;
-		CString strPPID = m_listPPID.GetItemText(nItem, 2);
-		m_editPPID.SetWindowText(strPPID);
+	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);
+}
+
+void CPageRecipe::OnCbnSelchangeComboEquipment()
+{
+	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
+	int nEqSel = pComboBox->GetCurSel();
+	int selectedCount = ListView_GetSelectedCount(m_listPPID.GetSafeHwnd());
+
+	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);
+	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) {
+		auto vecData = RecipeManager::getInstance().getAllRecipes();
+		FillDataToListCtrl(vecData);
 	}
-}
\ No newline at end of file
+	else {
+		SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0);
+		FillRecipeListToListCtrl(pRecipeList);
+	}
+	
+
+
+}
+
+
+void CPageRecipe::OnDestroy()
+{
+	CDialogEx::OnDestroy();
+
+	// 淇濆瓨鍒楀
+	CString strIniFile, strItem, strTemp;
+	strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+	CHeaderCtrl* pHeader = m_listPPID.GetHeaderCtrl();
+	for (int i = 0; i < pHeader->GetItemCount(); i++) {
+		RECT rect;
+		pHeader->GetItemRect(i, &rect);
+		strItem.Format(_T("Col_%d_Width"), i);
+		strTemp.Format(_T("%d"), rect.right - rect.left);
+		WritePrivateProfileString("PageRecipeListCtrl", strItem, strTemp, strIniFile);
+	}
+}
+
+
+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]);
+			}
+			pComboBox->SetCurSel(0);
+		}
+	}
+}

--
Gitblit v1.9.3