1176 lines
45 KiB
C#
1176 lines
45 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.IO;
|
|
using System.Text;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Media.Imaging;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using DevExpress.Xpf.Core;
|
|
using DevExpress.XtraPrinting.Native;
|
|
using DevExpress.XtraPrinting.XamlExport;
|
|
using Microsoft.Office.Interop.Word;
|
|
using Color = System.Drawing.Color;
|
|
|
|
namespace BeWo.View
|
|
{
|
|
public partial class ChatView
|
|
{
|
|
public UserVM ViewModel { get; set; }
|
|
public int abr = 0;
|
|
|
|
protected TcpClient tcpClient;
|
|
|
|
protected CollectionView view;
|
|
|
|
protected List<KontaktlistBuilder> ita = new List<KontaktlistBuilder>();
|
|
protected List<long> oidspeicher = new List<long>();
|
|
protected List<string> teamdc = new List<string>();
|
|
protected PropertyGroupDescription groupDescription;// = new PropertyGroupDescription("TypeChat");
|
|
|
|
public ChatView(String nameinf, String Chatinf, TcpClient tcpClient)
|
|
{
|
|
InitializeComponent();
|
|
|
|
rootGroupBox.Header = nameinf;
|
|
|
|
this.tcpClient = tcpClient;
|
|
|
|
closeWindow();
|
|
LoadallChatKontakts();
|
|
ErstelleContextMenue();
|
|
SetChatSetting();
|
|
}
|
|
|
|
private void SetChatSetting()
|
|
{
|
|
try
|
|
{
|
|
List<string> data = new List<string>();
|
|
data.Add("Online");
|
|
data.Add("Offline");
|
|
data.Add("Beschäftigt");
|
|
|
|
StatusSetting.ItemsSource = data;
|
|
// StatusSetting.SelectedIndex = 0;
|
|
}
|
|
catch (Exception edf)
|
|
{
|
|
MessageBox.Show("Das Aufbauen der Chat-Settings ist fehlgeschlagen. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2200 ", MessageBoxButton.OK);
|
|
}
|
|
}
|
|
|
|
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();
|
|
|
|
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));
|
|
//SaveChatMessageinDB(personoid,BeWoApp.LoggedOnUser.Employee.PersonOid, text);
|
|
|
|
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();
|
|
//SaveChatMessageinDB(personoid, BeWoApp.LoggedOnUser.Employee.PersonOid, text);
|
|
}
|
|
}
|
|
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 /* type == ChatType.Team*/)
|
|
{
|
|
int x;
|
|
bool wasdrin = int.TryParse(abc.Receivems, out x);
|
|
|
|
if (wasdrin)
|
|
{
|
|
//x = int.TryParse(abc.Receivems,);
|
|
x++;
|
|
abc.Receivems = x.ToString();
|
|
//abc.Receivems = 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, "Online", BuildImg(ServiceFacade.DoEmployeeServiceSync(s => s.GetEmployeeImage(mitarbeiter.EmployeeOid.Value))), personoid,ChatType.Mitarbeiter);
|
|
|
|
var zugehorigkeit = ServiceFacade.DoEmployeeServiceSync(s => s.GetTeamOidsByEmployee(personoid));
|
|
|
|
foreach (var variable in ita)
|
|
{
|
|
if (konbuild.Name.Equals(variable.Name))
|
|
variable.Lastms = "Online";
|
|
|
|
if (variable.TypeChat == ChatType.Team)
|
|
{
|
|
foreach (var zug in zugehorigkeit)
|
|
{
|
|
if (zug.SimpleDescription.Equals(variable.Name))
|
|
{
|
|
variable.Lastms = "Online";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
view.Refresh();
|
|
}
|
|
else if ( a == PersonType.Customer)
|
|
{
|
|
|
|
var klienten = ServiceFacade.DoCustomerServiceSync(s => s.GetCustomerWithPersonOid(personoid));
|
|
|
|
KontaktlistBuilder konbuild = new KontaktlistBuilder(clientname, "Online", BuildImg(ServiceFacade.DoCustomerServiceSync(s => s.GetCustomerImage(klienten.CustomerOid.Value))), personoid, ChatType.Klienten);
|
|
|
|
foreach (var variable in ita)
|
|
{
|
|
if (konbuild.Name.Equals(variable.Name))
|
|
variable.Lastms = "Online";
|
|
}
|
|
|
|
view.Refresh();
|
|
}
|
|
|
|
if (AktChatUser.Items.Count != 0)
|
|
{
|
|
KontaktlistBuilder curItem = (KontaktlistBuilder) AktChatUser.Items[0];
|
|
|
|
if (curItem.EmpfaengerOid == personoid)
|
|
{
|
|
curItem.Lastms = "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.Lastms = "Offline";
|
|
}
|
|
}
|
|
|
|
PruefeTeamsObOnline();
|
|
|
|
teamdc.Clear();
|
|
oidspeicher.Clear();
|
|
|
|
if (AktChatUser.Items.Count > 0)
|
|
{
|
|
KontaktlistBuilder curItem = (KontaktlistBuilder)AktChatUser.Items[0];
|
|
|
|
if (curItem.EmpfaengerOid.Equals(clientid))
|
|
{
|
|
curItem.Lastms = "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.Lastms.Equals("Online"))
|
|
{
|
|
oidspeicher.Add(teamprof.EmpfaengerOid);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (oidspeicher.Count == 0)
|
|
{
|
|
foreach (var tt in ita)
|
|
{
|
|
if (tt.TypeChat == ChatType.Team)
|
|
{
|
|
tt.Lastms = "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.Lastms = "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.Lastms.Equals("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(""))
|
|
{
|
|
KontaktlistBuilder curItem = (KontaktlistBuilder) AktChatUser.Items[0];
|
|
|
|
SendMessage(curItem.EmpfaengerOid,curItem.TypeChat);
|
|
|
|
// SaveChatMessageinDB(BeWoApp.LoggedOnEmployee.PersonOid.Value,curItem.EmpfaengerOid, Chatbox.Text);
|
|
|
|
Chat.Items.MoveCurrentToLast();
|
|
Chat.ScrollIntoView(Chat.Items.CurrentItem);
|
|
|
|
Chatbox.Text = "";
|
|
|
|
if (Chatbox.Text.Equals(""))
|
|
{
|
|
Chatbox.Text = "Nachricht schreiben";
|
|
Chatbox.Foreground = new SolidColorBrush(Colors.DarkGray);
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
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);
|
|
|
|
// SaveChatMessageinDB(BeWoApp.LoggedOnEmployee.PersonOid.Value, curItem.EmpfaengerOid, Chatbox.Text);
|
|
|
|
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());
|
|
|
|
string Goff = "Offline";
|
|
|
|
foreach (var team in employeeteamoids)
|
|
{
|
|
Clientlist.Items.Add(new KontaktlistBuilder(team.Name, Goff, BuildImg(null), team.TeamOid, ChatType.Team));
|
|
}
|
|
|
|
foreach (var list in offmitarbeiter)
|
|
{
|
|
Clientlist.Items.Add(new KontaktlistBuilder(list.FirstName + " " + list.LastName, Goff,
|
|
BuildImg(ServiceFacade.DoEmployeeServiceSync(s => s.GetEmployeeImage(list.EmployeeOid))),
|
|
list.PersonOid, ChatType.Mitarbeiter));
|
|
}
|
|
foreach (var list in offklienten)
|
|
{
|
|
Clientlist.Items.Add(new KontaktlistBuilder(list.FirstName + " " + list.LastName, Goff,
|
|
BuildImg(ServiceFacade.DoCustomerServiceSync(s => s.GetCustomerImage(list.CustomerOid))),
|
|
list.PersonOid, ChatType.Klienten));
|
|
}
|
|
|
|
|
|
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);
|
|
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());
|
|
|
|
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,"Offline", BuildImg(null), 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)
|
|
{
|
|
ita.Add(new KontaktlistBuilder(var.FirstName + " " + var.LastName,"Offline",
|
|
BuildImg(ServiceFacade.DoEmployeeServiceSync(s => s.GetEmployeeImage(var.EmployeeOid))),
|
|
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, "Offline",
|
|
BuildImg(ServiceFacade.DoCustomerServiceSync(s => s.GetCustomerImage(var.CustomerOid))),
|
|
var.PersonOid, ChatType.Klienten));
|
|
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();
|
|
}
|
|
}
|
|
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.Lastms = "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.Lastms = "Beschäftigt";
|
|
else if(type == DataIdentifier.StatusNotificationOnline)
|
|
list.Lastms = "Online";
|
|
//else if (type == DataIdentifier.StatusNotificationOffline)
|
|
// list.Lastms = "Offline"; //<--- Muss noch überdacht werden villeicht bei offlien ein Dellet LoggedOffUser oder so
|
|
}
|
|
|
|
}
|
|
|
|
view.Refresh();
|
|
}
|
|
|
|
|
|
private void ErstelleContextMenue()
|
|
{
|
|
try
|
|
{
|
|
ContextMenu 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);
|
|
|
|
Image icon = new Image();
|
|
icon.Source = (ImageSource) new ImageSourceConverter().ConvertFromString("../../Ressources/Icons/ClipboardDisabled.png");
|
|
icon.SetSize(new Size(16,16));
|
|
item1.Icon = icon;
|
|
|
|
//item2.Header = "Klick";
|
|
//item2.Visibility = Visibility.Visible;
|
|
|
|
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);
|
|
}
|
|
|
|
}
|
|
|
|
private void OnChatRightClickMenue(object sender, RoutedEventArgs e)
|
|
{
|
|
KontakMessageBuilder Item;
|
|
foreach (Object selecteditem in Chat.SelectedItems)
|
|
{
|
|
Item = selecteditem as KontakMessageBuilder;
|
|
Console.WriteLine(Item.UserMessage +" Oid: "+Item.MessagePersonOid); // <---- Gibt die UserMessages in der Console aus.
|
|
}
|
|
}
|
|
|
|
|
|
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
// string value = StatusSetting.SelectedItem as string;
|
|
|
|
switch (StatusSetting.SelectedIndex)
|
|
{
|
|
case 0:
|
|
if ( tcpClient == null)
|
|
{
|
|
StatusSetting.SelectedIndex = 1;
|
|
}else if (!tcpClient.Connected)
|
|
{
|
|
StatusSetting.SelectedIndex = 1;
|
|
}
|
|
else
|
|
{
|
|
//Console.WriteLine("Ich bin bei Online");
|
|
SendUserStatus(DataIdentifier.StatusNotificationOnline);
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
if (tcpClient == null)
|
|
{
|
|
StatusSetting.SelectedIndex = 1;
|
|
}
|
|
else if (!tcpClient.Connected)
|
|
{
|
|
StatusSetting.SelectedIndex = 1;
|
|
}
|
|
else
|
|
{
|
|
//Console.WriteLine("Ich bin bei Offline");
|
|
SendUserStatus(DataIdentifier.StatusNotificationOffline);
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
if (tcpClient == null)
|
|
{
|
|
StatusSetting.SelectedIndex = 1;
|
|
}
|
|
else if (!tcpClient.Connected)
|
|
{
|
|
StatusSetting.SelectedIndex = 1;
|
|
}
|
|
else
|
|
{
|
|
//Console.WriteLine("Ich bin bei Beschäftigt");
|
|
SendUserStatus(DataIdentifier.StatusNotificationBeschäftigt);
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
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
|
|
{
|
|
foreach (var blub in ita)
|
|
{
|
|
if (blub.EmpfaengerOid == personoid && blub.TypeChat == type)
|
|
{
|
|
AktChatUser.Items.Clear();
|
|
Chat.Items.Clear();
|
|
blub.Receivems = "";
|
|
//Clientlist.Items[] // setze die selektion auf den aktuellen chatuser weil das fehlt noch ?!
|
|
|
|
AktChatUser.Items.Add(new KontaktlistBuilder(blub.Name, blub.Lastms, blub.Image, blub.EmpfaengerOid, blub.TypeChat));
|
|
LoadChatMessagefromDB(BeWoApp.LoggedOnEmployee.PersonOid.Value, blub.EmpfaengerOid, blub);
|
|
}
|
|
}
|
|
|
|
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
|
|
{
|
|
if (!Clientlist.Items.IsEmpty)
|
|
{
|
|
curItem = (KontaktlistBuilder) Clientlist.SelectedItem;
|
|
|
|
Chat.Items.Clear();
|
|
|
|
AktChatUser.Items.Clear();
|
|
|
|
if(!curItem.Receivems.Equals("")){
|
|
curItem.Receivems = "";
|
|
}
|
|
|
|
|
|
ChatType a = curItem.TypeChat;
|
|
|
|
AktChatUser.Items.Add(new KontaktlistBuilder(curItem.Name, curItem.Lastms, curItem.Image, curItem.EmpfaengerOid, curItem.TypeChat));
|
|
|
|
|
|
LoadChatMessagefromDB(BeWoApp.LoggedOnEmployee.PersonOid.Value, curItem.EmpfaengerOid, curItem);
|
|
Chat.Items.MoveCurrentToLast();
|
|
Chat.ScrollIntoView(Chat.Items.CurrentItem);
|
|
view.Refresh();
|
|
}
|
|
}
|
|
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)
|
|
{
|
|
try
|
|
{
|
|
if (c != null)
|
|
{
|
|
var biImg = new BitmapImage();
|
|
var ms = new MemoryStream(c);
|
|
|
|
biImg.BeginInit();
|
|
biImg.StreamSource = ms;
|
|
biImg.EndInit();
|
|
|
|
return biImg;
|
|
}
|
|
else
|
|
{
|
|
return
|
|
(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 ReConnect(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
/*if (MessageBox.Show("Versuchen eine Verbindung aufzubauen?", "Verbinden ?", // Aktivieren wenn gewünscht.
|
|
MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
|
|
{
|
|
//Es werden mehrer Threads Erstellt die dann nach und nach versuchen eine Verbindung aufzubauen, zu lasten der cpu,
|
|
//entweder nur anzeigen das man nicht verbunden ist oder eine zwischen lösung finden.
|
|
|
|
|
|
|
|
BeWoApp.MainControl.HomeView.ReconnectServer();
|
|
}*/
|
|
}
|
|
catch (Exception edf)
|
|
{
|
|
MessageBox.Show("Erneute Verbindung Fehlgeschlagen", "Fehler 2360", MessageBoxButton.OK);
|
|
}
|
|
}
|
|
|
|
|
|
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));
|
|
|
|
|
|
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();
|
|
|
|
Dispatcher.Invoke(
|
|
DispatcherPriority.Normal,
|
|
(ThreadStart) delegate { ServerStats.Text = "Nachricht erfolgreich gesendet"; });
|
|
}
|
|
else
|
|
{
|
|
SaveChatMessageinDB(BeWoApp.LoggedOnUser.Employee.PersonOid,empfängeroid, msg, 0, type);
|
|
MessageBox.Show("Die Daten werden in der Datenbank Gespeichert, da der Server nicht zur Verfügung steht.", "Info ", MessageBoxButton.OK);
|
|
}
|
|
}
|
|
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);
|
|
|
|
Dispatcher.Invoke(
|
|
DispatcherPriority.Normal,
|
|
(ThreadStart) // <--- Muss dass nicht Weg
|
|
delegate { ServerStats.Text = "Fehler: Die Nachricht konnte nicht gesendet werden."; });
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SaveChatMessageinDB( long senderoid,long empfangid,string message,int 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
|
|
{
|
|
if (Curitem.TypeChat == ChatType.Team)
|
|
{
|
|
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))
|
|
{
|
|
// Hier muss noch abfrage für ungelesene Nachricht hin
|
|
int zahl = (int) x.IndexOf(anzeige.SenderPersonOid.Value);
|
|
Chat.Items.Add(new KontakMessageBuilder(person[zahl].FirstName, anzeige.ChatText,
|
|
anzeige.Uhrzeit.ToString(), anzeige.SenderPersonOid.Value));
|
|
}
|
|
}
|
|
}
|
|
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)
|
|
{
|
|
Chat.Items.Add(new KontakMessageBuilder(person[0].FirstName, list.ChatText,
|
|
list.Uhrzeit.ToString(), senderoid));
|
|
}
|
|
else
|
|
{
|
|
Chat.Items.Add(new KontakMessageBuilder(person[1].FirstName, list.ChatText,
|
|
list.Uhrzeit.ToString(), empfaengerOid));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (list.TeamOid == null || list.TeamOid == 0 ){
|
|
if (i == 0)
|
|
{
|
|
Chat.Items.Add(new KontakMessageBuilder("", "------------------------ Ungelesene Nachrichten -----------------------", "", 0));
|
|
i++;
|
|
}
|
|
|
|
if (list.SenderPersonOid == senderoid)
|
|
{
|
|
Chat.Items.Add(new KontakMessageBuilder(person[0].FirstName, list.ChatText,
|
|
list.Uhrzeit.ToString(), senderoid));
|
|
}
|
|
else
|
|
{
|
|
Chat.Items.Add(new KontakMessageBuilder(person[1].FirstName, list.ChatText,
|
|
list.Uhrzeit.ToString(), empfaengerOid));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ServiceFacade.DoCustomerServiceSync(s => s.UpdateIstGelesen(senderoid, empfaengerOid, 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);
|
|
}
|
|
}
|
|
|
|
//placeholder
|
|
private void OnFocus(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Chatbox.Text = "";
|
|
Chatbox.Foreground = new SolidColorBrush(Colors.Black);
|
|
}
|
|
catch (Exception edf)
|
|
{
|
|
MessageBox.Show("Fehler beim Fokusieren der Nachrichten Leiste. " + edf.Message + "\n" + edf.StackTrace, "Fehler: 2330 ", MessageBoxButton.OK);
|
|
}
|
|
}
|
|
|
|
/* private void OnDefocus(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (Chatbox.Text.Equals(""))
|
|
{
|
|
/* Chatbox.Text = "Nachricht schreiben";
|
|
Chatbox.Foreground = new SolidColorBrush(Colors.DarkGray);
|
|
}
|
|
}
|
|
catch (Exception edf)
|
|
{
|
|
MessageBox.Show("Fehler beim De-Fokusieren der Nachrichten Leiste.", "Fehler: 2340 ", MessageBoxButton.OK);
|
|
}
|
|
}*/
|
|
|
|
}
|
|
|
|
//KontaklisteFormat und KontaktMessageBuilder Klasse
|
|
public class KontaktlistBuilder : INotifyPropertyChanged
|
|
{
|
|
public KontaktlistBuilder(string name, string lastms, ImageSource image, long empfaengerid,ChatType typeChat)
|
|
{
|
|
this.Name = name;
|
|
this.Lastms = lastms;
|
|
this.Image = image;
|
|
this.EmpfaengerOid = empfaengerid;
|
|
|
|
Receivems = "";
|
|
TypeChat = typeChat;
|
|
}
|
|
|
|
public string Name { get; private set; }
|
|
|
|
private string _lastms;
|
|
public string Lastms { get{return _lastms;} set { _lastms = value; 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; }
|
|
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)
|
|
{
|
|
Username = username;
|
|
UserMessage = message;
|
|
SendTime = sendtime;
|
|
MessagePersonOid = messagePersonOid;
|
|
}
|
|
|
|
public string Username { get; private set; }
|
|
public string UserMessage { get; private set; }
|
|
public string SendTime { get; private set; }
|
|
public long MessagePersonOid { get; private set; }
|
|
|
|
}
|
|
}
|