예제 #1
0
		void initializeDataServices()
		{
			_uow = new Dal.SoheilEdmContext();
			_productGroupDs = new DataServices.ProductGroupDataService(_uow);
			_fpcDs = new DataServices.FPCDataService(_uow);
			_jobDs = new DataServices.JobDataService(_uow);
		}
예제 #2
0
		public OperatorManagerVm(Dal.SoheilEdmContext uow)
		{
			_uow = uow;
			//OperatorsList.Add(OperatorEditorVm.CreateAnonymous());
			#region get all operators and convert them to VM
			OperatorDataService = new DataServices.OperatorDataService(_uow);
			var allOperators = OperatorDataService.GetActives();
			foreach (var oper in allOperators)
			{
				var operVm = new OperatorEditorVm(oper);

				//Notify
				// Add|Remove selected|deselected operator in vm
				operVm.SelectedOperatorChanged += Operator_SelectedOperatorChanged;

				//Updates role in uow
				operVm.OperatorRoleChanged += Operator_RoleChanged;

				OperatorsList.Add(operVm);
			} 
			#endregion

			#region init commands
			ClearSearchCommand = new Commands.Command(textBox =>
			{
				if (textBox is System.Windows.Controls.TextBox)
					(textBox as System.Windows.Controls.TextBox).Clear();
			});

			RefreshCommand = new Commands.Command(o => refresh()); 
			#endregion
		}
예제 #3
0
		public SetupVm(int setupId, PPItemCollection parent) 
			: base(parent)
		{
			UOW = new Dal.SoheilEdmContext();
			_id = setupId;
			reloadFromModel();
			initializeCommands();
		}
예제 #4
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();
		}
예제 #5
0
		/// <summary>
		/// Creates an instance of <see cref="ProcessVm"/> for the given model
		/// </summary>
		public ProcessVm(Model.Process model, Dal.SoheilEdmContext uow)
		{
			Model = model;
			UOW = uow;
			StartDateTime = model.StartDateTime;
			DurationSeconds = model.DurationSeconds;
			TargetPoint = model.TargetCount;

			initializeCommands();
		}
예제 #6
0
		/// <summary>
		/// Reloads the NonProductiveTask full data keeping the current UOW
		/// </summary>
		public void Reload()
		{
			HasVm = false;

			if (UOW == null)
				UOW = new Dal.SoheilEdmContext();
			var nptDataService = new DataServices.NPTDataService(UOW);

			ModifiedDate = DateTime.MinValue;//???
			Model = nptDataService.GetSingle(Id);
			Start = Model.StartDateTime;
			End = Model.EndDateTime;
		}
예제 #7
0
		/// <summary>
		/// Reloads all jobs within current date range
		/// </summary>
		void reloadJobs()
		{
			using (var uow = new Dal.SoheilEdmContext())
			{
				var jobs = new DataServices.JobDataService(uow).GetInRange(StartDate, EndDate, ByDefinition);
				Jobs.Clear();
				foreach (var job in jobs)
				{
					var jobItemVm = new JobListItemVm(job);
					Jobs.Add(jobItemVm);
					jobItemVm.JobSelected += id => { if (JobSelected != null) JobSelected(jobItemVm); };
				}
			}
		}
예제 #8
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();
		}
예제 #9
0
		/// <summary>
		/// Initializes all commands and Shift colors and, at last, Loads data
		/// </summary>
		/// <param name="dataService"></param>
		private void InitializeData()
		{
			UOW = new Dal.SoheilEdmContext();
			WorkProfileDataService = new WorkProfileDataService(UOW);
			if (_model == null)
			{
				_model = WorkProfile.CreateDefault();
				WorkProfileDataService.AttachModel(_model);
			}
			else
				_model = WorkProfileDataService.GetSingle(_model.Id);


			SaveCommand = new Command(Save, CanSave);

			AskForIncreaseNumberOfShifts = new Command(o => IsPrototypeChangeAskVisible = true);
			IncreaseNumberOfShifts = new Command(o => { IsPrototypeChangeAskVisible = false; NumberOfShiftsModifier++; });

			ShiftColors.Add(new ShiftColorVm { Color = DefaultColors.Shift.Day });
			ShiftColors.Add(new ShiftColorVm { Color = DefaultColors.Shift.Evening });
			ShiftColors.Add(new ShiftColorVm { Color = DefaultColors.Shift.Night });
			ShiftColors.Add(new ShiftColorVm { Color = DefaultColors.Shift.Reserve1 });
			ShiftColors.Add(new ShiftColorVm { Color = DefaultColors.Shift.Reserve2 });
			ShiftColors.Add(new ShiftColorVm { Color = DefaultColors.Shift.Reserve3 });

			//fill vm with _model data
			Load();

			ShiftPrototypes.CollectionChanged += (s, e) =>
			{
				if (e.NewItems != null)
					foreach (WorkShiftPrototypeVm proto in e.NewItems)
					{
						_model.WorkShiftPrototypes.Add(proto.Model);
					}
				if (e.OldItems != null)
					foreach (WorkShiftPrototypeVm proto in e.OldItems)
					{
						_model.WorkShiftPrototypes.Remove(proto.Model);
					}
			};

		}
예제 #10
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;
		}
예제 #11
0
		public void Reload()
		{
			var pgModelList = new DataServices.ProductGroupDataService(null).GetActivesRecursive(Id);

			#region Reload Sync
			int col = 0;
			int row = 0;
			foreach (var pgModel in pgModelList)
			{
				if (!pgModel.Products.Any()) continue;

				//Add ProductGroup To ColumnHeaders
				var cpg = new ProductGroup(pgModel, this, isRowHeader: false);
				cpg.RowIndex = 0;
				cpg.ColumnIndex = col++;//pg itself is a column
				ColumnHeaders.Add(cpg);
				ColumnPGList.Add(cpg);
				foreach (var p in cpg.Products)
				{
					foreach (var r in p.Reworks)
					{
						//Add Rework To ColumnHeaders
						r.RowIndex = 0;
						r.ColumnIndex = col;
						ColumnHeaders.Add(r);
						//...
						col++;
					}
				}

				//Add ProductGroup To RowHeaders
				var rpg = new ProductGroup(pgModel, this, isRowHeader: true);
				rpg.RowIndex = row++;//pg itself is a row
				rpg.ColumnIndex = 0;
				RowHeaders.Add(rpg);
				RowPGList.Add(rpg);
				foreach (var p in rpg.Products)
				{
					foreach (var r in p.Reworks)
					{
						//Add Rework to RowHeaders
						r.RowIndex = row;
						r.ColumnIndex = 0;
						RowHeaders.Add(r);
						//Add Checkbox
						r.Checkbox.RowIndex = row;
						r.Checkbox.ColumnIndex = 1;
						RowHeaders.Add(r.Checkbox);
						//Add Warmup
						r.Warmup.RowIndex = row;
						r.Warmup.ColumnIndex = 2;
						RowHeaders.Add(r.Warmup);

						//...
						row++;
					}
				}
			}

			//				*********
			//use of Context in a non DataService class
			//This is to speed up the reading of changeovers
			//				*********
			using (var context = new Dal.SoheilEdmContext())
			{
				//Add ChangeoverCells
				foreach (var rpg in RowPGList)
				{
					foreach (var cpg in ColumnPGList)
					{
						ChangeoverCells.Add(Cell.Blank(rpg, cpg));
						foreach (var cp in cpg.Products)
							foreach (var cr in cp.Reworks)
								ChangeoverCells.Add(Cell.Blank(rpg, cr, columnColor: cp.Color));
					}
					foreach (var rp in rpg.Products)
						foreach (var rr in rp.Reworks)
							foreach (var cpg in ColumnPGList)
							{
								ChangeoverCells.Add(Cell.Blank(rr, cpg, rowColor: rr.Product.Color));
								foreach (var cp in cpg.Products)
									foreach (var cr in cp.Reworks)
										if (cr.IsValid)
											ChangeoverCells.Add(new ChangeoverCell(rr, cr, this.Id, context));
										else
											ChangeoverCells.Add(Cell.Blank(rr, cr, rowColor: rr.Product.Color, columnColor: cr.Product.Color));
							}
				}
			}
			//				*********
			TotalVisualColumns = col;
			TotalVisualRows = row;
			#endregion
		}
예제 #12
0
		/// <summary>
		/// Creates a UOW and initializes DataServices and adds ProductGroups and stuff
		/// </summary>
		private void InitializeData()
		{
			var uow = new Dal.SoheilEdmContext();
			ProductGroupDataService = new ProductGroupDataService(uow);
			ProductDataService = new ProductDataService(uow);

			//Create Tree

			//add general node first
			var general = new GeneralVm();
			general.Selected += SelectNode;
			Tree.Add(general);

			//add all groups and their children recursively
			var allGroups = ProductGroupDataService.GetActives();
			foreach (var productGroup in allGroups)
			{
				var pg = new ProductGroupVm(productGroup);
				pg.Selected += SelectNode;
				Tree.Add(pg);
			}

			IsLoading = false;
		}
예제 #13
0
		/// <summary>
		/// Must be called with an open connection
		/// </summary>
		/// <param name="model"></param>
		internal TaskEditorVm(Model.Task model, Dal.SoheilEdmContext uow)
		{
			Model = model;
			_uow = uow;
            initializeCommands();
			OperatorManager = new OperatorManagerVm(_uow);

			// Adds|Removes the selected|deselected operator in model
			// Changes SelectedOperatorsCount in vm
			OperatorManager.SelectionChanged += (operatorVm, isSelected, updateCount) =>
			{
				if (SelectedProcess == null) return;
				if (isSelected)
				{
					if (!SelectedProcess.Model.ProcessOperators.Any(x => x.Operator.Id == operatorVm.OperatorId))
						SelectedProcess.Model.ProcessOperators.Add(new Model.ProcessOperator
						{
							Process = SelectedProcess.Model,
							Operator = operatorVm.OperatorModel,
							Role = operatorVm.Role,
							Code = model.Code + operatorVm.Code,
						});
					if(updateCount)
						SelectedProcess.SelectedOperatorsCount++;
				}
				else
				{
					var po = SelectedProcess.Model.ProcessOperators.FirstOrDefault(x => x.Operator.Id == operatorVm.OperatorId);
					if (po != null) SelectedProcess.Model.ProcessOperators.Remove(po);
					if (updateCount)
						SelectedProcess.SelectedOperatorsCount--;
				}
			};

			//Updates Role in model
			OperatorManager.RoleChanged += (operatorVm, role) =>
			{
				if (SelectedProcess == null) return;
				var po = SelectedProcess.Model.ProcessOperators.FirstOrDefault(x => x.Operator.Id == operatorVm.OperatorId);
				if (po == null)
					MessageBox.Show("Is not selected");
				else
					po.Role = role;
			};

			StartDate = model.StartDateTime.Date;
			StartTime = model.StartDateTime.TimeOfDay;

            //subValues
			TaskTargetPoint = model.TaskTargetPoint;
			DurationSeconds = model.DurationSeconds;

			#region Auto check RadioButtons
			if (!model.Processes.Any())
			{
				IsDeferToActivitiesSelected = true;
			}
			else if (model.Processes.AreAllEqual(x => x.TargetCount))
			{
				SameQtyForActivities = model.Processes.FirstOrDefault().TargetCount;
				IsSameQtyForActivitiesSelected = true;
			}
			// if all processes have same duration then
			//		DurationOfProcess = TP * CT
			//		=> DurationOfTask = TP * CT + d, where (0 <= d < CT)
			//		=> d = DurationOfTask - TP * CT
			//		=> 0 <= (DurationOfTask - TP * CT)/CT < 1
			else if (model.Processes.Select(
				p => (DurationSeconds - p.TargetCount * p.StateStationActivity.CycleTime) / (float)p.StateStationActivity.CycleTime)
				.All(diff => 0 <= diff && diff < 1f))
			{
				SameTimeForActivities = TimeSpan.FromSeconds(model.Processes.Max(p => p.TargetCount * p.StateStationActivity.CycleTime));
				IsSameTimeForActivitiesSelected = true;
			}
			else
			{
				IsDeferToActivitiesSelected = true;
			} 
			#endregion

			RebuildProcesses();
		}
예제 #14
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;
		}