Beispiel #1
0
		/// <summary>
		/// Instantiates an instance of SkillCenterVm and initializes its DataServices and Commands and loads basic data
		/// </summary>
		public SkillCenterVm(AccessType access)
		{
			Access = access;
			CanEdit = (int)Access >= (int)AccessType.Update;
			Message = new EmbeddedException();
			InitializeData();
			initializeCommands();
		}
Beispiel #2
0
		/// <summary>
		/// Creates a ViewModel for the given ProcessReport with given row and column
		/// </summary>
		/// <param name="model">if null, it automatically assign unreported process space</param>
		public ProcessReportVm(Model.ProcessReport model, Dal.SoheilEdmContext uow)
		{
			Model = model;
			Message = new EmbeddedException();
			try
			{
				ActivityName = model.Process.StateStationActivity.Activity.Name;
				ProductName = model.Process.StateStationActivity.StateStation.State.FPC.Product.Name;
				ProductColor = model.Process.StateStationActivity.StateStation.State.FPC.Product.Color;
			}
			catch { }

			//uow
			UOW = uow;
			_processReportDataService = new DataServices.ProcessReportDataService(UOW);
			_taskReportDataService = new DataServices.TaskReportDataService(UOW);

			//properties
			//Model.ProducedG1 = Model.OperatorProcessReports.Sum(x => x.OperatorProducedG1);//??? can be different than sum
			ProducedG1 = Model.ProducedG1;
			Timing = new TimingSet(this);
			Timing.Saved += () => Save();
			Timing.DurationChanged += v => Model.DurationSeconds = v;
			Timing.StartChanged += v => Model.StartDateTime = v;
			Timing.EndChanged += v => Model.EndDateTime = v;
			Timing.TargetPointChanged += tp =>
			{
				TargetPointForOperator = Model.OperatorProcessReports.Any() ?
					string.Format("{0:F2}", (float)tp / Model.OperatorProcessReports.Count) :
					"---";
				Model.ProcessReportTargetPoint = tp;
				updateEmptyCount(tp: tp);
			};
			TargetPointForOperator = Model.OperatorProcessReports.Any() ?
				string.Format("{0:F2}", (float)Model.ProcessReportTargetPoint / Model.OperatorProcessReports.Count) :
				"---";
			//reports
			OperatorReports = new OperatorReportCollection(this);
			DefectionReports = new DefectionReportCollection(this);
			DefectionCount = (int)Model.DefectionReports.Sum(x => x.CountEquivalence);
			StoppageReports = new StoppageReportCollection(this);
			StoppageCount = (int)Model.StoppageReports.Sum(x => x.CountEquivalence);

			IsUserDrag = false;
			_isInInitializingPhase = false;
			initializeCommands();
		}
Beispiel #3
0
		public TaskVm(Model.Task taskModel, Dal.SoheilEdmContext uow)
		{
			//data service
			UOW = uow;
			_taskReportDataService = new DataServices.TaskReportDataService(UOW);
			
			Message = new EmbeddedException();

			//update model data
			Model = taskModel;
			StartDateTime = taskModel.StartDateTime;
			StartDateTimeChanged += newVal => Model.StartDateTime = newVal;
			DurationSeconds = taskModel.DurationSeconds;
			DurationSecondsChanged += newVal => Model.DurationSeconds = newVal;
			//TaskTargetPoint = taskModel.TaskTargetPoint;
			TaskProducedG1 = taskModel.TaskReports.Sum(x => x.TaskProducedG1);

			//this non-crucial block of code is likely to throw
			try
			{
				//calculate the number of distinct operators
				var ids = new List<int>();
				foreach (var item in taskModel.Processes)
				{
					ids.AddRange(item.ProcessOperators.Select(x => x.Operator.Id));
				}
				TaskOperatorCount = ids.Distinct().Count();
			}
			catch { TaskOperatorCount = -1; }///??? does happen?

			#region FillEmptySpaces Command
			FillEmptySpacesCommand = new Commands.Command(o =>
			{
				var models = Model.TaskReports.OrderBy(x => x.ReportStartDateTime).ToArray();
				var dt = StartDateTime;
				var tp = Model.TaskTargetPoint;
				if (models.Any()) tp -= models.Sum(x => x.TaskReportTargetPoint);

				//insert before each task report
				foreach (var model in models)
				{
					if (model.ReportStartDateTime - dt > TimeSpan.FromSeconds(1))
					{
						//insert taskReport newModel before model
						var duration = model.ReportStartDateTime - dt;
						var newModel = new Model.TaskReport
						{
							Task = Model,
							Code = Model.Code,
							ReportStartDateTime = dt,
							ReportEndDateTime = model.ReportStartDateTime,
							ReportDurationSeconds = (int)duration.TotalSeconds,
							TaskProducedG1 = 0,
							TaskReportTargetPoint = (int)(duration.TotalSeconds * Model.TaskTargetPoint / Model.DurationSeconds),
							CreatedDate = DateTime.Now,
							ModifiedDate = DateTime.Now,
							ModifiedBy = LoginInfo.Id,
						};
						Model.TaskReports.Add(newModel);
					}

					dt = model.ReportEndDateTime;
				}

				//insert after last task report
				if (Model.EndDateTime - dt > TimeSpan.FromSeconds(1))
				{
					//insert taskReport after last model
					var duration = Model.EndDateTime - dt;
					var newModel = new Model.TaskReport
					{
						Task = Model,
						Code = Model.Code,
						ReportStartDateTime = dt,
						ReportEndDateTime = Model.EndDateTime,
						ReportDurationSeconds = (int)duration.TotalSeconds,
						TaskProducedG1 = 0,
						TaskReportTargetPoint = (int)(duration.TotalSeconds * Model.TaskTargetPoint / Model.DurationSeconds),
						CreatedDate = DateTime.Now,
						ModifiedDate = DateTime.Now,
						ModifiedBy = LoginInfo.Id,
					};
					Model.TaskReports.Add(newModel);
				}

				//reload reports
				ReloadTaskReports();
			});
			#endregion

		}
Beispiel #4
0
		protected PPItemVm() { Message = new EmbeddedException(); }