Files
BeWoPlaner/BeWo/View/Detail/Report/FlexibleReportView.xaml.cs
2026-07-14 14:40:39 +02:00

1012 lines
43 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Forms;
using BeWo.Controls;
using BeWo.Core;
using BeWo.ServiceProxy;
using BeWo.ViewModel;
using BS.Shared;
using BS.Shared.DataContracts;
using BS.Shared.Extensions;
using BS.Shared.Translation;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.Printing;
using DevExpress.Xpf.PivotGrid;
using DevExpress.Xpf.Charts;
using System.IO;
using MessageBox = System.Windows.MessageBox;
using DevExpress.XtraReports.UI;
using DevExpress.Data.PivotGrid;
using System.Windows.Media;
using BeWo.Core.Service;
using DevExpress.Utils.Gesture;
using DevExpress.Xpf.Core.Native;
namespace BeWo.View.Detail.Report
{
/// <summary>
/// Interaction logic for FlexibleReportView.xaml
/// </summary>
public partial class FlexibleReportView : BeWoView
{
#region Fields
private readonly List<string> _Columns = new List<string>() { nameof(FlexibleJahr), nameof(FlexibleMonat), nameof(FlexibleWeek), nameof(FlexibleTag) };
private readonly List<string> _Rows = new List<string>() { nameof(FlexibleKlient), nameof(FlexibleMitarbeiter) };
//private readonly List<string> _DataArbeitszeitDiff = new List<string>() { nameof(FlexibleDifferenzArbeitszeitIstSollMin), nameof(FlexibleDifferenzArbeitszeitIstSollStd) };
//private readonly List<string> _DataArbeitszeitPer = new List<string>() { nameof(UFlexibleProzentualeAbweichungArbeitszeit) };
//private readonly List<string> _DataBetreuungszeitDiff = new List<string>() { nameof(FlexibleDifferenzArbeitszeitIstSollMin), nameof(FlexibleDifferenzArbeitszeitIstSollStd) };
//private readonly List<string> _DataBetreuungszeitPer = new List<string>() { nameof(UFlexibleProzentualeAbweichungArbeitszeit) };
#endregion
#region Constructor
public FlexibleReportView()
{
InitializeComponent();
FlexibleArbeitszeitMinIst.CellFormat = "{0:N0}";
FlexibleArbeitszeitStdIst.CellFormat = "{0:N2}";
FlexibleBetreuungszeitMinIst.CellFormat = "{0:N0}";
FlexibleBetreuungszeitStdIst.CellFormat = "{0:N2}";
FlexibleGefahreneKilometer.CellFormat = "{0:N0}";
FlexibleRundungspotenzial.CellFormat = "{0:N0}";
FlexibleGefahreneKilometer.CellFormat = "{0:N0}";
FlexibleKlient.TotalValueFormat = "{0}";
FlexibleMitarbeiter.TotalValueFormat = "{0}";
FlexibleLeistung.TotalValueFormat = "{0}";
FlexibleLeistungskategorie.TotalValueFormat = "{0}";
FlexibleQuarter.ValueFormat = "{0}. Quartal";
// Soll Stunden erst mal entfernen
//FlexibleArbeitszeitMinSoll.CellFormat = "{0:N0}";
//FlexibleArbeitszeitStdSoll.CellFormat = "{0:N2}";
//FlexibleBetreuungszeitMinSoll.CellFormat = "{0:N0}";
//FlexibleBetreuungszeitStdSoll.CellFormat = "{0:N2}";
//FlexibleDifferenzArbeitszeitIstSollMin.CellFormat = "{0:N0}";
//FlexibleDifferenzArbeitszeitIstSollStd.CellFormat = "{0:N2}";
//FlexibleDifferenzBetreuungszeitIstSollMin.CellFormat = "{0:N0}";
//FlexibleDifferenzBetreuungszeitIstSollStd.CellFormat = "{0:N2}";
//UFlexibleProzentualeAbweichungArbeitszeit.UnboundExpressionMode = FieldUnboundExpressionMode.UseAggregateFunctions;
//UFlexibleProzentualeAbweichungArbeitszeit.UnboundType = FieldUnboundColumnType.Decimal;
//UFlexibleProzentualeAbweichungArbeitszeit.CellFormat = "{0:P2}";
//UFlexibleProzentualeAbweichungArbeitszeit.UnboundExpression = $"SUM([{FlexibleArbeitszeitStdIst.ExpressionFieldName}]) / SUM([{FlexibleArbeitszeitStdSoll.ExpressionFieldName}])";
//UFlexibleProzentualeAbweichungArbeitszeit.SummaryType = FieldSummaryType.Average;
//UFlexibleProzentualeAbweichungBetreuungszeit.UnboundExpressionMode = FieldUnboundExpressionMode.UseAggregateFunctions;
//UFlexibleProzentualeAbweichungBetreuungszeit.UnboundType = FieldUnboundColumnType.Decimal;
//UFlexibleProzentualeAbweichungBetreuungszeit.CellFormat = "{0:P2}";
//UFlexibleProzentualeAbweichungBetreuungszeit.UnboundExpression = $"SUM([{FlexibleBetreuungszeitStdIst.ExpressionFieldName}]) / SUM([{FlexibleBetreuungszeitStdSoll.ExpressionFieldName}])";
//UFlexibleProzentualeAbweichungBetreuungszeit.SummaryType = FieldSummaryType.Average;
//FlexibleStundensatz.SummaryType = FieldSummaryType.Average;
// Soll Stunden erst mal entfernen
FlexibleDatum.SortMode = FieldSortMode.Custom;
datePickerEndDate.AllowNullInput = false;
datePickerStartDate.AllowNullInput = false;
var i = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
datePickerStartDate.DateTime = i;
datePickerEndDate.DateTime = i.AddMonths(1).AddDays(-1);
myPivotGridControl.PrintColumnHeaders = false;
myPivotGridControl.PrintRowHeaders = false;
myPivotGridControl.PrintFilterHeaders = false;
myPivotGridControl.PrintDataHeaders = false;
myPivotGridControl.PrintUnusedFilterFields = false;
myPivotGridControl.PrintHeadersOnEveryPage = false;
myPivotGridControl.AllowCustomizationForm = true;
myPivotGridControl.FieldListIncludeVisibleFields = true;
myPivotGridControl.GroupFieldsInFieldList = true;
//checkBetrag.IsChecked = true;
//checkHilepläne.IsChecked = true;
//checkIst.IsChecked = true;
//checkKilometer.IsChecked = true;
checkKlienten.IsChecked = false;
checkMitarbeiter.IsChecked = false;
//checkRecords.IsChecked = true;
//checkSoll.IsChecked = true;
LayoutGroupPivotChart.IsCollapsible = true;
LayoutGroupPivotChart.Visibility = Visibility.Collapsed;
DocTypes = Cache.GetInstance().GetAllValueListEntrysByTypeSync(ValueListEntryType.DocumentType);
DocTypes.Sort((a, b) => a.ValueListEntryOid.Value.CompareTo(b.ValueListEntryOid.Value));
}
#endregion
#region Events
private void buttonRefresh_Click(object sender, RoutedEventArgs e)
{
var filter = new FlexibleReportFilterDC()
{
StartDatum = datePickerStartDate.DateTime,
EndDatum = datePickerEndDate.DateTime,
ReduzierteAnsicht = false, //checkReduzierteAnsicht.IsChecked,
AlleHilfeplaneAnzeigen = true, //checkHilepläne.IsChecked,
AlleKlientenAnzeigen = checkKlienten.IsChecked,
AlleMitarbeiterAnzeigen = checkMitarbeiter.IsChecked,
AlleServiceBerichteAnzeigen = true, //checkRecords.IsChecked,
BetragAnzeigen = true, //checkBetrag.IsChecked,
GefahreneKilometerAnzeigen = true, //checkKilometer.IsChecked,
IstAnzeigen = true, //checkIst.IsChecked,
SollAnzeigen = true //checkSoll.IsChecked
};
ServiceFacade.DoOperationsServiceAsync(
s => s.GetFlexibleReportResult(filter),
r => this.Dispatch(delegate
{
var liste = new List<FlexibleReportEntry>();
if (r.Entries != null) liste.AddRange(r.Entries.Select(FlexibleReportEntry.InitByFlexibleReportEntryDC));
if (r.Dummies != null)
foreach (var item in r.Dummies)
liste.AddRange(FlexibleReportEntry.InitByFlexibleReportDummyDC(item));
if (r.Employees != null)
liste.AddRange(FlexibleReportEntry.InitByFlexibleReportDictornary(r.Employees, filter.StartDatum, filter.EndDatum, filter.ReduzierteAnsicht.HasValue && filter.ReduzierteAnsicht.Value, true));
if (r.Customers != null)
liste.AddRange(FlexibleReportEntry.InitByFlexibleReportDictornary(r.Customers, filter.StartDatum, filter.EndDatum, filter.ReduzierteAnsicht.HasValue && filter.ReduzierteAnsicht.Value, false));
myPivotGridControl.DataSource = liste;
checkBoxChart.IsEnabled = true;
}));
}
private void GridControl_CustomCellDisplayText(object sender, PivotCellDisplayTextEventArgs e)
{
//if (e.data)
//if (e.DataField.Name == nameof(FlexibleArbeitszeitStdSoll))
//{
// if (e.RowField != null && (e.RowField.Name == nameof(FlexibleLeistungskategorie) || e.RowField.Name == nameof(FlexibleLeistung)))
// {
// //e.DisplayText = "";
// }
//}
if (e.Value != null && decimal.TryParse(e.Value.ToString(), out decimal d) && d == 0)
e.DisplayText = "";
if (e.DisplayText == "Fehler")
e.DisplayText = "";
}
private void GridControl_CustomFieldValueCells(object sender, PivotCustomFieldValueCellsEventArgs e)
{
var pivot = (PivotGridControl)sender;
if (pivot.DataSource == null)
return;
// Iterates through all row headers.
for (int i = e.GetCellCount(false) - 1; i >= 0; i--)
{
var cell = e.GetCell(false, i);
if (cell == null)
continue;
// If the current header corresponds to the "Employee B"
// field value, and is not the Total Row header,
// it is removed with all corresponding rows.
if (Equals(cell.Value, null) && cell.ValueType == FieldValueType.Value)
e.Remove(cell);
if (string.IsNullOrWhiteSpace(cell.DisplayText) && cell.ValueType == FieldValueType.Total)
e.Remove(cell);
}
}
private void MyPivotGridControl_CustomValueAppearance(object sender, PivotCustomValueAppearanceEventArgs e)
{
// Header
}
private void CheckChartChanged(object sender, RoutedEventArgs e)
{
if (myPivotGridControl.DataSource == null) return;
if (!checkBoxChart.IsChecked.HasValue) return;
ChartControl.Visibility = checkBoxChart.IsChecked.Value ? Visibility.Visible : Visibility.Collapsed;
LayoutGroupPivotChart.Visibility = checkBoxChart.IsChecked.Value ? Visibility.Visible : Visibility.Collapsed;
if (ChartControl.Visibility == Visibility.Visible)
{
InitChart();
}
else
{
LayoutGroupPivotGrid.Height = double.NaN;
}
}
private void CheckDataBarChanged(object sender, RoutedEventArgs e)
{
if (!checkBoxData.IsChecked.HasValue) return;
if (myPivotGridControl.DataSource == null) return;
//var conditions = CreateDataBarConditions(_Columns, _Rows, _DataArbeitszeitDiff, "GreenSolidDataBar");
//var conditions2 = CreateDataBarConditions(_Columns, _Rows, _DataBetreuungszeitDiff, "GreenSolidDataBar");
//if (checkBoxData.IsChecked.Value)
//{
// myPivotGridControl.FormatConditions.AddRange(conditions);
// myPivotGridControl.FormatConditions.AddRange(conditions2);
//}
//else
//{
// myPivotGridControl.FormatConditions.RemoveRange(conditions);
// myPivotGridControl.FormatConditions.RemoveRange(conditions2);
//}
}
private void ButtonLayoutSave_Click(object sender, RoutedEventArgs e)
{
popup_save_layout.IsOpen = true;
#region Fenster (alt)
/*
var control = new FlexibleReportLayoutSaveControl();
var beWoWindow = new BeWoWindow();
control.CancelButtonClicked += () => beWoWindow.Close();
control.SaveButtonClicked += delegate
{
var liste = new List<FlexibleReportLayout>();
ServiceFacade.DoOperationsServiceAsync(
s => s.GetFlexibleReportLayouts(),
r => this.Dispatch(delegate
{
foreach (var item in r)
{
liste.Add(FlexibleReportLayout.InitByFlexibleReportLayoutDC(item));
}
}));
if (string.IsNullOrWhiteSpace(control.LayoutName))
{
MessageBox.Show("Fehler beim Hinzufügen des Berichts. Der Name darf nicht leer sein.", "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
if (liste.Any(x => x.LayoutName == control.LayoutName))
{
MessageBox.Show("Fehler beim Hinzufügen des Berichts. Der Name existiert bereits.", "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
var layout = new FlexibleReportLayoutDC()
{
LayoutName = control.LayoutName,
LayoutString = LayoutString
};
ServiceFacade.DoOperationsServiceAsync(s => s.InsertNewFlexibleReportLayout(layout));
MessageBox.Show("Bericht erfolgreich hinzugefügt!", "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Information);
beWoWindow.Close();
};
beWoWindow.Height = 200;
beWoWindow.Width = 500;
beWoWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
beWoWindow.GroupBoxContent = control;
beWoWindow.Owner = BeWoApp.CurrentBeWo.MainWindow;
beWoWindow.rootGroupBox.Header = "Bericht speichern";
beWoWindow.ShowDialog();
*/
#endregion
}
private void popupbutton_layout_speichern_Click(object sender, RoutedEventArgs e)
{
var liste = new List<FlexibleReportLayout>();
ServiceFacade.DoOperationsServiceAsync(
s => s.GetFlexibleReportLayouts(), //hier muss noch Filter angepasst werden, damit alle Layouts geliefert werden, die für alle sichtbar sind
r => this.Dispatch(delegate
{
foreach (var item in r)
{
liste.Add(FlexibleReportLayout.InitByFlexibleReportLayoutDC(item));
}
}));
if (string.IsNullOrWhiteSpace(textbox_layoutname.Text))
{
MessageBox.Show("Fehler beim Hinzufügen des Berichts. Der Name darf nicht leer sein.", "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
if (liste.Any(x => x.LayoutName == textbox_layoutname.Text))
{
MessageBox.Show("Fehler beim Hinzufügen des Berichts. Der Name existiert bereits.", "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
var layout = new FlexibleReportLayoutDC()
{
LayoutName = textbox_layoutname.Text,
LayoutString = LayoutString,
VisibleForAllEmployee = (bool)checkbox_VisibleForAllEmployee.IsChecked ? true : false
};
ServiceFacade.DoOperationsServiceAsync(s => s.InsertNewFlexibleReportLayout(layout));
MessageBox.Show("Bericht erfolgreich hinzugefügt!", "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Information);
popup_save_layout.IsOpen = false;
}
private void popupbutton_speichern_abbrechen_Click(object sender, RoutedEventArgs e)
{
popup_save_layout.IsOpen = false;
}
private void ButtonLayoutLoad_Click(object sender, RoutedEventArgs e)
{
var control = new FlexibleReportLayoutListControl();
var beWoWindow = new BeWoWindow
{
rootGroupBox = { Header = "Bericht Laden" },
Height = 500,
Width = 500,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
GroupBoxContent = control,
Owner = BeWoApp.CurrentBeWo.MainWindow
};
control.DatagridRegions.Columns.Remove(control.LayoutDeleteColumn);
control.LayoutNameColumn.ReadOnly = true;
control.ActionButton.Content = "Laden";
control.ActionButtonClicked += delegate
{
if (control.SelectedLayout == null)
{
MessageBox.Show("Sie haben keine Berichte angelegt/ausgewählt.", "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
LayoutString = control.SelectedLayout.LayoutString;
beWoWindow.Close();
};
control.CancelButtonClicked += () => beWoWindow.Close();
control.MouseDoubleClick += delegate
{
if (control.SelectedLayout == null)
{
MessageBox.Show("Sie haben keine Berichte angelegt/ausgewählt.", "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
LayoutString = control.SelectedLayout.LayoutString;
beWoWindow.Close();
};
beWoWindow.ShowDialog();
}
private void ButtonLayoutEdit_Click(object sender, RoutedEventArgs e)
{
var control = new FlexibleReportLayoutListControl();
var beWoWindow = new BeWoWindow
{
rootGroupBox = { Header = "Berichte bearbeiten" },
Height = 500,
Width = 500,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
GroupBoxContent = control,
Owner = BeWoApp.CurrentBeWo.MainWindow
};
control.ActionButton.Content = "Speichern";
control.ActionButtonClicked += delegate
{
if (control.IsDirty)
{
control.Save();
MessageBox.Show("Die Liste wurde erfolgreich aktualisiert.", "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Asterisk);
}
beWoWindow.Close();
};
control.CancelButtonClicked += delegate
{
if (!control.IsDirty)
{
beWoWindow.Close();
return;
}
var result = MessageBox.Show("Möchten Sie die Änderung(en) verwerfen?", "BeWoPlaner", MessageBoxButton.YesNo, MessageBoxImage.Question);
switch (result)
{
case MessageBoxResult.None:
return;
case MessageBoxResult.Yes:
beWoWindow.Close();
break;
case MessageBoxResult.No:
control.Save();
MessageBox.Show("Die Liste wurde erfolgreich aktualisiert.", "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Asterisk);
beWoWindow.Close();
break;
}
};
beWoWindow.ShowDialog();
}
private void MyPivotGridControl_CustomCellAppearance(object sender, PivotCustomCellAppearanceEventArgs e)
{
if (e.ColumnValueType == FieldValueType.Total || e.RowValueType == FieldValueType.Total)
e.Background = e.Selected
? new SolidColorBrush(Color.FromArgb(180, 193, 180, 120))
: new SolidColorBrush(Color.FromArgb(60, 150, 150, 150));
if (e.ColumnValueType == FieldValueType.GrandTotal || e.RowValueType == FieldValueType.GrandTotal)
e.Background = e.Selected
? new SolidColorBrush(Color.FromArgb(180, 191, 168, 66))
: new SolidColorBrush(Color.FromArgb(60, 120, 120, 120));
}
private void CheckDataBarPerChanged(object sender, RoutedEventArgs e)
{
if (myPivotGridControl.DataSource == null) return;
if (!checkBoxDataPer.IsChecked.HasValue) return;
//var conditions = CreateDataBarConditions(_Columns, _Rows, _DataArbeitszeitPer, "BlueSolidDataBar", 0, 1);
//var conditions2 = CreateDataBarConditions(_Columns, _Rows, _DataBetreuungszeitPer, "BlueSolidDataBar", 0, 1);
//if (checkBoxDataPer.IsChecked.Value)
//{
// myPivotGridControl.FormatConditions.AddRange(conditions);
// myPivotGridControl.FormatConditions.AddRange(conditions2);
//}
//else
//{
// myPivotGridControl.FormatConditions.RemoveRange(conditions);
// myPivotGridControl.FormatConditions.RemoveRange(conditions2);
//}
}
private void ButtonLayoutPrint_Click(object sender, RoutedEventArgs e)
{
myPivotGridControl.ShowPrintPreviewDialog(Window.GetWindow(this));
}
private void MyPivotGridControl_CustomGroupInterval(object sender, PivotCustomGroupIntervalEventArgs e)
{
e.GroupValue = ((DateTime)e.Value).ToString("ddd, dd.MM.yyyy");
}
private void MyPivotGridControl_CustomFieldSort(object sender, PivotCustomFieldSortEventArgs e)
{
if (e.Value1 != null && e.Value2 != null)
{
var str1 = e.Value1.ToString();
var str2 = e.Value2.ToString();
if (str1.Contains(","))
{
str1 = str1.Substring(str1.IndexOf(",") + 1);
}
if (str2.Contains(","))
{
str2 = str2.Substring(str2.IndexOf(",") + 1);
}
DateTime dt1;
DateTime dt2;
if (DateTime.TryParse(str1, out dt1) && DateTime.TryParse(str2, out dt2))
{
e.Result = dt1.CompareTo(dt2);
e.Handled = true;
}
}
}
private void ButtonShowOptions_Click(object sender, RoutedEventArgs e)
{
myPivotGridControl.IsFieldListVisible = true;
}
private void MyPivotGridControl_CellDoubleClick(object sender, PivotCellEventArgs e)
{
var selectedEntries = e.CreateDrillDownDataSource()
.Cast<PivotDrillDownDataRow>()
.Select(row => ActualFlexibleReportEntries[row.ListSourceRowIndex])
.Where(item => item.Type == FlexibleReportEntryType.ServiceRecordEntry)
.ToList();
if (selectedEntries.Count > 0)
{
var beWoWindow = new BeWoWindow
{
Height = 500,
Width = 1500,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
GroupBoxContent = new FlexibleReportEntryDetail(selectedEntries, DocTypes),
Owner = BeWoApp.CurrentBeWo.MainWindow,
rootGroupBox = { Header = Translator.Translate("Zeiterfassung") }
};
beWoWindow.ShowDialog();
}
else
{
MessageBox.Show("Keine Einträge vorhanden.", "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
#endregion
#region Proterties
public List<ValueListEntryDC> DocTypes { get; set; }
public string LayoutString
{
get
{
using (var stream = new MemoryStream())
{
myPivotGridControl.SaveLayoutToStream(stream);
return Encoding.Default.GetString(stream.ToArray());
}
}
set
{
using (var stream = new MemoryStream(Encoding.Default.GetBytes(value ?? "")))
{
myPivotGridControl.RestoreLayoutFromStream(stream);
}
}
}
public List<FlexibleReportEntry> ActualFlexibleReportEntries => myPivotGridControl?.DataSource as List<FlexibleReportEntry>;
#endregion
#region Methoden
private void InitChart()
{
var chart = ChartFactory.GenerateDiagram(typeof(BarSideBySideSeries2D), false);
//chart.CrosshairSeriesLabelItems
ChartControl.Diagram = chart;
}
private IEnumerable<DataBarFormatCondition> CreateDataBarConditions(List<string> columns, List<string> rows, List<string> datas, string formatName)
{
foreach (var column in columns)
{
foreach (var row in rows)
{
foreach (var data in datas)
{
yield return new DataBarFormatCondition()
{
ColumnName = column,
RowName = row,
MeasureName = data,
ApplyToSpecificLevel = true,
PredefinedFormatName = formatName,
};
}
}
}
}
private IEnumerable<DataBarFormatCondition> CreateDataBarConditions(List<string> columns, List<string> rows, List<string> datas, string formatName, decimal min, decimal max)
{
foreach (var column in columns)
{
foreach (var row in rows)
{
foreach (var data in datas)
{
var cond = new DataBarFormatCondition()
{
ColumnName = column,
RowName = row,
MeasureName = data,
ApplyToSpecificLevel = true,
PredefinedFormatName = formatName,
};
cond.MinValue = min;
cond.MaxValue = max;
yield return cond;
}
}
}
}
private DevExpress.XtraPivotGrid.PivotGroupInterval GetGroupInterval(FieldGroupInterval groupInterval)
{
switch (groupInterval)
{
case FieldGroupInterval.DateDay:
return DevExpress.XtraPivotGrid.PivotGroupInterval.DateDay;
case FieldGroupInterval.DateWeekOfYear:
return DevExpress.XtraPivotGrid.PivotGroupInterval.DateWeekOfYear;
case FieldGroupInterval.DateMonth:
return DevExpress.XtraPivotGrid.PivotGroupInterval.DateMonth;
case FieldGroupInterval.DateYear:
return DevExpress.XtraPivotGrid.PivotGroupInterval.DateYear;
}
return DevExpress.XtraPivotGrid.PivotGroupInterval.Default;
}
private DevExpress.XtraPivotGrid.PivotArea GetArea(FieldArea area)
{
switch (area)
{
case FieldArea.RowArea:
return DevExpress.XtraPivotGrid.PivotArea.RowArea;
case FieldArea.ColumnArea:
return DevExpress.XtraPivotGrid.PivotArea.ColumnArea;
case FieldArea.FilterArea:
return DevExpress.XtraPivotGrid.PivotArea.FilterArea;
case FieldArea.DataArea:
return DevExpress.XtraPivotGrid.PivotArea.DataArea;
}
return DevExpress.XtraPivotGrid.PivotArea.FilterArea;
}
#endregion
#region Classes
public class FlexibleReportEntry
{
public long? ServiceRecordOid { get; set; }
public long? CustomerOid { get; set; }
public string CustomerString { get; set; }
public long? SupportConceptOid { get; set; }
public string SupportConceptString { get; set; }
public long? EmployeeOid { get; set; }
public string EmployeeString { get; set; }
public string Team { get; set; }
public string Leistungskategorie { get; set; }
public string Leistung { get; set; }
public decimal? IstArbeitszeitMinuten { get; set; }
public decimal? SollArbeitszeitMinuten { get; set; }
public decimal? IstBetreuungszeitMinuten { get; set; }
public decimal? SollBetreuungszeitMinuten { get; set; }
public DateTime StartDatum { get; set; }
public DateTime EndDatum { get; set; }
public FlexibleReportEntryType Type { get; set; }
public decimal? Kilometer { get; set; }
public decimal? Betrag { get; set; }
public decimal? Stundensatz { get; set; }
public decimal Rundungspotenzial { get; set; }
public string Organisation { get; set; }
public string Notice { get; set; }
public string Notice2 { get; set; }
public string Notice3 { get; set; }
public string Notice4 { get; set; }
public string Notice5 { get; set; }
public decimal? IstArbeitszeitStunden => IstArbeitszeitMinuten / 60;
public decimal? SollArbeitszeitStunden => SollArbeitszeitMinuten / 60;
public decimal DifferenzArbeitszeitIstSollMinuten => (IstArbeitszeitMinuten ?? 0) - (SollArbeitszeitMinuten ?? 0);
public decimal DifferenzArbeitszeitIstSollStunden => DifferenzArbeitszeitIstSollMinuten / 60;
public decimal? IstBetreuungszeitStunden => IstBetreuungszeitMinuten / 60;
public decimal? SollBetreuungszeitStunden => SollBetreuungszeitMinuten / 60;
public decimal DifferenzBetreuungszeitIstSollMinuten => (IstBetreuungszeitMinuten ?? 0) - (SollBetreuungszeitMinuten ?? 0);
public decimal DifferenzBetreuungszeitIstSollStunden => DifferenzBetreuungszeitIstSollMinuten / 60;
public int Anzahl { get; set; }
public static FlexibleReportEntry InitByFlexibleReportEntryDC(FlexibleReportEntryDC entryDC)
{
var entry = new FlexibleReportEntry()
{
ServiceRecordOid = entryDC.ServiceRecordOid,
CustomerOid = entryDC.CustomerOid,
CustomerString = entryDC.CustomerString ?? Translator.Translate(" Ohne Klient/in"),
EmployeeOid = entryDC.EmployeeOid,
EmployeeString = entryDC.EmployeeString ?? Translator.Translate(" Ohne Mitarbeiter/in"),
SupportConceptOid = entryDC.SupportConceptOid,
SupportConceptString = entryDC.SupportConceptString ?? Translator.Translate(" Ohne Hilfeplan"),
IstArbeitszeitMinuten = entryDC.IstArbeitszeitMinuten,
IstBetreuungszeitMinuten = entryDC.IstBetreuungszeitMinuten,
StartDatum = entryDC.StartDatum,
EndDatum = entryDC.EndDatum,
Leistung = entryDC.Leistung,
Leistungskategorie = entryDC.Leistungskategorie,
Team = entryDC.Team,
SollArbeitszeitMinuten = entryDC.SollArbeitszeitMinuten,
SollBetreuungszeitMinuten = entryDC.SollBetreuungszeitMinuten,
Type = FlexibleReportEntryType.ServiceRecordEntry,
Kilometer = entryDC.Kilometer,
Organisation = entryDC.Organisation,
Rundungspotenzial = (entryDC.IstBetreuungszeitMinuten ?? 0) - ((decimal)entryDC.EndDatum.Subtract(entryDC.StartDatum).TotalMinutes),
Betrag = entryDC.Betrag,
Stundensatz = entryDC.Stundensatz,
Notice = entryDC.Notice,
Notice2 = entryDC.Notice2,
Notice3 = entryDC.Notice3,
Notice4 = entryDC.Notice4,
Notice5 = entryDC.Notice5,
Anzahl = 1
};
return entry;
}
public static IList<FlexibleReportEntry> InitByFlexibleReportDummyDC(FlexibleReportDummyDC dummyDC)
{
var flexibleReports = new List<FlexibleReportEntry>();
for (DateTime date = dummyDC.StartDate; date.Date <= dummyDC.EndDate; date = date.AddDays(1.0))
{
flexibleReports.Add(new FlexibleReportEntry()
{
SollArbeitszeitMinuten = dummyDC.SollArbeitszeit ?? 0,
IstArbeitszeitMinuten = 0m,
SollBetreuungszeitMinuten = dummyDC.SollBetreuungszeit ?? 0,
IstBetreuungszeitMinuten = 0m,
Betrag = 0,
CustomerOid = dummyDC.CustomerOid,
CustomerString = dummyDC.CustomerString,
StartDatum = date,
EndDatum = dummyDC.EndDate,
EmployeeOid = dummyDC.EmployeeOid,
EmployeeString = dummyDC.EmployeeString,
Kilometer = null,
Leistung = null,
Leistungskategorie = dummyDC.Leistungskategorie,
Organisation = dummyDC.Organisation,
Rundungspotenzial = 0m,
Stundensatz = 0m,
SupportConceptOid = dummyDC.SupportConceptOid,
SupportConceptString = dummyDC.SupportConceptString,
Team = null,
Type = FlexibleReportEntryType.SupportConceptEntry
});
}
return flexibleReports;
}
public static IList<FlexibleReportEntry> InitByFlexibleReportDictornary(Dictionary<long, string> dic, DateTime start, DateTime ende, bool reduziert, bool isEmployee)
{
var flexibleReports = new List<FlexibleReportEntry>();
foreach (var item in dic)
{
for (var date = start; date <= ende; date = date.AddDays(1))
{
// isEmployee = true -> Employee
if (isEmployee)
flexibleReports.Add(new FlexibleReportEntry()
{
EmployeeOid = item.Key,
EmployeeString = item.Value,
Type = FlexibleReportEntryType.EmployeeNullEntry,
StartDatum = date,
EndDatum = date
});
// isEmployee = false -> Customer
else
flexibleReports.Add(new FlexibleReportEntry()
{
CustomerOid = item.Key,
CustomerString = item.Value,
Type = FlexibleReportEntryType.CustomerNullEntry,
StartDatum = date,
EndDatum = date
});
if (reduziert)
break;
}
}
return flexibleReports;
}
// Wurde eig nur zum Testen verwendet, kann bei Bedarf überschrieben werden
public override string ToString()
{
return StartDatum.ToShortTimeString();
}
}
public class FlexibleReportLayout
{
public long FlexibleReportLayoutOid { get; set; }
public long CreatorOid { get; set; }
public string LayoutName { get; set; }
public string LayoutString { get; set; }
public static FlexibleReportLayout InitByFlexibleReportLayoutDC(FlexibleReportLayoutDC entryDC)
{
return new FlexibleReportLayout()
{
CreatorOid = entryDC.CreatorOid,
LayoutName = entryDC.LayoutName,
LayoutString = entryDC.LayoutString,
FlexibleReportLayoutOid = entryDC.FlexibleReportOid.Value
};
}
public FlexibleReportLayoutDC ConvertToFlexibleReportLayoutDC()
{
return new FlexibleReportLayoutDC()
{
CreatorOid = CreatorOid,
LayoutName = LayoutName,
LayoutString = LayoutString,
FlexibleReportOid = FlexibleReportLayoutOid
};
}
}
internal static class ChartFactory
{
static readonly Type XYDiagram2DType = typeof(XYDiagram2D);
static readonly Type XYDiagram3DType = typeof(XYDiagram3D);
static readonly Type SimpleDiagram3DType = typeof(SimpleDiagram3D);
static readonly Type SimpleDiagram2DType = typeof(SimpleDiagram2D);
static readonly Type DefaultSeriesType = typeof(BarStackedSeries2D);
static Dictionary<Type, SeriesTypeDescriptor> seriesTypes;
public static Dictionary<Type, SeriesTypeDescriptor> SeriesTypes
{
get
{
if (seriesTypes == null)
seriesTypes = CreateSeriesTypes();
return seriesTypes;
}
}
static Dictionary<Type, SeriesTypeDescriptor> CreateSeriesTypes()
{
Dictionary<Type, SeriesTypeDescriptor> seriesTypes = new Dictionary<Type, SeriesTypeDescriptor>();
seriesTypes.Add(typeof(AreaFullStackedSeries2D), new SeriesTypeDescriptor { DiagramType = XYDiagram2DType, DisplayText = "Area Full-Stacked Series 2D" });
seriesTypes.Add(typeof(AreaSeries2D), new SeriesTypeDescriptor { DiagramType = XYDiagram2DType, DisplayText = "Area Series 2D" });
seriesTypes.Add(typeof(AreaStackedSeries2D), new SeriesTypeDescriptor { DiagramType = XYDiagram2DType, DisplayText = "Area Stacked Series 2D" });
seriesTypes.Add(typeof(BarFullStackedSeries2D), new SeriesTypeDescriptor { DiagramType = XYDiagram2DType, DisplayText = "Bar Full-Stacked Series 2D" });
seriesTypes.Add(typeof(BarStackedSeries2D), new SeriesTypeDescriptor { DiagramType = XYDiagram2DType, DisplayText = "Bar Stacked Series 2D" });
seriesTypes.Add(typeof(LineSeries2D), new SeriesTypeDescriptor { DiagramType = XYDiagram2DType, DisplayText = "Line Series 2D" });
seriesTypes.Add(typeof(PointSeries2D), new SeriesTypeDescriptor { DiagramType = XYDiagram2DType, DisplayText = "Point Series 2D" });
seriesTypes.Add(typeof(AreaSeries3D), new SeriesTypeDescriptor { DiagramType = XYDiagram3DType, DisplayText = "Area Series 3D" });
seriesTypes.Add(typeof(AreaStackedSeries3D), new SeriesTypeDescriptor { DiagramType = XYDiagram3DType, DisplayText = "Area Stacked Series 3D" });
seriesTypes.Add(typeof(AreaFullStackedSeries3D), new SeriesTypeDescriptor { DiagramType = XYDiagram3DType, DisplayText = "Area Full-Stacked Series 3D" });
seriesTypes.Add(typeof(BarSeries3D), new SeriesTypeDescriptor { DiagramType = XYDiagram3DType, DisplayText = "Bar Series 3D" });
seriesTypes.Add(typeof(BarSideBySideSeries2D), new SeriesTypeDescriptor { DiagramType = XYDiagram2DType, DisplayText = "Bar Series 2D" });
seriesTypes.Add(typeof(PointSeries3D), new SeriesTypeDescriptor { DiagramType = XYDiagram3DType, DisplayText = "Point Series 3D" });
seriesTypes.Add(typeof(PieSeries3D), new SeriesTypeDescriptor { DiagramType = SimpleDiagram3DType, DisplayText = "Pie Series 3D" });
seriesTypes.Add(typeof(PieSeries2D), new SeriesTypeDescriptor { DiagramType = SimpleDiagram2DType, DisplayText = "Pie Series 2D" });
return seriesTypes;
}
public class SeriesTypeDescriptor
{
public Type DiagramType { get; set; }
public string DisplayText { get; set; }
}
public static Diagram GenerateDiagram(Type seriesType, bool? showPointsLabels)
{
Series seriesTemplate = CreateSeriesInstance(seriesType);
Diagram diagram = CreateDiagramBySeriesType(seriesType);
if (diagram is XYDiagram2D)
PrepareXYDiagram2D(diagram as XYDiagram2D);
if (diagram is XYDiagram3D)
PrepareXYDiagram3D(diagram as XYDiagram3D);
if (diagram is Diagram3D)
((Diagram3D)diagram).RuntimeRotation = true;
diagram.SeriesDataMember = "Series";
seriesTemplate.ArgumentDataMember = "Arguments";
seriesTemplate.ValueDataMember = "Values";
if (seriesTemplate.Label == null)
seriesTemplate.Label = new SeriesLabel();
seriesTemplate.LabelsVisibility = showPointsLabels == true;
if (seriesTemplate is PieSeries2D || seriesTemplate is PieSeries3D)
{
seriesTemplate.LegendTextPattern = "{A}";
seriesTemplate.Label.TextPattern = "{A}: {VP:P0}";
}
else
{
seriesTemplate.LegendTextPattern = "{A}: {V:G}";
seriesTemplate.ShowInLegend = true;
}
diagram.SeriesTemplate = seriesTemplate;
return diagram;
}
static void PrepareXYDiagram2D(XYDiagram2D diagram)
{
if (diagram == null)
return;
diagram.AxisX = new AxisX2D();
diagram.AxisX.Label = new AxisLabel();
diagram.AxisX.Label.Staggered = true;
}
static void PrepareXYDiagram3D(XYDiagram3D diagram)
{
if (diagram == null)
return;
diagram.AxisX = new AxisX3D();
diagram.AxisX.Label = new AxisLabel();
diagram.AxisX.Label.Visible = false;
}
public static Series CreateSeriesInstance(Type seriesType)
{
Series series = (Series)Activator.CreateInstance(seriesType);
ISupportTransparency supportTransparency = series as ISupportTransparency;
if (supportTransparency != null)
{
bool flag = series is AreaSeries2D || series is AreaSeries3D;
supportTransparency.Transparency = flag ? 0.4 : 0;
}
return series;
}
static Diagram CreateDiagramBySeriesType(Type seriesType)
{
return (Diagram)Activator.CreateInstance(SeriesTypes[seriesType].DiagramType);
}
}
#endregion
}
}