yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Quintiq file version 2.0
#parent: #root
Method SetTypePartial (
  Real capacity_i
) as LibCal_Event
{
  Description:
  [*
    Set the type of the event to 'Partial', if allowed.
    Otherwise set it to 'Available'.
  *]
  TextBody:
  [*
    // Use a FeedbackObject to collect the validation feedback.
    feedback := LibCal_Validate::FeedbackObject();
    
    // Validate if using partial capacity is allowed.
    // Is only a warning, because if it is not allowed the type will be changed.
    moreInfo := this.GetEventInfo();
    LibCal_Validate::RegisterWarning( LibCal_Validate::Event_UsePartialCapacity( LibCal_Event::TYPE_PARTIAL(), capacity_i ), moreInfo );
    
    // Type can only be set to Partial if partial capacity is enabled.
    if( LibCal_Event::USE_PARTIAL_CAPACITY() )
    {
      //isChanged := this.Type() <> LibCal_Event::TYPE_PARTIAL()
      //          or this.PartialCapacity() <> capacity_i;
      // this.IsChanged( isChanged ); Change of Type or Capacity should NOT trigger re-generation of occurrences.
                
      this.Type( LibCal_Event::TYPE_PARTIAL() );
      
      // Validate the capacity.
      moreInfo := moreInfo + ", PartialCapacity = " + LibCal_Util::RealToString( capacity_i );
      LibCal_Validate::RegisterError( LibCal_Validate::Event_PartialCapacity( capacity_i ), moreInfo );
    }
    else
    {
      // Force the type to be Available otherwise, unless the capacity is 0.0;
      // In that case set it to Unavailable.
      if( capacity_i = 0.0 )
      {
        this.SetTypeUnavailable();
      }
      else
      {
        this.SetTypeAvailable();
      }
    }
    
    // Process the feedback that has been registered by the validation (if any).
    LibCal_Util::ProcessFeedbackObject( feedback );
    
    // The below is only executed when no validation errors were encountered.
    // Set the ParticalCapacity, also when it is not used.
    this.PartialCapacity( capacity_i );
                          
    // Make the API fluent.
    return this;
  *]
}