384 lines
15 KiB
C#
384 lines
15 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Globalization;
|
|
using DevExpress.XtraReports.UI;
|
|
using BeWo.Report.ReportObjects;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace BeWo.Report.DefaultReports
|
|
{
|
|
public partial class RosterReport : XtraReport, IBeWoReport<RosterRO>
|
|
{
|
|
public XRTable Table1 { get; set; }
|
|
public XRTable Table2 { get; set; }
|
|
|
|
public XRTableRow Row1 { get; set; }
|
|
public XRTableRow Row2 { get; set; }
|
|
|
|
public Tuple<XRTableCell, XRTableCell> Title { get; set; }
|
|
public Tuple<XRTableCell, XRTableCell>[] Days { get; set; }
|
|
public Tuple<XRTableCell, XRTableCell>[] Weeks { get; set; }
|
|
public Tuple<XRTableCell, XRTableCell> Month { get; set; }
|
|
|
|
public DateTime monthAndYear { get; set; }
|
|
public int Modifier { get; set; }
|
|
public int LastIndex { get; set; }
|
|
public List<int> Feiertage { get; set; }
|
|
public List<int> WoIndexes { get; set; }
|
|
|
|
public RosterReport()
|
|
{
|
|
Modifier = 0;
|
|
WoIndexes = new List<int>();
|
|
InitializeComponent();
|
|
InitializeComponent2();
|
|
}
|
|
|
|
public void SetReportDataSource(RosterRO pRO)
|
|
{
|
|
int days = DateTime.DaysInMonth(pRO.ReportDateTime.Year, pRO.ReportDateTime.Month);
|
|
monthAndYear = new DateTime(pRO.ReportDateTime.Year, pRO.ReportDateTime.Month, 1);
|
|
Feiertage = pRO.Feiertage;
|
|
|
|
Table1.BeginInit();
|
|
Table2.BeginInit();
|
|
|
|
Row1.Cells.Clear();
|
|
Row2.Cells.Clear();
|
|
|
|
Row1.Cells.Add(Title.Item1);
|
|
Row2.Cells.Add(Title.Item2);
|
|
|
|
int w = 0;
|
|
|
|
for (int i = 0; i < days; i++)
|
|
{
|
|
var tmp = Days[i];
|
|
|
|
Row1.Cells.Add(tmp.Item1);
|
|
Row2.Cells.Add(tmp.Item2);
|
|
|
|
if (pRO.ReportDateTime.AddDays(i).DayOfWeek == DayOfWeek.Sunday)
|
|
{
|
|
var week = Weeks[w++];
|
|
Row1.Cells.Add(week.Item1);
|
|
Row2.Cells.Add(week.Item2);
|
|
}
|
|
|
|
}
|
|
Row1.Cells.Add(Month.Item1);
|
|
Row2.Cells.Add(Month.Item2);
|
|
|
|
Table1.EndInit();
|
|
Table2.EndInit();
|
|
|
|
SetWeekDayNames(monthAndYear.Year, monthAndYear.Month, DateTime.DaysInMonth(monthAndYear.Year, monthAndYear.Month));
|
|
|
|
bindingSource1.DataSource = pRO;
|
|
|
|
List<DienstInfoDC> dienste = new List<DienstInfoDC>();
|
|
if (pRO.RosterReportRows.Count > 0)
|
|
{
|
|
if (pRO.RosterReportRows[0].AlleDienste.Count > 0)
|
|
{
|
|
foreach (var dienst in pRO.RosterReportRows[0].AlleDienste)
|
|
dienste.Add(dienst.Value);
|
|
}
|
|
}
|
|
|
|
if (dienste.Count > 0)
|
|
{
|
|
xrLabel_Image.Text = dienste[0].Kurz;
|
|
xrLabel_Image.BackColor = ColorTranslator.FromHtml(dienste[0].Farbe);
|
|
xrLabel_Image.BorderColor = Color.Black;
|
|
xrLabel_Time.Text = AdaptTime(dienste[0].Start.TimeOfDay, dienste[0].Ende.TimeOfDay);
|
|
dienste.RemoveAt(0);
|
|
int zeile = 0;
|
|
int elem = 1;
|
|
int counter = 1;
|
|
int schwellwert = 7;
|
|
foreach (var d in dienste)
|
|
{
|
|
var foreColor = Color.Black;
|
|
|
|
this.ReportFooter.Controls.Add(
|
|
new XRLabel()
|
|
{
|
|
LocationF = new PointF(xrLabel_Image.WidthF * elem + xrLabel_Time.WidthF * elem + 55f, xrLabel_Time.LocationF.Y + zeile * (xrLabel_Image.HeightF + 10)),
|
|
Font = xrLabel_Image.Font,
|
|
TextAlignment = xrLabel_Image.TextAlignment,
|
|
WidthF = xrLabel_Image.WidthF,
|
|
HeightF = xrLabel_Image.HeightF,
|
|
Borders = xrLabel_Image.Borders,
|
|
BorderColor = Color.Black,
|
|
BorderWidth = xrLabel_Image.BorderWidth,
|
|
BackColor = ColorTranslator.FromHtml(d.Farbe),
|
|
ForeColor = foreColor,
|
|
Text = d.Kurz
|
|
});
|
|
this.ReportFooter.Controls.Add(
|
|
new XRLabel()
|
|
{
|
|
LocationF = new PointF(xrLabel_Image.WidthF * (elem + 1) + xrLabel_Time.WidthF * elem + 67f, xrLabel_Time.LocationF.Y + zeile * (xrLabel_Time.HeightF + 10)),
|
|
Font = xrLabel_Time.Font,
|
|
TextAlignment = xrLabel_Time.TextAlignment,
|
|
WidthF = xrLabel_Time.WidthF,
|
|
HeightF = xrLabel_Time.HeightF,
|
|
Text = AdaptTime(d.Start.TimeOfDay, d.Ende.TimeOfDay),
|
|
Padding = xrLabel_Time.Padding
|
|
});
|
|
|
|
elem++;
|
|
counter++;
|
|
|
|
if (counter % schwellwert == 0) //Hier muss Wert für x wieder resettet werden
|
|
{
|
|
zeile++;
|
|
elem = 0;
|
|
if (schwellwert == 7)
|
|
schwellwert++;
|
|
counter = 1;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private string AdaptTime(TimeSpan start, TimeSpan ende)
|
|
{
|
|
string[] startArray = start.ToString().Split(':');
|
|
string[] endeArray = ende.ToString().Split(':');
|
|
|
|
return startArray[0] + ":" + startArray[1] + " - " + endeArray[0] + ":" + endeArray[1];
|
|
}
|
|
|
|
private void InitializeComponent2()
|
|
{
|
|
Table1 = new XRTable();
|
|
Table2 = new XRTable();
|
|
Row1 = new XRTableRow();
|
|
Row2 = new XRTableRow();
|
|
|
|
Table1.BeginInit();
|
|
Table2.BeginInit();
|
|
|
|
|
|
Table1.BackColor = System.Drawing.Color.LightBlue;
|
|
Table1.Borders = ((DevExpress.XtraPrinting.BorderSide)(((DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Top) | DevExpress.XtraPrinting.BorderSide.Bottom)));
|
|
Table1.Font = new System.Drawing.Font("Arial", 7F, System.Drawing.FontStyle.Bold);
|
|
Table1.LocationFloat = new DevExpress.Utils.PointFloat(0F, 0F);
|
|
Table1.Name = "xrTable1";
|
|
Table1.Rows.Add(Row1);
|
|
Table1.SizeF = new System.Drawing.SizeF(1109F, 20F);
|
|
Table1.StylePriority.UseBackColor = false;
|
|
Table1.StylePriority.UseBorders = false;
|
|
Table1.StylePriority.UseFont = false;
|
|
Table1.StylePriority.UseTextAlignment = false;
|
|
Table1.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
|
|
|
|
Table2.BackColor = System.Drawing.Color.Transparent;
|
|
Table2.Borders = ((DevExpress.XtraPrinting.BorderSide)((DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Bottom)));
|
|
Table2.Font = new System.Drawing.Font("Arial", 7F);
|
|
Table2.LocationFloat = new DevExpress.Utils.PointFloat(0F, 0F);
|
|
Table2.Name = "xrTable2";
|
|
Table2.Padding = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100F);
|
|
Table2.Rows.Add(Row2);
|
|
Table2.SizeF = new System.Drawing.SizeF(1109F, 20F);
|
|
Table2.StylePriority.UseBackColor = false;
|
|
Table2.StylePriority.UseBorders = false;
|
|
Table2.StylePriority.UseFont = false;
|
|
Table2.StylePriority.UsePadding = false;
|
|
Table2.StylePriority.UseTextAlignment = false;
|
|
Table2.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
|
|
Table2.CanGrow = false;
|
|
|
|
Row1.Name = "xrTableRow1";
|
|
Row1.Weight = 0.47;
|
|
|
|
Row2.Name = "xrTableRow2";
|
|
Row2.Weight = 0.47;
|
|
Row2.FormattingRules.Add(ruleNotApprovedAndExpiringNext4Months);
|
|
Row2.FormattingRules.Add(ruleNotApprovedAndExpiringNext8Months);
|
|
|
|
|
|
|
|
var empColumn = CreateColumn(0x0D, "Mitarbeiter", 0.33, false);
|
|
|
|
empColumn.Item2.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", null, "RosterReportRows.Title")});
|
|
|
|
Title = empColumn;
|
|
|
|
Days = new Tuple<XRTableCell, XRTableCell>[31];
|
|
for (int i = 0; i < Days.Length; i++)
|
|
{
|
|
var dayColumn = CreateColumn(0x0C, $"{i + 1}.", 0.10, false);
|
|
monthAndYear = new DateTime(monthAndYear.Year, monthAndYear.Month, i + 1);
|
|
dayColumn.Item2.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", null, $"RosterReportRows.Day{ i + 1 }") });
|
|
dayColumn.Item2.EvaluateBinding += new DevExpress.XtraReports.UI.BindingEventHandler(this.Cell_EvaluateBinding);
|
|
Days[i] = dayColumn;
|
|
}
|
|
|
|
Weeks = new Tuple<XRTableCell, XRTableCell>[6];
|
|
for (int i = 0; i < Weeks.Length; i++)
|
|
{
|
|
var weekColumns = CreateColumn(0x0C, "Wo.", 0.10, false);
|
|
|
|
weekColumns.Item2.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", null, $"RosterReportRows.Week{ i + 1 }", "{0:F2}")});
|
|
weekColumns.Item2.EvaluateBinding += new DevExpress.XtraReports.UI.BindingEventHandler(this.Cell_EvaluateBinding);
|
|
|
|
Weeks[i] = weekColumns;
|
|
}
|
|
var monthColumn = CreateColumn(0x0D, "Monat", 0.16, false);
|
|
monthColumn.Item2.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { new DevExpress.XtraReports.UI.XRBinding("Text", null, "RosterReportRows.MonthSum", "{0:F2}" )});
|
|
Month = monthColumn;
|
|
|
|
PageHeader.Controls.Add(Table1);
|
|
|
|
Detail1.Controls.Add(Table2);
|
|
Detail1.HeightF = 20;
|
|
|
|
|
|
|
|
Table1.EndInit();
|
|
Table2.EndInit();
|
|
}
|
|
|
|
private Tuple<XRTableCell, XRTableCell> CreateColumn(byte border, string text, double weight, bool canGrow)
|
|
{
|
|
var res = new Tuple<XRTableCell, XRTableCell>(new XRTableCell(), new XRTableCell());
|
|
|
|
res.Item1.Borders = DevExpress.XtraPrinting.BorderSide.All;
|
|
res.Item1.CanGrow = canGrow;
|
|
res.Item1.Text = text;
|
|
res.Item1.Weight = weight;
|
|
|
|
res.Item2.Borders = (DevExpress.XtraPrinting.BorderSide)border;
|
|
res.Item2.CanGrow = canGrow;
|
|
res.Item2.Weight = weight;
|
|
|
|
return res;
|
|
}
|
|
|
|
|
|
public int EvalCount { get; set; }
|
|
private void Cell_EvaluateBinding(object sender, BindingEventArgs e)
|
|
{
|
|
EvalCount++;
|
|
|
|
var cell = sender as XRTableCell;
|
|
var sv = e.Value as DienstInfoDC;
|
|
if (sv != null && !string.IsNullOrEmpty(sv.Farbe))
|
|
{
|
|
int argb = Int32.Parse(sv.Farbe.Replace("#", ""), NumberStyles.HexNumber);
|
|
var clr = Color.FromArgb(argb);
|
|
var clr2 = Color.FromArgb(clr.R, clr.G, clr.B);
|
|
|
|
cell.BackColor = clr;
|
|
cell.ForeColor = /*clr2.IsBrighter(70) ? Color.Black :*/ Color.White;
|
|
}
|
|
else
|
|
{
|
|
cell.BackColor = Color.Transparent;
|
|
cell.ForeColor = Color.Black;
|
|
|
|
var index = cell.Index;
|
|
|
|
if (Table1.Rows[0].Cells[index].Text.Contains("Wo"))
|
|
{
|
|
if (!WoIndexes.Contains(index))
|
|
WoIndexes.Add(index);
|
|
return;
|
|
}
|
|
if (WoIndexes.Any(i => i - 1 == index))
|
|
cell.Row.Cells[index].BackColor = Color.LightGray;
|
|
if (Feiertage != null)
|
|
{
|
|
if (Feiertage.Count > 0)
|
|
{
|
|
var header = Table1.Rows[0].Cells[index].Text;
|
|
int tag = 0;
|
|
if (header.Length == 4)
|
|
{
|
|
tag = int.Parse(header.Remove(2, 2));
|
|
}
|
|
else
|
|
{
|
|
tag = int.Parse(header.Remove(1, 2));
|
|
}
|
|
|
|
foreach (var feiertag in Feiertage)
|
|
{
|
|
if (tag == feiertag)
|
|
cell.Row.Cells[index].BackColor = Color.LightPink;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//if (index > LastIndex)
|
|
// Modifier = 0;
|
|
|
|
//if (index <= DateTime.DaysInMonth(monthAndYear.Year, monthAndYear.Month))
|
|
//{
|
|
// DateTime date = new DateTime(monthAndYear.Year, monthAndYear.Month, index);
|
|
|
|
// if (date.DayOfWeek == DayOfWeek.Sunday)
|
|
// {
|
|
// cell.Row.Cells[index].BackColor = Color.LightPink;
|
|
// Modifier++;
|
|
// }
|
|
// LastIndex = index;
|
|
|
|
//else if (Feiertage != null)
|
|
//{
|
|
// if (Feiertage.Contains(date.Day))
|
|
// cell.BackColor = Color.LightPink;
|
|
//}
|
|
//}
|
|
}
|
|
}
|
|
private void SetWeekDayNames(int year, int month, int numberOfDays)
|
|
{
|
|
int skipper = 0;
|
|
for (int i = 1; i <= numberOfDays; i++)
|
|
{
|
|
if (!Table1.Rows[0].Cells[i + skipper].Text.Contains("Wo"))
|
|
{
|
|
DateTime date = new DateTime(year, month, i);
|
|
CultureInfo c = new CultureInfo("de-DE");
|
|
string weekday = c.DateTimeFormat.GetAbbreviatedDayName(date.DayOfWeek);
|
|
weekday = weekday.Remove(weekday.Length - 1, 1);
|
|
|
|
Table1.Rows[0].Cells[i + skipper].Text += weekday;
|
|
}
|
|
else
|
|
{
|
|
skipper++;
|
|
i--;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private Color TransformStringToColor(string colorString)
|
|
{
|
|
//Hier bei keiner Farbe String weiß machen(Übergangslösung)
|
|
if (colorString == null)
|
|
colorString = "#FF7B68EE";
|
|
|
|
|
|
int argb = Int32.Parse(colorString.Replace("#", ""), NumberStyles.HexNumber);
|
|
var clr = Color.FromArgb(argb);
|
|
|
|
return Color.FromArgb(clr.R, clr.G, clr.B);
|
|
}
|
|
}
|
|
}
|