Exemplo n.º 1
0
		public StoppageReportVm(StoppageReportCollection parent, Model.StoppageReport model)
		{
			Model = model;
			Index = parent.Parent.StoppageReports.List.Count + 1;
			Parent = parent;
			
			int[] causeIds = null;
			if (model.Cause != null)
				if (model.Cause.Parent != null)
					if (model.Cause.Parent.Parent != null)
						causeIds = new int[3] { model.Cause.Parent.Parent.Id, model.Cause.Parent.Id, model.Cause.Id };
			StoppageLevels = FilterBoxVmCollection.CreateForStoppageReport(this, causeIds);

			GuiltyOperators = FilterBoxVmCollection.CreateForGuiltyOperators(model.OperatorStoppageReports, Parent.Parent.UOW);
			var osrRepo = new Dal.Repository<Model.OperatorStoppageReport>(Parent.Parent.UOW);
			GuiltyOperators.OperatorSelected += (vm, oldOp, newOp) =>
			{
				if (newOp.Model == null) return;
				//update model
				if (vm.Model == null)
				{
					//create and add new OSR
					var osr = new Model.OperatorStoppageReport
					{
						StoppageReport = model,
						Operator = newOp.Model,
						ModifiedBy = LoginInfo.Id,
					};
					osrRepo.Add(osr);
					vm.Model = osr;
				}
				else
				{
					//update existing OSR
					(vm.Model as Model.OperatorStoppageReport).Operator = newOp.Model;
				}
			};
			GuiltyOperators.OperatorRemoved += vm =>
			{
				if (vm.Model != null)
				{
					model.OperatorStoppageReports.Remove((vm.Model as Model.OperatorStoppageReport));
					osrRepo.Delete((vm.Model as Model.OperatorStoppageReport));
				}
			};

			AffectsTaskReport = model.AffectsTaskReport;
			LostSeconds = model.LostTime;
			LostCount = model.LostCount;
			Description = model.Description;

			DeleteCommand = new Commands.Command(o => 
			{
				//correct sums
				Parent.SumOfLostCount -= LostCount;
				Parent.SumOfLostTime-= LostSeconds;
				Parent.SumOfTimeEquivalent -= TimeEquivalent;
				Parent.SumOfCountEquivalent -= QuantityEquivalent;
				
				//delete
				Parent.List.Remove(this);
				Model.ProcessReport.StoppageReports.Remove(Model);
				new DataServices.ProcessReportDataService(Parent.Parent.UOW).Delete(Model);

				//reset indices
				for (int i = 0; i < Parent.List.Count; i++)
				{
					Parent.List[i].Index = i + 1;
				}
			});
		}
Exemplo n.º 2
0
		public DefectionReportVm(DefectionReportCollection parent, Model.DefectionReport model)
		{

			Model = model;
			Index = parent.Parent.DefectionReports.List.Count + 1;
			Parent = parent;
			IsG2 = model.IsG2;

			ProductDefection = FilterBoxVm.CreateForProductDefections(
				model.ProductDefection == null ? -1 : model.ProductDefection.Id, 
				model.ProcessReport.Process.StateStationActivity.StateStation.State.FPC.Product.Id);
			var pdrepo = new Dal.Repository<Model.ProductDefection>(Parent.Parent.UOW);
			ProductDefection.FilterableItemSelected += (s, old, v) => 
				Model.ProductDefection = pdrepo.FirstOrDefault(x => x.Id == v.Id);
			if (ProductDefection.SelectedItem == null) ProductDefection.SelectedItem = ProductDefection.FilteredList.FirstOrDefault();

			//create and load OperatorDefectionReports
			GuiltyOperators = FilterBoxVmCollection.CreateForGuiltyOperators(model.OperatorDefectionReports, Parent.Parent.UOW);
			var odrRepo = new Dal.Repository<Model.OperatorDefectionReport>(Parent.Parent.UOW);
			GuiltyOperators.OperatorSelected += (vm, oldOp, newOp) =>
			{
				if (newOp.Model == null) return;

				if (vm.Model == null)
				{
					//create and add new ODR
					var odr = new Model.OperatorDefectionReport
					{
						DefectionReport = model,
						Operator = newOp.Model,
						ModifiedBy = LoginInfo.Id,
					};
					odrRepo.Add(odr);
					vm.Model = odr;
				}
				else
				{
					//update existing ODR
					(vm.Model as Model.OperatorDefectionReport).Operator = newOp.Model;
				}
			};
			GuiltyOperators.OperatorRemoved += vm =>
			{
				if (vm.Model != null)
				{
					model.OperatorDefectionReports.Remove(vm.Model as Model.OperatorDefectionReport);
					odrRepo.Delete(vm.Model as Model.OperatorDefectionReport);
				}
			};
	
			AffectsTaskReport = model.AffectsTaskReport;
			LostSeconds = model.LostTime;
			LostCount = model.LostCount;
			Description = model.Description;
			
			DeleteCommand = new Commands.Command(o => 
			{
				//correct sums
				Parent.SumOfLostCount -= LostCount;
				Parent.SumOfLostTime-= LostSeconds;
				Parent.SumOfTimeEquivalent -= TimeEquivalent;
				Parent.SumOfCountEquivalent -= QuantityEquivalent;

				//delete
				Parent.List.Remove(this);
				Model.ProcessReport.DefectionReports.Remove(Model);
				new DataServices.ProcessReportDataService(Parent.Parent.UOW).Delete(Model);

				//reset indices
				for (int i = 0; i < Parent.List.Count; i++)
				{
					Parent.List[i].Index = i + 1;
				}
			});
		}