// 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