Datei: SimpleMappingTool/RelationNode.cs
Last Commit (2ee4f7f)
1 | // |
2 | // Copyright (c) 2002-2016 Mirko Matytschak |
3 | // (www.netdataobjects.de) |
4 | // |
5 | // Author: Mirko Matytschak |
6 | // |
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
11 | // conditions: |
12 | |
13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
14 | // of the Software. |
15 | // |
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. |
21 | |
22 | |
23 | using System; |
24 | using System.Windows.Forms; |
25 | using NDO.Mapping; |
26 | |
27 | namespace SimpleMappingTool |
28 | { |
29 | ····/// <summary> |
30 | ····/// Zusammenfassung für RelationNode. |
31 | ····/// </summary> |
32 | ····internal class RelationNode : NDOTreeNode |
33 | ····{ |
34 | ········public RelationNode(Relation relation) : base (relation.FieldName, relation) |
35 | ········{ |
36 | ············this.ImageIndex = 4; |
37 | ············this.SelectedImageIndex = 4; |
38 | ············if (relation.MappingTable != null) |
39 | ················this.Nodes.Add(new MappingTableNode(relation.MappingTable)); |
40 | ············foreach (ForeignKeyColumn fkCol in relation.ForeignKeyColumns) |
41 | ················this.Nodes.Add(new ColumnNode(this, fkCol)); |
42 | ········} |
43 | |
44 | Relation MyRelation |
45 | ········{ |
46 | ············get { return o as Relation; } |
47 | ········} |
48 | public override ContextMenu GetContextMenu( ) |
49 | ········{ |
50 | ············ContextMenu menu = base.GetContextMenu(); |
51 | ············if (MyRelation.MappingTable == null) |
52 | menu. MenuItems. Add( new MenuItem( "Add mapping table", new EventHandler( AddMappingTable) ) ) ; |
53 | ············else |
54 | menu. MenuItems. Add( new MenuItem( "Delete mapping table", new EventHandler( DeleteMappingTable) ) ) ; |
55 | ············return menu; |
56 | ········} |
57 | |
58 | void DeleteMappingTable( object sender, EventArgs ea) |
59 | ········{ |
60 | ············MyRelation.MappingTable = null; |
61 | ············while (this.Nodes.Count > 0) |
62 | this. Nodes. RemoveAt( 0) ; |
63 | ············this.TreeView.Refresh(); |
64 | ········} |
65 | |
66 | void AddMappingTable( object sender, EventArgs ea) |
67 | ········{ |
68 | ············MessageBox.Show("Sorry, we didn't implement this part yet."); |
69 | #if nix |
70 | ············MappingTable mt = new MappingTable(MyRelation); |
71 | ············MyRelation.MappingTable = mt;············ |
72 | ············mt.ConnectionId = MyRelation.Parent.ConnectionId; |
73 | ············Class cl = MyRelation.Parent; |
74 | ············string tableName; |
75 | ············string myName = cl.FullName.Substring(cl.FullName.LastIndexOf(".") + 1); |
76 | ············string otherName = MyRelation.ReferencedTypeName.Substring(MyRelation.ReferencedTypeName.LastIndexOf(".") + 1); |
77 | ············if (myName.CompareTo(otherName) < 0) |
78 | ················tableName = "rel" + myName + otherName; |
79 | ············else |
80 | ················tableName = "rel" + otherName + myName; |
81 | ············mt.TableName = tableName; |
82 | |
83 | ············MyRelation.ForeignKeyColumnName = "ID" + myName; |
84 | ············if (cl.SystemType != null) |
85 | ············{ |
86 | ················if (cl.Subclasses.Count > 0) |
87 | ····················MyRelation.ForeignKeyTypeColumnName = "TC" + myName;···················· |
88 | ············} |
89 | ············mt.ChildForeignKeyColumnName = "ID" + otherName; |
90 | ············if (MyRelation.ReferencedType != null) |
91 | ············{ |
92 | ················if (MyRelation.ReferencedSubClasses.Count > 1) |
93 | ····················mt.ChildForeignKeyTypeColumnName = "TC" + otherName; |
94 | ············} |
95 | ············MappingTableNode mtn = new MappingTableNode(mt); |
96 | ············this.Nodes.Add(mtn); |
97 | ············this.TreeView.Refresh(); |
98 | #endif |
99 | ········} |
100 | |
101 | ········ |
102 | ····} |
103 | } |
104 |
New Commit (37eab6b)
1 | // |
2 | // Copyright (c) 2002-2016 Mirko Matytschak |
3 | // (www.netdataobjects.de) |
4 | // |
5 | // Author: Mirko Matytschak |
6 | // |
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
11 | // conditions: |
12 | |
13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
14 | // of the Software. |
15 | // |
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. |
21 | |
22 | |
23 | using System; |
24 | using System.Windows.Forms; |
25 | using NDO; |
26 | using NDO.Mapping; |
27 | |
28 | namespace SimpleMappingTool |
29 | { |
30 | ····/// <summary> |
31 | ····/// Zusammenfassung für RelationNode. |
32 | ····/// </summary> |
33 | ····internal class RelationNode : NDOTreeNode |
34 | ····{ |
35 | ········public RelationNode(Relation relation) : base (relation.FieldName, relation) |
36 | ········{ |
37 | ············this.ImageIndex = 4; |
38 | ············this.SelectedImageIndex = 4; |
39 | ············if (relation.MappingTable != null) |
40 | ················this.Nodes.Add(new MappingTableNode(relation.MappingTable)); |
41 | ············foreach (ForeignKeyColumn fkCol in relation.ForeignKeyColumns) |
42 | ················this.Nodes.Add(new ColumnNode(this, fkCol)); |
43 | ········} |
44 | |
45 | Relation? MyRelation |
46 | ········{ |
47 | ············get { return o as Relation; } |
48 | ········} |
49 | |
50 | ········public override ContextMenuStrip GetContextMenu() |
51 | ········{ |
52 | ············ContextMenuStrip menu = base.GetContextMenu(); |
53 | ············if (MyRelation != null) |
54 | ············{ |
55 | ················if (MyRelation.MappingTable == null) |
56 | menu. Items. Add( new ToolStripMenuItem( "Add mapping table", null, AddMappingTable ) ) ; |
57 | ················else |
58 | menu. Items. Add( new ToolStripMenuItem( "Delete mapping table", null, new EventHandler( DeleteMappingTable ) ) ) ; |
59 | ············} |
60 | ············return menu; |
61 | ········} |
62 | |
63 | void DeleteMappingTable( object? sender, EventArgs ea) |
64 | ········{ |
65 | ············if (MyRelation != null) |
66 | ············{ |
67 | ················MyRelation.MappingTable = null; |
68 | ················while (this.Nodes.Count > 0) |
69 | this. Nodes. RemoveAt( 0 ) ; |
70 | ················this.TreeView.Refresh(); |
71 | ············} |
72 | ········} |
73 | |
74 | void AddMappingTable( object? sender, EventArgs ea) |
75 | ········{ |
76 | ············MessageBox.Show("Sorry, we didn't implement this part yet."); |
77 | #if nix |
78 | ············MappingTable mt = new MappingTable(MyRelation); |
79 | ············MyRelation.MappingTable = mt;············ |
80 | ············mt.ConnectionId = MyRelation.Parent.ConnectionId; |
81 | ············Class cl = MyRelation.Parent; |
82 | ············string tableName; |
83 | ············string myName = cl.FullName.Substring(cl.FullName.LastIndexOf(".") + 1); |
84 | ············string otherName = MyRelation.ReferencedTypeName.Substring(MyRelation.ReferencedTypeName.LastIndexOf(".") + 1); |
85 | ············if (myName.CompareTo(otherName) < 0) |
86 | ················tableName = "rel" + myName + otherName; |
87 | ············else |
88 | ················tableName = "rel" + otherName + myName; |
89 | ············mt.TableName = tableName; |
90 | |
91 | ············MyRelation.ForeignKeyColumnName = "ID" + myName; |
92 | ············if (cl.SystemType != null) |
93 | ············{ |
94 | ················if (cl.Subclasses.Count > 0) |
95 | ····················MyRelation.ForeignKeyTypeColumnName = "TC" + myName;···················· |
96 | ············} |
97 | ············mt.ChildForeignKeyColumnName = "ID" + otherName; |
98 | ············if (MyRelation.ReferencedType != null) |
99 | ············{ |
100 | ················if (MyRelation.ReferencedSubClasses.Count > 1) |
101 | ····················mt.ChildForeignKeyTypeColumnName = "TC" + otherName; |
102 | ············} |
103 | ············MappingTableNode mtn = new MappingTableNode(mt); |
104 | ············this.Nodes.Add(mtn); |
105 | ············this.TreeView.Refresh(); |
106 | #endif |
107 | ········} |
108 | |
109 | ········ |
110 | ····} |
111 | } |
112 |