From c5dd6808b3b307ccc0add38f75f31bd5389ba76c Mon Sep 17 00:00:00 2001 From: vbtang Date: Wed, 28 Jun 2017 23:25:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BC=A0=E6=84=9F=E5=99=A8?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=AF=B9=E8=AF=9D=E6=A1=86=E5=88=B0grid?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E7=9A=84=E5=88=B7=E6=96=B0=E8=81=94=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Edislab/Edislab Pro/DlgSensorChoose.cpp | 80 ++++++++++++++++----- Src/Edislab/Edislab Pro/DlgSensorChoose.h | 4 ++ 2 files changed, 65 insertions(+), 19 deletions(-) diff --git a/Src/Edislab/Edislab Pro/DlgSensorChoose.cpp b/Src/Edislab/Edislab Pro/DlgSensorChoose.cpp index b2ba63f..8f7ffd9 100644 --- a/Src/Edislab/Edislab Pro/DlgSensorChoose.cpp +++ b/Src/Edislab/Edislab Pro/DlgSensorChoose.cpp @@ -120,6 +120,7 @@ void CDlgSensorChoose::OnBnClickedCheckAutoRecognize() m_BtnDel.EnableWindow(true); m_BtnDelAll.EnableWindow(true); m_BtnChooseCon.EnableWindow(true); + CSerialPortService::CreateInstance().StopSerialPortService(); } // 添加传感器识别部分代码 @@ -151,32 +152,61 @@ void CDlgSensorChoose::OnBnClickedBtnAdd() { CString str; // 拼凑添加项的头 + // 传感器只能添加一个 2017.06.28 int nNum = (int)m_setChooseSensorID.count(iter->second.nSensorID); if (nNum == 0) { + + if (-1 == CSensorIDGenerator::CreateInstance().AddSensor(iter->second.strSensorName)) + { + return; + } + str.Format(_T("数据列:%s(%s)"), CString(iter->second.strSensorSymbol.c_str()), CString(iter->second.strSensorName.c_str())); - } - else - { - str.Format(_T("数据列:%s_%d(%s)"), CString(iter->second.strSensorSymbol.c_str()), nNum, CString(iter->second.strSensorName.c_str())); - } - // 拼凑添加项描述文字 - m_setChooseSensorID.insert(iter->second.nSensorID); - if (iter->second.SensorRangeInfoArray.size() > 0) - { - nIndex = m_ListChoosedSensor.AddString(str); - str = iter->second.SensorRangeInfoArray[0].strRangeName.c_str(); - int nCharPos = str.Find('('); - str = str.Left(nCharPos); - str = _T("量程:") + str; - - m_ListChoosedSensor.SetItemDescription(nIndex, str); - // 将sensor ID作为item Data - m_ListChoosedSensor.SetItemData(nIndex, iter->second.nSensorID); + // 拼凑添加项描述文字 + m_setChooseSensorID.insert(iter->second.nSensorID); + if (iter->second.SensorRangeInfoArray.size() > 0) + { + nIndex = m_ListChoosedSensor.AddString(str); + str = iter->second.SensorRangeInfoArray[0].strRangeName.c_str(); + int nCharPos = str.Find('('); + str = str.Left(nCharPos); + str = _T("量程:") + str; + + m_ListChoosedSensor.SetItemDescription(nIndex, str); + // 将sensor ID作为item Data + m_ListChoosedSensor.SetItemData(nIndex, iter->second.nSensorID); - m_ListChoosedSensor.SetItemImage(nIndex, iter->second.nSensorID); + m_ListChoosedSensor.SetItemImage(nIndex, iter->second.nSensorID); + } + + // 添加列表显示列 + COLUMN_INFO AddColumnInfo; + AddColumnInfo.strColumnName.Format(_T("%s(%s)"), CString(iter->second.strSensorSymbol.c_str()), CString(iter->second.strSensorName.c_str())); + CGridColumnGroupManager::CreateInstance().AddDisplayColumnInfo(_T("当前"), AddColumnInfo); + //通知Grid刷新 + CWnd* pWnd = AfxGetMainWnd(); + if (nullptr != pWnd) + { + pWnd->PostMessage(WM_NOTIFY_GRID_GROUP_INFO_CHANGE,0,0); + } + + // 删除已有的传感器,防止重新添加 + nIndex = m_ListSensor.GetCurSel(); + m_ListSensor.DeleteString(nIndex); + auto iter = m_mapCurrentSensor.find(nIndex); + if (m_mapCurrentSensor.end() != iter) + { + m_mapCurrentSensor.erase(iter); + } } +// else +// { +// str.Format(_T("数据列:%s_%d(%s)"), CString(iter->second.strSensorSymbol.c_str()), nNum, CString(iter->second.strSensorName.c_str())); +// } + + } } @@ -194,6 +224,16 @@ void CDlgSensorChoose::OnBnClickedBtnDelete() } m_ListChoosedSensor.DeleteString(m_ListChoosedSensor.GetCurSel()); + + // 为右侧待选传感器恢复删除的传感器 + SENSOR_CONFIG_ELEMENT element = CSensorConfig::CreateInstance().GetSensorInfo(nIndex); + CString str(element.strSensorName.c_str()); + int nIndex = m_ListSensor.AddString(str); + str = element.strSensorModelName.c_str(); + m_ListSensor.SetItemDescription(nIndex, str); + m_ListSensor.SetItemData(nIndex, element.nSensorID); + m_ListSensor.SetItemImage(nIndex, element.nSensorID); + m_mapCurrentSensor[element.nSensorID] = element; } } @@ -217,6 +257,8 @@ void CDlgSensorChoose::OnBnClickedBtnChooseConnected() void CDlgSensorChoose::OnBnClickedBtnOk() { // TODO: 在此添加控件通知处理程序代码 + + CSerialPortService::CreateInstance().StartSerialPortService(); } void CDlgSensorChoose::OnCbnSelchangeCmbSensorType() diff --git a/Src/Edislab/Edislab Pro/DlgSensorChoose.h b/Src/Edislab/Edislab Pro/DlgSensorChoose.h index 9968ddd..ae62472 100644 --- a/Src/Edislab/Edislab Pro/DlgSensorChoose.h +++ b/Src/Edislab/Edislab Pro/DlgSensorChoose.h @@ -2,6 +2,10 @@ #include "BaseDialog.h" #include "Type.h" #include "SensorConfig.h" +#include "SensorIDGenerator.h" +#include "GridColumnGroupManager.h" +#include "SerialPortService.h" +#include "Msg.h" #include // CDlgSensorChoose 对话框