| | |
| | | #include "afxdialogex.h" |
| | | #include "Common.h" |
| | | #include "CBonder.h" |
| | | #include "ToolUnits.h" |
| | | #include "SettingsDlg.h" |
| | | #include "UserManager.h" |
| | | #include "InputDialog.h" |
| | | #include "LoginDlg.h" |
| | | #include "ChangePasswordDlg.h" |
| | | #include "UserManagerDlg.h" |
| | | #include "SystemLogManagerDlg.h" |
| | | |
| | | // test |
| | | #include "AxisSettingsDlg.h" |
| | | #include "UserManagerDlg.h" |
| | | |
| | | #include "IOMonitoringDlg.h" |
| | | |
| | | #ifdef _DEBUG |
| | | #define new DEBUG_NEW |
| | |
| | | SetTimer(1, 60000, nullptr); |
| | | #endif |
| | | userManager.loadSession(); |
| | | std::unique_ptr<BL::Database>& db = userManager.getDatabaseInstance(); |
| | | |
| | | // 设置运行日志模块的数据库连接 |
| | | SystemLogManager& logManager = SystemLogManager::getInstance(); |
| | | logManager.setDatabase(db.get()); |
| | | |
| | | // 初始化运行日志表 |
| | | try { |
| | | if (!logManager.initializeLogTable()) { |
| | | 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"); |
| | | CToolUnits::createDir(strRecipePath.c_str()); |
| | | recipeManager.setRecipeFolder(strRecipePath); |
| | | |
| | | |
| | | // 菜单 |
| | |
| | | InitRxWindows(); |
| | | |
| | | |
| | | // 登录管理 |
| | | if (userManager.isLoggedIn()) { |
| | | m_pTopToolbar->SetOperatorBtnText(userManager.getCurrentUser().c_str()); |
| | | } |
| | | // 更新登录状态 |
| | | UpdateLoginStatus(); |
| | | logManager.log(SystemLogManager::LogType::Info, _T("BondEq启动...")); |
| | | |
| | | |
| | | return TRUE; // 除非将焦点设置到控件,否则返回 TRUE |
| | |
| | | UserManager::getInstance().terminateIdleDetection(); |
| | | KillTimer(1); |
| | | #endif |
| | | |
| | | SystemLogManager::getInstance().log(SystemLogManager::LogType::Info, _T("BondEq关闭...")); |
| | | } |
| | | |
| | | void CBondEqDlg::OnSize(UINT nType, int cx, int cy) |
| | |
| | | |
| | | void CBondEqDlg::OnMenuFileSettings() |
| | | { |
| | | // Cavity VacuumBake AfterBake AOI |
| | | CIOMonitoringDlg dlg; |
| | | dlg.SetIOManager("Cavity"); |
| | | dlg.DoModal(); |
| | | |
| | | //CAxisSettingsDlg axisDlg; |
| | | //axisDlg.SetPLC(theApp.m_model.getBonder().getPLC("PLC(1)")); |
| | | //axisDlg.SetRecipeName(_T("Default")); |
| | | //axisDlg.DoModal(); |
| | | |
| | | /* |
| | | CSettingsDlg dlg; |
| | | dlg.DoModal(); |
| | | */ |
| | | } |
| | | |
| | | void CBondEqDlg::OnUpdateMenuFileSettings(CCmdUI* pCmdUI) |
| | |
| | | LRESULT CBondEqDlg::OnToolbarBtnClicked(WPARAM wParam, LPARAM lParam) |
| | | { |
| | | int id = (int)lParam; |
| | | SystemLogManager& logManager = SystemLogManager::getInstance(); |
| | | if (id == IDC_BUTTON_RUN || id == IDC_BUTTON_STOP || id == IDC_BUTTON_SETTINGS) |
| | | { |
| | | CInputDialog inputDialog(_T("验证用户"), _T("请输入用户密码:")); |
| | | if (inputDialog.DoModal() != IDOK) { |
| | | AfxMessageBox(_T("取消验证!")); |
| | | return 0; |
| | | } |
| | | |
| | | CString inputText = inputDialog.GetInputText(); |
| | | std::string strPass = UserManager::getInstance().getCurrentPass(); |
| | | if (inputText.Compare(strPass.c_str()) != 0) { |
| | | AfxMessageBox(_T("密码错误!")); |
| | | logManager.log(SystemLogManager::LogType::Info, _T("验证时,密码错误!")); |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | if (id == IDC_BUTTON_RUN) { |
| | | 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) { |
| | | 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_SETTINGS) { |
| | | CSettingsDlg dlg; |
| | |
| | | int menuId = (int)wParam; |
| | | UserManager& userManager = UserManager::getInstance(); |
| | | if (menuId == 0) { |
| | | ShowLoginDlg(); |
| | | CLoginDlg loginDlg; |
| | | loginDlg.DoModal(); |
| | | } |
| | | else if (1 == menuId) { |
| | | CChangePasswordDlg changePasswordDlg; |
| | | changePasswordDlg.DoModal(); |
| | | } |
| | | else if (2 == menuId) { |
| | | CUserManagerDlg dlg; |
| | | if (dlg.DoModal()!= IDOK) { |
| | | logManager.log(SystemLogManager::LogType::Operation, _T("用户管理的预操作被取消!")); |
| | | } |
| | | } |
| | | else if (3 == menuId) { |
| | | CSystemLogManagerDlg dlg; |
| | | dlg.DoModal(); |
| | | } |
| | | else if (4 == menuId) { |
| | | int ret = AfxMessageBox(_T("是否切换用户?切换用户会退出当前账号!"), MB_OKCANCEL | MB_ICONEXCLAMATION); |
| | | if (ret != IDOK) { |
| | | return 0; |
| | | } |
| | | |
| | | logManager.log(SystemLogManager::LogType::Operation, _T("确认切换角色!")); |
| | | if (userManager.isLoggedIn()) { |
| | | logManager.log(SystemLogManager::LogType::Info, _T("退出登录!")); |
| | | userManager.logout(); |
| | | } |
| | | |
| | | ShowLoginDlg(); |
| | | CLoginDlg loginDlg; |
| | | loginDlg.DoModal(); |
| | | } |
| | | else if (2 == menuId) { |
| | | // test |
| | | CUserManagerDlg dlg; |
| | | dlg.DoModal(); |
| | | else { |
| | | CString cstrMessage; |
| | | cstrMessage.Format(_T("是否退出用户 [%s]?"), userManager.getCurrentUser().c_str()); |
| | | int ret = AfxMessageBox(_T(cstrMessage), MB_OKCANCEL | MB_ICONEXCLAMATION); |
| | | if (ret != IDOK) { |
| | | return 0; |
| | | } |
| | | |
| | | //if (userManager.isLoggedIn()) { |
| | | // userManager.logout(); |
| | | // m_pTopToolbar->SetOperatorBtnText(_T("未登录")); |
| | | //} |
| | | logManager.log(SystemLogManager::LogType::Info, _T("退出登录!")); |
| | | userManager.logout(); |
| | | } |
| | | |
| | | UpdateLoginStatus(); |
| | | } |
| | | |
| | | return 0; |
| | |
| | | return pDlg; |
| | | } |
| | | |
| | | void CBondEqDlg::ShowLoginDlg() |
| | | void CBondEqDlg::UpdateLoginStatus() |
| | | { |
| | | CLoginDlg loginDlg; |
| | | loginDlg.DoModal(); |
| | | |
| | | HMENU hMenu = m_pTopToolbar->GetOperatorMenu(); |
| | | UserManager& userManager = UserManager::getInstance(); |
| | | if (userManager.isLoggedIn()) |
| | | { |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_LOGIN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_CHANGE_PASSWORD, MF_BYCOMMAND | MF_ENABLED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_SYSTEM_LOG, MF_BYCOMMAND | MF_ENABLED); |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_SWITCH, MF_BYCOMMAND | MF_ENABLED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_LOGOUT, MF_BYCOMMAND | MF_ENABLED); |
| | | |
| | | if (userManager.getCurrentUserRole() == UserRole::SuperAdmin) { |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_USER_MANAGER, MF_BYCOMMAND | MF_ENABLED); |
| | | } |
| | | else { |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_USER_MANAGER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | } |
| | | |
| | | m_pTopToolbar->SetOperatorBtnText(userManager.getCurrentUser().c_str()); |
| | | } |
| | | else { |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_LOGIN, MF_BYCOMMAND | MF_ENABLED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_CHANGE_PASSWORD, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_USER_MANAGER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_SYSTEM_LOG, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_SWITCH, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_LOGOUT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | |
| | | m_pTopToolbar->SetOperatorBtnText(_T("未登录")); |
| | | } |
| | | } |