Files
BeWoPlaner/BeWo/View/ChatView.xaml.cs
2016-10-21 11:26:42 +02:00

2735 lines
109 KiB
C#

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;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Media;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using BeWo.View.Detail;
using BS.Shared;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.Docking;
using DevExpress.XtraEditors.Senders;
using DevExpress.XtraPrinting.Native;
using DevExpress.XtraPrinting.XamlExport;
using Microsoft.Office.Interop.Word;
using NAudio.Wave;
using Brush = System.Windows.Media.Brush;
using Button = System.Windows.Forms.Button;
using Color = System.Drawing.Color;
using ContextMenu = System.Windows.Controls.ContextMenu;
using GroupBox = System.Windows.Forms.GroupBox;
using Image = System.Windows.Controls.Image;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MenuItem = System.Windows.Controls.MenuItem;
using MessageBox = System.Windows.MessageBox;
using Panel = System.Windows.Forms.Panel;
using Point = System.Windows.Point;
using SelectionMode = System.Windows.Controls.SelectionMode;
using Size = System.Windows.Size;
namespace BeWo.View
{
public partial class ChatView
{
public UserVM ViewModel { get; set; }
public int abr = 0;
protected TcpClient tcpClient;
protected CollectionView view;
protected ChatEmojisView emojiView = null;
protected List<KontaktlistBuilder> ita = new List<KontaktlistBuilder>();
protected List<long> oidspeicher = new List<long>();
protected List<string> teamdc = new List<string>();
protected PropertyGroupDescription groupDescription;
protected bool isOnFocus = false;
//Neu Sound und Datei Versende gedöns usw...
protected WaveIn waveSource = null;
protected WaveFileWriter waveFile = null;
protected SoundPlayer simpleSound = null;
protected Form form1 = null;
//versuch oder | probieren geht über studieren
protected Dictionary<string, byte[]> SoundZwischenSpeicher = new Dictionary<string, byte[]>();
protected Dictionary<string, byte[]> BildZwischenSpeicher = new Dictionary<string, byte[]>();
protected Dictionary<string, byte[]> DokumentZwischenSpeicher = new Dictionary<string, byte[]>();
protected bool sortLabelSwitch = false;
protected ContextMenu context;
public ChatView(String nameinf, String Chatinf, TcpClient tcpClient)
{
InitializeComponent();
rootGroupBox.Header = nameinf;
this.tcpClient = tcpClient;
CloseWindow();
LoadallChatKontakts();
ErstelleContextMenue();
Width = System.Windows.SystemParameters.PrimaryScreenWidth /2;
Height = System.Windows.SystemParameters.PrimaryScreenWidth / 2;
}
public void UpdateTcp(TcpClient tcpClient)
{
this.tcpClient = tcpClient;
}
private void RootGroupBox_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
try
{
DragMove();
}
catch (Exception) { }
}
public void CloseWindow()
{
CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (s, e) =>
{
abr = 1;
//Close();
if (emojiView != null && emojiView.Visibility == Visibility.Visible)
{
emojiView.Visibility = Visibility.Collapsed;
}
Visibility = Visibility.Collapsed;
}));
}
public void SetText(String text, String nameclient, long personoid)
{
try
{
if (AktChatUser.Items.Count != 0)
{
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
if (curItem.EmpfaengerOid == personoid)
{
foreach (var collection in ita)
{
if (collection.EmpfaengerOid == personoid)
collection.Receivems = "";
view.Refresh();
}
curItem.Receivems = "";
Chat.Items.Add(new KontakMessageBuilder(nameclient, text, DateTime.Now.ToString(), personoid,false));
Chat.Items.MoveCurrentToLast();
Chat.ScrollIntoView(Chat.Items.CurrentItem);
}
}
else
{
foreach (var abc in ita)
{
if (abc.EmpfaengerOid == personoid)
{
int x;
bool wasdrin = int.TryParse(abc.Receivems, out x);
if (wasdrin)
abc.Receivems = x++.ToString();
else
abc.Receivems = 1.ToString();
}
}
view.Refresh();
}
}
catch (Exception edf)
{
MessageBox.Show("Beim verarbeiten der Nachricht ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2220 ", MessageBoxButton.OK);
}
}
public void SetTeamAnzahlErhalteneNachricht(long personoid, ChatType type)
{
try
{
foreach (var abc in ita)
{
if (abc.EmpfaengerOid == personoid && abc.TypeChat == type)
{
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 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)
{
try
{
List<long> x = new List<long>();
x.Add(personoid);
var person = ServiceFacade.DoCustomerServiceSync(s => s.GetPersonsById(x));
var a = person[0].Type;
if (a == PersonType.Employee)
{
var mitarbeiter = ServiceFacade.DoEmployeeServiceSync(s => s.GetEmployeeWithPersonOid(personoid));
KontaktlistBuilder konbuild = new KontaktlistBuilder(clientname,StatusType.Online, BuildImg(mitarbeiter.EmployeeImage,ChatType.Mitarbeiter), personoid, ChatType.Mitarbeiter);//"Online"
var zugehorigkeit = ServiceFacade.DoEmployeeServiceSync(s => s.GetTeamOidsByEmployee(personoid));
foreach (var variable in ita)
{
if (konbuild.Name.Equals(variable.Name))
variable.StatusTyp = StatusType.Online;
if (variable.TypeChat == ChatType.Team)
{
foreach (var zug in zugehorigkeit)
{
if (zug.SimpleDescription.Equals(variable.Name))
{
variable.StatusTyp = StatusType.Online;
}
}
}
}
// if (SortCheckBox.IsChecked.Value)
// {
view.Refresh();
// }
// else
// {
// ChatViewName.RefreshUI();
// }
}
else if (a == PersonType.Customer)
{
var klienten = ServiceFacade.DoCustomerServiceSync(s => s.GetCustomerWithPersonOid(personoid));
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"
foreach (var variable in ita)
{
if (konbuild.Name.Equals(variable.Name))
variable.StatusTyp = StatusType.Online;
}
view.Refresh();
}
if (AktChatUser.Items.Count != 0)
{
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
if (curItem.EmpfaengerOid == personoid)
{
curItem.StatusTyp = StatusType.Online;
view.Refresh();
}
}
}
catch (Exception edf)
{
MessageBox.Show("Beim Erweitern der 'Gerade Online' liste ist ein fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2230 ", MessageBoxButton.OK);
}
}
public void RemoveListItem(long clientid)
{
try
{
foreach (var abc in ita)
{
if (abc.EmpfaengerOid == clientid)
{
abc.StatusTyp = StatusType.Offline;
}
}
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;
}
}
view.Refresh();
}
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);
}
}
public void PruefeTeamsObOnline()
{
try
{
foreach (var teamprof in ita)
{
if (teamprof.TypeChat == ChatType.Mitarbeiter)
{
if (teamprof.StatusTyp == StatusType.Online)
{
oidspeicher.Add(teamprof.EmpfaengerOid);
}
}
}
if (oidspeicher.Count == 0)
{
foreach (var tt in ita)
{
if (tt.TypeChat == ChatType.Team)
{
tt.StatusTyp = StatusType.Offline;
}
}
}
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);
}
}
foreach (var tt in ita)
{
if (tt.TypeChat == ChatType.Team && !teamdc.Contains(tt.Name))
{
tt.StatusTyp = StatusType.Offline;
}
}
}
}
catch (Exception edf)
{
MessageBox.Show("Es ist ein Fehler Aufgetreten. Bitte Ruhe Bewahren. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2390 ", MessageBoxButton.OK);
}
}
public Boolean CompareWithListItem(long personid)
{
try
{
foreach (var abc in ita)
{
if (abc.EmpfaengerOid == personid)
{
if (abc.StatusTyp == StatusType.Online)
return true;
}
}
return false;
}
catch (Exception edf)
{
MessageBox.Show("Das Vergleichen mit der User-Liste ist nicht möglich. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2350 ",
MessageBoxButton.OK);
return false;
}
}
public void SetServerStats(String servstats)
{
//ServerStats.Text = servstats;
}
private void SendButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (!AktChatUser.Items.IsEmpty && !Chatbox.Text.Equals("") && isOnFocus)
{
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
SendMessage(curItem.EmpfaengerOid, curItem.TypeChat);
Chat.Items.MoveCurrentToLast();
Chat.ScrollIntoView(Chat.Items.CurrentItem);
Chatbox.Text = "";
if (Chatbox.Text.Equals(""))
{
Chatbox.Text = "Nachricht schreiben";
Chatbox.Foreground = new SolidColorBrush(Colors.DarkGray);
isOnFocus = false;
}
}
else
{
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;
}
}
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;
}
}
}
}
catch (Exception sf)
{
MessageBox.Show("Beim Senden einer Nachricht ist ein Fehler aufgetreten. " + sf.Message + "\n" + sf.StackTrace, "Fehler: 2250 ", MessageBoxButton.OK);
}
}
private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
try
{
if (e.Key == Key.Return)
{
if (!AktChatUser.Items.IsEmpty && !Chatbox.Text.Equals(""))
{
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
SendMessage(curItem.EmpfaengerOid, curItem.TypeChat);
Chat.Items.MoveCurrentToLast();
Chat.ScrollIntoView(Chat.Items.CurrentItem);
Chatbox.Text = "";
}
else
{
if (AktChatUser.Items.IsEmpty)
{
MessageBox.Show("Bitte wählen Sie einen Chatpartner aus.", "Fehler", MessageBoxButton.OK);
}
else if (Chatbox.Text.Equals(""))
{
MessageBox.Show("Sie können keine lehre Nachricht verschicken.", "Fehler", MessageBoxButton.OK);
}
}
}
}
catch (Exception ed)
{
MessageBox.Show("Beim Senden einer Nachricht ist ein Fehler aufgetreten. " + ed.Message + "\n" + ed.StackTrace, "Fehler: 2260 ", MessageBoxButton.OK);
}
}
public void LoadallChatKontakts()
{
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));
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){
Clientlist.Items.Add(new KontaktlistBuilder(list.FirstName + " " + list.LastName, StatusType.Offline,
BuildImg(ServiceFacade.DoEmployeeServiceSync(s => s.GetEmployeeThumbnail(list.EmployeeOid)),ChatType.Mitarbeiter),
list.PersonOid, ChatType.Mitarbeiter));
}
}
foreach (var list in offklienten)
{
Clientlist.Items.Add(new KontaktlistBuilder(list.FirstName + " " + list.LastName, StatusType.Offline,
BuildImg(ServiceFacade.DoCustomerServiceSync(s => s.GetCustomerThumbnail(list.CustomerOid)), ChatType.Klienten),
list.PersonOid, ChatType.Klienten,list));
}
foreach (var a in Clientlist.Items)
{
KontaktlistBuilder cl = (KontaktlistBuilder)a;
ita.Add(cl);
}
Clientlist.Items.Clear();
Clientlist.ItemsSource = ita;
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);
}
}
public void AktualisiereChatKontakt()
{
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));
List<long> idMitarbeitspeicher = new List<long>();
List<long> idteamspeicher = new List<long>();
List<long> idKlientspeicher = new List<long>();
foreach (var teamprof in ita)
{
if (teamprof.TypeChat == ChatType.Klienten)
{
idKlientspeicher.Add(teamprof.EmpfaengerOid);
}
if (teamprof.TypeChat == ChatType.Team)
{
idteamspeicher.Add(teamprof.EmpfaengerOid);
}
if (teamprof.TypeChat == ChatType.Mitarbeiter)
{
idMitarbeitspeicher.Add(teamprof.EmpfaengerOid);
}
}
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));
view.Refresh();
}
if (idteamspeicher.Contains(var.TeamOid))
idteamspeicher.Remove(var.TeamOid);
}
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,
BuildImg(ServiceFacade.DoEmployeeServiceSync(s => s.GetEmployeeThumbnail(var.EmployeeOid)),ChatType.Mitarbeiter),
var.PersonOid, ChatType.Mitarbeiter));
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,
BuildImg(ServiceFacade.DoCustomerServiceSync(s => s.GetCustomerThumbnail(var.CustomerOid)), ChatType.Klienten),
var.PersonOid, ChatType.Klienten,var));
view.Refresh();
}
if (idKlientspeicher.Contains(var.PersonOid))
idKlientspeicher.Remove(var.PersonOid);
}
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);
view.Refresh();
}
if (sortLabelSwitch == true)
{
view.GroupDescriptions.Clear();
groupDescription = new PropertyGroupDescription("TypeChat");
view.GroupDescriptions.Add(groupDescription);
view.Refresh();
}
else
{
view.GroupDescriptions.Clear();
view.Refresh();
}
}
catch (Exception edf)
{
MessageBox.Show("Beim Aktualisieren der Kontakt Liste ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2210 ", MessageBoxButton.OK);
}
}
public void SetAllUserOfflineIfNoInet()
{
foreach (var list in ita)
{
list.StatusTyp = StatusType.Offline;
}
view.Refresh();
}
public void SetUserBeschäftigt(long oid, DataIdentifier type)
{
foreach (var list in ita)
{
if (oid == list.EmpfaengerOid)
{
if (type == DataIdentifier.StatusNotificationBeschäftigt)
list.StatusTyp = StatusType.Beschäftigt;// "Beschäftigt";
else if (type == DataIdentifier.StatusNotificationOnline)
list.StatusTyp = StatusType.Online;// "Online";
else if (type == DataIdentifier.StatusNotificationOffline)
list.StatusTyp = StatusType.Offline; //"Offline"; //<--- testen
}
}
view.Refresh();
}
private void ErstelleContextMenue()
{
try
{
context = new ContextMenu();
MenuItem item1 = new MenuItem();
MenuItem item2 = new MenuItem();
context.Items.Add(item1);
context.Items.Add(item2);
item1.Header = "Dokumentieren";
item1.Visibility = Visibility.Visible;
item1.Click += new RoutedEventHandler(OnChatRightClickMenue);
item2.Header = "Speichern unter";
item2.Visibility = Visibility.Visible;
item2.Click += onChatRightClickItem2;
Image icon = new Image();
//icon.UriSource = new Uri("pack://application:,,,/Ressources/icons/UserHomeBoyDisabled.png");
icon.Source = new BitmapImage(new Uri(@"..\..\Ressources\Icons\ClipboardDisabled.png", UriKind.Relative));
icon.SetSize(new Size(16, 16));
item1.Icon = icon;
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);
}
}
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)
{
SpeichernUnter(1,BildZwischenSpeicher[Item2.UserMessage],Item2.UserMessage);
}
if (Item2.DokumentVisibility == Visibility.Visible)
{
SpeichernUnter(2, DokumentZwischenSpeicher[Item2.UserMessage], Item2.UserMessage);
}
if (Item2.SoundVisibility == Visibility.Visible)
{
SpeichernUnter(3, SoundZwischenSpeicher[Item2.UserMessage], Item2.UserMessage);
}
}
}
else
{
MessageBox.Show("Um eine Datei Speichern zu können, dürfen sie nur eine Chat Nachricht auswählen","Info",MessageBoxButton.OK);
}
}
public void SpeichernUnter(int filterTyp, byte[] datensatz,string dateiname)
{
try
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.FileName = dateiname;
//using (var compressedMs = new MemoryStream(datensatz))
//{
// using (var decompressedMs = new MemoryStream())
// {
// using (var gzs = new BufferedStream(new GZipStream(compressedMs,
// CompressionMode.Decompress)))
// {
// gzs.CopyTo(decompressedMs);
// }
// datensatz = decompressedMs.ToArray();
// }
//}
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();
}
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();
}
}
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>();
KontakMessageBuilder Item;
foreach (Object selecteditem in Chat.SelectedItems)
{
Item = selecteditem as KontakMessageBuilder;
if (Item.MessagePersonOid != 0)
{
itemListe.Add(Item);
}
}
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);
//newView.Activate();
newView.ShowDialog();
Chat.SelectedIndex = -1;
}
else
{
MessageBox.Show("Sie können nur Klienten Nachrichten Dokumentieren.", "Info", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
}
else
{
MessageBox.Show("Sie müssen für diese art von Dokumentation Chat-Nachrichten auswählen.", "Info", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
itemListe.Clear();
}
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);
}
}
}
catch (Exception edf)
{
MessageBox.Show("Beim Setzen eines neuen Statuses ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2270 ", MessageBoxButton.OK);
}
}
public void SendUserStatus(DataIdentifier identi)
{
try
{
NetworkStream serverStream = tcpClient.GetStream();
String abc = "";
Packet a = new Packet();
byte[] outStream = a.GetDataStream(BeWoApp.LoggedOnUser.Employee.PersonOid, 0,
BeWoApp.LoggedOnUser.LoginName, abc, identi, BeWoApp.Tenant, false);
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
}
catch (Exception edf)
{
Console.WriteLine(edf.StackTrace);
}
}
public void SetListBoxSelection(long personoid, ChatType type)
{
try
{
context.IsOpen = false;
foreach (var blub in ita)
{
if (blub.EmpfaengerOid == personoid && blub.TypeChat == type)
{
AktChatUser.Items.Clear();
Chat.Items.Clear();
blub.Receivems = "";
if (blub.TypeChat == ChatType.Klienten)
{
AktChatUser.Items.Add(new KontaktlistBuilder(blub.Name, blub.StatusTyp, blub.Image, blub.EmpfaengerOid, blub.TypeChat, blub.Customer));
}
else
{
AktChatUser.Items.Add(new KontaktlistBuilder(blub.Name, blub.StatusTyp, blub.Image, blub.EmpfaengerOid, blub.TypeChat));
}
LoadChatMessagefromDB(BeWoApp.LoggedOnEmployee.PersonOid.Value, blub.EmpfaengerOid, blub);
if (blub.TypeChat == ChatType.Klienten)
{
context.Visibility = Visibility.Visible;
Chat.SelectionMode = SelectionMode.Extended;
Chat.Focusable = true;
}
else
{
context.Visibility = Visibility.Collapsed;
Chat.SelectionMode = SelectionMode.Single;
Chat.Focusable = false;
}
}
}
Chat.Items.MoveCurrentToLast();
Chat.ScrollIntoView(Chat.Items.CurrentItem);
}
catch (Exception edf)
{
MessageBox.Show("Fehler siehe Fehlercode. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2370", MessageBoxButton.OK);
}
}
private void ListBoxSelectedIndexChanged(object sender, System.EventArgs e)
{
KontaktlistBuilder curItem;
try
{
context.IsOpen = false;
if (!Clientlist.Items.IsEmpty)
{
curItem = (KontaktlistBuilder)Clientlist.SelectedItem;
Chat.Items.Clear();
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 = "";
view.Refresh();
if (curItem.TypeChat == ChatType.Klienten)
{
context.Visibility = Visibility.Visible;
Chat.SelectionMode = SelectionMode.Extended;
Chat.Focusable = true;
}
else
{
context.Visibility = Visibility.Collapsed;
Chat.SelectionMode = SelectionMode.Single;
Chat.Focusable = false;
}
}
}
}
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);
}
}
public ImageSource BuildImg(Byte[] c ,ChatType x)
{
try
{
if (c != null)
{
var biImg = new BitmapImage();
using (var ms = new MemoryStream(c))
{
biImg.BeginInit();
biImg.StreamSource = ms;
biImg.CacheOption = BitmapCacheOption.OnLoad;
biImg.EndInit();
}
return biImg;
}
else
{
//return null;
//return new BitmapImage(new Uri(@"..\..\Ressources\Icons\UserHomeBoyDisabled.png", UriKind.Relative));
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;
}
//return new ImageSource new BitmapImage(new Uri(@"..\..\Ressources\Icons\UserHomeBoyDisabled.png", UriKind.Relative));
//(ImageSource)
// new ImageSourceConverter().ConvertFromString(
// "../../Ressources/Icons/UserHomeBoyDisabled.png");
}
}
catch (Exception edf)
{
MessageBox.Show("Beim Aufbauen der Profilbilder ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2290 ", MessageBoxButton.OK);
return null;
}
}
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)
{
try
{
string msg = Chatbox.Text;
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, msg, DateTime.Now.ToString(), BeWoApp.LoggedOnUser.Employee.PersonOid,true));
if (tcpClient.Connected)
{
NetworkStream serverStream = tcpClient.GetStream();
Packet a = new Packet();
byte[] outStream;
if (type == ChatType.Team)
{
outStream = a.GetDataStream(BeWoApp.LoggedOnUser.Employee.PersonOid, empfängeroid, BeWoApp.LoggedOnUser.LoginName, msg, DataIdentifier.Team, BeWoApp.Tenant, false);
}
else
{
outStream = a.GetDataStream(BeWoApp.LoggedOnUser.Employee.PersonOid, empfängeroid, BeWoApp.LoggedOnUser.LoginName, msg, 0, BeWoApp.Tenant, false);
}
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
// ServerStats.Text = "Nachricht erfolgreich gesendet";
}
else
{
SaveChatMessageinDB(BeWoApp.LoggedOnUser.Employee.PersonOid, empfängeroid, msg, false, type);
}
}
catch (Exception xe)
{
if (tcpClient.Connected)
{
MessageBox.Show("Beim Senden einer Nachricht zum Server ist ein Fehler aufgetreten. " + xe.Message + "\n" + xe.StackTrace,
"Fehler: 2300 ", MessageBoxButton.OK);
//ServerStats.Text = "Fehler: Die Nachricht konnte nicht gesendet werden.";
}
}
}
public void SaveChatMessageinDB(long senderoid, long empfangid, string message, bool istZugestellt, ChatType type)
{
try
{
if (type == ChatType.Team)
{
ServiceFacade.DoOperationsServiceSync(s => s.CreateNewChatMessagesDC(senderoid, empfangid, message, istZugestellt, empfangid));
}
else
{
ServiceFacade.DoOperationsServiceSync(s => s.CreateNewChatMessagesDC(senderoid, empfangid, message, istZugestellt, 0));
}
}
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);
}
}
public void LoadChatMessagefromDB(long senderoid, long empfaengerOid, KontaktlistBuilder Curitem)
{
try
{
SoundZwischenSpeicher.Clear();
BildZwischenSpeicher.Clear();
DokumentZwischenSpeicher.Clear();
if (Curitem.TypeChat == ChatType.Team)
{
int sx = 0;
var allTeamItems =
ServiceFacade.DoCustomerServiceSync(
s => s.FindAllChatMessagesFromTeam(senderoid, empfaengerOid));
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))
{
if (anzeige.SenderPersonOid.Value == BeWoApp.LoggedOnUser.Employee.PersonOid)
{
int zahl = (int)x.IndexOf(anzeige.SenderPersonOid.Value);
if (anzeige.SoundDatei == null && anzeige.BildDatei == null && anzeige.DokuDatei == null)
{
Chat.Items.Add(new KontakMessageBuilder(person[zahl].FirstName, anzeige.ChatText,anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value, true));
}
else
{
if (anzeige.BildDatei != null)
{
var bild = DecodeBild(anzeige.BildDatei);
if (!BildZwischenSpeicher.ContainsKey(anzeige.ChatText))
BildZwischenSpeicher.Add(anzeige.ChatText, anzeige.BildDatei);
Chat.Items.Add(new KontakMessageBuilder(person[zahl].FirstName, anzeige.ChatText,anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value, true, false, true,false, bild));
}
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));
}
if (anzeige.DokuDatei != null)
{
if (!DokumentZwischenSpeicher.ContainsKey(anzeige.ChatText))
DokumentZwischenSpeicher.Add(anzeige.ChatText, anzeige.DokuDatei);
Chat.Items.Add(new KontakMessageBuilder(person[zahl].FirstName, anzeige.ChatText,anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value, true, false,false, true, null));
}
}
}
else
{
if (sx == 0 && anzeige.IstGelesen != 1 )
{
Chat.Items.Add(new KontakMessageBuilder("","------------------------ Ungelesene Nachrichten -----------------------", "", 0,false));
sx++;
}
int zahl = (int)x.IndexOf(anzeige.SenderPersonOid.Value);
if (anzeige.SoundDatei == null && anzeige.BildDatei == null && anzeige.DokuDatei == null)
{
Chat.Items.Add(new KontakMessageBuilder(person[zahl].FirstName, anzeige.ChatText,
anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value, false));
}
else
{
if (anzeige.BildDatei != null)
{
var bild = DecodeBild(anzeige.BildDatei);
if (!BildZwischenSpeicher.ContainsKey(anzeige.ChatText))
BildZwischenSpeicher.Add(anzeige.ChatText, anzeige.BildDatei);
Chat.Items.Add(new KontakMessageBuilder(person[zahl].FirstName, anzeige.ChatText,anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value, false, false, true,false, bild));
}
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));
}
if (anzeige.DokuDatei != null)
{
if (!DokumentZwischenSpeicher.ContainsKey(anzeige.ChatText))
DokumentZwischenSpeicher.Add(anzeige.ChatText, anzeige.DokuDatei);
Chat.Items.Add(new KontakMessageBuilder(person[zahl].FirstName, anzeige.ChatText,anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value, false, false, false, true, null));
}
}
}
if (anzeige.IstGelesen != 1)
{
ServiceFacade.DoCustomerServiceSync(s => s.UpdateIstGelesen(anzeige.EmpfängerPersonOid.Value,anzeige.SenderPersonOid.Value,true));
}
}
}
}
else
{
var allitems =
ServiceFacade.DoCustomerServiceSync(
s => s.FindAllChatMessages(senderoid, empfaengerOid));
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)
{
if (list.IstGelesen == 1 && (list.TeamOid == null || list.TeamOid == 0))
{
if (list.SenderPersonOid == senderoid)
{
if (list.SoundDatei == null && list.BildDatei == null && list.DokuDatei == null)
{
Chat.Items.Add(new KontakMessageBuilder(person[0].FirstName, list.ChatText,
list.Uhrzeit.ToString(), senderoid,true));
}
else
{
if (list.BildDatei != null)
{
var bild = DecodeBild(list.BildDatei);
if (!BildZwischenSpeicher.ContainsKey(list.ChatText))
BildZwischenSpeicher.Add(list.ChatText,list.BildDatei);
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText, list.Uhrzeit.ToString(), senderoid, true, false, true, false, bild));
}
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));
}
if (list.DokuDatei != null)
{
if (!DokumentZwischenSpeicher.ContainsKey(list.ChatText))
DokumentZwischenSpeicher.Add(list.ChatText,list.DokuDatei);
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText, list.Uhrzeit.ToString(), senderoid, true, false, false, true, null));
}
}
}
else
{
if (list.SoundDatei == null && list.BildDatei == null && list.DokuDatei == null)
{
Chat.Items.Add(new KontakMessageBuilder(person[1].FirstName, list.ChatText,
list.Uhrzeit.ToString(), empfaengerOid, false));
}
else
{
if (list.BildDatei != null)
{
var bild = DecodeBild(list.BildDatei);
if (!BildZwischenSpeicher.ContainsKey(list.ChatText))
BildZwischenSpeicher.Add(list.ChatText, list.BildDatei);
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText, list.Uhrzeit.ToString(), empfaengerOid, false, false, true, false, bild));
}
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));
}
if (list.DokuDatei != null)
{
if (!DokumentZwischenSpeicher.ContainsKey(list.ChatText))
DokumentZwischenSpeicher.Add(list.ChatText, list.DokuDatei);
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText, list.Uhrzeit.ToString(), empfaengerOid, false, false, false, true, null));
}
}
}
}
else
{
if (list.TeamOid == null || list.TeamOid == 0)
{
if (list.SenderPersonOid == senderoid)
{
if (list.SoundDatei == null && list.BildDatei == null && list.DokuDatei == null)
{
Chat.Items.Add(new KontakMessageBuilder(person[0].FirstName, list.ChatText,
list.Uhrzeit.ToString(), senderoid, true));
}
else
{
if (list.BildDatei != null)
{
var bild = DecodeBild(list.BildDatei);
if (!BildZwischenSpeicher.ContainsKey(list.ChatText))
BildZwischenSpeicher.Add(list.ChatText, list.BildDatei);
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText, list.Uhrzeit.ToString(), senderoid, true, false, true, false, bild));
}
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));
}
if (list.DokuDatei != null)
{
if(!DokumentZwischenSpeicher.ContainsKey(list.ChatText))
DokumentZwischenSpeicher.Add(list.ChatText, list.DokuDatei);
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText, list.Uhrzeit.ToString(), senderoid, true, false, false, true, null));
}
}
}
else
{
if (i == 0)
{
Chat.Items.Add(new KontakMessageBuilder("", "------------------------ Ungelesene Nachrichten -----------------------", "", 0,false));
i++;
}
if (list.SoundDatei == null && list.BildDatei == null && list.DokuDatei == null)
{
Chat.Items.Add(new KontakMessageBuilder(person[1].FirstName, list.ChatText,
list.Uhrzeit.ToString(), empfaengerOid, false));
}
else
{
if (list.BildDatei != null)
{
var bild = DecodeBild(list.BildDatei);
if (!BildZwischenSpeicher.ContainsKey(list.ChatText))
BildZwischenSpeicher.Add(list.ChatText, list.BildDatei);
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText, list.Uhrzeit.ToString(), empfaengerOid, false, false, true, false, bild));
}
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));
}
if (list.DokuDatei != null)
{
if (!DokumentZwischenSpeicher.ContainsKey(list.ChatText))
DokumentZwischenSpeicher.Add(list.ChatText,list.DokuDatei);
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, list.ChatText, list.Uhrzeit.ToString(), empfaengerOid, false, false, false, true, null));
}
}
}
}
}
}
ServiceFacade.DoCustomerServiceSync(s => s.UpdateIstGelesen(empfaengerOid, senderoid, true));
}
}
catch (Exception edf)
{
MessageBox.Show("Beim Laden einer Nachricht aus der Datenbank ist ein Fehler aufgetreten. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2320 ", MessageBoxButton.OK);
}
}
private void OnFocus(object sender, EventArgs e)
{
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;
}
}
}
catch (Exception edf)
{
MessageBox.Show("Fehler beim Fokusieren der Nachrichten Leiste. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2330 ", MessageBoxButton.OK);
}
}
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));
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.Collapsed;
}
else
{
emojiView.Visibility = Visibility.Visible;
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;
}
}
}
private void Chatbox_OnTextChanged(object sender, TextChangedEventArgs e)
{
/* if (ChatViewName.Height < 850 && Chatbox.LineCount >= 3)
{
ChatViewName.Height = ChatViewName.Height + 50;
}else
if(Chatbox.LineCount <=2)
{
ChatViewName.Height = 800;
}*/
}
public void PruefeInDbObNeueNachrichtenVerfügbar()
{
try
{
ServiceFacade.DoOperationsServiceAsync(
s => s.FindUnreadChatMessagesForRecipient(BeWoApp.LoggedOnEmployee.PersonOid.Value),
m =>
{
Dispatcher.Invoke(
DispatcherPriority.Normal,
(ThreadStart) delegate
{
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();
}
else if (aktChatPersons.EmpfaengerOid == ChatMessage.TeamOid && ChatMessage.SenderPersonOid != aktChatPersons.EmpfaengerOid)
{
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 SortCheckBox_OnChecked(object sender, RoutedEventArgs e)
{
//AktualisiereChatKontakt();
}
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);
}
}
//################# Lade ein Dokument in das programm #####################################################
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
string file = "";
string text = "";
int size = -1;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Alle Dateien|*.*"+
"|Office Dokumente |*.doc;*.xls;*.ppt;*.txt"+
"|Bilder |*.jpg;*.png;*.jpeg;*.jpe;*.gif;*.bmp";
DialogResult result = openFileDialog1.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK) // result beinhaltet ob etwas ausegwählt wurde oder nicht.
{
file = openFileDialog1.FileName;
try
{
text = File.ReadAllText(file);
size = text.Length;
// Bitmap image1 = (Bitmap) System.Drawing.Image.FromFile(file,true);
// Bitmap verschicken wie?? das wird lustig hehe. und nicht nur die sondern auch die files.
}
catch (IOException)
{
}
}
Console.WriteLine(size);
Console.WriteLine(file);
Console.WriteLine(result);
}
IWavePlayer waveOutDevice = null;
AudioFileReader audioFileReader = null;
// Code zum Abspielen von Sounds
private void PlayAufnahme_OnClick(object sender, RoutedEventArgs e)
{
Console.WriteLine("Abspielen Aufnahme");
// DisplayVisualTree(this, 1);
Image img = FindChildControl<Image>(this, "image") as Image;
img.Source = new BitmapImage(new Uri(@"..\..\Ressources\Icons\ClipboardDisabled.png", UriKind.Relative));
// Button btn = (Button) sender;
//btn.Image = new Bitmap("pack://application:,,,/Ressources/icons/UserHomeBoyDisabled.png");
if (waveOutDevice == null)
{
//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();
}
else
{
//simpleSound.Stop();
//simpleSound = null;
waveOutDevice.Stop();
audioFileReader.Dispose();
waveOutDevice.Dispose();
waveOutDevice = null;
audioFileReader = null;
}
Console.WriteLine("Abspielen Beendet");
}
//########################## Test Versuche zu lern zwecken ######################################
private void DisplayVisualTree(DependencyObject control, int indent)
{
/* string tab = "";
for (int i = 1; i <= indent; i++)
tab += "t";
// FrameworkElement ctrl = control as FrameworkElement;
Console.WriteLine("{0}, {1}",
tab ,control);*/
int childNumber = VisualTreeHelper.GetChildrenCount(control);
for (int i = 0; i < childNumber; i++)
{
DependencyObject child = VisualTreeHelper.GetChild(control, i);
DisplayVisualTree(child, indent + 1);
}
}
private DependencyObject FindChildControl<T>(DependencyObject control, string ctrlName)
{
int childNumber = VisualTreeHelper.GetChildrenCount(control);
for (int i = 0; i < childNumber; i++)
{
DependencyObject child = VisualTreeHelper.GetChild(control, i);
FrameworkElement fe = child as FrameworkElement;
// Not a framework element or is null
if (fe == null) return null;
if (child is T && fe.Name == ctrlName)
{
// Found the control so return
return child;
}
else
{
// Not found it - search children
DependencyObject nextLevel = FindChildControl<T>(child, ctrlName);
if (nextLevel != null)
return nextLevel;
}
}
return null;
}
//#################################################################################################
private void Sound_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (AktChatUser.Items.Count != 0)
{
if (WaveIn.DeviceCount != 0)
{
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);
}
}
else
{
// MessageBox.Show("Bitte Schließen sie ein Microfon an, um diese Funktion nutzen zu können.", "Kein Microfon vorhanden.",MessageBoxButton.OK);
}
}
else
{
MessageBox.Show("Bitte Wählen sie einen Chat Partner aus","Info",MessageBoxButton.OK);
}
}
private void Sound_OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (AktChatUser.Items.Count != 0)
{
if (WaveIn.DeviceCount != 0)
{
waveSource.StopRecording();
}
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
string filename = Path.GetFileName(@"C:\Temp\WOMBO.mp3");
// Sound name muss übergeben werden bzw eigentlich garnicht weil wir ja sound aufnehmen und da kann dann der name und das aufnahme datum hin
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName,filename, DateTime.Now.ToString(), curItem.EmpfaengerOid, true, true, false, false,null));
//waveSource in byte[] umwandeln und in db speichern
FileStream fileStream = new FileStream(@"C:\Temp\WOMBO.mp3", FileMode.Open, FileAccess.Read);
//versuchen geht über studieren
byte[] soundBytes = new Byte[fileStream.Length];
fileStream.Read(soundBytes, 0, soundBytes.Length);
//byte[] compressedbuffer = null;
//using (var buffercompress = new MemoryStream())
//{
// using (var gzs = new BufferedStream(new GZipStream(buffercompress,
// CompressionMode.Compress)))
// {
// gzs.Write(soundBytes, 0, soundBytes.Length);
// }
// compressedbuffer = buffercompress.ToArray();
//}
SendSpeziallToServer(curItem.EmpfaengerOid, curItem.TypeChat, filename, soundBytes, null, null);
Chat.Items.MoveCurrentToLast();
Chat.ScrollIntoView(Chat.Items.CurrentItem);
//Erstelle Hier den Bereich der im Chat dann die Sounddatei enthält um diese abspielen zu können.
}
}
//testen
private void waveSource_DataAvailable(object sender, WaveInEventArgs e)
{
if (waveFile != null)
{
waveFile.Write(e.Buffer, 0, e.BytesRecorded);
waveFile.Flush();
}
}
//testen
private void waveSource_RecordingStopped(object sender, StoppedEventArgs e)
{
if (waveSource != null)
{
waveSource.Dispose();
waveSource = null;
}
if (waveFile != null)
{
waveFile.Dispose();
waveFile = null;
}
}
//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(250, 100);
form1.FormBorderStyle = FormBorderStyle.FixedSingle;
form1.Text = "Media";
Button btnPic = new Button();
btnPic.Text = "Bild";
btnPic.Size = new System.Drawing.Size(120, 45);
btnPic.TextAlign = ContentAlignment.MiddleCenter;
btnPic.Click += buttonPic_Click;
Button btnDok = new Button();
btnDok.Text = "Dokument";
btnDok.Size = new System.Drawing.Size(120, 45);
btnDok.Location = new System.Drawing.Point(125,0);
btnDok.TextAlign = ContentAlignment.MiddleCenter;
btnDok.Click += buttonDok_Click;
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 buttonPic_Click(object s,EventArgs x)
{
bool format = false;
try
{
string file = "";
string text = "";
int size = -1;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Bilder |*.jpg;*.png;*.jpeg;*.jpe;*.gif;*.bmp";
DialogResult result = openFileDialog1.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
format = true;
file = openFileDialog1.FileName;
string filename = Path.GetFileName(file);
ImageSource imageSource = new BitmapImage(new Uri(file));
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, filename, DateTime.Now.ToString(), curItem.EmpfaengerOid, true, false, true, false, imageSource));
if (form1 != null)
{
form1.Close();
}
Chat.Items.MoveCurrentToLast();
Chat.ScrollIntoView(Chat.Items.CurrentItem);
// Bereich zum Speichern der Fotos in die Datenbank
FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read);
BitmapImage i = new BitmapImage();
i.BeginInit();
i.StreamSource = fileStream;
i.EndInit();
byte[] bits = ImageToByte(i);
//byte[] compressedbuffer = null;
//using (var buffercompress = new MemoryStream())
//{
// using (var gzs = new BufferedStream(new GZipStream(buffercompress,
// CompressionMode.Compress)))
// {
// gzs.Write(bits, 0, bits.Length);
// }
// compressedbuffer = buffercompress.ToArray();
//}
SendSpeziallToServer(curItem.EmpfaengerOid, curItem.TypeChat, filename, null, null, bits);
}
}
catch (Exception e)
{
if(format)
MessageBox.Show("Bitte wählen sie das richtige Dateiformat aus. ","Fehler: Falsches Dateiformat",MessageBoxButton.OK);
else
MessageBox.Show("Unbekannter Fehler: " + e.Message + "\n" + e.StackTrace, "Fehler: 2394 ", MessageBoxButton.OK);
}
}
//#################################### Extra für Speziall Messages Erstellt #########################################################################
private void SendSpeziallToServer(long empfängeroid,ChatType type,string filename,byte[] sound, byte[] doku, byte[] bild)
{
if (tcpClient.Connected)
{
NetworkStream serverStream = tcpClient.GetStream();
Packet a = new Packet();
byte[] outStream;
if (type == ChatType.Team)
{
outStream = a.GetDataStream(BeWoApp.LoggedOnUser.Employee.PersonOid, empfängeroid, BeWoApp.LoggedOnUser.LoginName, filename, DataIdentifier.Team, BeWoApp.Tenant, false/*,sound,doku,bild*/); // 3 werte
}
else
{
outStream = a.GetDataStream(BeWoApp.LoggedOnUser.Employee.PersonOid, empfängeroid, BeWoApp.LoggedOnUser.LoginName, filename,0, BeWoApp.Tenant, false/*,sound,doku,bild*/ );
}
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
}
else
{
SaveChatSpeziallMessageinDB(type, BeWoApp.LoggedOnUser.Employee.PersonOid, empfängeroid, filename, false, sound,doku,bild);
}
}
//fertig
private void SaveChatSpeziallMessageinDB(ChatType type,long senderoid,long empfangid,string message, bool istZugestellt,byte[] sound, byte[] doku, byte[] bild)
{
if (type == ChatType.Team)
{
ServiceFacade.DoOperationsServiceSync(s => s.CreateNewSpeziallChatMessagesDC(senderoid, empfangid, message, istZugestellt, empfangid, sound, doku, bild));
}
else
{
ServiceFacade.DoOperationsServiceSync(s => s.CreateNewSpeziallChatMessagesDC(senderoid, empfangid, message, istZugestellt, 0, sound, doku, bild));
}
}
//fertig
public Byte[] ImageToByte(BitmapImage imageSource)
{
var encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(imageSource));
using (var ms = new MemoryStream())
{
encoder.Save(ms);
return ms.ToArray();
}
}
//fertig
private ImageSource DecodeBild(byte[] byteVal)
{
try
{
//using (var compressedMs = new MemoryStream(byteVal))
//{
// using (var decompressedMs = new MemoryStream())
// {
// using (var gzs = new BufferedStream(new GZipStream(compressedMs,
// CompressionMode.Decompress)))
// {
// gzs.CopyTo(decompressedMs);
// }
// byteVal = decompressedMs.ToArray();
// }
//}
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();
}
return image;
}
catch (Exception ex)
{
return null;
}
}
//####################################################################################################################################################
public void buttonDok_Click(object s, EventArgs x)
{
try
{
string file = "";
string text = "";
int size = -1;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Office Dokumente |*.doc;*.xls;*.ppt;*.txt";
DialogResult result = openFileDialog1.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
file = openFileDialog1.FileName;
string filename = Path.GetFileName(file);
//text = File.ReadAllText(file);
size = text.Length;
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
Chat.Items.Add(new KontakMessageBuilder(BeWoApp.LoggedOnUser.Employee.FirstName, filename, DateTime.Now.ToString(), curItem.EmpfaengerOid, true, false, false, true, null));
// Maximum liegt hier bei 2GB
byte[] buffer = null;
using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
{
buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int)fs.Length);
}
//byte[] compressedbuffer= null;
//using (var buffercompress = new MemoryStream())
//{
// using (var gzs = new BufferedStream(new GZipStream(buffercompress,
// CompressionMode.Compress)))
// {
// gzs.Write(buffer, 0, buffer.Length);
// }
// compressedbuffer = buffercompress.ToArray();
//}
SendSpeziallToServer(curItem.EmpfaengerOid, curItem.TypeChat, filename, null, buffer, null);
Chat.Items.MoveCurrentToLast();
Chat.ScrollIntoView(Chat.Items.CurrentItem);
if (form1 != null)
{
form1.Close();
}
}
Console.WriteLine(size);
Console.WriteLine(file);
Console.WriteLine(result);
}
catch (Exception e)
{
Console.WriteLine("Fehler: "+ e.StackTrace);
}
}
//###########################################################################################################
private void OpenDokument_OnClick(object sender, RoutedEventArgs e)
{
Process.Start(@"C:\Users\LoginDaten.txt");
}
private void ChatView_OnStateChanged(object sender, EventArgs e)
{
if (this.WindowState == WindowState.Maximized)
{
this.WindowState = WindowState.Normal;
}
}
}
public class KontaktlistBuilder : INotifyPropertyChanged
{
public KontaktlistBuilder(string name, StatusType statustyp, ImageSource image, long empfaengerid, ChatType typeChat)
{
this.Name = name;
this.StatusTyp = statustyp;
this.Image = image;
this.EmpfaengerOid = empfaengerid;
Receivems = "";
TypeChat = typeChat;
if (statustyp == StatusType.Online)
{
this.Color = new BrushConverter().ConvertFromString("#00ae00") as SolidColorBrush;//new SolidColorBrush(Colors.Green);
//Color.Opacity = 0.5;
}
else if (statustyp == StatusType.Offline)
{
this.Color = new SolidColorBrush(Colors.Red);
}
else
{
this.Color = new SolidColorBrush(Colors.Orange);
}
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);
}
}
public KontaktlistBuilder(string name, StatusType statustyp, ImageSource image, long empfaengerid, ChatType typeChat, CompactCustomerDC customer)
{
this.Customer = customer;
this.Name = name;
this.StatusTyp = statustyp;
this.Image = image;
this.EmpfaengerOid = empfaengerid;
Receivems = "";
TypeChat = typeChat;
if (statustyp == StatusType.Online)
{
this.Color = new BrushConverter().ConvertFromString("#00ae00") as SolidColorBrush;//new SolidColorBrush(Colors.Green);
}
else if (statustyp == StatusType.Offline)
{
this.Color = new SolidColorBrush(Colors.Red);
}
else
{
this.Color = new SolidColorBrush(Colors.Orange);
}
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);
}
}
public string Name { get; private set; }
private StatusType _statustyp;
public StatusType StatusTyp { get { return _statustyp; } set { _statustyp = value;
if (_statustyp == StatusType.Online)
{
_color = new BrushConverter().ConvertFromString("#00ae00") as SolidColorBrush;//new SolidColorBrush(Colors.Green);
}
else if (_statustyp == StatusType.Offline)
{
_color = new SolidColorBrush(Colors.Red);
}
else
{
_color = new SolidColorBrush(Colors.Orange); //Orange
}
OnPropertyChanged("Lastms"); } }
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"); } }
public ChatType TypeChat { get; set; }
private Brush _color;
public Brush Color
{
get
{
return _color;}
set
{
if (StatusTyp == StatusType.Online)
{
_color = new BrushConverter().ConvertFromString("#00ae00") as SolidColorBrush;//new SolidColorBrush(Colors.Green);
}
else if (StatusTyp == StatusType.Offline)
{
_color = new SolidColorBrush(Colors.Red);
}
else
{
_color = new SolidColorBrush(Colors.Orange);
}
//_color = value;
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);
}
//_color = value;
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));
}
}
public class KontakMessageBuilder
{
public KontakMessageBuilder(string username, string message, string sendtime, long messagePersonOid, bool isme)
{
Username = username;
UserMessage = message;
SendTime = sendtime;
MessagePersonOid = messagePersonOid;
if (isme && messagePersonOid == 0)
{
ChatColor = new SolidColorBrush(Colors.Lavender);
Posi = "Center";
}else
if (isme)
{
//ChatColor = new SolidColorBrush(Colors.DarkOrange);
ChatColor = new BrushConverter().ConvertFromString("#ff5e00") as SolidColorBrush;
Posi = "Right";
}
else
{
//ChatColor = new SolidColorBrush(Colors.LightGray);
ChatColor = new BrushConverter().ConvertFromString("#cccccc") as SolidColorBrush;
Posi = "Left";
}
ChatVisibility = Visibility.Visible;
SoundVisibility = Visibility.Collapsed;
PictureVisibility = Visibility.Collapsed;
DokumentVisibility = Visibility.Collapsed;
}
//########################################### Konstrucktor für Sound Datei und Picture :) ################################################
public KontakMessageBuilder(string username, string message, string sendtime, long messagePersonOid, bool isme, bool isSoundDatei, bool isPicDatei, bool isDokument,ImageSource source)
{
Username = username;
UserMessage = message;
SendTime = sendtime;
MessagePersonOid = messagePersonOid;
if (isme && messagePersonOid == 0)
{
ChatColor = new SolidColorBrush(Colors.Lavender);
Posi = "Center";
}
else
if (isme)
{
//ChatColor = new SolidColorBrush(Colors.DarkOrange);
ChatColor = new BrushConverter().ConvertFromString("#ff5e00") as SolidColorBrush;
Posi = "Right";
}
else
{
//ChatColor = new SolidColorBrush(Colors.LightGray);
ChatColor = new BrushConverter().ConvertFromString("#cccccc") as SolidColorBrush;
Posi = "Left";
}
if (isSoundDatei)
{
ChatVisibility = Visibility.Collapsed;
SoundVisibility = Visibility.Visible;
PictureVisibility = Visibility.Collapsed;
DokumentVisibility = Visibility.Collapsed;
ImageSources = null;
}else
if (isDokument)
{
ChatVisibility = Visibility.Collapsed;
SoundVisibility = Visibility.Collapsed;
PictureVisibility = Visibility.Collapsed;
DokumentVisibility = Visibility.Visible;
ImageSources = null;
}else
if (isPicDatei && source != null)
{
ChatVisibility = Visibility.Collapsed;
SoundVisibility = Visibility.Collapsed;
PictureVisibility = Visibility.Visible;
DokumentVisibility = Visibility.Collapsed;
ImageSources = source;
}
else
{
ChatVisibility = Visibility.Visible;
SoundVisibility = Visibility.Collapsed;
PictureVisibility = Visibility.Collapsed;
DokumentVisibility = Visibility.Collapsed;
ImageSources = null;
}
}
//###########################################################################################################################################
public string Username { get; private set; }
public string UserMessage { get; private set; }
public string SendTime { get; private set; }
public long MessagePersonOid { get; private set; }
public Brush ChatColor { get; private set; }
public int ChatPosition { get; private set; }
public string Posi { get; private set; }
public Visibility ChatVisibility { get; private set; }
public Visibility SoundVisibility { get; private set; }
public Visibility PictureVisibility { get; private set; }
public Visibility DokumentVisibility { get; private set; }
public ImageSource ImageSources { get; private set; }
}
}