#if FRAMEWORK20 using System; using System.Collections.Generic; using System.Drawing; namespace DevComponents.DotNetBar.Schedule { public class MonthWeek { #region Private constants private const int DaysInWeek = 7; #endregion #region Private variables private DateTime _FirstDayOfWeek; // First day of the week private DateTime _LastDayOfWeek; // Last day of the week private Rectangle _Bounds; // Week bounding rectangle private ItemRects _DayRects; // Day bounding Rectangles private ItemRects _MoreItems; private List _CalendarItems = new List(); #endregion /// /// Constructor /// /// public MonthWeek(BaseItem baseItem) { // Allocate our DayRects array _DayRects = new ItemRects(baseItem, DaysInWeek); _MoreItems = new ItemRects(baseItem, DaysInWeek); } #region Public properties #region CalendarItems /// /// Gets array of CalendarItems /// public List CalendarItems { get { return (_CalendarItems); } } #endregion #region FirstDayOfWeek /// /// Gets the first day of the week /// public DateTime FirstDayOfWeek { get { return (_FirstDayOfWeek); } internal set { _FirstDayOfWeek = value; _LastDayOfWeek = _FirstDayOfWeek.AddDays(DaysInWeek - 1); } } #endregion #endregion #region Internal properties #region Bounds /// /// Gets and sets the week bounding Rectangle /// internal Rectangle Bounds { get { return (_Bounds); } set { if (_Bounds.Equals(value) == false) { _Bounds = value; CalcDayRects(); } } } #endregion #region DayRects /// /// Gets the day Rectangles /// internal ItemRects DayRects { get { return (_DayRects); } } #endregion #region LastDayOfWeek internal DateTime LastDayOfWeek { get { return (_LastDayOfWeek); } } #endregion #region MoreItems /// /// Gets the MoreItems /// internal ItemRects MoreItems { get { return (_MoreItems); } } #endregion #region WeekRange /// /// Gets the week day range text /// internal string WeekRange { get { string s1 = String.Format("{0:MMM} {1:d} - ", _FirstDayOfWeek, _FirstDayOfWeek.Day); if (_FirstDayOfWeek.Month.Equals(_LastDayOfWeek.Month) == false) s1 = s1 + String.Format("{0:MMM} ", _LastDayOfWeek); s1 = s1 + String.Format("{0:d}", _LastDayOfWeek.Day); return (s1); } } #endregion #endregion #region Private properties /// /// Gets day height /// private int DayHeight { get { return (_Bounds.Height); } } /// /// Gets day width /// private float DayWidth { get { return ((float)_Bounds.Width / DaysInWeek); } } #endregion #region DayRect calculation /// /// Calculates the day rectangles for the /// current bounding rectangle /// private void CalcDayRects() { float dx = 0; int sx = _Bounds.X; int sy = _Bounds.Y; int x2 = sx; // Loop through each day in the week for (int i = 0; i < DaysInWeek; i++) { int x1 = x2; x2 = sx + (int)(dx + DayWidth); dx += DayWidth; if (i + 1 == DaysInWeek) x2 = _Bounds.X + _Bounds.Width; _DayRects[i].Bounds = new Rectangle(x1, sy, x2 - x1, DayHeight); } } #endregion } } #endif