DashBoard update every 5sec

This commit is contained in:
Adrien VAN DAMME 2019-01-27 18:50:01 +01:00
parent 17331c389e
commit 5aec064536
3 changed files with 72 additions and 24 deletions

View File

@ -17,6 +17,8 @@ using System.Windows.Shapes;
using ProjetTheAlone.Model;
using ProjetTheAlone.Classes;
using ProjetTheAlone.ViewModel;
using System.Threading;
using System.Timers;
namespace ProjetTheAlone.View
{
@ -27,6 +29,7 @@ namespace ProjetTheAlone.View
public partial class DashBoard : Window
{
public System.Timers.Timer aTimer;
ObservableCollection<string> cl = new ObservableCollection<string>();
RepaModel rm = new RepaModel();
View.FicDetailEvent W_detailEvent = null;
@ -58,20 +61,27 @@ namespace ProjetTheAlone.View
InitializeComponent();
//EventPasse2.DataContext = EventPasse1.DataContext = Epm;
testQuand.DataContext = RepasAjd.DataContext = new RepaModel(DateTime.Now);
RepasDemain.DataContext = new RepaModel(DateTime.Now.AddDays(1));
RepasApresDemain.DataContext = new RepaModel(DateTime.Now.AddDays(2));
dgEventPasse2.DataContext = new EventDGV_VM(DateTime.Now.AddDays(-3));
dgEventPasse1.DataContext = new EventDGV_VM(DateTime.Now.AddDays(-2));
dgEventPasse0.DataContext = new EventDGV_VM(DateTime.Now.AddDays(-1));
dgEventFuture0.DataContext = new EventDGV_VM(DateTime.Now.AddDays(0));
dgEventFuture1.DataContext = new EventDGV_VM(DateTime.Now.AddDays(1));
dgEventFuture2.DataContext = new EventDGV_VM(DateTime.Now.AddDays(2));
setAllDataContext();
SetTimer(5000);
aTimer.Enabled = true;
}
private void SetTimer(int timeMs)
{
// Create a timer with a two second interval.
aTimer = new System.Timers.Timer(timeMs);
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += OnTimedEvent;
aTimer.AutoReset = true;
}
private void OnTimedEvent(Object source, ElapsedEventArgs e)
{
wnd.Dispatcher.Invoke(() =>
{
setAllDataContext();
});
}
private void wnd_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Accueil.Openaffichage = false;
@ -110,6 +120,8 @@ namespace ProjetTheAlone.View
W_detailEvent = new FicDetailEvent(_eventSelected);
}
else
W_detailEvent.setDataContext(_eventSelected);
if(!W_detailEvent.IsVisible)
{
W_detailEvent.Show();
@ -117,6 +129,19 @@ namespace ProjetTheAlone.View
W_detailEvent.Activate();
e.Handled = true;
}
private void setAllDataContext()
{
RepasAjd.DataContext = new RepaModel(DateTime.Now);
RepasDemain.DataContext = new RepaModel(DateTime.Now.AddDays(1));
RepasApresDemain.DataContext = new RepaModel(DateTime.Now.AddDays(2));
dgEventPasse2.DataContext = new EventDGV_VM(DateTime.Now.AddDays(-3));
dgEventPasse1.DataContext = new EventDGV_VM(DateTime.Now.AddDays(-2));
dgEventPasse0.DataContext = new EventDGV_VM(DateTime.Now.AddDays(-1));
dgEventFuture0.DataContext = new EventDGV_VM(DateTime.Now.AddDays(0));
dgEventFuture1.DataContext = new EventDGV_VM(DateTime.Now.AddDays(1));
dgEventFuture2.DataContext = new EventDGV_VM(DateTime.Now.AddDays(2));
}
}
public class DebugDummyConverter : IValueConverter
{

View File

@ -14,11 +14,18 @@ namespace ProjetTheAlone.ViewModel
{
public class TextDefilant : BasePropriete
{
public event TickHandler Tick;
public EventArgs e = null;
public delegate void TickHandler(object o, EventArgs e);
public Timer aTimer;
public TextBlock textContainer;
char[] textAfficherBuffer;
public string TextAfficher { set { fillBuffer(value); } get { return new string(textAfficherBuffer); } }
string textAfficher;
public string TextAfficher { set { fillBuffer(value); textAfficher = value; } get { return new string(textAfficherBuffer); } }
public TextDefilant(TextBlock tb, string text, int timeMs)
@ -41,6 +48,7 @@ namespace ProjetTheAlone.ViewModel
private void OnTimedEvent(Object source, ElapsedEventArgs e)
{
textAfficherBuffer = RotateChar(textAfficherBuffer);
Tick?.Invoke(this, null);
OnPropertyChanged("TextAfficher");
}
@ -72,7 +80,10 @@ namespace ProjetTheAlone.ViewModel
//https://stackoverflow.com/questions/9264398/how-to-calculate-wpf-textblock-width-for-its-known-font-size-and-characters
private Size MeasureString(string candidate)
{
var formattedText = new FormattedText(
FormattedText formattedText = null;
this.textContainer.Dispatcher.Invoke(() =>
{
formattedText = new FormattedText(
candidate,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
@ -80,6 +91,8 @@ namespace ProjetTheAlone.ViewModel
this.textContainer.FontSize,
Brushes.Black,
new NumberSubstitution(), (TextFormattingMode)1);
});
return new Size(formattedText.WidthIncludingTrailingWhitespace, formattedText.Height);
}

View File

@ -10,6 +10,7 @@ namespace ProjetTheAlone.ViewModel
{
public class VM_DashBoard : TextDefilant
{
int tick = 0;
public StringCollection Alerte
{
get
@ -29,6 +30,7 @@ namespace ProjetTheAlone.ViewModel
public VM_DashBoard(TextBlock tb, string text, int timeMs) : base (tb,text, timeMs)
{
updateAlert();
base.Tick += new TickHandler(onTick);
}
public void updateAlert()
{
@ -45,5 +47,13 @@ namespace ProjetTheAlone.ViewModel
}
base.TextAfficher = alert;
}
public void onTick(object o, EventArgs e)
{
if(++tick > base.TextAfficher.Length)
{
tick = 0;
updateAlert();
}
}
}
}