/// <summary> /// Updates Process and Activity and Refreshes operators status /// </summary> /// <param name="processVm"></param> public void Refresh(ProcessEditorVm processVm) { if (processVm != null) { Process = processVm.Model; Activity = processVm.ActivityModel; IsEnabled = true; } else { Process = null; Activity = null; IsEnabled = false; } refresh(); }
/// <summary> /// Recreate all activities within this task /// </summary> internal void RebuildProcesses() { ProcessList.Clear(); //convert and add each activity (ssaGroup) within current StateStation to ProcessList //note that: each group of SSA (grouped by activity) MUST be added ONCE (not 0 not 5) // if SSA of one of processModels is in ssaGroup, consider that SSA // else create a new processModel foreach (var ssaGroup in Model.Block.StateStation.StateStationActivities.GroupBy(ssa => ssa.Activity.Id)) { ProcessEditorVm processVm = null; #region processVm = Create a new PPEditorProcess for this ssaGroup //processModel: existing process which its ssa is in ssaGroup var processModel = Model.Processes .Where(p => p.StateStationActivity != null) .FirstOrDefault(p => ssaGroup.Any(ssa => ssa.Id == p.StateStationActivity.Id)); if (processModel != null)//a process exists matching a ssa in ssaGroup { processVm = new ProcessEditorVm(processModel, _uow); } else//no process matches any ssa in ssaGroup { processModel = new Model.Process(); processModel.Task = Model; processVm = new ProcessEditorVm(processModel, _uow, ssaGroup); } #endregion #region Set the event handlers of processVm processVm.ActivityChoiceChanged += (oldVal, newVal) => { if (newVal == null) return; //update TargetPoint of process if (IsSameQtyForActivitiesSelected) { processVm.TargetPoint = SameQtyForActivities; var newDuration = SameQtyForActivities * (int)newVal.CycleTime; if (newDuration != processVm.DurationSeconds) processVm.DurationSeconds = newDuration; } else if (IsSameTimeForActivitiesSelected) { processVm.TargetPoint = (int)Math.Floor(SameTimeForActivities.TotalSeconds / newVal.CycleTime); var newDuration = processVm.TargetPoint * (int)newVal.CycleTime; if (newDuration != processVm.DurationSeconds) processVm.DurationSeconds = newDuration; } else { if (processVm.DurationSeconds > 0) processVm.TargetPoint = (int)Math.Floor(processVm.DurationSeconds / newVal.CycleTime); else if (processVm.TargetPoint > 0) processVm.DurationSeconds = (int)Math.Floor(processVm.TargetPoint * newVal.CycleTime); } }; processVm.ProcessTargetPointChanged += (oldVal, newVal) => { }; processVm.ProcessDurationChanged += (oldVal, newVal) => { DurationSeconds = ProcessList.Max(x => x.DurationSeconds); }; #endregion //finally add it to ProcessList ProcessList.Add(processVm); } }
void ProcessList_Added(ProcessEditorVm processVm) { //create choice menuitems for process processVm.Choices.Clear(); foreach (var choice in Choices) { var choiceVm = new ChoiceEditorVm(choice.Model); choiceVm.Selected += ch => processVm.SelectedChoice = Choices.FirstOrDefault(x => x.ManHour == ch.ManHour); processVm.Choices.Add(choiceVm); } //notify Block about selection and delete processVm.Selected += Process_Selected; processVm.Deleted += Process_Deleted; //notify Block about changes in times processVm.TimesChanged += Process_TimesChanged; //change selected choice for the process processVm.SelectedOperatorsCountChanged += Process_OperatorsCountChanged; //Updates process TargetPoint or DurationSeconds based on Block fixed data (deferred, fixedDuration, fixedTP) processVm.SelectedChoiceChanged += Process_SelectedChoiceChanged; if (processVm.Model.StateStationActivity != null) { //select the right choice based on manHour //processVm.SelectedChoice = Choices.FirstOrDefault(x => x.ManHour == processVm.SelectedOperatorsCount); //select the right choice based on SSA processVm.SelectedChoice = Choices.FirstOrDefault(x => x.ManHour == processVm.Model.StateStationActivity.ManHour); } }
void Process_SelectedChoiceChanged(ProcessEditorVm processVm, ChoiceEditorVm newChoice) { if (SelectedChoiceChanged != null) SelectedChoiceChanged(processVm, newChoice); }
public ActivityEditorVm( Model.Task task, Dal.SoheilEdmContext uow, IGrouping<Model.Activity, Model.StateStationActivity> ssaGroup) : base(ssaGroup.Key) { Message = new Common.SoheilException.EmbeddedException(); if (!ssaGroup.Any()) { Message.AddEmbeddedException("فعالیتی وجود ندارد"); return; } //make ProcessList self-aware of all changes ProcessList.CollectionChanged += (s, e) => { if (e.NewItems != null) foreach (ProcessEditorVm processVm in e.NewItems) { ProcessList_Added(processVm); } }; //Add Choices foreach (var choice in ssaGroup.OrderBy(ssa => ssa.ManHour)) { Choices.Add(new ChoiceEditorVm(choice)); } //Add existing processes foreach (var process in task.Processes.Where(x => x.StateStationActivity.Activity.Id == ssaGroup.Key.Id)) { ProcessList.Add(new ProcessEditorVm(process, Model, uow)); } //Add process command AddProcessCommand = new Commands.Command(o => { DateTime dt; if (GetTaskStart == null) dt = ProcessList.Any() ? ProcessList .Where(x => x.ActivityModel.Id == ssaGroup.Key.Id) .Max(x => x.Model.EndDateTime) : task.StartDateTime; else dt = GetTaskStart(); var minMH = ssaGroup.Min(x => x.ManHour); var processVm = new ProcessEditorVm( new Model.Process { StartDateTime = dt, EndDateTime = dt, StateStationActivity = ssaGroup.First(x=>x.ManHour == minMH), TargetCount = 0, Task = task, }, Model, uow);//activity Model is set here ProcessList.Add(processVm); processVm.IsSelected = true; }); }
void Process_TimesChanged(ProcessEditorVm processVm, DateTime start, DateTime end) { if (TimesChanged != null) TimesChanged(processVm, start, end); }
void Process_OperatorsCountChanged(ProcessEditorVm processVm, int count) { processVm.SelectedChoice = Choices.FirstOrDefault(x => x.ManHour == count); }
void Process_Deleted(ProcessEditorVm processVm) { processVm.IsSelected = false; ProcessList.Remove(processVm); if (ProcessList.Any()) ProcessList.First().IsSelected = true; else { if (Selected != null) Selected(processVm, false); } }
void Process_Selected(ProcessEditorVm processVm) { if (Selected != null) Selected(processVm, true); }
void Activity_TimesChanged(ProcessEditorVm process, DateTime start, DateTime end) { if (start < Model.StartDateTime) { StartDate = start.Date; StartTime = start.TimeOfDay; } else { var max = ActivityList.Where(a => a.ProcessList.Any()) .Max(a => a.ProcessList.Max(p => p.Timing.EndDateTime)); EndDate = max.Date; EndTime = max.TimeOfDay; Model.EndDateTime = max; } Duration = Model.EndDateTime - Model.StartDateTime; OperatorManager.refresh(); }
void Activity_Selected(ProcessEditorVm processVm, bool isSelected) { if (isSelected) { foreach (var activity in ActivityList) { foreach (var process in activity.ProcessList) { if (process != processVm) process.IsSelected = false; } } OperatorManager.Refresh(processVm); } else { OperatorManager.Refresh(null); } }
void activityVm_SelectedChoiceChanged(ProcessEditorVm processVm, ChoiceEditorVm newChoice) { if (newChoice == null) return; if (IsTargetPointFixed) { processVm.Timing.TargetPoint = 0; processVm.Timing.TargetPoint = FixedTargetPoint; } else if (IsDurationFixed) { processVm.Timing.DurationSeconds = 0; processVm.Timing.DurationSeconds = FixedDurationSeconds; } else if (IsDeferred) { //set target point if (processVm.Timing.DurationSeconds > 0) processVm.Timing.TargetPoint = (int)(processVm.Timing.DurationSeconds / newChoice.CycleTime); //or set duration seconds else processVm.Timing.DurationSeconds = (int)(processVm.Timing.TargetPoint * newChoice.CycleTime); } }