using System; using System.Drawing; using System.Globalization; using DevExpress.XtraReports.UI; using BeWo.Report.ReportObjects; using System.Collections.Generic; namespace BeWo.Report.DefaultReports { public partial class AbsenceReport : XtraReport, IBeWoReport { public int Month { get; set; } public int Year { get; set; } public List Feiertage { get; set; } public AbsenceReport() { InitializeComponent(); } public void SetReportDataSource(AbsenceRO pRO) { int i = DateTime.DaysInMonth(pRO.ReportFilter.Year, pRO.ReportFilter.Month); Month = pRO.ReportFilter.Month; Year = pRO.ReportFilter.Year; Feiertage = pRO.Feiertage; cellHeader29.Visible = cellDetail29.Visible = i >= 29; cellHeader30.Visible = cellDetail30.Visible = i >= 30; cellHeader31.Visible = cellDetail31.Visible = i >= 31; SetWeekDayNames(pRO.ReportFilter.Year, pRO.ReportFilter.Month, i); string date = SetDate(pRO); if (pRO.Teams != null) { if(pRO.Teams.Count > 0) { date += " ("; for (int z = 0; z < pRO.Teams.Count; z++) { var t = pRO.Teams[z]; date += t.Name; if (t.TeamOid != pRO.Teams[pRO.Teams.Count - 1].TeamOid) date += ", "; } date += ") "; } } lblReportInformation.Text = date; bindingSource1.DataSource = pRO; } private void SetWeekDayNames(int year, int month, int numberOfDays) { for (int i = 1; i <= numberOfDays; i++) { DateTime date = new DateTime(year, month, i); CultureInfo c = new CultureInfo("de-DE"); string weekday = c.DateTimeFormat.GetAbbreviatedDayName(date.DayOfWeek); cellHeader1.Row.Cells[i].Text += "\n" + weekday; } } private string SetDate(AbsenceRO pRO) { string date = ""; DateTimeFormatInfo dti = CultureInfo.GetCultureInfo("de-DE").DateTimeFormat; date += dti.GetMonthName(pRO.ReportFilter.Month).ToString() + " " + pRO.ReportFilter.Year; return date; } private void Cell_EvaluateBinding(object sender, BindingEventArgs e) { var cell = sender as XRTableCell; var sv = e.Value as CellValue; if (sv != null && !string.IsNullOrEmpty(sv.Color)) { int argb = Int32.Parse(sv.Color.Replace("#", ""), NumberStyles.HexNumber); Color clr = Color.FromArgb(argb); cell.BackColor = clr; } else { cell.BackColor = Color.Transparent; if(cell.Index <= DateTime.DaysInMonth(Year, Month)) { DateTime date = new DateTime(Year, Month, cell.Index); if (date.DayOfWeek == DayOfWeek.Sunday || date.DayOfWeek == DayOfWeek.Saturday) cell.BackColor = Color.LightGray; if (Feiertage != null) { if (Feiertage.Contains(date.Day)) cell.BackColor = Color.LightPink; } } } } } }