123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- // HoursTestDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "HoursTest.h"
- #include "HoursTestDlg.h"
- #include "Winsock2.h"
- #include ".\hourstestdlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CHoursTestDlg dialog
- CHoursTestDlg::CHoursTestDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CHoursTestDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CHoursTestDlg)
- m_odtDate = COleDateTime::GetCurrentTime();
- m_odtTime = COleDateTime::GetCurrentTime();
- m_strVerbose = _T("");
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CHoursTestDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CHoursTestDlg)
- DDX_DateTimeCtrl(pDX, IDC_DATE, m_odtDate);
- DDX_DateTimeCtrl(pDX, IDC_TIME, m_odtTime);
- DDX_Text(pDX, IDC_VERBOSE, m_strVerbose);
- DDX_Control(pDX, IDC_HOURSSELECTOR, m_hsTimes);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CHoursTestDlg, CDialog)
- //{{AFX_MSG_MAP(CHoursTestDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_CHECK, OnCheck)
- //}}AFX_MSG_MAP
- ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
- ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CHoursTestDlg message handlers
- BOOL CHoursTestDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- m_hsTimes.SetFocus();
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CHoursTestDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CHoursTestDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- BEGIN_EVENTSINK_MAP(CHoursTestDlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CHoursTestDlg)
- ON_EVENT(CHoursTestDlg, IDC_HOURSSELECTOR, 1 /* Verbose */, OnVerboseHoursselector, VTS_BSTR)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
- void CHoursTestDlg::OnCheck()
- {
- UpdateData();
- COleSafeArray l_osaHours;
- unsigned char szArray[7][24];
- l_osaHours = m_hsTimes.GetHoursArray();
-
- unsigned char cBits;
- long m = 0;
- CString str,s;
- // Load the Information from the Grid to an Array
- for( int x=0; x<7; x++)
- {
- for(int y=0; y<24; y++)
- {
- m = long(x*24+y);
- l_osaHours.GetElement(&m, &cBits);
- szArray[x][y]= cBits;
- s.Format("%02d ",szArray[x][y]);
- str+=s;
- }
- str+="\n";
- }//AfxMessageBox(str);
- DealArray(szArray);
- //COleDateTime l_odtDate(m_odtDate.GetYear(), m_odtDate.GetMonth(), m_odtDate.GetDay(),
- // m_odtTime.GetHour(), m_odtTime.GetMinute(), m_odtTime.GetSecond());
- //long lOffset = ( ( ( l_odtDate.GetDayOfWeek() - 1 ) * 1440 ) + ( l_odtDate.GetHour() * 60 ) + l_odtDate.GetMinute() ) / 15;
- //int nByte = lOffset / 8;
- //int nBit = lOffset - (nByte * 8);
- //if( ( ( szArray[nByte]>> nBit ) & 0x01 ) == 0x01 )
- //{
- // MessageBox("Time Selected");
- //}
- //else
- //{
- // if( MessageBox("Time Not Selected\x0A\x0A Set Time?",NULL, MB_YESNO)==IDYES)
- // {
- // unsigned char cBits = (1 << nBit);
- // szArray[nByte] |= cBits;
- // for(long x=0; x<84; x++) {
- // l_osaHours.PutElement(&x, &szArray[x]);
- // }
- // m_hsTimes.SetHoursArray(l_osaHours);
- // }
- //}
- }
- void CHoursTestDlg::OnVerboseHoursselector(LPCTSTR pszVerbose)
- {
- m_strVerbose = pszVerbose;
- UpdateData(FALSE);
- }
- void CHoursTestDlg::DealArray(unsigned char nBuf[7][24])
- {
- CString s,sTemp,str;
- CString sReport[500];
- int nReportIndex = 0;
- for( int y=0; y<7; y++)
- {
- for(int x=0; x<24; x++)
- {
- if(nBuf[y][x] == 15)
- {
- sTemp.Format("%02d%02d",y,x);
- sReport[nReportIndex] = sTemp;
- for(int x1 = x+1; x1<24; x1++)
- {
- if(nBuf[y][x1] == 15)
- {
- sTemp.Format("%02d%02d",y,x1);
- sReport[nReportIndex] += sTemp;
- }
- else
- {
- x = x1;
- break;
- }
- if(nBuf[y][x1] == 15 && x1 == 23)
- {
- x = x1;
- break;
- }
- }
- s.Format("%s",sReport[nReportIndex]);
- //AfxMessageBox(s);
- nReportIndex++;
- str+=s;
- str+="\n";
- }
- }
- }
- //AfxMessageBox(str);
- ////////////////////////////////////////////////////////////////
- int nResultIndex = 0;
- int iSign = 0;
- CString sResult[500];
- bool bFlag[500];
- int i = 0,j = 0;
- for( i=0;i<500;i++ )
- bFlag[i] = true;
- for( i=0;i<nReportIndex;i++ )
- {
- iSign = 1;
- if(bFlag[i])
- {
- sResult[nResultIndex] = sReport[i];
- //sResult[nResultIndex] += "\n";
- }
-
- for( j=i+1;j<nReportIndex;j++ )
- {
- if( sReport[i].GetLength() == sReport[j].GetLength() && bFlag[i] && bFlag[j])
- {
- if( CompareStr(sReport[i],sReport[j],iSign) )
- {
- sResult[nResultIndex] += sReport[j];
- //sResult[nResultIndex] += "\n";
- bFlag[j] = false;
- iSign++;
- //break;
- }
- }
- }
- if(bFlag[i])
- {
- bFlag[i] = false;
- nResultIndex++;
- }
-
- }
- ///////////////////////////////////////////////////////////////////////////
- CString sWeek1,sWeek2,sHour1,sHour2;
- for( int x=0; x<nResultIndex; x++)
- {
- //AfxMessageBox(sResult[x]);
- sHour1 = sResult[x].Mid(2,2);
- switch(atoi(sResult[x].Mid(0,2)))
- {
- case 0:
- sWeek1 = "星期日";break;
- case 1:
- sWeek1 = "星期一";break;
- case 2:
- sWeek1 = "星期二";break;
- case 3:
- sWeek1 = "星期三";break;
- case 4:
- sWeek1 = "星期四";break;
- case 5:
- sWeek1 = "星期五";break;
- case 6:
- sWeek1 = "星期六";break;
- }
- sHour2 = sResult[x].Mid(sResult[x].GetLength()-2,2);
- switch(atoi(sResult[x].Mid(sResult[x].GetLength()-4,2)))
- {
- case 0:
- sWeek2 = "星期日";break;
- case 1:
- sWeek2 = "星期一";break;
- case 2:
- sWeek2 = "星期二";break;
- case 3:
- sWeek2 = "星期三";break;
- case 4:
- sWeek2 = "星期四";break;
- case 5:
- sWeek2 = "星期五";break;
- case 6:
- sWeek2 = "星期六";break;
- }
- CString sData;
- sData.Format("(%s-%s) %s--%s",sWeek1,sWeek2,sHour1,sHour2);
- AfxMessageBox(sData);
- }
- //CString sData;
- //sData.Format("(%s-%s) %s:%s",sWeek1,sWeek2,sHour1,sHour2);
- //m_strVerbose = sData;
- //UpdateData(false);
- //AfxMessageBox(sData);
- }
- bool CHoursTestDlg::CompareStr(CString str1, CString str2,int nSign)
- {
- bool bResult = false;
-
- if( atoi(str1.Mid(0,2)) == atoi(str2.Mid(0,2)) && atoi(str1.Mid(2,2))+nSign == atoi(str2.Mid(2,2)) )
- bResult = true;
- if( atoi(str1.Mid(0,2))+nSign == atoi(str2.Mid(0,2)) && atoi(str1.Mid(2,2)) == atoi(str2.Mid(2,2)) )
- bResult = true;
- return bResult;
- }
- void CHoursTestDlg::OnBnClickedButton1()
- {
- m_hsTimes.SetDBInfo("192.168.2.32","IvsSvr","sa","");
- CString str;
- str = "192.168.2.5";
- long nPCIP = inet_addr(str);
- nPCIP = ntohl(nPCIP);
- str = "192.168.2.101";
- long nDvsIP = inet_addr(str);
- nDvsIP = ntohl(nDvsIP);
- m_hsTimes.SetDvsInfo(nPCIP,0,nDvsIP,0);
- m_hsTimes.WriteDataBase();
- }
- void CHoursTestDlg::OnBnClickedButton2()
- {
- m_hsTimes.SetDBInfo("192.168.2.32","IvsSvr","sa","");
- CString str;
- //str = "192.168.2.7";
- //long nPCIP = inet_addr(str);
- //nPCIP = ntohl(nPCIP);
- //str = "192.168.2.101";
- //long nDvsIP = inet_addr(str);
- //nDvsIP = ntohl(nDvsIP);
- //m_hsTimes.SetDvsInfo(nPCIP,0,nDvsIP,0);
- str = "192.168.2.5";
- long nPCIP = inet_addr(str);
- nPCIP = ntohl(nPCIP);
- m_hsTimes.GetDetectDate(nPCIP,0,0,0);
- }
|