1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.ActiveRecord
.Generator
.Dialogs
19 using System
.Collections
;
20 using System
.ComponentModel
;
21 using System
.Windows
.Forms
;
23 using Castle
.ActiveRecord
.Generator
.Components
;
24 using Castle
.ActiveRecord
.Generator
.Components
.Database
;
27 /// Summary description for AddRelationDialog.
29 public class AddRelationDialog
: System
.Windows
.Forms
.Form
31 protected System
.Windows
.Forms
.Button cancelButton
;
32 protected System
.Windows
.Forms
.Button okButton
;
33 protected System
.Windows
.Forms
.TabControl tabControl1
;
34 protected System
.Windows
.Forms
.TabPage tabPage1
;
35 protected System
.Windows
.Forms
.TextBox className
;
36 protected System
.Windows
.Forms
.TabPage tabPage2
;
37 protected System
.Windows
.Forms
.TabPage tabPage3
;
38 protected System
.Windows
.Forms
.ListBox parentCols
;
39 protected System
.Windows
.Forms
.ListBox relatedCols
;
40 protected System
.Windows
.Forms
.ComboBox associationTable
;
41 protected System
.Windows
.Forms
.GroupBox groupBox1
;
42 protected System
.Windows
.Forms
.GroupBox groupBox2
;
43 protected System
.Windows
.Forms
.Label label4
;
44 protected System
.Windows
.Forms
.Label label5
;
45 protected System
.Windows
.Forms
.ListBox targetTableList
;
46 protected System
.Windows
.Forms
.RadioButton hasAndBelongsToManyButton
;
47 protected System
.Windows
.Forms
.RadioButton belongsToButton
;
48 protected System
.Windows
.Forms
.RadioButton hasManyButton
;
49 protected System
.Windows
.Forms
.TextBox where
;
50 protected System
.Windows
.Forms
.TextBox order
;
51 protected System
.Windows
.Forms
.CheckBox lazyButton
;
52 protected System
.Windows
.Forms
.CheckBox inverseButton
;
54 /// Required designer variable.
56 private System
.ComponentModel
.Container components
= null;
57 protected System
.Windows
.Forms
.Label label10
;
58 protected System
.Windows
.Forms
.Label label11
;
60 protected ActiveRecordDescriptor _descriptor
;
61 protected Project _project
;
62 protected AssociationEnum _association
= AssociationEnum
.Undefined
;
63 protected System
.Windows
.Forms
.Label associationTableLabel
;
64 protected System
.Windows
.Forms
.Label relatedColsLabel
;
65 protected System
.Windows
.Forms
.Label parentColsLabel
;
66 protected System
.Windows
.Forms
.ComboBox outerJoin
;
67 protected System
.Windows
.Forms
.Label label9
;
68 protected System
.Windows
.Forms
.ComboBox cascade
;
69 protected System
.Windows
.Forms
.Label label1
;
70 protected System
.Windows
.Forms
.CheckBox updateButton
;
71 protected System
.Windows
.Forms
.CheckBox insertButton
;
72 protected ActiveRecordDescriptor _oldDescSelection
;
73 protected IRelationshipBuilder _relationBuilder
;
76 public AddRelationDialog(ActiveRecordDescriptor descriptor
, Project project
) : this()
78 _descriptor
= descriptor
;
81 _relationBuilder
= (IRelationshipBuilder
) ServiceRegistry
.Instance
[ typeof(IRelationshipBuilder
) ];
83 className
.Text
= _descriptor
.ClassName
;
85 targetTableList
.ValueMember
= "ClassName";
87 foreach(IActiveRecordDescriptor desc
in _project
.Descriptors
)
89 if (desc
is ActiveRecordBaseDescriptor
) continue;
90 if (desc
.ClassName
== null) continue;
92 targetTableList
.Items
.Add( desc
);
96 public AddRelationDialog()
98 InitializeComponent();
100 outerJoin
.SelectedIndex
= 0;
101 cascade
.SelectedIndex
= 0;
105 /// Clean up any resources being used.
107 protected override void Dispose( bool disposing
)
111 if(components
!= null)
113 components
.Dispose();
116 base.Dispose( disposing
);
119 #region Windows Form Designer generated code
121 /// Required method for Designer support - do not modify
122 /// the contents of this method with the code editor.
124 private void InitializeComponent()
126 this.cancelButton
= new System
.Windows
.Forms
.Button();
127 this.okButton
= new System
.Windows
.Forms
.Button();
128 this.tabControl1
= new System
.Windows
.Forms
.TabControl();
129 this.tabPage1
= new System
.Windows
.Forms
.TabPage();
130 this.label11
= new System
.Windows
.Forms
.Label();
131 this.label10
= new System
.Windows
.Forms
.Label();
132 this.targetTableList
= new System
.Windows
.Forms
.ListBox();
133 this.className
= new System
.Windows
.Forms
.TextBox();
134 this.hasAndBelongsToManyButton
= new System
.Windows
.Forms
.RadioButton();
135 this.belongsToButton
= new System
.Windows
.Forms
.RadioButton();
136 this.hasManyButton
= new System
.Windows
.Forms
.RadioButton();
137 this.tabPage3
= new System
.Windows
.Forms
.TabPage();
138 this.associationTableLabel
= new System
.Windows
.Forms
.Label();
139 this.associationTable
= new System
.Windows
.Forms
.ComboBox();
140 this.relatedCols
= new System
.Windows
.Forms
.ListBox();
141 this.parentCols
= new System
.Windows
.Forms
.ListBox();
142 this.relatedColsLabel
= new System
.Windows
.Forms
.Label();
143 this.parentColsLabel
= new System
.Windows
.Forms
.Label();
144 this.tabPage2
= new System
.Windows
.Forms
.TabPage();
145 this.groupBox2
= new System
.Windows
.Forms
.GroupBox();
146 this.cascade
= new System
.Windows
.Forms
.ComboBox();
147 this.label1
= new System
.Windows
.Forms
.Label();
148 this.updateButton
= new System
.Windows
.Forms
.CheckBox();
149 this.insertButton
= new System
.Windows
.Forms
.CheckBox();
150 this.inverseButton
= new System
.Windows
.Forms
.CheckBox();
151 this.lazyButton
= new System
.Windows
.Forms
.CheckBox();
152 this.groupBox1
= new System
.Windows
.Forms
.GroupBox();
153 this.outerJoin
= new System
.Windows
.Forms
.ComboBox();
154 this.label9
= new System
.Windows
.Forms
.Label();
155 this.order
= new System
.Windows
.Forms
.TextBox();
156 this.label5
= new System
.Windows
.Forms
.Label();
157 this.where
= new System
.Windows
.Forms
.TextBox();
158 this.label4
= new System
.Windows
.Forms
.Label();
159 this.tabControl1
.SuspendLayout();
160 this.tabPage1
.SuspendLayout();
161 this.tabPage3
.SuspendLayout();
162 this.tabPage2
.SuspendLayout();
163 this.groupBox2
.SuspendLayout();
164 this.groupBox1
.SuspendLayout();
165 this.SuspendLayout();
169 this.cancelButton
.DialogResult
= System
.Windows
.Forms
.DialogResult
.Cancel
;
170 this.cancelButton
.Location
= new System
.Drawing
.Point(448, 296);
171 this.cancelButton
.Name
= "cancelButton";
172 this.cancelButton
.TabIndex
= 6;
173 this.cancelButton
.Text
= "Cancel";
174 this.cancelButton
.Click
+= new System
.EventHandler(this.cancelButton_Click
);
178 this.okButton
.DialogResult
= System
.Windows
.Forms
.DialogResult
.OK
;
179 this.okButton
.Location
= new System
.Drawing
.Point(536, 296);
180 this.okButton
.Name
= "okButton";
181 this.okButton
.TabIndex
= 5;
182 this.okButton
.Text
= "OK";
183 this.okButton
.Click
+= new System
.EventHandler(this.okButton_Click
);
187 this.tabControl1
.Appearance
= System
.Windows
.Forms
.TabAppearance
.FlatButtons
;
188 this.tabControl1
.Controls
.Add(this.tabPage1
);
189 this.tabControl1
.Controls
.Add(this.tabPage3
);
190 this.tabControl1
.Controls
.Add(this.tabPage2
);
191 this.tabControl1
.Location
= new System
.Drawing
.Point(16, 16);
192 this.tabControl1
.Multiline
= true;
193 this.tabControl1
.Name
= "tabControl1";
194 this.tabControl1
.SelectedIndex
= 0;
195 this.tabControl1
.Size
= new System
.Drawing
.Size(600, 272);
196 this.tabControl1
.TabIndex
= 9;
200 this.tabPage1
.BorderStyle
= System
.Windows
.Forms
.BorderStyle
.FixedSingle
;
201 this.tabPage1
.Controls
.Add(this.label11
);
202 this.tabPage1
.Controls
.Add(this.label10
);
203 this.tabPage1
.Controls
.Add(this.targetTableList
);
204 this.tabPage1
.Controls
.Add(this.className
);
205 this.tabPage1
.Controls
.Add(this.hasAndBelongsToManyButton
);
206 this.tabPage1
.Controls
.Add(this.belongsToButton
);
207 this.tabPage1
.Controls
.Add(this.hasManyButton
);
208 this.tabPage1
.Location
= new System
.Drawing
.Point(4, 25);
209 this.tabPage1
.Name
= "tabPage1";
210 this.tabPage1
.Size
= new System
.Drawing
.Size(592, 243);
211 this.tabPage1
.TabIndex
= 0;
212 this.tabPage1
.Text
= "Association";
216 this.label11
.Location
= new System
.Drawing
.Point(24, 72);
217 this.label11
.Name
= "label11";
218 this.label11
.Size
= new System
.Drawing
.Size(120, 16);
219 this.label11
.TabIndex
= 11;
220 this.label11
.Text
= "ActiveRecord class:";
224 this.label10
.Location
= new System
.Drawing
.Point(400, 24);
225 this.label10
.Name
= "label10";
226 this.label10
.Size
= new System
.Drawing
.Size(120, 16);
227 this.label10
.TabIndex
= 10;
228 this.label10
.Text
= "ActiveRecord classes:";
232 this.targetTableList
.Location
= new System
.Drawing
.Point(400, 40);
233 this.targetTableList
.Name
= "targetTableList";
234 this.targetTableList
.Size
= new System
.Drawing
.Size(168, 160);
235 this.targetTableList
.TabIndex
= 9;
236 this.targetTableList
.SelectedIndexChanged
+= new System
.EventHandler(this.CheckRelationDeclaration
);
240 this.className
.Location
= new System
.Drawing
.Point(24, 88);
241 this.className
.Name
= "className";
242 this.className
.ReadOnly
= true;
243 this.className
.Size
= new System
.Drawing
.Size(168, 21);
244 this.className
.TabIndex
= 8;
245 this.className
.Text
= "Firm";
247 // hasAndBelongsToManyButton
249 this.hasAndBelongsToManyButton
.Location
= new System
.Drawing
.Point(224, 112);
250 this.hasAndBelongsToManyButton
.Name
= "hasAndBelongsToManyButton";
251 this.hasAndBelongsToManyButton
.Size
= new System
.Drawing
.Size(152, 24);
252 this.hasAndBelongsToManyButton
.TabIndex
= 7;
253 this.hasAndBelongsToManyButton
.Text
= "Has and Belongs to Many";
254 this.hasAndBelongsToManyButton
.CheckedChanged
+= new System
.EventHandler(this.CheckRelationDeclaration
);
258 this.belongsToButton
.Location
= new System
.Drawing
.Point(224, 88);
259 this.belongsToButton
.Name
= "belongsToButton";
260 this.belongsToButton
.TabIndex
= 6;
261 this.belongsToButton
.Text
= "Belongs to";
262 this.belongsToButton
.CheckedChanged
+= new System
.EventHandler(this.CheckRelationDeclaration
);
266 this.hasManyButton
.Location
= new System
.Drawing
.Point(224, 64);
267 this.hasManyButton
.Name
= "hasManyButton";
268 this.hasManyButton
.TabIndex
= 5;
269 this.hasManyButton
.Text
= "Has Many";
270 this.hasManyButton
.CheckedChanged
+= new System
.EventHandler(this.CheckRelationDeclaration
);
274 this.tabPage3
.BorderStyle
= System
.Windows
.Forms
.BorderStyle
.FixedSingle
;
275 this.tabPage3
.Controls
.Add(this.associationTableLabel
);
276 this.tabPage3
.Controls
.Add(this.associationTable
);
277 this.tabPage3
.Controls
.Add(this.relatedCols
);
278 this.tabPage3
.Controls
.Add(this.parentCols
);
279 this.tabPage3
.Controls
.Add(this.relatedColsLabel
);
280 this.tabPage3
.Controls
.Add(this.parentColsLabel
);
281 this.tabPage3
.Location
= new System
.Drawing
.Point(4, 25);
282 this.tabPage3
.Name
= "tabPage3";
283 this.tabPage3
.Size
= new System
.Drawing
.Size(592, 243);
284 this.tabPage3
.TabIndex
= 2;
285 this.tabPage3
.Text
= "Columns";
287 // associationTableLabel
289 this.associationTableLabel
.Font
= new System
.Drawing
.Font("Tahoma", 8.25F
, System
.Drawing
.FontStyle
.Bold
, System
.Drawing
.GraphicsUnit
.Point
, ((System
.Byte
)(0)));
290 this.associationTableLabel
.Location
= new System
.Drawing
.Point(208, 8);
291 this.associationTableLabel
.Name
= "associationTableLabel";
292 this.associationTableLabel
.Size
= new System
.Drawing
.Size(112, 16);
293 this.associationTableLabel
.TabIndex
= 5;
294 this.associationTableLabel
.Text
= "Association table:";
298 this.associationTable
.DropDownStyle
= System
.Windows
.Forms
.ComboBoxStyle
.DropDownList
;
299 this.associationTable
.Location
= new System
.Drawing
.Point(208, 24);
300 this.associationTable
.Name
= "associationTable";
301 this.associationTable
.Size
= new System
.Drawing
.Size(160, 21);
302 this.associationTable
.TabIndex
= 4;
303 this.associationTable
.SelectedIndexChanged
+= new System
.EventHandler(this.associationTable_SelectedIndexChanged
);
307 this.relatedCols
.Location
= new System
.Drawing
.Point(360, 88);
308 this.relatedCols
.Name
= "relatedCols";
309 this.relatedCols
.Size
= new System
.Drawing
.Size(192, 121);
310 this.relatedCols
.TabIndex
= 3;
314 this.parentCols
.Location
= new System
.Drawing
.Point(24, 88);
315 this.parentCols
.Name
= "parentCols";
316 this.parentCols
.Size
= new System
.Drawing
.Size(192, 121);
317 this.parentCols
.TabIndex
= 2;
321 this.relatedColsLabel
.Font
= new System
.Drawing
.Font("Tahoma", 8.25F
, System
.Drawing
.FontStyle
.Bold
, System
.Drawing
.GraphicsUnit
.Point
, ((System
.Byte
)(0)));
322 this.relatedColsLabel
.Location
= new System
.Drawing
.Point(360, 72);
323 this.relatedColsLabel
.Name
= "relatedColsLabel";
324 this.relatedColsLabel
.Size
= new System
.Drawing
.Size(100, 16);
325 this.relatedColsLabel
.TabIndex
= 1;
326 this.relatedColsLabel
.Text
= "Foreign Key:";
330 this.parentColsLabel
.Font
= new System
.Drawing
.Font("Tahoma", 8.25F
, System
.Drawing
.FontStyle
.Bold
, System
.Drawing
.GraphicsUnit
.Point
, ((System
.Byte
)(0)));
331 this.parentColsLabel
.Location
= new System
.Drawing
.Point(24, 72);
332 this.parentColsLabel
.Name
= "parentColsLabel";
333 this.parentColsLabel
.Size
= new System
.Drawing
.Size(100, 16);
334 this.parentColsLabel
.TabIndex
= 0;
335 this.parentColsLabel
.Text
= "Parent column:";
339 this.tabPage2
.BorderStyle
= System
.Windows
.Forms
.BorderStyle
.FixedSingle
;
340 this.tabPage2
.Controls
.Add(this.groupBox2
);
341 this.tabPage2
.Controls
.Add(this.groupBox1
);
342 this.tabPage2
.Location
= new System
.Drawing
.Point(4, 25);
343 this.tabPage2
.Name
= "tabPage2";
344 this.tabPage2
.Size
= new System
.Drawing
.Size(592, 243);
345 this.tabPage2
.TabIndex
= 1;
346 this.tabPage2
.Text
= "Customizations";
350 this.groupBox2
.Controls
.Add(this.cascade
);
351 this.groupBox2
.Controls
.Add(this.label1
);
352 this.groupBox2
.Controls
.Add(this.updateButton
);
353 this.groupBox2
.Controls
.Add(this.insertButton
);
354 this.groupBox2
.Controls
.Add(this.inverseButton
);
355 this.groupBox2
.Controls
.Add(this.lazyButton
);
356 this.groupBox2
.Location
= new System
.Drawing
.Point(24, 136);
357 this.groupBox2
.Name
= "groupBox2";
358 this.groupBox2
.Size
= new System
.Drawing
.Size(544, 88);
359 this.groupBox2
.TabIndex
= 1;
360 this.groupBox2
.TabStop
= false;
361 this.groupBox2
.Text
= "Behavior and tuning";
365 this.cascade
.DropDownStyle
= System
.Windows
.Forms
.ComboBoxStyle
.DropDownList
;
366 this.cascade
.Items
.AddRange(new object[] {
371 this.cascade
.Location
= new System
.Drawing
.Point(320, 42);
372 this.cascade
.Name
= "cascade";
373 this.cascade
.Size
= new System
.Drawing
.Size(184, 21);
374 this.cascade
.TabIndex
= 19;
378 this.label1
.Location
= new System
.Drawing
.Point(320, 26);
379 this.label1
.Name
= "label1";
380 this.label1
.Size
= new System
.Drawing
.Size(100, 16);
381 this.label1
.TabIndex
= 18;
382 this.label1
.Text
= "Cascade:";
386 this.updateButton
.Checked
= true;
387 this.updateButton
.CheckState
= System
.Windows
.Forms
.CheckState
.Checked
;
388 this.updateButton
.Location
= new System
.Drawing
.Point(48, 56);
389 this.updateButton
.Name
= "updateButton";
390 this.updateButton
.Size
= new System
.Drawing
.Size(104, 16);
391 this.updateButton
.TabIndex
= 17;
392 this.updateButton
.Text
= "Update";
396 this.insertButton
.Checked
= true;
397 this.insertButton
.CheckState
= System
.Windows
.Forms
.CheckState
.Checked
;
398 this.insertButton
.Location
= new System
.Drawing
.Point(48, 24);
399 this.insertButton
.Name
= "insertButton";
400 this.insertButton
.Size
= new System
.Drawing
.Size(104, 16);
401 this.insertButton
.TabIndex
= 16;
402 this.insertButton
.Text
= "Insert";
406 this.inverseButton
.Location
= new System
.Drawing
.Point(208, 24);
407 this.inverseButton
.Name
= "inverseButton";
408 this.inverseButton
.Size
= new System
.Drawing
.Size(64, 16);
409 this.inverseButton
.TabIndex
= 1;
410 this.inverseButton
.Text
= "Inverse";
414 this.lazyButton
.Location
= new System
.Drawing
.Point(208, 56);
415 this.lazyButton
.Name
= "lazyButton";
416 this.lazyButton
.Size
= new System
.Drawing
.Size(96, 16);
417 this.lazyButton
.TabIndex
= 0;
418 this.lazyButton
.Text
= "Lazy";
422 this.groupBox1
.Controls
.Add(this.outerJoin
);
423 this.groupBox1
.Controls
.Add(this.label9
);
424 this.groupBox1
.Controls
.Add(this.order
);
425 this.groupBox1
.Controls
.Add(this.label5
);
426 this.groupBox1
.Controls
.Add(this.where
);
427 this.groupBox1
.Controls
.Add(this.label4
);
428 this.groupBox1
.Location
= new System
.Drawing
.Point(24, 8);
429 this.groupBox1
.Name
= "groupBox1";
430 this.groupBox1
.Size
= new System
.Drawing
.Size(544, 112);
431 this.groupBox1
.TabIndex
= 0;
432 this.groupBox1
.TabStop
= false;
433 this.groupBox1
.Text
= "Queries";
437 this.outerJoin
.DropDownStyle
= System
.Windows
.Forms
.ComboBoxStyle
.DropDownList
;
438 this.outerJoin
.Items
.AddRange(new object[] {
442 this.outerJoin
.Location
= new System
.Drawing
.Point(16, 80);
443 this.outerJoin
.Name
= "outerJoin";
444 this.outerJoin
.Size
= new System
.Drawing
.Size(224, 21);
445 this.outerJoin
.TabIndex
= 17;
449 this.label9
.Location
= new System
.Drawing
.Point(16, 64);
450 this.label9
.Name
= "label9";
451 this.label9
.Size
= new System
.Drawing
.Size(100, 16);
452 this.label9
.TabIndex
= 16;
453 this.label9
.Text
= "Outer join:";
457 this.order
.Location
= new System
.Drawing
.Point(288, 40);
458 this.order
.Name
= "order";
459 this.order
.Size
= new System
.Drawing
.Size(224, 21);
460 this.order
.TabIndex
= 3;
461 this.order
.Text
= "";
465 this.label5
.Location
= new System
.Drawing
.Point(288, 24);
466 this.label5
.Name
= "label5";
467 this.label5
.Size
= new System
.Drawing
.Size(100, 16);
468 this.label5
.TabIndex
= 2;
469 this.label5
.Text
= "Order:";
473 this.where
.Location
= new System
.Drawing
.Point(16, 40);
474 this.where
.Name
= "where";
475 this.where
.Size
= new System
.Drawing
.Size(224, 21);
476 this.where
.TabIndex
= 1;
477 this.where
.Text
= "";
481 this.label4
.Location
= new System
.Drawing
.Point(16, 24);
482 this.label4
.Name
= "label4";
483 this.label4
.Size
= new System
.Drawing
.Size(100, 16);
484 this.label4
.TabIndex
= 0;
485 this.label4
.Text
= "Where:";
489 this.AutoScaleBaseSize
= new System
.Drawing
.Size(5, 14);
490 this.ClientSize
= new System
.Drawing
.Size(632, 330);
491 this.Controls
.Add(this.tabControl1
);
492 this.Controls
.Add(this.cancelButton
);
493 this.Controls
.Add(this.okButton
);
494 this.Font
= new System
.Drawing
.Font("Tahoma", 8.25F
, System
.Drawing
.FontStyle
.Regular
, System
.Drawing
.GraphicsUnit
.Point
, ((System
.Byte
)(0)));
495 this.FormBorderStyle
= System
.Windows
.Forms
.FormBorderStyle
.FixedDialog
;
496 this.MaximizeBox
= false;
497 this.Name
= "AddRelationDialog";
498 this.StartPosition
= System
.Windows
.Forms
.FormStartPosition
.CenterParent
;
499 this.Text
= "Add New Relationship";
500 this.tabControl1
.ResumeLayout(false);
501 this.tabPage1
.ResumeLayout(false);
502 this.tabPage3
.ResumeLayout(false);
503 this.tabPage2
.ResumeLayout(false);
504 this.groupBox2
.ResumeLayout(false);
505 this.groupBox1
.ResumeLayout(false);
506 this.ResumeLayout(false);
511 private void CheckRelationDeclaration(object sender
, System
.EventArgs e
)
513 CheckRelationDeclaration();
516 private void CheckRelationDeclaration()
518 tabPage2
.Enabled
= tabPage3
.Enabled
= false;
520 if (hasManyButton
.Checked
|| belongsToButton
.Checked
|| hasAndBelongsToManyButton
.Checked
)
522 if (SelectedTarget
!= null)
524 tabPage2
.Enabled
= tabPage3
.Enabled
= true;
532 if (hasManyButton
.Checked
)
534 SwitchViewTo(AssociationEnum
.HasMany
);
536 else if (hasAndBelongsToManyButton
.Checked
)
538 SwitchViewTo(AssociationEnum
.HasAndBelongsToMany
);
540 else if (belongsToButton
.Checked
)
542 SwitchViewTo(AssociationEnum
.BelongsTo
);
546 protected ActiveRecordDescriptor SelectedTarget
550 if (targetTableList
.SelectedIndex
!= -1)
552 return targetTableList
.SelectedItem
as ActiveRecordDescriptor
;
558 targetTableList
.SelectedItem
= value;
562 protected ColumnDefinition SelectedRelatedCol
566 if (relatedCols
.SelectedIndex
!= -1)
568 return relatedCols
.SelectedItem
as ColumnDefinition
;
574 protected ColumnDefinition SelectedParentCol
578 if (parentCols
.SelectedIndex
!= -1)
580 return parentCols
.SelectedItem
as ColumnDefinition
;
586 protected TableDefinition SelectedAssociationTable
590 if (associationTable
.SelectedIndex
!= -1)
592 return associationTable
.SelectedItem
as TableDefinition
;
598 protected void SwitchViewTo(AssociationEnum association
)
600 // Nothing's changed?
601 if (_oldDescSelection
== SelectedTarget
&& association
== _association
)
608 _oldDescSelection
= SelectedTarget
;
609 _association
= association
;
612 associationTable
.Enabled
= associationTableLabel
.Enabled
= false;
613 parentCols
.Enabled
= parentColsLabel
.Enabled
= false;
614 relatedCols
.Enabled
= relatedColsLabel
.Enabled
= false;
616 if (association
== AssociationEnum
.BelongsTo
)
618 parentCols
.Enabled
= parentColsLabel
.Enabled
= true;
620 PopulateColumnsInListBox( parentCols
, _descriptor
.Table
);
622 else if (association
== AssociationEnum
.HasAndBelongsToMany
)
624 associationTable
.Enabled
= associationTableLabel
.Enabled
= true;
625 parentCols
.Enabled
= parentColsLabel
.Enabled
= true;
626 relatedCols
.Enabled
= relatedColsLabel
.Enabled
= true;
628 associationTable
.SelectedIndex
= -1;
630 parentCols
.Items
.Clear();
631 relatedCols
.Items
.Clear();
633 PopulateTablesInComboBox(associationTable
, _descriptor
.Table
.DatabaseDefinition
);
635 else if (association
== AssociationEnum
.HasMany
)
637 relatedCols
.Enabled
= relatedColsLabel
.Enabled
= true;
639 PopulateColumnsInListBox( relatedCols
, SelectedTarget
.Table
);
643 private void PopulateColumnsInListBox(ListBox cols
, TableDefinition table
)
646 cols
.ValueMember
= "Name";
648 foreach(ColumnDefinition col
in table
.Columns
)
654 private void PopulateTablesInComboBox(ComboBox combo
, DatabaseDefinition dbDef
)
657 combo
.ValueMember
= "Name";
659 foreach(TableDefinition table
in dbDef
.Tables
)
661 combo
.Items
.Add(table
);
665 private void cancelButton_Click(object sender
, System
.EventArgs e
)
667 DialogResult
= DialogResult
.Cancel
;
670 private void okButton_Click(object sender
, System
.EventArgs e
)
672 if (_association
== AssociationEnum
.Undefined
)
674 cancelButton_Click(sender
, e
);
680 RelationshipInfo info
= new RelationshipInfo(_association
, _descriptor
, SelectedTarget
);
682 info
.ParentCol
= SelectedParentCol
;
683 info
.ChildCol
= SelectedRelatedCol
;
684 info
.AssociationTable
= SelectedAssociationTable
;
686 info
.Where
= where
.Text
;
687 info
.OrderBy
= order
.Text
;
688 info
.OuterJoin
= outerJoin
.Text
;
690 // TODO: Add checkbox for proxy
691 info
.UseProxy
= false;
693 info
.Insert
= insertButton
.Checked
;
694 info
.Update
= updateButton
.Checked
;
695 info
.Lazy
= lazyButton
.Checked
;
696 info
.Cascade
= cascade
.SelectedText
;
698 ActiveRecordPropertyRelationDescriptor prop
= _relationBuilder
.Build( info
);
700 _descriptor
.PropertiesRelations
.Add(prop
);
704 String message
= String
.Format("Something is missing... \r\n\r\n{0}", ex
.Message
);
705 MessageBox
.Show(this, message
, "Error", MessageBoxButtons
.OK
, MessageBoxIcon
.Error
);
709 DialogResult
= DialogResult
.OK
;
712 private void associationTable_SelectedIndexChanged(object sender
, System
.EventArgs e
)
714 if (SelectedAssociationTable
!= null)
716 PopulateColumnsInListBox(parentCols
, SelectedAssociationTable
);
717 PopulateColumnsInListBox(relatedCols
, SelectedAssociationTable
);