2017-11-13 10:59:42 +01:00
using System ;
using System.Collections.Generic ;
using System.Collections.Specialized ;
using System.Diagnostics ;
using System.IO ;
using System.Linq ;
using System.Net ;
using System.Text ;
using System.Threading ;
using System.Web ;
using System.Windows ;
using System.Windows.Controls ;
using System.Windows.Controls.Primitives ;
using System.Windows.Documents ;
using System.Windows.Forms ;
using System.Windows.Forms.VisualStyles ;
using System.Windows.Input ;
using System.Windows.Media ;
using System.Windows.Media.Imaging ;
using System.Windows.Navigation ;
using System.Windows.Threading ;
using BeWo.Core ;
using BeWo.Core.Service ;
using BeWo.PasswortSecurity ;
using BeWo.ViewModel ;
using BeWo.ServiceProxy ;
using BS.Shared.Extensions ;
using BS.Shared ;
using BS.Shared.Core ;
using ChatController.ChatKlassen ;
using Microsoft.Win32 ;
using Newtonsoft.Json ;
using CheckBox = System . Windows . Controls . CheckBox ;
using KeyEventArgs = System . Windows . Input . KeyEventArgs ;
using MessageBox = System . Windows . MessageBox ;
using Panel = System . Windows . Controls . Panel ;
using SaveFileDialog = System . Windows . Forms . SaveFileDialog ;
using BeWo.View ;
namespace BeWo.ownChat
{
public partial class ChatServiceCustomer
{
private CustomerVM _ViewModel ;
// TableID tableid;
private long? customerOid ;
private long? personOid ;
PasswortSicherheit pwS = new PasswortSicherheit ( ) ;
public ChatServiceCustomer ( TableID pObjectTid , long? oid , long? cusUserOid )
{
InitializeComponent ( ) ;
customerOid = oid ;
personOid = cusUserOid ;
2018-03-02 16:24:55 +01:00
// tableid = pObjectTid;
2017-11-13 10:59:42 +01:00
2018-03-02 16:24:55 +01:00
this . Loaded + = ChatServiceCustomer_Loaded ;
2017-11-13 10:59:42 +01:00
}
2018-03-02 16:24:55 +01:00
private void ChatServiceCustomer_Loaded ( object sender , RoutedEventArgs e )
{
LaodInfostoView ( ) ;
}
2017-11-13 10:59:42 +01:00
public CustomerVM PublicViewModel { get { return _ViewModel ; } }
public override bool IsDirty
{
get
{
return ViewModel ! = null & & ViewModel . IsDirty ;
}
}
private CustomerVM ViewModel
{
get { return _ViewModel ; }
set
{
DataContext = value ;
_ViewModel = value ;
}
}
#region DoSaveCheck Nicht aktiviert
//TODO Speicher Button Aktivieren
/ * private bool DoSaveCheck ( )
{
Cache . GetInstance ( ) . GetActiveSupportConceptCostbearer ( scList = >
VMFactory . CreateServiceRecordVMAsync (
BeWoApp . LoggedOnUser . Employee . EmployeeOid ,
vm = > this . Dispatch (
delegate
{
ChatServiceCustomer newView = new ChatServiceCustomer ( tableid , customerOid ) ;
if ( newView . CommandBindings . Count = = 0 )
{
newView . CommandBindings . Add (
new CommandBinding (
ApplicationCommands . Close ,
( s , e ) = >
{
if ( ! newView . DoSaveCheck ( ) )
{
return ;
}
} ) ) ;
newView . CommandBindings . Add (
new CommandBinding (
ApplicationCommands . Save ,
( s , e ) = >
{
bool save = true ;
if ( ! save )
{
return ;
}
newView . SaveData ( ) ;
} ) ) ;
}
} ) ) ) ;
}
* /
#endregion
private void LaodInfostoView ( )
{
var getCustomerAppCode = ServiceFacade . DoOperationsServiceSync ( s = > s . GetIsChatActiveCustomerAPPCodeDC ( customerOid . Value , 0 ) ) ;
int x ;
if ( getCustomerAppCode . Count > 0 )
{
x = getCustomerAppCode [ getCustomerAppCode . Count - 1 ] . IsChatAktive ;
GeneratetTexfield . Text = getCustomerAppCode [ getCustomerAppCode . Count - 1 ] . CustomerCode ;
}
CodeButtonsOnOFF ( ) ;
if ( getCustomerAppCode . Count > 0 )
{
TXTBenutzerName . Text = getCustomerAppCode [ getCustomerAppCode . Count - 1 ] . Benutzername ;
TXTPasswort . Text = getCustomerAppCode [ getCustomerAppCode . Count - 1 ] . Passwort ;
2018-03-02 16:24:55 +01:00
pwS . ErmittleUndZeigePasswortStaerke ( TXTPasswort . Text , LblPwStaerkenAnzeige ) ;
2017-11-13 10:59:42 +01:00
}
}
private void CodeButtonsOnOFF ( )
{
if ( ! GeneratetTexfield . Text . Equals ( "" ) )
{
//lblGenerateCode.Content = "Chat-Code erneuern";
RemoveButton . Visibility = Visibility . Visible ;
CustomerHandoutButton . Visibility = Visibility . Visible ;
// CustomerBenutzerKontoGroupBox.Visibility = Visibility.Visible;
ButtonGenerateCode . ToolTip = "Chat-Code erneuern" ;
2021-09-07 15:51:34 +02:00
var image = new System . Windows . Controls . Image
2017-11-13 10:59:42 +01:00
{
Source = new BitmapImage (
new Uri (
"pack://application:,,,/Ressources/Icons/SymbolRefresh32.png" ) )
} ;
ImageGenerateCode . Source = image . Source ;
}
else
{
//lblGenerateCode.Content = "Chat-Code erneuern";
RemoveButton . Visibility = Visibility . Collapsed ;
CustomerHandoutButton . Visibility = Visibility . Collapsed ;
2017-11-16 15:37:29 +01:00
2017-11-13 10:59:42 +01:00
//CustomerBenutzerKontoGroupBox.Visibility = Visibility.Collapsed;
2017-11-16 15:37:29 +01:00
TXTBenutzerName . Visibility = Visibility . Collapsed ;
Benutzer . Visibility = Visibility . Collapsed ;
passwd . Visibility = Visibility . Collapsed ;
TXTPasswort . Visibility = Visibility . Collapsed ;
LblPwStaerkenAnzeige . Visibility = Visibility . Collapsed ;
Speichernbutton . Visibility = Visibility . Collapsed ;
2017-11-13 10:59:42 +01:00
ButtonGenerateCode . ToolTip = "Chat-Code anfordern" ;
2021-09-07 15:51:34 +02:00
var image = new System . Windows . Controls . Image
2017-11-13 10:59:42 +01:00
{
Source = new BitmapImage (
new Uri (
"pack://application:,,,/Ressources/Icons/DocumentWithAdd2.png" ) )
} ;
ImageGenerateCode . Source = image . Source ;
}
}
#region Code Generieren / Erneuern / Löschen
private void GenerateCodeClick ( object sender , RoutedEventArgs e )
{
if ( ! GeneratetTexfield . Text . Equals ( "" ) & & BeWoApp . Tenant ! = null & & BeWoApp . Mandator . Apikey ! = null )
{
2017-12-07 11:14:50 +01:00
if ( MessageBox . Show ( "Wollen Sie wirklich den Chat-Code ändern?\nAlle Daten auf dem Mobilgerät werden gelöscht." , "Chat-Code ändern" , MessageBoxButton . YesNo ,
2017-11-13 10:59:42 +01:00
MessageBoxImage . Question ) = = MessageBoxResult . Yes )
{
StartGenerateCode ( ) ;
}
}
else if ( BeWoApp . Tenant ! = null & & BeWoApp . Mandator . Apikey ! = null )
{
StartGenerateCode ( ) ;
2017-11-16 15:37:29 +01:00
// BeWoUtils.ownChatSynchronisationVeranlassen();
2017-11-13 10:59:42 +01:00
}
else
{
MessageBox . Show ( "Sie besitzen derzeit keinen API-Key. Bitte wenden sie sich an den Support." , "Info" ,
MessageBoxButton . OK , MessageBoxImage . Exclamation ) ;
}
}
private void StartGenerateCode ( )
{
StartWaiting ( ) ;
List < string > parameter = new List < string > ( ) ;
parameter . Add ( customerOid . Value . ToString ( ) ) ;
parameter . Add ( BeWoApp . Tenant ) ;
parameter . Add ( BeWoApp . Mandator . Apikey ) ;
Thread newThread = new Thread ( GenerateCode ) ;
newThread . IsBackground = true ;
newThread . Start ( parameter ) ;
}
private void GenerateCode ( object o )
{
List < string > para = o as List < string > ;
var result =
ServiceFacade . DoOperationsServiceSync ( s = > s . CreateNewCustomerAPPCodeDC ( Convert . ToInt64 ( para [ 0 ] ) , para [ 1 ] , para [ 2 ] ) ) ;
EndWaiting ( ) ;
this . Dispatcher . BeginInvoke (
DispatcherPriority . Background ,
( Action ) delegate
{
if ( result ! = null )
{
2017-11-23 10:58:07 +01:00
if ( result . Result = = 0 )
2017-11-16 15:37:29 +01:00
{
2017-11-23 10:58:07 +01:00
if ( GeneratetTexfield . Text . IsNullOrEmpty ( ) )
{
BeWoUtils . OwnChatSynchronisationVeranlassen ( ) ;
}
2017-11-16 15:37:29 +01:00
2017-11-23 10:58:07 +01:00
GeneratetTexfield . Text = result . CustomerCode ;
CodeButtonsOnOFF ( ) ;
}
else
{
OwnChatResults ( result . Result ) ;
}
2017-11-13 10:59:42 +01:00
}
2017-11-16 15:37:29 +01:00
2017-11-23 10:58:07 +01:00
2017-11-13 10:59:42 +01:00
} ) ;
}
2017-11-16 15:37:29 +01:00
public void OwnChatResults ( int result )
{
switch ( result )
{
case 3 :
MessageBox . Show ( "Chat Server konnte nicht ermittelt werden." , "Chat-Code erstellen" , MessageBoxButton . OK , MessageBoxImage . Exclamation ) ;
break ;
case 4 :
MessageBox . Show ( "ChatCode Datensatz konnte nicht gefunden werden." , "Fehler" , MessageBoxButton . OK ) ;
break ;
case 11 :
MessageBox . Show ( "Kundennummer unbekannt." , "Chat-Code erstellen" , MessageBoxButton . OK , MessageBoxImage . Exclamation ) ;
break ;
case 12 :
MessageBox . Show ( "Der Api-Key ist falsch." , "Chat-Code erstellen" , MessageBoxButton . OK , MessageBoxImage . Exclamation ) ;
break ;
case 32 :
MessageBox . Show ( "Der vorhandene ChatCode konnte nicht deaktiviert werden." , "Chat-Code erstellen" , MessageBoxButton . OK , MessageBoxImage . Exclamation ) ;
break ;
default :
2018-06-13 14:38:35 +02:00
MessageBox . Show ( "Beim Erstellen eines neuen Chat-Codes ist ein Fehler aufgetreten." , "Chat-Code erstellen" , MessageBoxButton . OK , MessageBoxImage . Exclamation ) ;
2017-11-16 15:37:29 +01:00
break ;
}
}
2017-11-13 10:59:42 +01:00
#region Remove
private void RemoveCode_OnClick ( object sender , RoutedEventArgs e )
{
if ( ! GeneratetTexfield . Text . Equals ( "" ) )
{
if ( MessageBox . Show ( "Wollen Sie den Chat-Code wirklich löschen?\nAlle Daten werden gelöscht." , "Achtung" , MessageBoxButton . YesNo , MessageBoxImage . Question ) = = MessageBoxResult . Yes )
{
StartWaiting ( ) ;
List < string > parameter = new List < string > ( ) ;
parameter . Add ( BeWoApp . Mandator . Apikey ) ;
parameter . Add ( BeWoApp . Tenant ) ;
parameter . Add ( customerOid . Value . ToString ( ) ) ;
Thread newThread = new Thread ( DeletGeneratedCode ) ;
newThread . IsBackground = true ;
newThread . Start ( parameter ) ;
}
}
else
{
MessageBox . Show ( "Sie müssen vorher einen Chat-Code generieren, bevor sie ihn löschen können" , "Info" ,
MessageBoxButton . OK , MessageBoxImage . Information ) ;
}
}
private void DeletGeneratedCode ( object o )
{
List < string > para = o as List < string > ;
2017-11-16 15:37:29 +01:00
var result = ServiceFacade . DoOperationsServiceSync ( r = > r . DeletCustomerChatCode ( para [ 0 ] , para [ 1 ] , Convert . ToInt64 ( para [ 2 ] ) ) ) ;
2017-11-13 10:59:42 +01:00
EndWaiting ( ) ;
this . Dispatcher . BeginInvoke (
DispatcherPriority . Background ,
( Action ) delegate
{
2017-11-16 15:37:29 +01:00
if ( result . Result = = 0 )
2017-11-13 10:59:42 +01:00
{
GeneratetTexfield . Text = "" ;
CodeButtonsOnOFF ( ) ;
2017-11-23 10:58:07 +01:00
BeWoUtils . OwnChatSynchronisationVeranlassen ( ) ;
2017-11-13 10:59:42 +01:00
}
else
{
2017-11-16 15:37:29 +01:00
//MessageBox.Show("Löschen des Chat-Codes fehlgeschlagen.", "Fehler", MessageBoxButton.OK, MessageBoxImage.Exclamation);
OwnChatResults ( result . Result ) ; //ändern
2017-11-13 10:59:42 +01:00
}
} ) ;
}
#endregion
#endregion
#region Klient Ownchat Anmelde - Daten Handler
//speicher button auf do savecheck auslagern
private void SpeicherButton_OnClick ( object sender , RoutedEventArgs e )
2017-11-16 15:37:29 +01:00
{
2017-11-13 10:59:42 +01:00
var pwStaerke = BeWoUtils . CheckPasswordSecurity ( TXTPasswort . Text ) ;
if ( BeWoApp . AppSettings . IsPasswordSecurityActiv & & ( pwStaerke = = PasswortSecurityStrength . SehrSchwach | | pwStaerke = = PasswortSecurityStrength . Schwach ) )
{
2017-12-15 10:47:43 +01:00
string failure = "Das Passwort ist zu schwach! Das Passwort sollte mindestens 8 Zeichen lang sein und Sonderzeichen, Ziffern oder Großbuchstaben enthalten." ;
2017-11-13 10:59:42 +01:00
MessageBox . Show ( failure , "Erstellen des Passworts fehlgeschlagen" , MessageBoxButton . OK , MessageBoxImage . Information ) ;
return ;
}
StartWaiting ( ) ;
var isBenutzerNameVorhanden = ServiceFacade . DoCustomerServiceSync ( r = > r . PruefeObBenutzerKontoSchonVorhanden ( customerOid . Value , TXTBenutzerName . Text ) ) ;
if ( ! isBenutzerNameVorhanden )
{
ServiceFacade . DoCustomerServiceSync (
s = >
s . SetBenutzerPasswortChatAppCode ( customerOid . Value , TXTBenutzerName . Text ,
TXTPasswort . Text ) ) ;
EndWaiting ( ) ;
2017-12-15 10:47:43 +01:00
BeWoUtils . OwnChatSynchronisationVeranlassen ( ) ;
2017-11-13 10:59:42 +01:00
MessageBox . Show ( "Benutzername und Passwort wurden erfolgreich gespeichert." , "Speichern" , MessageBoxButton . OK , MessageBoxImage . Information ) ;
2017-11-16 15:37:29 +01:00
2017-12-15 10:47:43 +01:00
2017-11-16 15:37:29 +01:00
2017-11-13 10:59:42 +01:00
}
else
{
EndWaiting ( ) ;
MessageBox . Show ( "Dieser Benutzername ist bereits vergeben." , "Speichern" , MessageBoxButton . OK , MessageBoxImage . Exclamation ) ;
2017-11-16 15:37:29 +01:00
}
2017-11-13 10:59:42 +01:00
}
private void TXTPasswort_OnTextChanged ( object sender , TextChangedEventArgs e )
{
LblPwStaerkenAnzeige = pwS . ErmittleUndZeigePasswortStaerke ( TXTPasswort . Text , LblPwStaerkenAnzeige ) ;
}
#endregion
2017-11-15 08:08:12 +01:00
#region pdf // auf den server auslagern und als byte[] zurück geben und hier verarbeiten
2017-11-13 10:59:42 +01:00
private void ZeigeHandoutPDF_OnClick ( object sender , RoutedEventArgs e )
{
2017-12-17 17:29:07 +01:00
String tenant = BeWoApp . Tenant ;
2017-12-15 10:47:43 +01:00
#if DEBUG
2017-12-17 17:29:07 +01:00
tenant = "5473568546" ;
2017-12-15 10:47:43 +01:00
#endif
2017-12-17 17:29:07 +01:00
OwnChatHelper . OpenOwnChatPdf ( tenant , BeWoApp . Mandator . Apikey , TXTBenutzerName . Text , TXTPasswort . Text , GeneratetTexfield . Text ) ;
2017-11-13 10:59:42 +01:00
}
2017-12-17 17:29:07 +01:00
2017-11-13 10:59:42 +01:00
#endregion
#region Waitlayer
private WaitLayer2 _waitLayer = null ;
public void StartWaiting ( )
{
Dispatcher . BeginInvoke ( DispatcherPriority . Background , ( Action ) StartWaitingImmediately ) ;
}
public void StartWaitingImmediately ( )
{
if ( _waitLayer = = null )
{
_waitLayer = new WaitLayer2 ( ) ;
//Grid.SetColumnSpan(_waitLayer, 3);
//Grid.SetRowSpan(_waitLayer, 3);
ChatServiceCustomerGrid . Children . Add ( _waitLayer ) ;
Panel . SetZIndex ( _waitLayer , int . MaxValue ) ;
_waitLayer . RefreshChatUI ( ) ;
}
}
public void EndWaiting ( )
{
Dispatcher . BeginInvoke (
DispatcherPriority . Background ,
( Action ) delegate
{
if ( _waitLayer ! = null )
{
ChatServiceCustomerGrid . Children . Remove ( _waitLayer ) ;
_waitLayer = null ;
}
} ) ;
}
#endregion
}
2016-06-27 01:45:38 +02:00
}