Files
BeWoPlaner/Report/DefaultReports/RosterReport.cs
2020-09-30 10:00:31 +02:00

194 lines
7.1 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;
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 RosterReport()
{
InitializeComponent();
InitializeComponent2();
}
public void SetReportDataSource(RosterRO pRO)
{
int days = DateTime.DaysInMonth(pRO.ReportDateTime.Year, pRO.ReportDateTime.Month);
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);
}
}
Table1.EndInit();
Table2.EndInit();
bindingSource1.DataSource = pRO;
}
private void InitializeComponent2()
{
Table1 = new XRTable();
Table2 = new XRTable();
Row1 = new XRTableRow();
Row2 = new XRTableRow();
Table1.BeginInit();
Table2.BeginInit();
Table1.BackColor = System.Drawing.Color.LightSteelBlue;
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.5, 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.08, false);
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.16, 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;
}
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;
}
private void Cell_EvaluateBinding(object sender, BindingEventArgs e)
{
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 = System.Windows.Media.Color.FromRgb(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;
}
}
}
}