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
Quintiq file version 2.0
#parent: #root
StaticMethod CanSave (KpiMetaDataFactory factory, KpiMetaData original, String name, 
  String displayName, String description, Boolean isMaximize, 
  Boolean isMinimize, String unitOfMeasure) remote as Boolean
{
  Description: 'Checks to see if a KPI with the specified parameters would be valid. Used in preconditions. Sets the FeedbackObject.'
  TextBody:
  [*
    feedback := FeedbackObject::LocalFeedback();
    isNew    := isnull( original );
    
    // Pre-check if we need to go checking for uniqueness (which does a lookup).
    if ( isNew or guard( original.Name() <> name, false ) )
    {
      // Check uniqueness.
      if ( not feedback.CheckHard( factory.CanCreateInstance( name ) ) )
      {
        feedback.AddHard( Translations::Kpi_MetaData_AlreadyExists( name ) );
      }
    }
     
    // Can't have both IsMaximize and IsMinimize
    if ( not feedback.CheckHard( not ( isMaximize and isMinimize ) ) )
    {
      feedback.AddHard( Translations::Kpi_MetaData_CanHaveBothIsMaximizeAndIsMinimize() );
    }
    
    // Name can't be empty
    if ( not feedback.CheckHard( not name.TrimBoth() = "" ) ) 
    {
      feedback.AddHard( Translations::Kpi_MetaData_NameCantBeEmpty() );  
    }
    
    // DisplayName can't be empty
    if ( not feedback.CheckHard( not displayName.TrimBoth() = "" ) )
    {
      feedback.AddHard( Translations::Kpi_MetaData_DisplayNameCantBeEmpty() );
    }
    
    return feedback.IsAllowed();
  *]
}