aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels
diff options
context:
space:
mode:
authorVictoria Plitt <Victoria.Plitt@twine-s.com>2019-12-22 11:27:51 +0200
committerVictoria Plitt <Victoria.Plitt@twine-s.com>2019-12-22 11:27:51 +0200
commit8c3ab6389c3ba0d5bfefc151cd6718016ea9cf44 (patch)
treee280a4df15077f02f9b9efd972a3350929db428a /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels
parentd0ad477ecc3b4de354aee900e1b5335bc31ab103 (diff)
parentcd670d0404673efd095ae2baec1873b916c49c81 (diff)
downloadTango-8c3ab6389c3ba0d5bfefc151cd6718016ea9cf44.tar.gz
Tango-8c3ab6389c3ba0d5bfefc151cd6718016ea9cf44.zip
MERGE
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs38
1 files changed, 36 insertions, 2 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
index 9939e4876..5c55892ba 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
@@ -21,12 +21,18 @@ using Tango.MachineStudio.RML.Views;
using Tango.PMR.ColorLab;
using System.Data.Entity;
using Tango.Core.ExtensionMethods;
+using Tango.MachineStudio.Common.Authentication;
+using Tango.BL.ActionLogs;
+using Tango.BL.DTO;
namespace Tango.MachineStudio.RML.ViewModels
{
public class MainViewVM : StudioViewModel<IMainView>
{
private INotificationProvider _notification;
+ private IAuthenticationProvider _authentication;
+ private IActionLogManager _actionLogManager;
+ private RmlDTO _rmlBeforeSave;
private ObservablesContext _rmls_context;
private ObservablesContext _active_context;
@@ -185,9 +191,11 @@ namespace Tango.MachineStudio.RML.ViewModels
public RelayCommand ImportRMLFileCommand { get; set; }
- public MainViewVM(INotificationProvider notificationProvider)
+ public MainViewVM(INotificationProvider notificationProvider, IAuthenticationProvider authentication, IActionLogManager actionLogManager)
{
_notification = notificationProvider;
+ _authentication = authentication;
+ _actionLogManager = actionLogManager;
ManageRmlCommand = new RelayCommand(() => LoadActiveRML(SelectedRML.Guid), () => SelectedRML != null);
RemoveRmlCommand = new RelayCommand(RemoveSelectedRml, () => SelectedRML != null);
CloneRmlCommand = new RelayCommand(CloneSelectedRml, () => SelectedRML != null);
@@ -334,6 +342,8 @@ namespace Tango.MachineStudio.RML.ViewModels
LiquidTypesRmls = LiquidTypesRmls,
};
+ _rmlBeforeSave = RmlDTO.FromObservable(ActiveRML);
+
View.NavigateTo(RmlNavigationView.RmlView);
InvalidateRelayCommands();
@@ -423,6 +433,9 @@ namespace Tango.MachineStudio.RML.ViewModels
_active_context.ProcessParametersTables.Add(group.ProcessParametersTables[0]);
_active_context.Rmls.Add(rml);
await _active_context.SaveChangesAsync();
+
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlCreated, _authentication.CurrentUser, rml.Name, rml, "Rml created using Machine Studio.");
+
LoadActiveRML(rml.Guid);
IsFree = true;
@@ -432,7 +445,7 @@ namespace Tango.MachineStudio.RML.ViewModels
private async void RemoveSelectedRml()
{
- if (_notification.ShowQuestion("Removing the selected RML will result in the loss of all related process parameters and default calibration data. Are you sure you want to delete the selected RML?"))
+ if (_notification.ShowQuestion("Removing the selected thread will result in the loss of all related process parameters and default calibration data. Are you sure you want to delete the selected RML?"))
{
IsFree = false;
@@ -440,7 +453,18 @@ namespace Tango.MachineStudio.RML.ViewModels
{
try
{
+ var rml_jobs = await _rmls_context.Jobs.Where(x => x.RmlGuid == SelectedRML.Guid).Include(x => x.Machine).OrderBy(x => x.Machine.SerialNumber).ToListAsync();
+
+ if (rml_jobs.Count > 0)
+ {
+ _notification.ShowError($"The following jobs must be removed or change thread type before the selected thread can be deleted:\n{String.Join("\n",rml_jobs.Select(x => $"{x.Machine.SerialNumber} => {x.Name}"))}");
+ return;
+ }
+
await SelectedRML.DeleteCascadeAsync(_rmls_context);
+
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlDeleted, _authentication.CurrentUser, SelectedRML.Name, SelectedRML, "RML deleted from Machine Studio.");
+
LoadRmls();
}
catch (Exception ex)
@@ -504,6 +528,8 @@ namespace Tango.MachineStudio.RML.ViewModels
context.Rmls.Add(cloned);
await context.SaveChangesAsync();
+
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlCreated, _authentication.CurrentUser, cloned.Name, cloned, "RML cloned from Machine Studio.");
}
LoadRmls();
@@ -665,7 +691,13 @@ namespace Tango.MachineStudio.RML.ViewModels
}
}
+ var rmlAfter = RmlDTO.FromObservable(ActiveRML);
+
await _active_context.SaveChangesAsync();
+
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlSaved, _authentication.CurrentUser, _rmlBeforeSave.Name, _rmlBeforeSave, rmlAfter, "RML saved using Machine Studio.");
+
+ _rmlBeforeSave = rmlAfter;
}
}
catch (Exception ex)
@@ -804,6 +836,8 @@ namespace Tango.MachineStudio.RML.ViewModels
var rmlFile = await Rml.FromRmlFile(db, json);
db.Rmls.Add(rmlFile);
+
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlImported, _authentication.CurrentUser, rmlFile.Name, rmlFile, "RML imported from Machine Studio.");
}
await db.SaveChangesAsync();