From 3fdcdac577d552bbdf6d7320c6ffb0753e810a08 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 10 Dec 2017 19:01:05 +0200 Subject: Started working on machine designer view models. Added NAME field to MACHINE table. --- .../Visual_Studio/Tango.Core/ExtendedObject.cs | 10 ++++ .../ExtensionMethods/IEnumerableExtensions.cs | 22 ++++++++ .../Visual_Studio/Tango.Core/Tango.Core.csproj | 1 + .../Tango.DAL.Observables/Entities/Machine.cs | 19 +++++++ .../Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs | 1 + .../Tango.DAL.Remote/DB/RemoteADO.edmx | 3 ++ .../Tango.DAL.Remote/DB/RemoteADO.edmx.diagram | 58 +++++++++++----------- Software/Visual_Studio/Tango.sln | 1 - .../Utilities/Tango.MachineDesigner.UI/App.config | 18 +++++-- .../Utilities/Tango.MachineDesigner.UI/App.xaml.cs | 6 +++ .../Tango.MachineDesigner.UI/DBAdapter.cs | 20 ++++++++ .../Tango.MachineDesigner.UI/EntityViewModel.cs | 30 +++++++++++ .../SupervisingController/IMachinesView.cs | 14 ------ .../Tango.MachineDesigner.UI.csproj | 18 ++++++- .../Tango.MachineDesigner.UI/ViewModelLocator.cs | 13 +++-- .../ViewModels/MachinesViewVM.cs | 41 +++++++++++++-- .../Views/MachinesView.xaml | 36 ++++++++++++-- .../Views/MachinesView.xaml.cs | 2 +- .../Tango.MachineDesigner.UI/Views/MainView.xaml | 2 +- .../Tango.MachineDesigner.UI/packages.config | 1 + 20 files changed, 254 insertions(+), 62 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Core/ExtensionMethods/IEnumerableExtensions.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/DBAdapter.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/EntityViewModel.cs delete mode 100644 Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/SupervisingController/IMachinesView.cs (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/Tango.Core/ExtendedObject.cs b/Software/Visual_Studio/Tango.Core/ExtendedObject.cs index 84a73bf7c..8ac80034d 100644 --- a/Software/Visual_Studio/Tango.Core/ExtendedObject.cs +++ b/Software/Visual_Studio/Tango.Core/ExtendedObject.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -31,6 +32,15 @@ namespace Tango.Core PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName)); } + /// + /// Raises the property changed event. + /// + /// Name of the property. + protected virtual void RaisePropertyChangedAuto([CallerMemberName] string caller = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(caller)); + } + /// /// Raises all relay commands CanExecute methods in the current instance. /// diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/IEnumerableExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/IEnumerableExtensions.cs new file mode 100644 index 000000000..0e430e631 --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/IEnumerableExtensions.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +public static class IEnumerableExtensions +{ + /// + /// Creates a new observable collection from the specified enumerable. + /// + /// + /// The enumerable. + /// + public static ObservableCollection ToObservableCollection(this IEnumerable enumerable) + { + return new ObservableCollection(enumerable); + } +} + diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index 7af35f628..fd3eeddf9 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -59,6 +59,7 @@ + diff --git a/Software/Visual_Studio/Tango.DAL.Observables/Entities/Machine.cs b/Software/Visual_Studio/Tango.DAL.Observables/Entities/Machine.cs index bdbe5d67d..3e6e08889 100644 --- a/Software/Visual_Studio/Tango.DAL.Observables/Entities/Machine.cs +++ b/Software/Visual_Studio/Tango.DAL.Observables/Entities/Machine.cs @@ -29,6 +29,25 @@ namespace Tango.DAL.Observables } + private String _name; + /// + /// Gets or sets the machine name. + /// + [EntityFieldName("NAME")] + public String Name + { + get + { + return _name; + } + + set + { + _name = value; RaisePropertyChanged(nameof(Name)); + } + + } + private DateTime _productiondate; /// /// Gets or sets the machine production date. diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs index 97c84a140..496f3b645 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs @@ -26,6 +26,7 @@ namespace Tango.DAL.Remote.DB public System.DateTime LAST_UPDATED { get; set; } public bool DELETED { get; set; } public string SERIAL_NUMBER { get; set; } + public string NAME { get; set; } public System.DateTime PRODUCTION_DATE { get; set; } public string ORGANIZATION_GUID { get; set; } public string MACHINE_VERSION_GUID { get; set; } diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx index 6dc1ad1ed..68b43ba94 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx @@ -288,6 +288,7 @@ + @@ -1734,6 +1735,7 @@ + @@ -2774,6 +2776,7 @@ + diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram index 390be5547..cce34f3fb 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram @@ -5,46 +5,46 @@ - - - + + + - - - - + + + + - + - - - - - - - + + + + + + + - + - + - + - - - - - - - + + + + + + + - - + + - - + + diff --git a/Software/Visual_Studio/Tango.sln b/Software/Visual_Studio/Tango.sln index 6551f2c0b..60c58b76b 100644 --- a/Software/Visual_Studio/Tango.sln +++ b/Software/Visual_Studio/Tango.sln @@ -440,7 +440,6 @@ Global {8491D07B-C1F6-4B62-A412-41B9FD2D6538}.Release|x86.ActiveCfg = Release|Any CPU {8491D07B-C1F6-4B62-A412-41B9FD2D6538}.Release|x86.Build.0 = Release|Any CPU {0ECD6DA8-7AA6-48D9-8B65-279D176AD9AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0ECD6DA8-7AA6-48D9-8B65-279D176AD9AF}.Debug|Any CPU.Build.0 = Debug|Any CPU {0ECD6DA8-7AA6-48D9-8B65-279D176AD9AF}.Debug|x64.ActiveCfg = Debug|Any CPU {0ECD6DA8-7AA6-48D9-8B65-279D176AD9AF}.Debug|x64.Build.0 = Debug|Any CPU {0ECD6DA8-7AA6-48D9-8B65-279D176AD9AF}.Debug|x86.ActiveCfg = Debug|Any CPU diff --git a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/App.config b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/App.config index 8324aa6ff..92aa00bf9 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/App.config +++ b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/App.config @@ -1,6 +1,16 @@ - + - - - + + +
+ + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/App.xaml.cs b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/App.xaml.cs index 04e61e96b..7b4aa8b01 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/App.xaml.cs +++ b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/App.xaml.cs @@ -13,5 +13,11 @@ namespace Tango.MachineDesigner.UI ///
public partial class App : Application { + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + + DBAdapter.Initialize(); + } } } diff --git a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/DBAdapter.cs b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/DBAdapter.cs new file mode 100644 index 000000000..e628db850 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/DBAdapter.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.DAL.Remote.DB; +using Tango.Settings; + +namespace Tango.MachineDesigner.UI +{ + public class DBAdapter + { + public static RemoteDB DbContext { get; set; } + + public static void Initialize() + { + DbContext = new RemoteDB(SettingsManager.Default.DataBase.SQLServerAddress, false); + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/EntityViewModel.cs b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/EntityViewModel.cs new file mode 100644 index 000000000..a580098eb --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/EntityViewModel.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.SharedUI; + +namespace Tango.MachineDesigner.UI +{ + public class EntityViewModel : ViewModel + { + private T _entity; + + public T Entity + { + get { return _entity; } + set { _entity = value; RaisePropertyChanged(nameof(Entity)); } + } + + public EntityViewModel() : base() + { + + } + + public EntityViewModel(T entity) : this() + { + Entity = entity; + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/SupervisingController/IMachinesView.cs b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/SupervisingController/IMachinesView.cs deleted file mode 100644 index ba676c925..000000000 --- a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/SupervisingController/IMachinesView.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.SharedUI; - -namespace Tango.MachineDesigner.UI.SupervisingController -{ - public interface IMachinesView : IView - { - - } -} diff --git a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Tango.MachineDesigner.UI.csproj b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Tango.MachineDesigner.UI.csproj index 7f291de85..b0cce92a0 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Tango.MachineDesigner.UI.csproj +++ b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Tango.MachineDesigner.UI.csproj @@ -40,6 +40,12 @@ ..\..\packages\Dragablz.0.0.3.197\lib\net45\Dragablz.dll + + ..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll + + + ..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll + ..\..\packages\FontAwesome.WPF.4.7.0.9\lib\net40\FontAwesome.WPF.dll @@ -65,6 +71,7 @@ ..\..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll + ..\..\packages\MvvmLightLibs.5.3.0.0\lib\net45\System.Windows.Interactivity.dll @@ -87,7 +94,8 @@ MSBuild:Compile Designer - + + @@ -158,6 +166,10 @@ {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core + + {0ecd6da8-7aa6-48d9-8b65-279d176ad9af} + Tango.DAL.Observables + {38197109-8610-4d3f-92b9-16d48df94d7c} Tango.DAL.Remote @@ -166,6 +178,10 @@ {bc932dbd-7cdb-488c-99e4-f02cf441f55e} Tango.Logging + + {d8f1ad85-526a-4f50-b6dc-d437af63d8d8} + Tango.Settings + {8491d07b-c1f6-4b62-a412-41b9fd2d6538} Tango.SharedUI diff --git a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModelLocator.cs b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModelLocator.cs index 6b8bc5aea..5d26a3e21 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModelLocator.cs @@ -33,17 +33,14 @@ namespace Tango.MachineDesigner.UI //// SimpleIoc.Default.Register(); ////} - LogManager.Log("Registering MainView View Model..."); SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); //Register View (Supervising Controller Pattern). if (!ViewModelBase.IsInDesignModeStatic) { LogManager.Log(String.Format("Registering Supervising Controller {0}...", nameof(IMainView))); SimpleIoc.Default.Register(() => (IMainView)MainView.Self); - - LogManager.Log(String.Format("Registering Supervising Controller {0}...", nameof(IMachinesView))); - SimpleIoc.Default.Register(() => (IMachinesView)MainView.Self); } } @@ -54,5 +51,13 @@ namespace Tango.MachineDesigner.UI return ServiceLocator.Current.GetInstance(); } } + + public MachinesViewVM MachinesViewVM + { + get + { + return ServiceLocator.Current.GetInstance(); + } + } } } \ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModels/MachinesViewVM.cs b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModels/MachinesViewVM.cs index 6d2cddda6..88a62dff8 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModels/MachinesViewVM.cs +++ b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/ViewModels/MachinesViewVM.cs @@ -1,18 +1,53 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; -using Tango.MachineDesigner.UI.SupervisingController; +using Tango.DAL.Observables; using Tango.SharedUI; namespace Tango.MachineDesigner.UI.ViewModels { - public class MachinesViewVM : ViewModel + public class MachinesViewVM : ViewModel { - public MachinesViewVM(IMachinesView view) : base(view) + private ObservableCollection _machines; + /// + /// Gets or sets the machines. + /// + public ObservableCollection Machines { + get { return _machines; } + set { _machines = value; RaisePropertyChangedAuto(); } + } + + private ObservableCollection _organizations; + /// + /// Gets or sets the organizations. + /// + public ObservableCollection Organizations + { + get { return _organizations; } + set { _organizations = value; RaisePropertyChangedAuto(); } + } + private Machine _selectedMachine; + /// + /// Gets or sets the selected machine. + /// + public Machine SelectedMachine + { + get { return _selectedMachine; } + set { _selectedMachine = value; RaisePropertyChangedAuto(); } + } + + /// + /// Initializes a new instance of the class. + /// + public MachinesViewVM() : base() + { + Organizations = DBAdapter.DbContext.ORGANIZATIONS.Where(x => !x.DELETED).ToList().Select(x => new Organization(x)).ToObservableCollection(); + Machines = DBAdapter.DbContext.MACHINES.Where(x => !x.DELETED).ToList().Select(x => new Machine(x)).ToObservableCollection(); } } } diff --git a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Views/MachinesView.xaml b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Views/MachinesView.xaml index c85f03682..0bbf3a285 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Views/MachinesView.xaml +++ b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Views/MachinesView.xaml @@ -1,4 +1,4 @@ - + d:DesignHeight="720" d:DesignWidth="1280" Background="White" DataContext="{Binding MachinesViewVM, Source={StaticResource Locator}}"> - + + + + + + + + + + + + + + + + + + + + + + + + Name + + Organization + + + - + diff --git a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Views/MachinesView.xaml.cs b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Views/MachinesView.xaml.cs index ebab90278..3b0013051 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Views/MachinesView.xaml.cs +++ b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Views/MachinesView.xaml.cs @@ -19,7 +19,7 @@ namespace Tango.MachineDesigner.UI.Views /// /// Interaction logic for MachinesView.xaml /// - public partial class MachinesView : View + public partial class MachinesView : UserControl { public MachinesView() : base() { diff --git a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Views/MainView.xaml b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Views/MainView.xaml index 510ffd0c3..76048199b 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/Views/MainView.xaml @@ -63,7 +63,7 @@ - Hello World + Material Design diff --git a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/packages.config b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/packages.config index 08bc64f62..05f5d8725 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/packages.config +++ b/Software/Visual_Studio/Utilities/Tango.MachineDesigner.UI/packages.config @@ -2,6 +2,7 @@ + -- cgit v1.3.1