215 lines
7.2 KiB
C#
215 lines
7.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
|
|
using BeWo.Controls;
|
|
using BeWo.Core;
|
|
using BeWo.ServiceProxy;
|
|
using BeWo.Validation;
|
|
using BeWo.View.Search;
|
|
using BeWo.ViewModel;
|
|
using BeWo.ViewModel.ListViewModel;
|
|
using BeWo.Core.Service;
|
|
|
|
using BS.Shared;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.ClientPartials;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Services;
|
|
using BS.Shared.Translation;
|
|
using DevExpress.Xpf.RichEdit;
|
|
using SupportConceptService = BeWo.Core.Service.SupportConceptService;
|
|
using DevExpress.XtraRichEdit.API.Native;
|
|
using System.Drawing;
|
|
using DevExpress.Office.Utils;
|
|
using System.Windows.Media.Imaging;
|
|
|
|
namespace BeWo.View.Document
|
|
{
|
|
public partial class RtfEditView
|
|
{
|
|
List<PlatzhalterVM> Templates = new List<PlatzhalterVM>();
|
|
Dictionary<string, BitmapImage> ImageTypeToImage = new Dictionary<string, BitmapImage>();
|
|
|
|
|
|
public event Action ButtonSavedClicked;
|
|
public event Action ButtonCancelClicked;
|
|
|
|
public VorlagentabelleDC VorlagenTabelle { get; set; }
|
|
public DokumentvorlageVM ViewModel { get; set; }
|
|
|
|
public RtfEditView()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public override bool IsDirty
|
|
{
|
|
get
|
|
{
|
|
|
|
//if (ViewModel.SelectedVMForEditing != null && _SelectedEmployee != null &&
|
|
// !_SelectedEmployee.Equals(ViewModel.SelectedVMForEditing.Employee))
|
|
// return true;
|
|
|
|
return ViewModel != null && ViewModel.IsDirty;
|
|
}
|
|
}
|
|
|
|
public void InitView(VorlagentabelleDC vorlagenTabelle, DokumentvorlageVM pVM)
|
|
{
|
|
InitializeComponent();
|
|
VorlagenTabelle = vorlagenTabelle;
|
|
ViewModel = pVM;
|
|
DataContext = pVM;
|
|
|
|
if (pVM.Text != null)
|
|
{
|
|
EditorControl.RtfText = pVM.RTFText;
|
|
}
|
|
|
|
|
|
Focus();
|
|
}
|
|
|
|
private void LoadImagesForNodes(List<PlatzhalterVM> templates)
|
|
{
|
|
// Icons in ImageTypeToImage laden
|
|
foreach (var item in templates)
|
|
{
|
|
if (item.Children != null)
|
|
LoadImagesForNodes(item.Children);
|
|
|
|
if (item.IconType != null)
|
|
item.Icon = LoadImage(item.IconType);
|
|
|
|
}
|
|
}
|
|
private BitmapImage LoadImage(string imageName)
|
|
{
|
|
return new BitmapImage(new Uri("/Ressources/Icons/" + imageName + ".png", UriKind.Relative));
|
|
}
|
|
|
|
private PlatzhalterVM ConvertDataContractToViewModel(PlatzhalterDC dc)
|
|
{
|
|
var vm = new PlatzhalterVM()
|
|
{
|
|
Bezeichnung = dc.Bezeichnung,
|
|
Children = new List<PlatzhalterVM>(),
|
|
FieldName = dc.FieldName,
|
|
Icon = LoadImage(dc.IconType),
|
|
IconType = dc.IconType,
|
|
Platzhalter = dc.Platzhalter
|
|
};
|
|
|
|
if (dc.Children != null && dc.Children.Count > 0)
|
|
{
|
|
foreach (var item in dc.Children)
|
|
vm.Children.Add(ConvertDataContractToViewModel(item));
|
|
}
|
|
|
|
return vm;
|
|
}
|
|
private List<PlatzhalterVM> ConvertListOfDataContractsToViewModels(List<PlatzhalterDC> dcs)
|
|
{
|
|
List<PlatzhalterVM> vms = new List<PlatzhalterVM>();
|
|
foreach (var dc in dcs)
|
|
vms.Add(ConvertDataContractToViewModel(dc));
|
|
|
|
return vms;
|
|
}
|
|
|
|
//private List<PlatzhalterDC> LoadTemplates(long? tabelle)
|
|
//{
|
|
// List<PlatzhalterDC> templates = new List<PlatzhalterDC>();
|
|
|
|
// List<PlatzhalterDC> platzhalterDCs = new List<PlatzhalterDC>();
|
|
|
|
// switch (tabelle)
|
|
// {
|
|
// case 1: platzhalterDCs = ServiceFacade.DoOperationsServiceSync(s => s.GetPlatzhalterForSupportConcept()); break;
|
|
// case 2: platzhalterDCs = TemplatesForCustomers(); break;
|
|
// case 3: platzhalterDCs = TemplatesForEmployee(); break;
|
|
// }
|
|
|
|
// return templates;
|
|
//}
|
|
|
|
private List<PlatzhalterVM> GetPlatzhalter()
|
|
{
|
|
return ConvertListOfDataContractsToViewModels(ServiceFacade.DoOperationsServiceSync(s => s.GetPlatzhalterForTemplate(VorlagenTabelle)));
|
|
|
|
}
|
|
/*
|
|
private void combobox_templates_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
if (combobox_templates.SelectedItem == null)
|
|
return;
|
|
var selected = combobox_templates.SelectedItem as PlatzhalterDC;
|
|
|
|
if(selected.ToString().StartsWith("-") && selected.ToString().EndsWith("-"))
|
|
{
|
|
MessageBox.Show("Bindestriche kennzeichnen eine Vorlagenkategorie. Wählen Sie eine Vorlage ohne Bindestriche.", "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
return;
|
|
}
|
|
EditorControl.Document.InsertText(EditorControl.Document.CaretPosition, "[" + selected.Platzhalter + "]");
|
|
|
|
|
|
|
|
|
|
//EditorControl.Text += "[" + selected.Platzhalter + "]";
|
|
//EditorControl.RtfText += "[" + selected.Platzhalter + "]";
|
|
|
|
combobox_templates.SelectedItem = null;
|
|
}
|
|
*/
|
|
private void btnSave_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
ButtonSavedClicked?.Invoke();
|
|
}
|
|
|
|
private void btnClose_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
bool close = true;
|
|
if (ViewModel.IsDirty)
|
|
{
|
|
if (MessageBox.Show(
|
|
Translator.Translate("Möchten Sie wirklich abbrechen und die Änderungen verwerfen?"),
|
|
"BeWoPlaner", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.Cancel)
|
|
{
|
|
close = false;
|
|
}
|
|
}
|
|
|
|
if (close)
|
|
{
|
|
ButtonCancelClicked?.Invoke();
|
|
}
|
|
}
|
|
|
|
// Mouseup, um die aktuelle Position des Cursors zu speichern, um dort den Platzhalter an der aktuellen Stelle einzusetzen
|
|
// Klappt nur, wenn in Text geklickt wird und nicht hinter ein Wort..
|
|
// Hat aber keine verwendbaren Inhalte
|
|
private void richEditControl1_MouseUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
RichEditControl richEditControl = sender as RichEditControl;
|
|
System.Windows.Point point = e.GetPosition(richEditControl);
|
|
System.Drawing.Point docPoint = new System.Drawing.Point((int)point.X, (int)point.Y);
|
|
docPoint = Units.PixelsToDocuments(docPoint, richEditControl.DpiX, richEditControl.DpiY);
|
|
DocumentPosition pos = richEditControl.GetPositionFromPoint(docPoint);
|
|
//pos.
|
|
}
|
|
|
|
private void EditorControl_RtfTextChanged(object sender, EventArgs e)
|
|
{
|
|
ViewModel.Text = EditorControl.Text;
|
|
ViewModel.RTFText = EditorControl.RtfText;
|
|
}
|
|
|
|
}
|
|
} |