| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod LinkOperation ( | 
|   OperationOutput sourceoperationoutput, | 
|   Operation destinationoperation, | 
|   output BaseOperationLinks trash | 
| ) as OperationLink | 
| { | 
|   Description: 'Add given operation outputs as souce operation.' | 
|   TextBody: | 
|   [* | 
|     // DWE2 Feb-1-2016 (created) | 
|      | 
|     ol := null( OperationLink ); | 
|     targetoperationlink := OperationLink::FindOperationLinkTypeIndex( sourceoperationoutput.Operation().ID(), destinationoperation.ID() ); | 
|      | 
|     // Case of moving an OO to Operation that already have the OO linked | 
|     // E.g O1 have 2 OO (OO1, OO2) linked to O2 and O3, when user drag OO1 to O3, we will then link OO1 to O3 and remove OO2 | 
|     if( not isnull( targetoperationlink ) | 
|         and not exists( destinationoperation, OperationInput.BaseOperationLink.OperationOutput, oo, | 
|                         oo = sourceoperationoutput ) ) | 
|     { | 
|       ol := OperationLink::RecreateWithDifferentGroup( sourceoperationoutput.OperationLinkGroupID(), | 
|                                                        targetoperationlink.DestGroupID(), | 
|                                                        targetoperationlink ); | 
|     } | 
|     else | 
|     { | 
|       defaultqty := sourceoperationoutput.MacroPlan().GlobalParameters_MP().DefaultOperationInputOutputQuantity(); | 
|      | 
|       sourcegroupid := sourceoperationoutput.OperationLinkGroupID(); | 
|       destinationgroupid := OperationLink::GetDestinationGroupID( sourceoperationoutput.Operation(), destinationoperation ); | 
|      | 
|       ol := OperationLink::CreateOrDelete( sourceoperationoutput.Operation(), | 
|                                            destinationoperation, | 
|                                            trash, | 
|                                            sourcegroupid, | 
|                                            destinationgroupid, | 
|                                            sourceoperationoutput.Quantity(), // Source quantity | 
|                                            false, | 
|                                            defaultqty, // destination quantity | 
|                                            defaultqty, // destiantion min quantity | 
|                                            defaultqty, // destination max quantity | 
|                                            defaultqty ); // destination group quantity | 
|     } | 
|      | 
|     return ol; | 
|   *] | 
| } |