internal void InsertRow(DataRow row, long proposedID)
{
long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTable.InsertRow|INFO> {0}, row={1}", ObjectID, row._objectID);
try
{
if (row.Table != this)
{
throw ExceptionBuilder.RowAlreadyInOtherCollection();
}
if (row.rowID != -1)
{
throw ExceptionBuilder.RowAlreadyInTheCollection();
}
if (row._oldRecord == -1 && row._newRecord == -1)
{
throw ExceptionBuilder.RowEmpty();
}
if (proposedID == -1)
{
proposedID = _nextRowID;
}
row.rowID = proposedID;
if (_nextRowID <= proposedID)
{
_nextRowID = checked(proposedID + 1);
}
DataRowChangeEventArgs drcevent = null;
if (row._newRecord != -1)
{
row._tempRecord = row._newRecord;
row._newRecord = -1;
try
{
drcevent = RaiseRowChanging(null, row, DataRowAction.Add, true);
}
catch
{
row._tempRecord = -1;
throw;
}
row._newRecord = row._tempRecord;
row._tempRecord = -1;
}
if (row._oldRecord != -1)
{
_recordManager[row._oldRecord] = row;
}
if (row._newRecord != -1)
{
_recordManager[row._newRecord] = row;
}
Rows.ArrayAdd(row);
if (row.RowState == DataRowState.Unchanged)
{
// how about row.oldRecord == row.newRecord both == -1
RecordStateChanged(row._oldRecord, DataViewRowState.None, DataViewRowState.Unchanged);
}
else
{
RecordStateChanged(row._oldRecord, DataViewRowState.None, row.GetRecordState(row._oldRecord),
row._newRecord, DataViewRowState.None, row.GetRecordState(row._newRecord));
}
if (_dependentColumns != null && _dependentColumns.Count > 0)
{
EvaluateExpressions(row, DataRowAction.Add, null);
}
RaiseRowChanged(drcevent, row, DataRowAction.Add);
}
finally
{
DataCommonEventSource.Log.ExitScope(logScopeId);
}
}