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.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;
|
||||
|
@ -105,11 +115,13 @@ namespace ProjetTheAlone.View
|
|||
if (((DataGrid)sender).SelectedItems.Count == 0)
|
||||
return;
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
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
|
||||
{
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -52,7 +60,7 @@ namespace ProjetTheAlone.ViewModel
|
|||
double WTB = textContainer.ActualWidth; //With of textBlock container
|
||||
double WT = MeasureString(text).Width; //With of Text
|
||||
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();
|
||||
this.textAfficherBuffer = new char[nbSp + text.ToCharArray().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
|
||||
private Size MeasureString(string candidate)
|
||||
{
|
||||
var formattedText = new FormattedText(
|
||||
candidate,
|
||||
CultureInfo.CurrentCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
new Typeface(this.textContainer.FontFamily, this.textContainer.FontStyle, this.textContainer.FontWeight, this.textContainer.FontStretch),
|
||||
this.textContainer.FontSize,
|
||||
Brushes.Black,
|
||||
new NumberSubstitution(), (TextFormattingMode)1);
|
||||
FormattedText formattedText = null;
|
||||
this.textContainer.Dispatcher.Invoke(() =>
|
||||
{
|
||||
formattedText = new FormattedText(
|
||||
candidate,
|
||||
CultureInfo.CurrentCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue