Files
BeWoPlaner/BeWo/View/ChatView.xaml.cs
2017-10-06 12:06:34 +02:00

189 lines
5.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using BeWo.Core.Config;
using BeWo.ServiceProxy;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
using ChatController.ChatKlassen;
using ChatController.Klassen;
using DevExpress.Xpf.Core;
using Button = System.Windows.Controls.Button;
using MessageBox = System.Windows.MessageBox;
namespace BeWo.View
{
/// <summary>
/// Interaktionslogik für ChatService.xaml
/// </summary>
public partial class ChatView : Window
{
public ChatEmojiView _emojiView;
public ChatView(ChatDatenUebergabe chatDaten)
{
InitializeComponent();
CloseWindow();
ChatMainControl.InitMitChatdaten(chatDaten);
ChatMainControl.AddContextMenu("In Dokumentation übernehmen", ChatMainControl_OnClickContextMenuItem);
//in einem thread auslagern
Thread newThread = new Thread(ChatMainControl.SynchronisationVeranlassen);
newThread.IsBackground = true;
newThread.Start();
}
private void RootGroupBox_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
try
{
DragMove();
}
catch (Exception) { }
}
private void CloseWindow()
{
CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (s, e) =>
{
//Close();
Visibility = Visibility.Hidden;
if (_emojiView != null)
{
_emojiView.Close(); // hidden
}
}));
}
private void ChatMainControl_OnOnEmoji(Button emojiButton)
{
if (_emojiView == null)
{
_emojiView = new ChatEmojiView(ChatMainControl);
var x = emojiButton.PointToScreen(new Point(0, 0));
PresentationSource source = PresentationSource.FromVisual(emojiButton);
_emojiView.Top = (x.Y / source.CompositionTarget.TransformToDevice.M22) - _emojiView.Height - 5;
_emojiView.Left = x.X / source.CompositionTarget.TransformToDevice.M11;
_emojiView.Show();
}
else
{
//if (_emojiView.Visibility == Visibility.Visible)
//{
// _emojiView.Visibility = Visibility.Hidden; // hidden
//}
//else
//{
_emojiView.Close();
_emojiView = null;
_emojiView = new ChatEmojiView(ChatMainControl);
var x = emojiButton.PointToScreen(new Point(0, 0));
PresentationSource source = PresentationSource.FromVisual(emojiButton);
_emojiView.Top = (x.Y / source.CompositionTarget.TransformToDevice.M22) - _emojiView.Height - 5;
_emojiView.Left = x.X / source.CompositionTarget.TransformToDevice.M11;
_emojiView.Show();
//}
}
}
private void ChatMainControl_OnClickContextMenuItem(String menuItem)
{
var aktuellerKontakt = ChatMainControl.GetAktuellenKontakt();
if (aktuellerKontakt != null)
{
var itemListe = ChatMainControl.GetSelectedMessages();
if (itemListe != null)
{
List<long> sdf = new List<long>();
//hier die Customer Oid hinzufügen
sdf.Add(1);
var compactCustomerlist = ServiceFacade.DoCustomerServiceSync(s => s.GetCompactCustomersById(sdf));
CompactCustomerDC compactCustomer = null;
foreach (var cc in compactCustomerlist)
{
compactCustomer = cc;
}
ChatDokumentationsView newView = new ChatDokumentationsView(itemListe,
BeWoApp.LoggedOnUser.Employee.PersonOid, compactCustomer);
newView.ShowDialog();
}
else
{
MessageBox.Show("Bitte Nachrichten auswählen");
}
}
else
{
MessageBox.Show("Dokumentiert werden kann nur im Chat der Klienten");
}
}
#region Fenster Größen verstellung
internal void Normal()
{
this.WindowState = (WindowState) FormWindowState.Normal;
}
internal void Maximize()
{
this.WindowState = (WindowState)FormWindowState.Maximized;
}
internal void Minimize()
{
this.WindowState = (WindowState)FormWindowState.Minimized;
}
#endregion
#region Close chat
private void ChatMainControl_OnOnClose()
{
_emojiView = null;
this.Dispatch(delegate
{
BeWoApp.MainControl.HomeView.ServiceChatView.Close();
BeWoApp.MainControl.HomeView.ServiceChatView = null;
});
}
#endregion
}
}