/// <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(); // }); // } //}; }
/// <summary> /// Zooms to fit the given block in screen /// </summary> /// <param name="blockVm"></param> public void ZoomToBlock(BlockVm blockVm) { var start = blockVm.StartDateTime; HoursPassed = start.GetPersianDayOfMonth() * 24 + start.Hour + start.Minute / 60d + start.Second / 3600d - 24; HourZoom = (GridWidth * 3600) / blockVm.DurationSeconds; }