Beispiel #1
0
		/// <summary>
		/// Creates a report for the given block, fills all process reports
		/// </summary>
		/// <param name="block"></param>
		public BlockReportVm(BlockVm vm)
		{
			_parent = vm;
			UOW = new Dal.SoheilEdmContext();
			TaskDataService = new DataServices.TaskDataService(UOW);
			ProcessReportDataService = new DataServices.ProcessReportDataService(UOW);
			entity = new DataServices.BlockDataService(UOW).GetSingle(vm.Id);

			ReloadReports();
		}
Beispiel #2
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;
		}