522 lines
16 KiB
C#
522 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Navigation;
|
|
using BeWo.Controls;
|
|
using BeWo.Core;
|
|
using BeWo.ServiceProxy;
|
|
using BeWo.ViewModel;
|
|
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Translation;
|
|
using DevExpress.Xpf.Core;
|
|
using DevExpress.Xpf.Editors;
|
|
using DevExpress.Xpf.Printing;
|
|
using DevExpress.XtraReports.UI;
|
|
|
|
namespace BeWo.View.Detail.Report
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for TimeSheetMailView.xaml
|
|
/// </summary>
|
|
public partial class TimeSheetMailView : BeWoView
|
|
{
|
|
private List<EmployeeTimesheetDetails> _employeeTimesheets = new List<EmployeeTimesheetDetails>();
|
|
|
|
private Dictionary<string, DateTime> Dicdate = new Dictionary<string, DateTime>();
|
|
|
|
private Dictionary<string, DateTime> DictYear = new Dictionary<string, DateTime>();
|
|
|
|
public TimeSheetMailView()
|
|
{
|
|
InitializeComponent();
|
|
InitDateCombos();
|
|
|
|
//if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View))
|
|
//{
|
|
// checkbox_all.IsEnabled = false;
|
|
// checkbox_all.IsChecked = false;
|
|
//}
|
|
|
|
// SetMonthCombobox();
|
|
// SetYearCombobox();
|
|
|
|
TxtStatus.Text = "";
|
|
GridControlTimesheet.ItemsSource = _employeeTimesheets;
|
|
|
|
RefreshTimesheetStatusList(GetSelectedMonth());
|
|
|
|
combobox_month.SelectionChanged += combobox_month_SelectionChanged;
|
|
combobox_year.SelectionChanged += combobox_year_SelectionChanged;
|
|
|
|
ThemeManager.SetTheme(BeWoApp.CurrentBeWo.MainWindow, Theme.Office2010Black);
|
|
|
|
}
|
|
|
|
void combobox_month_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
RefreshTimesheetStatusList(GetSelectedMonth());
|
|
}
|
|
|
|
|
|
|
|
void combobox_year_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
RefreshTimesheetStatusList(GetSelectedMonth());
|
|
}
|
|
|
|
private DateTime GetSelectedMonth()
|
|
{
|
|
int month = combobox_month.SelectedIndex + 1;
|
|
int year = (int)combobox_year.SelectedItem;
|
|
|
|
return new DateTime(year, month, 1);
|
|
}
|
|
|
|
private void InitDateCombos()
|
|
{
|
|
this.combobox_month.ItemsSource = DateTimeFormatInfo.CurrentInfo.MonthNames.Where(s => !string.IsNullOrEmpty(s));
|
|
int monthIdx = DateTime.Now.AddMonths(1).Month;
|
|
//if (DateTime.Now.Day < 15)
|
|
//{
|
|
monthIdx--;
|
|
if (monthIdx < 0)
|
|
monthIdx = 11;
|
|
//}
|
|
this.combobox_month.SelectedIndex = monthIdx;
|
|
var years = new List<int>();
|
|
years.Add(DateTime.Now.Year + 1);
|
|
for (int i = 0; i <= 10; i++)
|
|
{
|
|
years.Add(DateTime.Now.Year - i);
|
|
}
|
|
|
|
this.combobox_year.ItemsSource = years;
|
|
if (monthIdx == 0)
|
|
{
|
|
this.combobox_year.SelectedItem = DateTime.Now.Year + 1;
|
|
}
|
|
else
|
|
this.combobox_year.SelectedItem = DateTime.Now.Year;
|
|
|
|
}
|
|
|
|
private void button_generate_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
RefreshTimesheetStatusList(GetSelectedMonth());
|
|
}
|
|
|
|
private void RefreshTimesheetStatusList(DateTime monat)
|
|
{
|
|
|
|
ServiceFacade.DoCustomerServiceAsync(
|
|
s => s.GetTimesheetStatusList(monat),
|
|
r =>
|
|
{
|
|
List<TimeSheetStatusItemDC> list = r;
|
|
|
|
CreateEmployeeTimesheetDetails(list);
|
|
|
|
this.Dispatch(delegate
|
|
{
|
|
|
|
GridControlTimesheet.RefreshData();
|
|
GridControlTimesheet.RefreshUI();
|
|
|
|
UpdateStatusText();
|
|
});
|
|
});
|
|
}
|
|
|
|
private void CreateEmployeeTimesheetDetails(List<TimeSheetStatusItemDC> list)
|
|
{
|
|
_employeeTimesheets.Clear();
|
|
foreach (var ts in list)
|
|
{
|
|
var d = new EmployeeTimesheetDetails();
|
|
d.TimeSheetStatusItem = ts;
|
|
d.Employee = ts.Employee;
|
|
d.TeamLeader = ts.TeamLeader;
|
|
d.MailAddress = ts.MailAddress;
|
|
|
|
if (ts.Mails != null)
|
|
{
|
|
foreach (var m in ts.Mails)
|
|
{
|
|
if (!d.LastSendDate.HasValue || d.LastSendDate < m.InsertedOn)
|
|
{
|
|
d.LastSendDate = m.InsertedOn;
|
|
}
|
|
}
|
|
|
|
d.Mails = ts.Mails;
|
|
}
|
|
|
|
d.Customer = "";
|
|
if (ts.Customer != null)
|
|
{
|
|
foreach (var cc in ts.Customer)
|
|
{
|
|
if (d.Customer.Length > 0)
|
|
{
|
|
d.Customer += "; ";
|
|
}
|
|
|
|
d.Customer += cc.DetailDescription;
|
|
}
|
|
}
|
|
_employeeTimesheets.Add(d);
|
|
}
|
|
}
|
|
|
|
private void btn_CreateTimeSheet_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var vm = this.GridControlTimesheet.GetCurrentValue<EmployeeTimesheetDetails>();
|
|
var url = BeWoApp.SiteOfOrigin + "/ReportView.aspx?";
|
|
|
|
url += "cOid=0&empOid=" + vm.Employee.EmployeeOid + "&type=" + Utils.EnumName(ReportTypes.Stundenzettel);
|
|
|
|
url += "&orgaOid=0&month=" + (combobox_month.SelectedIndex + 1) + "&year=" + combobox_year.SelectedItem;
|
|
|
|
|
|
url = BeWoWpfUtils.GetHTMLEncodedURL(url);
|
|
|
|
BeWoUtils.NavigateToReportUri(url, "Druckvorschau");
|
|
|
|
}
|
|
|
|
private void btn_sendTestMail_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var vm = this.GridControlTimesheet.GetCurrentValue<EmployeeTimesheetDetails>();
|
|
CreateTestMailWindow(vm);
|
|
}
|
|
|
|
private void CreateTestMailWindow(EmployeeTimesheetDetails vm)
|
|
{
|
|
BeWoWindow bewoWindow = new BeWoWindow();
|
|
bewoWindow.Width = 500;
|
|
bewoWindow.Height = 500;
|
|
bewoWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
|
|
|
TestEMailControl ctrl = new TestEMailControl();
|
|
|
|
ctrl.Subject = vm.TimeSheetStatusItem.MailSubjectTemplate;
|
|
ctrl.Message = vm.TimeSheetStatusItem.MailMessageTemplate;
|
|
|
|
if (BeWoApp.LoggedOnEmployee.ContactInformations != null)
|
|
{
|
|
foreach (var contact in BeWoApp.LoggedOnEmployee.ContactInformations)
|
|
{
|
|
if (contact.ContactType == ContactType.business_Mail)
|
|
{
|
|
ctrl.SenderEMail = contact.ContactValue;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
ctrl.CancelButtonClicked += delegate
|
|
{
|
|
bewoWindow.Close();
|
|
};
|
|
|
|
ctrl.OkButtonClicked += delegate
|
|
{
|
|
EMailVersenden(ctrl.SenderEMail, ctrl.Subject, ctrl.Message, vm.TimeSheetStatusItem, bewoWindow);
|
|
};
|
|
|
|
bewoWindow.GroupBoxContent = ctrl;
|
|
bewoWindow.rootGroupBox.Header = "E-Mail versenden";
|
|
bewoWindow.Owner = BeWoApp.CurrentBeWo.MainWindow;
|
|
bewoWindow.ShowDialog();
|
|
}
|
|
|
|
private void EMailVersenden(string senderEMail, string subject, string mailbody, TimeSheetStatusItemDC timeSheetStatusItem, BeWoWindow window)
|
|
{
|
|
timeSheetStatusItem.MailAddress = senderEMail;
|
|
timeSheetStatusItem.MailSubjectTemplate = subject;
|
|
timeSheetStatusItem.MailMessageTemplate = mailbody;
|
|
|
|
var result = ServiceFacade.DoReportServiceSync(m => m.SendTimeSheetMail(timeSheetStatusItem, false));
|
|
|
|
if (result == null || String.IsNullOrWhiteSpace(result))
|
|
{
|
|
window.Close();
|
|
MessageBox.Show("Die E-Mail wurde erfolgreich versendet.", "E-Mail senden", MessageBoxButton.OK,
|
|
MessageBoxImage.Information);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Die E-Mail konnte leider nicht gesendet werden.\n\n" + result, "E-Mail senden", MessageBoxButton.OK,
|
|
MessageBoxImage.Error);
|
|
}
|
|
|
|
}
|
|
|
|
private void button_checkAll_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var list = GetVisibleTimesheetDetails();
|
|
|
|
foreach (var etd in list)
|
|
{
|
|
etd.IsChecked = true;
|
|
}
|
|
GridControlTimesheet.RefreshData();
|
|
UpdateStatusText();
|
|
|
|
}
|
|
|
|
private void button_checkAllWithoutMail_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var list = GetVisibleTimesheetDetails();
|
|
|
|
foreach (var etd in list)
|
|
{
|
|
if (etd.Mails == null || etd.Mails.Count == 0)
|
|
{
|
|
etd.IsChecked = true;
|
|
}
|
|
else
|
|
{
|
|
etd.IsChecked = false;
|
|
}
|
|
}
|
|
GridControlTimesheet.RefreshData();
|
|
UpdateStatusText();
|
|
|
|
}
|
|
|
|
private void button_uncheckAll_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var list = GetVisibleTimesheetDetails();
|
|
|
|
foreach (var etd in list)
|
|
{
|
|
etd.IsChecked = false;
|
|
}
|
|
GridControlTimesheet.RefreshData();
|
|
UpdateStatusText();
|
|
}
|
|
|
|
private void UpdateStatusText()
|
|
{
|
|
var list = GetVisibleTimesheetDetails();
|
|
|
|
int count = 0;
|
|
foreach (var ts in _employeeTimesheets)
|
|
{
|
|
if (ts.IsChecked)
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
TxtStatus.Text = String.Format("Anzahl Gesamt: {0} Gefiltert: {1} Ausgewählt: {2}", _employeeTimesheets.Count, list.Count, count);
|
|
}
|
|
|
|
private void button_sendMail_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
SendMailToSelectedEmployees();
|
|
}
|
|
|
|
private void SendMailToSelectedEmployees()
|
|
{
|
|
IList<EmployeeTimesheetDetails> details = GetSelectedTimesheetDetails();
|
|
|
|
BeWoWindow bewoWindow = new BeWoWindow();
|
|
//bewoWindow.ResizeMode = ResizeMode.NoResize
|
|
// IsMaximizable = false
|
|
//};
|
|
bewoWindow.Width = 800;
|
|
bewoWindow.Height = 800;
|
|
bewoWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
|
|
|
EMailStatusLogControl ctrl = new EMailStatusLogControl();
|
|
|
|
ctrl.EmployeeTimesheetDetails = new ObservableCollection<EmployeeTimesheetDetails>(details);
|
|
|
|
bewoWindow.Closing += (sender, args) =>
|
|
{
|
|
if (!ctrl.CancelSending())
|
|
{
|
|
args.Cancel = true;
|
|
}
|
|
else
|
|
{
|
|
if (ctrl.MailSendingSuccessful)
|
|
{
|
|
RefreshTimesheetStatusList(GetSelectedMonth());
|
|
}
|
|
}
|
|
};
|
|
|
|
ctrl.CloseButtonClicked += () =>
|
|
{
|
|
bewoWindow.Close();
|
|
};
|
|
//ctrl.CancelButtonClicked += delegate
|
|
//{
|
|
// bewoWindow.Close();
|
|
//};
|
|
|
|
//ctrl.OkButtonClicked += delegate
|
|
//{
|
|
// //EMailVersenden(ctrl.SenderEMail, vm.TimeSheetStatusItem, bewoWindow);
|
|
//};
|
|
|
|
bewoWindow.GroupBoxContent = ctrl;
|
|
bewoWindow.rootGroupBox.Header = "E-Mail versenden";
|
|
bewoWindow.Owner = BeWoApp.CurrentBeWo.MainWindow;
|
|
bewoWindow.Show();
|
|
}
|
|
|
|
private void button_createServiceRecords_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var month = GetSelectedMonth();
|
|
IList<EmployeeTimesheetDetails> details = GetSelectedTimesheetDetails();
|
|
|
|
List<long> employeeOids = details.Select(d => d.Employee.EmployeeOid).ToList();
|
|
|
|
ServiceFacade.DoOperationsServiceAsync(
|
|
s => s.CreateDefaultServiceRecords(month, employeeOids),
|
|
result =>
|
|
{
|
|
this.Dispatch(delegate
|
|
{
|
|
if (result == null || !result.Contains("Fehler"))
|
|
{
|
|
MessageBox.Show(result, "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(result, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
private IList<EmployeeTimesheetDetails> GetVisibleTimesheetDetails()
|
|
{
|
|
List<EmployeeTimesheetDetails> details = new List<EmployeeTimesheetDetails>();
|
|
for (int i = 0; i < GridControlTimesheet.VisibleRowCount; i++)
|
|
{
|
|
int rowHandle = GridControlTimesheet.GetRowHandleByVisibleIndex(i);
|
|
|
|
var d = GridControlTimesheet.GetRow(rowHandle) as EmployeeTimesheetDetails;
|
|
|
|
if (d != null)
|
|
{
|
|
details.Add(d);
|
|
}
|
|
}
|
|
return details;
|
|
}
|
|
|
|
|
|
private IList<EmployeeTimesheetDetails> GetSelectedTimesheetDetails()
|
|
{
|
|
List<EmployeeTimesheetDetails> details = new List<EmployeeTimesheetDetails>();
|
|
for (int i = 0; i < GridControlTimesheet.VisibleRowCount; i++)
|
|
{
|
|
int rowHandle = GridControlTimesheet.GetRowHandleByVisibleIndex(i);
|
|
|
|
var d = GridControlTimesheet.GetRow(rowHandle) as EmployeeTimesheetDetails;
|
|
|
|
if (d != null && d.IsChecked)
|
|
{
|
|
details.Add(d);
|
|
}
|
|
}
|
|
return details;
|
|
}
|
|
|
|
private void GridControlTimesheet_OnFilterChanged(object sender, RoutedEventArgs e)
|
|
{
|
|
UpdateStatusText();
|
|
}
|
|
}
|
|
|
|
public class EmployeeTimesheetDetails : INotifyPropertyChanged
|
|
{
|
|
private bool _IsChecked;
|
|
|
|
private String _status;
|
|
|
|
public bool IsChecked
|
|
{
|
|
get { return _IsChecked; }
|
|
set
|
|
{
|
|
_IsChecked = value;
|
|
OnPropertyChanged("IsChecked");
|
|
}
|
|
}
|
|
|
|
public CompactEmployeeDC Employee { get; set; }
|
|
|
|
public String Customer { get; set; }
|
|
|
|
public String TeamLeader { get; set; }
|
|
|
|
public String MailAddress { get; set; }
|
|
|
|
|
|
public DateTime? LastSendDate { get; set; }
|
|
|
|
public TimeSheetStatusItemDC TimeSheetStatusItem { get; set; }
|
|
|
|
public IList<MailDC> Mails { get; set; }
|
|
|
|
public string Status
|
|
{
|
|
get { return _status;}
|
|
set
|
|
{
|
|
_status = value;
|
|
OnPropertyChanged("Status");
|
|
OnPropertyChanged("StatusColor");
|
|
}
|
|
}
|
|
|
|
public string StatusColor
|
|
{
|
|
get
|
|
{
|
|
if (Status != null)
|
|
{
|
|
if (Status.Contains("Fehler") || Status.Contains("Keine Mailadresse"))
|
|
{
|
|
return "#FF0000";
|
|
}
|
|
if (Status.Contains("erfolgreich"))
|
|
{
|
|
return "#00FF00";
|
|
}
|
|
}
|
|
|
|
return "#000000";
|
|
}
|
|
}
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
}
|
|
|
|
} |