123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
-
- // CTSManager.cpp: 定义应用程序的类行为。
- //
- #include "pch.h"
- #include "framework.h"
- #include "afxwinappex.h"
- #include "afxdialogex.h"
- #include "CTSManager.h"
- #include "MainFrm.h"
- #include "ChildFrm.h"
- #include "CTSManagerDoc.h"
- #include "CTSManagerView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- #define _STR_HOST_ "10.201.44.26"
- #define _STR_USER_ "root"
- #define _STR_PASSWD_ "Root@123"
- #define _STR_DBNAME_ "scbc_cts"
- #include "Database.h"
- // CCTSManagerApp
- BEGIN_MESSAGE_MAP(CCTSManagerApp, CWinAppEx)
- ON_COMMAND(ID_APP_ABOUT, &CCTSManagerApp::OnAppAbout)
- // 基于文件的标准文档命令
- ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
- ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
- // 标准打印设置命令
- ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinAppEx::OnFilePrintSetup)
- END_MESSAGE_MAP()
- // CCTSManagerApp 构造
- CCTSManagerApp::CCTSManagerApp() noexcept
- {
- m_bHiColorIcons = TRUE;
- // 支持重新启动管理器
- m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_ALL_ASPECTS;
- #ifdef _MANAGED
- // 如果应用程序是利用公共语言运行时支持(/clr)构建的,则:
- // 1) 必须有此附加设置,“重新启动管理器”支持才能正常工作。
- // 2) 在您的项目中,您必须按照生成顺序向 System.Windows.Forms 添加引用。
- System::Windows::Forms::Application::SetUnhandledExceptionMode(System::Windows::Forms::UnhandledExceptionMode::ThrowException);
- #endif
- // TODO: 将以下应用程序 ID 字符串替换为唯一的 ID 字符串;建议的字符串格式
- //为 CompanyName.ProductName.SubProduct.VersionInformation
- SetAppID(_T("CTSManager.AppID.NoVersion"));
- // TODO: 在此处添加构造代码,
- // 将所有重要的初始化放置在 InitInstance 中
- }
- // 唯一的 CCTSManagerApp 对象
- CCTSManagerApp theApp;
- // CCTSManagerApp 初始化
- BOOL CCTSManagerApp::InitInstance()
- {
- // 如果一个运行在 Windows XP 上的应用程序清单指定要
- // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
- //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。
- INITCOMMONCONTROLSEX InitCtrls;
- InitCtrls.dwSize = sizeof(InitCtrls);
- // 将它设置为包括所有要在应用程序中使用的
- // 公共控件类。
- InitCtrls.dwICC = ICC_WIN95_CLASSES;
- InitCommonControlsEx(&InitCtrls);
- CWinAppEx::InitInstance();
- #if 0 // 用例演示;
- // 创建mysql对象;
- MYSQL* pConn = mysql_init(NULL); // 会调用mysql_library_init;
- // 如果要多线程使用,必须在线程开始处调用;
- mysql_thread_init(); //在mysql_init后调用;
- const char* perr = mysql_error(pConn);
- if (pConn) {
- // 创建连接;
- if (mysql_real_connect(pConn, _STR_HOST_, _STR_USER_, _STR_PASSWD_, _STR_DBNAME_, 0, NULL, 0)) {
- // 查询数据库的表;
- if (mysql_query(pConn, "show tables;"))
- {
- return FALSE;
- }
- // 获取数据;
- MYSQL_RES* pres = mysql_store_result(pConn);
- if (pres != NULL) {
- MYSQL_ROW row;
- unsigned int rlen = mysql_num_fields(pres);
- // 打印行数据;
- while ((row = mysql_fetch_row(pres))) {
- for (unsigned int i = 0; i < rlen; i++) {
- OutputDebugString(mysql_fetch_field(pres)->name);
- OutputDebugString("=");
- OutputDebugString(row[i]);
- OutputDebugString("\n");
- }
- }
- // 释放结果内存;
- mysql_free_result(pres);
- }
- }
- // 释放连接对象;
- mysql_close(pConn);
- }
- // 对应mysql_thread_init,在线程结束时调用;
- mysql_thread_end();
- // 释放mysql库;
- mysql_library_end();
- #endif
- #ifdef _DEBUG
- CDatabase db;
- if (db.Init(_STR_HOST_, _STR_USER_, _STR_PASSWD_, _STR_DBNAME_))
- {
- if (0) {
- db.InserSoc(_T("RT2851C"), _T("RealTealk"), _T("RTK台湾"));
- db.InserSoc(_T("RT2851M"), _T("RealTealk2"), _T("RTK台湾"));
- std::vector<STSOC> vtSOC;
- db.QuerySoc(vtSOC);
- for (std::vector<STSOC>::iterator it = vtSOC.begin(); it != vtSOC.end(); it++) {
- TRACE3(_T("name=%s, provider=%s, note=%s\n"), it->name.c_str(), it->provider.c_str(), it->note.c_str());
- it->note = _T("xxxx1111xxx");
- db.UpdateSoc(it->name, *it);
- }
- }
- if (0) {
- CFile file;
- BYTE* pImage = NULL;
- DWORD dwLength = 0;
- if (file.Open(_T("D:\\桌面\\logo\\channels\\AccuWeather.png"), CFile::modeRead))
- {
- dwLength = file.GetLength();
- pImage = new BYTE[dwLength];
- file.Read(pImage, dwLength);
- file.Close();
- }
- db.SetBinaryField("update brand set logo = ? where `name`='SCBC'", pImage, dwLength);
- if (pImage)
- delete[]pImage;
- pImage = NULL;
- dwLength = 0;
- }
- if (0)
- {
- BYTE* pImage = NULL;
- DWORD dwLength = 0;
- db.GetBinaryField("select logo from brand where `name`='SCBC';", (void**)&pImage, dwLength);
- CFile file;
- if (file.Open(_T("D:\\11.png"), CFile::modeCreate | CFile::modeWrite))
- {
- file.Write(pImage, dwLength);
- file.Close();
- }
- }
- }
- #endif
- // 初始化 OLE 库
- if (!AfxOleInit())
- {
- AfxMessageBox(IDP_OLE_INIT_FAILED);
- return FALSE;
- }
- AfxEnableControlContainer();
- EnableTaskbarInteraction();
- // 使用 RichEdit 控件需要 AfxInitRichEdit2()
- // AfxInitRichEdit2();
- // 标准初始化
- // 如果未使用这些功能并希望减小
- // 最终可执行文件的大小,则应移除下列
- // 不需要的特定初始化例程
- // 更改用于存储设置的注册表项
- // TODO: 应适当修改该字符串,
- // 例如修改为公司或组织名
- SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
- LoadStdProfileSettings(4); // 加载标准 INI 文件选项(包括 MRU)
- InitContextMenuManager();
- InitShellManager();
- InitKeyboardManager();
- InitTooltipManager();
- CMFCToolTipInfo ttParams;
- ttParams.m_bVislManagerTheme = TRUE;
- theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
- RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
- // 注册应用程序的文档模板。 文档模板
- // 将用作文档、框架窗口和视图之间的连接
- CMultiDocTemplate* pDocTemplate;
- pDocTemplate = new CMultiDocTemplate(IDR_CTSManagerTYPE,
- RUNTIME_CLASS(CCTSManagerDoc),
- RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
- RUNTIME_CLASS(CCTSManagerView));
- if (!pDocTemplate)
- return FALSE;
- AddDocTemplate(pDocTemplate);
- // 创建主 MDI 框架窗口
- CMainFrame* pMainFrame = new CMainFrame;
- if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
- {
- delete pMainFrame;
- return FALSE;
- }
- m_pMainWnd = pMainFrame;
- // 分析标准 shell 命令、DDE、打开文件操作的命令行
- CCommandLineInfo cmdInfo;
- ParseCommandLine(cmdInfo);
- // 调度在命令行中指定的命令。 如果
- // 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
- if (!ProcessShellCommand(cmdInfo))
- return FALSE;
- // 主窗口已初始化,因此显示它并对其进行更新
- pMainFrame->ShowWindow(m_nCmdShow);
- pMainFrame->UpdateWindow();
- return TRUE;
- }
- int CCTSManagerApp::ExitInstance()
- {
- //TODO: 处理可能已添加的附加资源
- AfxOleTerm(FALSE);
- return CWinAppEx::ExitInstance();
- }
- // CCTSManagerApp 消息处理程序
- // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
- class CAboutDlg : public CDialogEx
- {
- public:
- CAboutDlg() noexcept;
- // 对话框数据
- #ifdef AFX_DESIGN_TIME
- enum { IDD = IDD_ABOUTBOX };
- #endif
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
- // 实现
- protected:
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() noexcept : CDialogEx(IDD_ABOUTBOX)
- {
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialogEx::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
- END_MESSAGE_MAP()
- // 用于运行对话框的应用程序命令
- void CCTSManagerApp::OnAppAbout()
- {
- CAboutDlg aboutDlg;
- aboutDlg.DoModal();
- }
- // CCTSManagerApp 自定义加载/保存方法
- void CCTSManagerApp::PreLoadState()
- {
- BOOL bNameValid;
- CString strName;
- bNameValid = strName.LoadString(IDS_EDIT_MENU);
- ASSERT(bNameValid);
- GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EDIT);
- bNameValid = strName.LoadString(IDS_EXPLORER);
- ASSERT(bNameValid);
- GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EXPLORER);
- }
- void CCTSManagerApp::LoadCustomState()
- {
- }
- void CCTSManagerApp::SaveCustomState()
- {
- }
- // CCTSManagerApp 消息处理程序
|