CTSManager.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. 
  2. // CTSManager.cpp: 定义应用程序的类行为。
  3. //
  4. #include "pch.h"
  5. #include "framework.h"
  6. #include "afxwinappex.h"
  7. #include "afxdialogex.h"
  8. #include "CTSManager.h"
  9. #include "MainFrm.h"
  10. #include "ChildFrm.h"
  11. #include "CTSManagerDoc.h"
  12. #include "CTSManagerView.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #endif
  16. #define _STR_HOST_ "10.201.44.26"
  17. #define _STR_USER_ "root"
  18. #define _STR_PASSWD_ "Root@123"
  19. #define _STR_DBNAME_ "scbc_cts"
  20. #include "Database.h"
  21. // CCTSManagerApp
  22. BEGIN_MESSAGE_MAP(CCTSManagerApp, CWinAppEx)
  23. ON_COMMAND(ID_APP_ABOUT, &CCTSManagerApp::OnAppAbout)
  24. // 基于文件的标准文档命令
  25. ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
  26. ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
  27. // 标准打印设置命令
  28. ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinAppEx::OnFilePrintSetup)
  29. END_MESSAGE_MAP()
  30. // CCTSManagerApp 构造
  31. CCTSManagerApp::CCTSManagerApp() noexcept
  32. {
  33. m_bHiColorIcons = TRUE;
  34. // 支持重新启动管理器
  35. m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_ALL_ASPECTS;
  36. #ifdef _MANAGED
  37. // 如果应用程序是利用公共语言运行时支持(/clr)构建的,则:
  38. // 1) 必须有此附加设置,“重新启动管理器”支持才能正常工作。
  39. // 2) 在您的项目中,您必须按照生成顺序向 System.Windows.Forms 添加引用。
  40. System::Windows::Forms::Application::SetUnhandledExceptionMode(System::Windows::Forms::UnhandledExceptionMode::ThrowException);
  41. #endif
  42. // TODO: 将以下应用程序 ID 字符串替换为唯一的 ID 字符串;建议的字符串格式
  43. //为 CompanyName.ProductName.SubProduct.VersionInformation
  44. SetAppID(_T("CTSManager.AppID.NoVersion"));
  45. // TODO: 在此处添加构造代码,
  46. // 将所有重要的初始化放置在 InitInstance 中
  47. }
  48. // 唯一的 CCTSManagerApp 对象
  49. CCTSManagerApp theApp;
  50. // CCTSManagerApp 初始化
  51. BOOL CCTSManagerApp::InitInstance()
  52. {
  53. // 如果一个运行在 Windows XP 上的应用程序清单指定要
  54. // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
  55. //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。
  56. INITCOMMONCONTROLSEX InitCtrls;
  57. InitCtrls.dwSize = sizeof(InitCtrls);
  58. // 将它设置为包括所有要在应用程序中使用的
  59. // 公共控件类。
  60. InitCtrls.dwICC = ICC_WIN95_CLASSES;
  61. InitCommonControlsEx(&InitCtrls);
  62. CWinAppEx::InitInstance();
  63. #if 0 // 用例演示;
  64. // 创建mysql对象;
  65. MYSQL* pConn = mysql_init(NULL); // 会调用mysql_library_init;
  66. // 如果要多线程使用,必须在线程开始处调用;
  67. mysql_thread_init(); //在mysql_init后调用;
  68. const char* perr = mysql_error(pConn);
  69. if (pConn) {
  70. // 创建连接;
  71. if (mysql_real_connect(pConn, _STR_HOST_, _STR_USER_, _STR_PASSWD_, _STR_DBNAME_, 0, NULL, 0)) {
  72. // 查询数据库的表;
  73. if (mysql_query(pConn, "show tables;"))
  74. {
  75. return FALSE;
  76. }
  77. // 获取数据;
  78. MYSQL_RES* pres = mysql_store_result(pConn);
  79. if (pres != NULL) {
  80. MYSQL_ROW row;
  81. unsigned int rlen = mysql_num_fields(pres);
  82. // 打印行数据;
  83. while ((row = mysql_fetch_row(pres))) {
  84. for (unsigned int i = 0; i < rlen; i++) {
  85. OutputDebugString(mysql_fetch_field(pres)->name);
  86. OutputDebugString("=");
  87. OutputDebugString(row[i]);
  88. OutputDebugString("\n");
  89. }
  90. }
  91. // 释放结果内存;
  92. mysql_free_result(pres);
  93. }
  94. }
  95. // 释放连接对象;
  96. mysql_close(pConn);
  97. }
  98. // 对应mysql_thread_init,在线程结束时调用;
  99. mysql_thread_end();
  100. // 释放mysql库;
  101. mysql_library_end();
  102. #endif
  103. #ifdef _DEBUG
  104. CDatabase db;
  105. if (db.Init(_STR_HOST_, _STR_USER_, _STR_PASSWD_, _STR_DBNAME_))
  106. {
  107. if (0) {
  108. db.InserSoc(_T("RT2851C"), _T("RealTealk"), _T("RTK台湾"));
  109. db.InserSoc(_T("RT2851M"), _T("RealTealk2"), _T("RTK台湾"));
  110. std::vector<STSOC> vtSOC;
  111. db.QuerySoc(vtSOC);
  112. for (std::vector<STSOC>::iterator it = vtSOC.begin(); it != vtSOC.end(); it++) {
  113. TRACE3(_T("name=%s, provider=%s, note=%s\n"), it->name.c_str(), it->provider.c_str(), it->note.c_str());
  114. it->note = _T("xxxx1111xxx");
  115. db.UpdateSoc(it->name, *it);
  116. }
  117. }
  118. if (0) {
  119. CFile file;
  120. BYTE* pImage = NULL;
  121. DWORD dwLength = 0;
  122. if (file.Open(_T("D:\\桌面\\logo\\channels\\AccuWeather.png"), CFile::modeRead))
  123. {
  124. dwLength = file.GetLength();
  125. pImage = new BYTE[dwLength];
  126. file.Read(pImage, dwLength);
  127. file.Close();
  128. }
  129. db.SetBinaryField("update brand set logo = ? where `name`='SCBC'", pImage, dwLength);
  130. if (pImage)
  131. delete[]pImage;
  132. pImage = NULL;
  133. dwLength = 0;
  134. }
  135. if (0)
  136. {
  137. BYTE* pImage = NULL;
  138. DWORD dwLength = 0;
  139. db.GetBinaryField("select logo from brand where `name`='SCBC';", (void**)&pImage, dwLength);
  140. CFile file;
  141. if (file.Open(_T("D:\\11.png"), CFile::modeCreate | CFile::modeWrite))
  142. {
  143. file.Write(pImage, dwLength);
  144. file.Close();
  145. }
  146. }
  147. }
  148. #endif
  149. // 初始化 OLE 库
  150. if (!AfxOleInit())
  151. {
  152. AfxMessageBox(IDP_OLE_INIT_FAILED);
  153. return FALSE;
  154. }
  155. AfxEnableControlContainer();
  156. EnableTaskbarInteraction();
  157. // 使用 RichEdit 控件需要 AfxInitRichEdit2()
  158. // AfxInitRichEdit2();
  159. // 标准初始化
  160. // 如果未使用这些功能并希望减小
  161. // 最终可执行文件的大小,则应移除下列
  162. // 不需要的特定初始化例程
  163. // 更改用于存储设置的注册表项
  164. // TODO: 应适当修改该字符串,
  165. // 例如修改为公司或组织名
  166. SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
  167. LoadStdProfileSettings(4); // 加载标准 INI 文件选项(包括 MRU)
  168. InitContextMenuManager();
  169. InitShellManager();
  170. InitKeyboardManager();
  171. InitTooltipManager();
  172. CMFCToolTipInfo ttParams;
  173. ttParams.m_bVislManagerTheme = TRUE;
  174. theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
  175. RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
  176. // 注册应用程序的文档模板。 文档模板
  177. // 将用作文档、框架窗口和视图之间的连接
  178. CMultiDocTemplate* pDocTemplate;
  179. pDocTemplate = new CMultiDocTemplate(IDR_CTSManagerTYPE,
  180. RUNTIME_CLASS(CCTSManagerDoc),
  181. RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
  182. RUNTIME_CLASS(CCTSManagerView));
  183. if (!pDocTemplate)
  184. return FALSE;
  185. AddDocTemplate(pDocTemplate);
  186. // 创建主 MDI 框架窗口
  187. CMainFrame* pMainFrame = new CMainFrame;
  188. if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
  189. {
  190. delete pMainFrame;
  191. return FALSE;
  192. }
  193. m_pMainWnd = pMainFrame;
  194. // 分析标准 shell 命令、DDE、打开文件操作的命令行
  195. CCommandLineInfo cmdInfo;
  196. ParseCommandLine(cmdInfo);
  197. // 调度在命令行中指定的命令。 如果
  198. // 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
  199. if (!ProcessShellCommand(cmdInfo))
  200. return FALSE;
  201. // 主窗口已初始化,因此显示它并对其进行更新
  202. pMainFrame->ShowWindow(m_nCmdShow);
  203. pMainFrame->UpdateWindow();
  204. return TRUE;
  205. }
  206. int CCTSManagerApp::ExitInstance()
  207. {
  208. //TODO: 处理可能已添加的附加资源
  209. AfxOleTerm(FALSE);
  210. return CWinAppEx::ExitInstance();
  211. }
  212. // CCTSManagerApp 消息处理程序
  213. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  214. class CAboutDlg : public CDialogEx
  215. {
  216. public:
  217. CAboutDlg() noexcept;
  218. // 对话框数据
  219. #ifdef AFX_DESIGN_TIME
  220. enum { IDD = IDD_ABOUTBOX };
  221. #endif
  222. protected:
  223. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  224. // 实现
  225. protected:
  226. DECLARE_MESSAGE_MAP()
  227. };
  228. CAboutDlg::CAboutDlg() noexcept : CDialogEx(IDD_ABOUTBOX)
  229. {
  230. }
  231. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  232. {
  233. CDialogEx::DoDataExchange(pDX);
  234. }
  235. BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
  236. END_MESSAGE_MAP()
  237. // 用于运行对话框的应用程序命令
  238. void CCTSManagerApp::OnAppAbout()
  239. {
  240. CAboutDlg aboutDlg;
  241. aboutDlg.DoModal();
  242. }
  243. // CCTSManagerApp 自定义加载/保存方法
  244. void CCTSManagerApp::PreLoadState()
  245. {
  246. BOOL bNameValid;
  247. CString strName;
  248. bNameValid = strName.LoadString(IDS_EDIT_MENU);
  249. ASSERT(bNameValid);
  250. GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EDIT);
  251. bNameValid = strName.LoadString(IDS_EXPLORER);
  252. ASSERT(bNameValid);
  253. GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EXPLORER);
  254. }
  255. void CCTSManagerApp::LoadCustomState()
  256. {
  257. }
  258. void CCTSManagerApp::SaveCustomState()
  259. {
  260. }
  261. // CCTSManagerApp 消息处理程序