From f5d3efdcec2d59e4adf6a3ae534082023e2df345 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期四, 04 九月 2025 15:51:25 +0800
Subject: [PATCH] 1. 配方列表中添加设备配方参数 2. 测试权限功能
---
SourceCode/Bond/Servo/PageRecipe.cpp | 220 +++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 181 insertions(+), 39 deletions(-)
diff --git a/SourceCode/Bond/Servo/PageRecipe.cpp b/SourceCode/Bond/Servo/PageRecipe.cpp
index a625647..bbbfe21 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,53 @@
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, 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_CENTER, width[2]);
+ m_listPPID.InsertColumn(3, _T("Recipe 鍚嶇О"), LVCFMT_CENTER, width[3]);
+ m_listPPID.InsertColumn(4, _T("Recipe 鍙傛暟"), LVCFMT_CENTER, width[4]);
}
void CPageRecipe::UpdateRecipeByPPID(const CString& strPPID)
@@ -100,8 +148,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 +179,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 +207,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());
}
// 鑾峰彇鍒楁暟
@@ -157,7 +238,8 @@
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()
@@ -168,15 +250,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 +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, 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 +317,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 +373,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 +452,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()
@@ -468,18 +577,48 @@
}
}
-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;
CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
- int nEqSel = pComboBox->GetCurSel();
- int selectedCount = ListView_GetSelectedCount(m_listPPID.GetSafeHwnd());
+ if (pComboBox == nullptr) {
+ return;
+ }
- 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);
+ int nItem = pNMItemActivate->iItem;
+ int nEqSel = pComboBox->GetCurSel();
+
+ GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(nEqSel == 0);
+ GetDlgItem(IDC_BUTTON_MODIFY)->EnableWindow(nItem > 0);
+ GetDlgItem(IDC_BUTTON_DELETE)->EnableWindow(nEqSel == 0 && nItem > 0);
+ GetDlgItem(IDC_BUTTON_DELETE_ALL)->EnableWindow(nEqSel == 0 && nItem > 0);
+}
+
+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 strText = m_listPPID.GetItemText(nItem, 2);
+ CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_EQUIPMENT);
+ int nEqSel = pComboBox->GetCurSel();
+ if (nEqSel == CB_ERR) {
+ return;
+ }
+
+ SERVO::CEquipment* pEq = (SERVO::CEquipment*)pComboBox->GetItemDataPtr(nEqSel);
+ if (pEq == nullptr) {
+ return;
+ }
}
void CPageRecipe::OnCbnSelchangeComboEquipment()
@@ -488,6 +627,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,11 +636,13 @@
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);
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3