FATP_FQCDlg.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. // FATP_FQCDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "FATP_FQC.h"
  5. #include "FATP_FQCDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #endif
  9. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  10. class CAboutDlg : public CDialog
  11. {
  12. public:
  13. CAboutDlg();
  14. // 对话框数据
  15. enum { IDD = IDD_ABOUTBOX };
  16. protected:
  17. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  18. // 实现
  19. protected:
  20. DECLARE_MESSAGE_MAP()
  21. };
  22. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  23. {
  24. }
  25. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. }
  29. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  30. END_MESSAGE_MAP()
  31. // CFATP_FQCDlg 对话框
  32. CFATP_FQCDlg::CFATP_FQCDlg(CWnd* pParent /*=NULL*/)
  33. : CDialog(CFATP_FQCDlg::IDD, pParent)
  34. {
  35. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  36. }
  37. void CFATP_FQCDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. DDX_Control(pDX, IDC_LIST1, m_list);
  41. }
  42. BEGIN_MESSAGE_MAP(CFATP_FQCDlg, CDialog)
  43. ON_WM_SYSCOMMAND()
  44. ON_WM_PAINT()
  45. ON_WM_QUERYDRAGICON()
  46. //}}AFX_MSG_MAP
  47. ON_BN_CLICKED(BTN_GET_LOG, &CFATP_FQCDlg::OnBnClickedGetLog)
  48. ON_BN_CLICKED(BTN_SHOP_INIT, &CFATP_FQCDlg::OnBnClickedShopInit)
  49. END_MESSAGE_MAP()
  50. // CFATP_FQCDlg 消息处理程序
  51. BOOL CFATP_FQCDlg::OnInitDialog()
  52. {
  53. CDialog::OnInitDialog();
  54. // 将“关于...”菜单项添加到系统菜单中。
  55. // IDM_ABOUTBOX 必须在系统命令范围内。
  56. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  57. ASSERT(IDM_ABOUTBOX < 0xF000);
  58. CMenu* pSysMenu = GetSystemMenu(FALSE);
  59. if (pSysMenu != NULL)
  60. {
  61. BOOL bNameValid;
  62. CString strAboutMenu;
  63. bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
  64. ASSERT(bNameValid);
  65. if (!strAboutMenu.IsEmpty())
  66. {
  67. pSysMenu->AppendMenu(MF_SEPARATOR);
  68. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  69. }
  70. }
  71. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  72. // 执行此操作
  73. SetIcon(m_hIcon, TRUE); // 设置大图标
  74. SetIcon(m_hIcon, FALSE); // 设置小图标
  75. // TODO: 在此添加额外的初始化代码
  76. // 初始化列表;
  77. m_list.InsertColumn( 0, _T("DSN"));
  78. m_list.SetColumnWidth( 0, 200 );
  79. m_list.InsertColumn( 1, _T("Log"));
  80. m_list.SetColumnWidth( 1, 100 );
  81. m_list.InsertColumn( 2, _T("percent"));
  82. m_list.SetColumnWidth( 2, 120);
  83. m_list.InsertColumn( 3, _T("Result"));
  84. m_list.SetColumnWidth( 3, 100);
  85. #ifdef _DEBUG
  86. TCHAR szLogDir[MAX_PATH] = {0};
  87. _stprintf_s(szLogDir, _T("%s%s"), GLOBAL::g_szModulePath, _T("G9V287002073047H"));
  88. CheckLog(szLogDir);
  89. #endif
  90. return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
  91. }
  92. void CFATP_FQCDlg::OnSysCommand(UINT nID, LPARAM lParam)
  93. {
  94. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  95. {
  96. CAboutDlg dlgAbout;
  97. dlgAbout.DoModal();
  98. }
  99. else
  100. {
  101. CDialog::OnSysCommand(nID, lParam);
  102. }
  103. }
  104. // 如果向对话框添加最小化按钮,则需要下面的代码
  105. // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  106. // 这将由框架自动完成。
  107. void CFATP_FQCDlg::OnPaint()
  108. {
  109. if (IsIconic())
  110. {
  111. CPaintDC dc(this); // 用于绘制的设备上下文
  112. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  113. // 使图标在工作区矩形中居中
  114. int cxIcon = GetSystemMetrics(SM_CXICON);
  115. int cyIcon = GetSystemMetrics(SM_CYICON);
  116. CRect rect;
  117. GetClientRect(&rect);
  118. int x = (rect.Width() - cxIcon + 1) / 2;
  119. int y = (rect.Height() - cyIcon + 1) / 2;
  120. // 绘制图标
  121. dc.DrawIcon(x, y, m_hIcon);
  122. }
  123. else
  124. {
  125. CDialog::OnPaint();
  126. }
  127. }
  128. //当用户拖动最小化窗口时系统调用此函数取得光标
  129. //显示。
  130. HCURSOR CFATP_FQCDlg::OnQueryDragIcon()
  131. {
  132. return static_cast<HCURSOR>(m_hIcon);
  133. }
  134. BOOL CFATP_FQCDlg::CheckLog(CString strLogDir)
  135. {
  136. if ( PathFileExists(strLogDir) )
  137. {
  138. INT nPassLog = 0;
  139. CString strLogFile;
  140. for ( int i = 1; i < 6; i++ )
  141. {
  142. strLogFile.Format(_T("%s\\radar_data_fan_dmesg_%d.log"), strLogDir, i);
  143. if ( !PathFileExists(strLogFile) )
  144. return FALSE;
  145. CStringList listStr;
  146. CString strData = GLOBAL::ReadFileContent(strLogFile);
  147. GLOBAL::GetStringList(strData, _T("\n"), listStr);
  148. INT nPassCount = GLOBAL::CheckListData(listStr);
  149. FLOAT fPercent = (float)nPassCount/(float)(listStr.GetSize()/2)*100;
  150. CString strResult;
  151. strResult.Format(_T("%s,log_%d,%d/%d=%.2f%%,%s"),
  152. m_strDSN,
  153. i,
  154. nPassCount,
  155. listStr.GetSize()/2,
  156. fPercent,
  157. (90.0 < fPercent) ? _T("PASS") : _T("FAIL"));
  158. m_listResult.AddTail(strResult);
  159. INT nItemCount = m_list.GetItemCount();
  160. m_list.InsertItem(nItemCount, m_strDSN);
  161. strResult.Format(_T("Log.%d"), i);
  162. m_list.SetItemText(nItemCount, 1, strResult);
  163. strResult.Format(_T("%d/%d=%.2f%%"), nPassCount, listStr.GetSize()/2, fPercent);
  164. m_list.SetItemText(nItemCount, 2, strResult);
  165. strResult.Format(_T("%s"), (90.0 < fPercent) ? _T("PASS") : _T("FAIL"));
  166. m_list.SetItemText(nItemCount, 3, strResult);
  167. if ( 90.0 < fPercent )
  168. nPassLog++;
  169. UpdateData();
  170. }
  171. GLOBAL::SaveList(m_listResult);
  172. m_listResult.RemoveAll();
  173. if ( nPassLog == 5 )
  174. return TRUE;
  175. }
  176. return FALSE;
  177. }
  178. void CFATP_FQCDlg::OnBnClickedGetLog()
  179. {
  180. // TODO: 在此添加控件通知处理程序代码
  181. CString strStdOutput;
  182. TCHAR szApplicationName[MAX_PATH] = {0};
  183. #ifdef _DEBUG
  184. _stprintf_s(szApplicationName, _T("%s%s"), GLOBAL::g_szModulePath, _T("test.bat"));
  185. #else
  186. _stprintf_s(szApplicationName, _T("%s%s"), GLOBAL::g_szModulePath, _T("radar_data_collection_V03.bat"));
  187. #endif
  188. if ( GLOBAL::StartProcess(szApplicationName, NULL, strStdOutput) )
  189. {
  190. // 获取DSN;
  191. CStringList listDSN;
  192. GLOBAL::GetStringList(strStdOutput, _T("\r\n"), listDSN);
  193. CString strDSN, strTemp;
  194. CString strFindStr = _T("folder is ");
  195. if ( GLOBAL::FindString(listDSN, strFindStr, strDSN) )
  196. {
  197. m_strDSN = strDSN.Mid(strDSN.Find(strFindStr) + strFindStr.GetLength());
  198. m_strDSN.Trim();
  199. strFindStr.Format(_T("[%s][PASS]radar fan data collection"), strDSN);
  200. if ( GLOBAL::FindString(listDSN, strFindStr, strTemp) )
  201. {
  202. CString strLogDir;
  203. strLogDir.Format(_T("%s%s"),GLOBAL::g_szModulePath, strDSN);
  204. if ( CheckLog(strLogDir) )
  205. {
  206. OnBnClickedShopInit();
  207. }
  208. else
  209. {
  210. MessageBox(_T("日志统计失败"), _T("提示"), MB_ICONERROR);
  211. }
  212. }
  213. else
  214. {
  215. MessageBox(_T("未找到关键字<[PASS]radar fan data collection]>,执行结果失败"), _T("提示"), MB_ICONERROR);
  216. }
  217. }
  218. else
  219. {
  220. MessageBox(_T("未找到关键字<folder is>"), _T("提示"), MB_ICONERROR);
  221. }
  222. }
  223. else
  224. {
  225. MessageBox(_T("运行BAT失败"), _T("提示"), MB_ICONERROR);
  226. }
  227. }
  228. void CFATP_FQCDlg::OnBnClickedShopInit()
  229. {
  230. // TODO: 在此添加控件通知处理程序代码
  231. CString strStdOutput;
  232. TCHAR szApplicationName[MAX_PATH] = {0};
  233. _stprintf_s(szApplicationName, _T("%s%s"), GLOBAL::g_szModulePath, _T("radar_tv_set_shop_init_V03.bat"));
  234. if ( GLOBAL::StartProcess(szApplicationName, NULL, strStdOutput) )
  235. {
  236. // 获取DSN;
  237. CStringList listStr;
  238. GLOBAL::GetStringList(strStdOutput, _T("\r\n"), listStr);
  239. CString strResult;
  240. CString strFindStr = _T("[PASS]TV shop init finished ...[PASS]");
  241. if ( GLOBAL::FindString(listStr, strFindStr, strResult) )
  242. {
  243. MessageBox(_T("TV shop init finished ...[PASS]"), _T("提示"), MB_OK);
  244. }
  245. else
  246. {
  247. MessageBox(_T("未找到关键字<[PASS]TV shop init finished ...[PASS]>"), _T("提示"), MB_ICONERROR);
  248. }
  249. }
  250. else
  251. {
  252. MessageBox(_T("运行BAT失败"), _T("提示"), MB_ICONERROR);
  253. }
  254. }