Exemple #1
0
		void initOperatorManager()
		{
			OperatorManager = new OperatorManagerVm(_uow);
			//update operators quicklist (readonly list inside a process rectangle)
			//also update SelectedOperatorsCount of a process
			OperatorManager.SelectionChanged += OperatorManager_SelectionChanged;
			OperatorManager.ErrorOccured += OperatorManager_ErrorOccured;
		}
Exemple #2
0
		/// <summary>
		/// Must be called with an open connection
		/// </summary>
		/// <param name="model"></param>
		internal TaskEditorVm(Model.Task model, Dal.SoheilEdmContext uow)
		{
			Model = model;
			_uow = uow;
            initializeCommands();
			OperatorManager = new OperatorManagerVm(_uow);

			// Adds|Removes the selected|deselected operator in model
			// Changes SelectedOperatorsCount in vm
			OperatorManager.SelectionChanged += (operatorVm, isSelected, updateCount) =>
			{
				if (SelectedProcess == null) return;
				if (isSelected)
				{
					if (!SelectedProcess.Model.ProcessOperators.Any(x => x.Operator.Id == operatorVm.OperatorId))
						SelectedProcess.Model.ProcessOperators.Add(new Model.ProcessOperator
						{
							Process = SelectedProcess.Model,
							Operator = operatorVm.OperatorModel,
							Role = operatorVm.Role,
							Code = model.Code + operatorVm.Code,
						});
					if(updateCount)
						SelectedProcess.SelectedOperatorsCount++;
				}
				else
				{
					var po = SelectedProcess.Model.ProcessOperators.FirstOrDefault(x => x.Operator.Id == operatorVm.OperatorId);
					if (po != null) SelectedProcess.Model.ProcessOperators.Remove(po);
					if (updateCount)
						SelectedProcess.SelectedOperatorsCount--;
				}
			};

			//Updates Role in model
			OperatorManager.RoleChanged += (operatorVm, role) =>
			{
				if (SelectedProcess == null) return;
				var po = SelectedProcess.Model.ProcessOperators.FirstOrDefault(x => x.Operator.Id == operatorVm.OperatorId);
				if (po == null)
					MessageBox.Show("Is not selected");
				else
					po.Role = role;
			};

			StartDate = model.StartDateTime.Date;
			StartTime = model.StartDateTime.TimeOfDay;

            //subValues
			TaskTargetPoint = model.TaskTargetPoint;
			DurationSeconds = model.DurationSeconds;

			#region Auto check RadioButtons
			if (!model.Processes.Any())
			{
				IsDeferToActivitiesSelected = true;
			}
			else if (model.Processes.AreAllEqual(x => x.TargetCount))
			{
				SameQtyForActivities = model.Processes.FirstOrDefault().TargetCount;
				IsSameQtyForActivitiesSelected = true;
			}
			// if all processes have same duration then
			//		DurationOfProcess = TP * CT
			//		=> DurationOfTask = TP * CT + d, where (0 <= d < CT)
			//		=> d = DurationOfTask - TP * CT
			//		=> 0 <= (DurationOfTask - TP * CT)/CT < 1
			else if (model.Processes.Select(
				p => (DurationSeconds - p.TargetCount * p.StateStationActivity.CycleTime) / (float)p.StateStationActivity.CycleTime)
				.All(diff => 0 <= diff && diff < 1f))
			{
				SameTimeForActivities = TimeSpan.FromSeconds(model.Processes.Max(p => p.TargetCount * p.StateStationActivity.CycleTime));
				IsSameTimeForActivitiesSelected = true;
			}
			else
			{
				IsDeferToActivitiesSelected = true;
			} 
			#endregion

			RebuildProcesses();
		}