public EnterPeriodPanel() { InitializeComponent(); CaptionFont = new Font(FontFamily.GenericSansSerif, 13); TextFont = new Font(FontFamily.GenericSansSerif, 10); DateRecord dr; DateTime d = DateTime.Now; dr = new DateRecord() { Title = "Year " + d.Year }; dr.StartDate = new GregorianDateTime(DateTime.Now.Year, 1, 1); dr.EndDate = new GregorianDateTime(DateTime.Now.Year, 12, 31); dr.UpdateSubtitle(); listBox1.Items.Add(dr); dr = new DateRecord() { Title = "Year " + (d.Year + 1).ToString() }; dr.StartDate = new GregorianDateTime(DateTime.Now.Year + 1, 1, 1); dr.EndDate = new GregorianDateTime(DateTime.Now.Year + 1, 12, 31); dr.UpdateSubtitle(); listBox1.Items.Add(dr); dr = new DateRecord(); if (d.Month == 12) { dr.Title = string.Format("{0} {1} - {2} {3}", GregorianDateTime.GetMonthAbreviation(12), d.Year, GregorianDateTime.GetMonthAbreviation(1), d.Year + 1); dr.StartDate = new GregorianDateTime(d.Year, 12, 1); dr.EndDate = new GregorianDateTime(d.Year + 1, 1, 31); } else { dr.Title = string.Format("{0} - {1} {2}", GregorianDateTime.GetMonthAbreviation(d.Month), GregorianDateTime.GetMonthAbreviation(d.Month + 1), d.Year); dr.StartDate = new GregorianDateTime(d.Year, d.Month, 1); dr.EndDate = new GregorianDateTime(d.Year, d.Month + 1, GregorianDateTime.GetMonthMaxDays(d.Year, d.Month + 1)); } dr.UpdateSubtitle(); listBox1.Items.Add(dr); dr = new DateRecord(); dr.Title = "Custom Date Range"; dr.Subtitle = "Enter start date manually"; listBox1.Items.Add(dr); }
internal void Draw(Graphics graphics, Size size, Base.TResultCalendar tResultCalendar, int nYear, int nMonth) { Graphics g = graphics; SizeF textSize = Size.Empty; float fontH1Size = Math.Min(size.Height - PaddingLeft - PaddingRight, size.Width * 0.707f - PaddingTop - PaddingBottom) / 30; xMarginLeft = PaddingLeft; yMarginTop = PaddingTop; xMarginRight = size.Width - PaddingRight; yUnderTitleBar = 0; yUnderMainTitle = 0; float tx; float cellInset = fontH1Size / 5; StringFormat rectFormat = new StringFormat(); rectFormat.Trimming = StringTrimming.EllipsisWord; DateTime dtToday = DateTime.Now; InitializeFonts(fontH1Size); string str; DrawTitle(nYear, nMonth, g); if (tResultCalendar == null) { return; } DrawRightTitleInfo(tResultCalendar, g); g.DrawLine(monthDivider, xMarginLeft, yUnderTitleBar, xMarginRight, yUnderTitleBar); firstDayOfWeekGeneral = GCDisplaySettings.Current.getValue(GCDS.GENERAL_FIRST_DOW); xCellWidth = (xMarginRight - xMarginLeft) / 7.0f; float tempTextHeight = fontH1Size / 5; // draw names of weekdays textSize = DrawWeekdayHeader(g, tempTextHeight); yTableTop = yUnderTitleBar + 2 * tempTextHeight + textSize.Height; yMarginBottom = size.Height - PaddingBottom; int firstIndex = 0; int firstDayDow = 0; for (int i = 0; i < tResultCalendar.m_nCount; i++) { GregorianDateTime gdt = tResultCalendar.m_pData[i].date; if (gdt.day == 1 && gdt.month == nMonth && gdt.year == nYear) { firstIndex = i; firstDayDow = gdt.dayOfWeek; } } int daysBeforeFirstDay = (firstDayDow - firstDayOfWeekGeneral + 14) % 7; int monthDays = GregorianDateTime.GetMonthMaxDays(nYear, nMonth); int totalDays = daysBeforeFirstDay + monthDays; int weeksCount = ((totalDays % 7) == 0) ? (totalDays / 7) : (totalDays / 7 + 1); yCellHeight = (yMarginBottom - yTableTop) / weeksCount; RectangleF rcf = new RectangleF(); int row, column, di; StringBuilder masaText = new StringBuilder(); for (int i = 1; i <= monthDays; i++) { di = daysBeforeFirstDay + i - 1; row = di / 7; column = di % 7; VAISNAVADAY vd = tResultCalendar.m_pData[firstIndex + i - 1]; VAISNAVADAY vd_prev = tResultCalendar.m_pData[firstIndex + i - 2]; VAISNAVADAY vd_next = tResultCalendar.m_pData[firstIndex + i]; ConstructMasaText(masaText, i, vd, vd_prev, vd_next); yCellMarginTop = yTableTop + row * yCellHeight + cellInset; xCellMarginLeft = xMarginLeft + column * xCellWidth + cellInset; rcf.X = xCellMarginLeft - cellInset; rcf.Y = yCellMarginTop - cellInset; rcf.Width = xCellWidth; rcf.Height = yCellHeight; if (vd.nFastID == FastType.FAST_EKADASI) { g.FillRectangle(Brushes.LightGreen, rcf); } else if (vd.nFastID != 0) { g.FillRectangle(Brushes.LightSkyBlue, rcf); } if (dtToday.Day == i && dtToday.Month == nMonth && dtToday.Year == nYear) { g.DrawRectangle(todayBorder, rcf.Left, rcf.Top, rcf.Width, rcf.Height); } textSize = DrawCellDayNumber(g, i); yCellAnchor1 = yCellMarginTop + textSize.Height + cellInset; xCellAnchor1 = xCellMarginLeft + textSize.Width + cellInset; xCellMarginRight = xCellMarginLeft + xCellWidth - 2 * cellInset; yCellMarginBottom = yCellMarginTop + yCellHeight - 2 * cellInset; tempTextHeight = DrawTithiText(g, vd); yCellAnchor1 = Math.Max(tempTextHeight + cellInset, yCellAnchor1); rcf.X = xCellAnchor1; rcf.Y = yCellMarginTop; rcf.Width = xCellMarginRight - xCellAnchor1; rcf.Height = textSize.Height + 2; str = GetEventsLineText(vd); Font f = fontS2; textSize = g.MeasureString(str, fontS2, Convert.ToInt32(xCellMarginRight - xCellMarginLeft)); if (textSize.Height + yCellAnchor1 + cellInset > yCellMarginTop + yCellHeight) { f = fontS3; textSize = g.MeasureString(str, f, Convert.ToInt32(xCellMarginRight - xCellMarginLeft)); } rcf.Y = yCellAnchor1; rcf.X = xCellMarginLeft; rcf.Width = textSize.Width; rcf.Height = Math.Min(yCellMarginBottom - yCellAnchor1, textSize.Height); g.DrawString(str, f, Brushes.Black, rcf, rectFormat); } // masa info text g.DrawString(masaText.ToString(), fontS2, Brushes.Black, xMarginLeft, yUnderMainTitle); // final step: draw matrix for (int i = 0; i < 8; i++) { g.DrawLine(dayDivider, xMarginLeft + i * xCellWidth, yTableTop, xMarginLeft + i * xCellWidth, yMarginBottom); } for (int j = 0; j <= weeksCount; j++) { g.DrawLine(dayDivider, xMarginLeft, yTableTop + j * yCellHeight, xMarginRight, yTableTop + j * yCellHeight); } }