HoursTestDlg.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. // HoursTestDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "HoursTest.h"
  5. #include "HoursTestDlg.h"
  6. #include "Winsock2.h"
  7. #include ".\hourstestdlg.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CHoursTestDlg dialog
  15. CHoursTestDlg::CHoursTestDlg(CWnd* pParent /*=NULL*/)
  16. : CDialog(CHoursTestDlg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CHoursTestDlg)
  19. m_odtDate = COleDateTime::GetCurrentTime();
  20. m_odtTime = COleDateTime::GetCurrentTime();
  21. m_strVerbose = _T("");
  22. //}}AFX_DATA_INIT
  23. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  24. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  25. }
  26. void CHoursTestDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CHoursTestDlg)
  30. DDX_DateTimeCtrl(pDX, IDC_DATE, m_odtDate);
  31. DDX_DateTimeCtrl(pDX, IDC_TIME, m_odtTime);
  32. DDX_Text(pDX, IDC_VERBOSE, m_strVerbose);
  33. DDX_Control(pDX, IDC_HOURSSELECTOR, m_hsTimes);
  34. //}}AFX_DATA_MAP
  35. }
  36. BEGIN_MESSAGE_MAP(CHoursTestDlg, CDialog)
  37. //{{AFX_MSG_MAP(CHoursTestDlg)
  38. ON_WM_PAINT()
  39. ON_WM_QUERYDRAGICON()
  40. ON_BN_CLICKED(IDC_CHECK, OnCheck)
  41. //}}AFX_MSG_MAP
  42. ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
  43. ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CHoursTestDlg message handlers
  47. BOOL CHoursTestDlg::OnInitDialog()
  48. {
  49. CDialog::OnInitDialog();
  50. m_hsTimes.SetFocus();
  51. // Set the icon for this dialog. The framework does this automatically
  52. // when the application's main window is not a dialog
  53. SetIcon(m_hIcon, TRUE); // Set big icon
  54. SetIcon(m_hIcon, FALSE); // Set small icon
  55. // TODO: Add extra initialization here
  56. return TRUE; // return TRUE unless you set the focus to a control
  57. }
  58. // If you add a minimize button to your dialog, you will need the code below
  59. // to draw the icon. For MFC applications using the document/view model,
  60. // this is automatically done for you by the framework.
  61. void CHoursTestDlg::OnPaint()
  62. {
  63. if (IsIconic())
  64. {
  65. CPaintDC dc(this); // device context for painting
  66. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  67. // Center icon in client rectangle
  68. int cxIcon = GetSystemMetrics(SM_CXICON);
  69. int cyIcon = GetSystemMetrics(SM_CYICON);
  70. CRect rect;
  71. GetClientRect(&rect);
  72. int x = (rect.Width() - cxIcon + 1) / 2;
  73. int y = (rect.Height() - cyIcon + 1) / 2;
  74. // Draw the icon
  75. dc.DrawIcon(x, y, m_hIcon);
  76. }
  77. else
  78. {
  79. CDialog::OnPaint();
  80. }
  81. }
  82. // The system calls this to obtain the cursor to display while the user drags
  83. // the minimized window.
  84. HCURSOR CHoursTestDlg::OnQueryDragIcon()
  85. {
  86. return (HCURSOR) m_hIcon;
  87. }
  88. BEGIN_EVENTSINK_MAP(CHoursTestDlg, CDialog)
  89. //{{AFX_EVENTSINK_MAP(CHoursTestDlg)
  90. ON_EVENT(CHoursTestDlg, IDC_HOURSSELECTOR, 1 /* Verbose */, OnVerboseHoursselector, VTS_BSTR)
  91. //}}AFX_EVENTSINK_MAP
  92. END_EVENTSINK_MAP()
  93. void CHoursTestDlg::OnCheck()
  94. {
  95. UpdateData();
  96. COleSafeArray l_osaHours;
  97. unsigned char szArray[7][24];
  98. l_osaHours = m_hsTimes.GetHoursArray();
  99. unsigned char cBits;
  100. long m = 0;
  101. CString str,s;
  102. // Load the Information from the Grid to an Array
  103. for( int x=0; x<7; x++)
  104. {
  105. for(int y=0; y<24; y++)
  106. {
  107. m = long(x*24+y);
  108. l_osaHours.GetElement(&m, &cBits);
  109. szArray[x][y]= cBits;
  110. s.Format("%02d ",szArray[x][y]);
  111. str+=s;
  112. }
  113. str+="\n";
  114. }//AfxMessageBox(str);
  115. DealArray(szArray);
  116. //COleDateTime l_odtDate(m_odtDate.GetYear(), m_odtDate.GetMonth(), m_odtDate.GetDay(),
  117. // m_odtTime.GetHour(), m_odtTime.GetMinute(), m_odtTime.GetSecond());
  118. //long lOffset = ( ( ( l_odtDate.GetDayOfWeek() - 1 ) * 1440 ) + ( l_odtDate.GetHour() * 60 ) + l_odtDate.GetMinute() ) / 15;
  119. //int nByte = lOffset / 8;
  120. //int nBit = lOffset - (nByte * 8);
  121. //if( ( ( szArray[nByte]>> nBit ) & 0x01 ) == 0x01 )
  122. //{
  123. // MessageBox("Time Selected");
  124. //}
  125. //else
  126. //{
  127. // if( MessageBox("Time Not Selected\x0A\x0A Set Time?",NULL, MB_YESNO)==IDYES)
  128. // {
  129. // unsigned char cBits = (1 << nBit);
  130. // szArray[nByte] |= cBits;
  131. // for(long x=0; x<84; x++) {
  132. // l_osaHours.PutElement(&x, &szArray[x]);
  133. // }
  134. // m_hsTimes.SetHoursArray(l_osaHours);
  135. // }
  136. //}
  137. }
  138. void CHoursTestDlg::OnVerboseHoursselector(LPCTSTR pszVerbose)
  139. {
  140. m_strVerbose = pszVerbose;
  141. UpdateData(FALSE);
  142. }
  143. void CHoursTestDlg::DealArray(unsigned char nBuf[7][24])
  144. {
  145. CString s,sTemp,str;
  146. CString sReport[500];
  147. int nReportIndex = 0;
  148. for( int y=0; y<7; y++)
  149. {
  150. for(int x=0; x<24; x++)
  151. {
  152. if(nBuf[y][x] == 15)
  153. {
  154. sTemp.Format("%02d%02d",y,x);
  155. sReport[nReportIndex] = sTemp;
  156. for(int x1 = x+1; x1<24; x1++)
  157. {
  158. if(nBuf[y][x1] == 15)
  159. {
  160. sTemp.Format("%02d%02d",y,x1);
  161. sReport[nReportIndex] += sTemp;
  162. }
  163. else
  164. {
  165. x = x1;
  166. break;
  167. }
  168. if(nBuf[y][x1] == 15 && x1 == 23)
  169. {
  170. x = x1;
  171. break;
  172. }
  173. }
  174. s.Format("%s",sReport[nReportIndex]);
  175. //AfxMessageBox(s);
  176. nReportIndex++;
  177. str+=s;
  178. str+="\n";
  179. }
  180. }
  181. }
  182. //AfxMessageBox(str);
  183. ////////////////////////////////////////////////////////////////
  184. int nResultIndex = 0;
  185. int iSign = 0;
  186. CString sResult[500];
  187. bool bFlag[500];
  188. int i = 0,j = 0;
  189. for( i=0;i<500;i++ )
  190. bFlag[i] = true;
  191. for( i=0;i<nReportIndex;i++ )
  192. {
  193. iSign = 1;
  194. if(bFlag[i])
  195. {
  196. sResult[nResultIndex] = sReport[i];
  197. //sResult[nResultIndex] += "\n";
  198. }
  199. for( j=i+1;j<nReportIndex;j++ )
  200. {
  201. if( sReport[i].GetLength() == sReport[j].GetLength() && bFlag[i] && bFlag[j])
  202. {
  203. if( CompareStr(sReport[i],sReport[j],iSign) )
  204. {
  205. sResult[nResultIndex] += sReport[j];
  206. //sResult[nResultIndex] += "\n";
  207. bFlag[j] = false;
  208. iSign++;
  209. //break;
  210. }
  211. }
  212. }
  213. if(bFlag[i])
  214. {
  215. bFlag[i] = false;
  216. nResultIndex++;
  217. }
  218. }
  219. ///////////////////////////////////////////////////////////////////////////
  220. CString sWeek1,sWeek2,sHour1,sHour2;
  221. for( int x=0; x<nResultIndex; x++)
  222. {
  223. //AfxMessageBox(sResult[x]);
  224. sHour1 = sResult[x].Mid(2,2);
  225. switch(atoi(sResult[x].Mid(0,2)))
  226. {
  227. case 0:
  228. sWeek1 = "星期日";break;
  229. case 1:
  230. sWeek1 = "星期一";break;
  231. case 2:
  232. sWeek1 = "星期二";break;
  233. case 3:
  234. sWeek1 = "星期三";break;
  235. case 4:
  236. sWeek1 = "星期四";break;
  237. case 5:
  238. sWeek1 = "星期五";break;
  239. case 6:
  240. sWeek1 = "星期六";break;
  241. }
  242. sHour2 = sResult[x].Mid(sResult[x].GetLength()-2,2);
  243. switch(atoi(sResult[x].Mid(sResult[x].GetLength()-4,2)))
  244. {
  245. case 0:
  246. sWeek2 = "星期日";break;
  247. case 1:
  248. sWeek2 = "星期一";break;
  249. case 2:
  250. sWeek2 = "星期二";break;
  251. case 3:
  252. sWeek2 = "星期三";break;
  253. case 4:
  254. sWeek2 = "星期四";break;
  255. case 5:
  256. sWeek2 = "星期五";break;
  257. case 6:
  258. sWeek2 = "星期六";break;
  259. }
  260. CString sData;
  261. sData.Format("(%s-%s) %s--%s",sWeek1,sWeek2,sHour1,sHour2);
  262. AfxMessageBox(sData);
  263. }
  264. //CString sData;
  265. //sData.Format("(%s-%s) %s:%s",sWeek1,sWeek2,sHour1,sHour2);
  266. //m_strVerbose = sData;
  267. //UpdateData(false);
  268. //AfxMessageBox(sData);
  269. }
  270. bool CHoursTestDlg::CompareStr(CString str1, CString str2,int nSign)
  271. {
  272. bool bResult = false;
  273. if( atoi(str1.Mid(0,2)) == atoi(str2.Mid(0,2)) && atoi(str1.Mid(2,2))+nSign == atoi(str2.Mid(2,2)) )
  274. bResult = true;
  275. if( atoi(str1.Mid(0,2))+nSign == atoi(str2.Mid(0,2)) && atoi(str1.Mid(2,2)) == atoi(str2.Mid(2,2)) )
  276. bResult = true;
  277. return bResult;
  278. }
  279. void CHoursTestDlg::OnBnClickedButton1()
  280. {
  281. m_hsTimes.SetDBInfo("192.168.2.32","IvsSvr","sa","");
  282. CString str;
  283. str = "192.168.2.5";
  284. long nPCIP = inet_addr(str);
  285. nPCIP = ntohl(nPCIP);
  286. str = "192.168.2.101";
  287. long nDvsIP = inet_addr(str);
  288. nDvsIP = ntohl(nDvsIP);
  289. m_hsTimes.SetDvsInfo(nPCIP,0,nDvsIP,0);
  290. m_hsTimes.WriteDataBase();
  291. }
  292. void CHoursTestDlg::OnBnClickedButton2()
  293. {
  294. m_hsTimes.SetDBInfo("192.168.2.32","IvsSvr","sa","");
  295. CString str;
  296. //str = "192.168.2.7";
  297. //long nPCIP = inet_addr(str);
  298. //nPCIP = ntohl(nPCIP);
  299. //str = "192.168.2.101";
  300. //long nDvsIP = inet_addr(str);
  301. //nDvsIP = ntohl(nDvsIP);
  302. //m_hsTimes.SetDvsInfo(nPCIP,0,nDvsIP,0);
  303. str = "192.168.2.5";
  304. long nPCIP = inet_addr(str);
  305. nPCIP = ntohl(nPCIP);
  306. m_hsTimes.GetDetectDate(nPCIP,0,0,0);
  307. }