161 lines
4.7 KiB
C#
161 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Input;
|
|
|
|
using BeWo.Annotations;
|
|
using BeWo.Core;
|
|
using BeWo.ServiceProxy;
|
|
using BeWo.Validation;
|
|
using BeWo.View;
|
|
using BeWo.ViewModel;
|
|
using BeWo.ViewModel.ListViewModel;
|
|
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Translation;
|
|
using DevExpress.Utils;
|
|
using DevExpress.Xpf.Editors;
|
|
using DevExpress.Xpf.Grid;
|
|
using MessageBox = System.Windows.MessageBox;
|
|
|
|
namespace BeWo.AI.View
|
|
{
|
|
public partial class AiChatView : BeWoView
|
|
{
|
|
public event Action CloseButtonClicked;
|
|
|
|
int type = 0; //0 = ServiceRecordQuery, 1 = SingleCustomerQuery, 2 = AllCustomerQuery
|
|
|
|
private long cb2scOid;
|
|
private long customerOid;
|
|
private TableID tableID;
|
|
private DateTime startDate;
|
|
private DateTime endDate;
|
|
private AiSettingsDC aiSettings;
|
|
|
|
public AiChatView()
|
|
{
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
public void InitServiceRecordQuery(long c2sOid, DateTime start, DateTime end)
|
|
{
|
|
type = 0;
|
|
this.cb2scOid = c2sOid;
|
|
this.startDate = start;
|
|
this.endDate = end;
|
|
|
|
LoadAiSettings(1);
|
|
}
|
|
|
|
|
|
public void InitSingleCustomerQuery(long customerOid)
|
|
{
|
|
type = 1;
|
|
this.customerOid = customerOid;
|
|
}
|
|
|
|
public void InitObjectQuery(TableID tableId)
|
|
{
|
|
type = 2;
|
|
tableID = tableId;
|
|
}
|
|
|
|
private void LoadAiSettings(int settingsType)
|
|
{
|
|
aiSettings = ServiceFacade.DoOperationsServiceSync(s => s.GetAiSettings(settingsType));
|
|
}
|
|
|
|
private void ReloadViewModel(AiChatDC dc)
|
|
{
|
|
TextBoxErgebnis.Text = dc.Result;
|
|
}
|
|
|
|
private void btnSend_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var acdc = new AiChatDC();
|
|
acdc.Prompt = TextBoxAnfrage.Text;
|
|
|
|
if (type == 1)
|
|
{
|
|
ServiceFacade.DoOperationsServiceAsync(s => s.CreateAiQueryForSingleCustomer(acdc, customerOid),
|
|
dc =>
|
|
{
|
|
this.Dispatch(delegate
|
|
{
|
|
ReloadViewModel(dc);
|
|
});
|
|
});
|
|
}
|
|
else if (type == 2)
|
|
{
|
|
ServiceFacade.DoOperationsServiceAsync(s => s.CreateAiQueryForObjects(acdc, (int)tableID),
|
|
dc =>
|
|
{
|
|
this.Dispatch(delegate
|
|
{
|
|
ReloadViewModel(dc);
|
|
});
|
|
});
|
|
}
|
|
else
|
|
{
|
|
ServiceFacade.DoOperationsServiceAsync(s => s.CreateAiQueryForServiceRecords(acdc, cb2scOid, startDate, endDate),
|
|
dc =>
|
|
{
|
|
this.Dispatch(delegate
|
|
{
|
|
ReloadViewModel(dc);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
private void btnClose_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
CloseButtonClicked?.Invoke();
|
|
}
|
|
|
|
private void btnSettings_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (aiSettings != null)
|
|
{
|
|
TextBoxTemplate.Text = aiSettings.Settings;
|
|
}
|
|
PopupTemplate.IsOpen = true;
|
|
}
|
|
|
|
|
|
private void btnSaveSettings_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
PopupTemplate.IsOpen = false;
|
|
if (aiSettings != null)
|
|
{
|
|
aiSettings.Settings = TextBoxTemplate.Text;
|
|
|
|
ServiceFacade.DoOperationsServiceAsync(s => s.UpdateAiSettings(aiSettings),
|
|
dc =>
|
|
{
|
|
this.Dispatch(delegate
|
|
{
|
|
aiSettings = dc;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
private void btnCancelSettings_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
PopupTemplate.IsOpen = false;
|
|
}
|
|
}
|
|
}
|