88 lines
3.2 KiB
C#
88 lines
3.2 KiB
C#
using EBS_POC.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Timers;
|
|
using System.IO;
|
|
|
|
namespace EBS_POC.Controls
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for Worker_Window.xaml
|
|
/// </summary>
|
|
public partial class Worker_Window : UserControl
|
|
{
|
|
public Worker ThisWorker { get; set; }
|
|
//private Timer TextChangeTimer { get; set; } = new Timer();
|
|
|
|
public Worker_Window(Worker Worker)
|
|
{
|
|
InitializeComponent();
|
|
ThisWorker = Worker;
|
|
this.Name = Worker.Name;
|
|
}
|
|
private void userControl_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
textNotes.Text = ThisWorker.Notes;
|
|
textWorker.Text = ThisWorker.Name;
|
|
}
|
|
|
|
private async void textNotes_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
|
{
|
|
ThisWorker.Notes = (sender as TextBox).Text + e.Text;
|
|
if (Main_Model.Current.IsHost)
|
|
{
|
|
foreach (var client in Main_Model.Current.ClientList)
|
|
{
|
|
client.Value.Send(Encoding.UTF8.GetBytes(JsonHelper.Encode(ThisWorker)));
|
|
}
|
|
await FilePlus.WriteAllText(Main_Model.Current.EBSFilePath, JsonHelper.Encode(Main_Model.Current.EBSFile));
|
|
}
|
|
else
|
|
{
|
|
Main_Model.Current.ConnectionToServer.Client.Send(Encoding.UTF8.GetBytes(JsonHelper.Encode(ThisWorker)));
|
|
}
|
|
// * Use this to set a required input delay before the updated message will be sent. * //
|
|
//TextChangeTimer.Stop();
|
|
//TextChangeTimer = new Timer();
|
|
//TextChangeTimer.Elapsed += async (sen, arg) =>
|
|
//{
|
|
// if (Main_Model.Current.IsHost)
|
|
// {
|
|
// foreach (var client in Main_Model.Current.ClientList)
|
|
// {
|
|
// client.Value.Send(Encoding.UTF8.GetBytes(JsonHelper.Encode(ThisWorker)));
|
|
// }
|
|
// await FilePlus.WriteAllText(Main_Model.Current.EBSFilePath, JsonHelper.Encode(Main_Model.Current.EBSFile));
|
|
// }
|
|
// else
|
|
// {
|
|
// Main_Model.Current.ConnectionToServer.Client.Send(Encoding.UTF8.GetBytes(JsonHelper.Encode(ThisWorker)));
|
|
// }
|
|
//};
|
|
//TextChangeTimer.AutoReset = false;
|
|
//TextChangeTimer.Interval = 2000;
|
|
//TextChangeTimer.Start();
|
|
}
|
|
|
|
private void textNotes_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.Key == Key.Delete || e.Key == Key.Back)
|
|
{
|
|
var tce = new TextCompositionEventArgs(Keyboard.PrimaryDevice, new TextComposition(InputManager.Current, textNotes, ""));
|
|
textNotes_PreviewTextInput(textNotes, tce);
|
|
}
|
|
}
|
|
}
|
|
}
|