Exemplo n.º 1
0
		public PPItemManager(Dispatcher dispatcher)
		{
			_dispatcher = dispatcher;
			IsAutoRefresh = true;
			_instances.Add(this);

			//initialize cache
			var stations = new DataServices.StationDataService().GetActives();
			if (stations.Any())
				_stations = stations.Max(x => x.Index)+1;
			else
				_stations = 0;
			_blocks = new List<PPItemBlock>[_stations];
			_npts = new List<PPItemNpt>[_stations];
			for (int i = 0; i < _stations; i++)
			{
				_blocks[i] = new List<PPItemBlock>();
				_npts[i] = new List<PPItemNpt>();
			}
			_shifts = new List<PPItemWorkTime>();


			//initialize qTimer and actions
			initializeActions();

			//start the thread
			Pause = false;
		}
Exemplo n.º 2
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);
		}
Exemplo n.º 3
0
		/// <summary>
		/// Resets the timeline to Now, loads PPItems in range and loads Stations
		/// <para>This method is using _initialTimer so its body will be run with a 10ms delay</para>
		/// </summary>
		public void ResetTimeLine()
		{
			//exit if loaded once
			if (_initialTimer != null) return;

			_initialTimer = new System.Threading.Timer(new System.Threading.TimerCallback
				(t => Dispatcher.Invoke(() =>
				{
					_suppressUpdateRange = true;
					//initialize DateTimes
					var currentDate = Arash.PersianDate.Today.ToDateTime();
					var startDate = currentDate.GetNorooz();

					//initialize Timeline components
					Days = new DayCollection();
					Months = new MonthCollection(startDate);
					Months.SelectedMonthChanged += month => SelectedMonth = month;
					Hours = new HourCollection();

					//initialize PPItems
					PPItems = new PPItemCollection(this);
					PPItems.Manager.DayColorsUpdated += (startingDate, colors) =>
					{
						//refetch it, if selected month is changed after fetch
						if (SelectedMonth.Data != startingDate)
						{
							PPItems.Manager.InitMonth(SelectedMonth.Data);
							return;
						}
						//colorize days
						for (int i = 0; i < colors.Length; i++)
						{
							Days[i].Color = colors[i];
						}
					};
					PPItems.Manager.WorkTimeAdded += item =>
					{
						var vms = Soheil.Core.ViewModels.OrganizationCalendar.WorkTimeRangeVm.CreateAuto(item);
						foreach (var vm in vms)
						{
							ShiftsAndBreaks.Add(vm);
						}
					};
					PPItems.Manager.WorkTimesRemoved += () =>
					{
						ShiftsAndBreaks.Clear();
					};
					PPItems.BlockAdded += vm =>
					{
						initializeCommands(vm);
					};
					PPItems.BlockRemoved += id =>
					{
						if (SelectedBlock != null && SelectedBlock.Id == id)
							SelectedBlock = null;
					};
					PPItems.NptAdded += vm =>
					{
						initializeCommands(vm);
					};
					PPItems.NptRemoved += id =>
					{
						if (SelectedNPT != null && SelectedNPT.Id == id)
							SelectedNPT = null;
					};


					//Initialize stations
					var stationModels = new DataServices.StationDataService().FixAndGetActives();
					NumberOfStations = stationModels.Count();
					foreach (var stationModel in stationModels)
					{
						PPItems.Add(new StationVm { Text = stationModel.Name });
					}

					//Set advanced timeline components
					SelectedMonth = Months[(int)currentDate.GetPersianMonth() - 1];
					HoursPassed = currentDate.Subtract(SelectedMonth.Data).TotalHours;
					if (currentDate.Year % 4 == 3)
					{
						HoursInYear = 8784;
						DaysInYear = 366;
					}
					else
					{
						HoursInYear = 8760;
						DaysInYear = 365;
					}

					//Loads PPItems
					_suppressUpdateRange = false;
					GoToNowCommand.Execute(null);
				})), null, _initialTimerInterval, System.Threading.Timeout.Infinite);
		}