352 lines
11 KiB
C#
352 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using BeWo.Annotations;
|
|
using BeWo.ServiceProxy;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using ChatController.Utilities.Extensions;
|
|
using DevExpress.Xpf.Core;
|
|
using DevExpress.XtraReports.UI;
|
|
|
|
namespace BeWo.View.Report.Kilometerauswertung
|
|
{
|
|
public partial class KilometerauslastungsView : INotifyPropertyChanged
|
|
{
|
|
public bool IsCreateButtonEnabled => ShouldDoListReport || _ReportType == KilometerauslastungsType.Customer && _SelectedCustomer != null || _ReportType == KilometerauslastungsType.Employee && _SelectedEmployee != null;
|
|
|
|
private List<CompactCustomerDC> AllCustomers { get; set; } = new List<CompactCustomerDC>();
|
|
|
|
private List<CompactEmployeeDC> AllEmployees { get; set; } = new List<CompactEmployeeDC>();
|
|
|
|
public bool ShouldDoListReport
|
|
{
|
|
get
|
|
{
|
|
if(_ReportType == KilometerauslastungsType.Customer)
|
|
{
|
|
return AllCustomersCheckBox.IsChecked.HasValue && AllCustomersCheckBox.IsChecked.Value;
|
|
}
|
|
|
|
return AllEmployeesCheckBox.IsChecked.HasValue && AllEmployeesCheckBox.IsChecked.Value;
|
|
}
|
|
}
|
|
|
|
private CompactCustomerDC _SelectedCustomer;
|
|
public CompactCustomerDC SelectedCustomer
|
|
{
|
|
get => _SelectedCustomer;
|
|
|
|
set
|
|
{
|
|
if(!Equals(_SelectedCustomer, value))
|
|
{
|
|
_SelectedCustomer = value;
|
|
|
|
if(value != null)
|
|
{
|
|
OnPropertyChanged(nameof(IsCreateButtonEnabled));
|
|
}
|
|
|
|
OnPropertyChanged(nameof(SelectedCustomer));
|
|
}
|
|
}
|
|
}
|
|
|
|
private CompactEmployeeDC _SelectedEmployee;
|
|
public CompactEmployeeDC SelectedEmployee
|
|
{
|
|
get => _SelectedEmployee;
|
|
|
|
set
|
|
{
|
|
if(!Equals(_SelectedEmployee, value))
|
|
{
|
|
_SelectedEmployee = value;
|
|
|
|
if(value != null)
|
|
{
|
|
OnPropertyChanged(nameof(IsCreateButtonEnabled));
|
|
}
|
|
|
|
OnPropertyChanged(nameof(SelectedEmployee));
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<string> MonthNames => DateTimeFormatInfo.CurrentInfo?.MonthNames.Where(s => !string.IsNullOrEmpty(s)).ToList();
|
|
|
|
private int _SelectedMonthIndex;
|
|
|
|
private List<int> _Years;
|
|
|
|
public List<int> Years
|
|
{
|
|
get => _Years;
|
|
|
|
set
|
|
{
|
|
if(_Years != value)
|
|
{
|
|
_Years = value;
|
|
|
|
OnPropertyChanged(nameof(Years));
|
|
}
|
|
}
|
|
}
|
|
|
|
public int SelectedMonthIndex
|
|
{
|
|
get => _SelectedMonthIndex;
|
|
|
|
set
|
|
{
|
|
if(_SelectedMonthIndex != value)
|
|
{
|
|
_SelectedMonthIndex = value;
|
|
|
|
OnPropertyChanged(nameof(SelectedMonthIndex));
|
|
}
|
|
}
|
|
}
|
|
|
|
private int _SelectedYearIndex;
|
|
|
|
public int SelectedYearIndex
|
|
{
|
|
get => _SelectedYearIndex;
|
|
|
|
set
|
|
{
|
|
if(_SelectedYearIndex != value)
|
|
{
|
|
_SelectedYearIndex = value;
|
|
|
|
OnPropertyChanged(nameof(SelectedYearIndex));
|
|
}
|
|
}
|
|
}
|
|
|
|
private KilometerauslastungsType _ReportType = KilometerauslastungsType.Customer;
|
|
|
|
|
|
public KilometerauslastungsView()
|
|
{
|
|
InitializeComponent();
|
|
|
|
DataContext = this;
|
|
|
|
var monthIndex = DateTime.Now.Month - 2;
|
|
|
|
SelectedMonthIndex = monthIndex < 0 ? 11 : monthIndex;
|
|
|
|
|
|
InitYearComboBox();
|
|
if (DateTime.Now.Month == 1)
|
|
{
|
|
SelectedYearIndex = 1;
|
|
}
|
|
|
|
ServiceFacade.DoEmployeeServiceAsync(s => s.GetActiveCompactCustomersForEmployee(BeWoApp.LoggedOnEmployeeOid), allCustomers =>
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
AllCustomers = allCustomers;
|
|
});
|
|
});
|
|
|
|
ServiceFacade.DoEmployeeServiceAsync(s => s.GetActiveCompactEmployeesForEmployee(BeWoApp.LoggedOnEmployeeOid.Value), allEmployees =>
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
AllEmployees = allEmployees;
|
|
});
|
|
});
|
|
|
|
// DevExpress
|
|
ThemeManager.SetTheme(BeWoApp.CurrentBeWo.MainWindow, Theme.Office2010Black);
|
|
|
|
Unloaded += delegate
|
|
{
|
|
ThemeManager.SetTheme(BeWoApp.CurrentBeWo.MainWindow, null);
|
|
};
|
|
}
|
|
|
|
private void InitYearComboBox()
|
|
{
|
|
var years = new List<int>();
|
|
|
|
for(var i = 0; i < 10; i++)
|
|
{
|
|
years.Add(DateTime.Now.Year - i);
|
|
}
|
|
|
|
Years = years;
|
|
}
|
|
|
|
private void CustomersPopUpEdit_OnPopUpClick(object sender, RoutedEventArgs e)
|
|
{
|
|
CustomerSearchViewPopup.IsOpen = true;
|
|
}
|
|
|
|
private void EmployeesPopUpEdit_OnPopUpClick(object sender, RoutedEventArgs e)
|
|
{
|
|
EmployeeSearchViewPopup.IsOpen = true;
|
|
}
|
|
|
|
private void CustomerSearchViewPopup_CustomerSelected(object sender, EventArgs<CompactCustomerDC> e)
|
|
{
|
|
SelectedCustomer = e.Data;
|
|
CustomerSearchViewPopup.IsOpen = false;
|
|
}
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
[NotifyPropertyChangedInvocator]
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
private void ButtonGenerate_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
var selectedYear = Years[SelectedYearIndex];
|
|
|
|
var rangeDate = new DateTime(selectedYear, SelectedMonthIndex + 1, 1);
|
|
|
|
if(ShouldDoListReport)
|
|
{
|
|
if(_ReportType == KilometerauslastungsType.Customer)
|
|
{
|
|
ServiceFacade.DoReportServiceAsync(s => s.CreateKilometerauswertungForAllCustomers(AllCustomers.Select(customer => customer.CustomerOid).ToList(), rangeDate), ShowReport, true);
|
|
}
|
|
else
|
|
{
|
|
ServiceFacade.DoReportServiceAsync(s => s.CreateKilometerauswertungForAllEmployees(AllEmployees.Select(employee => employee.EmployeeOid).ToList(), rangeDate), ShowReport, true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(_ReportType == KilometerauslastungsType.Customer)
|
|
{
|
|
ServiceFacade.DoReportServiceAsync(s => s.CreateKilometerauswertung(SelectedCustomer.CustomerOid, rangeDate), ShowReport, true);
|
|
}
|
|
else
|
|
{
|
|
ServiceFacade.DoReportServiceAsync(s => s.CreateEmployeeKilometerauswertung(SelectedEmployee.EmployeeOid, rangeDate), ShowReport, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ShowReport(MemoryStream reportStream)
|
|
{
|
|
if(reportStream == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
this.Dispatch(() =>
|
|
{
|
|
var report = new XtraReport();
|
|
|
|
try
|
|
{
|
|
report.PrintingSystem.LoadDocument(reportStream);
|
|
}
|
|
catch(Exception exception)
|
|
{
|
|
MessageBox.Show("Beim Öffnen der Druckvorschau ist leider ein Fehler aufgetreten!", "Fehler", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
}
|
|
|
|
reportStream.Close();
|
|
reportStream.Dispose();
|
|
|
|
DocumentPreviewControl.DocumentSource = report;
|
|
DocumentPreviewControl.Visibility = Visibility.Visible;
|
|
});
|
|
}
|
|
|
|
private void AllCustomersCheckBox_OnCheckedChanged(object sender, RoutedEventArgs e)
|
|
{
|
|
CustomerPopUpEdit.Visibility = ShouldDoListReport ? Visibility.Hidden : Visibility.Visible;
|
|
EmployeePopUpEdit.Visibility = Visibility.Collapsed;
|
|
|
|
OnPropertyChanged(nameof(IsCreateButtonEnabled));
|
|
OnPropertyChanged(nameof(ShouldDoListReport));
|
|
}
|
|
|
|
private void ToggleButton_OnChecked(object sender, RoutedEventArgs e)
|
|
{
|
|
var radioButton = (RadioButton) sender;
|
|
|
|
switch(radioButton.Name)
|
|
{
|
|
case "CustomerKmReportRadioButton":
|
|
_ReportType = KilometerauslastungsType.Customer;
|
|
break;
|
|
case "EmployeeKmReportRadioButton":
|
|
_ReportType = KilometerauslastungsType.Employee;
|
|
break;
|
|
}
|
|
|
|
SetVisibilityValues();
|
|
}
|
|
|
|
private void AllEmployeesCheckBox_OnChecked(object sender, RoutedEventArgs e)
|
|
{
|
|
EmployeePopUpEdit.Visibility = ShouldDoListReport ? Visibility.Hidden : Visibility.Visible;
|
|
CustomerPopUpEdit.Visibility = Visibility.Collapsed;
|
|
|
|
OnPropertyChanged(nameof(IsCreateButtonEnabled));
|
|
OnPropertyChanged(nameof(ShouldDoListReport));
|
|
}
|
|
|
|
private void EmployeeSearchViewPopup_EmployeeSelected(object sender, EventArgs<CompactEmployeeDC> e)
|
|
{
|
|
SelectedEmployee = e.Data;
|
|
EmployeeSearchViewPopup.IsOpen = false;
|
|
}
|
|
|
|
private void SetVisibilityValues()
|
|
{
|
|
if(_ReportType == KilometerauslastungsType.Customer)
|
|
{
|
|
EmployeeSearchViewPopup.Visibility = Visibility.Collapsed;
|
|
AllEmployeesCheckBox.Visibility = Visibility.Collapsed;
|
|
EmployeePopUpEdit.Visibility = Visibility.Collapsed;
|
|
|
|
CustomerSearchViewPopup.Visibility = Visibility.Visible;
|
|
AllCustomersCheckBox.Visibility = Visibility.Visible;
|
|
CustomerSearchViewPopup.Visibility = Visibility.Visible;
|
|
}
|
|
else
|
|
{
|
|
CustomerSearchViewPopup.Visibility = Visibility.Collapsed;
|
|
AllCustomersCheckBox.Visibility = Visibility.Collapsed;
|
|
CustomerSearchViewPopup.Visibility = Visibility.Collapsed;
|
|
|
|
EmployeeSearchViewPopup.Visibility = Visibility.Visible;
|
|
AllEmployeesCheckBox.Visibility = Visibility.Visible;
|
|
EmployeePopUpEdit.Visibility = Visibility.Visible;
|
|
}
|
|
}
|
|
|
|
private void KilometerauslastungsView_OnInitialized(object sender, EventArgs e)
|
|
{
|
|
CustomerKmReportRadioButton.IsChecked = true;
|
|
}
|
|
}
|
|
|
|
public enum KilometerauslastungsType
|
|
{
|
|
Customer,
|
|
Employee
|
|
}
|
|
}
|