private void UpdateValidityAssesment(bool actuallyDoIt = false) { ragSmiley1.Reset(); try { var fks = new ColumnInfo[] { fk1.SelectedColumn, fk2.SelectedColumn, fk3.SelectedColumn }.Where(f => f != null).ToArray(); var pks = new ColumnInfo[] { pk1.SelectedColumn, pk2.SelectedColumn, pk3.SelectedColumn }.Where(p => p != null).ToArray(); if (fk1.SelectedColumn == null || pk1.SelectedColumn == null) { throw new Exception("You must specify at least one pair of keys to join on, do this by dragging columns out of the collection into the key boxes"); } if ( ((pk2.SelectedColumn == null) != (fk2.SelectedColumn == null)) || ((pk3.SelectedColumn == null) != (fk3.SelectedColumn == null))) { throw new Exception("You must have the same number of primary and foregin keys (they must come in pairs)"); } if (pks.Any(p => p.TableInfo_ID != _leftTableInfo.ID)) { throw new Exception("All Primary Keys must come from the Left hand TableInfo"); } if (fks.Any(f => f.TableInfo_ID != _rightTableInfo.ID)) { throw new Exception("All Foreign Keys must come from the Right hand TableInfo"); } ExtractionJoinType joinType; if (rbAllLeftHandTableRecords.Checked) { joinType = ExtractionJoinType.Right; //confusing I know, basically JoinInfo database record has fk,pk and direction field assuming fk joins via that direction to pk which is the opposite to the layout of this form } else if (rbAllRightHandTableRecords.Checked) { joinType = ExtractionJoinType.Left; } else if (rbJoinInner.Checked) { joinType = ExtractionJoinType.Inner; } else { throw new Exception("You must select an Extraction Join direction"); } var cataRepo = _leftTableInfo.CatalogueRepository; for (int i = 0; i < pks.Length; i++) { if (cataRepo.GetAllObjects <JoinInfo>().Any(j => j.PrimaryKey_ID == pks[i].ID && j.ForeignKey_ID == fks[i].ID)) { throw new Exception("Join already exists between " + fks[i] + " and " + pks[i].ID); } } if (actuallyDoIt) { for (int i = 0; i < pks.Length; i++) { new JoinInfo(cataRepo, fks[i], pks[i], joinType, tbCollation.Text); } MessageBox.Show("Successfully Created Joins"); Activator.RefreshBus.Publish(this, new RefreshObjectEventArgs(_leftTableInfo)); foreach (KeyDropLocationUI ui in new[] { pk1, pk2, pk3, fk1, fk2, fk3 }) { ui.Clear(); } } else { btnCreateJoinInfo.Enabled = true; } } catch (Exception ex) { btnCreateJoinInfo.Enabled = false; ragSmiley1.Fatal(ex); } }