350 lines
13 KiB
C#
350 lines
13 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
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.Navigation;
|
|
using System.Windows.Threading;
|
|
|
|
using BeWo.Core;
|
|
using BeWo.Core.Service;
|
|
using BeWo.ViewModel;
|
|
using BeWo.ServiceProxy;
|
|
using BeWo.View.Detail;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
|
|
using Microsoft.Win32;
|
|
using CheckBox = System.Windows.Controls.CheckBox;
|
|
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
|
using MessageBox = System.Windows.MessageBox;
|
|
|
|
namespace BeWo.View
|
|
{
|
|
public partial class ChatServiceCustomer
|
|
{
|
|
|
|
private CustomerVM _ViewModel;
|
|
|
|
// TableID tableid;
|
|
private long? customerOid;
|
|
private long? personOid;
|
|
|
|
public ChatServiceCustomer(TableID pObjectTid, long? oid,long? cusUserOid)
|
|
{
|
|
InitializeComponent();
|
|
|
|
customerOid = oid;
|
|
personOid = cusUserOid;
|
|
// tableid = pObjectTid;
|
|
|
|
LaodInfostoView();
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
//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();
|
|
|
|
}));
|
|
}
|
|
})));
|
|
|
|
}
|
|
*/
|
|
|
|
|
|
|
|
private void GenerateCodeClick(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
//#if DEBUG
|
|
// //Am ende des Tages Wegnehmen
|
|
// if (true)
|
|
// {
|
|
// if (MessageBox.Show("Wollen sie wirklich ihren Code ändern?", "Achtung", MessageBoxButton.YesNo,
|
|
// MessageBoxImage.Question) == MessageBoxResult.Yes)
|
|
// {
|
|
// var result = ServiceFacade.DoOperationsServiceSync(s => s.CreateNewCustomerAPPCodeDC(customerOid.Value, "5473568546", "123", personOid.Value));
|
|
|
|
// if (result != null)
|
|
// {
|
|
// GeneratetTexfield.Text = result.CustomerCode;
|
|
// }
|
|
// else
|
|
// {
|
|
// //erstmal
|
|
// MessageBox.Show("Beim erstellen eines neuen Chatcodes ist ein fehler aufgetreten. ");
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
//#else
|
|
|
|
//Abfrage mit null catchen
|
|
|
|
if (!GeneratetTexfield.Text.Equals("") && BeWoApp.Tenant != null && BeWoApp.Mandator.Apikey != null)
|
|
{
|
|
if (MessageBox.Show("Wollen Sie wirklich den Code ändern?", "Achtung", MessageBoxButton.YesNo,
|
|
MessageBoxImage.Question) == MessageBoxResult.Yes)
|
|
{
|
|
var result =
|
|
ServiceFacade.DoOperationsServiceSync(s => s.CreateNewCustomerAPPCodeDC(customerOid.Value, BeWoApp.Tenant, BeWoApp.Mandator.Apikey,personOid.Value)); // die useroid muss noch rausgeholt werden
|
|
|
|
|
|
if(result != null){
|
|
GeneratetTexfield.Text = result.CustomerCode;
|
|
}else{
|
|
MessageBox.Show("Beim Erstellen eines neuen Chatcodes ist ein Fehler aufgetreten.");
|
|
}
|
|
|
|
//GeneratetTexfield.Text = result.CustomerCode;
|
|
}
|
|
}
|
|
else if (BeWoApp.Tenant != null && BeWoApp.Mandator.Apikey != null)
|
|
{
|
|
var result = ServiceFacade.DoOperationsServiceSync(s => s.CreateNewCustomerAPPCodeDC(customerOid.Value, BeWoApp.Tenant, BeWoApp.Mandator.Apikey, personOid.Value));// die useroid muss noch rausgeholt werden
|
|
|
|
if(result != null){
|
|
GeneratetTexfield.Text = result.CustomerCode;
|
|
}else{
|
|
MessageBox.Show("Beim Erstellen eines neuen Chatcodes ist ein Fehler aufgetreten.");
|
|
}
|
|
//GeneratetTexfield.Text = result.CustomerCode;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Sie besitzen derzeit keinen API-Key. Bitte wenden sie sich an den Support.","Info",MessageBoxButton.OK);
|
|
}
|
|
//#endif
|
|
}
|
|
|
|
|
|
private void CheckBox_Checked(object sender, RoutedEventArgs e)
|
|
{
|
|
ServiceFacade.DoOperationsServiceSync(s => s.UpdateIsChatActiveCustomerAPPCodeDC(customerOid.Value, 1));
|
|
}
|
|
|
|
private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
|
|
{
|
|
ServiceFacade.DoOperationsServiceSync(s => s.UpdateIsChatActiveCustomerAPPCodeDC(customerOid.Value, 0));
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
if (!GeneratetTexfield.Text.Equals("")) {
|
|
GenerateButon.Content = "Chat-Code erneuern";
|
|
}
|
|
//else
|
|
// x = 0;
|
|
|
|
//if (x == 0)
|
|
//{
|
|
// ChatAktive.SetCurrentValue(CheckBox.IsCheckedProperty, false);
|
|
//}
|
|
//else
|
|
//{
|
|
// ChatAktive.SetCurrentValue(CheckBox.IsCheckedProperty, true);
|
|
//}
|
|
|
|
if (getCustomerAppCode.Count > 0)
|
|
{
|
|
TXTBenutzerName.Text = getCustomerAppCode[getCustomerAppCode.Count - 1].Benutzername;
|
|
TXTPasswort.Text = getCustomerAppCode[getCustomerAppCode.Count - 1].Passwort;
|
|
}
|
|
}
|
|
|
|
//######### Erstmal vorrübergehend #####################################################################################
|
|
//#region Passwort geändert
|
|
// private void TXTPasswort_OnKeyDown(object sender, KeyEventArgs e)
|
|
// {
|
|
// if (e.Key == Key.Enter) {
|
|
// var passwort = TXTPasswort.Text;
|
|
|
|
// ServiceFacade.DoCustomerServiceSync(s => s.SetBenutzerPasswortChatAppCode(customerOid.Value,"", passwort));
|
|
// }
|
|
// }
|
|
|
|
// private void TXTPasswort_OnLostFocus(object sender, RoutedEventArgs e)
|
|
// {
|
|
// var passwort = TXTPasswort.Text;
|
|
// ServiceFacade.DoCustomerServiceSync(s => s.SetBenutzerPasswortChatAppCode(customerOid.Value, "", passwort));
|
|
// }
|
|
//#endregion
|
|
|
|
//#region BenutzerName
|
|
// private void TXTBenutzerName_OnKeyDown(object sender, KeyEventArgs e)
|
|
// {
|
|
// if(e.Key == Key.Enter) {
|
|
// var benutzerName = TXTBenutzerName.Text;
|
|
|
|
// ServiceFacade.DoCustomerServiceSync(s => s.SetBenutzerPasswortChatAppCode(customerOid.Value, benutzerName, ""));
|
|
// }
|
|
// }
|
|
|
|
// private void TXTBenutzerName_OnLostFocus(object sender, RoutedEventArgs e)
|
|
// {
|
|
// var benutzerName = TXTBenutzerName.Text;
|
|
// ServiceFacade.DoCustomerServiceSync(s => s.SetBenutzerPasswortChatAppCode(customerOid.Value, benutzerName, ""));
|
|
// }
|
|
//#endregion
|
|
|
|
private void SpeicherButton_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (BeWoApp.AppSettings.IsPasswordSecurityActiv)
|
|
{
|
|
if (TXTPasswort.Text.Length >= 8)
|
|
{
|
|
ServiceFacade.DoCustomerServiceSync(s => s.SetBenutzerPasswortChatAppCode(customerOid.Value, TXTBenutzerName.Text, TXTPasswort.Text));
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Das Passwort ist zu schwach.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ServiceFacade.DoCustomerServiceSync(s => s.SetBenutzerPasswortChatAppCode(customerOid.Value, TXTBenutzerName.Text, TXTPasswort.Text));
|
|
}
|
|
}
|
|
|
|
private void RemoveCode_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (!GeneratetTexfield.Text.Equals(""))
|
|
{
|
|
var isdeletet = ServiceFacade.DoOperationsServiceSync(r => r.DeletCustomerChatCode(BeWoApp.Mandator.Apikey, BeWoApp.Tenant, personOid.Value));
|
|
|
|
if (isdeletet)
|
|
{
|
|
GeneratetTexfield.Text = "";
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Löschen des ChatCodes Fehlgeschlagen.", "Fehler");
|
|
}
|
|
}
|
|
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 ZeigeHandoutPDF_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
var handout = ServiceFacade.DoOperationsServiceSync(r => r.GetHandOutPdfForChat(BeWoApp.Tenant, BeWoApp.Mandator.Apikey));
|
|
|
|
if (handout.File != null && !handout.File.Equals(""))
|
|
{
|
|
handout.Result = 0;
|
|
}
|
|
|
|
switch (handout.Result)
|
|
{
|
|
case 0:
|
|
//Hier die pdf anzeigen
|
|
|
|
Process.Start(handout.File);
|
|
|
|
break;
|
|
case 11:
|
|
MessageBox.Show("Kundennummer unbekannt.", "Fehler", MessageBoxButton.OK);
|
|
break;
|
|
case 12:
|
|
MessageBox.Show("Der API-Key ist falsch -> Auth-Error.", "Fehler", MessageBoxButton.OK);
|
|
break;
|
|
case 13:
|
|
MessageBox.Show("Es existiert kein API-Key für die angegebene Kundennummer.", "Fehler", MessageBoxButton.OK);
|
|
break;
|
|
case 40:
|
|
MessageBox.Show("Vorlage nicht gefunden.", "Fehler", MessageBoxButton.OK);
|
|
break;
|
|
case 41:
|
|
MessageBox.Show("Ungültige Custom-Logo-URL.", "Fehler", MessageBoxButton.OK);
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
} |