void CBCGPRecurrenceRuleYearly::CorrectStart ()
{
	COleDateTime dt (GetDateStart ());

	int y = dt.GetYear ();
	int m = m_Type == BCGP_REC_RULE_YEARLY_TYPE_DAY ? m_dwDayMonth : m_dwDayTypeMonth;
	int d = GetPossibleDay (y);

	int nDays = CBCGPCalendar::GetMaxMonthDay (m, y);

	dt = COleDateTime (y, m, nDays < d ? nDays : d, 0, 0, 0);

	if (dt < GetDateStart ())
	{
		y++;
		
		d = GetPossibleDay (y);
		nDays = CBCGPCalendar::GetMaxMonthDay (m, y);

		dt = COleDateTime (y, m, nDays < d ? nDays : d, 0, 0, 0);
	}

	if (dt != GetDateStart ())
	{
		SetDateStart (dt);
	}
}
Example #2
0
DWORD COXDateTimeCtrl::GetRange(COleDateTime* pMinTime,
								COleDateTime* pMaxTime) const
{
#if _MFC_VER<=0x0421
	ASSERT(::IsWindow(m_hWnd));

	SYSTEMTIME sysTimes[2];
	memset(sysTimes, 0, sizeof(sysTimes));

	DWORD dwResult = ::SendMessage(m_hWnd, DTM_GETRANGE, 0, (LPARAM) &sysTimes);
	if (pMinTime != NULL)
	{
		if (dwResult & GDTR_MIN)
			*pMinTime = COleDateTime(sysTimes[0]);
		else
			pMinTime->SetStatus(COleDateTime::null);
	}

	if (pMaxTime != NULL)
	{
		if (dwResult & GDTR_MAX)
			*pMaxTime = COleDateTime(sysTimes[1]);
		else
			pMaxTime->SetStatus(COleDateTime::null);
	}

	return dwResult;
#else
	return CDateTimeCtrl::GetRange(pMinTime,pMaxTime);
#endif	//	_MFC_VER>0x0421
}
Example #3
0
BOOL CCalendarDateDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
/*	
	LANGID dwLanguageID = GetSystemLanguagePrimaryID();
	switch( dwLanguageID)
	{
	case LANG_SPANISH:
		CWnd::SetWindowText(_T("Cuadro de selección"));
		GetDlgItem(IDC_STATIC_PICKDATE)->SetWindowText(_T("Seleccione una fecha:"));
		GetDlgItem(IDOK)->SetWindowText(_T("Aceptar"));
		GetDlgItem(IDCANCEL)->SetWindowText(_T("Cancelar"));
		break;
	default:
		CWnd::SetWindowText(_T("Selection dialog"));
		GetDlgItem(IDC_STATIC_PICKDATE)->SetWindowText(_T("Select a date:"));
		GetDlgItem(IDOK)->SetWindowText(_T("OK"));
		GetDlgItem(IDCANCEL)->SetWindowText(_T("Cancel"));
		break;
	}

*/	
	// TODO: Add extra initialization here
	COleDateTime DateMin = COleDateTime(2000,1,1,0,0,0);
	COleDateTime DateMax = COleDateTime(2035,12,31,0,0,0);
	m_DateCtrl.SetRange(&DateMin, &DateMax);
	m_DateCtrl.SetFocus();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
Example #4
0
DWORD CDateTimeCtrl::GetRange(COleDateTime* pMinTime,
                              COleDateTime* pMaxTime) const
{
    ASSERT(::IsWindow(m_hWnd));

    SYSTEMTIME sysTimes[2];
    memset(sysTimes, 0, sizeof(sysTimes));

    //IA64: Assume retval of DTM_GETRANGE is still 32-bit
    DWORD dwResult = DWORD(::SendMessage(m_hWnd, DTM_GETRANGE, 0, (LPARAM) sysTimes));
    if (pMinTime != NULL)
    {
        if (dwResult & GDTR_MIN)
            *pMinTime = COleDateTime(sysTimes[0]);
        else
            pMinTime->SetStatus(COleDateTime::null);
    }

    if (pMaxTime != NULL)
    {
        if (dwResult & GDTR_MAX)
            *pMaxTime = COleDateTime(sysTimes[1]);
        else
            pMaxTime->SetStatus(COleDateTime::null);
    }

    return dwResult;
}
void CBCGPPlannerViewWorkWeek::OnActivate(CBCGPPlannerManagerCtrl* pPlanner, const CBCGPPlannerView* pOldView)
{
	ASSERT_VALID(pPlanner);

	if (pOldView != NULL)
	{
		m_Date = pOldView->GetDate ();
	}

	m_DateStart = CalculateDateStart (
		COleDateTime(m_Date.GetYear (), m_Date.GetMonth (), m_Date.GetDay (), 0, 0, 0));
	m_DateEnd   = m_DateStart + COleDateTimeSpan (pPlanner->GetWorkWeekInterval () - 1, 23, 59, 59);

	COleDateTime sel1 (m_Date);
	COleDateTime sel2 (m_Date);

	if (pOldView != NULL)
	{
		sel1 = pOldView->GetSelectionStart ();
		sel2 = pOldView->GetSelectionEnd ();
	}

	const int nMinuts = CBCGPPlannerView::GetTimeDeltaInMinuts (pPlanner->GetTimeDelta ());

	sel1 = COleDateTime (m_DateStart.GetYear (), m_DateStart.GetMonth (), m_DateStart.GetDay (),
		pPlanner->GetFirstSelectionHour (), (int)(pPlanner->GetFirstSelectionMinute () / nMinuts) * nMinuts, 0);
	sel2 = sel1 + COleDateTimeSpan (0, 0, nMinuts - 1, 59);

	//SetSelection (sel1, sel2, FALSE);

	CBCGPPlannerView::OnActivate (pPlanner, NULL);

	SetSelection (sel1, sel2);
}
CBCGPDateTimeCtrl::CBCGPDateTimeCtrl()
{
	m_checkButton = TRUE;
	m_dropCalendar = TRUE;
	m_showDate = TRUE;
	m_showTime = TRUE;
	m_spinButton = TRUE;

	m_type2DigitsInYear = TRUE;
	m_maxYear2Digits = 2090;

	m_bCheckBoxIsAvailable = FALSE;
	m_iPartNum = 0;
	m_iPartsNumber = 0;
	m_bIsChecked = TRUE;
	m_Date = COleDateTime::GetCurrentTime ();
	m_iPrevDigit = -1;

	m_rectText.SetRectEmpty ();

	m_bShowSelection = FALSE;
	m_bDropButtonIsPressed = FALSE;

	m_pPopup = NULL;

	m_bDropButtonIsPressed = FALSE;
	m_bMouseOnDropButton = FALSE;

	for (int i = 0; i < MAX_PARTS; i ++)
	{
		m_arPartRects [i].SetRectEmpty ();
	}

	m_rectText.SetRectEmpty ();
	m_bAutoResize = TRUE;

	m_iControlWidth = 0;
	m_iControlHeight = 0;

	m_iYearPos = 0;
	m_monthFormat = 0;

	m_MinDate = COleDateTime (iFirstAllowedYear, 1, 1, 0, 0, 0);
	m_MaxDate = COleDateTime (iLastAllowedYear, 12, 31, 23, 59, 59);

	m_weekStart = 1;
	m_b24HoursByLocale = TRUE;

	m_hFont	= NULL;
	m_bIsInitialized = FALSE;

	m_bDrawDateTimeOnly = FALSE;

	m_colorText = (COLORREF)-1;
	m_colorBackground = (COLORREF)-1;
}
Example #7
0
CDlgStock::CDlgStock(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_DIALOG1, pParent)
{
	m_strMarket = _T("SZ");
	m_strLable = _T("000002");
	m_Cycle = STKCYCLE::DAY;
	m_bCumDividendPrice = TRUE;
	m_Time.start = COleDateTime(2004, 5, 19, 0, 0, 0);
	m_Time.end = COleDateTime(2004, 5, 31, 23, 59, 59);
}
Example #8
0
COleDateTime	CDBField::AsDate()	const
{
	COleDateTime	date;
	if( IsNull() ) {
		date.SetStatus( COleDateTime::null );
		return	date;
	}

	switch( m_dwType ) {
	case	DBVT_NULL:
			date.SetStatus( COleDateTime::null );
			return	date;

	case	DBVT_BOOL:
			date.SetStatus( COleDateTime::invalid );
			return	date;

	case	DBVT_UCHAR:
			date.SetStatus( COleDateTime::invalid );
			return	date;

	case	DBVT_SHORT:
			return	COleDateTime( (time_t)m_iVal );

	case	DBVT_LONG:
			return	COleDateTime( (time_t)m_lVal );

	case	DBVT_SINGLE:
			return	COleDateTime( (time_t)m_fltVal );

	case	DBVT_DOUBLE:
			return	COleDateTime( (time_t)m_dblVal );

	case	DBVT_DATE:
			ASSERT( m_pdate != NULL );
			return	COleDateTime(	m_pdate->year, m_pdate->month, m_pdate->day,
									m_pdate->hour, m_pdate->minute, m_pdate->second );

	case	DBVT_STRING:
			ASSERT( m_pstring != NULL );
			date.ParseDateTime( *m_pstring );
			return	date;

	case	DBVT_BINARY:
			//	Cannot conver long binary to date
			ASSERT( FALSE );
			break;
	}
	//	Undefined data type
	ASSERT( FALSE );
	date.SetStatus( COleDateTime::invalid );
	return	date;
}
Example #9
0
// ///////////////////////////////////////////////////////////////////////////
//
COleDateTime Time2AdjustedDate( const CString& sTime, const COleDateTime& startDate )
{
	int hr,min;
	String2HourMin(sTime, hr, min);

	// If the given time is before the startDate's time, then the target date is one day further
	//
	if ((hr < startDate.GetHour()) || ((hr == startDate.GetHour()) && (min < startDate.GetMinute())))
	{
		COleDateTime dt = startDate + COleDateTimeSpan(1,0,0,0);
		return COleDateTime(dt.GetYear(), dt.GetMonth(), dt.GetDay(), hr, min, 0);
	}

	return COleDateTime(startDate.GetYear(), startDate.GetMonth(), startDate.GetDay(), hr, min, 0);
}
//*****************************************************************************************
void CBCGPDateTimeCtrl::ChangeMonth (UINT uiMonthLetter)
{
	ASSERT (m_monthFormat == 0 || m_monthFormat == 1);

	CBCGPDefaultLocale dl;

	int iDay = m_Date.GetDay ();
	int iMonth = m_Date.GetMonth ();
	int iYear = m_Date.GetYear ();
	int iHour = m_Date.GetHour ();
	int iMin = m_Date.GetMinute ();

	BOOL bLastDayInMonth = (iDay == GetDaysInMonth (iMonth, iYear));

	BOOL bFound = FALSE;
	for (int i = iMonth + 1; i != iMonth; i ++)
	{
		if (i > 12)
		{
			i = 1;
		}

		if (i == iMonth)
		{
			break;
		}

		//--------------------------------------------------
		// Compare manth 'i' first char with the typed char:
		//--------------------------------------------------
		CString strMonth = COleDateTime (iYear, i, 1, 0, 0, 0).
			Format (m_monthFormat == 0 ? _T ("%b") : _T ("%B"));

		if (strMonth.GetLength () > 1 &&
			strMonth.GetAt (0) == (char) uiMonthLetter)
		{
			iMonth = i;
			bFound = TRUE;
			break;
		}
	}

	if (bFound)
	{
		if (bLastDayInMonth ||
			iDay > GetDaysInMonth (iMonth, iYear))
		{
			iDay = GetDaysInMonth (iMonth, iYear);
		}

		COleDateTime date (iYear, iMonth, iDay, iHour, iMin, 0);
		if (IsDateValid (date))
		{
			m_Date = date;
			RedrawWindow (m_rectText);

			OnDateChanged ();
		}
	}
}
Example #11
0
void CWizKbSync::onAttachmentsGetInfo(const std::deque<WIZDOCUMENTATTACHMENTDATAEX>& arrayRet)
{
    size_t count = arrayRet.size();

    // new attachment
    if (count == 0) {
        WIZDOCUMENTATTACHMENTDATA data;
        data.strGUID = m_currentUploadAttachment.strGUID;
        data.strDocumentGUID = m_currentUploadAttachment.strDocumentGUID;
        data.strName = m_currentUploadAttachment.strName;
        data.tInfoModified = COleDateTime(1900, 1, 1, 0, 0, 0);
        data.tDataModified = data.tInfoModified;
        data.strInfoMD5 = "-1";
        data.strDataMD5 = "-1";

        onQueryAttachmentInfo(data);

    // server return exist
    } else if (count == 1) {
        onQueryAttachmentInfo(arrayRet[0]);

    // fatal error
    } else {
        Q_EMIT processErrorLog("Can not query document info");
        onXmlRpcError(SyncMethod_GetDocumentsInfo, errorXmlRpcFault, -1, "Fault error: Invalid document info");
    }
}
Example #12
0
void CWizKbSync::onDocumentsGetInfo(const std::deque<WIZDOCUMENTDATABASE>& arrayRet)
{
    size_t count = arrayRet.size();

    // new document
    if (count == 0) {
        WIZDOCUMENTDATABASE data;
        data.strGUID = m_currentUploadDocument.strGUID;
        data.strTitle = m_currentUploadDocument.strTitle;
        data.strLocation = m_currentUploadDocument.strLocation;
        data.tInfoModified = COleDateTime(1900, 1, 1, 0, 0, 0);
        data.tDataModified = data.tInfoModified;
        data.tParamModified = data.tInfoModified;
        data.strInfoMD5 = "-1";
        data.strDataMD5 = "-1";
        data.strParamMD5 = "-1";

        onQueryDocumentInfo(data);

    // server already have this document
    } else if (count == 1) {
        onQueryDocumentInfo(arrayRet[0]);

    // absolutely count should not more than 1
    } else {
        Q_EMIT processErrorLog("Can not query document info");
        onXmlRpcError(SyncMethod_GetDocumentsInfo, errorXmlRpcFault, -1, "Fault error: Invalid document info");
    }
}
// NOTE: Windows SCM more tolerant of slow starting processes than terminating processes.
void MtcOpcAdapter::start()
{
 	static char name[] = "MtcOpcAdapter::start";
	_bRunning=true; 
	if(_bResetAtMidnight)
	{
		COleDateTime now = COleDateTime::GetCurrentTime();
		COleDateTime date2 =  COleDateTime(now.GetYear(), now.GetMonth(), now.GetDay(), 0, 0, 0) +  COleDateTimeSpan(1, 0, 0, 1);
		//COleDateTime date2 =  now +  COleDateTimeSpan(0, 0, 2, 0); // testing reset time - 2 minutes

		COleDateTimeSpan tilmidnight = date2-now;
		_resetthread.Initialize();
		_resetthread.AddTimer(
			(long) tilmidnight.GetTotalSeconds() * 1000,
			&_ResetThread,
			(DWORD_PTR) this,
			&_ResetThread._hTimer  // stored newly created timer handle
			) ;

		GLogger << INFO << "Adapter will Reset At Midnight " << date2.Format() << std::endl;
	}

	if(_bOPCEnabled)
	{
		_workerthread.Initialize();
		::SetEvent (_StartThread._hEvent); // start OPC thread
		_workerthread.AddHandle(_StartThread._hEvent, &_StartThread,(DWORD_PTR) this);
	}

	// This goes last... never returns
	startServer();
}
Example #14
0
int CMonthCalCtrl::GetMonthRange(COleDateTime& refMinRange,
                                 COleDateTime& refMaxRange, DWORD dwFlags) const
{
    ASSERT(::IsWindow(m_hWnd));
    ASSERT(dwFlags == GMR_DAYSTATE || dwFlags == GMR_VISIBLE);

    SYSTEMTIME sysTimes[2];
    memset(sysTimes, 0, sizeof(sysTimes));
    int nCount = (int) ::SendMessage(m_hWnd, MCM_GETMONTHRANGE,
                                     (WPARAM) dwFlags, (LPARAM) sysTimes);

    refMinRange = COleDateTime(sysTimes[0]);
    refMaxRange = COleDateTime(sysTimes[1]);

    return nCount;
}
void CBCGPPlannerViewMonth::OnActivate(CBCGPPlannerManagerCtrl* pPlanner, const CBCGPPlannerView* pOldView)
{
	ASSERT_VALID(pPlanner);

	if (pOldView != NULL)
	{
		m_Date = pOldView->GetDate ();
	}

	m_nDuration = 35;
	m_DateStart = CalculateDateStart (
		COleDateTime(m_Date.GetYear (), m_Date.GetMonth (), m_Date.GetDay (), 0, 0, 0));
	m_DateEnd   = m_DateStart + COleDateTimeSpan (m_nDuration - 1, 23, 59, 59);

	if (m_Date > m_DateEnd || m_Date < m_DateStart)
	{
		m_Date = m_DateStart;
	}

	COleDateTime sel1 (m_Date);
	COleDateTime sel2 (m_Date);

	if (pOldView != NULL)
	{
		sel1 = pOldView->GetSelectionStart ();
		sel2 = pOldView->GetSelectionEnd ();
	}

	SetSelection (sel1, sel2, FALSE);

	CBCGPPlannerView::OnActivate (pPlanner, NULL);
}
Example #16
0
// ////////////////////////////////////////////////////////////////////////////
//
void CDlgEvents::OnModify() 
{
	int n = m_Events.GetCurSel();
	if (n == -1)
		return;

	long id = (long) m_Events.GetItemData(n);

	CRecEvent rec;
	if (! rec.FindByID(id) )
		return;

	CDlgEditEvent dlg(this);

	SYSTEMTIME st;
	rec.m_trigger.GetAsSystemTime(st);
	dlg.m_Date = CTime(st);
	dlg.m_Time = CTime(st);
	dlg.m_Text = rec.m_text;

	if ( dlg.DoModal() != IDOK )
		return;

	rec.FindByID(id);
	rec.Edit();
	rec.m_time = COleDateTime( dlg.m_Date.GetYear(), dlg.m_Date.GetMonth(), dlg.m_Date.GetDay(),
							   dlg.m_Time.GetHour(), dlg.m_Time.GetMinute(), dlg.m_Time.GetSecond() );
	rec.m_trigger = rec.m_time;
	rec.m_text = dlg.m_Text;
	rec.m_fired = FALSE;
	rec.Update();

	refreshList();
}
Example #17
0
// ///////////////////////////////////////////////////////////////////////////
// Build a new date object  by copying the given date object and replacing
// its time by the given one
//
COleDateTime SetTimeOfDate( const COleDateTime& date, const CString& sTime )
{
	int hr,min;
	String2HourMin(sTime, hr, min);

	return COleDateTime(date.GetYear(), date.GetMonth(), date.GetDay(), hr, min, 0);
}
Example #18
0
COleDateTime COXCalendarEdit::GetDateFromString(LPCTSTR lpszDateString)
{
	CString strDate = lpszDateString;

	// First get the year

	// 1. Find where the year starts and where it ends
	int iYearStartIdx = m_strDateFormat.Find('Y');
	int iYearEndIdx = m_strDateFormat.ReverseFind('Y');
	CString strYearOnly = strDate.Mid(iYearStartIdx, iYearEndIdx - iYearStartIdx + 1);
	int iYear = ::_ttoi(strYearOnly);

	// 2. Find where the month starts and where it ends
	int iMonthStartIdx = m_strDateFormat.Find('M');
	int iMonthEndIdx = m_strDateFormat.ReverseFind('M');
	CString strMonthOnly = strDate.Mid(iMonthStartIdx, iMonthEndIdx - iMonthStartIdx + 1);
	int iMonth = ::_ttoi(strMonthOnly);

	// 3. Find where the day starts and where it ends
	int iDayStartIdx = m_strDateFormat.Find('D');
	int iDayEndIdx = m_strDateFormat.ReverseFind('D');
	CString strDayOnly = strDate.Mid(iDayStartIdx, iDayEndIdx - iDayStartIdx + 1);
	int iDay = ::_ttoi(strDayOnly);

	return COleDateTime(iYear, iMonth, iDay, 0, 0, 0);
}
//****************************************************************************************
void CBCGPDateTimeCtrl::BuidWidestDate (CDC* pDC)
{
	ASSERT_VALID (pDC);

	CBCGPDefaultLocale dl;

	//-----------------------
	// Find the widest month:
	//-----------------------
	int iMaxMonth = 1;

	if (m_monthFormat == 2)	// Numeric
	{
		iMaxMonth = 9;
	}
	else
	{
		int iMaxMonthWidth = 0;
		for (int iMonth = 1; iMonth <= 12; iMonth ++)
		{
			COleDateTime date (1998, iMonth, 1, 0, 0, 0);
			CString strMonth = date.Format (m_monthFormat == 0 ? _T ("%b") : _T("%B"));

			int iMonthWidth = pDC->GetTextExtent (strMonth).cx;
			if (iMonthWidth > iMaxMonthWidth)
			{
				iMaxMonthWidth = iMonthWidth;
				iMaxMonth = iMonth;
			}
		}
	}

	m_WidestDate = COleDateTime (2000, iMaxMonth, 20, 0, 0, 0);
}
void CBCGPRecurrenceRuleMonthly::CorrectStart ()
{
	COleDateTime dt (GetDateStart ());

	int m = dt.GetMonth ();
	int y = dt.GetYear ();

	int d = GetPossibleDay (m, y);

	if (d < dt.GetDay ())
	{
		m++;

		if (m == 13)
		{
			m = 1;
			y++;
		}

		d = GetPossibleDay (m, y);
	}

	int nDays = CBCGPCalendar::GetMaxMonthDay (m, y);

	dt = COleDateTime (y, m, nDays < d ? nDays : d, 0, 0, 0);

	if (dt != GetDateStart ())
	{
		SetDateStart (dt);
	}
}
int CRemoteFileDialog::AddFileItem(LPCTSTR szFileName, int nType, UINT nUniqueID, DWORD dwFileSize,
	const FILETIME* pLastMod, int nImage)
{
	if (nImage == -1)
	{
		nImage = CSysImageList().GetFileImageIndex(szFileName);
	}

	int nItem = m_lcFiles.InsertItem(LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM, 0, szFileName, 0, 0, nImage, nUniqueID);

	// add to map
	FILEITEM fi;
	fi.sFilename = szFileName;
	fi.nType = nType;
	fi.dwSize = dwFileSize;

	if (pLastMod)
	{
		FILETIME ftLocal;
		FileTimeToLocalFileTime(pLastMod, &ftLocal);

		fi.dLastMod = COleDateTime(ftLocal);
	}

	m_mapItems[nUniqueID] = fi;

	// add size and date item if a file
	if (nType == RFDT_FILE && m_bInitReport)
	{
		m_lcFiles.SetItemText(nItem, 1, FormatSize(fi.dwSize));
		m_lcFiles.SetItemText(nItem, 2, FormatDate(fi.dLastMod));
	}

	return nItem;
}
void CXTPDatePickerItemMonth::PopulateDays()
{
	if (m_dtMonth.GetYear() <= 100 && m_dtMonth.GetMonth() <= 2)
		m_dtMonth = COleDateTime(100,2,1,0,0,0);

	if (m_dtMonth.GetStatus() != COleDateTime::valid)
	{
		ASSERT(FALSE);
		m_dtMonth = CXTPCalendarUtils::ResetTime(COleDateTime::GetCurrentTime());
	}
	//if (m_dtMonth < COleDateTime(1601,4,1,0,0,0))
	//  m_dtMonth = COleDateTime(1601,4,1,0,0,0);

	// init days from 1st to last
	COleDateTime dtDay(m_dtMonth.GetYear(), m_dtMonth.GetMonth(), 1, 0, 0, 0);
	COleDateTimeSpan spDay(1, 0, 0, 0);

	// adjust first day of the week
	int nOleFirstDayOfWeek = m_pControl->GetFirstDayOfWeek();

	int iDayOfWeek = dtDay.GetDayOfWeek();
	if (iDayOfWeek != -1)
	{
		while (dtDay.GetDayOfWeek() != nOleFirstDayOfWeek && dtDay.GetDayOfWeek() != -1)
		{
			dtDay -= spDay;
		}
	}
	else
	{
		COleDateTime dtFutureDay(dtDay);
		dtFutureDay.SetDate(dtFutureDay.GetYear() + 2000, dtFutureDay.GetMonth(), dtFutureDay.GetDay());
		iDayOfWeek = dtFutureDay.GetDayOfWeek();

		while (dtFutureDay.GetDayOfWeek() != nOleFirstDayOfWeek && dtFutureDay.GetDayOfWeek() != -1)
		{
			dtFutureDay -= spDay;
			dtDay -= spDay;
		}
	}

	//while (dtDay.GetDayOfWeek() != nOleFirstDayOfWeek && dtDay.GetDayOfWeek() != -1)
	//{
	//  dtDay -= spDay;
	//}

	// populate all grid days
	for (int nWeek = 0; nWeek < XTP_MAX_WEEKS; nWeek++)
	{
		for (int nDay = 0; nDay < XTP_WEEK_DAYS; nDay++)
		{
			// create and add new day item
			CXTPDatePickerItemDay* pDay = new CXTPDatePickerItemDay(m_pControl, this, dtDay);
			m_arrDays.Add(pDay);
			// move next day
			dtDay += spDay;
		}
	}
}
void CCalendarDlg2::SetTextForDay(SYSTEMTIME* sysTime)
{
    static BOOL bFirst=1;
    static CString sDovesok;
    static COleDateTime dtCurrent;
    if(!bFirst && dtCurrent.GetStatus()!=COleDateTime::invalid) {
        CString sThisDayNKey=Format(sKey,dtCurrent.GetDay(),dtCurrent.GetMonth(),dtCurrent.GetYear());
        CString sCurDay;
        m_eText.GetWindowText(sCurDay);
        sCurDay.TrimLeft();
        sCurDay.TrimRight();
        if(sCurDay!="") {
            sCurDay.Replace("\r\n","\n");
            if(sDovesok!="") {
                sCurDay+=Format("[?CDATA{%s}?DATAC:)]",sDovesok);
            }
            if(!bINewLine) {
                sCurDay.Replace("\n","<br>");
            }
            CString sContent=CString("\n")+sCurDay+"\n";
            while(sContent!="") {
                CString sLine=sContent.SpanExcluding("\n");
                if(sLine!="") {
                    aItems.Add(sThisDayNKey+sLine);
                    if(sContent.GetLength()>sLine.GetLength()) {
                        sContent=sContent.Mid(sLine.GetLength()+1);
                    } else {
                        sContent="";
                    }
                }
                sContent.TrimLeft();
            }
        }
        sDovesok="";
    }
    bFirst=0;
    if(sysTime) {
        COleDateTime dtTime=COleDateTime(sysTime->wYear,sysTime->wMonth,sysTime->wDay,0,0,0);
        char szTmp[256]= {0};
        GetDateFormat(LOCALE_USER_DEFAULT,DATE_SHORTDATE,sysTime,0,szTmp,sizeof(szTmp));
        GetDlgItem(IDC_STATIC3)->SetWindowText(Format("%s: %s",_l("Current date"),szTmp));
        CString sThisDayNKey=Format(sKey,dtTime.GetDay(),dtTime.GetMonth(),dtTime.GetYear());
        dtCurrent=dtTime;
        CString sDayNote;
        for(int i=aItems.GetSize()-1; i>=0; i--) {
            if(aItems[i].Find(sThisDayNKey)==0) {
                if(sDayNote!="") {
                    sDayNote+="\r\n";
                }
                sDayNote+=aItems[i].Mid(sThisDayNKey.GetLength());
                aItems.RemoveAt(i);
            }
        }
        sDovesok=CDataXMLSaver::GetInstringPart("[?CDATA{","}?DATAC:)]",sDayNote);
        sDayNote.Replace(Format("[?CDATA{%s}?DATAC:)]",sDovesok),"");
        sDayNote.Replace("<br>","\r\n");
        m_eText.SetWindowText(sDayNote);
    }
}
void CBCGPPlannerPrintMonth::CalculateDates (const COleDateTime& date)
{
	BOOL bNeedUpdate = TRUE;

	if (m_DateStart != COleDateTime () && m_DateEnd != COleDateTime ())
	{
		bNeedUpdate = ((m_DateEnd - m_DateStart).GetTotalDays () + 1) < 14;
	}

	if (bNeedUpdate)
	{
		m_DateStart = GetFirstWeekDay2 (COleDateTime (date.GetYear (), 
			date.GetMonth (), 1, 0, 0, 0), CBCGPPlannerManagerCtrl::GetFirstDayOfWeek () + 1);

		m_DateEnd   = m_DateStart + COleDateTimeSpan (34, 23, 59, 59);
	}
}
Example #25
0
//日期转化函数(需要delete)
WCHAR* WindData::DateToString(DATE date, LPCWSTR strFormat)
{
	wstring str = COleDateTime(date).Format(strFormat);
	int length = str.length() + 1;
	WCHAR* timeBuffer = new WCHAR[length];
	swprintf(timeBuffer, length, L"%s", str.c_str());

	return timeBuffer;
}
void CBCGPPlannerViewMonth::SetSelection (const COleDateTime& sel1, const COleDateTime& sel2, BOOL bRedraw)
{
	COleDateTime s1 (sel1);
	COleDateTime s2 (sel2);

	if (s1 < s2 || IsOneDay (s1, s2))
	{
		s1 = COleDateTime (s1.GetYear (), s1.GetMonth (), s1.GetDay (), 0, 0, 0);
		s2 = COleDateTime (s2.GetYear (), s2.GetMonth (), s2.GetDay (), 23, 59, 59);
	}
	else
	{
		s2 = COleDateTime (s2.GetYear (), s2.GetMonth (), s2.GetDay (), 0, 0, 0);
		s1 = COleDateTime (s1.GetYear (), s1.GetMonth (), s1.GetDay (), 23, 59, 59);
	}

	CBCGPPlannerView::SetSelection (s1, s2, bRedraw);
}
Example #27
0
   /// <summary>Opens a document template.</summary>
   /// <param name="docPath">document path.</param>
   /// <param name="t">template.</param>
   /// <returns></returns>
   BOOL ScriptDocument::OnOpenTemplate(Path docPath, const TemplateFile& t)
   {
      WorkerData data(Operation::LoadSaveDocument);
      
      try
      {
         // Feedback
         Console << Cons::UserAction << "Creating script: " << docPath << " from template: " << Path(t.SubPath) << ENDL;
         data.SendFeedback(ProgressType::Operation, 0, VString(L"Creating %s '%s'", t.Name.c_str(), docPath.c_str()));

         // Read/Parse template script
         AppPath path(t.SubPath);
         Script = ScriptFileReader(XFileInfo(path).OpenRead()).ReadFile(path, false);

         // Set properties
         Script.Name = docPath.RemoveExtension().FileName;
         Script.Game = PrefsLib.GameDataVersion;
         Script.Version = 1;
         Script.Description = L"no description";

         // Populate template
         LineArray lines;
         wstring date = COleDateTime(time(nullptr)).Format(L"%d/%m/%Y");
         for (auto& cmd : Script.Commands.Input)
         {
            cmd.Text = cmd.Text.ReplaceAll(L"$NAME$", Script.Name);
            cmd.Text = cmd.Text.ReplaceAll(L"$DATE$", date);
            cmd.Text = cmd.Text.ReplaceAll(L"$AUTHOR$", L"");
            lines.push_back(cmd.Text);
         }

         // Create temp scriptFile
         ScriptFile tmp(Script);
         tmp.FullPath = docPath;

         // Compile changes into temporary script
         ScriptParser parser(tmp, lines, Script.Game);
         parser.Compile();
         
         // Write to disc
         ScriptFileWriter w(XFileInfo(docPath).OpenWrite());
         w.Write(tmp);
         w.Close();

         // Feedback
         data.SendFeedback(Cons::Success, ProgressType::Succcess, 0, L"Script created successfully");
         return TRUE;
      }
      catch (ExceptionBase&  e)
      {
         // Feedback/Display error
         data.SendFeedback(Cons::Error, ProgressType::Failure, 0, VString(L"Failed to create %s '%s'", t.Name.c_str(), docPath.c_str()));
         theApp.ShowError(HERE, e, VString(L"Failed to create %s '%s'", t.Name.c_str(), docPath.c_str()));
         return FALSE;
      }
   }
Example #28
0
BOOL CMonthCalCtrl::GetSelRange(COleDateTime& refMinRange,
                                COleDateTime& refMaxRange) const
{
    // control must have multiple select
    ASSERT((GetStyle() & MCS_MULTISELECT));
    ASSERT(::IsWindow(m_hWnd));

    SYSTEMTIME sysTimes[2];
    memset(sysTimes, 0, sizeof(sysTimes));
    BOOL bResult = (BOOL)
                   ::SendMessage(m_hWnd, MCM_GETSELRANGE, 0, (LPARAM) sysTimes);

    if (bResult)
    {
        refMinRange = COleDateTime(sysTimes[0]);
        refMaxRange = COleDateTime(sysTimes[1]);
    }
    return bResult;
}
Example #29
0
DWORD CMonthCalCtrl::GetRange(COleDateTime* pMinRange,
                              COleDateTime* pMaxRange) const
{
    ASSERT(::IsWindow(m_hWnd));

    SYSTEMTIME sysTimes[2];
    memset(sysTimes, 0, sizeof(sysTimes));

    DWORD dwRanges = (DWORD)
                     ::SendMessage(m_hWnd, MCM_GETRANGE, 0, (LPARAM) sysTimes);

    if (dwRanges & GDTR_MIN && pMinRange)
        *pMinRange = COleDateTime(sysTimes[0]);

    if (dwRanges & GDTR_MAX && pMaxRange)
        *pMaxRange = COleDateTime(sysTimes[1]);

    return dwRanges;
}
static COleDateTime GetDateTime(std::string s)
{
	// parse 2012-02-03T17:31:51.0968Z 
	int Year, Month, Day, Hour, Minute, Second, Millisecond;
	if(sscanf(s.c_str(), "%d-%d-%dT%d:%d:%d.%d", &Year, &Month, &Day, &Hour, &Minute,&Second, &Millisecond)==7){}
		//12/2/2009 2:42:25 PM
	else if(sscanf(s.c_str(), "%d/%d/%4d%d:%d:%d", &Month, &Day, &Year,  &Hour, &Minute,&Second)==6){}
	else throw std::exception("Unrecognized date-time format\n");
	return COleDateTime( Year, Month, Day, Hour, Minute, Second ); 
}