Example #1
0
		/// <summary>
		/// Creates an instance of BlockEditor viewModel for an existing fpcState model
		/// </summary>
		/// <param name="stateModel">state model to create a block (can be obtained from a different context)</param>
		public BlockEditorVm(Model.State stateModel)
		{
			_uow = new Dal.SoheilEdmContext();
			_blockDataService = new DataServices.BlockDataService(_uow);
			Message = new Common.SoheilException.EmbeddedException();

			var stateEntity = new Soheil.Core.DataServices.StateDataService(_uow).GetSingle(stateModel.Id);
			State = new StateVm(stateEntity);
			SelectedStateStation = State.StateStationList.FirstOrDefault();
			EditorStartDate = DateTime.Now.Date;
			EditorStartTime = DateTime.Now.TimeOfDay;

			initOperatorManager();
			initializeCommands();
		}
Example #2
0
		/// <summary>
		/// Creates an instance of BlockEditor viewModel for an existing block model
		/// <para>Each instance has an exclusive uow</para>
		/// </summary>
		/// <param name="blockModel">block containing some (or no) tasks to edit (must be obtained from the same context)</param>
		public BlockEditorVm(Model.Block blockModel)
		{
			_isInitializing = true;
			_uow = new Dal.SoheilEdmContext();
			_blockDataService = new DataServices.BlockDataService(_uow);
			Message = new Common.SoheilException.EmbeddedException();

			//change context graph
			Model = _blockDataService.GetSingle(blockModel.Id);
			State = new StateVm(Model.StateStation.State);
			StateStation = State.StateStationList.First(x => x.StateStationId == Model.StateStation.Id);
            SelectedStateStation = StateStation;
			BlockTargetPoint = Model.BlockTargetPoint;

			initOperatorManager();
			initTask();
			initializeCommands();
			_isInitializing = false;
		}
Example #3
0
		public ActivityEditorVm(
			Model.Task task, 
			Dal.SoheilEdmContext uow,
			IGrouping<Model.Activity, Model.StateStationActivity> ssaGroup)
			: base(ssaGroup.Key)
		{
			Message = new Common.SoheilException.EmbeddedException();

			if (!ssaGroup.Any())
			{
				Message.AddEmbeddedException("فعالیتی وجود ندارد");
				return;
			}

			//make ProcessList self-aware of all changes
			ProcessList.CollectionChanged += (s, e) =>
			{
				if (e.NewItems != null)
					foreach (ProcessEditorVm processVm in e.NewItems)
					{
						ProcessList_Added(processVm);
					}
			};

			//Add Choices
			foreach (var choice in ssaGroup.OrderBy(ssa => ssa.ManHour))
			{
				Choices.Add(new ChoiceEditorVm(choice));
			}

			//Add existing processes
			foreach (var process in task.Processes.Where(x => x.StateStationActivity.Activity.Id == ssaGroup.Key.Id))
			{
				ProcessList.Add(new ProcessEditorVm(process, Model, uow));
			}

			//Add process command
			AddProcessCommand = new Commands.Command(o =>
			{
				
				DateTime dt;
				if (GetTaskStart == null)
					dt = ProcessList.Any() ?
						ProcessList
							.Where(x => x.ActivityModel.Id == ssaGroup.Key.Id)
							.Max(x => x.Model.EndDateTime)
						: task.StartDateTime;
				else
					dt = GetTaskStart();

				var minMH = ssaGroup.Min(x => x.ManHour);

				var processVm = new ProcessEditorVm(
					new Model.Process
					{
						StartDateTime = dt,
						EndDateTime = dt,
						StateStationActivity = ssaGroup.First(x=>x.ManHour == minMH),
						TargetCount = 0,
						Task = task,
					}, Model, uow);//activity Model is set here
				ProcessList.Add(processVm);
				processVm.IsSelected = true;
			});
		}
Example #4
0
		/// <summary>
		/// Creates an instance of PPEditorProcess with given model within the given PPEditorTask
		/// <para>Updates its choices and operators and machines as well</para>
		/// </summary>
		/// <param name="model"></param>
		public ProcessEditorVm(Model.Process model, Model.Activity activityModel, Dal.SoheilEdmContext uow)
		{
			_isInitializing = true;

			#region Basic
			_uow = uow;
			Model = model;
			ActivityModel = activityModel;
			HasReport = Model.ProcessReports.Any();
			Message = new Common.SoheilException.EmbeddedException();

			Timing = new TimingSet(this);
			Timing.DurationChanged += v => Model.DurationSeconds = v;
			Timing.StartChanged += v => Model.StartDateTime = v;
			Timing.EndChanged += v => Model.EndDateTime = v;
			Timing.TargetPointChanged += tp => Model.TargetCount = tp;
			Timing.TimesChanged += (start, end) =>
			{
				if (TimesChanged != null) TimesChanged(this, start, end);
			};
			#endregion

			#region Machines
			//SelectedMachines
			foreach (var sm in model.SelectedMachines)
			{
				var machineVm = new MachineEditorVm(sm);
				SelectedMachines.Add(machineVm);
			}
			NoSelectedMachines = !SelectedMachines.Any();

			//MachineFamilyList
			ShowAllMachinesCommand = new Commands.Command(o =>
			{
				if (Model.StateStationActivity == null)
				{
					Message.AddEmbeddedException("فعالیت یا نفرساعت آن نامعتبر است"); 
					return;
				}

				IsSelected = true;

				if (ShowAllMachines) return;
				ShowAllMachines = true;
				MachineFamilyList.Clear();

				//Load Model
				var ssams = new List<Model.StateStationActivityMachine>();
				foreach (var ssa in Model.StateStationActivity.StateStation.StateStationActivities)
				{
					ssams.AddRange(ssa.StateStationActivityMachines);
				}
				var machines = ssams.GroupBy(x => x.Machine);
				var machineFamilies = machines.GroupBy(x => x.Key.MachineFamily);

				//Create ViewModel
				foreach (var machineFamily in machineFamilies)
				{
					var machineFamilyVm = new MachineFamilyEditorVm(machineFamily);
					machineFamilyVm.SelectionChanged += (vm, val) =>
					{
						//add/remove SelectedMachines
						var sm = SelectedMachines.FirstOrDefault(x => x.MachineId == vm.MachineId);
						if (val && sm == null)
						{
							SelectedMachines.Add(vm);
						}
						else if (!val)
						{
							SelectedMachines.Remove(sm);
						}
						NoSelectedMachines = !SelectedMachines.Any();
					};

					//revalidate
					foreach (var machineVm in machineFamilyVm.MachineList)
					{
						machineVm.Revalidate(model);
						machineVm.IsUsed = SelectedMachines.Any(x => x.MachineId == machineVm.MachineId);
					}
					MachineFamilyList.Add(machineFamilyVm);
				}
			}); 
			#endregion

			//set operators after those 2, because when choice is selected we expect to have valid information in this vm
			#region Operators
			//select the right choice based on ManHour
			foreach (var oper in model.ProcessOperators)
			{
				SelectedOperators.Add(new OperatorVm(oper.Operator));
			}
			SelectedOperatorsCount = model.ProcessOperators.Count;
			SelectedOperators.CollectionChanged += (s, e) =>
			{
				SelectedOperatorsCount = SelectedOperators.Count;
				if (SelectedOperatorsCountChanged != null)
					SelectedOperatorsCountChanged(this, SelectedOperators.Count);
			};
			#endregion

			//command
			SelectCommand = new Commands.Command(o => IsSelected = true);
			DeleteCommand = new Commands.Command(o =>
			{
				var succeed = new DataServices.TaskDataService(uow).DeleteModel(Model, (bool)o);
				if (succeed)
				{
					//uow.Commit();
					if (Deleted != null) Deleted(this);
				}
				else
					Message.AddEmbeddedException("Activity has reports");
			});

			_isInitializing = false;
		}