Quintiq file version 2.0
#parent: #root
Method OnOK () id:Method_DialogCreateEditSupplyTarget_OnOK
{
  #keys: '[139394.1.50988109]'
  Body:
  [*
    // On ok
    this.ApplyChanges();
    
    data := DataHolderDialogData.Data();
    if( isnull( data.WrappedInstance() ) )
    {
      newsupplyspec := SupplySpecification::Create( data.Unit(),
                                   DropDownListProduct.Data(),
                                   ifexpr( CheckboxStart.Checked(), DateTimeSelectorStart.DateTime(), DateTime::MinDateTime() ), // Read-only, apply changes to shadow is not taking place for read-only attribute when editing
                                   ifexpr( CheckboxEnd.Checked(), DateTimeSelectorEnd.DateTime(), DateTime::MaxDateTime() ),
                                   data.MinQuantity(),
                                   data.TargetQuantity(),
                                   data.HasMaxQuantity(),
                                   data.MaxQuantity(),
                                   false /*isfromdb*/ );
      // Access form, select new supply target
      DataHolderForm.Data().ListSupplyTargets().SelectByKey( newsupplyspec.Key() );
    }
    else
    {
      data.WrappedInstance().Update( data.Unit(),
                                     DropDownListProduct.Data(),
                                     ifexpr( CheckboxStart.Checked(), DateTimeSelectorStart.DateTime(), DateTime::MinDateTime() ), // Read-only, apply changes to shadow is not taking place for read-only attribute when editing
                                     ifexpr( CheckboxEnd.Checked(), DateTimeSelectorEnd.DateTime(), DateTime::MaxDateTime() ), // Read-only, apply changes to shadow is not taking place for read-only attribute when editing
                                     data.MinQuantity(),
                                     data.TargetQuantity(),
                                     data.HasMaxQuantity(),
                                     data.MaxQuantity(),
                                     false /*isfro,db*/ ); 
    }
    
    this.Close();
  *]
}
