| Quintiq file version 2.0 | 
| #parent: #root | 
| Method EditUnitAvailabilityFromListUnitPeriodTime ( | 
|   internal[GUIComponent] parent, | 
|   structured[UnitPeriodTime] selection | 
| ) id:Method_DialogCreateEditUnitAvailability_EditUnitAvailabilityFromListUnitPeriodTime | 
| { | 
|   #keys: '[105706.0.2071122933]' | 
|   Body: | 
|   [* | 
|     // Edit the capacity of the selection unit period times from periods list | 
|      | 
|     isbatchedit := selection.Size() > 1; | 
|     Dialog.ShowHideComponentForBatchEdit( isbatchedit, false, true ); | 
|      | 
|     upt := selection.Element( 0 ); | 
|     // Need this for excluding itself in pre-condition primary keys checking. | 
|     data := shadow( upt.UnitAvailability() ); | 
|      | 
|     // In case selection.Element( 0 ) doesn't bind to any unit availability, calling SetDefaultValue method will return null error. | 
|     // Check start in case of editing from UPT later than the existing UA, the Start date will be off if we pass in existing UA | 
|     if( isnull( data ) | 
|         or data.Start() <> upt.Start() ) | 
|     { | 
|       data := selection.Element( 0 ).Unit().UnitAvailability( relshadow, UnitID := upt.Unit().ID(), Start := upt.Start() ); | 
|     } | 
|      | 
|     Dialog.Data( data ); | 
|      | 
|     // Need this so that when the upt doesn't not have a unit availability, the fields in this Dialog will not be blank. | 
|     Dialog.SetDefaultValue( selection.Element( 0 ) ); | 
|      | 
|     result := this.DoModal( parent ); | 
|      | 
|     if( result > 0 ) | 
|     { | 
|       UnitAvailability::CreateOrUpdateForUnitPeriodTimes( selection, | 
|                                                           not isbatchedit or CheckBoxBatchEditMaintenance.Checked(), | 
|                                                           data.TimeUnit(), | 
|                                                           data.Maintenance(), | 
|                                                           not isbatchedit or CheckBoxBatchEditEfficiency.Checked(), | 
|                                                           data.Efficiency(), | 
|                                                           not isbatchedit or CheckBoxBatchEditAllocation.Checked(), | 
|                                                           data.Allocation(), | 
|                                                           not isbatchedit or CheckBoxBatchEditShiftPattern.Checked(), | 
|                                                           data.ShiftPattern(), | 
|                                                           not isbatchedit or CheckBoxBatchEditMaxLoadPercentage.Checked(), | 
|                                                           data.MaximumLoadPercentage(), | 
|                                                           not isbatchedit or CheckBoxBatchEditNrOfUnitsOpen.Checked(), | 
|                                                           data.NrOfUnitsOpen(), | 
|                                                           CheckBoxThisPeriodOnwards.Checked(), | 
|                                                           not isbatchedit or CheckBoxBatchEditMinimumLoadThreshold.Checked(), | 
|                                                           data.MinimumLoadThreshold() | 
|                                                           ); | 
|     } | 
|   *] | 
| } |