264 lines
12 KiB
C#
264 lines
12 KiB
C#
using System;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Report;
|
|
using System.Collections.Generic;
|
|
using DevExpress.XtraReports.UI;
|
|
using System.Linq;
|
|
|
|
namespace BeWo.Report.DefaultReports
|
|
{
|
|
public partial class FLSSollIstWeeklyReport : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<FLSSollIstReportRO>
|
|
{
|
|
private Dictionary<String, decimal> summeIstNachWochenString = new Dictionary<String, decimal>();
|
|
private Dictionary<String, decimal> diffNachWochenString = new Dictionary<String, decimal>();
|
|
|
|
public FLSSollIstWeeklyReport()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void SetReportDataSource(FLSSollIstReportRO pRO)
|
|
{
|
|
var wochen = new List<FLSSollIstReportRO.FLSSollIstWochenSummen>();
|
|
|
|
if (pRO.RootObjectList.Count > 0)
|
|
{
|
|
if (pRO.RootObjectList[0].Groups.Count > 0)
|
|
{
|
|
wochen = pRO.RootObjectList[0].Groups[0].WochenSummen;
|
|
}
|
|
}
|
|
|
|
//Berechne Wochen Ist Gesamt
|
|
foreach (var ro in pRO.RootObjectList)
|
|
{
|
|
foreach (var grp in ro.Groups)
|
|
{
|
|
foreach (var woche in grp.WochenSummen)
|
|
{
|
|
String key = woche.WochenString;
|
|
|
|
if (!summeIstNachWochenString.ContainsKey(key))
|
|
{
|
|
summeIstNachWochenString.Add(key, 0);
|
|
diffNachWochenString.Add(key, (woche.SollStunden ?? 0) * -1);
|
|
}
|
|
summeIstNachWochenString[key] += woche.IstStunden ?? 0;
|
|
diffNachWochenString[key] += woche.IstStunden ?? 0;
|
|
}
|
|
}
|
|
}
|
|
CreateTableCells(wochen);
|
|
|
|
this.bindingSource1.DataSource = pRO;
|
|
}
|
|
|
|
|
|
private void CreateTableCells(List<FLSSollIstReportRO.FLSSollIstWochenSummen> wochen)
|
|
{
|
|
xrTableHeader.BeginInit();
|
|
xrTableData.BeginInit();
|
|
xrTableGesamt.BeginInit();
|
|
for (int i = 0; i < wochen.Count; i++)
|
|
{
|
|
if (i > 0)
|
|
{
|
|
AddSpalten(i, false);
|
|
|
|
}
|
|
xrTableRowHeader1.Cells[xrTableRowHeader1.Cells.Count - 1].Text = String.Format("KW {0}, {1:dd.MM.yy} - {2:dd.MM.yy}", wochen[i].KalenderWoche, wochen[i].WocheStart, wochen[i].WocheEnde);
|
|
}
|
|
|
|
//Add Gesamtsummen
|
|
AddSpalten(0, true);
|
|
xrTableRowHeader1.Cells[xrTableRowHeader1.Cells.Count - 1].Text = "Gesamt";
|
|
|
|
xrTableGesamt.EndInit();
|
|
xrTableData.EndInit();
|
|
xrTableHeader.EndInit();
|
|
|
|
}
|
|
|
|
private void AddSpalten(int index, bool gesamt)
|
|
{
|
|
var backcolor = System.Drawing.Color.White;
|
|
|
|
if (index % 2 == 0)
|
|
{
|
|
backcolor = System.Drawing.Color.Gainsboro;
|
|
}
|
|
if (gesamt)
|
|
{
|
|
backcolor = System.Drawing.Color.Wheat;
|
|
}
|
|
|
|
xrTableHeader.WidthF += 210;
|
|
xrTableData.WidthF += 210;
|
|
xrTableGesamt.WidthF += 210;
|
|
if (xrTableHeader.WidthF >= PageWidth)
|
|
{
|
|
PaperKind = DevExpress.Drawing.Printing.DXPaperKind.Custom;
|
|
PageWidth += 210;
|
|
}
|
|
var cell = xrTableRowHeader1.Cells[xrTableRowHeader1.Cells.Count - 1];
|
|
|
|
xrTableRowHeader1.Cells.Add(new XRTableCell { Weight = cell.Weight, BackColor = backcolor });
|
|
|
|
xrTableRowHeader2.Cells.Add(new XRTableCell { Weight = xrTableRowHeader2.Cells[xrTableRowHeader2.Cells.Count - 1].Weight, Text = "Soll", BackColor = backcolor });
|
|
xrTableRowHeader2.Cells.Add(new XRTableCell { Weight = xrTableRowHeader2.Cells[xrTableRowHeader2.Cells.Count - 1].Weight, Text = "Ist", BackColor = backcolor });
|
|
xrTableRowHeader2.Cells.Add(new XRTableCell { Weight = xrTableRowHeader2.Cells[xrTableRowHeader2.Cells.Count - 1].Weight, Text = "Diff.", BackColor = backcolor });
|
|
|
|
xrTableRowData.Cells.Add(new XRTableCell { Weight = xrTableRowData.Cells[xrTableRowData.Cells.Count - 1].Weight, Tag = String.Format("{0}_Soll", index), BackColor = backcolor });
|
|
xrTableRowData.Cells.Add(new XRTableCell { Weight = xrTableRowData.Cells[xrTableRowData.Cells.Count - 1].Weight, Tag = String.Format("{0}_Ist", index), BackColor = backcolor });
|
|
xrTableRowData.Cells.Add(new XRTableCell { Weight = xrTableRowData.Cells[xrTableRowData.Cells.Count - 1].Weight, Tag = String.Format("{0}_Diff", index), BackColor = backcolor });
|
|
|
|
xrTableRowGesamt.Cells.Add(new XRTableCell { Weight = xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 1].Weight, Tag = String.Format("{0}_Soll_Gesamt", index), BackColor = backcolor });
|
|
xrTableRowGesamt.Cells.Add(new XRTableCell { Weight = xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 1].Weight, Tag = String.Format("{0}_Ist_Gesamt", index), BackColor = backcolor });
|
|
xrTableRowGesamt.Cells.Add(new XRTableCell { Weight = xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 1].Weight, Tag = String.Format("{0}_Diff_Gesamt", index), BackColor = backcolor });
|
|
|
|
|
|
xrTableRowData.Cells[xrTableRowData.Cells.Count - 1].BeforePrint += new DevExpress.XtraReports.UI.BeforePrintEventHandler(this.DataCell_BeforePrint);
|
|
xrTableRowData.Cells[xrTableRowData.Cells.Count - 2].BeforePrint += new DevExpress.XtraReports.UI.BeforePrintEventHandler(this.DataCell_BeforePrint);
|
|
xrTableRowData.Cells[xrTableRowData.Cells.Count - 3].BeforePrint += new DevExpress.XtraReports.UI.BeforePrintEventHandler(this.DataCell_BeforePrint);
|
|
|
|
xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 1].BeforePrint += new DevExpress.XtraReports.UI.BeforePrintEventHandler(this.DataCell_BeforePrint);
|
|
xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 2].BeforePrint += new DevExpress.XtraReports.UI.BeforePrintEventHandler(this.DataCell_BeforePrint);
|
|
xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 3].BeforePrint += new DevExpress.XtraReports.UI.BeforePrintEventHandler(this.DataCell_BeforePrint);
|
|
|
|
if (gesamt)
|
|
{
|
|
xrTableRowData.Cells[xrTableRowData.Cells.Count - 1].Tag += "_Summe";
|
|
xrTableRowData.Cells[xrTableRowData.Cells.Count - 2].Tag += "_Summe";
|
|
xrTableRowData.Cells[xrTableRowData.Cells.Count - 3].Tag += "_Summe";
|
|
|
|
xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 1].Tag += "_Summe";
|
|
xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 2].Tag += "_Summe";
|
|
xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 3].Tag += "_Summe";
|
|
|
|
xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 1].DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
|
|
new DevExpress.XtraReports.UI.XRBinding("Text", null, "RootObjectList.DifferenzSollIstGesamt")});
|
|
xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 1].TextFormatString = "{0:0.00}";
|
|
xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 2].DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
|
|
new DevExpress.XtraReports.UI.XRBinding("Text", null, "RootObjectList.IstGesamt")});
|
|
xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 2].TextFormatString = "{0:0.00}";
|
|
xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 3].DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
|
|
new DevExpress.XtraReports.UI.XRBinding("Text", null, "RootObjectList.SollGesamt")});
|
|
xrTableRowGesamt.Cells[xrTableRowGesamt.Cells.Count - 3].TextFormatString = "{0:0.00}";
|
|
|
|
}
|
|
}
|
|
|
|
private void DataCell_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
XRTableCell cell = sender as XRTableCell;
|
|
|
|
// Zugriff auf das aktuelle Datenobjekt
|
|
var group = cell.Report.GetCurrentRow() as FLSSollIstReportRO.FLSSollIstReportGroupRO;
|
|
var tag = "";
|
|
|
|
if (cell.Tag != null)
|
|
{
|
|
tag = cell.Tag.ToString();
|
|
}
|
|
|
|
var indexStr = "";
|
|
|
|
if (tag.IndexOf("_") > 0)
|
|
{
|
|
indexStr = tag.Substring(0, tag.IndexOf("_"));
|
|
}
|
|
|
|
cell.ForeColor = System.Drawing.Color.Black;
|
|
|
|
//Im Tag wird der Wochenindex gespeichert
|
|
if (group != null && tag != null && Int32.TryParse(indexStr, out var idx))
|
|
{
|
|
if (idx >= 0 && idx < group.WochenSummen.Count)
|
|
{
|
|
var ws = group.WochenSummen[idx];
|
|
|
|
//Prüfe Summen Spalte (letzte Spalte)
|
|
if (tag.Contains("Summe"))
|
|
{
|
|
if (tag.Contains("Gesamt"))
|
|
{
|
|
if (cell.Text.StartsWith("-"))
|
|
{
|
|
cell.ForeColor = System.Drawing.Color.Red;
|
|
}
|
|
}
|
|
else if (tag.Contains("Ist"))
|
|
{
|
|
cell.Text = String.Format("{0:0.00}", group.WochenSummen.Sum(w => w.IstStunden));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (tag.Contains("Gesamt"))
|
|
{
|
|
var key = ws.WochenString;
|
|
|
|
if (tag.Contains("Ist"))
|
|
{
|
|
if (summeIstNachWochenString.ContainsKey(key))
|
|
{
|
|
cell.Text = String.Format("{0:0.00}", summeIstNachWochenString[key]);
|
|
}
|
|
else
|
|
{
|
|
cell.Text = String.Format("{0:0.00}", ws.IstStunden);
|
|
}
|
|
|
|
}
|
|
else if (tag.Contains("Soll"))
|
|
{
|
|
cell.Text = String.Format("{0:0.00}", ws.SollStunden);
|
|
}
|
|
else if (tag.Contains("Diff"))
|
|
{
|
|
decimal diff = ws.Differenz ?? 0;
|
|
|
|
if (diffNachWochenString.ContainsKey(key))
|
|
{
|
|
diff = diffNachWochenString[key];
|
|
}
|
|
cell.Text = String.Format("{0:0.00}", diff);
|
|
|
|
if (diff < 0)
|
|
{
|
|
cell.ForeColor = System.Drawing.Color.Red;
|
|
}
|
|
}
|
|
}
|
|
else if (tag.Contains("Ist"))
|
|
{
|
|
cell.Text = String.Format("{0:0.00}", ws.IstStunden);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
//if (rowObj is DayDetail myRow && myRow.Date != null)
|
|
//{
|
|
// var date = myRow.Date;
|
|
|
|
// XRTableRow row = cell.Parent as XRTableRow;
|
|
|
|
// System.Drawing.Color backColor = System.Drawing.Color.Transparent;
|
|
|
|
// if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
|
|
// backColor = System.Drawing.Color.LightSteelBlue;
|
|
// if (vs.IstFeiertag(date))
|
|
// backColor = System.Drawing.Color.Yellow;
|
|
|
|
// foreach (XRTableCell c in row.Cells)
|
|
// c.BackColor = backColor;
|
|
//}
|
|
}
|
|
}
|
|
}
|