| | |
| | | |
| | | CRecipeDeviceBindDlg::CRecipeDeviceBindDlg(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_DIALOG_RECIPE_DEVICE_BIND, pParent) |
| | | , m_strPPID(_T("")) |
| | | , m_strDesc(_T("")) |
| | | { |
| | | |
| | | } |
| | |
| | | { |
| | | } |
| | | |
| | | void CRecipeDeviceBindDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CDialogEx::DoDataExchange(pDX); |
| | | const RecipeInfo& CRecipeDeviceBindDlg::GetRecipeInfo() const { |
| | | return m_recipe; |
| | | } |
| | | |
| | | void CRecipeDeviceBindDlg::SetRecipeInfo(const RecipeInfo& info) |
| | | { |
| | | m_recipe = info; |
| | | } |
| | | |
| | | void CRecipeDeviceBindDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CDialogEx::DoDataExchange(pDX); |
| | | DDX_Text(pDX, IDC_EDIT_PPID, m_strPPID); |
| | | DDX_Text(pDX, IDC_EDIT_DESC, m_strDesc); |
| | | } |
| | | |
| | | BEGIN_MESSAGE_MAP(CRecipeDeviceBindDlg, CDialogEx) |
| | | ON_WM_CLOSE() |
| | | ON_WM_SIZE() |
| | | ON_BN_CLICKED(IDOK, &CRecipeDeviceBindDlg::OnBnClickedOk) |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | |
| | | // TODO: 在此添加额外的初始化 |
| | | // 设置固定大小(例如 600x400) |
| | | SetWindowPos(nullptr, 0, 0, 600, 400, SWP_NOMOVE | SWP_NOZORDER); |
| | | // TODO: 在此添加额外的初始化 |
| | | if (m_recipe.vecDeviceList.empty()) { |
| | | SetWindowText(_T("新建配方")); |
| | | |
| | | // 创建控件 |
| | | const int totalControlWidth = 340; |
| | | CRect clientRect; |
| | | GetClientRect(&clientRect); |
| | | int xStart = (clientRect.Width() - totalControlWidth) / 2; |
| | | // 设置固定大小(例如 600x400) |
| | | SetWindowPos(nullptr, 0, 0, 600, 400, SWP_NOMOVE | SWP_NOZORDER); |
| | | |
| | | const int nRowHeight = 30; |
| | | const int yStart = 30; // 顶部起始高度 |
| | | // 创建控件 |
| | | const int totalControlWidth = 340; |
| | | CRect clientRect; |
| | | GetClientRect(&clientRect); |
| | | int xStart = (clientRect.Width() - totalControlWidth) / 2; |
| | | |
| | | const int nRowCount = static_cast<int>(g_vecBindDevices.size()); |
| | | for (int i = 0; i < nRowCount; ++i) { |
| | | int y = yStart + i * nRowHeight; |
| | | const auto& meta = g_vecBindDevices[i]; |
| | | const int nRowHeight = 30; |
| | | const int yStart = 30; // 顶部起始高度 |
| | | |
| | | CEdit* pEditID = new CEdit(); |
| | | pEditID->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(xStart, y, xStart + 100, y + 25), this, IDC_EDIT_DEVICEID_BASE + i); |
| | | const int nRowCount = static_cast<int>(g_vecBindDevices.size()); |
| | | for (int i = 0; i < nRowCount; ++i) { |
| | | int y = yStart + i * nRowHeight; |
| | | const auto& meta = g_vecBindDevices[i]; |
| | | |
| | | CString strID; |
| | | strID.Format(_T("%d"), meta.nDeviceID); |
| | | pEditID->SetWindowText(strID); |
| | | pEditID->SetReadOnly(TRUE); // 设备ID只读 |
| | | CEdit* pEditID = new CEdit(); |
| | | pEditID->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(xStart, y, xStart + 100, y + 25), this, IDC_EDIT_DEVICEID_BASE + i); |
| | | |
| | | CEdit* pEditName = new CEdit(); |
| | | pEditName->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(xStart + 110, y, xStart + 210, y + 25), this, IDC_EDIT_DEVICENAME_BASE + i); |
| | | pEditName->SetWindowText(CA2T(meta.strDeviceName)); |
| | | pEditName->SetReadOnly(TRUE); // 设备名称只读 |
| | | CString strID; |
| | | strID.Format(_T("%d"), meta.nDeviceID); |
| | | pEditID->SetWindowText(strID); |
| | | pEditID->SetReadOnly(TRUE); // 设备ID只读 |
| | | |
| | | CComboBox* pCombo = new CComboBox(); |
| | | pCombo->Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, CRect(xStart + 220, y, xStart + 340, y + 300), this, IDC_COMBO_RECIPEID_BASE + i); |
| | | CEdit* pEditName = new CEdit(); |
| | | pEditName->Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(xStart + 110, y, xStart + 210, y + 25), this, IDC_EDIT_DEVICENAME_BASE + i); |
| | | pEditName->SetWindowText(CA2T(meta.strDeviceName)); |
| | | pEditName->SetReadOnly(TRUE); // 设备名称只读 |
| | | |
| | | // 添加选项到 ComboBox |
| | | m_vecDevices.push_back({ pEditID, pEditName, pCombo }); |
| | | CComboBox* pCombo = new CComboBox(); |
| | | pCombo->Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, CRect(xStart + 220, y, xStart + 340, y + 300), this, IDC_COMBO_RECIPEID_BASE + i); |
| | | |
| | | // 添加选项到 ComboBox |
| | | m_vecDevices.push_back({ pEditID, pEditName, pCombo }); |
| | | } |
| | | } |
| | | else { |
| | | SetWindowText(_T("编辑配方")); |
| | | |
| | | m_strPPID = CA2T(m_recipe.strPPID.c_str()); |
| | | m_strDesc = CA2T(m_recipe.strDescription.c_str()); |
| | | UpdateData(FALSE); |
| | | |
| | | // 设置设备行数据 |
| | | for (size_t i = 0; i < m_recipe.vecDeviceList.size() && i < m_vecDevices.size(); ++i) { |
| | | const DeviceRecipe& d = m_recipe.vecDeviceList[i]; |
| | | CString str; |
| | | // 设置设备ID和名称 |
| | | str.Format(_T("%d"), d.nDeviceID); |
| | | m_vecDevices[i].editDeviceID->SetWindowText(str); |
| | | |
| | | str.Format(_T("%s"), d.strDeviceName.c_str()); |
| | | m_vecDevices[i].editDeviceName->SetWindowText(str); |
| | | |
| | | /*ComboBox选择配方ID,后面需要修改****/ |
| | | //int nCount = m_vecDevices[i].comboRecipeID->GetCount(); |
| | | //for (int idx = 0; idx < nCount; ++idx) { |
| | | // if ((int)m_vecDevices[i].comboRecipeID->GetItemData(idx) == d.nRecipeID) { |
| | | // m_vecDevices[i].comboRecipeID->SetCurSel(idx); |
| | | // break; |
| | | // } |
| | | //} |
| | | } |
| | | } |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | |
| | | CDialogEx::OnSize(nType, cx, cy); |
| | | |
| | | // TODO: 在此处添加消息处理程序代码 |
| | | } |
| | | } |
| | | |
| | | void CRecipeDeviceBindDlg::OnBnClickedOk() |
| | | { |
| | | // TODO: 在此添加控件通知处理程序代码 |
| | | UpdateData(TRUE); |
| | | |
| | | // 收集所有设备映射 |
| | | m_recipe.vecDeviceList.clear(); |
| | | for (const auto& dev : m_vecDevices) { |
| | | DeviceRecipe info; |
| | | CString strID, strName; |
| | | dev.editDeviceID->GetWindowText(strID); |
| | | dev.editDeviceName->GetWindowText(strName); |
| | | |
| | | int sel = dev.comboRecipeID->GetCurSel(); |
| | | info.nRecipeID = -1; |
| | | if (sel != CB_ERR) { |
| | | info.nRecipeID = (int)dev.comboRecipeID->GetItemData(sel); |
| | | } |
| | | info.nDeviceID = _ttoi(strID); |
| | | info.strDeviceName = CT2A(strName); |
| | | |
| | | m_recipe.vecDeviceList.push_back(info); |
| | | } |
| | | |
| | | // 检查 PPID 是否为空 |
| | | if (m_strPPID.IsEmpty()) { |
| | | AfxMessageBox(_T("配方 PPID 不能为空")); |
| | | return; |
| | | } |
| | | |
| | | // PPID和描述 |
| | | m_recipe.strPPID = CT2A(m_strPPID); |
| | | m_recipe.strDescription = CT2A(m_strDesc); |
| | | |
| | | CDialogEx::OnOK(); |
| | | } |