DashBoard update every 5sec
This commit is contained in:
parent
17331c389e
commit
5aec064536
|
@ -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;
|
||||||
|
@ -105,11 +115,13 @@ namespace ProjetTheAlone.View
|
||||||
if (((DataGrid)sender).SelectedItems.Count == 0)
|
if (((DataGrid)sender).SelectedItems.Count == 0)
|
||||||
return;
|
return;
|
||||||
C_T_event _eventSelected = ((C_T_event)((DataGrid)sender).SelectedItem);
|
C_T_event _eventSelected = ((C_T_event)((DataGrid)sender).SelectedItem);
|
||||||
if(W_detailEvent == null || W_detailEvent != null && W_detailEvent.IsClosed)
|
if (W_detailEvent == null || W_detailEvent != null && W_detailEvent.IsClosed)
|
||||||
{
|
{
|
||||||
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
|
||||||
{
|
{
|
||||||
|
|
|
@ -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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +60,7 @@ namespace ProjetTheAlone.ViewModel
|
||||||
double WTB = textContainer.ActualWidth; //With of textBlock container
|
double WTB = textContainer.ActualWidth; //With of textBlock container
|
||||||
double WT = MeasureString(text).Width; //With of Text
|
double WT = MeasureString(text).Width; //With of Text
|
||||||
double WS = MeasureString(" ").Width; //With of whiteSpace
|
double WS = MeasureString(" ").Width; //With of whiteSpace
|
||||||
int nbSp = (int)Math.Ceiling((WTB - WT) / WS); //number of space need to fill textBlock
|
int nbSp = (int)Math.Ceiling((WTB-WT) / WS); //number of space need to fill textBlock
|
||||||
char[] spText = new string(' ', nbSp).ToCharArray();
|
char[] spText = new string(' ', nbSp).ToCharArray();
|
||||||
this.textAfficherBuffer = new char[nbSp + text.ToCharArray().Length];
|
this.textAfficherBuffer = new char[nbSp + text.ToCharArray().Length];
|
||||||
Array.Copy(text.ToCharArray(), 0, this.textAfficherBuffer, 0, text.Length);
|
Array.Copy(text.ToCharArray(), 0, this.textAfficherBuffer, 0, text.Length);
|
||||||
|
@ -72,14 +80,19 @@ 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;
|
||||||
candidate,
|
this.textContainer.Dispatcher.Invoke(() =>
|
||||||
CultureInfo.CurrentCulture,
|
{
|
||||||
FlowDirection.LeftToRight,
|
formattedText = new FormattedText(
|
||||||
new Typeface(this.textContainer.FontFamily, this.textContainer.FontStyle, this.textContainer.FontWeight, this.textContainer.FontStretch),
|
candidate,
|
||||||
this.textContainer.FontSize,
|
CultureInfo.CurrentCulture,
|
||||||
Brushes.Black,
|
FlowDirection.LeftToRight,
|
||||||
new NumberSubstitution(), (TextFormattingMode)1);
|
new Typeface(this.textContainer.FontFamily, this.textContainer.FontStyle, this.textContainer.FontWeight, this.textContainer.FontStretch),
|
||||||
|
this.textContainer.FontSize,
|
||||||
|
Brushes.Black,
|
||||||
|
new NumberSubstitution(), (TextFormattingMode)1);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
return new Size(formattedText.WidthIncludingTrailingWhitespace, formattedText.Height);
|
return new Size(formattedText.WidthIncludingTrailingWhitespace, formattedText.Height);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue