Files
BeWoPlaner/BeWo/View/ChatView.xaml.cs

3129 lines
124 KiB
C#
Raw Normal View History

2016-06-27 01:45:38 +02:00
using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using BeWo.ServiceProxy;
using BeWo.ViewModel;
using BS.Shared.Extensions;
using System.Windows.Controls;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Threading;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
2016-10-21 11:26:42 +02:00
using System.Diagnostics;
2016-09-16 13:45:25 +02:00
using System.Drawing;
using System.Globalization;
2016-06-27 01:45:38 +02:00
using System.IO;
2016-10-21 11:26:42 +02:00
using System.IO.Compression;
using System.Linq.Expressions;
2016-10-21 11:26:42 +02:00
using System.Media;
using System.Security.Permissions;
2016-06-27 01:45:38 +02:00
using System.Text;
using System.Text.RegularExpressions;
2016-07-29 13:11:34 +02:00
using System.Windows.Data;
2016-06-27 01:45:38 +02:00
using System.Windows.Documents;
2016-09-21 09:31:23 +02:00
using System.Windows.Forms;
2016-06-27 01:45:38 +02:00
using System.Windows.Media.Imaging;
2016-10-21 11:26:42 +02:00
using System.Windows.Navigation;
using BeWo.View.Detail;
2016-07-25 09:26:56 +02:00
using BS.Shared;
using BS.Shared.Core;
2016-07-29 13:11:34 +02:00
using BS.Shared.DataContracts;
2016-06-27 01:45:38 +02:00
using BS.Shared.DataContracts.Compact;
using DevExpress.Xpf.Core;
2016-09-14 13:53:58 +02:00
using DevExpress.Xpf.Docking;
2016-10-21 11:26:42 +02:00
using DevExpress.XtraEditors.Senders;
2016-08-01 10:15:24 +02:00
using DevExpress.XtraPrinting.Native;
2016-06-27 01:45:38 +02:00
using DevExpress.XtraPrinting.XamlExport;
using Microsoft.Office.Interop.Word;
//using NAudio.Wave;
2016-09-16 13:45:25 +02:00
using Brush = System.Windows.Media.Brush;
2016-10-21 11:26:42 +02:00
using Button = System.Windows.Forms.Button;
2016-06-27 01:45:38 +02:00
using Color = System.Drawing.Color;
2016-09-21 09:31:23 +02:00
using ContextMenu = System.Windows.Controls.ContextMenu;
2016-10-21 11:26:42 +02:00
using GroupBox = System.Windows.Forms.GroupBox;
2016-09-16 13:45:25 +02:00
using Image = System.Windows.Controls.Image;
2016-09-21 09:31:23 +02:00
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MenuItem = System.Windows.Controls.MenuItem;
using MessageBox = System.Windows.MessageBox;
2016-10-21 11:26:42 +02:00
using Panel = System.Windows.Forms.Panel;
using Point = System.Windows.Point;
2016-09-21 09:31:23 +02:00
using SelectionMode = System.Windows.Controls.SelectionMode;
2016-09-16 13:45:25 +02:00
using Size = System.Windows.Size;
2016-06-27 01:45:38 +02:00
2016-10-21 11:26:42 +02:00
2016-06-27 01:45:38 +02:00
namespace BeWo.View
{
public partial class ChatView
2016-06-27 01:45:38 +02:00
{
public UserVM ViewModel { get; set; }
public int abr = 0;
private TcpClient tcpClient;
2016-06-27 01:45:38 +02:00
private CollectionView view;
2016-07-29 13:11:34 +02:00
private ChatEmojisView emojiView = null;
private List<KontaktlistBuilder> ita = new List<KontaktlistBuilder>();
private List<long> oidspeicher = new List<long>();
private List<string> teamdc = new List<string>();
private PropertyGroupDescription groupDescription;
private bool isOnFocus = false;
2016-07-29 13:11:34 +02:00
2016-11-14 15:46:54 +01:00
private bool SendtoServerFailes = false;
2016-10-21 11:26:42 +02:00
//Neu Sound und Datei Versende gedöns usw...
//private WaveIn waveSource = null;
//private WaveFileWriter waveFile = null;
private SoundPlayer simpleSound = null;
private Form form1 = null;
private ChatProgressBarView progressView = null;
2016-11-08 14:32:38 +01:00
//protected IWavePlayer waveOutDevice = null;
//protected AudioFileReader audioFileReader = null;
2016-10-21 11:26:42 +02:00
//Für anzeige MEhr Anzeigen wen mehr als 20 items Vorhanden
private int itemGrenze = 10;
private List<string> aktuelleChatMessageIDListe = new List<string>();
private List<string> aktuelleChatMessageIDListeforTeam = new List<string>();
2016-11-15 13:35:31 +01:00
private bool WeitereNachrichtSchalter = false;
2016-10-21 11:26:42 +02:00
//versuch oder | probieren geht über studieren
private Dictionary<string, byte[]> SoundZwischenSpeicher = new Dictionary<string, byte[]>();
private Dictionary<string, byte[]> BildZwischenSpeicher = new Dictionary<string, byte[]>();
private Dictionary<string, byte[]> DokumentZwischenSpeicher = new Dictionary<string, byte[]>();
public Dictionary<string, string> Speicherpfad = new Dictionary<string, string>();
private bool sortLabelSwitch = false;
private ContextMenu context;
2016-07-25 09:26:56 +02:00
public ChatView(String nameinf, String Chatinf, TcpClient tcpClient)
2016-06-27 01:45:38 +02:00
{
InitializeComponent();
2016-11-14 15:46:54 +01:00
rootGroupBox.Header = nameinf;
2016-06-27 01:45:38 +02:00
2016-07-25 09:26:56 +02:00
this.tcpClient = tcpClient;
CloseWindow();
2016-09-14 13:53:58 +02:00
LoadallChatKontakts();
ErstelleContextMenue();
2016-10-21 11:26:42 +02:00
2016-10-04 14:02:30 +02:00
Width = System.Windows.SystemParameters.PrimaryScreenWidth /2;
Height = System.Windows.SystemParameters.PrimaryScreenWidth / 2;
2016-06-27 01:45:38 +02:00
}
public void UpdateTcp(TcpClient tcpClient)
{
this.tcpClient = tcpClient;
}
2016-06-27 01:45:38 +02:00
private void RootGroupBox_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
try
{
DragMove();
}
catch (Exception) { }
}
public void CloseWindow()
{
2016-06-27 01:45:38 +02:00
CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (s, e) =>
{
abr = 1;
if (emojiView != null && emojiView.Visibility == Visibility.Visible)
{
emojiView.Visibility = Visibility.Collapsed;
}
2016-06-27 01:45:38 +02:00
Visibility = Visibility.Collapsed;
}));
}
public void SetText(String text, String nameclient, long personoid)
2016-06-27 01:45:38 +02:00
{
2016-07-25 09:26:56 +02:00
try
2016-06-27 01:45:38 +02:00
{
2016-08-18 12:52:26 +02:00
if (AktChatUser.Items.Count != 0)
2016-06-27 01:45:38 +02:00
{
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
2016-07-25 09:26:56 +02:00
if (curItem.EmpfaengerOid == personoid)
{
2016-08-18 12:52:26 +02:00
foreach (var collection in ita)
2016-06-27 01:45:38 +02:00
{
2016-08-18 12:52:26 +02:00
if (collection.EmpfaengerOid == personoid)
collection.Receivems = "";
2016-07-25 09:26:56 +02:00
2016-08-18 12:52:26 +02:00
view.Refresh();
2016-06-27 01:45:38 +02:00
}
2016-08-18 12:52:26 +02:00
curItem.Receivems = "";
2016-06-27 01:45:38 +02:00
Chat.Items.Add(new KontakMessageBuilder(nameclient, text, DateTime.Now.ToString(), personoid,false,false,null));
2016-08-18 12:52:26 +02:00
Chat.Items.MoveCurrentToLast();
Chat.ScrollIntoView(Chat.Items.CurrentItem);
2016-06-27 01:45:38 +02:00
}
}
else
{
2016-08-18 12:52:26 +02:00
foreach (var abc in ita)
2016-06-27 01:45:38 +02:00
{
2016-08-18 12:52:26 +02:00
if (abc.EmpfaengerOid == personoid)
2016-06-27 01:45:38 +02:00
{
2016-08-18 12:52:26 +02:00
int x;
bool wasdrin = int.TryParse(abc.Receivems, out x);
2016-08-18 12:52:26 +02:00
if (wasdrin)
abc.Receivems = x++.ToString();
else
abc.Receivems = 1.ToString();
2016-06-27 01:45:38 +02:00
}
}
view.Refresh();
2016-07-25 09:26:56 +02:00
}
}
catch (Exception edf)
2016-07-25 09:26:56 +02:00
{
MessageBox.Show("Beim verarbeiten der Nachricht ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2220 ", MessageBoxButton.OK);
2016-06-27 01:45:38 +02:00
}
}
2016-08-12 14:50:25 +02:00
public void SetTeamAnzahlErhalteneNachricht(long personoid, ChatType type)
{
try
{
foreach (var abc in ita)
{
if (abc.EmpfaengerOid == personoid && abc.TypeChat == type)
2016-08-12 14:50:25 +02:00
{
int x;
bool wasdrin = int.TryParse(abc.Receivems, out x);
if (wasdrin)
{
x++;
2016-11-14 15:46:54 +01:00
abc.Receivems = x.ToString();
}
2016-08-12 14:50:25 +02:00
else
abc.Receivems = 1.ToString();
}
}
view.Refresh();
}
catch (Exception edf)
2016-08-12 14:50:25 +02:00
{
MessageBox.Show("Beim Setzen der Anzahl angekommender Nachrichten ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler 2391", MessageBoxButton.OK);
2016-08-12 14:50:25 +02:00
}
}
public void SetAnzahlErhalteneNachricht(long personoid)
{
try
{
foreach (var abc in ita)
{
if (abc.EmpfaengerOid == personoid && abc.TypeChat != ChatType.Team)
{
int x;
bool wasdrin = int.TryParse(abc.Receivems, out x);
if (wasdrin)
{
x++;
abc.Receivems = x.ToString();
}
else
abc.Receivems = 1.ToString();
}
}
view.Refresh();
}
catch (Exception edf)
{
MessageBox.Show("Beim Setzen der Anzahl angekommender Nachrichten ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler 2391", MessageBoxButton.OK);
}
}
public void RefreshViewModel()
{
view.Refresh();
}
public void SetList(String clientname, long personoid)
2016-06-27 01:45:38 +02:00
{
try
{
2016-07-25 09:26:56 +02:00
List<long> x = new List<long>();
x.Add(personoid);
2016-07-18 09:15:00 +02:00
2016-07-25 09:26:56 +02:00
var person = ServiceFacade.DoCustomerServiceSync(s => s.GetPersonsById(x));
2016-06-27 01:45:38 +02:00
2016-07-25 09:26:56 +02:00
var a = person[0].Type;
2016-06-27 01:45:38 +02:00
if (a == PersonType.Employee)
2016-07-25 09:26:56 +02:00
{
var mitarbeiter = ServiceFacade.DoEmployeeServiceSync(s => s.GetEmployeeWithPersonOid(personoid));
2016-07-29 13:11:34 +02:00
KontaktlistBuilder konbuild = new KontaktlistBuilder(clientname,StatusType.Online, BuildImg(mitarbeiter.EmployeeImage,ChatType.Mitarbeiter), personoid, ChatType.Mitarbeiter);//"Online"
2016-08-12 14:50:25 +02:00
var zugehorigkeit = ServiceFacade.DoEmployeeServiceSync(s => s.GetTeamOidsByEmployee(personoid));
2016-07-29 13:11:34 +02:00
foreach (var variable in ita)
{
if (konbuild.Name.Equals(variable.Name))
variable.StatusTyp = StatusType.Online;
2016-07-29 13:11:34 +02:00
if (variable.TypeChat == ChatType.Team)
2016-08-12 14:50:25 +02:00
{
foreach (var zug in zugehorigkeit)
{
if (zug.SimpleDescription.Equals(variable.Name))
{
variable.StatusTyp = StatusType.Online;
2016-08-12 14:50:25 +02:00
}
}
}
2016-07-29 13:11:34 +02:00
}
2016-11-14 15:46:54 +01:00
view.Refresh();
2016-07-25 09:26:56 +02:00
}
else if (a == PersonType.Customer)
2016-07-25 09:26:56 +02:00
{
var klienten = ServiceFacade.DoCustomerServiceSync(s => s.GetCustomerWithPersonOid(personoid));
2016-07-29 13:11:34 +02:00
CompactCustomerDC customerCompact = new CompactCustomerDC();
customerCompact = new CompactCustomerDC();
customerCompact.CustomerOid = klienten.CustomerOid.Value;
customerCompact.PersonOid = klienten.PersonOid.Value;
customerCompact.FirstName = klienten.FirstName;
customerCompact.LastName = klienten.LastName;
customerCompact.DateOfBirth = klienten.DateOfBirth;
KontaktlistBuilder konbuild = new KontaktlistBuilder(clientname, StatusType.Online, BuildImg(klienten.CustomerImage,ChatType.Klienten), personoid, ChatType.Klienten, customerCompact);//"Online"
2016-07-29 13:11:34 +02:00
foreach (var variable in ita)
{
if (konbuild.Name.Equals(variable.Name))
variable.StatusTyp = StatusType.Online;
2016-07-29 13:11:34 +02:00
}
view.Refresh();
2016-07-25 09:26:56 +02:00
}
2016-08-18 12:52:26 +02:00
if (AktChatUser.Items.Count != 0)
2016-08-18 12:52:26 +02:00
{
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
2016-08-18 12:52:26 +02:00
if (curItem.EmpfaengerOid == personoid)
{
curItem.StatusTyp = StatusType.Online;
2016-08-18 12:52:26 +02:00
view.Refresh();
}
}
2016-06-27 01:45:38 +02:00
}
catch (Exception edf)
2016-06-27 01:45:38 +02:00
{
MessageBox.Show("Beim Erweitern der 'Gerade Online' liste ist ein fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2230 ", MessageBoxButton.OK);
2016-06-27 01:45:38 +02:00
}
}
2016-08-12 14:50:25 +02:00
2016-06-27 01:45:38 +02:00
public void RemoveListItem(long clientid)
{
2016-07-25 09:26:56 +02:00
try
2016-06-27 01:45:38 +02:00
{
2016-07-29 13:11:34 +02:00
foreach (var abc in ita)
{
if (abc.EmpfaengerOid == clientid)
2016-06-27 01:45:38 +02:00
{
abc.StatusTyp = StatusType.Offline;
2016-06-27 01:45:38 +02:00
}
}
2016-07-29 13:11:34 +02:00
2016-08-12 14:50:25 +02:00
PruefeTeamsObOnline();
teamdc.Clear();
oidspeicher.Clear();
if (AktChatUser.Items.Count > 0)
{
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
if (curItem.EmpfaengerOid.Equals(clientid))
{
curItem.StatusTyp = StatusType.Offline;
}
}
2016-07-29 13:11:34 +02:00
view.Refresh();
2016-06-27 01:45:38 +02:00
}
2016-07-25 09:26:56 +02:00
catch (Exception e)
{
MessageBox.Show("Beim Entfernen eines Users von der 'Gerade Online' liste ist ein Fehler aufgetreten. " + e.Message + "\n" + e.StackTrace, "Fehler: 2240 ", MessageBoxButton.OK);
2016-07-25 09:26:56 +02:00
}
2016-06-27 01:45:38 +02:00
}
2016-08-12 14:50:25 +02:00
public void PruefeTeamsObOnline()
{
try
{
foreach (var teamprof in ita)
{
if (teamprof.TypeChat == ChatType.Mitarbeiter)
{
if (teamprof.StatusTyp == StatusType.Online)
2016-08-12 14:50:25 +02:00
{
oidspeicher.Add(teamprof.EmpfaengerOid);
}
}
}
if (oidspeicher.Count == 0)
{
foreach (var tt in ita)
{
if (tt.TypeChat == ChatType.Team)
{
tt.StatusTyp = StatusType.Offline;
2016-08-12 14:50:25 +02:00
}
}
}
else
{
foreach (var oid in oidspeicher)
{
var zugehorigkeit = ServiceFacade.DoEmployeeServiceSync(s => s.GetTeamOidsByEmployee(oid));
foreach (var dc in zugehorigkeit)
{
if (!teamdc.Contains(dc.SimpleDescription))
teamdc.Add(dc.SimpleDescription);
}
}
2016-08-12 14:50:25 +02:00
foreach (var tt in ita)
{
if (tt.TypeChat == ChatType.Team && !teamdc.Contains(tt.Name))
{
tt.StatusTyp = StatusType.Offline;
2016-08-12 14:50:25 +02:00
}
}
}
}
catch (Exception edf)
{
MessageBox.Show("Es ist ein Fehler Aufgetreten. Bitte Ruhe Bewahren. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2390 ", MessageBoxButton.OK);
2016-08-12 14:50:25 +02:00
}
}
2016-07-25 09:26:56 +02:00
public Boolean CompareWithListItem(long personid)
2016-06-27 01:45:38 +02:00
{
2016-07-25 09:26:56 +02:00
try
2016-06-27 01:45:38 +02:00
{
2016-08-01 10:15:24 +02:00
foreach (var abc in ita)
2016-06-27 01:45:38 +02:00
{
2016-08-01 10:15:24 +02:00
if (abc.EmpfaengerOid == personid)
2016-07-25 09:26:56 +02:00
{
2016-09-14 13:53:58 +02:00
if (abc.StatusTyp == StatusType.Online)
return true;
}
2016-06-27 01:45:38 +02:00
}
2016-07-25 09:26:56 +02:00
return false;
2016-06-27 01:45:38 +02:00
}
2016-07-25 09:26:56 +02:00
catch (Exception edf)
2016-06-27 01:45:38 +02:00
{
MessageBox.Show("Das Vergleichen mit der User-Liste ist nicht möglich. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2350 ",
2016-07-25 09:26:56 +02:00
MessageBoxButton.OK);
return false;
2016-06-27 01:45:38 +02:00
}
}
2016-07-25 09:26:56 +02:00
public void SetServerStats(String servstats)
{
2016-11-14 15:46:54 +01:00
//ServerStats.Text = servstats; //Ungenutzt
2016-07-25 09:26:56 +02:00
}
private void SendButton_Click(object sender, RoutedEventArgs e)
{
try
2016-06-27 01:45:38 +02:00
{
if (!AktChatUser.Items.IsEmpty && !Chatbox.Text.Equals("") && isOnFocus)
2016-06-27 01:45:38 +02:00
{
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
2016-07-25 09:26:56 +02:00
SendMessage(curItem.EmpfaengerOid, curItem.TypeChat);
2016-06-27 01:45:38 +02:00
Chat.Items.MoveCurrentToLast();
Chat.ScrollIntoView(Chat.Items.CurrentItem);
Chatbox.Text = "";
2016-07-25 09:26:56 +02:00
if (Chatbox.Text.Equals(""))
{
Chatbox.Text = "Nachricht schreiben";
Chatbox.Foreground = new SolidColorBrush(Colors.DarkGray);
isOnFocus = false;
2016-07-25 09:26:56 +02:00
}
2016-06-27 01:45:38 +02:00
}
else
{
2016-07-25 09:26:56 +02:00
if (AktChatUser.Items.IsEmpty)
{
MessageBox.Show("Bitte wählen Sie einen Chatpartner aus.", "Fehler", MessageBoxButton.OK);
if (Chatbox.Text.Equals(""))
{
Chatbox.Text = "Nachricht schreiben";
Chatbox.Foreground = new SolidColorBrush(Colors.DarkGray);
isOnFocus = false;
2016-07-25 09:26:56 +02:00
}
}
else if (Chatbox.Text.Equals(""))
{
MessageBox.Show("Sie können keine lehre Nachricht verschicken.", "Fehler", MessageBoxButton.OK);
if (Chatbox.Text.Equals(""))
{
Chatbox.Text = "Nachricht schreiben";
Chatbox.Foreground = new SolidColorBrush(Colors.DarkGray);
isOnFocus = false;
}
2016-07-25 09:26:56 +02:00
}
}
2016-07-25 09:26:56 +02:00
}
catch (Exception sf)
{
MessageBox.Show("Beim Senden einer Nachricht ist ein Fehler aufgetreten. " + sf.Message + "\n" + sf.StackTrace, "Fehler: 2250 ", MessageBoxButton.OK);
2016-06-27 01:45:38 +02:00
}
}
2016-07-25 09:26:56 +02:00
private void OnKeyDownHandler(object sender, KeyEventArgs e)
2016-06-27 01:45:38 +02:00
{
2016-07-25 09:26:56 +02:00
try
2016-06-27 01:45:38 +02:00
{
2016-07-25 09:26:56 +02:00
if (e.Key == Key.Return)
{
if (!AktChatUser.Items.IsEmpty && !Chatbox.Text.Equals(""))
2016-06-27 01:45:38 +02:00
{
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
2016-06-27 01:45:38 +02:00
SendMessage(curItem.EmpfaengerOid, curItem.TypeChat);
2016-06-27 01:45:38 +02:00
2016-07-25 09:26:56 +02:00
Chat.Items.MoveCurrentToLast();
Chat.ScrollIntoView(Chat.Items.CurrentItem);
2016-06-27 01:45:38 +02:00
Chatbox.Text = "";
2016-06-27 01:45:38 +02:00
}
2016-07-25 09:26:56 +02:00
else
2016-06-27 01:45:38 +02:00
{
2016-07-25 09:26:56 +02:00
if (AktChatUser.Items.IsEmpty)
{
MessageBox.Show("Bitte wählen Sie einen Chatpartner aus.", "Fehler", MessageBoxButton.OK);
2016-07-25 09:26:56 +02:00
}
else if (Chatbox.Text.Equals(""))
{
MessageBox.Show("Sie können keine lehre Nachricht verschicken.", "Fehler", MessageBoxButton.OK);
2016-07-25 09:26:56 +02:00
}
2016-06-27 01:45:38 +02:00
}
2016-07-25 09:26:56 +02:00
}
}
catch (Exception ed)
{
MessageBox.Show("Beim Senden einer Nachricht ist ein Fehler aufgetreten. " + ed.Message + "\n" + ed.StackTrace, "Fehler: 2260 ", MessageBoxButton.OK);
2016-07-25 09:26:56 +02:00
}
}
2016-06-27 01:45:38 +02:00
2016-07-29 13:11:34 +02:00
2016-08-18 12:52:26 +02:00
public void LoadallChatKontakts()
2016-07-29 13:11:34 +02:00
{
try
{
var employeeteamoids = ServiceFacade.DoEmployeeServiceSync(s => s.GetTeamOidsByEmployee(BeWoApp.LoggedOnUser.Employee.EmployeeOid));
var offmitarbeiter = ServiceFacade.DoEmployeeServiceSync(s => s.GetAllChatActiveEmployeesCompact());
var offklienten = ServiceFacade.DoCustomerServiceSync(s => s.GetAllChatActiveCustomersCompact(BeWoApp.LoggedOnUser.Employee.EmployeeOid));
2016-07-29 13:11:34 +02:00
2016-08-18 12:52:26 +02:00
foreach (var team in employeeteamoids)
{
Clientlist.Items.Add(new KontaktlistBuilder(team.Name, StatusType.Offline, BuildImg(null,ChatType.Team), team.TeamOid, ChatType.Team));
}
foreach (var list in offmitarbeiter)
{
if(list.PersonOid != BeWoApp.LoggedOnUser.Employee.PersonOid){
2016-09-19 08:42:35 +02:00
Clientlist.Items.Add(new KontaktlistBuilder(list.FirstName + " " + list.LastName, StatusType.Offline,
2016-10-06 08:57:05 +02:00
BuildImg(ServiceFacade.DoEmployeeServiceSync(s => s.GetEmployeeThumbnail(list.EmployeeOid)),ChatType.Mitarbeiter),
list.PersonOid, ChatType.Mitarbeiter));
}
}
foreach (var list in offklienten)
{
2016-09-16 13:45:25 +02:00
2016-09-19 08:42:35 +02:00
Clientlist.Items.Add(new KontaktlistBuilder(list.FirstName + " " + list.LastName, StatusType.Offline,
2016-09-30 09:00:41 +02:00
BuildImg(ServiceFacade.DoCustomerServiceSync(s => s.GetCustomerThumbnail(list.CustomerOid)), ChatType.Klienten),
list.PersonOid, ChatType.Klienten,list));
}
2016-07-29 13:11:34 +02:00
foreach (var a in Clientlist.Items)
{
KontaktlistBuilder cl = (KontaktlistBuilder)a;
2016-07-29 13:11:34 +02:00
ita.Add(cl);
}
2016-07-29 13:11:34 +02:00
Clientlist.Items.Clear();
Clientlist.ItemsSource = ita;
2016-07-29 13:11:34 +02:00
view = (CollectionView)CollectionViewSource.GetDefaultView(Clientlist.ItemsSource);
view.SortDescriptions.Add(new SortDescription("Receivems", ListSortDirection.Descending));
view.SortDescriptions.Add(new SortDescription("StatusType", ListSortDirection.Descending));
view.Filter = UserFilter;
if (sortLabelSwitch == true)
{
groupDescription = new PropertyGroupDescription("TypeChat");
view.GroupDescriptions.Add(groupDescription);
}
}
catch (Exception edf)
{
MessageBox.Show("Beim Setzen einer Neuen Chat Einstellung ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2270 ", MessageBoxButton.OK);
}
2016-07-29 13:11:34 +02:00
}
2016-08-18 12:52:26 +02:00
public void AktualisiereChatKontakt()
{
try
{
2016-08-18 12:52:26 +02:00
var employeeteamoids = ServiceFacade.DoEmployeeServiceSync(s => s.GetTeamOidsByEmployee(BeWoApp.LoggedOnUser.Employee.EmployeeOid));
var offmitarbeiter = ServiceFacade.DoEmployeeServiceSync(s => s.GetAllChatActiveEmployeesCompact());
2016-09-20 14:59:49 +02:00
var offklienten = ServiceFacade.DoCustomerServiceSync(s => s.GetAllChatActiveCustomersCompact(BeWoApp.LoggedOnUser.Employee.EmployeeOid));
2016-08-18 12:52:26 +02:00
List<long> idMitarbeitspeicher = new List<long>();
List<long> idteamspeicher = new List<long>();
List<long> idKlientspeicher = new List<long>();
2016-08-18 12:52:26 +02:00
foreach (var teamprof in ita)
{
if (teamprof.TypeChat == ChatType.Klienten)
{
idKlientspeicher.Add(teamprof.EmpfaengerOid);
2016-08-18 12:52:26 +02:00
}
if (teamprof.TypeChat == ChatType.Team)
{
idteamspeicher.Add(teamprof.EmpfaengerOid);
}
if (teamprof.TypeChat == ChatType.Mitarbeiter)
{
idMitarbeitspeicher.Add(teamprof.EmpfaengerOid);
}
}
2016-08-18 12:52:26 +02:00
foreach (var var in employeeteamoids)
{
if (!idteamspeicher.Contains(var.TeamOid) && idteamspeicher.Count <= employeeteamoids.Count)
{
ita.Add(new KontaktlistBuilder(var.Name,StatusType.Offline, BuildImg(null,ChatType.Team), var.TeamOid, ChatType.Team));
2016-08-18 12:52:26 +02:00
view.Refresh();
}
2016-07-29 13:11:34 +02:00
2016-08-18 12:52:26 +02:00
if (idteamspeicher.Contains(var.TeamOid))
idteamspeicher.Remove(var.TeamOid);
}
2016-08-18 12:52:26 +02:00
foreach (var var in offmitarbeiter)
{
if (!idMitarbeitspeicher.Contains(var.PersonOid) && idMitarbeitspeicher.Count <= offmitarbeiter.Count && var.PersonOid != BeWoApp.LoggedOnUser.Employee.PersonOid)
{
ita.Add(new KontaktlistBuilder(var.FirstName + " " + var.LastName,StatusType.Offline,
2016-10-06 08:57:05 +02:00
BuildImg(ServiceFacade.DoEmployeeServiceSync(s => s.GetEmployeeThumbnail(var.EmployeeOid)),ChatType.Mitarbeiter),
var.PersonOid, ChatType.Mitarbeiter));
2016-08-18 12:52:26 +02:00
view.Refresh();
}
if (idMitarbeitspeicher.Contains(var.PersonOid))
idMitarbeitspeicher.Remove(var.PersonOid);
}
foreach (var var in offklienten)
{
if (!idKlientspeicher.Contains(var.PersonOid) && idKlientspeicher.Count <= offklienten.Count)
{
ita.Add(new KontaktlistBuilder(var.FirstName + " " + var.LastName, StatusType.Offline,
2016-09-30 09:00:41 +02:00
BuildImg(ServiceFacade.DoCustomerServiceSync(s => s.GetCustomerThumbnail(var.CustomerOid)), ChatType.Klienten),
var.PersonOid, ChatType.Klienten,var));
2016-08-18 12:52:26 +02:00
view.Refresh();
}
if (idKlientspeicher.Contains(var.PersonOid))
2016-08-18 12:52:26 +02:00
idKlientspeicher.Remove(var.PersonOid);
}
2016-08-18 12:52:26 +02:00
if (idKlientspeicher.Count != 0)
{
var itemToRemove = ita.SingleOrDefault(r => r.EmpfaengerOid == idKlientspeicher[0] && r.TypeChat == ChatType.Klienten);
if (itemToRemove != null)
ita.Remove(itemToRemove);
view.Refresh();
}
if (idMitarbeitspeicher.Count != 0)
{
var itemToRemove = ita.SingleOrDefault(r => r.EmpfaengerOid == idMitarbeitspeicher[0] && r.TypeChat == ChatType.Mitarbeiter);
if (itemToRemove != null)
ita.Remove(itemToRemove);
view.Refresh();
}
if (idteamspeicher.Count != 0)
{
var itemToRemove = ita.SingleOrDefault(r => r.EmpfaengerOid == idteamspeicher[0] && r.TypeChat == ChatType.Team);
if (itemToRemove != null)
ita.Remove(itemToRemove);
2016-07-29 13:11:34 +02:00
2016-08-18 12:52:26 +02:00
view.Refresh();
}
if (sortLabelSwitch == true)
{
2016-09-28 10:16:32 +02:00
view.GroupDescriptions.Clear();
groupDescription = new PropertyGroupDescription("TypeChat");
view.GroupDescriptions.Add(groupDescription);
view.Refresh();
}
else
{
view.GroupDescriptions.Clear();
view.Refresh();
}
2016-08-18 12:52:26 +02:00
}
catch (Exception edf)
{
MessageBox.Show("Beim Aktualisieren der Kontakt Liste ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2210 ", MessageBoxButton.OK);
2016-08-18 12:52:26 +02:00
}
}
2016-07-29 13:11:34 +02:00
public void SetAllUserOfflineIfNoInet()
{
foreach (var list in ita)
{
list.StatusTyp = StatusType.Offline;
2016-07-29 13:11:34 +02:00
}
2016-11-14 15:46:54 +01:00
view.Refresh();
2016-07-29 13:11:34 +02:00
}
public void SetUserBeschäftigt(long oid, DataIdentifier type)
{
foreach (var list in ita)
{
if (oid == list.EmpfaengerOid)
{
if (type == DataIdentifier.StatusNotificationBeschäftigt)
2016-11-14 15:46:54 +01:00
list.StatusTyp = StatusType.Beschäftigt;
else if (type == DataIdentifier.StatusNotificationOnline)
2016-11-14 15:46:54 +01:00
list.StatusTyp = StatusType.Online;
else if (type == DataIdentifier.StatusNotificationOffline)
2016-11-14 15:46:54 +01:00
list.StatusTyp = StatusType.Offline;
}
}
view.Refresh();
}
private void ErstelleContextMenue()
2016-07-25 09:26:56 +02:00
{
try
{
context = new ContextMenu();
2016-07-29 13:11:34 +02:00
MenuItem item1 = new MenuItem();
2016-10-21 11:26:42 +02:00
MenuItem item2 = new MenuItem();
2016-07-29 13:11:34 +02:00
2016-10-21 11:26:42 +02:00
context.Items.Add(item1);
context.Items.Add(item2);
2016-07-29 13:11:34 +02:00
item1.Header = "Dokumentieren";
item1.Visibility = Visibility.Visible;
item1.Click += OnChatRightClickMenue;
2016-07-29 13:11:34 +02:00
2016-10-21 11:26:42 +02:00
item2.Header = "Speichern unter";
item2.Visibility = Visibility.Visible;
item2.Click += onChatRightClickItem2;
2016-11-14 15:46:54 +01:00
Image icon = new Image();
2016-08-31 10:55:59 +02:00
icon.Source = new BitmapImage(new Uri(@"..\..\Ressources\Icons\ClipboardDisabled.png", UriKind.Relative));
icon.SetSize(new Size(16, 16));
item1.Icon = icon;
2016-07-25 09:26:56 +02:00
Chat.ContextMenu = context;
}
catch (Exception edf)
{
MessageBox.Show("Beim Setzen einer Neuen Chat Einstellung ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2380 ", MessageBoxButton.OK);
}
}
2016-06-27 01:45:38 +02:00
2016-10-21 11:26:42 +02:00
public void onChatRightClickItem2(object sender, RoutedEventArgs e)
{
KontakMessageBuilder Item2;
if (Chat.SelectedItems.Count > 0 && Chat.SelectedItems.Count < 2 )
{
foreach (Object selecteditem in Chat.SelectedItems)
{
Item2 = selecteditem as KontakMessageBuilder;
if (Item2.PictureVisibility == Visibility.Visible)
{
2016-11-17 14:46:54 +01:00
if (Item2.ChatMessageOid.Value != 0)
{
SpeichernUnter(1,null, Item2.UserMessage,
Item2.ChatMessageOid.Value);
}
else
{
MessageBox.Show("Sie besitzen bereits dieses Bild.", "Info", MessageBoxButton.OK);
}
2016-10-21 11:26:42 +02:00
}
if (Item2.DokumentVisibility == Visibility.Visible)
{
2016-11-17 14:46:54 +01:00
if(Item2.ChatMessageOid.Value != 0){
SpeichernUnter(2, null, Item2.UserMessage, Item2.ChatMessageOid.Value);
}
else
{
MessageBox.Show("Sie besitzen bereits dieses Dokument.", "Info", MessageBoxButton.OK);
}
2016-10-21 11:26:42 +02:00
}
if (Item2.SoundVisibility == Visibility.Visible)
2016-11-17 14:46:54 +01:00
{
if (Item2.ChatMessageOid.Value != 0)
{
SpeichernUnter(3,null, Item2.UserMessage,
Item2.ChatMessageOid.Value);
}
else
{
MessageBox.Show("Sie besitzen bereits dieses SoundFile.", "Info", MessageBoxButton.OK);
}
2016-10-21 11:26:42 +02:00
}
if (Item2.SoundVisibility == Visibility.Collapsed && Item2.DokumentVisibility == Visibility.Collapsed && Item2.PictureVisibility == Visibility.Collapsed)
{
MessageBox.Show("Sie können keine normalen Chat Nachrichten Speichern.", "Info", MessageBoxButton.OK);
}
}
2016-10-21 11:26:42 +02:00
}
else
{
MessageBox.Show("Um eine Datei Speichern zu können, dürfen sie nur eine Chat Nachricht auswählen","Info",MessageBoxButton.OK);
}
}
2016-11-17 14:46:54 +01:00
public void SpeichernUnter(int filterTyp, byte[] datensatz,string dateiname,long chatmessageoid)
2016-10-21 11:26:42 +02:00
{
try
{
2016-11-17 14:46:54 +01:00
//lade hier die MEdia Datei runter
datensatz = ServiceFacade.DoCustomerServiceSync(r => r.GetChatMedia(chatmessageoid));
2016-10-21 11:26:42 +02:00
2016-11-17 14:46:54 +01:00
if (datensatz != null)
2016-10-21 11:26:42 +02:00
{
2016-11-17 14:46:54 +01:00
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
2016-10-21 11:26:42 +02:00
2016-11-17 14:46:54 +01:00
saveFileDialog1.FileName = dateiname;
2016-10-21 11:26:42 +02:00
2016-11-17 14:46:54 +01:00
if (filterTyp == 1) // Bilder
{
saveFileDialog1.Filter = "Bilder |*.jpg;*.png;*.jpeg;*.jpe;*.gif;*.bmp";
saveFileDialog1.Title = "Bild Speichern";
saveFileDialog1.ShowDialog();
}
if (filterTyp == 2) //Office
{
saveFileDialog1.Filter = "Office Dokumente |*.doc;*.xls;*.ppt;*.txt";
saveFileDialog1.Title = "Dokument Speichern";
saveFileDialog1.ShowDialog();
}
2016-10-21 11:26:42 +02:00
2016-11-17 14:46:54 +01:00
if (filterTyp == 3) // Audio
{
saveFileDialog1.Filter = "Audio Datei|*.wav;*.mp3;*.wma;*.aac;*.ogg;";
saveFileDialog1.Title = "Audio Speichern";
saveFileDialog1.ShowDialog();
}
if (saveFileDialog1.FileName != "")
{
FileStream fs = (FileStream) saveFileDialog1.OpenFile();
fs.Write(datensatz, 0, datensatz.Length);
fs.Close();
}
}
else
{
MessageBox.Show("Die Datei wurde nicht gefunden.", "Info", MessageBoxButton.OK);
2016-10-21 11:26:42 +02:00
}
}
catch (Exception e)
{
MessageBox.Show("Beim Speichern der Datei ist ein Fehler aufgetreten."+e.Message+" \n" +e.StackTrace, "Fehler: 2395", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
}
private void OnChatRightClickMenue(object sender, RoutedEventArgs e)
{
List<KontakMessageBuilder> itemListe = new List<KontakMessageBuilder>();
2016-11-14 15:46:54 +01:00
KontakMessageBuilder Item;
foreach (Object selecteditem in Chat.SelectedItems)
{
Item = selecteditem as KontakMessageBuilder;
if (Item.MessagePersonOid != 0)
{
itemListe.Add(Item);
2016-11-14 15:46:54 +01:00
}
}
if(itemListe.Count !=0){
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
if (curItem.TypeChat != ChatType.Team && curItem.TypeChat != ChatType.Mitarbeiter)
{
ChatDokumentationsView newView = new ChatDokumentationsView(itemListe, BeWoApp.LoggedOnUser.Employee.PersonOid, curItem.EmpfaengerOid,curItem.Customer);
2016-11-14 15:46:54 +01:00
newView.ShowDialog();
Chat.SelectedIndex = -1;
}
else
{
MessageBox.Show("Sie können nur Klienten Nachrichten Dokumentieren.", "Info", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
}
else
{
2016-11-14 15:46:54 +01:00
MessageBox.Show("Sie müssen für diese art von Dokumentation Chat-Nachrichten auswählen.", "Info", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
itemListe.Clear();
}
2016-06-27 01:45:38 +02:00
private void ComboBox_SelectionChanged(object sender, RoutedEventArgs e)
{
try
{
if (RadioButtonOnline.IsChecked.Value)
{
if (tcpClient == null)
{
RadioButtonOffline.IsChecked = true;
}
else if (!tcpClient.Connected)
{
RadioButtonOffline.IsChecked = true;
}
else
{
SendUserStatus(DataIdentifier.StatusNotificationOnline);
}
}
if (RadioButtonOffline.IsChecked.Value)
{
if (tcpClient == null)
{
RadioButtonOffline.IsChecked = true;
}
else if (!tcpClient.Connected)
{
RadioButtonOffline.IsChecked = true;
}
else
{
SendUserStatus(DataIdentifier.StatusNotificationOffline);
}
}
if (RadioButtonBeschaeftigt.IsChecked.Value)
{
if (tcpClient == null)
{
RadioButtonOffline.IsChecked = true;
}
else if (!tcpClient.Connected)
{
RadioButtonOffline.IsChecked = true;
}
else
{
SendUserStatus(DataIdentifier.StatusNotificationBeschäftigt);
2016-06-27 01:45:38 +02:00
}
2016-11-14 15:46:54 +01:00
}
2016-07-25 09:26:56 +02:00
}
catch (Exception edf)
{
MessageBox.Show("Beim Setzen eines neuen Statuses ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2270 ", MessageBoxButton.OK);
2016-06-27 01:45:38 +02:00
}
}
2016-07-29 13:11:34 +02:00
public void SendUserStatus(DataIdentifier identi)
2016-07-29 13:11:34 +02:00
{
try
{
NetworkStream serverStream = tcpClient.GetStream();
String abc = "";
Packet a = new Packet();
2016-10-21 12:08:54 +02:00
var guid = Guid.NewGuid();
byte[] outStream = a.GetDataStream(BeWoApp.LoggedOnUser.Employee.PersonOid, 0,
2016-10-21 12:08:54 +02:00
BeWoApp.LoggedOnUser.LoginName, abc, identi, BeWoApp.Tenant, false, true, guid.ToString());
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
}
catch (Exception edf)
{
Console.WriteLine(edf.StackTrace);
}
}
2016-07-29 13:11:34 +02:00
public void SetListBoxSelection(long personoid, ChatType type)
{
try
{
context.IsOpen = false;
2016-07-29 13:11:34 +02:00
foreach (var blub in ita)
{
if (blub.EmpfaengerOid == personoid && blub.TypeChat == type)
2016-07-29 13:11:34 +02:00
{
AktChatUser.Items.Clear();
Chat.Items.Clear();
2016-08-12 14:50:25 +02:00
blub.Receivems = "";
if (blub.TypeChat == ChatType.Klienten)
{
2016-09-14 13:53:58 +02:00
AktChatUser.Items.Add(new KontaktlistBuilder(blub.Name, blub.StatusTyp, blub.Image, blub.EmpfaengerOid, blub.TypeChat, blub.Customer));
}
else
{
2016-09-14 13:53:58 +02:00
AktChatUser.Items.Add(new KontaktlistBuilder(blub.Name, blub.StatusTyp, blub.Image, blub.EmpfaengerOid, blub.TypeChat));
}
LoadChatMessagefromDB(BeWoApp.LoggedOnEmployee.PersonOid.Value, blub.EmpfaengerOid, blub);
2016-11-14 15:46:54 +01:00
if (blub.TypeChat == ChatType.Klienten)
{
context.Visibility = Visibility.Visible;
var item = context.Items[0] as MenuItem;
item.Visibility = Visibility.Visible;
Chat.SelectionMode = SelectionMode.Extended;
Chat.Focusable = true;
}
else
{
2016-11-14 15:46:54 +01:00
context.Visibility = Visibility.Visible;
var item = context.Items[0] as MenuItem;
item.Visibility = Visibility.Collapsed;
Chat.SelectionMode = SelectionMode.Single;
2016-11-14 15:46:54 +01:00
Chat.Focusable = true;
}
}
2016-07-29 13:11:34 +02:00
}
Chat.Items.MoveCurrentToLast();
2016-11-14 15:46:54 +01:00
Chat.ScrollIntoView(Chat.Items.CurrentItem);
2016-07-29 13:11:34 +02:00
}
catch (Exception edf)
{
MessageBox.Show("Fehler siehe Fehlercode. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2370", MessageBoxButton.OK);
2016-07-29 13:11:34 +02:00
}
2016-06-27 01:45:38 +02:00
}
2016-07-29 13:11:34 +02:00
2016-06-27 01:45:38 +02:00
private void ListBoxSelectedIndexChanged(object sender, System.EventArgs e)
{
KontaktlistBuilder curItem;
try
{
context.IsOpen = false;
2016-06-27 01:45:38 +02:00
if (!Clientlist.Items.IsEmpty)
{
curItem = (KontaktlistBuilder)Clientlist.SelectedItem;
2016-06-27 01:45:38 +02:00
Chat.Items.Clear();
2016-06-27 01:45:38 +02:00
AktChatUser.Items.Clear();
if(curItem != null){
if (!curItem.Receivems.Equals(""))
{
curItem.Receivems = "";
}
if (curItem.TypeChat == ChatType.Klienten)
{
AktChatUser.Items.Add(new KontaktlistBuilder(curItem.Name, curItem.StatusTyp, curItem.Image, curItem.EmpfaengerOid, curItem.TypeChat, curItem.Customer));
}
else
{
AktChatUser.Items.Add(new KontaktlistBuilder(curItem.Name, curItem.StatusTyp, curItem.Image, curItem.EmpfaengerOid, curItem.TypeChat));
}
LoadChatMessagefromDB(BeWoApp.LoggedOnEmployee.PersonOid.Value, curItem.EmpfaengerOid, curItem);
Chat.Items.MoveCurrentToLast();
Chat.ScrollIntoView(Chat.Items.CurrentItem);
Suche.Text = "";
2016-11-14 15:46:54 +01:00
view.Refresh();
if (curItem.TypeChat == ChatType.Klienten)
{
context.Visibility = Visibility.Visible;
var item = context.Items[0] as MenuItem;
item.Visibility = Visibility.Visible;
Chat.SelectionMode = SelectionMode.Extended;
Chat.Focusable = true;
}
else
{
2016-11-14 15:46:54 +01:00
context.Visibility = Visibility.Visible;
var item = context.Items[0] as MenuItem;
2016-11-14 15:46:54 +01:00
item.Visibility = Visibility.Collapsed;
Chat.SelectionMode = SelectionMode.Single;
Chat.Focusable = true;
}
}
2016-06-27 01:45:38 +02:00
}
}
catch (Exception s)
{
curItem = null;
MessageBox.Show("Beim Auswählen eines Users ist ein Fehler aufgetreten. " + s.Message + "\n" + s.StackTrace, "Fehler: 2280 ", MessageBoxButton.OK);
2016-06-27 01:45:38 +02:00
}
}
public ImageSource BuildImg(Byte[] c ,ChatType x)
2016-06-27 01:45:38 +02:00
{
2016-07-25 09:26:56 +02:00
try
2016-06-27 01:45:38 +02:00
{
2016-07-25 09:26:56 +02:00
if (c != null)
{
var biImg = new BitmapImage();
2016-06-27 01:45:38 +02:00
2016-08-26 11:35:39 +02:00
using (var ms = new MemoryStream(c))
{
2016-08-26 11:35:39 +02:00
biImg.BeginInit();
biImg.StreamSource = ms;
biImg.CacheOption = BitmapCacheOption.OnLoad;
biImg.EndInit();
2016-08-26 11:35:39 +02:00
}
2016-07-25 09:26:56 +02:00
return biImg;
}
else
{
if (x == ChatType.Klienten)
{
BitmapImage bix = new BitmapImage();
bix.BeginInit();
bix.UriSource = new Uri("pack://application:,,,/Ressources/icons/klient-avatar.png");
bix.EndInit();
return bix;
}else
if (x == ChatType.Mitarbeiter)
{
BitmapImage biy = new BitmapImage();
biy.BeginInit();
biy.UriSource = new Uri("pack://application:,,,/Ressources/icons/mitarbeiter-avatar.png");
biy.EndInit();
return biy;
}else
if (x == ChatType.Team)
{
BitmapImage biz = new BitmapImage();
biz.BeginInit();
biz.UriSource = new Uri("pack://application:,,,/Ressources/icons/mitarbeiter-team-avatar.png");
biz.EndInit();
return biz;
}
else
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri("pack://application:,,,/Ressources/icons/UserHomeBoyDisabled.png");
bi.EndInit();
return bi;
}
2016-07-25 09:26:56 +02:00
}
2016-06-27 01:45:38 +02:00
}
2016-07-25 09:26:56 +02:00
catch (Exception edf)
2016-06-27 01:45:38 +02:00
{
MessageBox.Show("Beim Aufbauen der Profilbilder ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2290 ", MessageBoxButton.OK);
2016-07-25 09:26:56 +02:00
return null;
2016-06-27 01:45:38 +02:00
}
}
2016-07-29 13:11:34 +02:00
public void setConnectionLostIcon()
{
System.Drawing.Icon icon = System.Drawing.SystemIcons.Warning;
BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
AlarmLabel.Source = bs;
ButtonAlarmLabel.Visibility = Visibility.Visible;
}
public void SendMessage(long empfängeroid, ChatType type)
2016-06-27 01:45:38 +02:00
{
try
{
string msg = Chatbox.Text;
2016-07-29 13:11:34 +02:00
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, msg, DateTime.Now.ToString(), BeWoApp.LoggedOnUser.Employee.PersonOid,true,false,null));
2016-07-25 14:45:38 +02:00
if (tcpClient.Connected)
{
NetworkStream serverStream = tcpClient.GetStream();
2016-07-25 14:45:38 +02:00
Packet a = new Packet();
2016-10-21 12:08:54 +02:00
var guid = Guid.NewGuid();
byte[] outStream;
if (type == ChatType.Team)
{
2016-10-21 12:08:54 +02:00
outStream = a.GetDataStream(BeWoApp.LoggedOnUser.Employee.PersonOid, empfängeroid, BeWoApp.LoggedOnUser.LoginName, msg, DataIdentifier.Team, BeWoApp.Tenant, false,true,guid.ToString());
}
else
{
2016-10-21 12:08:54 +02:00
outStream = a.GetDataStream(BeWoApp.LoggedOnUser.Employee.PersonOid, empfängeroid, BeWoApp.LoggedOnUser.LoginName, msg, 0, BeWoApp.Tenant, false, true, guid.ToString());
}
2016-07-25 14:45:38 +02:00
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
}
else
{
2016-11-14 15:46:54 +01:00
if (!SendtoServerFailes)
{
MessageBox.Show("Der Server Stehet Zurzeit nicht zur verfügung. \nDie Nachrichten werden dennoch zur Datenbank übermittelt.", "Info", MessageBoxButton.OK);
SendtoServerFailes = true;
}
2016-11-15 13:35:31 +01:00
SaveChatMessageinDB(BeWoApp.LoggedOnUser.Employee.PersonOid, empfängeroid, msg, false, type);
2016-07-25 14:45:38 +02:00
}
2016-07-29 13:11:34 +02:00
}
2016-06-27 01:45:38 +02:00
catch (Exception xe)
{
if (tcpClient.Connected)
{
2016-11-14 15:46:54 +01:00
MessageBox.Show("Beim Senden einer Nachricht ist ein Fehler aufgetreten. " + xe.Message + "\n" + xe.StackTrace,
2016-07-25 14:45:38 +02:00
"Fehler: 2300 ", MessageBoxButton.OK);
}
2016-06-27 01:45:38 +02:00
}
}
2016-09-16 13:45:25 +02:00
public void SaveChatMessageinDB(long senderoid, long empfangid, string message, bool istZugestellt, ChatType type)
2016-06-27 01:45:38 +02:00
{
try
2016-07-25 14:45:38 +02:00
{
var guid = Guid.NewGuid();
if (type == ChatType.Team)
2016-11-15 13:35:31 +01:00
{
ServiceFacade.DoOperationsServiceSync(
s =>
s.CreateNewChatMessagesDC(senderoid, empfangid, message, istZugestellt, empfangid,
guid.ToString()));
aktuelleChatMessageIDListeforTeam.Add(guid.ToString());
}
else
2016-11-15 13:35:31 +01:00
{
ServiceFacade.DoOperationsServiceSync(
s =>
s.CreateNewChatMessagesDC(senderoid, empfangid, message, istZugestellt, 0,
guid.ToString()));
aktuelleChatMessageIDListe.Add(guid.ToString());
}
2016-06-27 01:45:38 +02:00
}
catch (InvalidOperationException e)
{
MessageBox.Show("Beim Speichern einer Nachricht in die Datenbank ist ein Fehler aufgetreten." + e.Message + "\n" + e.StackTrace, "Fehler: 2310 ", MessageBoxButton.OK);
2016-06-27 01:45:38 +02:00
}
}
2016-07-29 13:11:34 +02:00
public void LoadChatMessagefromDB(long senderoid, long empfaengerOid, KontaktlistBuilder Curitem)
2016-06-27 01:45:38 +02:00
{
2016-07-25 09:26:56 +02:00
try
{
aktuelleChatMessageIDListe.Clear();
2016-11-14 15:46:54 +01:00
aktuelleChatMessageIDListeforTeam.Clear();
2016-10-21 11:26:42 +02:00
if (Curitem.TypeChat == ChatType.Team)
2016-11-14 15:46:54 +01:00
{
var allTeamItems =
ServiceFacade.DoCustomerServiceSync(
s => s.FindAllChatMessagesFromTeam(senderoid, empfaengerOid,itemGrenze));
ShowTeamMessageInChat(allTeamItems,true);
foreach (var item in allTeamItems)
{
2016-11-14 15:46:54 +01:00
aktuelleChatMessageIDListeforTeam.Add(item.MessageId);
}
}
else
{
var allitems2 =
ServiceFacade.DoCustomerServiceSync(
s => s.FindAllChatMessages(senderoid, empfaengerOid, itemGrenze));
2016-11-14 15:46:54 +01:00
ShowMessageInChat(allitems2, true, senderoid, empfaengerOid);
foreach (var item in allitems2)
{
aktuelleChatMessageIDListe.Add(item.MessageId);
2016-11-14 15:46:54 +01:00
}
2016-07-25 09:26:56 +02:00
}
}
catch (Exception edf)
2016-06-27 01:45:38 +02:00
{
MessageBox.Show("Beim Laden einer Nachricht aus der Datenbank ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2320 ", MessageBoxButton.OK);
2016-06-27 01:45:38 +02:00
}
}
2016-06-27 01:45:38 +02:00
private void OnFocus(object sender, EventArgs e)
{
2016-07-25 09:26:56 +02:00
try
{
if (Chatbox.Text.Equals("Nachricht schreiben"))
{
Chatbox.Text = "";
Chatbox.Foreground = new SolidColorBrush(Colors.Black);
isOnFocus = true;
}
if (emojiView != null)
{
if (emojiView.Visibility == Visibility.Visible)
{
emojiView.Visibility = Visibility.Collapsed;
}
}
2016-07-25 09:26:56 +02:00
}
catch (Exception edf)
{
MessageBox.Show("Fehler beim Fokusieren der Nachrichten Leiste. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2330 ", MessageBoxButton.OK);
2016-07-25 09:26:56 +02:00
}
2016-06-27 01:45:38 +02:00
}
public void OnRightClickEvent(object sender, RoutedEventArgs e)
{
e.Handled = true;
}
public void SmileyButton_OnClick(object sender, RoutedEventArgs e)
{
if (emojiView == null)
{
emojiView = new ChatEmojisView();
var x = EmojiButton.PointToScreen(new Point(0, 0));
2016-09-21 10:00:53 +02:00
PresentationSource source = PresentationSource.FromVisual(EmojiButton);
emojiView.Top = (x.Y / source.CompositionTarget.TransformToDevice.M22) - emojiView.Height - 5;
emojiView.Left = x.X / source.CompositionTarget.TransformToDevice.M11;
2016-09-21 09:31:23 +02:00
emojiView.Show();
}
else
{
if (emojiView.Visibility == Visibility.Visible)
{
emojiView.Visibility = Visibility.Collapsed;
}
else
{
emojiView.Visibility = Visibility.Visible;
2016-09-19 14:21:21 +02:00
var x = EmojiButton.PointToScreen(new Point(0, 0));
2016-09-21 10:00:53 +02:00
PresentationSource source = PresentationSource.FromVisual(EmojiButton);
2016-09-19 14:21:21 +02:00
2016-09-21 10:00:53 +02:00
emojiView.Top = (x.Y/source.CompositionTarget.TransformToDevice.M22)- emojiView.Height - 5;
emojiView.Left = x.X / source.CompositionTarget.TransformToDevice.M11;
}
}
}
public void PruefeInDbObNeueNachrichtenVerfügbar()
{
try
{
2016-09-22 14:57:55 +02:00
ServiceFacade.DoOperationsServiceAsync(
s => s.FindUnreadChatMessagesForRecipient(BeWoApp.LoggedOnEmployee.PersonOid.Value),
m =>
{
2016-09-22 14:57:55 +02:00
Dispatcher.Invoke(
DispatcherPriority.Normal,
(ThreadStart) delegate
{
2016-09-22 14:57:55 +02:00
foreach (var ChatMessage in m)
{
foreach (var aktChatPersons in ita)
{
if (aktChatPersons.EmpfaengerOid == ChatMessage.SenderPersonOid &&
aktChatPersons.TypeChat != ChatType.Team)
{
int aktc;
bool wasdrin = int.TryParse(aktChatPersons.Receivems, out aktc);
if (wasdrin)
{
aktc++;
aktChatPersons.Receivems = aktc.ToString();
}
else
aktChatPersons.Receivems = 1.ToString();
}
2016-09-30 12:55:01 +02:00
else if (aktChatPersons.EmpfaengerOid == ChatMessage.TeamOid && ChatMessage.SenderPersonOid != aktChatPersons.EmpfaengerOid)
2016-09-22 14:57:55 +02:00
{
int aktt;
bool wasdrin = int.TryParse(aktChatPersons.Receivems, out aktt);
if (wasdrin)
{
aktt++;
aktChatPersons.Receivems = aktt.ToString();
}
else
aktChatPersons.Receivems = 1.ToString();
}
}
}
});
});
}
catch (Exception e)
{
MessageBox.Show("Fehler :" + e.Message + "\n" + e.StackTrace, "Info", MessageBoxButton.OK);
}
}
private void Suche_OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
Suche.Text = "";
}
}
private void Suche_OnTextChanged(object sender, TextChangedEventArgs e)
{
CollectionViewSource.GetDefaultView(Clientlist.ItemsSource).Refresh();
}
private bool UserFilter(object item)
{
if (String.IsNullOrEmpty(Suche.Text))
return true;
else
return ((item as KontaktlistBuilder).Name.IndexOf(Suche.Text, StringComparison.OrdinalIgnoreCase) >= 0);
}
private void Suche_OnLostFocus(object sender, RoutedEventArgs e)
{
// Suche.Text = "";
}
private void ButtonSortLabel_OnClick(object sender, RoutedEventArgs e)
{
if (sortLabelSwitch == false)
{
BitmapImage biy = new BitmapImage();
biy.BeginInit();
biy.UriSource = new Uri("pack://application:,,,/Ressources/icons/sortiert.png");
biy.EndInit();
SortLabel.Source = biy;
sortLabelSwitch = true;
AktualisiereChatKontakt();
}
else
{
BitmapImage biy = new BitmapImage();
biy.BeginInit();
biy.UriSource = new Uri("pack://application:,,,/Ressources/icons/unsortiert.png");
biy.EndInit();
SortLabel.Source = biy;
sortLabelSwitch = false;
AktualisiereChatKontakt();
}
}
private void AktChatUser_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
try
{
var offmitarbeiter = ServiceFacade.DoEmployeeServiceSync(s => s.GetAllChatActiveEmployeesCompact());
var offklienten = ServiceFacade.DoCustomerServiceSync(s => s.GetAllChatActiveCustomersCompact(BeWoApp.LoggedOnUser.Employee.EmployeeOid));
using (Form form = new Form())
{
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
Image imgg = new Image();
if (curItem.TypeChat == ChatType.Mitarbeiter)
{
foreach (var list in offmitarbeiter)
{
if (list.PersonOid == curItem.EmpfaengerOid)
{
imgg.Source = BuildImg(ServiceFacade.DoEmployeeServiceSync(s => s.GetEmployeeImage(list.EmployeeOid)), curItem.TypeChat);
}
}
}
if (curItem.TypeChat == ChatType.Klienten)
{
foreach (var list in offklienten)
{
if (list.PersonOid == curItem.EmpfaengerOid)
{
imgg.Source = BuildImg(ServiceFacade.DoCustomerServiceSync(s => s.GetCustomerImage(list.CustomerOid)), curItem.TypeChat);
}
}
}
if (curItem.TypeChat == ChatType.Team)
{
imgg.Source = BuildImg(null, curItem.TypeChat);
}
BmpBitmapEncoder encoder = new BmpBitmapEncoder();
MemoryStream ms = new MemoryStream();
encoder.Frames.Add(BitmapFrame.Create((BitmapSource)imgg.Source));
encoder.Save(ms);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
Bitmap imgbit = new Bitmap(img);
form.StartPosition = FormStartPosition.CenterScreen;
form.Size = imgbit.Size;
form.FormBorderStyle = FormBorderStyle.FixedSingle;
PictureBox pb = new PictureBox();
pb.Dock = DockStyle.Fill;
pb.Image = imgbit;
form.Controls.Add(pb);
form.ShowDialog();
}
}
catch (Exception edf)
{
MessageBox.Show("Unbekannter Fehler: " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2392 ", MessageBoxButton.OK);
}
}
2016-10-21 11:26:42 +02:00
//################# Umbauen in ein Stream programm zum videochatten. #####################################################
private void ButtonVideoChat_OnClick(object sender, RoutedEventArgs e)
2016-10-21 11:26:42 +02:00
{
}
2016-10-21 11:26:42 +02:00
// Code zum Abspielen von Sounds
private void PlayAufnahme_OnClick(object sender, RoutedEventArgs e)
{
2016-10-21 11:26:42 +02:00
var btn = sender as System.Windows.Controls.Button;
2016-10-21 11:26:42 +02:00
var soundArray = btn.Tag;
2016-10-21 11:26:42 +02:00
//Verarbeite den SoundArray
//byte array
2016-10-21 11:26:42 +02:00
Console.WriteLine("Abspielen Aufnahme");
2016-10-21 11:26:42 +02:00
//Image img = FindChildControl<Image>(this, "image") as Image;
//img.Source = new BitmapImage(new Uri(@"..\..\Ressources\Icons\ClipboardDisabled.png", UriKind.Relative));
2016-10-21 11:26:42 +02:00
//btn.Image = new Bitmap("pack://application:,,,/Ressources/icons/UserHomeBoyDisabled.png");
2016-10-21 11:26:42 +02:00
// if (mediaPlayer == null/*waveOutDevice == null*/)
2016-10-21 12:09:39 +02:00
// {
//simpleSound = new SoundPlayer(@"C:\Temp\WOMBO.mp3"); // Lade hier den Zwischenspeicher der noch erstellt werden soll und den Pfad der wav datei enthält
//simpleSound.Play();
/*waveOutDevice = new WaveOut();
audioFileReader = new AudioFileReader(@"C:\Temp\WOMBO.mp3");
waveOutDevice.Init(audioFileReader);
waveOutDevice.Play();
*/
// InitialiseMediaPlayer();
// }
// else
// {
//simpleSound.Stop();
//simpleSound = null;
// mediaPlayer.Stop();
// mediaPlayerTimer.Stop();
// mediaPlayer = null;
// mediaPlayerTimer = null;
/*waveOutDevice.Stop();
audioFileReader.Dispose();
waveOutDevice.Dispose();
waveOutDevice = null;
audioFileReader = null;*/
// }
Console.WriteLine("Abspielen Beendet");
}
//######################## Test phasen für Sound Datei ##########################
/* MediaPlayer mediaPlayer = null;
DispatcherTimer mediaPlayerTimer = null;
KontakSliderBuilder newSlide = new KontakSliderBuilder();
private void InitialiseMediaPlayer()
{
mediaPlayer = new MediaPlayer();
mediaPlayer.MediaOpened += MediaPlayer_MediaOpened;
mediaPlayer.Open(new Uri(@"C:\Temp\WOMBO.mp3", UriKind.Absolute));
2016-10-21 11:26:42 +02:00
}
private void MediaPlayer_MediaOpened(object sender, EventArgs e)
2016-10-21 11:26:42 +02:00
{
if (mediaPlayer.NaturalDuration.HasTimeSpan)
{
newSlide.sliderMaximum = mediaPlayer.NaturalDuration.TimeSpan.TotalSeconds;
mediaPlayerTimer = new DispatcherTimer();
mediaPlayerTimer.Interval = TimeSpan.FromMilliseconds(1000);
mediaPlayerTimer.Tick += MediaPlayerTimer_Tick;
mediaPlayerTimer.Start();
mediaPlayer.Play();
}
}
2016-10-21 11:26:42 +02:00
private void MediaPlayerTimer_Tick(object sender, EventArgs e)
{
if (mediaPlayer != null)
2016-10-21 11:26:42 +02:00
{
newSlide.position = mediaPlayer.Position.TotalSeconds;
newSlide.time = mediaPlayer.Position;
2016-10-21 11:26:42 +02:00
}
}*/
//##################################################################################
2016-10-21 11:26:42 +02:00
private void Sound_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
2016-10-21 11:26:42 +02:00
{
if (AktChatUser.Items.Count != 0)
2016-10-21 11:26:42 +02:00
{
/* if (WaveIn.DeviceCount != 0)
2016-10-21 11:26:42 +02:00
{
try
{
WaveInCapabilities deviceInfo = WaveIn.GetCapabilities(0);
Console.WriteLine("Device {0}: {1}, {2} channels", WaveIn.DeviceCount, deviceInfo.ProductName,
deviceInfo.Channels);
waveSource = new WaveIn();
waveSource.WaveFormat = new WaveFormat(441000, 2);
// waveSource.DeviceNumber = 1;
waveSource.DataAvailable += waveSource_DataAvailable;
waveSource.RecordingStopped += waveSource_RecordingStopped;
// waveFile = new WaveFileWriter(@"C:\Temp\Ich_Hau_Dich.wav", waveSource.WaveFormat); // <---- Muss abgesprochen werden
waveSource.StartRecording(); //<---- Da gibt es zurzeit probleme, der grund könnte mit dem mic zusammen hängen.
}
catch (Exception f)
{
MessageBox.Show("Unbekannter Fehler: " + f.Message + "\n" + f.StackTrace, "Fehler: 2393 ", MessageBoxButton.OK);
}
2016-10-21 11:26:42 +02:00
}
else
{
// MessageBox.Show("Bitte Schließen sie ein Microfon an, um diese Funktion nutzen zu können.", "Kein Microfon vorhanden.",MessageBoxButton.OK);
}*/
2016-10-21 11:26:42 +02:00
}
else
{
MessageBox.Show("Bitte Wählen sie einen Chat Partner aus", "Info", MessageBoxButton.OK);
}
2016-10-21 11:26:42 +02:00
}
private void Sound_OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (AktChatUser.Items.Count != 0)
{
/*if (WaveIn.DeviceCount != 0)
{
waveSource.StopRecording();
}*/
//übergebe gespeicherte aufnahme an prozess zum senden/speichern WOMBO.mp3
// ZeigeProgressWärendUpload(3, @"C:\Temp\WOMBO.mp3");
}
2016-10-21 11:26:42 +02:00
}
//testen
/* private void waveSource_DataAvailable(object sender, WaveInEventArgs e)
{
if (waveFile != null)
{
waveFile.Write(e.Buffer, 0, e.BytesRecorded);
waveFile.Flush();
}
}
2016-10-21 12:09:39 +02:00
////testen
private void waveSource_RecordingStopped(object sender, StoppedEventArgs e)
{
if (waveSource != null)
{
waveSource.Dispose();
waveSource = null;
}
2016-10-21 12:09:39 +02:00
if (waveFile != null)
{
waveFile.Dispose();
waveFile = null;
}
}
*/
2016-10-21 11:26:42 +02:00
//fertig | design aber noch nicht
private void MediaBase_OnClick(object sender, RoutedEventArgs e)
{
if (AktChatUser.Items.Count != 0)
{
using ( form1 = new Form())
{
form1.StartPosition = FormStartPosition.CenterParent;
form1.Size = new System.Drawing.Size(260, 80);
2016-10-21 11:26:42 +02:00
form1.FormBorderStyle = FormBorderStyle.FixedSingle;
form1.Text = "Media";
Button btnPic = new Button();
btnPic.Text = "Bild";
btnPic.Name = "Pic";
2016-10-21 11:26:42 +02:00
btnPic.Size = new System.Drawing.Size(120, 45);
btnPic.Margin = new Padding(2,2,2,2);
2016-10-21 11:26:42 +02:00
btnPic.TextAlign = ContentAlignment.MiddleCenter;
btnPic.Click += buttonMedia_Click;
2016-10-21 11:26:42 +02:00
Button btnDok = new Button();
btnDok.Text = "Dokument";
btnDok.Name = "Dok";
2016-10-21 11:26:42 +02:00
btnDok.Size = new System.Drawing.Size(120, 45);
btnDok.Margin = new Padding(2,2,2,2);
2016-10-21 11:26:42 +02:00
btnDok.Location = new System.Drawing.Point(125,0);
btnDok.TextAlign = ContentAlignment.MiddleCenter;
btnDok.Click += buttonMedia_Click;
2016-10-21 11:26:42 +02:00
form1.Controls.Add(btnPic);
form1.Controls.Add(btnDok);
form1.ShowDialog();
}
}
else
{
MessageBox.Show("Bitte Wählen sie einen Chat Partner aus", "Info", MessageBoxButton.OK);
}
}
//fertig
public void buttonMedia_Click(object s,EventArgs x)
{
2016-10-21 11:26:42 +02:00
try
{
Button btn = (Button) s;
int typ = 0;
if (btn.Name.Equals("Pic"))
typ = 1;
else
typ = 2;
2016-10-21 11:26:42 +02:00
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if(typ == 1)
openFileDialog1.Filter = "Bilder |*.jpg;*.png;*.jpeg;*.jpe;*.gif;*.bmp";
else
openFileDialog1.Filter = "Office Dokumente |*.doc;*.xls;*.ppt;*.txt";
2016-10-21 11:26:42 +02:00
DialogResult result = openFileDialog1.ShowDialog();
2016-10-21 11:26:42 +02:00
if (result == System.Windows.Forms.DialogResult.OK)
{
ZeigeProgressWärendUpload(typ,openFileDialog1.FileName);
}
}
catch (Exception e)
{
MessageBox.Show("Unbekannter Fehler: " + e.Message + "\n" + e.StackTrace, "Fehler: 2394 ", MessageBoxButton.OK);
}
}
2016-10-21 11:26:42 +02:00
private void ZeigeProgressWärendUpload(int mediaart, string file)
{
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
string filename = "";
2016-10-21 11:26:42 +02:00
try
{
filename = Path.GetFileName(file);
2016-10-21 11:26:42 +02:00
Dispatcher.BeginInvoke(
DispatcherPriority.Background,
(Action)(() =>
2016-10-21 11:26:42 +02:00
{
progressView = new ChatProgressBarView("Upload");
progressView.Show();
2016-10-21 11:26:42 +02:00
var upload = new ProgressStream(File.OpenRead(file));
2016-10-21 11:26:42 +02:00
upload.ProgressChanged += (s, e) => Dispatcher.BeginInvoke(
DispatcherPriority.Normal,
(Action)(() =>
{
progressView.progressBar.Value = e.Data * 100;
}));
2016-10-21 11:26:42 +02:00
SendSpeziallToServer(curItem.EmpfaengerOid, curItem.TypeChat, filename, upload, mediaart);
}));
}
catch (Exception edf)
{
MessageBox.Show("Es ist ein Fehler beim speichern der Datei aufgetreten. \n" + edf.Message + "\n" + edf.StackTrace, "Fehler", MessageBoxButton.OK);
}
2016-10-21 11:26:42 +02:00
try
{
switch (mediaart)
{
case 1:
ImageSource imageSource = new BitmapImage(new Uri(file));
2016-10-21 11:26:42 +02:00
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName,
filename, DateTime.Now.ToString(), curItem.EmpfaengerOid, true, false, true, false,
2016-11-17 14:46:54 +01:00
imageSource,null,null,false,null,0));
break;
case 2:
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName,
2016-11-17 14:46:54 +01:00
filename, DateTime.Now.ToString(), curItem.EmpfaengerOid, true, false, false, true, null, file, null, false, null,0));
break;
case 3:
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName,
2016-11-17 14:46:54 +01:00
filename, DateTime.Now.ToString(), curItem.EmpfaengerOid, true, true, false, false, null, null, null, false, null,0));
break;
2016-10-21 11:26:42 +02:00
}
Chat.Items.MoveCurrentToLast();
Chat.ScrollIntoView(Chat.Items.CurrentItem);
2016-10-21 11:26:42 +02:00
}
catch (Exception edfx)
2016-10-21 11:26:42 +02:00
{
MessageBox.Show("Bitte wählen sie das richtige Dateiformat aus. \n" + edfx.Message + "\n" + edfx.StackTrace, "Fehler: Falsches Dateiformat", MessageBoxButton.OK);
}
2016-10-21 11:26:42 +02:00
}
private void SendSpeziallToServer(long empfängeroid, ChatType type, string filename, Stream istream,int mediatyp)
2016-10-21 11:26:42 +02:00
{
if (tcpClient.Connected)
{
NetworkStream serverStream = tcpClient.GetStream();
Packet a = new Packet();
byte[] outStream;
2016-10-21 12:08:54 +02:00
var guid = Guid.NewGuid();
2016-10-21 11:26:42 +02:00
if (type == ChatType.Team)
{
2016-10-21 12:08:54 +02:00
outStream = a.GetDataStream(BeWoApp.LoggedOnUser.Employee.PersonOid, empfängeroid, BeWoApp.LoggedOnUser.LoginName, filename, DataIdentifier.Team, BeWoApp.Tenant, false, true, guid.ToString()/*,sound,doku,bild*/); // 3 werte
2016-10-21 11:26:42 +02:00
}
else
{
2016-10-21 12:08:54 +02:00
outStream = a.GetDataStream(BeWoApp.LoggedOnUser.Employee.PersonOid, empfängeroid, BeWoApp.LoggedOnUser.LoginName, filename, 0, BeWoApp.Tenant, false, true, guid.ToString()/*,sound,doku,bild*/ );
2016-10-21 11:26:42 +02:00
}
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
}
else
{
SaveChatSpeziallMessageinDB(type, BeWoApp.LoggedOnUser.Employee.PersonOid, empfängeroid, filename, false,mediatyp,istream);
2016-10-21 11:26:42 +02:00
}
}
2016-11-15 13:35:31 +01:00
private void SaveChatSpeziallMessageinDB(ChatType type, long senderoid, long empfangid, string message, bool istZugestellt, int mediatype, Stream upload)
2016-10-21 11:26:42 +02:00
{
UploadChatPackage chatpack;
var guid = Guid.NewGuid();
2016-10-21 11:26:42 +02:00
if (type == ChatType.Team)
{
chatpack = new UploadChatPackage(empfangid, istZugestellt, mediatype, message,guid.ToString() ,senderoid, empfangid, upload);
2016-11-15 13:35:31 +01:00
aktuelleChatMessageIDListeforTeam.Add(guid.ToString());
2016-10-21 11:26:42 +02:00
}
else
{
chatpack = new UploadChatPackage(empfangid, istZugestellt, mediatype, message,guid.ToString(), senderoid, 0, upload);
2016-11-15 13:35:31 +01:00
aktuelleChatMessageIDListe.Add(guid.ToString());
2016-10-21 11:26:42 +02:00
}
2016-11-14 15:46:54 +01:00
try
{
ServiceFacade.DoStreamingServiceAsync(s => s.CreateNewSpeziallStreamChatMessagesDC(chatpack),
r => this.Dispatch(
delegate
{
if (form1 != null)
{
form1.Close();
}
progressView.Close();
upload.Dispose();
}),
() => this.Dispatch(
delegate
{
progressView.Close();
upload.Dispose();
}));
}
catch (Exception edfg)
{
MessageBox.Show("Ups, Da ging was schief. \n Bitte Versuchen sie es Erneut. \n Fehler: "+edfg.Message,"Fehler",MessageBoxButton.OK);
}
2016-10-21 11:26:42 +02:00
}
2016-10-21 11:26:42 +02:00
private ImageSource DecodeBild(byte[] byteVal)
{
try
{
var image = new BitmapImage();
using (var mem = new MemoryStream(byteVal))
{
mem.Position = 0;
image.BeginInit();
image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
image.CacheOption = BitmapCacheOption.OnLoad;
image.UriSource = null;
image.StreamSource = mem;
image.EndInit();
}
2016-10-21 11:26:42 +02:00
return image;
}
catch (Exception ex)
{
return null;
}
}
private void OpenDokument_OnClick(object sender, RoutedEventArgs e)
2016-11-17 14:46:54 +01:00
{
var btn = sender as System.Windows.Controls.Button;
2016-11-17 14:46:54 +01:00
if (btn.Tag != null)
{
var filename = btn.Tag;
2016-10-21 11:26:42 +02:00
var fileType = filename.GetType();
2016-10-21 11:26:42 +02:00
if (fileType == typeof (String))
{
Process.Start(filename.ToString());
2016-10-21 11:26:42 +02:00
if (!Speicherpfad.ContainsKey(filename.ToString()))
Speicherpfad.Add(filename.ToString(), filename.ToString());
}
else if (fileType == typeof (object[]))
{
var dokarray = (object[]) btn.Tag;
2016-10-21 11:26:42 +02:00
string file = dokarray[0].ToString();
2016-11-17 14:46:54 +01:00
// byte[] dokBytes = (byte[]) dokarray[1];
long? chatMessageOid = (long?) dokarray[2];
2016-10-21 11:26:42 +02:00
2016-11-17 14:46:54 +01:00
//LAde Hier die Nötige Datei Herunter und übergebe diese dem
byte[] dokBytes = ServiceFacade.DoCustomerServiceSync(r => r.GetChatMedia(chatMessageOid.Value));
2016-10-21 11:26:42 +02:00
2016-11-17 14:46:54 +01:00
if(dokBytes != null){
string path = @"c:\temp\" + file;
2016-11-17 14:46:54 +01:00
if (File.Exists(path))
{
2016-11-17 14:46:54 +01:00
try
{
File.Delete(path);
2016-10-21 11:26:42 +02:00
2016-11-17 14:46:54 +01:00
using (FileStream SourceStream = File.Open(path, FileMode.OpenOrCreate))
{
SourceStream.Seek(0, SeekOrigin.End);
SourceStream.Write(dokBytes, 0, dokBytes.Length);
}
}
catch (Exception)
{
}
}
else
{
using (FileStream SourceStream = File.Open(path, FileMode.OpenOrCreate))
{
SourceStream.Seek(0, SeekOrigin.End);
SourceStream.Write(dokBytes, 0, dokBytes.Length);
}
}
2016-11-17 14:46:54 +01:00
//Dispatcher.BeginInvoke(
// DispatcherPriority.Normal,
// (Action)(() =>
// {
2016-10-21 11:26:42 +02:00
2016-11-17 14:46:54 +01:00
// myProcess.StartInfo.FileName = path;
// myProcess.EnableRaisingEvents = true;
// myProcess.Exited += myProcess_Exited;
2016-10-21 11:26:42 +02:00
2016-11-17 14:46:54 +01:00
// myProcess.Start();
2016-10-21 11:26:42 +02:00
2016-11-17 14:46:54 +01:00
// myProcess.WaitForExit();
2016-10-21 11:26:42 +02:00
2016-11-17 14:46:54 +01:00
// myProcess.Close();
//}));
Process.Start(path);
2016-10-21 11:26:42 +02:00
2016-11-17 14:46:54 +01:00
if(!Speicherpfad.ContainsKey(file))
Speicherpfad.Add(file,path);
2016-11-17 14:46:54 +01:00
}
else
{
MessageBox.Show("Die Datei wurde nicht Gefunden","Info",MessageBoxButton.OK);
}
}
2016-10-21 11:26:42 +02:00
}
}
//private void myProcess_Exited(object sender, EventArgs e)
//{
// var x = (Process)sender;
2016-10-21 11:26:42 +02:00
// try
// {
// if (File.Exists(x.StartInfo.FileName))
// {
// File.Delete(x.StartInfo.FileName);
// MessageBox.Show("File wurde erfolgreich deletet/ ID: " + x.Id, "File Deletet Info", MessageBoxButton.OK);
// }
// }
// catch (Exception)
// {
// MessageBox.Show("File Wurde bereits gelöscht / ID: " + x.Id + " / Filename: " + x.StartInfo.FileName, "File Deletet Info", MessageBoxButton.OK);
// }
//}
2016-10-21 11:26:42 +02:00
private void ChatView_OnStateChanged(object sender, EventArgs e)
{
if (this.WindowState == WindowState.Maximized)
{
this.WindowState = WindowState.Normal;
}
}
//VerunVolständigt
//private void AudioSlider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
//{
// var slider = sender as Slider;
// slider.Minimum = 0;
// slider.Maximum = audioFileReader.Length;
// slider.Value = (int)audioFileReader.Position;
//}
//Lade Media Daten aus der Datenbank
private void DatenRunterladen_OnClick(object sender, RoutedEventArgs e)
{
System.Windows.Controls.Button x = (System.Windows.Controls.Button)sender;
object[] array = (object[])x.Tag;
ChatMessageDC messagedc = (ChatMessageDC) array[0];
KontakMessageBuilder kontaktmessage = (KontakMessageBuilder) array[1];
var index = Chat.Items.IndexOf(kontaktmessage);
if(messagedc.MediaTyp == 1)
kontaktmessage.PictureVisibility = Visibility.Visible;
else
kontaktmessage.DokumentVisibility = Visibility.Visible;
kontaktmessage.Herunterladen = Visibility.Collapsed;
Chat.Items[index] = kontaktmessage;
//Von der Datenbank aus die Daten Rausholen.
//messagedc.ChatMessagesOid, sender und empfänger oid
Chat.Items.Refresh();
}
2016-11-15 13:35:31 +01:00
2016-11-14 15:46:54 +01:00
private void WeitereNachrichten_OnMouse(object sender, MouseButtonEventArgs e)
{
long senderoid, empfaengeroid;
2016-11-14 15:46:54 +01:00
System.Windows.Controls.Image x = (System.Windows.Controls.Image)sender;
List<ChatMessageDC> chatlist = (List<ChatMessageDC>)x.Tag;
senderoid = chatlist[0].SenderPersonOid ?? 0;
empfaengeroid = chatlist[0].EmpfängerPersonOid ?? 0;
List<ChatMessageDC> newitems;
2016-11-15 13:35:31 +01:00
if (chatlist[0].TeamOid == 0 || chatlist[0].TeamOid == null)
{
newitems =
ServiceFacade.DoCustomerServiceSync(
s =>
s.GetNextChatMessages(senderoid, empfaengeroid, false, aktuelleChatMessageIDListe,
itemGrenze));
}
else
{
newitems =
ServiceFacade.DoCustomerServiceSync(
s =>
2016-11-14 15:46:54 +01:00
s.GetNextChatMessages(senderoid, empfaengeroid, true, aktuelleChatMessageIDListeforTeam,
itemGrenze));
}
if(newitems.Count > 0){
2016-11-14 15:46:54 +01:00
if (chatlist[0].TeamOid != null)
{
2016-11-14 15:46:54 +01:00
foreach (var item in newitems)
{
if (!aktuelleChatMessageIDListeforTeam.Contains(item.MessageId))
aktuelleChatMessageIDListeforTeam.Add(item.MessageId);
}
2016-11-15 13:35:31 +01:00
var zahl = ServiceFacade.DoCustomerServiceSync(
s =>
s.CountChatMessages(aktuelleChatMessageIDListeforTeam.Count,senderoid,empfaengeroid,true));
if (zahl == 0)
WeitereNachrichtSchalter = true;
ShowTeamMessageInChat(newitems,false);
2016-11-14 15:46:54 +01:00
}
else{
foreach (var item in newitems)
{
if (!aktuelleChatMessageIDListe.Contains(item.MessageId))
aktuelleChatMessageIDListe.Add(item.MessageId);
}
2016-11-15 13:35:31 +01:00
var zahl = ServiceFacade.DoCustomerServiceSync(
s =>
s.CountChatMessages(aktuelleChatMessageIDListe.Count, senderoid, empfaengeroid,false));
if (zahl == 0)
WeitereNachrichtSchalter = true;
2016-11-14 15:46:54 +01:00
ShowMessageInChat(newitems, false,chatlist[0].SenderPersonOid,chatlist[0].EmpfängerPersonOid);
}
}
else
{
var itemprop = (KontakMessageBuilder)Chat.Items[0];
if(itemprop.MessagePersonOid == 0)
Chat.Items.RemoveAt(0);
}
2016-11-15 13:35:31 +01:00
if (WeitereNachrichtSchalter)
{
var itemprop = (KontakMessageBuilder)Chat.Items[0];
if (itemprop.MessagePersonOid == 0)
Chat.Items.RemoveAt(0);
WeitereNachrichtSchalter = false;
}
}
#region ChatMessagebuilder
2016-11-14 15:46:54 +01:00
private void ShowMessageInChat(List<ChatMessageDC> allitems2, bool firstTime, long? sendoid, long? empfangOid)
{
try
{
SoundZwischenSpeicher.Clear();
BildZwischenSpeicher.Clear();
DokumentZwischenSpeicher.Clear();
var allitems = allitems2.OrderBy(dc => dc.Uhrzeit).ToList();
2016-11-14 15:46:54 +01:00
long senderoid = sendoid ?? 0;//allitems[0].SenderPersonOid ?? 0;
long empfaengerOid = empfangOid ?? 0; //allitems[0].EmpfängerPersonOid ?? 0;
if (firstTime)
{
if (allitems.Count == itemGrenze)
{
Chat.Items.Add(new KontakMessageBuilder("", "------------------------ Mehr Nachrichten Vorhanden ---------------------------------", "", 0, false, true, allitems));
}
else
{
2016-11-15 13:35:31 +01:00
//Chat.Items.Add(new KontakMessageBuilder("", "------------------------ Keine weiteren Nachrichten Verfügbar -----------------------", "", 0, false, false, null));
}
}
List<long> x = new List<long>();
x.Add(senderoid);
x.Add(empfaengerOid);
var person = ServiceFacade.DoCustomerServiceSync(s => s.GetPersonsById(x));
int i = 0;
foreach (var list in allitems)
{
//Chat Message dem array übergeben
object[] datenmengen = new object[2];
datenmengen[0] = list;
if (list.IstGelesen == 1 && (list.TeamOid == null || list.TeamOid == 0))
{
if (list.SenderPersonOid == senderoid)
{
2016-11-17 14:46:54 +01:00
if (list.MediaTyp == 0)
{
Chat.Items.Add(new KontakMessageBuilder(person[0].FirstName, list.ChatText,
list.Uhrzeit.ToString(), senderoid, true, false, null));
}
else
{
2016-11-17 14:46:54 +01:00
if (list.MediaTyp == 1)
{
2016-11-17 14:46:54 +01:00
var bild = DecodeBild(list.ImageThumpNail);
if (!BildZwischenSpeicher.ContainsKey(list.ChatText))
BildZwischenSpeicher.Add(list.ChatText, list.MediaDatei);
KontakMessageBuilder builder =
new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText,
2016-11-17 14:46:54 +01:00
list.Uhrzeit.ToString(), senderoid, true, false, true, false, bild, null,
null, false, datenmengen, list.ChatMessagesOid);
datenmengen[1] = builder;
Chat.Items.Add(builder);
}
//if (list.SoundDatei != null)
//{
// if (!SoundZwischenSpeicher.ContainsKey(list.ChatText))
// SoundZwischenSpeicher.Add(list.ChatText,list.SoundDatei);
// Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText, list.Uhrzeit.ToString(), senderoid, true, true, false, false, null,null,null));
//}
2016-11-17 14:46:54 +01:00
if (list.MediaTyp == 2)
{
if (!DokumentZwischenSpeicher.ContainsKey(list.ChatText))
DokumentZwischenSpeicher.Add(list.ChatText, list.MediaDatei);
KontakMessageBuilder builder =
new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText,
2016-11-14 15:46:54 +01:00
list.Uhrzeit.ToString(), senderoid, true, false, false, true, null,
2016-11-17 14:46:54 +01:00
list.ChatText, null, false, datenmengen, list.ChatMessagesOid);
datenmengen[1] = builder;
Chat.Items.Add(builder);
}
}
}
else
{
2016-11-17 14:46:54 +01:00
if (list.MediaTyp == 0)
{
Chat.Items.Add(new KontakMessageBuilder(person[1].FirstName, list.ChatText,
list.Uhrzeit.ToString(), empfaengerOid, false, false, null));
}
else
{
2016-11-17 14:46:54 +01:00
if (list.MediaTyp == 1)
{
2016-11-17 14:46:54 +01:00
var bild = DecodeBild(list.ImageThumpNail);
if (!BildZwischenSpeicher.ContainsKey(list.ChatText))
BildZwischenSpeicher.Add(list.ChatText, list.MediaDatei);
KontakMessageBuilder builder =
new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText,
2016-11-17 14:46:54 +01:00
list.Uhrzeit.ToString(), empfaengerOid, false, false, true, false, bild,
null, null, false, datenmengen, list.ChatMessagesOid);
datenmengen[1] = builder;
Chat.Items.Add(builder);
}
//if (list.SoundDatei != null)
//{
// if (!SoundZwischenSpeicher.ContainsKey(list.ChatText))
// SoundZwischenSpeicher.Add(list.ChatText, list.SoundDatei);
// Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText, list.Uhrzeit.ToString(), empfaengerOid, true, true, false, false, null,null,null));
//}
2016-11-17 14:46:54 +01:00
if (list.MediaTyp == 2)
{
if (!DokumentZwischenSpeicher.ContainsKey(list.ChatText))
DokumentZwischenSpeicher.Add(list.ChatText, list.MediaDatei);
KontakMessageBuilder builder =
new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText,
2016-11-14 15:46:54 +01:00
list.Uhrzeit.ToString(), empfaengerOid, false, false, false, true, null,
2016-11-17 14:46:54 +01:00
list.ChatText, null, false, datenmengen, list.ChatMessagesOid);
datenmengen[1] = builder;
Chat.Items.Add(builder);
}
}
}
}
else
{
if (list.TeamOid == null || list.TeamOid == 0)
{
if (list.SenderPersonOid == senderoid)
{
2016-11-17 14:46:54 +01:00
if (list.MediaTyp == 0)
{
Chat.Items.Add(new KontakMessageBuilder(person[0].FirstName, list.ChatText,
list.Uhrzeit.ToString(), senderoid, true, false, null));
}
else
{
2016-11-17 14:46:54 +01:00
if (list.MediaTyp == 1)
{
2016-11-17 14:46:54 +01:00
var bild = DecodeBild(list.ImageThumpNail);
if (!BildZwischenSpeicher.ContainsKey(list.ChatText))
BildZwischenSpeicher.Add(list.ChatText, list.MediaDatei);
KontakMessageBuilder builder =
new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName,
2016-11-17 14:46:54 +01:00
list.ChatText, list.Uhrzeit.ToString(), senderoid, true, false, true,
false, bild, null, null, false, datenmengen, list.ChatMessagesOid);
datenmengen[1] = builder;
Chat.Items.Add(builder);
}
//if (list.SoundDatei != null)
//{
// if (!SoundZwischenSpeicher.ContainsKey(list.ChatText))
// SoundZwischenSpeicher.Add(list.ChatText, list.SoundDatei);
// Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText, list.Uhrzeit.ToString(), senderoid, true, true, false, false, null,null,null));
//}
2016-11-17 14:46:54 +01:00
if ( list.MediaTyp == 2)
{
if (!DokumentZwischenSpeicher.ContainsKey(list.ChatText))
DokumentZwischenSpeicher.Add(list.ChatText, list.MediaDatei);
KontakMessageBuilder builder =
new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName,
list.ChatText, list.Uhrzeit.ToString(), senderoid, true, false, false,
2016-11-17 14:46:54 +01:00
true, null, list.ChatText, null, false, datenmengen, list.ChatMessagesOid);
datenmengen[1] = builder;
Chat.Items.Add(builder);
}
}
}
else
{
if (i == 0)
{
Chat.Items.Add(new KontakMessageBuilder("",
"------------------------ Ungelesene Nachrichten -----------------------", "", 0,
false, false, null));
i++;
}
2016-11-17 14:46:54 +01:00
if (list.MediaTyp == 0)
{
Chat.Items.Add(new KontakMessageBuilder(person[1].FirstName, list.ChatText,
list.Uhrzeit.ToString(), empfaengerOid, false, false, null));
}
else
{
2016-11-17 14:46:54 +01:00
if (list.MediaTyp == 1)
{
2016-11-17 14:46:54 +01:00
var bild = DecodeBild(list.ImageThumpNail);
if (!BildZwischenSpeicher.ContainsKey(list.ChatText))
BildZwischenSpeicher.Add(list.ChatText, list.MediaDatei);
Chat.Items.Add(new KontakMessageBuilder(
BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText,
2016-11-17 14:46:54 +01:00
list.Uhrzeit.ToString(), empfaengerOid, false, false, true, false, bild,
null, null, false, datenmengen, list.ChatMessagesOid));
}
//if (list.SoundDatei != null)
//{
// if (!SoundZwischenSpeicher.ContainsKey(list.ChatText))
// SoundZwischenSpeicher.Add(list.ChatText, list.SoundDatei);
// Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText, list.Uhrzeit.ToString(), empfaengerOid, true, true, false, false, null,null,null));
//}
2016-11-17 14:46:54 +01:00
if (list.MediaTyp == 2)
{
if (!DokumentZwischenSpeicher.ContainsKey(list.ChatText))
DokumentZwischenSpeicher.Add(list.ChatText, list.MediaDatei);
Chat.Items.Add(new KontakMessageBuilder(
BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText,
2016-11-17 14:46:54 +01:00
list.Uhrzeit.ToString(), empfaengerOid, false, false, false, true, null,
list.ChatText, null, false, datenmengen,list.ChatMessagesOid));
}
}
}
}
}
}
ServiceFacade.DoCustomerServiceSync(s => s.UpdateIstGelesen(empfaengerOid, senderoid, true));
var lisadst = Chat.Items.Cast<KontakMessageBuilder>().OrderBy(item => item.SendTime).ToList();
Chat.Items.Clear();
foreach (KontakMessageBuilder listItem in lisadst)
{
Chat.Items.Add(listItem);
}
}
catch (Exception edf)
{
MessageBox.Show("Beim Laden der Nachricht aus der Datenbank ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2320 ", MessageBoxButton.OK);
}
}
#endregion
2016-11-15 13:35:31 +01:00
#region ChatTeamMessageBuilder
private void ShowTeamMessageInChat(List<ChatMessageDC> allTeamItems2,bool firstTime)
{
try
{
SoundZwischenSpeicher.Clear();
BildZwischenSpeicher.Clear();
DokumentZwischenSpeicher.Clear();
int sx = 0;
var allTeamItems = allTeamItems2.OrderBy(dc => dc.Uhrzeit).ToList();
if (firstTime)
{
if (allTeamItems.Count == itemGrenze)
{
Chat.Items.Add(new KontakMessageBuilder("",
2016-11-14 15:46:54 +01:00
"------------------------ Mehr Nachrichten Vorhanden ----------------------------------",
"", 0, false, true, allTeamItems));
}
else
{
2016-11-15 13:35:31 +01:00
/* Chat.Items.Add(new KontakMessageBuilder("",
2016-11-14 15:46:54 +01:00
"------------------------ Keine weiteren Nachrichten Verfügbar -----------------------",
2016-11-15 13:35:31 +01:00
"", 0, false, false, null));*/
}
}
List<long> x = new List<long>();
foreach (var team in allTeamItems)
{
if (!x.Contains(team.SenderPersonOid.Value))
x.Add(team.SenderPersonOid.Value);
}
x.Sort();
var person = ServiceFacade.DoCustomerServiceSync(s => s.GetPersonsById(x));
foreach (var anzeige in allTeamItems)
{
if (x.Contains(anzeige.SenderPersonOid.Value))
{
//Chat Message dem array übergeben
object[] datenmengen = new object[2];
datenmengen[0] = anzeige;
if (anzeige.SenderPersonOid.Value == BeWoApp.LoggedOnUser.Employee.PersonOid)
{
int zahl = (int) x.IndexOf(anzeige.SenderPersonOid.Value);
2016-11-17 14:46:54 +01:00
if (anzeige.MediaTyp == 0)
{
Chat.Items.Add(new KontakMessageBuilder(person[zahl].FirstName, anzeige.ChatText,
anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value, true, false, null));
}
else
{
2016-11-17 14:46:54 +01:00
if (/*anzeige.MediaDatei != null &&*/ anzeige.MediaTyp == 1)
{
2016-11-17 14:46:54 +01:00
var bild = DecodeBild(anzeige.ImageThumpNail);
if (!BildZwischenSpeicher.ContainsKey(anzeige.ChatText))
BildZwischenSpeicher.Add(anzeige.ChatText, anzeige.MediaDatei);
KontakMessageBuilder builder = new KontakMessageBuilder(person[zahl].FirstName,
anzeige.ChatText, anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value,
2016-11-17 14:46:54 +01:00
true, false, true, false, bild, null, null, false, datenmengen, anzeige.ChatMessagesOid);
datenmengen[1] = builder;
//Bearbeiten ,false,null
Chat.Items.Add(builder);
}
//if (anzeige.SoundDatei != null)
//{
// if (!SoundZwischenSpeicher.ContainsKey(anzeige.ChatText))
// SoundZwischenSpeicher.Add(anzeige.ChatText, anzeige.SoundDatei);
// Chat.Items.Add(new KontakMessageBuilder(person[zahl].FirstName, anzeige.ChatText,anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value, true, true, false,false, null,null,null));
//}
2016-11-17 14:46:54 +01:00
if (anzeige.MediaTyp == 2)
{
if (!DokumentZwischenSpeicher.ContainsKey(anzeige.ChatText))
DokumentZwischenSpeicher.Add(anzeige.ChatText, anzeige.MediaDatei);
KontakMessageBuilder builder = new KontakMessageBuilder(person[zahl].FirstName,
anzeige.ChatText, anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value,
2016-11-17 14:46:54 +01:00
true, false, false, true, null, anzeige.ChatText, null, false,
datenmengen,anzeige.ChatMessagesOid);
datenmengen[1] = builder;
Chat.Items.Add(builder);
}
}
}
else
{
if (sx == 0 && anzeige.IstGelesen != 1)
{
Chat.Items.Add(new KontakMessageBuilder("",
"------------------------ Ungelesene Nachrichten -----------------------", "", 0,
false, false, null));
sx++;
}
int zahl = (int) x.IndexOf(anzeige.SenderPersonOid.Value);
2016-11-17 14:46:54 +01:00
if (anzeige.MediaTyp == 0)
{
Chat.Items.Add(new KontakMessageBuilder(person[zahl].FirstName, anzeige.ChatText,
anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value, false, false, null));
}
else
{
2016-11-17 14:46:54 +01:00
if (/*anzeige.MediaDatei != null &&*/ anzeige.MediaTyp == 1)
{
2016-11-17 14:46:54 +01:00
var bild = DecodeBild(anzeige.ImageThumpNail);
if (!BildZwischenSpeicher.ContainsKey(anzeige.ChatText))
BildZwischenSpeicher.Add(anzeige.ChatText, anzeige.MediaDatei);
KontakMessageBuilder builder = new KontakMessageBuilder(person[zahl].FirstName,
anzeige.ChatText, anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value,
2016-11-17 14:46:54 +01:00
false, false, true, false, bild, null, null, false, datenmengen,anzeige.ChatMessagesOid);
datenmengen[1] = builder;
Chat.Items.Add(builder);
}
//if (anzeige.SoundDatei != null)
//{
// if (!SoundZwischenSpeicher.ContainsKey(anzeige.ChatText))
// SoundZwischenSpeicher.Add(anzeige.ChatText, anzeige.SoundDatei);
// Chat.Items.Add(new KontakMessageBuilder(person[zahl].FirstName, anzeige.ChatText,anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value, false, true, false,false, null,null,null));
//}
2016-11-17 14:46:54 +01:00
if (anzeige.MediaTyp == 2)
{
if (!DokumentZwischenSpeicher.ContainsKey(anzeige.ChatText))
DokumentZwischenSpeicher.Add(anzeige.ChatText, anzeige.MediaDatei);
KontakMessageBuilder builder = new KontakMessageBuilder(person[zahl].FirstName,
anzeige.ChatText, anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value,
2016-11-17 14:46:54 +01:00
false, false, false, true, null, anzeige.ChatText, null, false,
datenmengen,anzeige.ChatMessagesOid);
datenmengen[1] = builder;
Chat.Items.Add(builder);
}
}
}
if (anzeige.IstGelesen != 1)
{
ServiceFacade.DoCustomerServiceSync(
s =>
s.UpdateIstGelesen(anzeige.EmpfängerPersonOid.Value,
anzeige.SenderPersonOid.Value, true));
}
}
}
2016-11-14 15:46:54 +01:00
var lisadst = Chat.Items.Cast<KontakMessageBuilder>().OrderBy(item => item.SendTime).ToList();
Chat.Items.Clear();
foreach (KontakMessageBuilder listItem in lisadst)
{
Chat.Items.Add(listItem);
}
}
catch (Exception e)
{
MessageBox.Show("Es ist ein Fehler aufgetreten ", "Fehler", MessageBoxButton.OK);
}
}
#endregion
2016-06-27 01:45:38 +02:00
}
2016-11-14 15:46:54 +01:00
#region KontaklistBuilder
public class KontaktlistBuilder : INotifyPropertyChanged
2016-06-27 01:45:38 +02:00
{
2016-09-14 13:53:58 +02:00
public KontaktlistBuilder(string name, StatusType statustyp, ImageSource image, long empfaengerid, ChatType typeChat)
2016-06-27 01:45:38 +02:00
{
this.Name = name;
2016-09-14 13:53:58 +02:00
this.StatusTyp = statustyp;
2016-06-27 01:45:38 +02:00
this.Image = image;
this.EmpfaengerOid = empfaengerid;
2016-06-27 01:45:38 +02:00
Receivems = "";
2016-07-29 13:11:34 +02:00
TypeChat = typeChat;
2016-09-14 13:53:58 +02:00
if (statustyp == StatusType.Online)
{
this.Color = new BrushConverter().ConvertFromString("#00ae00") as SolidColorBrush;
2016-09-14 13:53:58 +02:00
}
else if (statustyp == StatusType.Offline)
{
2016-09-16 13:45:25 +02:00
this.Color = new SolidColorBrush(Colors.Red);
2016-09-14 13:53:58 +02:00
}
else
{
2016-09-19 14:21:21 +02:00
this.Color = new SolidColorBrush(Colors.Orange);
2016-09-14 13:53:58 +02:00
}
if (typeChat == ChatType.Team)
{
_colorType = new SolidColorBrush(Colors.DarkViolet);
}
else if (typeChat == ChatType.Klienten)
{
_colorType = new SolidColorBrush(Colors.Blue);
}
else
{
_colorType = new SolidColorBrush(Colors.Green);
}
2016-06-27 01:45:38 +02:00
}
2016-09-14 13:53:58 +02:00
public KontaktlistBuilder(string name, StatusType statustyp, ImageSource image, long empfaengerid, ChatType typeChat, CompactCustomerDC customer)
{
this.Customer = customer;
this.Name = name;
2016-09-14 13:53:58 +02:00
this.StatusTyp = statustyp;
this.Image = image;
this.EmpfaengerOid = empfaengerid;
Receivems = "";
TypeChat = typeChat;
2016-09-14 13:53:58 +02:00
if (statustyp == StatusType.Online)
{
this.Color = new BrushConverter().ConvertFromString("#00ae00") as SolidColorBrush;
2016-09-14 13:53:58 +02:00
}
else if (statustyp == StatusType.Offline)
{
this.Color = new SolidColorBrush(Colors.Red);
}
else
{
2016-09-19 14:21:21 +02:00
this.Color = new SolidColorBrush(Colors.Orange);
2016-09-14 13:53:58 +02:00
}
if (typeChat == ChatType.Team)
{
_colorType = new SolidColorBrush(Colors.DarkViolet);
}
else if (typeChat == ChatType.Klienten)
{
_colorType = new SolidColorBrush(Colors.Blue);
}
else
{
_colorType = new SolidColorBrush(Colors.Green);
}
}
2016-06-27 01:45:38 +02:00
public string Name { get; private set; }
2016-09-14 13:53:58 +02:00
private StatusType _statustyp;
public StatusType StatusTyp { get { return _statustyp; } set { _statustyp = value;
if (_statustyp == StatusType.Online)
{
_color = new BrushConverter().ConvertFromString("#00ae00") as SolidColorBrush;
2016-09-14 13:53:58 +02:00
}
else if (_statustyp == StatusType.Offline)
{
_color = new SolidColorBrush(Colors.Red);
}
else
{
_color = new SolidColorBrush(Colors.Orange);
2016-09-14 13:53:58 +02:00
}
OnPropertyChanged("Lastms"); } }
2016-06-27 01:45:38 +02:00
public ImageSource Image { get; private set; }
public long EmpfaengerOid { get; private set; }
private string _receivems;
public string Receivems { get { return _receivems; } set { _receivems = value; OnPropertyChanged("Receivems"); } }
2016-07-29 13:11:34 +02:00
public ChatType TypeChat { get; set; }
2016-09-14 13:53:58 +02:00
private Brush _color;
public Brush Color
{
get
{
return _color;}
set
{
if (StatusTyp == StatusType.Online)
{
_color = new BrushConverter().ConvertFromString("#00ae00") as SolidColorBrush;
2016-09-14 13:53:58 +02:00
}
else if (StatusTyp == StatusType.Offline)
{
_color = new SolidColorBrush(Colors.Red);
}
else
{
2016-09-19 14:21:21 +02:00
_color = new SolidColorBrush(Colors.Orange);
2016-09-14 13:53:58 +02:00
}
2016-09-14 13:53:58 +02:00
OnPropertyChanged("Color"); }
}
private Brush _colorType;
public Brush ColorType
{
get
{
return _colorType;
}
set
{
if (TypeChat == ChatType.Team)
{
_colorType = new SolidColorBrush(Colors.DarkViolet);
}
else if (TypeChat == ChatType.Klienten)
{
_colorType = new SolidColorBrush(Colors.Blue);
}
else
{
_colorType = new SolidColorBrush(Colors.Green);
}
OnPropertyChanged("ColorType");
}
}
public CompactCustomerDC Customer { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
2016-06-27 01:45:38 +02:00
}
2016-11-14 15:46:54 +01:00
#endregion
#region KontaktMessageBuilder
2016-06-27 01:45:38 +02:00
public class KontakMessageBuilder
{
public KontakMessageBuilder(string username, string message, string sendtime, long messagePersonOid, bool isme, bool loadnext, object loadObject)
2016-06-27 01:45:38 +02:00
{
Username = username;
UserMessage = message;
SendTime = sendtime;
2016-11-17 14:46:54 +01:00
MessagePersonOid = messagePersonOid;
2016-11-14 15:46:54 +01:00
if (messagePersonOid == 0 && !loadnext)
2016-09-14 13:53:58 +02:00
{
2016-11-14 15:46:54 +01:00
ChatColor = new SolidColorBrush(Colors.AliceBlue); //CornflowerBlue
Posi = "Center"; //Center
}else
if (isme)
{
2016-10-05 14:09:15 +02:00
ChatColor = new BrushConverter().ConvertFromString("#ff5e00") as SolidColorBrush;
Posi = "Right";
}
else
{
2016-10-05 14:09:15 +02:00
ChatColor = new BrushConverter().ConvertFromString("#cccccc") as SolidColorBrush;
Posi = "Left";
}
2016-10-21 11:26:42 +02:00
2016-11-14 15:46:54 +01:00
if (loadnext) // <--
{
2016-11-14 15:46:54 +01:00
Posi = "Right";
LoadNextVisibility = Visibility.Visible;
ChatVisibility = Visibility.Collapsed;
LoadObject = loadObject;
2016-11-14 15:46:54 +01:00
MainVisibility = Visibility.Collapsed;
}
else
{
LoadNextVisibility = Visibility.Collapsed;
ChatVisibility = Visibility.Visible;
LoadObject = null;
2016-11-14 15:46:54 +01:00
MainVisibility = Visibility.Visible;
}
SoundVisibility = Visibility.Collapsed;
_pictureVisibility = Visibility.Collapsed;
DokumentVisibility = Visibility.Collapsed;
_herunterladen = Visibility.Collapsed;
2016-09-14 13:53:58 +02:00
2016-06-27 01:45:38 +02:00
}
public KontakMessageBuilder(string username, string message, string sendtime, long messagePersonOid, bool isme,
2016-11-17 14:46:54 +01:00
bool isSoundDatei, bool isPicDatei, bool isDokument, ImageSource source, string fulldokpfad, byte[] dokarray,bool isHerunterladen,object[] herunterladbares,long? chatMessageOid)
2016-10-21 11:26:42 +02:00
{
Username = username;
UserMessage = message;
SendTime = sendtime;
MessagePersonOid = messagePersonOid;
2016-11-17 14:46:54 +01:00
ChatMessageOid = chatMessageOid;
2016-10-21 11:26:42 +02:00
if (isme && messagePersonOid == 0)
{
ChatColor = new SolidColorBrush(Colors.CornflowerBlue);
2016-10-21 11:26:42 +02:00
Posi = "Center";
}
else if (isme)
{
ChatColor = new BrushConverter().ConvertFromString("#ff5e00") as SolidColorBrush;
Posi = "Right";
}
2016-10-21 11:26:42 +02:00
else
{
ChatColor = new BrushConverter().ConvertFromString("#cccccc") as SolidColorBrush;
Posi = "Left";
}
2016-10-21 11:26:42 +02:00
if (isSoundDatei)
{
ChatVisibility = Visibility.Collapsed;
SoundVisibility = Visibility.Visible;
_pictureVisibility = Visibility.Collapsed;
2016-10-21 11:26:42 +02:00
DokumentVisibility = Visibility.Collapsed;
_herunterladen = Visibility.Collapsed;
}
else if (isDokument)
{
ChatVisibility = Visibility.Collapsed;
SoundVisibility = Visibility.Collapsed;
_pictureVisibility = Visibility.Collapsed;
DokumentVisibility = Visibility.Visible;
_herunterladen = Visibility.Collapsed;
}
else if (isPicDatei && source != null)
{
ChatVisibility = Visibility.Collapsed;
SoundVisibility = Visibility.Collapsed;
_pictureVisibility = Visibility.Visible;
DokumentVisibility = Visibility.Collapsed;
_herunterladen = Visibility.Collapsed;
}
else if (isHerunterladen)
{
_herunterladen = Visibility.Visible;
ChatVisibility = Visibility.Collapsed;
SoundVisibility = Visibility.Collapsed;
_pictureVisibility = Visibility.Collapsed;
DokumentVisibility = Visibility.Collapsed;
}
else
{
ChatVisibility = Visibility.Visible;
SoundVisibility = Visibility.Collapsed;
_pictureVisibility = Visibility.Collapsed;
DokumentVisibility = Visibility.Collapsed;
_herunterladen = Visibility.Collapsed;
}
if (source != null)
{
ImageSources = source;
}
//Dokument
2016-11-17 14:46:54 +01:00
object[] array1 = new object[3];
2016-11-17 14:46:54 +01:00
if (fulldokpfad != null && chatMessageOid == 0)
{
Dokpfad = fulldokpfad;
}
2016-11-17 14:46:54 +01:00
else if (chatMessageOid > 0 && fulldokpfad != null)
{
array1[0] = fulldokpfad;
array1[1] = dokarray;
2016-11-17 14:46:54 +01:00
array1[2] = chatMessageOid;
Dokpfad = array1;
}
2016-10-21 11:26:42 +02:00
if (herunterladbares != null)
{
Herunterladbares = herunterladbares;
}
2016-10-21 11:26:42 +02:00
//array übergabe für Sound ermöglichen
SoundArray = null;
LoadNextVisibility = Visibility.Collapsed;
2016-11-14 15:46:54 +01:00
MainVisibility = Visibility.Visible;
}
2016-10-21 11:26:42 +02:00
2016-06-27 01:45:38 +02:00
public string Username { get; private set; }
public string UserMessage { get; private set; }
public string SendTime { get; private set; }
public long MessagePersonOid { get; private set; }
2016-09-14 13:53:58 +02:00
public Brush ChatColor { get; private set; }
public int ChatPosition { get; private set; }
public string Posi { get; private set; }
2016-11-14 15:46:54 +01:00
public Visibility MainVisibility { get; set; }
public Visibility ChatVisibility { get; set; }
public Visibility LoadNextVisibility { get; set; }
public object LoadObject { get; set; }
public Visibility SoundVisibility { get; set; }
private Visibility _pictureVisibility;
public Visibility PictureVisibility { get { return _pictureVisibility; } set { _pictureVisibility = value; OnPropertyChanged("PictureVisibility"); } }
public Visibility DokumentVisibility { get; set; }
2016-10-21 11:26:42 +02:00
public ImageSource ImageSources { get; private set; }
public object Dokpfad { get; private set; }
public byte[] SoundArray { get; private set; }
2016-11-17 14:46:54 +01:00
public long? ChatMessageOid { get; private set; }
private Visibility _herunterladen;
public Visibility Herunterladen
{
get { return _herunterladen; }
set { _herunterladen = value; OnPropertyChanged("Herunterladen"); }
}
public object[] Herunterladbares { get; private set; }
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
2016-10-21 11:26:42 +02:00
2016-06-27 01:45:38 +02:00
}
2016-11-14 15:46:54 +01:00
#endregion
2016-06-27 01:45:38 +02:00
}
2016-09-14 13:53:58 +02:00