From b67e16869a5bfbbde3896a4e5a13f1301f1b978d Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 13 十二月 2024 14:55:55 +0800
Subject: [PATCH] 1.调整保存警告到数据库的位置; 2.CAlarmMonitor组件不再保存已完成的警告的数据;

---
 SourceCode/Bond/BondEq/BondEqDlg.cpp |   62 ++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 1 deletions(-)

diff --git a/SourceCode/Bond/BondEq/BondEqDlg.cpp b/SourceCode/Bond/BondEq/BondEqDlg.cpp
index 3584094..e30ac6f 100644
--- a/SourceCode/Bond/BondEq/BondEqDlg.cpp
+++ b/SourceCode/Bond/BondEq/BondEqDlg.cpp
@@ -72,6 +72,7 @@
 	m_pHomeDialog = nullptr;
 	m_pActiveView = nullptr;
 	m_pActiveComponentDlg = nullptr;
+	m_pAlarmWnd = nullptr;
 }
 
 void CBondEqDlg::DoDataExchange(CDataExchange* pDX)
@@ -152,6 +153,16 @@
 					}
 				}
 			}
+			else if (code == RX_CODE_ALARM_ON) {
+				AlarmOn();
+				CAlarmMonitor* pComponent = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent(ALARM_MONITOR);
+				m_pTopToolbar->GetBtn(IDC_BUTTON_ALARM)->EnableWindow(pComponent->isAlarming());
+			}
+			else if (code == RX_CODE_ALARM_OFF) {
+				AlarmOff();
+				CAlarmMonitor* pComponent = (CAlarmMonitor*)theApp.m_model.getBonder().GetComponent(ALARM_MONITOR);
+				m_pTopToolbar->GetBtn(IDC_BUTTON_ALARM)->EnableWindow(pComponent->isAlarming());
+			}
 			pAny->release();
 		}, [&]() -> void {
 			// onComplete
@@ -222,6 +233,22 @@
 		return FALSE;
 	}
 
+	// 初始化报警模块
+	AlarmManager& alarmManager = AlarmManager::getInstance();
+	alarmManager.setDatabase(db.get());
+	try {
+		if (!alarmManager.initializeAlarmTable()) {
+			AfxMessageBox("初始化报警模块失败!");
+			return FALSE;
+		}
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("初始化报警模块失败:%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+		return FALSE;
+	}
+
 	// 设置配方文件夹路径
 	RecipeManager& recipeManager = RecipeManager::getInstance();
 	std::string strRecipePath =  CToolUnits::getCurrentExePath() + _T("\\Recipe");
@@ -244,6 +271,7 @@
 	m_pTopToolbar->Create(IDD_TOP_TOOLBAR, this);
 	m_pTopToolbar->ShowWindow(SW_SHOW);
 	m_pTopToolbar->GetBtn(IDC_BUTTON_STOP)->EnableWindow(FALSE);
+	m_pTopToolbar->GetBtn(IDC_BUTTON_ALARM)->EnableWindow(FALSE);
 	HMENU hMenu = m_pTopToolbar->GetOperatorMenu();
 	ASSERT(hMenu);
 	::EnableMenuItem(hMenu, ID_OPEATOR_SWITCH, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
@@ -391,6 +419,11 @@
 
 	if (m_hbrBkgnd != nullptr) {
 		::DeleteObject(m_hbrBkgnd);
+	}
+
+	if (m_pAlarmWnd != nullptr) {
+		m_pAlarmWnd->DestroyWindow();
+		delete m_pAlarmWnd;
 	}
 
 	ASSERT(m_pObserver != NULL);
@@ -573,6 +606,7 @@
 			return 0;
 		}
 
+		/*
 		CString inputText = inputDialog.GetInputText();
 		std::string strPass = UserManager::getInstance().getCurrentPass();
 		if (inputText.Compare(strPass.c_str()) != 0) {
@@ -580,17 +614,23 @@
 			logManager.log(SystemLogManager::LogType::Info, _T("验证时,密码错误!"));
 			return 0;
 		}
+		*/
 	}
 
 	if (id == IDC_BUTTON_RUN) {
+		theApp.m_model.getBonder().start();
 		m_pTopToolbar->GetBtn(IDC_BUTTON_RUN)->EnableWindow(FALSE);
 		m_pTopToolbar->GetBtn(IDC_BUTTON_STOP)->EnableWindow(TRUE);
 		logManager.log(SystemLogManager::LogType::Operation, _T("运行..."));
 	}
 	else if (id == IDC_BUTTON_STOP) {
+		theApp.m_model.getBonder().stop();
 		m_pTopToolbar->GetBtn(IDC_BUTTON_RUN)->EnableWindow(TRUE);
 		m_pTopToolbar->GetBtn(IDC_BUTTON_STOP)->EnableWindow(FALSE);
 		logManager.log(SystemLogManager::LogType::Operation, _T("停止..."));
+	}
+	else if (id == IDC_BUTTON_ALARM) {
+		AlarmOn();
 	}
 	else if (id == IDC_BUTTON_SETTINGS) {
 		CSettingsDlg dlg;
@@ -760,8 +800,9 @@
 CComponentPLCDlg* CBondEqDlg::CreateComponentPLCDlg(CComponent* pComponent)
 {
 	CComponentPLCDlg* pDlg = new CComponentPLCDlg(m_pMainContainer);
-	pDlg->Create(IDD_COMPONENT_PLC, m_pMainContainer);
 	pDlg->SetContext(pComponent);
+	pDlg->Create(IDD_COMPONENT_PLC, m_pMainContainer);
+
 
 	CString strIcon0, strIcon1, strIcon2, strIcon3;
 	strIcon0.Format(_T("%s\\Res\\small_close0.ico"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
@@ -780,3 +821,22 @@
 	return pDlg;
 }
 
+void CBondEqDlg::AlarmOn()
+{
+	if (m_pAlarmWnd == nullptr) {
+		m_pAlarmWnd = new CAlarmPopupDlg();
+		m_pAlarmWnd->Create(IDD_DIALOG_POPUP_ALARM, this);
+		m_pAlarmWnd->CenterWindow();
+	}
+	m_pAlarmWnd->AlarmOn();
+}
+
+void CBondEqDlg::AlarmOff()
+{
+	if (m_pAlarmWnd == nullptr) {
+		m_pAlarmWnd = new CAlarmPopupDlg();
+		m_pAlarmWnd->Create(IDD_DIALOG_POPUP_ALARM, this);
+		m_pAlarmWnd->CenterWindow();
+	}
+	m_pAlarmWnd->AlarmOff();
+}

--
Gitblit v1.9.3