lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
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
60
61
62
63
64
65
Quintiq file version 2.0
#parent: #root
StaticMethod ValidateInput (
  output String feedback_o,
  Unit unit,
  String name,
  Real minquantity,
  Real maxquantity,
  CampaignType_MP campaigntype,
  Boolean checkunique
) declarative remote as Boolean
{
  Description: 'Checks the correctness of input data from Create/Edit dialog.'
  TextBody:
  [*
    feedback_o := '';
    
    // Length limit of name
    lengthlimit := GlobalParameters_MP::GetLengthOfNames();
    
    // Check if unit is null
    if( isnull( unit ) )
    {
      feedback_o := Translations::MP_CampaignType_ValidateInput_IsNullUnit() ;
    }
    // Check if name is unique
    else if( checkunique
             and exists( unit, CampaignType_MP, ct,
                         ct <> campaigntype,
                         ct.Name() = name ) )
    {
      feedback_o := Translations::MP_CampaignType_ViolateHasUniqueName();
    }
    // Check if name is valid
    else if( name = '' or  name.Length() > lengthlimit )
    {
      feedback_o := Translations::MP_CampaignType_ValidateInput_IsNameEmptyOrExceedLengthLimit( lengthlimit );
    }
    // Check if min quantity is valid
    else if( minquantity < 0 )
    {
      feedback_o := Translations::MP_CampaignType_ValidateInput_IsNegativeMinQuantity( minquantity );
    }
    // Check if max quantity is valid
    else if( maxquantity < 0 )
    {
      feedback_o := Translations::MP_CampaignType_ValidateInput_IsNegativeMaxQuantity( maxquantity );
    }
    // Check if min & max quantity combination is valid
    else if( maxquantity < minquantity )
    {
      feedback_o := Translations::MP_CampaignType_ValidateInput_IsMinQuantityLessThanMaxQuantity( minquantity, maxquantity );
    }
    
    // Add feedback text if any precondition above is violated
    if( feedback_o <> '' )
    {
      subname := MacroPlan::GetSubstituteName( name );
      feedback_o := SanityCheckMessage::GetFormattedMessage( Translations::MP_CampaignType_Instance( subname ),
                                                             feedback_o );
    }
    
    return feedback_o.Length() = 0
  *]
}