예제 #1
0
UINT CXTPCalendarViewGroup::GetScheduleID()
{
	UINT uScheduleID = XTP_CALENDAR_UNKNOWN_SCHEDULE_ID;
	if (XTP_SAFE_GET1(GetResources(), GetCount(), 0) &&
		XTP_SAFE_GET3(GetResources(), GetAt(0), GetSchedules(), GetSize(), 0) )
	{
		uScheduleID = XTP_SAFE_GET3(GetResources(), GetAt(0), GetSchedules(),
									GetAt(0), 0);
	}

	return uScheduleID;
}
void CXTPCalendarDayViewTimeScale::AdjustLayout(CDC* pDC)
{
	UNREFERENCED_PARAMETER(pDC);

	ASSERT(pDC);
	ASSERT(m_pDayView);
	if (!m_pDayView || !pDC)
	{
		return;
	}

	CRect rcAllDayEvents = m_pDayView->GetAllDayEventsRectangle();

	m_Layout.m_nXPosBase = m_Layout.m_rcHeader.left;

	m_Layout.m_rcTimeZone = m_Layout.m_rcHeader;
	m_Layout.m_rcTimeZone.top = rcAllDayEvents.bottom;

	//----------------------------------------------------
	int nNowLineFlags = XTP_SAFE_GET3(m_pDayView, GetCalendarControl(), GetCalendarOptions(), nDayView_CurrentTimeMarkVisible, 0);

	m_bDrawNowLineDyn = m_bDrawNowLine;
	if (m_bDrawNowLineDyn)
	{
		if (m_pDayView->IsTodayVisible())
		{
			int nTAMask = xtpCalendarCurrentTimeMarkVisibleForToday | xtpCalendarCurrentTimeMarkVisibleAlways;
			m_bDrawNowLineDyn = m_bDrawNowLineDyn && (nNowLineFlags & nTAMask);
		}
		else
		{
			m_bDrawNowLineDyn = m_bDrawNowLineDyn && (nNowLineFlags & xtpCalendarCurrentTimeMarkVisibleAlways);
		}

		if (pDC->IsPrinting())
		{
			m_bDrawNowLineDyn = m_bDrawNowLineDyn && (nNowLineFlags & xtpCalendarCurrentTimeMarkPrinted);
		}
	}
}
COleDateTime CXTPCalendarTLV_TimeScaleParams::CalcScaleIntervalBegin(
														COleDateTime dtStart)
{
	if (!m_scaleInterval.m_nValue)
	{
		ASSERT(FALSE);
		return dtStart;
	}

	COleDateTime dtBegin = dtStart;

	int nFirstDayOfWeekIndex = 0;
	COleDateTimeSpan spAdd;

	LONGLONG nVal = 0;
	LONGLONG nDiv = 0;
	//int nMod = 0;
	LONGLONG nNewVal = 0;

	LONGLONG nllDays_total = (int)(DATE)dtStart;

	switch (m_scaleInterval.m_eType)
	{
	case xtpDTScale_Sec:
		nVal = dtStart.GetSecond() + nllDays_total * 24 * 60 * 60;
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = nDiv * m_scaleInterval.m_nValue;

		dtBegin = (DATE)(nNewVal / (24 * 60 * 60));
		dtBegin = CXTPCalendarUtils::UpdateTime(dtBegin, (int)(nNewVal % (24 * 60 * 60)),
										(int)(nNewVal % (60 * 60)), (int)(nNewVal % 60));

		/*nVal = dtStart.GetSecond();
		nDiv = nVal / m_scaleInterval.m_nValue;
		//nMod = nVal % m_scaleInterval.m_nValue;
		nNewVal = (nDiv + (nMod ? 1 : 0)) * m_scaleInterval.m_nValue;

		spAdd.SetDateTimeSpan(0, 0, 0, nNewVal);
		dtBegin = CXTPCalendarUtils::UpdateTime(dtBegin, dtStart.GetHour(), dtStart.GetMinute(), 0);
		dtBegin += spAdd;*/

		break;
	case xtpDTScale_Min:
		nVal = dtStart.GetMinute() /*+ (dtStart.GetSecond() ? 1 : 0)*/;
		nDiv = nVal / m_scaleInterval.m_nValue;
		//nMod = nVal % m_scaleInterval.m_nValue;
		//nNewVal = (nDiv +(nMod?1:0)) * m_scaleInterval.m_nValue;
		nNewVal = nDiv * m_scaleInterval.m_nValue;

		spAdd.SetDateTimeSpan(0, 0, (int)nNewVal, 0);
		dtBegin = CXTPCalendarUtils::UpdateTime(dtStart, dtStart.GetHour(), 0, 0);
		dtBegin += spAdd;

		break;

	case xtpDTScale_Hour:
		nVal = dtStart.GetHour();
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = (nDiv) * m_scaleInterval.m_nValue;

		spAdd.SetDateTimeSpan(0, (int)nNewVal, 0, 0);
		dtBegin = CXTPCalendarUtils::ResetTime(dtBegin);
		dtBegin += spAdd;

		break;

	case xtpDTScale_Day:
		nVal = dtStart.GetDay();
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = (nDiv) * m_scaleInterval.m_nValue;

		//spAdd.SetDateTimeSpan((int)max(0, nNewVal - 1), 0, 0, 0);
		//dtBegin = CXTPCalendarUtils::ResetTime(dtBegin);
		//CXTPCalendarUtils::UpdateMonthDay(dtBegin, 1);
		//dtBegin += spAdd;

		dtBegin = CXTPCalendarUtils::ResetTime(dtBegin);
		CXTPCalendarUtils::UpdateMonthDay(dtBegin, (int)nNewVal);

		break;
	case xtpDTScale_Week:
		// update first day of week
		nFirstDayOfWeekIndex = XTP_SAFE_GET3(m_pTimeScale, GetView(), GetCalendarControl(), GetFirstDayOfWeek(), 2);
		dtBegin = CXTPCalendarUtils::ShiftDateToWeekBegin(dtStart, nFirstDayOfWeekIndex);

		nVal = (int)(DATE)dtStart;
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = (nDiv) * m_scaleInterval.m_nValue;

		dtBegin = (DATE)nNewVal;

		break;

	case xtpDTScale_WorkWeek:
		// update first day of week
		nFirstDayOfWeekIndex = XTP_SAFE_GET3(m_pTimeScale, GetView(), GetCalendarControl(), GetFirstDayOfWeek(), 2);
		dtBegin = CXTPCalendarUtils::ShiftDateToWeekBegin(dtStart, nFirstDayOfWeekIndex);

		nVal = (int)(DATE)dtStart;
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = (nDiv) * m_scaleInterval.m_nValue;

		dtBegin = (DATE)nNewVal;

		break;
	case xtpDTScale_Month:
		dtBegin = CXTPCalendarUtils::ResetTime(dtStart);

		nVal = dtStart.GetMonth() + (dtStart.GetYear() - 1900) * 12;
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = (nDiv) * m_scaleInterval.m_nValue;
		{
			int nNewYear = (int)(nNewVal / 12 + 1900);
			int nNewMonth = (int)(nNewVal % 12);

			dtBegin.SetDate(nNewYear, nNewMonth, 1);
		}

		break;
	case xtpDTScale_Year:
		dtBegin = CXTPCalendarUtils::ResetTime(dtStart);

		nVal = dtStart.GetYear();
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = (nDiv) * m_scaleInterval.m_nValue;

		dtBegin.SetDate((int)nNewVal, 1, 1);

		break;
	default:
		ASSERT(FALSE);
	}

	return dtBegin;
}