Пример #1
0
		public SetupTimeTableVm(AccessType access)
		{
			Access = access;
			CanEdit = (int)access >= (int)AccessType.Update;

			RefreshAllCommand = new Commands.Command(o =>
			{
				var models = new DataServices.StationDataService().GetActives();
				foreach (var model in models)
				{
					Stations.Add(new Station(model));
				}
				if (Stations.Any())
				{
					if (SelectedStation != null)
					{
						SelectedStation = Stations.FirstOrDefault(x => x.Id == SelectedStation.Id);
					}
				}
			});

			RefreshAllCommand.Execute(null);
		}
Пример #2
0
		void initializeCommands()
		{
			ChangeStationCommand = new Commands.Command(o =>
			{
				if (Model != null)
					try { _blockDataService.DeleteModelRecursive(Model); }
					catch { }
				ActivityList.Clear();

				StateStation = SelectedStateStation;
				Model = new Model.Block
				{
					Code = StateStation.Code,
					StateStation = StateStation.Model,
					StartDateTime = DateTime.Now.Date.AddHours(DateTime.Now.Hour),
					EndDateTime = DateTime.Now.Date.AddHours(DateTime.Now.Hour),
					DurationSeconds = 0,
					ModifiedBy = LoginInfo.Id,
				};

				initTask();
			});
			DontChangeStationCommand = new Commands.Command(o =>
			{
				SelectedStateStation = StateStation;
				Model.StateStation = StateStation.Model;
			});
			DeleteBlockFromList = new Commands.Command(vm =>
			{
				var planEditor = vm as PlanEditorVm;
				if (planEditor != null) planEditor.RemoveBlock(this);
			});
			SelectTodayCommand = new Commands.Command(o => StartDateForAll = DateTime.Now.Date);
			SelectTomorrowCommand = new Commands.Command(o => StartDateForAll += TimeSpan.FromDays(1));
			SelectThisHourCommand = new Commands.Command(o =>
			{
				SelectTodayCommand.Execute(o);
				StartTime = TimeSpan.FromHours(DateTime.Now.Hour);
			});
			AddOneHourCommand = new Commands.Command(o =>
			{
				StartTime = StartTime.Add(TimeSpan.FromHours(1));
				if (StartTime.CompareTo(TimeSpan.FromDays(1)) >= 1)
				{
					StartTime = StartTime.Add(TimeSpan.FromHours(-24));
					StartDate = StartDate.AddDays(1);
				}
			});
			SubtractOneHourCommand = new Commands.Command(o =>
			{
				if (StartTime.CompareTo(TimeSpan.FromHours(1)) < 1)
				{
					StartTime = StartTime.Add(TimeSpan.FromHours(23));
					StartDate = StartDate.AddDays(-1);
				}
				else
					StartTime = StartTime.Add(TimeSpan.FromHours(-1));
			});
			SetStartForAllCommand = new Commands.Command(o =>
			{
				var start = StartDateForAll.Add(StartTimeForAll);
				var end = DateTime.MinValue;
				foreach (var act in ActivityList)
				{
					foreach (var process in act.ProcessList)
					{
						if (!process.HasReport)
							process.Timing.StartDateTime = start;
						if (process.Timing.EndDateTime > end)
							end = process.Timing.EndDateTime;
					}
				}
				StartDate = start.Date;
				StartTime = start.TimeOfDay;
				EndDate = end.Date;
				EndTime = end.TimeOfDay;
				Duration = end - start;
			});
			SetOffsetForAllCommand = new Commands.Command(o =>
			{
				var start = DateTime.MaxValue;
				var end = DateTime.MinValue;
				var offset = o == null ? StartOffsetForAll : -StartOffsetForAll;
				foreach (var act in ActivityList)
				{
					foreach (var process in act.ProcessList)
					{
						if (!process.HasReport)
							process.Timing.StartDateTime += offset;
						if (process.Timing.StartDateTime < start)
							start = process.Timing.StartDateTime; 
						if (process.Timing.EndDateTime > end)
							end = process.Timing.EndDateTime;
					}
				}
				StartDate = start.Date;
				StartTime = start.TimeOfDay;
				EndDate = end.Date;
				EndTime = end.TimeOfDay;
				Duration = end - start;
			});
		}