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

View File

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

View File

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