OAM.CPP
上传用户:shgx688
上传日期:2009-12-27
资源大小:855k
文件大小:8k
源码类别:

SNMP编程

开发平台:

MultiPlatform

  1. // OAM.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "OAM.h"
  5. //#include "CmdTreeSetup.h"
  6. #include "MainFrm.h"
  7. #include "OAMDoc.h"
  8. //#include "OAMView.h"
  9. //#include "snmp_cwdmView.h"
  10. //#include "StaProDlg.h"
  11. #include "Splash.h"
  12. #include <locale.h>
  13. #include "CreditStatic.h"
  14. #include "CoolControlsManager.h"
  15. #include "Agent.h"
  16. #include "MainView.h"
  17. #include "loginDialog.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // COAMApp
  25. BEGIN_MESSAGE_MAP(COAMApp, CWinApp)
  26. //{{AFX_MSG_MAP(COAMApp)
  27. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  28. //}}AFX_MSG_MAP
  29. // Standard file based document commands
  30. // ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  31. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  32. // Standard print setup command
  33. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // COAMApp construction
  37. COAMApp::COAMApp()
  38. {
  39. // TODO: add construction code here,
  40. // Place all significant initialization in InitInstance
  41. }
  42. /////////////////////////////////////////////////////////////////////////////
  43. // The one and only COAMApp object
  44. COAMApp theApp;
  45. /////////////////////////////////////////////////////////////////////////////
  46. // COAMApp initialization
  47. BOOL COAMApp::InitInstance()
  48. {
  49.    
  50.    INITCOMMONCONTROLSEX icex;
  51.    icex.dwSize = sizeof( icex );
  52.    icex.dwICC = ICC_DATE_CLASSES | ICC_INTERNET_CLASSES;
  53.    VERIFY( InitCommonControlsEx( &icex ) );
  54.    AfxOleInit();
  55.    AfxInitRichEdit();
  56.    AfxEnableControlContainer();
  57.    // Install the CoolControls 
  58.     GetCtrlManager().InstallHook(-1,TRUE);
  59. // CG: The following block was inserted by 'Status Bar' component.
  60. {
  61. //Set up date and time defaults so they're the same as system defaults
  62. setlocale(LC_ALL, "");
  63. }
  64. // CG: The following block was added by the Splash Screen component. { CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash); }
  65. /* if (!AfxSocketInit())
  66. {
  67. AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
  68. return FALSE;
  69. }*/
  70. AfxEnableControlContainer();
  71. /*connect database*/
  72. ////////////连接数据库//////////////
  73. HRESULT hr;
  74. try
  75. {
  76. hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
  77. if(SUCCEEDED(hr))
  78. {
  79. hr = m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb","","",adModeUnknown);///连接数据库
  80. }
  81. }
  82. catch(_com_error e)///捕捉异常
  83. {
  84. CString errormessage;
  85. errormessage.Format("连接数据库失败!rn错误信息:%s",e.ErrorMessage());
  86. AfxMessageBox(errormessage);///显示错误信息
  87. return FALSE;
  88. #ifdef _AFXDLL
  89. Enable3dControls(); // Call this when using MFC in a shared DLL
  90. #else
  91. Enable3dControlsStatic(); // Call this when linking to MFC statically
  92. #endif
  93. // Change the registry key under which our settings are stored.
  94. // TODO: You should modify this string to be something appropriate
  95. // such as the name of your company or organization.
  96. SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  97. LoadStdProfileSettings(0);  // Load standard INI file options (including MRU)
  98. // Register the application's document templates.  Document templates
  99. //  serve as the connection between documents, frame windows and views.
  100.    CLoginDialog dlg_login; /*登录*/
  101.     if(dlg_login.DoModal()==IDCANCEL)
  102. {
  103. exit(0);
  104. }
  105. //
  106. CSingleDocTemplate* pDocTemplate;
  107. pDocTemplate = new CSingleDocTemplate(
  108. IDR_MAINFRAME,
  109. RUNTIME_CLASS(COAMDoc),
  110. RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  111.     RUNTIME_CLASS(CMainView));
  112. AddDocTemplate(pDocTemplate);
  113. // Parse command line for standard shell commands, DDE, file open
  114. CCommandLineInfo cmdInfo;
  115. ParseCommandLine(cmdInfo);
  116. // Dispatch commands specified on the command line
  117. if (!ProcessShellCommand(cmdInfo))
  118. return FALSE;
  119. // The one and only window has been initialized, so show and update it.
  120. m_pMainWnd->ShowWindow(SW_SHOW);//MAXIMIZED);
  121. m_pMainWnd->CenterWindow();
  122.    
  123. if(::IsWindow(((CMainFrame*)m_pMainWnd)->m_wndReportBar.m_hWnd))
  124. ((CMainFrame*)m_pMainWnd)->m_wndReportBar.WriteReportLine("启动介质转换器管理系统", 0);
  125.  
  126. ((CMainFrame*)m_pMainWnd)->m_wndReportBar.WriteReportLine("欢迎进入snmp管理系统", 0);
  127. ((CMainFrame*)m_pMainWnd)->m_wndReportBar.WriteReportLine("当前您登录的用户名为", 0);
  128. ((CMainFrame*)m_pMainWnd)->m_wndReportBar.WriteReportLine(dlg_login.m_user, 0);
  129. ((CMainFrame*)m_pMainWnd)->m_wndReportBar.WriteReportLine("*******************", 0); 
  130.     
  131. if (dlg_login.power=="超级用户") /*用于权限管理*/
  132.   ((CMainFrame*)m_pMainWnd)->m_power= 1;
  133. else
  134.        ((CMainFrame*)m_pMainWnd)->m_power=0; 
  135. CAgent dlg;
  136. ((CMainFrame*)m_pMainWnd)->m_agent =dlg.m_agent;
  137.        // DWORD IpAddress;
  138. if(dlg.DoModal()==IDCANCEL)
  139. {
  140. ((CMainFrame*)m_pMainWnd)->m_wndReportBar.WriteReportLine("请设置代理相应的信息", 0);
  141. }
  142.     else
  143. {
  144.   
  145. ((CMainFrame*)m_pMainWnd)->m_wndReportBar.WriteReportLine("当前管理代理设备ip", 0);
  146. ((CMainFrame*)m_pMainWnd)->m_wndReportBar.WriteReportLine(dlg.m_agent, 0);
  147. ((CMainFrame*)m_pMainWnd)->m_wndReportBar.WriteReportLine("当前管理社区标志", 0);
  148. ((CMainFrame*)m_pMainWnd)->m_wndReportBar.WriteReportLine(dlg.m_community, 0);
  149. ((CMainFrame*)m_pMainWnd)->m_agent =dlg.m_agent;
  150. ((CMainFrame*)m_pMainWnd)->m_community =dlg.m_community;
  151. if (!(dlg.m_agent)||!(dlg.m_community))
  152. ((CMainFrame*)m_pMainWnd)->m_wndReportBar.WriteReportLine("请输入代理设备的信息", 0);
  153. }
  154. return TRUE;
  155. }
  156. /////////////////////////////////////////////////////////////////////////////
  157. // CAboutDlg dialog used for App About
  158. class CAboutDlg : public CDialog
  159. {
  160. public:
  161. CAboutDlg();
  162. // Dialog Data
  163. //{{AFX_DATA(CAboutDlg)
  164. enum { IDD = IDD_ABOUTBOX };
  165. CCreditStatic m_wndCredit;
  166. //}}AFX_DATA
  167. // ClassWizard generated virtual function overrides
  168. //{{AFX_VIRTUAL(CAboutDlg)
  169. protected:
  170. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  171. //}}AFX_VIRTUAL
  172. // Implementation
  173. protected:
  174. //{{AFX_MSG(CAboutDlg)
  175. virtual BOOL OnInitDialog();
  176. //}}AFX_MSG
  177. DECLARE_MESSAGE_MAP()
  178. };
  179. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  180. {
  181. //{{AFX_DATA_INIT(CAboutDlg)
  182. //}}AFX_DATA_INIT
  183. }
  184. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  185. {
  186. CDialog::DoDataExchange(pDX);
  187. //{{AFX_DATA_MAP(CAboutDlg)
  188. DDX_Control(pDX, IDC_STATIC_CREDIT, m_wndCredit);
  189. //}}AFX_DATA_MAP
  190. }
  191. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  192. //{{AFX_MSG_MAP(CAboutDlg)
  193. //}}AFX_MSG_MAP
  194. END_MESSAGE_MAP()
  195. // App command to run the dialog
  196. void COAMApp::OnAppAbout()
  197. {
  198. CAboutDlg aboutDlg;
  199. aboutDlg.DoModal();
  200. }
  201. /////////////////////////////////////////////////////////////////////////////
  202. // COAMApp message handlers
  203. BOOL CAboutDlg::OnInitDialog() 
  204. {
  205. CDialog::OnInitDialog();
  206. // TODO: Add extra initialization here
  207. m_wndCredit.SetCredits(IDS_CREDIT);
  208. m_wndCredit.SetSpeed(DISPLAY_SLOW);
  209. m_wndCredit.SetColor(BACKGROUND_COLOR, RGB(192,192,192));
  210. m_wndCredit.SetColor(NORMAL_TEXT_COLOR, RGB(0,0,255));
  211. m_wndCredit.StartScrolling();
  212. return TRUE;  // return TRUE unless you set the focus to a control
  213.               // EXCEPTION: OCX Property Pages should return FALSE
  214. }
  215. int COAMApp::ExitInstance() 
  216. {
  217.  if(m_pConnection->State)
  218.  m_pConnection->Close();
  219. return CWinApp::ExitInstance();
  220. }