Files
BeWoPlaner/BeWo/AI/View/AiChatView.xaml.cs

120 lines
3.4 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.View.Controls;
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;
public AiChatView()
{
InitializeComponent();
}
public void InitServiceRecordQuery(long c2sOid, DateTime start, DateTime end)
{
type = 0;
this.cb2scOid = c2sOid;
this.startDate = start;
this.endDate = end;
}
public void InitSingleCustomerQuery(long customerOid)
{
type = 1;
this.customerOid = customerOid;
}
public void InitObjectQuery(TableID tableId)
{
type = 2;
tableID = tableId;
}
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();
}
}
}