- DefaultValue in Paramter Klasse eingefügt - Queries für fehlende Unterschriften hinzugefügt
1196 lines
50 KiB
C#
1196 lines
50 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Controls.Primitives;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Media;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Threading;
|
|
using BeWo.Controls;
|
|
using BeWo.Core;
|
|
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 DevExpress.Xpf.Editors;
|
|
using DevExpress.Xpf.Grid;
|
|
|
|
using BeWo.Core.Service;
|
|
using BeWo.ViewModel;
|
|
using Microsoft.Win32;
|
|
using System.Text;
|
|
using DevExpress.XtraReports.UI;
|
|
|
|
namespace BeWo.View.Detail.Report
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for QueryView.xaml
|
|
/// </summary>
|
|
public partial class QueryView : BeWoView
|
|
{
|
|
private readonly Dictionary<string, UIElement> parameterUIElements = new Dictionary<string, UIElement>();
|
|
|
|
private CompactEmployeeDC lastSelectedEmployee;
|
|
private CompactCustomerDC lastSelectedCustomer;
|
|
private CompactSupportConceptDC lastSelectedSupportConcept;
|
|
private CompactTeamDC lastSelectedTeam;
|
|
private CompactOrganisationDC lastSelectedOrganisation;
|
|
|
|
private String _UploadFileName;
|
|
|
|
public QueryView(IEnumerable<QueryDC> pQueries)
|
|
{
|
|
try
|
|
{
|
|
InitializeComponent();
|
|
|
|
var filteredList = pQueries.Where(LoggedOnUserHasRightForQuery).ToList();
|
|
|
|
combo_query.ItemsSource = filteredList;
|
|
textblock_link.Visibility = Visibility.Collapsed;
|
|
textblock_link_pdfexport.Visibility = Visibility.Collapsed;
|
|
|
|
DownloadLinkEngine = new DownloadLinkEngine();
|
|
linkExcelExport.NavigateUri = DownloadLinkEngine.GenerateNewExcelLink();
|
|
|
|
btnExecuteQuery.Visibility = Visibility.Collapsed;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
public DownloadLinkEngine DownloadLinkEngine { get; set; }
|
|
|
|
public override string Title
|
|
{
|
|
get
|
|
{
|
|
return "öffentliche Abfragen";
|
|
}
|
|
}
|
|
|
|
private DateEdit CreateDateEdit()
|
|
{
|
|
var dtp = new DateEdit
|
|
{
|
|
Margin = new Thickness(3),
|
|
Background = Brushes.White,
|
|
Foreground = Brushes.Black,
|
|
BorderThickness = new Thickness(1),
|
|
BorderBrush = Application.Current.FindResource("TextBoxBorderBrush") as Brush,
|
|
Width = 90
|
|
};
|
|
//dtp.TodayContent = "Heute";
|
|
|
|
return dtp;
|
|
}
|
|
|
|
private ComboBox CreateMonthCombo()
|
|
{
|
|
var comboboxMonth = new ComboBox
|
|
{
|
|
ItemsSource = DateTimeFormatInfo.CurrentInfo.MonthNames.Where(s => !string.IsNullOrEmpty(s))
|
|
};
|
|
|
|
var firstOfMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
|
comboboxMonth.SelectedIndex = firstOfMonth.Subtract(new TimeSpan(1, 0, 0, 0)).Month - 1;
|
|
comboboxMonth.Width = 100;
|
|
return comboboxMonth;
|
|
}
|
|
|
|
private ComboBox CreateValueListEntryCombo(ValueListEntryType t)
|
|
{
|
|
var combobox = new ComboBox();
|
|
|
|
Cache.GetInstance().GetAllValueListEntrysByTypeAsync(t,
|
|
cb => this.Dispatch(
|
|
delegate
|
|
{
|
|
var items = new List<ValueListEntryDC>();
|
|
var dummy = new ValueListEntryDC
|
|
{
|
|
ValueListEntryOid = 0,
|
|
TypeDescription = ""
|
|
};
|
|
items.Add(dummy);
|
|
items.AddRange(cb);
|
|
combobox.ItemsSource = items;
|
|
combobox.SelectedItem = items[0];
|
|
}));
|
|
|
|
combobox.Width = 250;
|
|
combobox.Height = 23;
|
|
return combobox;
|
|
}
|
|
|
|
private ComboBox CreateServiceCategoryCombo()
|
|
{
|
|
var combobox = new ComboBox();
|
|
|
|
Cache.GetInstance().GetServiceCategoryDescriptionDict(
|
|
cb => this.Dispatch(
|
|
delegate
|
|
{
|
|
var items = new List<ServiceCategoryDC>();
|
|
var dummy = new ServiceCategoryDC
|
|
{
|
|
ServiceCategoryOid = 0,
|
|
Name = ""
|
|
};
|
|
items.Add(dummy);
|
|
items.AddRange(cb.Keys);
|
|
|
|
combobox.ItemsSource = items;
|
|
combobox.SelectedItem = items[0];
|
|
}));
|
|
|
|
combobox.Width = 250;
|
|
combobox.Height = 23;
|
|
return combobox;
|
|
}
|
|
|
|
private ComboBox CreateCustomCombo(IList<String> customValues)
|
|
{
|
|
var combobox = new ComboBox();
|
|
|
|
var items = new List<String>();
|
|
String dummy = "";
|
|
|
|
items.Add(dummy);
|
|
if (customValues != null)
|
|
{
|
|
items.AddRange(customValues);
|
|
}
|
|
|
|
combobox.ItemsSource = items;
|
|
combobox.SelectedItem = items[0];
|
|
|
|
combobox.Width = 250;
|
|
combobox.Height = 23;
|
|
return combobox;
|
|
}
|
|
|
|
private bool CreateParameterFieldsAndExecute(QueryDC query)
|
|
{
|
|
bool canExecute = true;
|
|
|
|
datagrid_result.Visibility = Visibility.Collapsed;
|
|
textblock_link.Visibility = Visibility.Collapsed;
|
|
textblock_link_pdfexport.Visibility = Visibility.Collapsed;
|
|
|
|
foreach (var item in query.Parameter)
|
|
{
|
|
string[] itemNames = item.Name.Split(new[] {'_'}, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
bool addPanel = true;
|
|
var sp = new StackPanel {Orientation = Orientation.Horizontal};
|
|
|
|
var lbl = new Label
|
|
{
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
Content = itemNames[0],
|
|
Width = 100
|
|
};
|
|
sp.Children.Add(lbl);
|
|
|
|
switch (item.ParamType)
|
|
{
|
|
case QueryParameterType.SupportConcept:
|
|
var peSc = new PopUpEdit
|
|
{
|
|
IsReadOnly = true,
|
|
MinWidth = 250,
|
|
Margin = new Thickness(3),
|
|
DeleteButtonVisibility = Visibility.Visible
|
|
};
|
|
peSc.DeleteClick += (s, e) =>
|
|
{
|
|
peSc.Text = "";
|
|
lastSelectedSupportConcept = null;
|
|
};
|
|
if (lastSelectedSupportConcept != null)
|
|
{
|
|
peSc.Text = lastSelectedSupportConcept.ToString();
|
|
}
|
|
|
|
var popupSc = new Popup();
|
|
popupSc.StaysOpen = false;
|
|
popupSc.Placement = PlacementMode.MousePoint;
|
|
popupSc.Width = 370;
|
|
popupSc.Height = 250;
|
|
|
|
var scsv = new SupportConceptSearchView();
|
|
scsv.SearchMode = SearchMode.ActiveCostbearer2SupportConcepts;
|
|
scsv.ItemSelected += (s, e) =>
|
|
{
|
|
popupSc.IsOpen = false;
|
|
peSc.Focus();
|
|
|
|
var newSc = e.Data;
|
|
|
|
peSc.Text = String.Format("{0}, {1}", newSc.Customer.LastNameFirstName, newSc.CostBearer);
|
|
|
|
lastSelectedSupportConcept = newSc;
|
|
};
|
|
popupSc.Child = scsv;
|
|
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_1", scsv);
|
|
|
|
peSc.PopUpClick += (s, e) => { popupSc.IsOpen = true; };
|
|
sp.Children.Add(peSc);
|
|
sp.Children.Add(popupSc);
|
|
break;
|
|
case QueryParameterType.Employee:
|
|
var peEmp = new PopUpEdit
|
|
{
|
|
IsReadOnly = true,
|
|
Width = 250,
|
|
Margin = new Thickness(3),
|
|
DeleteButtonVisibility = Visibility.Visible
|
|
};
|
|
peEmp.DeleteClick += (s, e) =>
|
|
{
|
|
peEmp.Text = "";
|
|
lastSelectedEmployee = null;
|
|
};
|
|
|
|
if (lastSelectedEmployee != null)
|
|
{
|
|
peEmp.Text = lastSelectedEmployee.ToString();
|
|
}
|
|
|
|
var popupEmployee = new Popup();
|
|
popupEmployee.StaysOpen = false;
|
|
popupEmployee.Width = 370;
|
|
popupEmployee.Height = 250;
|
|
popupEmployee.Placement = PlacementMode.MousePoint;
|
|
var esv = new EmployeeSearchView();
|
|
|
|
esv.ItemSelected += (s, e) =>
|
|
{
|
|
popupEmployee.IsOpen = false;
|
|
peEmp.Focus();
|
|
|
|
CompactEmployeeDC newEmployee = e.Data;
|
|
|
|
peEmp.Text = newEmployee.ToString();
|
|
|
|
lastSelectedEmployee = newEmployee;
|
|
};
|
|
popupEmployee.Child = esv;
|
|
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_1", esv);
|
|
|
|
peEmp.PopUpClick += (s, e) => { popupEmployee.IsOpen = true; };
|
|
sp.Children.Add(peEmp);
|
|
sp.Children.Add(popupEmployee);
|
|
break;
|
|
case QueryParameterType.Customer:
|
|
var pe = new PopUpEdit
|
|
{
|
|
IsReadOnly = true,
|
|
Width = 250,
|
|
Margin = new Thickness(3),
|
|
DeleteButtonVisibility = Visibility.Visible
|
|
};
|
|
pe.DeleteClick += (s, e) =>
|
|
{
|
|
pe.Text = "";
|
|
lastSelectedCustomer = null;
|
|
};
|
|
if (lastSelectedCustomer != null)
|
|
{
|
|
pe.Text = lastSelectedCustomer.ToString();
|
|
}
|
|
|
|
var popup = new Popup();
|
|
popup.StaysOpen = false;
|
|
popup.Placement = PlacementMode.MousePoint;
|
|
popup.Width = 370;
|
|
popup.Height = 250;
|
|
var csv = new CustomerSearchView();
|
|
csv.ItemSelected += (s, e) =>
|
|
{
|
|
popup.IsOpen = false;
|
|
pe.Focus();
|
|
|
|
CompactCustomerDC newCustomer = e.Data;
|
|
|
|
pe.Text = newCustomer.ToString();
|
|
|
|
lastSelectedCustomer = newCustomer;
|
|
};
|
|
popup.Child = csv;
|
|
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_1", csv);
|
|
|
|
pe.PopUpClick += (s, e) => { popup.IsOpen = true; };
|
|
sp.Children.Add(pe);
|
|
sp.Children.Add(popup);
|
|
|
|
break;
|
|
case QueryParameterType.Team:
|
|
var peTeam = new PopUpEdit
|
|
{
|
|
IsReadOnly = true,
|
|
Width = 250,
|
|
Margin = new Thickness(3),
|
|
DeleteButtonVisibility = Visibility.Visible
|
|
};
|
|
peTeam.DeleteClick += (s, e) =>
|
|
{
|
|
peTeam.Text = "";
|
|
lastSelectedTeam = null;
|
|
};
|
|
if (lastSelectedTeam != null)
|
|
{
|
|
peTeam.Text = lastSelectedTeam.ToString();
|
|
}
|
|
|
|
var popupTeam = new Popup();
|
|
popupTeam.StaysOpen = false;
|
|
popupTeam.Width = 370;
|
|
popupTeam.Height = 250;
|
|
popupTeam.Placement = PlacementMode.MousePoint;
|
|
var tsv = new TeamSearchView();
|
|
tsv.ItemSelected += (s, e) =>
|
|
{
|
|
popupTeam.IsOpen = false;
|
|
peTeam.Focus();
|
|
|
|
CompactTeamDC newTeam = e.Data;
|
|
|
|
peTeam.Text = newTeam.ToString();
|
|
|
|
lastSelectedTeam = newTeam;
|
|
};
|
|
popupTeam.Child = tsv;
|
|
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_1", tsv);
|
|
|
|
peTeam.PopUpClick += (s, e) => { popupTeam.IsOpen = true; };
|
|
sp.Children.Add(peTeam);
|
|
sp.Children.Add(popupTeam);
|
|
break;
|
|
case QueryParameterType.Organisation:
|
|
var peOrg = new PopUpEdit
|
|
{
|
|
IsReadOnly = true,
|
|
Width = 250,
|
|
Margin = new Thickness(3),
|
|
DeleteButtonVisibility = Visibility.Visible
|
|
};
|
|
peOrg.DeleteClick += (s, e) =>
|
|
{
|
|
peOrg.Text = "";
|
|
lastSelectedOrganisation = null;
|
|
};
|
|
if (lastSelectedOrganisation != null)
|
|
{
|
|
peOrg.Text = lastSelectedOrganisation.ToString();
|
|
}
|
|
|
|
var popupOrg = new Popup();
|
|
popupOrg.StaysOpen = false;
|
|
popupOrg.Width = 370;
|
|
popupOrg.Height = 250;
|
|
popupOrg.Placement = PlacementMode.MousePoint;
|
|
var osv = new OrganisationSearchView();
|
|
osv.ItemSelected += (s, e) =>
|
|
{
|
|
popupOrg.IsOpen = false;
|
|
peOrg.Focus();
|
|
|
|
var newOrg = e.Data;
|
|
|
|
peOrg.Text = newOrg.Name;
|
|
|
|
lastSelectedOrganisation = newOrg;
|
|
};
|
|
popupOrg.Child = osv;
|
|
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_1", osv);
|
|
|
|
peOrg.PopUpClick += (s, e) => { popupOrg.IsOpen = true; };
|
|
sp.Children.Add(peOrg);
|
|
sp.Children.Add(popupOrg);
|
|
break;
|
|
case QueryParameterType.Month:
|
|
ComboBox monthCombo = CreateMonthCombo();
|
|
monthCombo.Margin = new Thickness(3);
|
|
sp.Children.Add(monthCombo);
|
|
|
|
ComboBox monthYearCombo = CreateYearCombo();
|
|
monthYearCombo.Margin = new Thickness(3);
|
|
sp.Children.Add(monthYearCombo);
|
|
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_1", monthCombo);
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_2", monthYearCombo);
|
|
|
|
break;
|
|
case QueryParameterType.Year:
|
|
ComboBox yearCombo = CreateYearCombo();
|
|
yearCombo.Margin = new Thickness(3);
|
|
sp.Children.Add(yearCombo);
|
|
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_1", yearCombo);
|
|
|
|
break;
|
|
case QueryParameterType.Date:
|
|
DateEdit dtpStart2 = CreateDateEdit();
|
|
sp.Children.Add(dtpStart2);
|
|
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_1", dtpStart2);
|
|
break;
|
|
case QueryParameterType.DateRange:
|
|
DateEdit dtpStart = CreateDateEdit();
|
|
sp.Children.Add(dtpStart);
|
|
|
|
if (itemNames.Length > 1)
|
|
{
|
|
lbl = new Label();
|
|
lbl.VerticalAlignment = VerticalAlignment.Center;
|
|
lbl.Content = itemNames[1];
|
|
sp.Children.Add(lbl);
|
|
}
|
|
|
|
DateEdit dtpEnd = CreateDateEdit();
|
|
sp.Children.Add(dtpEnd);
|
|
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_1", dtpStart);
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_2", dtpEnd);
|
|
|
|
break;
|
|
case QueryParameterType.CurrentEmployee:
|
|
case QueryParameterType.CurrentUser:
|
|
addPanel = false;
|
|
break;
|
|
case QueryParameterType.ValueListEntryType:
|
|
int t = 0;
|
|
if (itemNames.Length > 1 && Int32.TryParse(itemNames[1], out t))
|
|
{
|
|
ComboBox vleCombo = CreateValueListEntryCombo((ValueListEntryType) t);
|
|
vleCombo.Margin = new Thickness(3);
|
|
sp.Children.Add(vleCombo);
|
|
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_1", vleCombo);
|
|
}
|
|
break;
|
|
case QueryParameterType.ServiceCategory:
|
|
ComboBox catCombo = CreateServiceCategoryCombo();
|
|
catCombo.Margin = new Thickness(3);
|
|
sp.Children.Add(catCombo);
|
|
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_1", catCombo);
|
|
|
|
break;
|
|
case QueryParameterType.Custom:
|
|
ComboBox customCombo = CreateCustomCombo(item.CustomValues);
|
|
customCombo.Margin = new Thickness(3);
|
|
sp.Children.Add(customCombo);
|
|
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_1", customCombo);
|
|
|
|
break;
|
|
case QueryParameterType.Text:
|
|
var textEdit = new TextEdit
|
|
{
|
|
Margin = new Thickness(3),
|
|
Background = Brushes.White,
|
|
Foreground = Brushes.Black,
|
|
BorderThickness = new Thickness(1),
|
|
BorderBrush = Application.Current.FindResource("TextBoxBorderBrush") as Brush,
|
|
Width = 250
|
|
};
|
|
//dtp.TodayContent = "Heute";
|
|
|
|
sp.Children.Add(textEdit);
|
|
|
|
parameterUIElements.Add(item.Name + "_" + item.ParamType + "_1", textEdit);
|
|
|
|
break;
|
|
}
|
|
if (addPanel)
|
|
{
|
|
canExecute = false;
|
|
paramterPanel.Children.Add(sp);
|
|
}
|
|
}
|
|
return canExecute;
|
|
}
|
|
|
|
|
|
private List<QueryParamDC> CreateQueryParamValues(QueryDC query)
|
|
{
|
|
var parameter = new List<QueryParamDC>();
|
|
|
|
foreach (QueryParamDC item in query.Parameter)
|
|
{
|
|
var param = new QueryParamDC();
|
|
parameter.Add(param);
|
|
|
|
param.Name = item.Name;
|
|
param.ParamType = item.ParamType;
|
|
param.DefaultValue = item.DefaultValue;
|
|
|
|
switch (item.ParamType)
|
|
{
|
|
case QueryParameterType.SupportConcept:
|
|
if (lastSelectedSupportConcept != null)
|
|
{
|
|
if (lastSelectedSupportConcept.CostBearerRelOids != null &&
|
|
lastSelectedSupportConcept.CostBearerRelOids.Count == 1)
|
|
{
|
|
param.Value = lastSelectedSupportConcept.CostBearerRelOids[0];
|
|
}
|
|
else
|
|
{
|
|
param.Value = lastSelectedSupportConcept.SupportConceptOid;
|
|
}
|
|
}
|
|
break;
|
|
case QueryParameterType.Employee:
|
|
if (lastSelectedEmployee != null)
|
|
{
|
|
param.Value = lastSelectedEmployee.EmployeeOid;
|
|
}
|
|
break;
|
|
case QueryParameterType.Customer:
|
|
if (lastSelectedCustomer != null)
|
|
{
|
|
param.Value = lastSelectedCustomer.CustomerOid;
|
|
}
|
|
|
|
break;
|
|
case QueryParameterType.Team:
|
|
if (lastSelectedTeam != null)
|
|
{
|
|
param.Value = lastSelectedTeam.TeamOid;
|
|
}
|
|
|
|
break;
|
|
case QueryParameterType.Organisation:
|
|
if (lastSelectedOrganisation != null)
|
|
{
|
|
param.Value = lastSelectedOrganisation.OrganisationOid;
|
|
}
|
|
|
|
break;
|
|
case QueryParameterType.Month:
|
|
if (parameterUIElements.ContainsKey(item.Name + "_" + item.ParamType + "_1") &&
|
|
parameterUIElements.ContainsKey(item.Name + "_" + item.ParamType + "_2"))
|
|
{
|
|
var monthCombo = parameterUIElements[item.Name + "_" + item.ParamType + "_1"] as ComboBox;
|
|
var yearCombo = parameterUIElements[item.Name + "_" + item.ParamType + "_2"] as ComboBox;
|
|
|
|
var dt = new DateTime((int) yearCombo.SelectedItem,
|
|
DateTimeFormatInfo.CurrentInfo.MonthNames.IndexOf(
|
|
(string) monthCombo.SelectedItem) + 1, 1);
|
|
|
|
param.Value = dt;
|
|
}
|
|
|
|
break;
|
|
case QueryParameterType.Year:
|
|
if (parameterUIElements.ContainsKey(item.Name + "_" + item.ParamType + "_1"))
|
|
{
|
|
var yearCombo = parameterUIElements[item.Name + "_" + item.ParamType + "_1"] as ComboBox;
|
|
|
|
var dt = new DateTime((int) yearCombo.SelectedItem, 1, 1);
|
|
|
|
param.Value = dt;
|
|
}
|
|
|
|
break;
|
|
case QueryParameterType.Date:
|
|
if (parameterUIElements.ContainsKey(item.Name + "_" + item.ParamType + "_1"))
|
|
{
|
|
var dtp = parameterUIElements[item.Name + "_" + item.ParamType + "_1"] as DateEdit;
|
|
|
|
if (dtp.EditValue != null)
|
|
{
|
|
var dt = dtp.DateTime;
|
|
|
|
param.Value = dt;
|
|
}
|
|
}
|
|
break;
|
|
case QueryParameterType.DateRange:
|
|
if (parameterUIElements.ContainsKey(item.Name + "_" + item.ParamType + "_1") &&
|
|
parameterUIElements.ContainsKey(item.Name + "_" + item.ParamType + "_2"))
|
|
{
|
|
var dtpStart = parameterUIElements[item.Name + "_" + item.ParamType + "_1"] as DateEdit;
|
|
var dtpEnd = parameterUIElements[item.Name + "_" + item.ParamType + "_2"] as DateEdit;
|
|
|
|
var dts = new DateTimeSpan();
|
|
if (dtpStart.EditValue != null)
|
|
{
|
|
dts.StartDate = dtpStart.DateTime;
|
|
}
|
|
else
|
|
{
|
|
dts.StartDate = DateTime.MinValue;
|
|
}
|
|
|
|
if (dtpEnd.EditValue != null)
|
|
{
|
|
dts.EndDate = dtpEnd.DateTime;
|
|
}
|
|
else
|
|
{
|
|
dts.EndDate = DateTime.MaxValue;
|
|
}
|
|
|
|
param.Value = dts;
|
|
}
|
|
|
|
break;
|
|
case QueryParameterType.CurrentEmployee:
|
|
param.Value = BeWoApp.LoggedOnEmployee.EmployeeOid;
|
|
|
|
break;
|
|
case QueryParameterType.CurrentUser:
|
|
param.Value = BeWoApp.LoggedOnUser.UserOid;
|
|
|
|
break;
|
|
case QueryParameterType.ValueListEntryType:
|
|
if (parameterUIElements.ContainsKey(item.Name + "_" + item.ParamType + "_1"))
|
|
{
|
|
var combo = parameterUIElements[item.Name + "_" + item.ParamType + "_1"] as ComboBox;
|
|
var vle = combo.SelectedItem as ValueListEntryDC;
|
|
if (vle != null)
|
|
param.Value = vle.ValueListEntryOid.Value;
|
|
}
|
|
|
|
break;
|
|
case QueryParameterType.ServiceCategory:
|
|
if (parameterUIElements.ContainsKey(item.Name + "_" + item.ParamType + "_1"))
|
|
{
|
|
var combo = parameterUIElements[item.Name + "_" + item.ParamType + "_1"] as ComboBox;
|
|
var cat = combo.SelectedItem as ServiceCategoryDC;
|
|
if (cat != null)
|
|
param.Value = cat.ServiceCategoryOid.Value;
|
|
}
|
|
break;
|
|
case QueryParameterType.Custom:
|
|
if (parameterUIElements.ContainsKey(item.Name + "_" + item.ParamType + "_1"))
|
|
{
|
|
var combo = parameterUIElements[item.Name + "_" + item.ParamType + "_1"] as ComboBox;
|
|
var customerValue = combo.SelectedItem as String;
|
|
if (customerValue != null)
|
|
param.Value = customerValue;
|
|
}
|
|
break;
|
|
case QueryParameterType.Text:
|
|
if (parameterUIElements.ContainsKey(item.Name + "_" + item.ParamType + "_1"))
|
|
{
|
|
var tb = parameterUIElements[item.Name + "_" + item.ParamType + "_1"] as TextEdit;
|
|
param.Value = tb.Text;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
return parameter;
|
|
}
|
|
|
|
private ComboBox CreateYearCombo()
|
|
{
|
|
var comboboxYear = new ComboBox();
|
|
|
|
var years = new List<int>();
|
|
for (int i = -1; i <= 10; i++)
|
|
{
|
|
years.Add(DateTime.Now.Year - i);
|
|
}
|
|
|
|
comboboxYear.ItemsSource = years;
|
|
|
|
var firstOfMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
|
comboboxYear.SelectedItem = firstOfMonth.Subtract(new TimeSpan(1, 0, 0, 0)).Year;
|
|
|
|
return comboboxYear;
|
|
}
|
|
|
|
private void ExecuteQuery(QueryDC query)
|
|
{
|
|
List<QueryParamDC> parameter = CreateQueryParamValues(query);
|
|
|
|
ExecuteQuery(query, parameter);
|
|
}
|
|
|
|
private void ExecuteQuery(QueryDC query, List<QueryParamDC> parameterList)
|
|
{
|
|
datagrid_result.Visibility = Visibility.Visible;
|
|
textblock_link.Visibility = Visibility.Visible;
|
|
textblock_link_pdfexport.Visibility = Visibility.Visible;
|
|
datagrid_result.Columns.Clear();
|
|
|
|
ServiceFacade.DoQueryServiceAsync(
|
|
s =>
|
|
{
|
|
try
|
|
{
|
|
return s.ExecuteQuery(query.Oid, parameterList);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
}
|
|
|
|
return null;
|
|
},
|
|
rstr => this.Dispatch(delegate
|
|
{
|
|
var table = Utils.XMLDeserializeFromString<DataTable>(rstr);
|
|
|
|
datagrid_result.ItemsSource = table;
|
|
SetOidColumnsInvisible();
|
|
|
|
foreach (
|
|
GridColumn column in
|
|
datagrid_result.Columns.Where(column => column.HeaderCaption.Equals("Mail") ||
|
|
column.HeaderCaption.Equals("Mail (dienstl.)") ||
|
|
column.HeaderCaption.Equals("Homepage")))
|
|
{
|
|
column.CellTemplate = BuildLinkTemplate(column.HeaderCaption.ToString());
|
|
}
|
|
|
|
if (table == null || table.Columns.Count <= 0) return;
|
|
|
|
summaryItem.FieldName = table.Columns[0].ColumnName;
|
|
summaryItem.DisplayFormat = "anz: {0}";
|
|
}));
|
|
}
|
|
|
|
private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e)
|
|
{
|
|
BeWoUtils.OpenMailClient(e.Uri.ToString());
|
|
}
|
|
|
|
private void Hyperlink_OnRequestNavigateToHomepage(object sender, RequestNavigateEventArgs e)
|
|
{
|
|
var originalString = e.Uri.OriginalString;
|
|
var u = !originalString.StartsWith("http://") ? new Uri("http://" + e.Uri.OriginalString) : e.Uri;
|
|
|
|
Process.Start(u.AbsoluteUri);
|
|
e.Handled = true;
|
|
}
|
|
|
|
private DataTemplate BuildLinkTemplate(string columnName)
|
|
{
|
|
var binding = new Binding {Path = new PropertyPath("Data." + columnName)};
|
|
|
|
var textBlockInHyperLinkFactory = new FrameworkElementFactory(typeof (TextBlock));
|
|
textBlockInHyperLinkFactory.SetBinding(TextBlock.TextProperty, binding);
|
|
|
|
var hyperLinkFactory = new FrameworkElementFactory(typeof (Hyperlink));
|
|
|
|
hyperLinkFactory.AddHandler(Hyperlink.RequestNavigateEvent,
|
|
columnName.Equals("Homepage")
|
|
? Hyperlink_OnRequestNavigateToHomepage
|
|
: new RequestNavigateEventHandler(Hyperlink_OnRequestNavigate));
|
|
|
|
hyperLinkFactory.SetBinding(Hyperlink.NavigateUriProperty, binding);
|
|
hyperLinkFactory.AppendChild(textBlockInHyperLinkFactory);
|
|
|
|
var outerTextBlockFactory = new FrameworkElementFactory(typeof (TextBlock));
|
|
outerTextBlockFactory.AppendChild(hyperLinkFactory);
|
|
|
|
var template = new DataTemplate {VisualTree = outerTextBlockFactory};
|
|
|
|
return template;
|
|
}
|
|
|
|
private void SetOidColumnsInvisible()
|
|
{
|
|
foreach (var col in datagrid_result.Columns.Where(col => !String.IsNullOrEmpty(col.FieldName) && col.FieldName.ToLower().IndexOf("oid") >= 0))
|
|
{
|
|
col.Visible = false;
|
|
}
|
|
}
|
|
|
|
|
|
private bool LoggedOnUserHasRightForQuery(QueryDC item)
|
|
{
|
|
if (!String.IsNullOrEmpty(item.UserGroupOids))
|
|
{
|
|
List<UserGroupDC> groups = BeWoApp.LoggedOnUser.UserGroups;
|
|
|
|
string oids = "," + item.UserGroupOids + ",";
|
|
return groups.Any(@group => oids.IndexOf(String.Format(",{0},", @group.UserGroupOid.Value)) >= 0);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void ResetQueryFields()
|
|
{
|
|
paramterPanel.Children.Clear();
|
|
parameterUIElements.Clear();
|
|
}
|
|
|
|
private void UpdatePDFExportUri(QueryDC query)
|
|
{
|
|
string url = BeWoApp.SiteOfOrigin + "/ReportView.aspx?dcid=" + BeWoApp.Tenant + "queryeoid" + BeWoApp.LoggedOnUser.Employee.EmployeeOid + "&qoid=" + query.Oid + "&type=" + Utils.EnumName(ReportTypes.QueryReport);
|
|
|
|
url = BeWoWpfUtils.GetHTMLEncodedURL(url);
|
|
linkPdfExport.NavigateUri = new Uri(BeWoUtils.RemoveAuthenticationInfoFromUri(url));
|
|
|
|
linkPdfExport.TargetName = Guid.NewGuid().ToString();
|
|
|
|
linkPdfExport_direct.NavigateUri = linkPdfExport.NavigateUri;
|
|
linkPdfExport_direct.TargetName = linkPdfExport.TargetName;
|
|
}
|
|
|
|
|
|
private void btnExecuteQuery_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var lQuery = combo_query.SelectedItem as QueryDC;
|
|
|
|
if (lQuery != null)
|
|
{
|
|
ExecuteQuery(lQuery);
|
|
}
|
|
}
|
|
|
|
private void combo_query_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
var lQuery = combo_query.SelectedItem as QueryDC;
|
|
|
|
ResetQueryFields();
|
|
GridImport.Visibility = Visibility.Collapsed;
|
|
|
|
String exportTitle = "Bericht öffnen";
|
|
if (lQuery != null)
|
|
{
|
|
|
|
if (!String.IsNullOrWhiteSpace(lQuery.ExportTitle))
|
|
{
|
|
exportTitle = lQuery.ExportTitle;
|
|
}
|
|
if (lQuery.Parameter == null || lQuery.Parameter.Count == 0)
|
|
{
|
|
if (lQuery.IsDirect)
|
|
{
|
|
datagrid_result.Visibility = Visibility.Collapsed;
|
|
textblock_link.Visibility = Visibility.Collapsed;
|
|
textblock_link_pdfexport.Visibility = Visibility.Collapsed;
|
|
btnExecuteQuery.Visibility = Visibility.Hidden;
|
|
textblock_link_pdfexport_direct.Visibility = Visibility.Visible;
|
|
}
|
|
else if (lQuery.IsImport)
|
|
{
|
|
datagrid_result.Visibility = Visibility.Collapsed;
|
|
textblock_link.Visibility = Visibility.Collapsed;
|
|
textblock_link_pdfexport.Visibility = Visibility.Collapsed;
|
|
btnExecuteQuery.Visibility = Visibility.Collapsed;
|
|
textblock_link_pdfexport_direct.Visibility = Visibility.Collapsed;
|
|
|
|
GridImport.Visibility = Visibility.Visible;
|
|
}
|
|
else
|
|
{
|
|
|
|
btnExecuteQuery.Visibility = Visibility.Collapsed;
|
|
textblock_link_pdfexport_direct.Visibility = Visibility.Collapsed;
|
|
ExecuteQuery(lQuery, null);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (CreateParameterFieldsAndExecute(lQuery))
|
|
{
|
|
btnExecuteQuery.Visibility = Visibility.Collapsed;
|
|
textblock_link_pdfexport_direct.Visibility = Visibility.Collapsed;
|
|
ExecuteQuery(lQuery);
|
|
}
|
|
else
|
|
{
|
|
if (lQuery.IsDirect)
|
|
{
|
|
btnExecuteQuery.Visibility = Visibility.Hidden;
|
|
textblock_link_pdfexport_direct.Visibility = Visibility.Visible;
|
|
}
|
|
else if (lQuery.IsImport)
|
|
{
|
|
GridImport.Visibility = Visibility.Visible;
|
|
}
|
|
else
|
|
{
|
|
btnExecuteQuery.Visibility = Visibility.Visible;
|
|
textblock_link_pdfexport_direct.Visibility = Visibility.Hidden;
|
|
}
|
|
}
|
|
}
|
|
TxtLinkExport.Text = exportTitle;
|
|
UpdatePDFExportUri(lQuery);
|
|
}
|
|
}
|
|
|
|
private void linkExcelExport_RequestNavigate(object sender, RequestNavigateEventArgs e)
|
|
{
|
|
var lView = datagrid_result.View as TableView;
|
|
|
|
var lHeaderCaptions = new List<string>();
|
|
var lContent = new List<List<string>>();
|
|
|
|
if (lView != null)
|
|
{
|
|
foreach (GridColumn iCol in lView.VisibleColumns)
|
|
{
|
|
lHeaderCaptions.Add(iCol.HeaderCaption.ToString());
|
|
|
|
for (int iRowIndex = 0; iRowIndex < datagrid_result.VisibleRowCount; iRowIndex++)
|
|
{
|
|
if (lContent.Count <= iRowIndex)
|
|
{
|
|
lContent.Add(new List<string>());
|
|
}
|
|
|
|
lContent[iRowIndex].Add(datagrid_result.GetCellValue(iRowIndex, iCol).ToStringNullCheck());
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
var path = BeWoApp.GetAndCreateUserAppDataPath() + "\\BeWoDokument.xls";
|
|
var lQuery = combo_query.SelectedItem as QueryDC;
|
|
|
|
bool isExcel = true;
|
|
if (lQuery != null)
|
|
{
|
|
if (!String.IsNullOrWhiteSpace(lQuery.FileName))
|
|
{
|
|
path = String.Format("{0}\\{1}", BeWoApp.GetAndCreateUserAppDataPath(), lQuery.FileName);
|
|
isExcel = false;
|
|
}
|
|
else
|
|
{
|
|
path = String.Format("{0}\\{1}.xls", BeWoApp.GetAndCreateUserAppDataPath(), lQuery.Title);
|
|
}
|
|
}
|
|
var sf = new SaveFileDialog
|
|
{
|
|
FileName = Path.GetFileName(path),
|
|
Filter = "Microsoft Excel 97-2003-Arbeitsblatt|*.xls|Alle Dateien|*.*"
|
|
};
|
|
if (sf.ShowDialog() != true)
|
|
return;
|
|
|
|
if (isExcel)
|
|
{
|
|
ServiceFacade.DoDownloadServiceSync(
|
|
s =>
|
|
BeWoUtils.WriteExcelFile(
|
|
s.PrepareExcelFile(DownloadLinkEngine.ExcelFileId, lHeaderCaptions, lContent),
|
|
sf.FileName));
|
|
}
|
|
else
|
|
{
|
|
ServiceFacade.DoDownloadServiceSync(
|
|
s =>
|
|
BeWoUtils.WriteFile(
|
|
s.PrepareExcelFile(DownloadLinkEngine.ExcelFileId, lHeaderCaptions, lContent),
|
|
sf.FileName));
|
|
}
|
|
|
|
//string navitageUri = ((Hyperlink)sender).NavigateUri.ToString();
|
|
//BeWoUtils.NavigateToReportUri(navitageUri);
|
|
//System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo((sender as System.Windows.Documents.Hyperlink).NavigateUri.ToString()));
|
|
|
|
//// Workaround Hyperlink mit neuem ersetzen, Navigate Uri lässt auf dem alten nicht ändern...
|
|
//this.textblock_link.Inlines.Clear();
|
|
//var lNewLink = new Hyperlink(new Run("Excel Export")) { NavigateUri = this.DownloadLinkEngine.GenerateNewExcelLink(), Foreground = Brushes.Black, TargetName = "newWindow" };
|
|
//lNewLink.RequestNavigate += this.linkExcelExport_RequestNavigate;
|
|
//this.textblock_link.Inlines.Add(lNewLink);
|
|
}
|
|
|
|
private void linkPdfExport_RequestNavigate(object sender, RequestNavigateEventArgs e)
|
|
{
|
|
var lQuery = combo_query.SelectedItem as QueryDC;
|
|
if (lQuery != null)
|
|
{
|
|
var dt = datagrid_result.ItemsSource as DataTable;
|
|
|
|
var dtStr = BS.Shared.Core.Utils.XMLSerializeToString(dt);
|
|
ServiceFacade.DoQueryServiceSync(
|
|
q =>
|
|
q.PrepareQueryReport(dtStr, BeWoApp.Tenant + "queryeoid" + BeWoApp.LoggedOnUser.Employee.EmployeeOid));
|
|
|
|
string navigateUri = linkPdfExport.NavigateUri.ToString();
|
|
|
|
navigateUri = BeWoUtils.RemoveAuthenticationInfoFromUri(navigateUri);
|
|
|
|
BeWoUtils.NavigateToReportUri(navigateUri, lQuery.Title);
|
|
}
|
|
|
|
e.Handled = true;
|
|
}
|
|
|
|
private void linkPdfExport_direct_RequestNavigate(object sender, RequestNavigateEventArgs e)
|
|
{
|
|
var lQuery = combo_query.SelectedItem as QueryDC;
|
|
if (lQuery != null)
|
|
{
|
|
List<QueryParamDC> parameterList = CreateQueryParamValues(lQuery);
|
|
|
|
if (!String.IsNullOrWhiteSpace(lQuery.ExportTitle))
|
|
{
|
|
lQuery.Parameter = parameterList;
|
|
|
|
//var result = ServiceFacade.DoDownloadServiceSync(s => s.CreateQuery(lQuery));
|
|
|
|
ServiceFacade.DoDownloadServiceAsync(s => s.CreateQuery(lQuery), result =>
|
|
this.Dispatch(
|
|
delegate
|
|
{
|
|
var path = String.Format("{0}\\{1}", BeWoApp.GetAndCreateUserAppDataPath(), result.FileName);
|
|
|
|
var sf = new SaveFileDialog
|
|
{
|
|
FileName = Path.GetFileName(path),
|
|
Filter = "Alle Dateien|*.*"
|
|
};
|
|
if (sf.ShowDialog() != true)
|
|
return;
|
|
|
|
|
|
if (result.Attachments != null)
|
|
{
|
|
var directoryName = Path.GetDirectoryName(sf.FileName);
|
|
|
|
foreach (var item in result.Attachments)
|
|
{
|
|
var pdfFilename = Path.Combine(directoryName, item.FileName);
|
|
File.WriteAllBytes(pdfFilename, item.BinaryData);
|
|
}
|
|
}
|
|
|
|
BeWoUtils.WriteFile(result.QueryResult, sf.FileName);
|
|
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
String dtStr = ServiceFacade.DoQueryServiceSync(s => s.ExecuteQuery(lQuery.Oid, parameterList));
|
|
|
|
ServiceFacade.DoQueryServiceSync(
|
|
q =>
|
|
q.PrepareQueryReport(dtStr, BeWoApp.Tenant + "queryeoid" + BeWoApp.LoggedOnUser.Employee.EmployeeOid));
|
|
|
|
string navigateUri = linkPdfExport.NavigateUri.ToString();
|
|
navigateUri = BeWoUtils.RemoveAuthenticationInfoFromUri(navigateUri);
|
|
BeWoUtils.NavigateToReportUri(navigateUri, lQuery.Title);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private void popupedit_file_PopUpClick(object sender, RoutedEventArgs ev)
|
|
{
|
|
var dlg = new OpenFileDialog();
|
|
|
|
if (dlg.ShowDialog() == true)
|
|
{
|
|
try
|
|
{
|
|
|
|
_UploadFileName = dlg.FileName;
|
|
|
|
popupedit_file.Text = dlg.SafeFileName;
|
|
button_uploadDocument.IsEnabled = true;
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void button_uploadDocument_Click(object sender, RoutedEventArgs pe)
|
|
{
|
|
if (!String.IsNullOrEmpty(popupedit_file.Text))
|
|
{
|
|
long? bewoFolderOid = null;
|
|
|
|
|
|
try
|
|
{
|
|
var upload = new ProgressStream(File.OpenRead(_UploadFileName));
|
|
//upload.ProgressChanged += (s, e) => Dispatcher.BeginInvoke(
|
|
// DispatcherPriority.Normal,
|
|
// (Action)(() =>
|
|
// {
|
|
// progressbar_upload.Value = e.Data;
|
|
// text_progress.Content = string.Format("Bitte warten... {0:00}%", e.Data * 100);
|
|
// }));
|
|
long oid = 0;
|
|
|
|
var lQuery = combo_query.SelectedItem as QueryDC;
|
|
if (lQuery != null)
|
|
{
|
|
oid = lQuery.Oid;
|
|
}
|
|
var lUlPackage = new UploadPackage(null, 0, _UploadFileName, null, oid, (int)TableID.Query, upload);
|
|
|
|
ServiceFacade.DoStreamingServiceAsync(
|
|
s => s.UploadImportFile(lUlPackage),
|
|
r => this.Dispatch(
|
|
delegate
|
|
{
|
|
|
|
|
|
//_UploadFileName = null;
|
|
//button_uploadDocument.IsEnabled = false;
|
|
//popupedit_file.Text = string.Empty;
|
|
|
|
upload.Dispose();
|
|
if (r != null && !String.IsNullOrEmpty(r.ResultMessage))
|
|
{
|
|
if (r.Success)
|
|
{
|
|
MessageBox.Show(r.ResultMessage, "Import", MessageBoxButton.OK,
|
|
MessageBoxImage.Information);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(r.ResultMessage, "Import", MessageBoxButton.OK,
|
|
MessageBoxImage.Exclamation);
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
() => this.Dispatch(
|
|
delegate
|
|
{
|
|
|
|
upload.Dispose();
|
|
}));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
} |