admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Quintiq file version 2.0
#parent: #root
Method ImportFromXML (
  String xmlstring,
  output String feedback_o
) as Boolean
{
  Description: 'Restores view setting. Called by designer during retrieve view'
  TextBody:
  [*
    // Import supply chain view from XML
    result := true;
    
    // Check if xmlstring is populated
    if( xmlstring.Length() > 0 )
    {
      xmlview := null( SupplyChainView );
      
      // Try to import xmlstring
      try
      {
        xmlview := SupplyChainView::XMLImportSupplyChainViewXML( xmlstring );
      }
      onerror
      {
        result := false;      
      }
      
      // Check if xmlview is null
      if( not isnull( xmlview ) )
      {
        // Update this with xmlview
        this.Update( xmlview.SupplyChainBackground(),
                     xmlview.FontSize(),
                     xmlview.FontName(),
                     xmlview.GridPointDistance(),
                     xmlview.RelativeStockingPointSize(),
                     xmlview.RelativeUnitHeight(),
                     xmlview.RelativeUnitWidth(),
                     xmlview.RelativeProductHeight(),
                     xmlview.RelativeProductWidth(),
                     xmlview.IsGridVisible(),
                     xmlview.IsLaneVisible(),
                     xmlview.IsUnitNodeLabelVisible(),
                     xmlview.IsStockingPointNodeLabelVisible(),
                     xmlview.ArrowColor(),
                     xmlview.HasPersistentArrows(),
                     this.OffsetX(),
                     this.OffsetY() )
    
        // Traverse all nodes in xmlview
        traverse( xmlview, Node, xmlnode )
        {
          // Executes logic according to the type of the object
          ontype( xmlnode )
          {
            // If xmlnode is type of UnitNode
            UnitNode as unitxmlnode:
            {
              // Select UnitNode with the same name as xmlnode
              node := select( this, UnitNode, n, n.Name() = xmlnode.Name() );
              // Check if node is null
              if( not isnull( node ) )
              {
                // Update node with values from xmlnode
                node.Update( unitxmlnode.GridX(), unitxmlnode.GridY(), unitxmlnode.IsUserVisible(), unitxmlnode.NameDisplayBehavior(),
                             unitxmlnode.TextColor(), unitxmlnode.BackgroundImageName() );
              }
            }
            // If xmlnode is type of StockingPointNode
            StockingPointNode as stockingpointxmlnode:
            {
              // Select StockingPointNode with the same name as xmlnode
              node := select( this, StockingPointNode, n, n.Name() = stockingpointxmlnode.Name() );
              // Check if node is null
              if( not isnull( node ) )
              {
                // Update node with values from xmlnode
                node.Update( stockingpointxmlnode.GridX(), stockingpointxmlnode.GridY(), stockingpointxmlnode.IsUserVisible(), stockingpointxmlnode.NameDisplayBehavior(),
                             stockingpointxmlnode.TextColor() );
              }
            }
          }
        }
    
        //Hide newly added nodes that are not defined in the xmlstring yet
        unitnodes := selectset( this, Node.astype( UnitNode ), n,
                                not exists( xmlview, Node.astype( UnitNode ), xmlnode, xmlnode.Name() = n.Name() ) )
        traverse( unitnodes, Elements, e )
        {
          e.IsUserVisible ( false );
        }
    
        spnodes := selectset( this, Node.astype( StockingPointNode ), n,
                              not exists( xmlview, Node.astype( StockingPointNode ), xmlnode, xmlnode.Name() = n.Name() ) )
        traverse( spnodes, Elements, e )
        {
          e.IsUserVisible ( false );
        }
    
        // Delete xmlview
        xmlview.Delete();
      }
    }
    else
    {
      result := false;
    }
    
    // Return feedback if the method failed to parse xmlstring
    if( not result )
    {
      feedback_o := Translations::MP_SupplyChainView_ImportFromXML_InvalidFile();
    }
    
    return result;
  *]
}