Example #1
0
		void reloadFromModel()
		{
			//update model from database with new UOW
			Model = new Dal.Repository<Model.NonProductiveTask>(UOW).OfType<Model.Setup>().Single(x => x.Id == _id);
			
			if(_startBackup == DateTime.MinValue)
				_startBackup = Model.StartDateTime;

			StartDateTime = Model.StartDateTime;
			EndDateTime = Model.EndDateTime;
			DurationSeconds = Model.DurationSeconds;
			RowIndex = Model.Warmup.Station.Index;

			ChangeoverId = Model.Changeover.Id;
			ChangeoverSeconds = Model.Changeover.Seconds;

			WarmupId = Model.Warmup.Id;
			WarmupSeconds = Model.Warmup.Seconds;

			FromProduct = new ViewModels.PP.ProductReworkVm(Model.Changeover.FromProductRework);
			ToProduct = new ViewModels.PP.ProductReworkVm(Model.Changeover.ToProductRework);
		}
Example #2
0
		private void initCommands()
		{
			SaveCommand = new Commands.Command(o =>
			{
				try
				{
					PromptSave();
					ParentWindowVm.fpcDataService.stateDataService.AttachModel(Model);
				}
				catch (Common.SoheilException.SoheilExceptionBase exp)
				{
					string msg = "";
					if (exp.Level == Common.SoheilException.ExceptionLevel.Error)
						msg += "قادر به ذخیره مرحله نیست\n";
					msg += exp.Message;
					ParentWindowVm.Message = new Common.SoheilException.DependencyMessageBox(msg, exp.Caption, MessageBoxButton.OK, exp.Level);
				}
				catch (Exception exp)
				{
					ParentWindowVm.Message = new Common.SoheilException.DependencyMessageBox(exp);
				}
			});

			DeleteCommand = new Commands.Command(o =>
			{
				try
				{
					//check for constraints
					var entity = new Dal.Repository<Model.State>(new Dal.SoheilEdmContext()).Single(x => x.Id == Id);
					if (entity != null && entity.StateStations.Any(ss => ss.Blocks.Any()))
					{
						ParentWindowVm.Message = new Common.SoheilException.DependencyMessageBox("این مرحله (بعضی از ایستگاهها) در برنامه تولید استفاده شده است", "Error", MessageBoxButton.OK, Common.SoheilException.ExceptionLevel.Error);
						return;
					}

					var connectors = ParentWindowVm.Connectors.Where(x => x.Start.Id == Id || x.End.Id == Id).ToList();
					ParentWindowVm.fpcDataService.stateDataService.DeleteModel(Model);

					//notify deletion (to remove state and its connectors from parent)
					if (StateDeleted != null) StateDeleted(connectors);
				}
				catch (Common.SoheilException.SoheilExceptionBase exp)
				{
					string msg = "";
					if (exp.Level == Common.SoheilException.ExceptionLevel.Error)
						msg += "قادر به حذف مرحله نیست\n";
					msg += exp.Message;
					ParentWindowVm.Message = new Common.SoheilException.DependencyMessageBox(msg, exp.Caption, MessageBoxButton.OK, exp.Level);
				}
				catch (Exception exp)
				{
					ParentWindowVm.Message = new Common.SoheilException.DependencyMessageBox(exp);
				}
			});

			SelectCommand = new Command(o =>
			{
				if (StateSelected != null) StateSelected();
			});
		}
Example #3
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;
				}
			});
		}
Example #4
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;
				}
			});
		}
Example #5
0
		/// <summary>
		/// Removes this StateStation from State
		/// </summary>
		public override void Delete()
		{
			//check for constraints
			var entity = new Dal.Repository<Model.StateStation>(new Dal.SoheilEdmContext()).Single(x => x.Id == Id);
			if (entity != null && entity.Blocks.Any())
			{
				ContainerS.Parent.Message = new Common.SoheilException.DependencyMessageBox("این مرحله (همین ایستگاه) در برنامه تولید استفاده شده است", "Error", MessageBoxButton.OK, Common.SoheilException.ExceptionLevel.Error);
				return;
			}
			//delete
			Container.ContentsList.Remove(this);
		}