private void ParseFKInfo(DataRow keyData) { Name = keyData["CONSTRAINT_NAME"].ToString(); ReferencedTable = keyData["REFERENCED_TABLE_NAME"].ToString(); if (keyData["MATCH_OPTION"] != DBNull.Value) { Match = (MatchOption)Enum.Parse(typeof(MatchOption), keyData["MATCH_OPTION"].ToString(), true); } if (keyData["UPDATE_RULE"] != DBNull.Value) { UpdateAction = GetActionForSql(keyData["UPDATE_RULE"].ToString()); } if (keyData["DELETE_RULE"] != DBNull.Value) { DeleteAction = GetActionForSql(keyData["DELETE_RULE"].ToString()); } string[] restrictions = new string[4] { null, Table.OwningNode.Database, Table.Name, Name }; DataTable cols = Table.OwningNode.GetSchema("Foreign Key Columns", restrictions); foreach (DataRow row in cols.Rows) { FKColumnPair colPair = new FKColumnPair(); colPair.Column = row["COLUMN_NAME"].ToString(); colPair.ReferencedColumn = row["REFERENCED_COLUMN_NAME"].ToString(); Columns.Add(colPair); } }
bool ITablePart.HasChanges() { if (!ObjectHelper.AreEqual(this, oldFk)) { return(true); } if (Columns.Count != oldFk.Columns.Count) { return(true); } foreach (FKColumnPair fc in Columns) { int i = 0; for (; i < oldFk.Columns.Count; i++) { FKColumnPair ofc = oldFk.Columns[i]; if (ofc.ReferencedColumn == fc.ReferencedColumn && ofc.Column == fc.Column) { break; } } if (i == oldFk.Columns.Count) { return(true); } } return(false); }
private void ParseFKInfo(DataRow keyData) { Name = keyData["CONSTRAINT_NAME"].ToString(); ReferencedTable = keyData["REFERENCED_TABLE_NAME"].ToString(); if (keyData["MATCH_OPTION"] != DBNull.Value) Match = (MatchOption)Enum.Parse(typeof(MatchOption), keyData["MATCH_OPTION"].ToString(), true); if (keyData["UPDATE_RULE"] != DBNull.Value) UpdateAction = GetActionForSql(keyData["UPDATE_RULE"].ToString()); if (keyData["DELETE_RULE"] != DBNull.Value) DeleteAction = GetActionForSql(keyData["DELETE_RULE"].ToString()); string[] restrictions = new string[4] { null, Table.OwningNode.Database, Table.Name, Name }; DataTable cols = Table.OwningNode.GetSchema("Foreign Key Columns", restrictions); foreach (DataRow row in cols.Rows) { FKColumnPair colPair = new FKColumnPair(); colPair.Column = row["COLUMN_NAME"].ToString(); colPair.ReferencedColumn = row["REFERENCED_COLUMN_NAME"].ToString(); Columns.Add(colPair); } }
void ITablePart.Saved() { if (oldFk == null) { oldFk = new ForeignKey(Table); } // copy over the top level properties oldFk.DeleteAction = DeleteAction; oldFk.Match = Match; oldFk.Name = Name; oldFk.ReferencedTable = ReferencedTable; oldFk.Table = Table; oldFk.UpdateAction = UpdateAction; // now we need to copy the columns oldFk.Columns.Clear(); foreach (FKColumnPair fc in Columns) { FKColumnPair old = new FKColumnPair(); old.ReferencedColumn = fc.ReferencedColumn; old.Column = fc.Column; oldFk.Columns.Add(old); } }
void ITablePart.Saved() { if (oldFk == null) oldFk = new ForeignKey(Table); // copy over the top level properties oldFk.DeleteAction = DeleteAction; oldFk.Match = Match; oldFk.Name = Name; oldFk.ReferencedTable = ReferencedTable; oldFk.Table = Table; oldFk.UpdateAction = UpdateAction; // now we need to copy the columns oldFk.Columns.Clear(); foreach (FKColumnPair fc in Columns) { FKColumnPair old = new FKColumnPair(); old.ReferencedColumn = fc.ReferencedColumn; old.Column = fc.Column; oldFk.Columns.Add(old); } }
private void columnGrid_CellValuePushed(object sender, DataGridViewCellValueEventArgs e) { if (columnGrid.Rows[e.RowIndex].IsNewRow) return; FKColumnPair fk; if ((e.RowIndex == columnGrid.Rows.Count - 1) && (columnGrid.Rows.Count > fkColumnsBindingSource.Count)) { fk = new FKColumnPair() { Column = "", ReferencedColumn = "" }; fkColumnsBindingSource.Add(fk); } else { fk = (fkColumnsBindingSource[e.RowIndex] as FKColumnPair); } switch (e.ColumnIndex) { case 0: fk.Column = (string)e.Value == None ? null : (string)e.Value; break; case 1: fk.ReferencedColumn = (string)e.Value == None ? null : (string)e.Value; break; } }