Beispiel #1
0
		public OperatorManagerVm(Dal.SoheilEdmContext uow)
		{
			_uow = uow;
			//OperatorsList.Add(OperatorEditorVm.CreateAnonymous());
			#region get all operators and convert them to VM
			OperatorDataService = new DataServices.OperatorDataService(_uow);
			var allOperators = OperatorDataService.GetActives();
			foreach (var oper in allOperators)
			{
				var operVm = new OperatorEditorVm(oper);

				//Notify
				// Add|Remove selected|deselected operator in vm
				operVm.SelectedOperatorChanged += Operator_SelectedOperatorChanged;

				//Updates role in uow
				operVm.OperatorRoleChanged += Operator_RoleChanged;

				OperatorsList.Add(operVm);
			} 
			#endregion

			#region init commands
			ClearSearchCommand = new Commands.Command(textBox =>
			{
				if (textBox is System.Windows.Controls.TextBox)
					(textBox as System.Windows.Controls.TextBox).Clear();
			});

			RefreshCommand = new Commands.Command(o => refresh()); 
			#endregion
		}
Beispiel #2
0
		void Operator_SelectedOperatorChanged(OperatorEditorVm operVm, bool isSelected, bool updateCount)
		{
			if(Process == null || Activity == null || Block == null)
			{
				if (ErrorOccured != null)
					ErrorOccured("ابتدا فعالیت را انتخاب کنید");
				//operVm.IsSelected = false;
				return;
			}
			if (Process.ProcessReports.Any())
			{
				if (ErrorOccured != null)
					ErrorOccured("این فعالیت گزارش دارد");
				//operVm.IsSelected = false;
			}
			else
			{
				//find ProcessOperator in uow
				var poModel = Process.ProcessOperators.FirstOrDefault(x => x.Operator.Id == operVm.OperatorId);
				//add/remove them
				if (poModel == null)
				{
					if (isSelected)
					{
						//if not exist but selected, add it to uow
						poModel = new Model.ProcessOperator
						{
							Operator = operVm.OperatorModel,
							Process = Process,
							Code = Process.Code + operVm.Code,
						};
						Process.ProcessOperators.Add(poModel);
					}
				}
				else
				{
					if (!isSelected)
					{
						//if exist but not selected, remove it from uow
						Process.ProcessOperators.Remove(poModel);
						new Dal.Repository<Model.ProcessOperator>(_uow).Delete(poModel);
					}
				}
			}
			//notify about selection (to update operators quicklist and SelectedOperatorsCount in process)
			if (SelectionChanged != null)
				SelectionChanged(operVm, isSelected, updateCount);

			//update OperatorsSelectedList
			if (isSelected)
			{
				if (!OperatorsSelectedList.Any(x => x.OperatorId == operVm.OperatorId))
					OperatorsSelectedList.Add(operVm);
			}
			else
			{
				OperatorsSelectedList.Remove(operVm);
			}
		}
Beispiel #3
0
		//Selection is for user selection only (not automatic selection)
		void OperatorManager_SelectionChanged(OperatorEditorVm vm, bool isSelected, bool updateCount)
		{
			//update quick list
			var activityVm = ActivityList.FirstOrDefault(x => x.Id == OperatorManager.Activity.Id);
			if (activityVm != null)
			{
				var processVm = activityVm.ProcessList.FirstOrDefault(x => x.Model == OperatorManager.Process);
				if (processVm != null)
				{
					if (isSelected)
					{
						if (!processVm.SelectedOperators.Any(x => x.OperatorId == vm.OperatorId))
							processVm.SelectedOperators.Add(vm);
					}
					else
					{
						var operVm = processVm.SelectedOperators.FirstOrDefault(x => x.OperatorId == vm.OperatorId);
						if (operVm != null)
							processVm.SelectedOperators.Remove(operVm);
					}
				}
			}
		}