373 lines
12 KiB
C#
373 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Input;
|
|
|
|
using BeWo.Annotations;
|
|
using BeWo.Core;
|
|
using BeWo.ServiceProxy;
|
|
using BeWo.Validation;
|
|
using BeWo.ViewModel;
|
|
using BeWo.ViewModel.ListViewModel;
|
|
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Translation;
|
|
using DevExpress.Utils;
|
|
using DevExpress.Xpf.Editors;
|
|
using DevExpress.Xpf.Grid;
|
|
using MessageBox = System.Windows.MessageBox;
|
|
|
|
namespace BeWo.View
|
|
{
|
|
public partial class HilfeplanImportView : INotifyPropertyChanged
|
|
{
|
|
private HilfeplanImportDC _ViewModel;
|
|
private String _UploadFileName;
|
|
private long? _SupportConceptOid;
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
public event Action CloseButtonClicked;
|
|
|
|
private HilfeplanImportDC ViewModel
|
|
{
|
|
get { return _ViewModel; }
|
|
set
|
|
{
|
|
DataContext = value;
|
|
_ViewModel = value;
|
|
}
|
|
}
|
|
|
|
public SupportConceptDC ImportedSupportConcept { get; private set; }
|
|
|
|
public HilfeplanImportView(long? supportConceptOid)
|
|
{
|
|
InitializeComponent();
|
|
_SupportConceptOid = supportConceptOid;
|
|
ClearControls();
|
|
}
|
|
|
|
|
|
|
|
private void ReloadViewModel(HilfeplanImportDC dc)
|
|
{
|
|
this.ViewModel = dc;
|
|
|
|
ClearControls();
|
|
UpdateControls(dc);
|
|
}
|
|
|
|
private void ClearControls()
|
|
{
|
|
PanelGruppen.Children.Clear();
|
|
treeview_Goals.ItemsSource = null;
|
|
|
|
}
|
|
|
|
private void UpdateControls(HilfeplanImportDC dc)
|
|
{
|
|
if (dc.Gruppen != null)
|
|
{
|
|
foreach (var gruppe in dc.Gruppen)
|
|
{
|
|
ErstelleGruppe(gruppe);
|
|
}
|
|
}
|
|
|
|
if (dc.Ziele != null)
|
|
{
|
|
ErstelleTreeView(dc.Ziele);
|
|
}
|
|
GroupBoxMain.Visibility = Visibility.Visible;
|
|
|
|
|
|
}
|
|
|
|
|
|
private void ErstelleGruppe(HilfeplanImportItemDC gruppe)
|
|
{
|
|
var expander = new Expander();
|
|
expander.Margin = new Thickness(5);
|
|
expander.FontSize = 14;
|
|
expander.Header = gruppe.Label;
|
|
expander.IsExpanded = true;
|
|
|
|
|
|
var itemGrid = new Grid();
|
|
|
|
//itemGrid.FontWeight = FontWeights.Normal;
|
|
itemGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
|
|
itemGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
|
|
|
|
expander.Content = itemGrid;
|
|
|
|
if (gruppe.Items != null)
|
|
{
|
|
foreach (var item in gruppe.Items)
|
|
{
|
|
itemGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
|
|
|
|
var label = new System.Windows.Controls.Label();
|
|
label.FontSize = 12;
|
|
label.Margin = new Thickness(3);
|
|
label.Content = item.Label;
|
|
label.SetValue(Grid.ColumnProperty, 0);
|
|
label.SetValue(Grid.RowProperty, itemGrid.RowDefinitions.Count - 1);
|
|
|
|
var txt = new System.Windows.Controls.TextBox();
|
|
txt.FontSize = 12;
|
|
txt.Margin = new Thickness(3);
|
|
txt.Text = item.Content;
|
|
txt.MinWidth = 300;
|
|
txt.SetValue(Grid.ColumnProperty, 1);
|
|
txt.SetValue(Grid.RowProperty, itemGrid.RowDefinitions.Count - 1);
|
|
txt.Tag = item;
|
|
|
|
itemGrid.Children.Add(label);
|
|
itemGrid.Children.Add(txt);
|
|
}
|
|
}
|
|
PanelGruppen.Children.Add(expander);
|
|
}
|
|
|
|
private void ErstelleTreeView(IList<HilfeplanImportZielDC> ziele)
|
|
{
|
|
var treeItems = new BindingList<GoalTreeItem>();
|
|
|
|
foreach (var item in ziele)
|
|
{
|
|
GoalTreeItem ziel = new GoalTreeItem {
|
|
Name = item.ZielName,
|
|
Notice = item.ZielBeschreibung,
|
|
HilfeplanImportZiel = item,
|
|
IsZiel = true,
|
|
IsExpanded = true,
|
|
IsChecked = item.DoImport
|
|
|
|
};
|
|
|
|
GoalTreeItem parent = treeItems.Where(i => i.Name == item.Bereich).FirstOrDefault();
|
|
if (parent == null)
|
|
{
|
|
parent = new GoalTreeItem();
|
|
parent.Name = item.Bereich;
|
|
parent.FontWeight = FontWeights.Bold;
|
|
parent.IsExpanded = true;
|
|
parent.IsChecked = item.DoImport;
|
|
treeItems.Add(parent);
|
|
}
|
|
parent.Children.Add(ziel);
|
|
|
|
if (item.Massnahmen != null)
|
|
{
|
|
foreach (var massnahme in item.Massnahmen)
|
|
{
|
|
GoalTreeItem massnahmeItem = new GoalTreeItem
|
|
{
|
|
Name = massnahme.ZielName,
|
|
Notice = massnahme.ZielBeschreibung,
|
|
HilfeplanImportZiel = massnahme,
|
|
IsMassnahme = true,
|
|
IsChecked = massnahme.DoImport
|
|
};
|
|
|
|
ziel.Children.Add(massnahmeItem);
|
|
}
|
|
}
|
|
}
|
|
treeview_Goals.ItemsSource = treeItems;
|
|
|
|
}
|
|
|
|
private void popupedit_file_PopUpClick(object sender, RoutedEventArgs ev)
|
|
{
|
|
var dlg = new OpenFileDialog();
|
|
|
|
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
try
|
|
{
|
|
|
|
_UploadFileName = dlg.FileName;
|
|
|
|
popupedit_file.Text = dlg.SafeFileName;
|
|
ButtonImport.IsEnabled = true;
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
}
|
|
}
|
|
}
|
|
private void ButtonImport_Click(object sender, RoutedEventArgs pe)
|
|
{
|
|
if (!String.IsNullOrEmpty(popupedit_file.Text))
|
|
{
|
|
|
|
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 lUlPackage = new UploadPackage(null, 0, _UploadFileName, null, 0, 0, upload);
|
|
|
|
ServiceFacade.DoStreamingServiceAsync(
|
|
s => s.UploadPersehFile(lUlPackage),
|
|
r => this.Dispatch(
|
|
delegate
|
|
{
|
|
upload.Dispose();
|
|
if (r.HilfeplanImportData != null)
|
|
{
|
|
ReloadViewModel(r.HilfeplanImportData);
|
|
}
|
|
|
|
}),
|
|
() => this.Dispatch(
|
|
delegate
|
|
{
|
|
|
|
upload.Dispose();
|
|
}));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private void btnSave_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (ViewModel != null)
|
|
{
|
|
UpdateViewModel();
|
|
var result = ServiceFacade.DoCustomerServiceSync(s => s.ImportSupportConcept(ViewModel));
|
|
if (!String.IsNullOrEmpty(result.ImportMessage))
|
|
{
|
|
MessageBox.Show(result.ImportMessage, "Import", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
ImportedSupportConcept = result.ImportedSupportConcept;
|
|
|
|
CloseButtonClicked?.Invoke();
|
|
}
|
|
}
|
|
|
|
private void UpdateViewModel()
|
|
{
|
|
ViewModel.SupportConceptOid = _SupportConceptOid;
|
|
//Update Stammdaten
|
|
foreach (var item in PanelGruppen.Children)
|
|
{
|
|
var exp = item as Expander;
|
|
if (exp != null)
|
|
{
|
|
var g = exp.Content as Grid;
|
|
foreach (var gridItem in g.Children)
|
|
{
|
|
var txt = gridItem as System.Windows.Controls.TextBox;
|
|
if (txt != null && txt.Tag != null)
|
|
{
|
|
var ii = txt.Tag as HilfeplanImportItemDC;
|
|
if (ii != null)
|
|
{
|
|
ii.Content = txt.Text;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//Update Ziele
|
|
foreach (var item in treeview_Goals.ItemsSource)
|
|
{
|
|
var gti = item as GoalTreeItem;
|
|
if (gti != null)
|
|
{
|
|
UpdateGoalWithChildren(null, gti);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void UpdateGoalWithChildren(GoalTreeItem parent, GoalTreeItem gti)
|
|
{
|
|
if (gti.HilfeplanImportZiel != null)
|
|
{
|
|
if (parent != null)
|
|
{
|
|
gti.HilfeplanImportZiel.Bereich = parent.Name;
|
|
}
|
|
|
|
gti.HilfeplanImportZiel.ZielName = gti.Name;
|
|
gti.HilfeplanImportZiel.DoImport = gti.IsChecked;
|
|
}
|
|
if (gti.Children != null)
|
|
{
|
|
foreach (var c in gti.Children)
|
|
{
|
|
UpdateGoalWithChildren(gti, c);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void btnClose_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
CloseButtonClicked?.Invoke();
|
|
}
|
|
}
|
|
|
|
public class GoalTreeItem
|
|
{
|
|
private BindingList<GoalTreeItem> _Children;
|
|
|
|
public GoalTreeItem() { }
|
|
|
|
public bool IsZiel { get; set; }
|
|
|
|
public bool IsMassnahme { get; set; }
|
|
|
|
public bool IsChecked { get; set; }
|
|
|
|
public bool IsExpanded { get; set; }
|
|
|
|
public FontWeight FontWeight { get; set; }
|
|
|
|
public String Name { get; set; }
|
|
|
|
public String Notice { get; set; }
|
|
|
|
public HilfeplanImportZielDC HilfeplanImportZiel { get; set; }
|
|
|
|
public BindingList<GoalTreeItem> Children
|
|
{
|
|
get => _Children ?? (_Children = new BindingList<GoalTreeItem>());
|
|
set => _Children = value;
|
|
}
|
|
|
|
}
|
|
}
|