Kevin Kok Khah Whey
2023-11-07 5ae534ab606e6f2ba5ea60914224d665b0447d5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Quintiq file version 2.0
#parent: #root
Method SetShadowOperationCostRetainUserValues (
  Operation operation
) id:Method_DialogCreateEditOperationCost_SetShadowOperationCostRetainUserValues
{
  #keys: '[144528.2.91510074]'
  Body:
  [*
    // Create shadow operation cost and retrieve values from UI elements
    // e.g when changing unit from dropdown, we do not want overwrite the previous values)
    
    // NOTE: This cannot be call before Show modal as it slows down dialog display (as the shadow creation below refers to UI elements)
    
    createCostForSingleOperation := DataHolderOperations.Data().Size() = 1;
    
    if( createCostForSingleOperation )
    {
      // As we using DataHolderSelectedOperation.OnDataChanged to workaround DropDownListOperation.OnUserSelectionChanged & enabled/disabled software bug
      // Check if user switched operation before re-creating shadow unit cost
      hasOperationChanged := not DataHolderOperations.Data().Find( operation ) >= 0;
      
      if( hasOperationChanged )
      {
        // All values except ID and Operation, we want to preserve user values after user switch operation from dropdown
        obj := operation.OperationCost ( relshadow,
                                         ID := MacroPlan.IDHolder().GetOperationCostID(),
                                         AccountName := DropDownListAccount.Data().Name(),
                                         Account_MP := DropDownListAccount.Data(),
                                         CostDriver := DropDownStringListCostDriver.Text(),
                                         Cost := ApplicationMacroPlanner.FormatStringToReal( EditFieldCost.Text() ),
                                         LengthOfTime := ApplicationMacroPlanner.FormatStringToNumber( EditFieldLengthOfTime.Text() ),
                                         TimeUnit := DropDownStringListTimeUnit.Text(),
                                         Start := DateSelectorCostStart.Date() );
        
        DataHolderDialogData.Data( & obj );
      }
      
      // Only if single operation cost creation, we want to replace the operation in dataholder (e.g on change operation in dropdown)
      DataHolderOperations.Data().Flush();
      DataHolderOperations.Data().Add( operation );
    }
  *]
}