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; } }
private void columnGrid_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { int index = e.ColumnIndex; DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)columnGrid.Rows[e.RowIndex].Cells[e.ColumnIndex]; FKColumnPair pair = fkColumnsBindingSource.Current as FKColumnPair; string value = e.FormattedValue as string; if (value == None) { cell.Value = null; if (index == 0) { pair.Column = null; } else { pair.ReferencedColumn = null; } } else { cell.Value = e.FormattedValue as string; } }
private void columnGrid_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { if (columnGrid.Rows[e.RowIndex].IsNewRow) { return; } int index = e.RowIndex; DataGridViewCell parentCell = columnGrid.Rows[e.RowIndex].Cells[0]; DataGridViewCell childCell = columnGrid.Rows[e.RowIndex].Cells[1]; string parent = parentCell.Value as string; string child = childCell.Value as string; bool bad = false; parentCell.ErrorText = childCell.ErrorText = null; if ((String.IsNullOrEmpty(parent) || parent == None) && (!String.IsNullOrEmpty(child) && child != None)) { parentCell.ErrorText = Resources.FKNeedColumn; bad = true; } else if ((String.IsNullOrEmpty(child) || child == None) && (!String.IsNullOrEmpty(parent) && parent != None)) { childCell.ErrorText = Resources.FKNeedColumn; bad = true; } if (bad) { InfoDialog.ShowDialog(InfoDialogProperties.GetInformationDialogProperties(Resources.MySqlDataProviderPackage_Information, Resources.FKColumnsNotMatched)); e.Cancel = true; return; } else if ( (((ForeignKey)foreignKeyBindingSource.Current).ReferencedTable == tableNode.Table.Name) && (parent == child)) { InfoDialog.ShowDialog(InfoDialogProperties.GetInformationDialogProperties(Resources.MySqlDataProviderPackage_Information, Resources.FKSameColumn)); return; } FKColumnPair pair = fkColumnsBindingSource.Current as FKColumnPair; pair.Column = parent; pair.ReferencedColumn = child; fkColumnsBindingSource.EndEdit(); }
private void columnGrid_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e) { FKColumnPair pair = fkColumnsBindingSource[e.RowIndex] as FKColumnPair; switch (e.ColumnIndex) { case 0: e.Value = pair.Column; break; case 1: e.Value = pair.ReferencedColumn; break; } }
private bool ValidGridData() { if (!InEditMode) { return(true); } // Removes empty rows columnGrid.CurrentCell = null; for (int i = 0; i < fkColumnsBindingSource.Count; i++) { FKColumnPair pair = fkColumnsBindingSource[i] as FKColumnPair; if ((string.IsNullOrEmpty(pair.Column) || pair.Column.Equals(None)) && (string.IsNullOrEmpty(pair.ReferencedColumn) || pair.ReferencedColumn.Equals(None))) { fkColumnsBindingSource.RemoveAt(i); columnGrid.CurrentCell = null; i--; } } for (int i = 0; i < columnGrid.Rows.Count; i++) { string str1 = ( string )((DataGridViewComboBoxCell)columnGrid.Rows[i].Cells[0]).FormattedValue; string str2 = (string)((DataGridViewComboBoxCell)columnGrid.Rows[i].Cells[1]).FormattedValue; if ((string.IsNullOrEmpty(str1) && string.IsNullOrEmpty(str2) && i == 0) || (str1.Equals("<None>", StringComparison.InvariantCultureIgnoreCase)) || (str2.Equals("<None>", StringComparison.InvariantCultureIgnoreCase))) { InfoDialog.ShowDialog(InfoDialogProperties.GetErrorDialogProperties(Resources.ErrorCaption, Resources.FkDlgBeforeClose)); return(false); } } foreach (object o in foreignKeyBindingSource) { ForeignKey fk = ( ForeignKey )o; if (fk.Columns.Count == 0) { InfoDialog.ShowDialog(InfoDialogProperties.GetErrorDialogProperties(Resources.ErrorCaption, string.Format(Resources.FkNoColumnsForForeignKey, fk.Name))); return(false); } } return(true); }
private void columnGrid_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { int index = e.RowIndex; DataGridViewCell parentCell = columnGrid.Rows[e.RowIndex].Cells[0]; DataGridViewCell childCell = columnGrid.Rows[e.RowIndex].Cells[1]; string parent = parentCell.Value as string; string child = childCell.Value as string; bool bad = false; parentCell.ErrorText = childCell.ErrorText = null; if ((String.IsNullOrEmpty(parent) || parent == None) && (!String.IsNullOrEmpty(child) && child != None)) { parentCell.ErrorText = Resources.FKNeedColumn; bad = true; } else if ((String.IsNullOrEmpty(child) || child == None) && (!String.IsNullOrEmpty(parent) && parent != None)) { childCell.ErrorText = Resources.FKNeedColumn; bad = true; } if (bad) { MessageBox.Show(Resources.FKColumnsNotMatched, null, MessageBoxButtons.OK, MessageBoxIcon.Information); e.Cancel = true; return; } FKColumnPair pair = fkColumnsBindingSource.Current as FKColumnPair; pair.Column = parent; pair.ReferencedColumn = child; fkColumnsBindingSource.EndEdit(); }