| | |
| | | #include "CReport.h" |
| | | #include <vector> |
| | | |
| | | |
| | | namespace SERVO { |
| | | class CCollectionEvent |
| | | { |
| | |
| | | std::string& getDescription(); |
| | | std::vector<CReport*>& getReports(); |
| | | std::string getReportIdsText(); |
| | | const std::vector<unsigned int>& getReportIds() const { return m_rptids; } |
| | | BOOL addReport(CReport* pReport); |
| | | BOOL deleteReport(unsigned int nReportId); |
| | | CReport* getReport(unsigned int nReportId); |
| | |
| | | std::vector<unsigned int> m_rptids; |
| | | std::vector<CReport*> m_reports; |
| | | }; |
| | | } |
| | | } |
| | |
| | | ON_WM_CTLCOLOR() |
| | | ON_WM_DESTROY() |
| | | ON_WM_SIZE() |
| | | ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, &CPageCollectionEvent::OnLvnItemchangedList1) |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | |
| | | m_listCtrl.SetItemText(index, 4, item->getReportIdsText().c_str()); |
| | | } |
| | | } |
| | | |
| | | void CPageCollectionEvent::OnCreateBtns() |
| | | { |
| | | const int BTN_W = 80; |
| | | const int BTN_H = 28; |
| | | CreateBtn(_T("新增"), BTN_W, BTN_H, 3001); |
| | | CreateBtn(_T("删除"), BTN_W, BTN_H, 3002)->EnableWindow(FALSE); |
| | | CreateBtn(_T("编辑"), BTN_W, BTN_H, 3003)->EnableWindow(FALSE); |
| | | } |
| | | |
| | | void CPageCollectionEvent::OnLvnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult) |
| | | { |
| | | LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR); |
| | | int nSelCount = m_listCtrl.GetSelectedCount(); |
| | | if (CButton* pDel = GetBtnByName("删除")) { |
| | | pDel->EnableWindow(nSelCount > 0); |
| | | } |
| | | if (CButton* pEdit = GetBtnByName("编辑")) { |
| | | pEdit->EnableWindow(nSelCount > 0); |
| | | } |
| | | *pResult = 0; |
| | | } |
| | | |
| | | void CPageCollectionEvent::OnClickedBtn(const char* btnName) |
| | | { |
| | | ASSERT(btnName); |
| | | if (_strcmpi(btnName, "删除") == 0) { |
| | | POSITION pos = m_listCtrl.GetFirstSelectedItemPosition(); |
| | | if (pos == nullptr) return; |
| | | int nItem = m_listCtrl.GetNextSelectedItem(pos); |
| | | auto pEvent = reinterpret_cast<SERVO::CCollectionEvent*>(m_listCtrl.GetItemData(nItem)); |
| | | if (pEvent == nullptr) return; |
| | | |
| | | int rc = UX_CanExecute(L"delEvents"); |
| | | if (rc != 1) { |
| | | AfxMessageBox("操作权限不足,请联系管理人员!"); |
| | | return; |
| | | } |
| | | |
| | | int ret = theApp.m_model.m_hsmsPassive.deleteCollectionEvent((unsigned short)pEvent->getEventId()); |
| | | if (ret == 0) { |
| | | UX_RecordAction(L"delEvents"); |
| | | m_listCtrl.DeleteAllItems(); |
| | | loadCollectionEvents(); |
| | | if (CButton* pDel = GetBtnByName("删除")) pDel->EnableWindow(FALSE); |
| | | if (CButton* pEdit = GetBtnByName("编辑")) pEdit->EnableWindow(FALSE); |
| | | } |
| | | else { |
| | | AfxMessageBox(_T("删除事件失败")); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | private: |
| | | CListCtrlEx m_listCtrl; |
| | | void OnCreateBtns() override; |
| | | void OnClickedBtn(const char* btnName) override; |
| | | |
| | | // 对话框数据 |
| | | #ifdef AFX_DESIGN_TIME |
| | |
| | | afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); |
| | | afx_msg void OnDestroy(); |
| | | afx_msg void OnSize(UINT nType, int cx, int cy); |
| | | afx_msg void OnLvnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult); |
| | | }; |
| | |
| | | UX_DefineAction(L"addReports", L"新增Report", L"PE"); |
| | | UX_DefineAction(L"editReports", L"编辑Report", L"PE"); |
| | | UX_DefineAction(L"delReports", L"删除Report", L"PE"); |
| | | UX_DefineAction(L"delEvents", L"删除Event", L"PE"); |
| | | } |
| | | |
| | | bool CUserManager2::login(const char* pszAccount, const char* pszPwd) |
| | |
| | | |
| | | int CHsmsPassive::loadCollectionEvents(const char* pszFilepath) |
| | | { |
| | | m_strCollectionEventFilepath = pszFilepath; |
| | | m_bCollectionUtf8 = false; |
| | | m_bCollectionUtf8Bom = false; |
| | | CFile file; |
| | | if (!file.Open(pszFilepath, CFile::modeRead | CFile::shareDenyNone)) { |
| | | return -1; |
| | |
| | | // UTF-8 BOM |
| | | if (nLen >= 3 && bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) { |
| | | offset = 3; |
| | | m_bCollectionUtf8 = true; |
| | | m_bCollectionUtf8Bom = true; |
| | | } |
| | | |
| | | // UTF-16 LE BOM |
| | |
| | | MultiByteToWideChar(CP_UTF8, 0, buffer.data() + off, |
| | | static_cast<int>(buffer.size() - off), temp.data(), need); |
| | | content = temp.c_str(); |
| | | m_bCollectionUtf8 = true; |
| | | return true; |
| | | }; |
| | | |
| | |
| | | return m_collectionEvents; |
| | | } |
| | | |
| | | int CHsmsPassive::deleteCollectionEvent(unsigned short CEID) |
| | | { |
| | | for (auto iter = m_collectionEvents.begin(); iter != m_collectionEvents.end(); ++iter) { |
| | | if ((*iter)->getEventId() == CEID) { |
| | | delete (*iter); |
| | | m_collectionEvents.erase(iter); |
| | | return writeCollectionEventsToFile(m_strCollectionEventFilepath); |
| | | } |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | void CHsmsPassive::clearAllCollectionEvent() |
| | | { |
| | | for (auto item : m_collectionEvents) { |
| | |
| | | return result; |
| | | } |
| | | |
| | | int CHsmsPassive::writeCollectionEventsToFile(const std::string& filepath) |
| | | { |
| | | if (filepath.empty()) return -1; |
| | | |
| | | CFile file; |
| | | if (!file.Open(filepath.c_str(), CFile::modeCreate | CFile::modeWrite)) { |
| | | return -1; |
| | | } |
| | | |
| | | if (m_bCollectionUtf8 && m_bCollectionUtf8Bom) { |
| | | const BYTE bom[3] = { 0xEF, 0xBB, 0xBF }; |
| | | file.Write(bom, 3); |
| | | } |
| | | |
| | | const std::string headerAnsi = "CEID,CE Name,Descriptions,Attached RPTID\r\n"; |
| | | if (m_bCollectionUtf8) { |
| | | CStringA header = AnsiToUtf8(headerAnsi); |
| | | file.Write(header.GetString(), header.GetLength()); |
| | | } |
| | | else { |
| | | file.Write(headerAnsi.data(), (UINT)headerAnsi.size()); |
| | | } |
| | | |
| | | for (auto ev : m_collectionEvents) { |
| | | if (ev == nullptr) continue; |
| | | std::string line; |
| | | line.reserve(128); |
| | | line += std::to_string(ev->getEventId()); |
| | | line.push_back(','); |
| | | line += ev->getName(); |
| | | line.push_back(','); |
| | | line += ev->getDescription(); |
| | | line.push_back(','); |
| | | line.push_back('('); |
| | | auto rptIds = ev->getReportIds(); |
| | | for (size_t i = 0; i < rptIds.size(); ++i) { |
| | | line += std::to_string(rptIds[i]); |
| | | if (i + 1 < rptIds.size()) { |
| | | line.push_back(','); |
| | | } |
| | | } |
| | | line += ")\r\n"; |
| | | |
| | | if (m_bCollectionUtf8) { |
| | | CStringA out = AnsiToUtf8(line); |
| | | file.Write(out.GetString(), out.GetLength()); |
| | | } |
| | | else { |
| | | file.Write(line.data(), (UINT)line.size()); |
| | | } |
| | | } |
| | | |
| | | file.Close(); |
| | | return 0; |
| | | } |
| | | |
| | | int CHsmsPassive::init(CModel* pModel, const char* pszName, unsigned int port) |
| | | { |
| | | m_pModel = pModel; |
| | |
| | | |
| | | // 取消/删除所有CollectionEvent |
| | | void clearAllCollectionEvent(); |
| | | int deleteCollectionEvent(unsigned short CEID); |
| | | |
| | | // 取得CCollectionEvent |
| | | SERVO::CCollectionEvent* getEvent(unsigned short CEID); |
| | |
| | | std::vector<unsigned int> parseVidList(CString& strNums); |
| | | int writeVariablesToFile(const std::string& filepath); |
| | | int writeReportsToFile(const std::string& filepath); |
| | | int writeCollectionEventsToFile(const std::string& filepath); |
| | | |
| | | private: |
| | | CModel* m_pModel; |
| | |
| | | std::string m_strReportFilepath; |
| | | bool m_bReportUtf8{ false }; |
| | | bool m_bReportUtf8Bom{ false }; |
| | | std::string m_strCollectionEventFilepath; |
| | | bool m_bCollectionUtf8{ false }; |
| | | bool m_bCollectionUtf8Bom{ false }; |
| | | BOOL m_bCimWorking; |
| | | HANDLE m_hCimWorkEvent; |
| | | HANDLE m_hCimWorkThreadHandle; |
| | |
| | | CEID,CE Name,Descriptions,Attached RPTID |
| | | 300,AccessMode_To_Manual,,(300) |
| | | 301,AccessMode_To_Auto,,(301) |
| | | 600,ControlStateChanged,,(600) |