hongji.li
2023-11-11 df5a7e1ad6835e78b2f9eb7428817b0c23b116bc
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 SetShadowUnitCostRetainUserValues (
  Unit unit
) id:Method_DialogCreateEditUnitCost_SetShadowUnitCostRetainUserValues
{
  #keys: '[144528.2.91510074]'
  Body:
  [*
    // Create shadow unit 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)
    
    createCostForSingleUnit := DataHolderUnits.Data().Size() = 1;
    
    if( createCostForSingleUnit )
    {
      // As we using DataHolderSelectedUnit.OnDataChanged to workaround DropDownListUnit.OnUserSelectionChanged & enabled/disabled software bug
      // Check if user switched unit before re-creating shadow unit cost
      hasUnitChanged := not DataHolderUnits.Data().Find( unit ) >= 0;
      
      if( hasUnitChanged )
      {
        // All values except ID and Unit, we want to preserve user values after user switch unit from dropdown
        obj := unit.UnitCost( relshadow,
                              ID := MacroPlan.IDHolder().GetUnitCostID(),
                              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 unit cost creation, we want to replace the unit in dataholder (e.g on change unit in dropdown)
      DataHolderUnits.Data().Flush();
      DataHolderUnits.Data().Add( unit );
    }
  *]
}