aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-07-16 15:51:33 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-07-16 15:51:33 +0300
commit13e34402f91fae6229b2d9719ddb48ced1d37fbf (patch)
tree1b60f7f1f719403ede6f3ebbfe6077ca673fe792 /Software/Visual_Studio
parentc326bf5d9c1290ecc79739a1938c0a75b276f552 (diff)
downloadTango-13e34402f91fae6229b2d9719ddb48ced1d37fbf.tar.gz
Tango-13e34402f91fae6229b2d9719ddb48ced1d37fbf.zip
Some fixed and improvements.
Diffstat (limited to 'Software/Visual_Studio')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs1
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml6
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml8
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Resources/BuildDate.txt2
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs8
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs21
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml32
-rw-r--r--Software/Visual_Studio/Tango.BL/EntitiesExtensions/Contact.cs8
-rw-r--r--Software/Visual_Studio/Tango.BL/EntitiesExtensions/Job.cs14
-rw-r--r--Software/Visual_Studio/Tango.BL/EntitiesExtensions/User.cs25
-rw-r--r--Software/Visual_Studio/Tango.BL/IObservableEntity.cs10
-rw-r--r--Software/Visual_Studio/Tango.BL/ObservableEntity.cs98
-rw-r--r--Software/Visual_Studio/Tango.Core/Commands/RelayCommand.cs2
14 files changed, 173 insertions, 64 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
index dacbc89b1..b4e588700 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
@@ -1478,6 +1478,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
seg.SegmentIndex = 1;
}
+
ActiveJob.Segments.Add(seg);
SelectedSegment = seg;
AddBrushStop();
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml
index fc62c0128..b4deb72a9 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml
@@ -1085,7 +1085,7 @@
<Grid Margin="0 -18 0 0">
<Border VerticalAlignment="Center" Height="55" Margin="30 0 40 0" ClipToBounds="False">
<Grid ClipToBounds="False">
- <ItemsControl x:Name="jobBrushList" ClipToBounds="False">
+ <ItemsControl x:Name="jobBrushList" ClipToBounds="False" Margin="40 0 50 0">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" ClipToBounds="False"></StackPanel>
@@ -1129,7 +1129,7 @@
</ItemsControl.ItemTemplate>
</ItemsControl>
- <StackPanel Margin="-20 -5 0 0" HorizontalAlignment="Left">
+ <StackPanel Margin="-30 -5 0 0" HorizontalAlignment="Left">
<TextBlock FontSize="12" Foreground="Black">
<Run Text="0"></Run>
<Run Foreground="Gray" FontSize="10" Text="m"></Run>
@@ -1149,7 +1149,7 @@
</materialDesign:PackIcon>
</StackPanel>
- <Border BorderBrush="Gainsboro" BorderThickness="1" VerticalAlignment="Bottom" Height="20">
+ <Border BorderBrush="Gainsboro" BorderThickness="1" VerticalAlignment="Bottom" Height="20" Margin="40 0 50 0">
</Border>
</Grid>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml
index 2ece5c76b..fd3b2289d 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml
@@ -110,7 +110,7 @@
<Border Margin="0 10 0 0" VerticalAlignment="Bottom" Width="1200" BorderBrush="#404040" BorderThickness="0" ClipToBounds="False">
<Grid ClipToBounds="False" >
- <ItemsControl ClipToBounds="False" x:Name="runningJobBrushList" ItemsSource="{Binding RunningJobSegments}">
+ <ItemsControl ClipToBounds="False" x:Name="runningJobBrushList" ItemsSource="{Binding RunningJobSegments}" Margin="0 0 60 0">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" ClipToBounds="False"></StackPanel>
@@ -179,7 +179,7 @@
</Canvas>
</StackPanel>
- <Rectangle HorizontalAlignment="Right" Stroke="White" Margin="0 35 0 25"></Rectangle>
+ <Rectangle HorizontalAlignment="Right" Stroke="White" Margin="0 35 0 25" ></Rectangle>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
@@ -195,7 +195,7 @@
</materialDesign:PackIcon>
</StackPanel>
- <StackPanel Margin="0 -5 -40 0" HorizontalAlignment="Right">
+ <StackPanel Margin="0 -5 -70 0" HorizontalAlignment="Right">
<TextBlock FontSize="14">
<Run Text="{Binding RunningJob.Length,Mode=OneWay,StringFormat=N2}"></Run>
<Run FontSize="13" Text="m"></Run>
@@ -207,7 +207,7 @@
</materialDesign:PackIcon>
</StackPanel>
- <Border BorderBrush="#404040" BorderThickness="1" VerticalAlignment="Center" Height="30" Margin="0 11 0 0">
+ <Border BorderBrush="#404040" BorderThickness="1" VerticalAlignment="Center" Height="30" Margin="0 11 60 0">
</Border>
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Resources/BuildDate.txt b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Resources/BuildDate.txt
index 53eb632e9..a112fbafb 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Resources/BuildDate.txt
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Resources/BuildDate.txt
@@ -1 +1 @@
-Mon 07/16/2018 10:23:46.28
+Mon 07/16/2018 15:39:26.63
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
index fd28d5b1e..a7762a5e6 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
@@ -444,9 +444,9 @@ namespace Tango.MachineStudio.UI.ViewModels
{
try
{
- if (!x.SelectedMachine.EnableDiagnostics)
+ if (x.SelectedMachine.EnableDiagnostics)
{
- x.SelectedMachine.EnableEmbeddedDebugging = false;
+ x.SelectedMachine.EnableEmbeddedDebugging = true;
}
await x.SelectedMachine.Connect();
@@ -484,9 +484,9 @@ namespace Tango.MachineStudio.UI.ViewModels
{
try
{
- if (!x.SelectedMachine.EnableDiagnostics)
+ if (x.SelectedMachine.EnableDiagnostics)
{
- x.SelectedMachine.EnableEmbeddedDebugging = false;
+ x.SelectedMachine.EnableEmbeddedDebugging = true;
}
await x.SelectedMachine.Connect();
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs
index 92c9b4b94..0b53974d2 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs
@@ -248,9 +248,12 @@ namespace Tango.PPC.Jobs.ViewModels
/// </summary>
private async void SaveJob()
{
- await _db.SaveChangesAsync();
- RaiseMessage(new JobSavedMessage() { Job = Job });
- await NotificationProvider.ShowInfo(String.Format("Job '{0}' saved successfully.", Job.Name));
+ if (Job.Validate(_db))
+ {
+ await _db.SaveChangesAsync();
+ RaiseMessage(new JobSavedMessage() { Job = Job });
+ await NotificationProvider.ShowInfo(String.Format("Job '{0}' saved successfully.", Job.Name));
+ }
}
/// <summary>
@@ -471,7 +474,7 @@ namespace Tango.PPC.Jobs.ViewModels
{
Thread.Sleep(500);
- if (Job != null && IsVisible)
+ if (Job != null && IsVisible && (Job.ColorSpace != null && Job.ColorSpace.Code == BL.Enumerations.ColorSpaces.RGB.ToInt32()))
{
var brushStops = Job.Segments.SelectMany(x => x.BrushStops).Where(x => !x.Corrected && !x.OutOfGamutChecked).ToList();
@@ -481,10 +484,13 @@ namespace Tango.PPC.Jobs.ViewModels
stop.OutOfGamutChecked = true;
}
- InvokeUI(() =>
+ if (brushStops.Count > 0)
{
- DyeCommand.RaiseCanExecuteChanged();
- });
+ InvokeUI(() =>
+ {
+ DyeCommand.RaiseCanExecuteChanged();
+ });
+ }
}
}
}
@@ -520,6 +526,7 @@ namespace Tango.PPC.Jobs.ViewModels
_db = ObservablesContext.CreateDefault();
Job = await _db.Jobs.SingleOrDefaultAsync(x => x.Guid == _job_to_load.Guid);
+ Job.ValidateOnPropertyChanged = true;
Rmls = await _db.Rmls.ToListAsync();
ColorSpaces = await _db.ColorSpaces.ToListAsync();
SpoolTypes = await _db.SpoolTypes.ToListAsync();
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml
index 656b0b33a..a9aebb068 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml
@@ -365,7 +365,7 @@
<controls:TableGrid RowHeight="50">
<TextBlock>Job name:</TextBlock>
- <touch:TouchTextBox Text="{Binding Job.Name,UpdateSourceTrigger=PropertyChanged}" KeyboardMode="AlphaNumeric" KeyboardAction="Next" KeyboardContainer="{Binding ElementName=Container}" />
+ <touch:TouchTextBox Text="{Binding Job.Name,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True,ValidatesOnNotifyDataErrors=True}" KeyboardMode="AlphaNumeric" KeyboardAction="Next" KeyboardContainer="{Binding ElementName=Container}" />
<TextBlock>Customer:</TextBlock>
<touch:TouchAutoComplete Text="{Binding CustomersFilter}" ItemsSource="{Binding Customers}" SelectedItem="{Binding Job.Customer}" DisplayMemberPath="Name" AutoCompleteProvider="{Binding CustomersAutoCompleteProvider}" KeyboardMode="AlphaNumeric" KeyboardAction="Next" KeyboardContainer="{Binding ElementName=Container}" />
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml
index 3aa6e0118..7f1c1a115 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml
@@ -26,8 +26,8 @@
<Grid>
<touch:TouchSideMenu x:Name="menu" IsOpened="{Binding IsMenuOpened,Mode=TwoWay}" Grid.Row="1">
<touch:TouchSideMenu.MenuContent>
- <Border x:Name="border" BorderThickness="0 0 1 0" BorderBrush="{StaticResource TangoDividerBrush}">
- <DockPanel LastChildFill="False" Background="{StaticResource TangoPrimaryBackgroundBrush}">
+ <Border x:Name="border" BorderThickness="0 0 1 0" BorderBrush="{StaticResource TangoDividerBrush}" TextElement.Foreground="{StaticResource TangoLightForegroundBrush}">
+ <DockPanel LastChildFill="False" Background="#D9151515">
<StackPanel MinWidth="300" DockPanel.Dock="Top">
<Grid>
<touch:TouchToggleButton Style="{StaticResource TangoTouchToggleButtonHamburger}"
@@ -61,21 +61,21 @@
</StackPanel>
</Grid>
<StackPanel Margin="0 16 0 0">
- <touch:TouchButton Style="{StaticResource TangoFlatButton}" Command="{Binding HomeCommand}">
- <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
- <fa:ImageAwesome VerticalAlignment="Center" Icon="Home" Width="32" Height="32"></fa:ImageAwesome>
- <TextBlock FontSize="16" VerticalAlignment="Center" Margin="10 0 0 0">Home</TextBlock>
+ <touch:TouchButton Style="{StaticResource TangoFlatButton}" Foreground="{StaticResource TangoLightForegroundBrush}" FontWeight="Normal" Command="{Binding HomeCommand}" FontSize="{StaticResource TangoHeaderFontSize}">
+ <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
+ <!--<fa:ImageAwesome VerticalAlignment="Center" Icon="Home" Width="48" Height="48"></fa:ImageAwesome>-->
+ <TextBlock VerticalAlignment="Center" Margin="0 0 0 0">Home</TextBlock>
</StackPanel>
</touch:TouchButton>
</StackPanel>
- <ItemsControl ItemsSource="{Binding ModuleLoader.UserModules}" Margin="0 20 0 0">
+ <ItemsControl ItemsSource="{Binding ModuleLoader.UserModules}">
<ItemsControl.ItemTemplate>
<DataTemplate>
- <touch:TouchButton Style="{StaticResource TangoFlatButton}" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.ModuleNavigationCommand}" CommandParameter="{Binding Name}">
- <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
- <Image VerticalAlignment="Center" Source="{Binding Image}" Width="32" Height="32"></Image>
- <TextBlock FontSize="16" VerticalAlignment="Center" Margin="10 0 0 0" Text="{Binding Name}"></TextBlock>
+ <touch:TouchButton Margin="0 30 0 0" FontWeight="Normal" Foreground="{StaticResource TangoLightForegroundBrush}" Style="{StaticResource TangoFlatButton}" FontSize="{StaticResource TangoHeaderFontSize}" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.ModuleNavigationCommand}" CommandParameter="{Binding Name}">
+ <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
+ <!--<Image VerticalAlignment="Center" Source="{Binding Image}" Width="48" Height="48"></Image>-->
+ <TextBlock VerticalAlignment="Center" Margin="0 0 0 0" Text="{Binding Name}"></TextBlock>
</StackPanel>
</touch:TouchButton>
</DataTemplate>
@@ -84,11 +84,11 @@
</StackPanel>
<StackPanel DockPanel.Dock="Bottom">
- <Separator Margin="0 10 0 0" Background="Gainsboro" />
- <touch:TouchButton Style="{StaticResource TangoFlatButton}" Command="{Binding SignOutCommand}">
- <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
- <fa:ImageAwesome VerticalAlignment="Center" Icon="SignOut" Width="32" Height="32"></fa:ImageAwesome>
- <TextBlock FontSize="16" VerticalAlignment="Center" Margin="10 0 0 0">Sign Out</TextBlock>
+ <Separator Margin="0 10 0 0" Background="#505050" />
+ <touch:TouchButton Style="{StaticResource TangoFlatButton}" Padding="30" Command="{Binding SignOutCommand}" FontSize="{StaticResource TangoHeaderFontSize}" Foreground="{StaticResource TangoLightForegroundBrush}">
+ <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
+ <touch:TouchIcon VerticalAlignment="Center" Angle="180" Icon="Logout" Width="32" Height="32"></touch:TouchIcon>
+ <TextBlock VerticalAlignment="Center" Margin="10 0 0 0">Sign Out</TextBlock>
</StackPanel>
</touch:TouchButton>
</StackPanel>
diff --git a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Contact.cs b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Contact.cs
index 26f0329b0..8dcfda32d 100644
--- a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Contact.cs
+++ b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Contact.cs
@@ -34,18 +34,18 @@ namespace Tango.BL.Entities
FullName = FirstName + " " + LastName;
}
- public override void Validate(ObservablesContext context)
+ protected override void OnValidating(ObservablesContext context)
{
- base.Validate(context);
+ base.OnValidating(context);
if (FirstName.IsNullOrWhiteSpace() || LastName.IsNullOrWhiteSpace())
{
- throw new ArgumentException("Contact first name and last name was not provided.");
+ InsertError(nameof(FirstName), "Contact first name and last name was not provided.");
}
if (!Email.IsEmail())
{
- throw new ArgumentException("Invalid contact email format.");
+ InsertError(nameof(Email), "Invalid contact email format.");
}
}
}
diff --git a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Job.cs b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Job.cs
index 0c5a72bd8..e5144386a 100644
--- a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Job.cs
+++ b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Job.cs
@@ -379,5 +379,19 @@ namespace Tango.BL.Entities
}
#endregion
+
+ #region Validation
+
+ protected override void OnValidating(ObservablesContext context)
+ {
+ base.OnValidating(context);
+
+ if (String.IsNullOrWhiteSpace(Name))
+ {
+ InsertError(nameof(Name), "Job name is required");
+ }
+ }
+
+ #endregion
}
}
diff --git a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/User.cs b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/User.cs
index 0d1e864ee..6c1b03145 100644
--- a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/User.cs
+++ b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/User.cs
@@ -85,37 +85,34 @@ namespace Tango.BL.Entities
}
}
- public override void Validate(ObservablesContext context)
+ public override bool Validate(ObservablesContext context)
{
+ return base.Validate(context) && Contact.Validate(context) && Address.Validate(context);
+ }
+
+ protected override void OnValidating(ObservablesContext context)
+ {
+ base.OnValidating(context);
+
var users = context.Users.ToList();
if (users.Exists(x => x.Guid != Guid && x.Email.ToLower() == Email.ToLower()))
{
- throw new ArgumentException("The specified email is already taken by another account.");
+ InsertError(nameof(Email), "The specified email is already taken by another account.");
}
if (!Email.IsEmail())
{
- throw new ArgumentException("The specified email address is invalid.");
+ InsertError(nameof(Email), "The specified email address is invalid.");
}
if (_passwordGatewayModified)
{
if (!PasswordGateWay.IsBetweenLength(4, 30))
{
- throw new ArgumentException("A user password must be at least 4 characters long and maximum 30.");
+ InsertError(nameof(PasswordGateWay), "A user password must be at least 4 characters long and maximum 30.");
}
}
-
- if (Contact != null)
- {
- Contact.Validate(context);
- }
-
- if (Address != null)
- {
- Address.Validate(context);
- }
}
/// <summary>
diff --git a/Software/Visual_Studio/Tango.BL/IObservableEntity.cs b/Software/Visual_Studio/Tango.BL/IObservableEntity.cs
index dcb7ad5da..d83f3a6b2 100644
--- a/Software/Visual_Studio/Tango.BL/IObservableEntity.cs
+++ b/Software/Visual_Studio/Tango.BL/IObservableEntity.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
@@ -13,7 +14,7 @@ namespace Tango.BL
/// <summary>
/// Represents an observable database entity.
/// </summary>
- public interface IObservableEntity : IParameterized
+ public interface IObservableEntity : INotifyDataErrorInfo, IParameterized
{
/// <summary>
/// Occurs after this observable has been saved.
@@ -85,13 +86,6 @@ namespace Tango.BL
Task DeleteCascadeAsync(ObservablesContext context);
/// <summary>
- /// Performs entity field validation.
- /// Will throw an exception with the proper message if one of the fields is invalid.
- /// </summary>
- /// <param name="context">The context.</param>
- void Validate(ObservablesContext context);
-
- /// <summary>
/// Gets the database set containing this entity.
/// </summary>
/// <typeparam name="T"></typeparam>
diff --git a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs
index 7c82d927b..99d7360ef 100644
--- a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs
+++ b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs
@@ -22,6 +22,7 @@ using Tango.Serialization;
using System.Xml.Serialization;
using Newtonsoft.Json;
using Tango.Logging;
+using System.ComponentModel;
namespace Tango.BL
{
@@ -35,6 +36,7 @@ namespace Tango.BL
public abstract class ObservableEntity<T> : ExtendedObject, IObservableEntity where T : class, IObservableEntity
{
private Regex regExDAL;
+ private List<KeyValuePair<String, String>> _currentErrors = new List<KeyValuePair<string, string>>(); //Holds the current validation errors.
/// <summary>
/// Occurs after this observable has been saved.
@@ -323,9 +325,36 @@ Maybe you have deleted an entity that was no yet inserted into database?", LogCa
/// Will throw an exception with the proper message if one of the fields is invalid.
/// </summary>
/// <param name="context">The context.</param>
- public virtual void Validate(ObservablesContext context)
+ public virtual bool Validate(ObservablesContext context)
{
+ HasErrors = false;
+ _currentErrors.Clear();
+ if (ValidationErrors == null)
+ {
+ ValidationErrors = new ObservableCollection<string>();
+ }
+
+ ValidationErrors.Clear();
+
+ OnValidating(context);
+
+ foreach (var prop in this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
+ {
+ foreach (var validation in prop.GetCustomAttributes<ValidationAttribute>())
+ {
+ if (!validation.IsValid(prop.GetValue(this)))
+ {
+ _currentErrors.Add(new KeyValuePair<string, string>(prop.Name, validation.ErrorMessage));
+ ValidationErrors.Add(validation.ErrorMessage);
+ }
+ }
+
+ HasErrors = _currentErrors.Count > 0;
+ RaiseError(prop.Name);
+ }
+
+ return !HasErrors;
}
public DbSet<T1> GetDbSet<T1>(ObservablesContext context) where T1 : class, IObservableEntity
@@ -333,6 +362,73 @@ Maybe you have deleted an entity that was no yet inserted into database?", LogCa
return GetDbSet(context) as DbSet<T1>;
}
+ public IEnumerable GetErrors(string propertyName)
+ {
+ return _currentErrors.Where(x => x.Key == propertyName).Select(x => x.Value).ToList();
+ }
+
+ protected virtual void OnValidating(ObservablesContext context)
+ {
+
+ }
+
+ protected void InsertError(String propName, String error)
+ {
+ _currentErrors.Add(new KeyValuePair<string, string>(propName, error));
+ }
+
+ private bool _validateOnPropertyChanged;
+ [NotMapped]
+ public bool ValidateOnPropertyChanged
+ {
+ get { return _validateOnPropertyChanged; }
+ set { _validateOnPropertyChanged = value; RaisePropertyChangedAuto(); }
+ }
+
+
+ /// <summary>
+ /// Invoked the <see cref="ErrorsChanged"/> event.
+ /// </summary>
+ /// <param name="propName">Name of the property.</param>
+ protected void RaiseError(String propName)
+ {
+ ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propName));
+ }
+
+ private bool _hasErrors;
+ /// <summary>
+ /// Gets a value that indicates whether the entity has validation errors.
+ /// </summary>
+ [NotMapped]
+ public bool HasErrors
+ {
+ get { return _hasErrors; }
+ set { _hasErrors = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ObservableCollection<String> _validationErrors;
+ /// <summary>
+ /// Gets or sets the validation errors.
+ /// </summary>
+ [NotMapped]
+ public ObservableCollection<String> ValidationErrors
+ {
+ get { return _validationErrors; }
+ protected set { _validationErrors = value; RaisePropertyChangedAuto(); }
+ }
+
+ public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
+
+ protected override void RaisePropertyChanged(string propName)
+ {
+ base.RaisePropertyChanged(propName);
+
+ if (ValidateOnPropertyChanged)
+ {
+ Validate(null);
+ }
+ }
+
#region Operator Overloading
//public static bool operator ==(ObservableEntity<T> observable1, ObservableEntity<T> observable2)
diff --git a/Software/Visual_Studio/Tango.Core/Commands/RelayCommand.cs b/Software/Visual_Studio/Tango.Core/Commands/RelayCommand.cs
index 761038284..b3964d1e0 100644
--- a/Software/Visual_Studio/Tango.Core/Commands/RelayCommand.cs
+++ b/Software/Visual_Studio/Tango.Core/Commands/RelayCommand.cs
@@ -40,7 +40,7 @@ namespace Tango.Core.Commands
}
- public RelayCommand(Action action, Func<bool> canExecuteChange) : this((x) => action(), new Func<object, bool>((x) => true))
+ public RelayCommand(Action action, Func<bool> canExecute) : this((x) => action(), canExecute)
{
}