Files
BeWoPlaner/BeWo/View/Detail/Report/SupportConceptsAnalysisView.xaml.cs

409 lines
16 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using BeWo.Core;
using BeWo.MultiLanguage;
using BeWo.ServiceProxy;
using BeWo.View.Search;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
using BS.Shared.Translation;
namespace BeWo.View.Detail.Report
{
public partial class SupportConceptsAnalysisView : BeWoView
{
private Dictionary<string, List<SupportConceptOverviewDC>> _UnfilteredSupportConcept2Overviews;
private CompactEmployeeDC _SelectedEmployee;
private CompactTeamDC _SelectedTeam;
public SupportConceptsAnalysisView(Dictionary<string, List<SupportConceptOverviewDC>> pSupportConcept2Overviews)
{
this.InitializeComponent();
this.datepicker_startdate.AllowNullInput = true;
this.datepicker_startdate.EditValue = null;
this.datepicker_appointeddate.AllowNullInput = true;
this.datepicker_appointeddate.EditValue = null;
_SelectedEmployee = BeWoApp.LoggedOnUser.Employee;
if (_SelectedEmployee != null)
{
popupedit_employee.Text = _SelectedEmployee.ToString();
}
if (!DarfAlleMitarbeiterSehen)
{
if (DarfTeamsSehen)
{
employeeSearchView.SearchMode = SearchMode.OnlyTeamMember;
}
else
{
checkbox_allEmployees.IsEnabled = false;
checkbox_allEmployees.IsChecked = false;
popupedit_employee.Text = String.Format("{0}, {1}", BeWoApp.LoggedOnEmployee.LastName,
BeWoApp.LoggedOnEmployee.FirstName);
}
}
InitServiceCategoryCombo();
ChangeReportType();
ChkHpDieAuslaufen.Content = Translator.Translate("Nur Hilfepläne anzeigen, die innerhalb der nächsten {0} Monate auslaufen", BeWoApp.AppSettings.HilfeplanAuslaufAuswahl);
// if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.Analysis_SupportConceptOverview_View))
// {
// Dictionary<string, List<SupportConceptOverviewDC>> filteredList = new Dictionary<string, List<SupportConceptOverviewDC>>();
// foreach (var item in pSupportConcept2Overviews)
// {
// (item.Value[0].
// }
// _UnfilteredSupportConcept2Overviews = filteredList;
// }
// else
// {
this._UnfilteredSupportConcept2Overviews = pSupportConcept2Overviews;
// }
this.DataContext = this._UnfilteredSupportConcept2Overviews;
this.Loaded += this.SupportConceptsAnalysisView_Loaded;
UpdateReportUrl();
}
private void InitServiceCategoryCombo()
{
ServiceFacade.DoOperationsServiceSync(s => ServiceCategoriesComboBox.ItemsSource = s.GetAllServiceCategories());
ServiceCategoriesComboBox.SelectedIndex = -1;
}
public bool DarfAlleMitarbeiterSehen
{
get
{
return BeWoApp.LoggedOnUser.HasRight(UserRightType.Analysis_EmployeeOverviewAll_View) && BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) && BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts);
}
}
public bool DarfTeamsSehen
{
get
{
return BeWoApp.LoggedOnUser.HasRight(UserRightType.Analysis_AllowFLSOverviewForAllTeams) || BeWoApp.LoggedOnUser.HasRight(UserRightType.Analysis_AllowFLSOverviewForTeam);
}
}
private void SupportConceptsAnalysisView_Loaded(object sender, RoutedEventArgs e)
{
this.textbox_search.Focus();
}
private void UpdateReportUrl()
{
string url;
int months = this.ChkHpDieAuslaufen.IsChecked.Value ? BeWoApp.AppSettings.HilfeplanAuslaufAuswahl : 0;
long showArchived = this.chkShowArchived.IsChecked.Value ? 1 : 0;
long eOid = 0;
long tOid = 0;
long catOid = 0;
if (_SelectedEmployee != null && checkbox_allEmployees.IsChecked == false)
{
eOid = _SelectedEmployee.EmployeeOid;
}
if (_SelectedTeam != null && checkbox_all_teams.IsChecked == false)
{
tOid = _SelectedTeam.TeamOid;
}
if (ChkFilterServiceCategory.IsChecked.HasValue && ChkFilterServiceCategory.IsChecked.Value && ServiceCategoriesComboBox.SelectedItem != null)
{
var cat = ServiceCategoriesComboBox.SelectedItem as ServiceCategoryDC;
catOid = cat.ServiceCategoryOid.Value;
}
List<SupportConceptOverviewDC> itemList = new List<SupportConceptOverviewDC>();
if (!String.IsNullOrWhiteSpace(textbox_search.Text))
{
var visibleScItems = listview_list.Items;
foreach (var item in visibleScItems)
{
var dcList = ((KeyValuePair<string, List<SupportConceptOverviewDC>>) item).Value;
foreach (var dc in dcList)
{
itemList.Add(dc);
}
}
}
if (itemList != null && itemList.Count > 0)
{
StringBuilder oidString = new StringBuilder();
foreach (var item in itemList)
{
if (oidString.Length > 0)
{
oidString.Append(",");
}
oidString.Append(item.CostBearer2SupportConceptOid);
}
url = BeWoApp.SiteOfOrigin + "/ReportView.aspx"
//+ "?tenant=" + BeWoApp.Tenant
//+ "&username=" + BeWoApp.UserName
//+ "&token=" + BeWoApp.LoggedOnUser.RC2Password
+ "?c2slist=" + oidString.ToString()
+ "&type=" + Utils.EnumName(ReportTypes.SupportConceptReport);
}
else
{
// if (ViewModel != null && ViewModel.ServiceRecordsForSelectedCustomer != null && ViewModel.ServiceRecordsForSelectedCustomer.Count > 0)
// {
url = BeWoApp.SiteOfOrigin + "/ReportView.aspx"
//+ "?tenant=" + BeWoApp.Tenant
//+ "&username=" + BeWoApp.UserName
//+ "&token=" + BeWoApp.LoggedOnUser.RC2Password
+ "?eOid=" + eOid
+ "&tOid=" + tOid
+ "&catOid=" + catOid
+ "&exp=" + months
+ "&arc=" + showArchived
+ "&type=" + Utils.EnumName(ReportTypes.SupportConceptReport);
}
if (datepicker_appointeddate.EditValue != null)
url += "&date=" + String.Format("{0:d}", datepicker_appointeddate.DateTime);
if (datepicker_startdate.EditValue != null)
url += "&start=" + String.Format("{0:d}", datepicker_startdate.DateTime);
url = BeWoWpfUtils.GetHTMLEncodedURL(url);
this.linkPdfExport.NavigateUri = new Uri(url);
// }
}
private void buttonRefresh_Click(object sender, RoutedEventArgs e)
{
//this.UpdateReportUrl();
DateTime? startdate = null;
DateTime? enddate = null;
if (this.datepicker_appointeddate.EditValue != null)
enddate = this.datepicker_appointeddate.DateTime;
if (this.datepicker_startdate.EditValue != null)
startdate = this.datepicker_startdate.DateTime;
int? months = null;
if (this.ChkHpDieAuslaufen.IsChecked.Value)
{
months = BeWoApp.AppSettings.HilfeplanAuslaufAuswahl;
}
bool showArchived = this.chkShowArchived.IsChecked.Value;
long? eOid = null;
long? tOid = null;
long? catOid = null;
if (_SelectedEmployee != null && checkbox_allEmployees.IsChecked == false && radioEmployeeReport.IsChecked.HasValue && radioEmployeeReport.IsChecked.Value)
{
eOid = _SelectedEmployee.EmployeeOid;
}
if (_SelectedTeam != null && checkbox_all_teams.IsChecked == false && radioTeamReport.IsChecked.HasValue && radioTeamReport.IsChecked.Value)
{
tOid = _SelectedTeam.TeamOid;
}
if (ChkFilterServiceCategory.IsChecked.HasValue && ChkFilterServiceCategory.IsChecked.Value && ServiceCategoriesComboBox.SelectedItem != null)
{
var cat = ServiceCategoriesComboBox.SelectedItem as ServiceCategoryDC;
catOid = cat.ServiceCategoryOid.Value;
}
ServiceFacade.DoAnalysisServiceAsync(s => s.GetSupportConceptAnalysis4(eOid, tOid, catOid, startdate, enddate, months, showArchived),
r =>
{
this.Dispatch(
delegate
{
this._UnfilteredSupportConcept2Overviews = r.OrderBy(o => o.CustomerLastName + ", " + o.CustomerFirstName).GroupBy(so => so.CustomerLastName + ", " + so.CustomerFirstName).ToDictionary(g => g.Key, g => g.ToList());
this.DataContext = this._UnfilteredSupportConcept2Overviews;
});
});
}
private void listview_list_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.listview_list.SelectedItem != null)
{
(this.listview_list.ItemContainerGenerator.ContainerFromItem(this.listview_list.SelectedItem) as ListViewItem).IsSelected = false;
}
}
private void textbox_searchVisible_TextChanged(object sender, TextChangedEventArgs e)
{
String test = textbox_searchVisible.Text;
textbox_search.Text = test;
}
private void LinkPdfExport_OnRequestNavigate(object sender, RequestNavigateEventArgs e)
{
UpdateReportUrl();
BeWoUtils.NavigateToReportUri((sender as System.Windows.Documents.Hyperlink).NavigateUri.ToString(), Translator.Translate("Hilfeplanübersicht"));
//System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo((sender as System.Windows.Documents.Hyperlink).NavigateUri.ToString()));
}
private void CheckBoxAllEmployees_Checked(object sender, RoutedEventArgs e)
{
if (popupedit_employee == null)
return;
popupedit_employee.Text = string.Empty;
_SelectedEmployee = null;
ChangeReportType();
}
private void popupedit_employee_PopUpClick(object sender, RoutedEventArgs e)
{
this.popup_employee.IsOpen = true;
}
private void CheckBoxAllTeams_Checked(object sender, RoutedEventArgs e)
{
if (popupedit_team != null)
{
popupedit_team.Text = string.Empty;
_SelectedTeam = null;
}
ChangeReportType();
}
private void popupedit_team_PopUpClick(object sender, RoutedEventArgs e)
{
this.popup_team.IsOpen = true;
}
private void EmployeeSearchView_ItemSelected(object sender, EventArgs<CompactEmployeeDC> e)
{
_SelectedEmployee = e.Data;
popupedit_employee.Text = _SelectedEmployee.ToString();
popup_employee.IsOpen = false;
}
private void TeamSearchView_ItemSelected(object sender, EventArgs<CompactTeamDC> e)
{
_SelectedTeam = e.Data;
popupedit_team.Text = _SelectedTeam.ToString();
popup_team.IsOpen = false;
}
private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
ChangeReportType();
}
private void ChangeReportType()
{
if (radioTeamReport != null && popupedit_team != null)
{
bool isEmployee = true;
if (radioTeamReport.IsChecked != null && radioTeamReport.IsChecked.Value)
{
isEmployee = false;
}
checkbox_allEmployees.Visibility = isEmployee ? Visibility.Visible : Visibility.Hidden;
popupedit_employee.Visibility = isEmployee ? Visibility.Visible : Visibility.Hidden;
checkbox_all_teams.Visibility = isEmployee ? Visibility.Hidden : Visibility.Visible;
popupedit_team.Visibility = isEmployee ? Visibility.Hidden : Visibility.Visible;
if (checkbox_allEmployees.IsChecked.HasValue && checkbox_allEmployees.Visibility == Visibility.Visible)
{
popupedit_employee.Visibility = checkbox_allEmployees.IsChecked.Value ? Visibility.Hidden : Visibility.Visible;
}
if (checkbox_all_teams.IsChecked.HasValue && checkbox_all_teams.Visibility == Visibility.Visible)
{
popupedit_team.Visibility = checkbox_all_teams.IsChecked.Value ? Visibility.Hidden : Visibility.Visible;
}
if (!DarfAlleMitarbeiterSehen)
{
checkbox_allEmployees.IsEnabled = false;
checkbox_allEmployees.IsChecked = false;
popupedit_employee.IsEnabled = false;
if (!DarfTeamsSehen)
{
checkbox_all_teams.IsEnabled = false;
popupedit_team.IsEnabled = false;
radioTeamReport.IsEnabled = false;
radioEmployeeReport.IsEnabled = false;
//checkbox_showTeamReport.Visibility = Visibility.Collapsed;
}
//else
//{
// //checkbox_all.Visibility = Visibility.Collapsed;
// //popupedit_employee.Visibility = Visibility.Collapsed;
// List<CompactEmployeeDC> mitarbeiterAllerTeams = new List<CompactEmployeeDC>();
// var ol = teamSearchView.ObjectList;
// if (ol != null)
// {
// List<CompactTeamDC> teams = new List<CompactTeamDC>();
// var emp = BeWoApp.LoggedOnUser.Employee;
// if (emp.LeadingTeamOids != null && emp.LeadingTeamOids.Count > 0)
// {
// foreach (var t in ol)
// {
// if (emp.LeadingTeamOids.Contains(t.TeamOid))
// {
// teams.Add(t);
// }
// }
// }
// teamSearchView.ObjectList = teams;
// //foreach (var t in teams)
// //{
// // var t = ServiceFacade.DoEmployeeServiceSync(s => s.GetAllTeamMember())
// // var emps = t.
// //}
// }
//}
}
//if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll))
//{
// checkbox_allEmployees.IsEnabled = false;
//}
}
}
}
}