Ejemplo n.º 1
0
		/// <summary>
		/// Removes a block from BlockList
		/// </summary>
		/// <param name="block"></param>
		public void RemoveBlock(BlockEditorVm block)
		{
			if (SelectedBlock != null && SelectedBlock.StateId == block.StateId)
			{
				SelectedBlock = null;
			}
			BlockList.Remove(block);
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Changes BlockList or SelectedBlock
		/// </summary>
		/// <param name="stateVm"></param>
		void FpcViewer_SelectedStateChanged(Fpc.StateVm stateVm)
		{
			var block = BlockList.FirstOrDefault(x => x.StateId == stateVm.Id);
			if (block == null)
			{
				//add to list
				block = new BlockEditorVm(stateVm.Model);
				BlockList.Add(block);
			}
			else
				//exists, select it (double click kind of thing)
				SelectedBlock = block;
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Initializes BlockVm commands of vm that can be assigned in this class
		/// </summary>
		/// <param name="vm"></param>
		void initializeCommands(BlockVm vm)
		{
			//Task editor
			vm.AddBlockToEditorCommand = new Commands.Command(o =>
			{
				try
				{
					var ppeBlock = new Editor.BlockEditorVm(vm.Model);
					TaskEditor.BlockList.Add(ppeBlock);
					TaskEditor.SelectedBlock = ppeBlock;
				}
				catch (Exception exp) { vm.Message.AddEmbeddedException(exp.Message); }
			}, () => vm.Model != null);
			vm.EditItemCommand = new Commands.Command(o =>
			{
				try
				{
					TaskEditor.Reset();
					TaskEditor.IsVisible = true;
					JobEditor.IsVisible = false;
					vm.AddBlockToEditorCommand.Execute(o);
				}
				catch (Exception exp) { vm.Message.AddEmbeddedException(exp.Message); }
			});
			//Job editor
			vm.AddJobToEditorCommand = new Commands.Command(o =>
			{
				try { JobEditor.Append(vm.Job); }
				catch (Exception exp) { vm.Message.AddEmbeddedException(exp.Message); }
			}, () =>
			{
				if (vm.Job == null) return false;
				if (vm.Job.Id == 0) return false;
				return true;
			});
			vm.EditJobCommand = new Commands.Command(o =>
			{
				try
				{
					TaskEditor.IsVisible = false;
					JobEditor.IsVisible = true;
					JobEditor.Reset();
					vm.AddJobToEditorCommand.Execute(o);
				}
				catch (Exception exp) { vm.Message.AddEmbeddedException(exp.Message); }
			}, () =>
			{
				if (vm.Job == null) return false;
				if (vm.Job.Id == 0) return false;
				return true;
			});


			vm.DeleteJobCommand = new Commands.Command(o =>
			{
				lock (PPItems.Manager)
				{
					try
					{
						new DataServices.JobDataService().DeleteModel(vm.Job.Model);
						RemoveBlocks(vm.Job);
					}
					catch (RoutedException exp)
					{
						if (exp.Target is TaskVm)
							(exp.Target as TaskVm).Message.AddEmbeddedException(exp.Message);
						else //if(exp.Target is BlockVm)
							vm.Message.AddEmbeddedException(exp.Message);
					}
					catch (Exception exp) { vm.Message.AddEmbeddedException(exp.Message); }
				}
			}, () => { return vm.Job != null; });

			//report
			vm.EditReportCommand = new Commands.Command(o =>
			{
				try
				{
					vm.BlockReport = new Report.BlockReportVm(vm);
					vm.BlockReport.ProcessReportBuilderChanged += val => CurrentProcessReportBuilder = val;
					SelectedBlock = vm;
				}
				catch (Exception exp) { vm.Message.AddEmbeddedException(exp.Message); }
			});
			//EditReportCommand reloads *ALL* reports for its block 
			//vm.TaskList.CollectionChanged += (s, e) =>
			//{
			//	if (e.NewItems != null)
			//		foreach (var task in e.NewItems.OfType<TaskVm>())
			//		{
			//			if (task != null)
			//				task.EditReportCommand = new Commands.Command(o =>
			//				{
			//					SelectedBlock = vm;
			//					vm.ReloadReports();
			//				});
			//		}
			//};
		}