/// <summary> /// Adds data in specified column at row number and table all into PartDataSet given /// </summary> /// <param name="Part"></param> /// <param name="tableName"></param> /// <param name="rowNum"></param> /// <param name="colName"></param> /// <param name="Input"></param> /// <returns></returns> public static PartDataSet AddDatum(PartDataSet Part, string tableName, int rowNum, string colName, string Input, DataViewRowState RowState) { DataTable PartDT = Part.Tables[tableName]; DataRow[] WorkRow = PartDT.Select(null, null, RowState); WorkRow[0] = PartDT.Rows[rowNum]; try { WorkRow[0][colName] = Input; } catch (System.Exception ex) { try { WorkRow[0][colName] = double.Parse(Input); } catch //(System.Exception ex1) { try { WorkRow[0][colName] = (int)(double.Parse(Input)); } catch //(System.Exception ex2) { System.Windows.Forms.MessageBox.Show(ex.Message, "Error!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); } } } return Part; }
/// <summary> /// Salva no banco de dados as alterações em uma tabela. /// </summary> /// <param name="dt">A tabela</param> /// <param name="state"> /// O estado que estará sendo processado. Pode ser /// <see cref="DataViewRowState.Added"/>, /// <see cref="DataViewRowState.ModifiedCurrent"/> ou /// <see cref="DataViewRowState.Deleted"/> /// </param> /// <returns>O número de registros atualizados</returns> protected int CommitTable(DataTable dt, DataViewRowState state) { int c = 0; if (dt != null && dt.Rows.Count > 0) { try { using (new PhysicalTableAdapter(conn, dt)) using (AdpDataAdapter da = new AdpDataAdapter()) { DataRow[] rows = dt.Select(null, null, state); if (rows.Length > 0) { if (!conn.BuildCommands(da, dbConn, dt)) new AdpCommandBuilder(da, dbConn, dt); if (trans != null) SetTransaction(da); if (state == DataViewRowState.Added) c += CommitInserts(dt, da, rows); else c += da.Update(rows); } } } catch (Exception ex) { throw ConnectorExceptionFactory.FromDatabaseException(ex).Detail("Error while updating data table named {0}", dt.TableName); } } return c; }
/// <summary> /// Creates a new <see cref="FeatureDataView"/> on the given /// <see cref="FeatureDataTable"/> having the specified geometry filter, /// sort order and row state filter. /// </summary> /// <param name="table">Table to create view on.</param> /// <param name="intersectionFilter"> /// Geometry used in intersection test to filter feature table rows. /// </param> /// <param name="sort">Sort expression to order view by.</param> /// <param name="rowState">Filter on the state of the rows to view.</param> public FeatureDataView(FeatureDataTable table, IGeometry intersectionFilter, String sort, DataViewRowState rowState) : this(table, intersectionFilter, SpatialOperation.Intersects, sort, rowState) { }
static internal DataRow[] SelectRows(DataTable dataTable, DataViewRowState rowStates) { // equivalent to but faster than 'return dataTable.Select("", "", rowStates);' int count = 0; DataRowCollection rows = dataTable.Rows; int rowCount = rows.Count; for (int i = 0; i < rowCount; ++i) { if (0 != ((int)rowStates & (int)rows[i].RowState)) { count++; } } DataRow[] dataRows = new DataRow[count]; if (0 < count) { int index = 0; for (int i = 0; index < count; ++i) { if (0 != ((int)rowStates & (int)rows[i].RowState)) { dataRows[index++] = rows[i]; } } } Debug.Assert(null != dataRows, "SelectRows: null return value"); return(dataRows); }
internal Key(DataTable table, DataColumn[] columns, ListSortDirection[] sort, DataViewRowState rowState, IExpression filter) { _table = table; _filter = filter; if (_filter != null) { _tmpRow = _table.NewNotInitializedRow(); } _columns = columns; if (sort != null && sort.Length == columns.Length) { _sortDirection = sort; } else { _sortDirection = new ListSortDirection[columns.Length]; for (int i = 0; i < _sortDirection.Length; i++) { _sortDirection[i] = ListSortDirection.Ascending; } } if (rowState != DataViewRowState.None) { _rowStateFilter = rowState; } else { // FIXME : what is the correct value ? _rowStateFilter = DataViewRowState.CurrentRows; } }
private void UpdateInternal(SqlDataAdapter dataAdapter, DataViewRowState recordStates, DataTable sourceTable, UpdateErrorHandler errorHandler) { try { while (true) { DataRow[] changedRows = sourceTable.Select(null, null, recordStates); ErrorHandlerArgs args = null; try { SqlRowUpdatedEventHandler rowUpdated = delegate(object sender, SqlRowUpdatedEventArgs e) { args = new ErrorHandlerArgs(sourceTable.TableName, e.Row, recordStates, e.Errors); }; dataAdapter.RowUpdated += rowUpdated; dataAdapter.Update(changedRows); break; } catch { if (errorHandler == null) { throw; } errorHandler(args); if (args.Action == ErrorHandlingAction.ThrowError) { throw; } } } } catch { throw; } }
internal void SetIndex2(String newSort, DataViewRowState dataViewRowState, Object dataExpression, Boolean fireEvent) { // Call the delegate we wired up to bypass the normally inaccessible // base class method _setIndex2(this, newSort, dataViewRowState, dataExpression, fireEvent); }
public virtual void DoRowEvents() { DataTable table = GetTable(); if (table == null) { return; } DataViewRowState st = DataViewRowState.Added | DataViewRowState.ModifiedCurrent | DataViewRowState.Deleted; DataRow[] rows = table.Select(null, null, st); List <DataRow> rows2 = new List <DataRow>(); foreach (var dr1 in rows) { if (dr1.RowState != DataRowState.Detached && !HasNewParent(dr1)) { rows2.Add(dr1); } } rows = rows2.ToArray(); OnMyBeforeRowUpdateA(rows); }
private Index(DataTable table, IndexField[] indexFields, System.Comparison <DataRow>?comparison, DataViewRowState recordStates, IFilter?rowFilter) { DataCommonEventSource.Log.Trace("<ds.Index.Index|API> {0}, table={1}, recordStates={2}", ObjectID, (table != null) ? table.ObjectID : 0, recordStates); Debug.Assert(indexFields != null); Debug.Assert(null != table, "null table"); if ((recordStates & (~(DataViewRowState.CurrentRows | DataViewRowState.OriginalRows))) != 0) { throw ExceptionBuilder.RecordStateRange(); } _table = table; _listeners = new Listeners <DataViewListener>(ObjectID, listener => null != listener); _indexFields = indexFields; _recordStates = recordStates; _comparison = comparison; _isSharable = (rowFilter == null) && (comparison == null); // a filter or comparison make an index unsharable if (null != rowFilter) { _rowFilter = new WeakReference(rowFilter); DataExpression?expr = (rowFilter as DataExpression); if (null != expr) { _hasRemoteAggregate = expr.HasRemoteAggregate(); } } InitRecords(rowFilter); // do not AddRef in ctor, every caller should be responsible to AddRef it // if caller does not AddRef, it is expected to be a one-time read operation because the index won't be maintained on writes }
/// <summary> /// Saves the data set simple. /// </summary> /// <param name="cmd">The cmd.</param> /// <param name="set">The set.</param> /// <param name="state">The state.</param> /// <param name="tables">The tables.</param> public static void SaveDataSetSimple(DataCommand cmd, DataSet set, DataViewRowState state, params string[] tables) { foreach (string table in tables) { SaveTableSimple(cmd, set.Tables[table], state); } }
private Index(DataTable table, int[] ndexDesc, IndexField[] indexFields, Comparison<DataRow> comparison, DataViewRowState recordStates, IFilter rowFilter) { this._objectID = Interlocked.Increment(ref _objectTypeCount); Bid.Trace("<ds.Index.Index|API> %d#, table=%d, recordStates=%d{ds.DataViewRowState}\n", this.ObjectID, (table != null) ? table.ObjectID : 0, (int) recordStates); if ((recordStates & ~(DataViewRowState.OriginalRows | DataViewRowState.ModifiedCurrent | DataViewRowState.Added)) != DataViewRowState.None) { throw ExceptionBuilder.RecordStateRange(); } this.table = table; this._listeners = new Listeners<DataViewListener>(this.ObjectID, listener => null != listener); this.IndexDesc = ndexDesc; this.IndexFields = indexFields; if (ndexDesc == null) { this.IndexDesc = Select.ConvertIndexFieldtoIndexDesc(indexFields); } this.recordStates = recordStates; this._comparison = comparison; DataColumnCollection columns = table.Columns; this.isSharable = (rowFilter == null) && (comparison == null); if (rowFilter != null) { this.rowFilter = new WeakReference(rowFilter); DataExpression expression = rowFilter as DataExpression; if (expression != null) { this._hasRemoteAggregate = expression.HasRemoteAggregate(); } } this.InitRecords(rowFilter); }
static internal DbSchemaRow[] GetSortedSchemaRows(DataTable dataTable, bool returnProviderSpecificTypes) { // MDAC 60609 DataColumn sortindex = dataTable.Columns[SchemaMappingUnsortedIndex]; if (null == sortindex) { // WebData 100390 sortindex = new DataColumn(SchemaMappingUnsortedIndex, typeof(Int32)); // MDAC 67050 dataTable.Columns.Add(sortindex); } int count = dataTable.Rows.Count; for (int i = 0; i < count; ++i) { dataTable.Rows[i][sortindex] = i; } ; DbSchemaTable schemaTable = new DbSchemaTable(dataTable, returnProviderSpecificTypes); const DataViewRowState rowStates = DataViewRowState.Unchanged | DataViewRowState.Added | DataViewRowState.ModifiedCurrent; DataRow[] dataRows = dataTable.Select(null, "ColumnOrdinal ASC", rowStates); Debug.Assert(null != dataRows, "GetSchemaRows: unexpected null dataRows"); DbSchemaRow[] schemaRows = new DbSchemaRow[dataRows.Length]; for (int i = 0; i < dataRows.Length; ++i) { schemaRows[i] = new DbSchemaRow(schemaTable, dataRows[i]); } return(schemaRows); }
internal DataView(DataTable table, DataViewManager manager) { dataTable = table; rowState = DataViewRowState.CurrentRows; dataViewManager = manager; Open(); }
private int GetChangeAction(DataViewRowState oldState, DataViewRowState newState) { int oldIncluded = ((int)recordStates & (int)oldState) == 0? 0: 1; int newIncluded = ((int)recordStates & (int)newState) == 0? 0: 1; return(newIncluded - oldIncluded); }
static internal DBSchemaRow[] GetSortedSchemaRows(DataTable dataTable) // MDAC 60609 { DataColumn sortindex = new DataColumn("SchemaMapping Unsorted Index", typeof(Int32)); // MDAC 67050 dataTable.Columns.Add(sortindex); int count = dataTable.Rows.Count; for (int i = 0; i < count; ++i) { dataTable.Rows[i][sortindex] = i; } ; DBSchemaTable schemaTable = new DBSchemaTable(dataTable); const DataViewRowState rowStates = DataViewRowState.Unchanged | DataViewRowState.Added | DataViewRowState.ModifiedCurrent; DataRow[] dataRows = dataTable.Select(null, "ColumnOrdinal ASC", rowStates); Debug.Assert(null != dataRows, "GetSchemaRows: unexpected null dataRows"); DBSchemaRow[] schemaRows = new DBSchemaRow[dataRows.Length]; for (int i = 0; i < dataRows.Length; ++i) { schemaRows[i] = new DBSchemaRow(schemaTable, dataRows[i]); } return(schemaRows); }
internal Key(DataTable table,DataColumn[] columns,ListSortDirection[] sort, DataViewRowState rowState, IExpression filter) { _table = table; _filter = filter; if (_filter != null) _tmpRow = _table.NewNotInitializedRow(); _columns = columns; if (sort != null && sort.Length == columns.Length) { _sortDirection = sort; } else { _sortDirection = new ListSortDirection[columns.Length]; for(int i=0; i < _sortDirection.Length; i++) { _sortDirection[i] = ListSortDirection.Ascending; } } if (rowState != DataViewRowState.None) { _rowStateFilter = rowState; } else { // FIXME : what is the correct value ? _rowStateFilter = DataViewRowState.CurrentRows; } }
public void RecordStateChanged(int record, DataViewRowState oldState, DataViewRowState newState) { DataCommonEventSource.Log.Trace("<ds.Index.RecordStateChanged|API> {0}, record={1}, oldState={2}, newState={3}", ObjectID, record, oldState, newState); int action = GetChangeAction(oldState, newState); ApplyChangeAction(record, action, GetReplaceAction(oldState)); }
public void RecordStateChanged(int record, DataViewRowState oldState, DataViewRowState newState) { Bid.Trace("<ds.Index.RecordStateChanged|API> %d#, record=%d, oldState=%d{ds.DataViewRowState}, newState=%d{ds.DataViewRowState}\n", ObjectID, record, (int)oldState, (int)newState); int action = GetChangeAction(oldState, newState); ApplyChangeAction(record, action, GetReplaceAction(oldState)); }
/// <summary> /// Creates a new <see cref="FeatureDataView"/> on the given /// <see cref="FeatureDataTable"/> having the specified geometry filter, /// sort order and row state filter. /// </summary> /// <param name="table">Table to create view on.</param> /// <param name="query"> /// Geometry used in building view to filter feature table rows. /// </param> /// <param name="op"> /// Type of spatial relation which <paramref name="query"/> has to features. /// </param> /// <param name="sort">Sort expression to order view by.</param> /// <param name="rowState">Filter on the state of the rows to view.</param> public FeatureDataView(FeatureDataTable table, IGeometry query, SpatialOperation op, String sort, DataViewRowState rowState) : this(table, new FeatureQueryExpression(query, op, table), sort, rowState) { }
/// <summary> /// Gets the row containing the specified primary key values by searching the rows /// filtered by the state. /// </summary> internal DataRow Find(object [] keys, DataViewRowState rowStateFilter) { if (table.PrimaryKey.Length == 0) { throw new MissingPrimaryKeyException("Table doesn't have a primary key."); } if (keys == null) { throw new ArgumentException("Expecting " + table.PrimaryKey.Length + " value(s) for the key being indexed, but received 0 value(s)."); } Index index = table.GetIndex(table.PrimaryKey, null, rowStateFilter, null, false); int record = index.Find(keys); if (record != -1 || !table._duringDataLoad) { return(record != -1 ? table.RecordCache [record] : null); } // If the key is not found using Index *and* if DataTable is under BeginLoadData // then, check all the DataRows for the key record = table.RecordCache.NewRecord(); try { for (int i = 0; i < table.PrimaryKey.Length; ++i) { table.PrimaryKey [i].DataContainer [record] = keys [i]; } bool found; foreach (DataRow row in this) { int rowIndex = Key.GetRecord(row, rowStateFilter); if (rowIndex == -1) { continue; } found = true; for (int columnCnt = 0; columnCnt < table.PrimaryKey.Length; ++columnCnt) { if (table.PrimaryKey [columnCnt].CompareValues(rowIndex, record) == 0) { continue; } found = false; break; } if (found) { return(row); } } return(null); } finally { table.RecordCache.DisposeRecord(record); } }
internal DataViewSetting(string sort, string rowFilter, DataViewRowState rowStateFilter) { this.sort = ""; this.rowFilter = ""; this.rowStateFilter = DataViewRowState.CurrentRows; this.sort = sort; this.rowFilter = rowFilter; this.rowStateFilter = rowStateFilter; }
/// <summary> /// find rows in the datatable /// </summary> /// <param name="strFilter">filter</param> /// <param name="rowState">data row state</param> /// <param name="objTable">table</param> /// <returns></returns> public static DataRow[] FindRows(string strFilter, DataViewRowState rowState, System.Data.DataTable objTable) { if (objTable == null || objTable.Rows.Count <= 0) { return(null); } return(objTable.Select(strFilter, "", rowState)); }
public Select(DataTable table, string filterExpression, string sort, DataViewRowState recordStates) { this.table = table; IndexFields = table.ParseSortString(sort); if (filterExpression != null && filterExpression.Length > 0) { this.rowFilter = new DataExpression(this.table, filterExpression); this.expression = this.rowFilter.ExpressionNode; } this.recordStates = recordStates; }
private void InitRecords(IFilter filter) { DataViewRowState states = recordStates; // SQLBU 428961: Serious performance issue when creating DataView // this improves performance when the is no filter, like with the default view (creating after rows added) // we know the records are in the correct order, just append to end, duplicates not possible bool append = (0 == IndexFields.Length); records = new IndexTree(this); recordCount = 0; // SQLBU 428961: Serious performance issue when creating DataView // this improves performance by iterating of the index instead of computing record by index foreach (DataRow b in table.Rows) { int record = -1; if (b.oldRecord == b.newRecord) { if ((int)(states & DataViewRowState.Unchanged) != 0) { record = b.oldRecord; } } else if (b.oldRecord == -1) { if ((int)(states & DataViewRowState.Added) != 0) { record = b.newRecord; } } else if (b.newRecord == -1) { if ((int)(states & DataViewRowState.Deleted) != 0) { record = b.oldRecord; } } else { if ((int)(states & DataViewRowState.ModifiedCurrent) != 0) { record = b.newRecord; } else if ((int)(states & DataViewRowState.ModifiedOriginal) != 0) { record = b.oldRecord; } } if (record != -1 && AcceptRecord(record, filter)) { records.InsertAt(-1, record, append); recordCount++; } } }
private void SaveState() { var state = new DataViewRowState { SelectedPublicKeys = this.PublicKeys.Where(model => model.IsSelected).Select(model => model.KeyPairInfos.PublicKey.ToAns1()).ToList() }; new LocalStorageManager().RemoveAll("SelectedPublicKeysAns1"); new LocalStorageManager().Add(state, "SelectedPublicKeysAns1"); }
public void RecordStateChanged(int oldRecord, DataViewRowState oldOldState, DataViewRowState oldNewState, int newRecord, DataViewRowState newOldState, DataViewRowState newNewState) { Bid.Trace("<ds.Index.RecordStateChanged|API> %d#, oldRecord=%d, oldOldState=%d{ds.DataViewRowState}, oldNewState=%d{ds.DataViewRowState}, newRecord=%d, newOldState=%d{ds.DataViewRowState}, newNewState=%d{ds.DataViewRowState}\n", this.ObjectID, oldRecord, (int) oldOldState, (int) oldNewState, newRecord, (int) newOldState, (int) newNewState); int changeAction = this.GetChangeAction(oldOldState, oldNewState); int action = this.GetChangeAction(newOldState, newNewState); if (((changeAction == -1) && (action == 1)) && this.AcceptRecord(newRecord)) { int index; if ((this._comparison != null) && (changeAction < 0)) { index = this.GetIndex(oldRecord, GetReplaceAction(oldOldState)); } else { index = this.GetIndex(oldRecord); } if (((this._comparison == null) && (index != -1)) && (this.CompareRecords(oldRecord, newRecord) == 0)) { this.records.UpdateNodeKey(oldRecord, newRecord); int newIndex = this.GetIndex(newRecord); this.OnListChanged(ListChangedType.ItemChanged, newIndex, newIndex); } else { this.suspendEvents = true; if (index != -1) { this.records.DeleteByIndex(index); this.recordCount--; } this.records.Insert(newRecord); this.recordCount++; this.suspendEvents = false; int num2 = this.GetIndex(newRecord); if (index == num2) { this.OnListChanged(ListChangedType.ItemChanged, num2, index); } else if (index == -1) { this.MaintainDataView(ListChangedType.ItemAdded, newRecord, false); this.OnListChanged(ListChangedType.ItemAdded, this.GetIndex(newRecord)); } else { this.OnListChanged(ListChangedType.ItemMoved, num2, index); } } } else { this.ApplyChangeAction(oldRecord, changeAction, GetReplaceAction(oldOldState)); this.ApplyChangeAction(newRecord, action, GetReplaceAction(newOldState)); } }
public Select(DataTable table, string filterExpression, string sort, DataViewRowState recordStates) { _table = table; _indexFields = table.ParseSortString(sort); if (filterExpression != null && filterExpression.Length > 0) { _rowFilter = new DataExpression(_table, filterExpression); _expression = _rowFilter.ExpressionNode; } _recordStates = recordStates; }
public Select(DataTable table, string filterExpression, string sort, DataViewRowState recordStates) { this.table = table; this.indexDesc = table.ParseSortString(sort); if (filterExpression != null && filterExpression.Length > 0) { this.rowFilter = new DataFilter(filterExpression, this.table); this.expression = this.rowFilter.expr; } this.recordStates = recordStates; }
public void BeginInit() { initTable = Table; initApplyDefaultSort = ApplyDefaultSort; initSort = Sort; initRowFilter = RowFilter; initRowState = RowStateFilter; isInitPhase = true; DataViewInitialized(false); }
internal DataView(DataTable table, DataViewManager manager, string RowFilter, string Sort, DataViewRowState RowState) { dataTable = table; dataViewManager = manager; rowState = DataViewRowState.CurrentRows; this.RowFilter = RowFilter; this.Sort = Sort; rowState = RowState; Open(); }
public ErrorHandlerArgs(string tableName, DataRow changedRow, DataViewRowState recordStates, Exception exception) { try { this._TableName = tableName; this._ChangedRow = changedRow; this._Exception = exception; this._RecordStates = recordStates; } catch { throw; } }
public Select(DataTable table, string?filterExpression, string?sort, DataViewRowState recordStates) { _table = table; _indexFields = table.ParseSortString(sort); if (filterExpression != null && filterExpression.Length > 0) { _rowFilter = new DataExpression(_table, filterExpression); _expression = _rowFilter.ExpressionNode; } _recordStates = recordStates; }
private void InitRecords() { int count = table.Rows.Count; DataViewRowState states = recordStates; records = new int[count]; recordCount = 0; for (int i = 0; i < count; i++) { DataRow b = table.Rows[i]; int record = -1; if (b.oldRecord == b.newRecord) { if ((int)(states & DataViewRowState.Unchanged) != 0) { record = b.oldRecord; } } else if (b.oldRecord == -1) { if ((int)(states & DataViewRowState.Added) != 0) { record = b.newRecord; } } else if (b.newRecord == -1) { if ((int)(states & DataViewRowState.Deleted) != 0) { record = b.oldRecord; } } else { if ((int)(states & DataViewRowState.ModifiedCurrent) != 0) { record = b.newRecord; } else if ((int)(states & DataViewRowState.ModifiedOriginal) != 0) { record = b.oldRecord; } } if (record != -1 && AcceptRecord(record)) { records[recordCount++] = record; } } if (recordCount > 1 && indexDesc.Length > 0) { Sort(0, recordCount - 1); } }
/// <summary> /// Overriding DataView's SetIndex to prevent users from setting RowState filter to anything other /// than CurrentRows. /// </summary> internal override void SetIndex(string newSort, DataViewRowState newRowStates, IFilter?newRowFilter) { // Throw only if expressions (filter or sort) are used and rowstate is not current rows if ((base.SortComparison != null || base.RowPredicate != null) && newRowStates != DataViewRowState.CurrentRows) { throw DataSetUtil.Argument(SR.LDVRowStateError); } else { base.SetIndex(newSort, newRowStates, newRowFilter); } }
private void ApplyFilter(DataViewRowState aDataViewRowState){ if (CurrentDataTable == null) { return; } fDataRows = new DataView(CurrentDataTable, "", "", aDataViewRowState); dataGrid.DataSource = fDataRows; fDataViewRowState = aDataViewRowState; fSelect = ""; SetStatusBar(); }
private void CheckData(DataViewRowState filterState, string errorMessage) { DataView dv = new DataView(_data.DsData.Tables[0]); dv.RowStateFilter = filterState; if (dv.Count == 0) return; DataRowView drv = dv[0]; string OldMaVT = drv["MaVT"].ToString(); if (CheckExist(OldMaVT)) { if (filterState == DataViewRowState.Deleted) { ShowMessageBox(errorMessage); _info.Result = false; } else { dv.RowStateFilter = DataViewRowState.ModifiedCurrent; string NewMaVT = drv["MaVT"].ToString(); if (NewMaVT != OldMaVT) { ShowMessageBox(errorMessage); _info.Result = false; } else { _info.Result = true; } } } else { _info.Result = true; } }
internal Index FindIndex (DataColumn[] columns, ListSortDirection[] sort, DataViewRowState rowState, IExpression filter) { if (Indexes != null) { foreach (Index index in Indexes) { if (index.Key.Equals (columns,sort,rowState, filter)) return index; } } return null; }
internal Index GetIndex (DataColumn[] columns, ListSortDirection[] sort, DataViewRowState rowState, IExpression filter, bool reset, bool addIndex) { Index index = FindIndex(columns, sort, rowState, filter); if (index == null) { index = new Index(new Key (this, columns, sort, rowState, filter)); if (addIndex) AddIndex (index); } else if (reset) { // reset existing index only if asked for this index.Reset (); } return index; }
/// <summary> /// Returns index corresponding to columns,sort,row state filter and unique values given. /// If such an index not exists, creates a new one. /// </summary> /// <param name="columns">Columns set of the index to look for.</param> /// <param name="sort">Columns sort order of the index to look for.</param> /// <param name="rowState">Rpw state filter of the index to look for.</param> /// <param name="unique">Uniqueness of the index to look for.</param> /// <param name="strict">Indicates whenever the index found should correspond in its uniquness to the value of unique parameter specified.</param> /// <param name="reset">Indicates whenever the already existing index should be forced to reset.</param> /// <returns></returns> internal Index GetIndex (DataColumn[] columns, ListSortDirection[] sort, DataViewRowState rowState, IExpression filter, bool reset) { return GetIndex (columns, sort, rowState, filter, reset, true); }
// // Summary: // Gets an array of all System.Data.DataRow objects that match the filter in // the order of the sort that match the specified state. // // Parameters: // filterExpression: // The criteria to use to filter the rows. // // sort: // A string specifying the column and sort direction. // // recordStates: // One of the System.Data.DataViewRowState values. // // Returns: // An array of System.Data.DataRow objects. public DataRow[] Select(string filterExpression, string sort, DataViewRowState recordStates) { Contract.Ensures(Contract.Result<DataRow[]>() != null); return default(DataRow[]); }
internal void RecordStateChanged(int record1, DataViewRowState oldState1, DataViewRowState newState1, int record2, DataViewRowState oldState2, DataViewRowState newState2) { SetShadowIndexes(); try{ int numIndexes = shadowIndexes.Count; for (int i = 0; i < numIndexes; i++) { Index ndx = shadowIndexes[i];// shadowindexes may change, see ShadowIndexCopy() if (0 < ndx.RefCount) { if (record1 != -1 && record2 != -1) ndx.RecordStateChanged(record1, oldState1, newState1, record2, oldState2, newState2); else if (record1 != -1) ndx.RecordStateChanged(record1, oldState1, newState1); else if (record2 != -1) ndx.RecordStateChanged(record2, oldState2, newState2); } } } finally { RestoreShadowIndexes(); } // System.Data.XML.Store.Store.OnROMChanged(record1, oldState1, newState1, record2, oldState2, newState2); }
/// <summary> /// Gets an array of all <see cref="T:System.Data.DataRow"/> objects that match the filter in the order of the sort that match the specified state. /// </summary> /// <returns> /// An array of <see cref="T:System.Data.DataRow"/> objects. /// </returns> /// <param name="filterExpression"> /// The criteria to use to filter the rows. For examples on how to filter rows, see DataView RowFilter Syntax [C#]. /// </param> /// <param name="sort"> /// A string specifying the column and sort direction. /// </param> /// <param name="recordStates"> /// One of the <see cref="T:System.Data.DataViewRowState"/> values. /// </param> public DataRow[] Select(string filterExpression, string sort, DataViewRowState recordStates) { return this.DataTableInstance.Select(filterExpression, sort, recordStates); }
public DataView (DataTable table, string rowFilter, string sort, DataViewRowState rowState) : this (table, null, rowFilter, sort, rowState) { }
internal DataView (DataTable table, DataViewManager manager) { dataTable = table; rowState = DataViewRowState.CurrentRows; dataViewManager = manager; Open (); }
public DataView () { rowState = DataViewRowState.CurrentRows; Open (); }
public void BeginInit() { initTable = Table; initApplyDefaultSort = ApplyDefaultSort; initSort = Sort; initRowFilter = RowFilter; initRowState = RowStateFilter; isInitPhase = true; }
/// <summary> /// Checks for key equality to parameters set given /// </summary> /// <param name="columns">Columns the key consits of. If this parameter is null, it does not affects equality check</param> /// <param name="sort">Sort order of columns. If this parameter is null, it does not affects equality check</param> /// <param name="rowState">DataViewRowState to check for.If this parameter is null, it does not affects equality check</param> /// <param name="unique">Indicates whenever the index managed by this key allows non-uniqie keys to appear.</param> /// <param name="strict">Indicates whenever unique parameter should affect the equality check.</param> /// <returns></returns> internal bool Equals(DataColumn[] columns, ListSortDirection[] sort, DataViewRowState rowState, IExpression filter) { if (rowState != DataViewRowState.None && RowStateFilter != rowState) { return false; } if (_filter != null) { if (!_filter.Equals (filter)) return false; } else if (filter != null) return false; if (Columns.Length != columns.Length) { return false; } if (sort != null && Sort.Length != sort.Length) { return false; } if (sort != null) { for(int i=0; i < columns.Length; i++) { if (Sort[i] != sort[i] || Columns[i] != columns[i]) { return false; } } } else { for(int i=0; i < columns.Length; i++) { if (Sort [i] != ListSortDirection.Ascending || Columns[i] != columns[i]) { return false; } } } return true; }
internal static int GetRecord(DataRow row, DataViewRowState rowStateFilter) { switch (row.RowState) { case DataRowState.Unchanged: { if ((rowStateFilter & DataViewRowState.Unchanged) != DataViewRowState.None) return row.Proposed >= 0 ? row.Proposed : row.Current; break; } case DataRowState.Added: { if ((rowStateFilter & DataViewRowState.Added) != DataViewRowState.None) return row.Proposed >= 0 ? row.Proposed : row.Current; break; } case DataRowState.Deleted: { if ((rowStateFilter & DataViewRowState.Deleted) != DataViewRowState.None) return row.Original; break; } default: if ((rowStateFilter & DataViewRowState.ModifiedCurrent) != DataViewRowState.None) return row.Proposed >= 0 ? row.Proposed : row.Current; if ((rowStateFilter & DataViewRowState.ModifiedOriginal) != DataViewRowState.None) return row.Original; break; } return -1; }
public UpdateableDataView(DataTable table, string rowfilter, string sort, DataViewRowState rowstate) : base(table, rowfilter, sort, rowstate) { this.BaseRowFilter = rowfilter; }
internal Index GetIndex(IndexField[] indexDesc, DataViewRowState recordStates, IFilter rowFilter) { indexesLock.AcquireReaderLock(-1); try { for (int i = 0; i < indexes.Count; i++) { Index index = indexes[i]; if (index != null) { if (index.Equal(indexDesc, recordStates, rowFilter)) { return index; } } } } finally { indexesLock.ReleaseReaderLock(); } Index ndx = new Index(this, indexDesc, recordStates, rowFilter); ndx.AddRef(); return ndx; }
internal DataView (DataTable table, DataViewManager manager, string RowFilter, string Sort, DataViewRowState RowState) { dataTable = table; dataViewManager = manager; rowState = DataViewRowState.CurrentRows; this.RowFilter = RowFilter; this.Sort = Sort; rowState = RowState; Open (); }
internal override void SetIndex(string newSort, DataViewRowState newRowStates, IFilter newRowFilter) { SetIndex2(newSort, newRowStates, newRowFilter, false); Reset(); }
internal Index GetIndex(string sort, DataViewRowState recordStates, IFilter rowFilter) { return GetIndex(ParseSortString(sort), recordStates, rowFilter); }
/// <summary> /// Gets the row containing the specified primary key values by searching the rows /// filtered by the state. /// </summary> internal DataRow Find (object [] keys, DataViewRowState rowStateFilter) { if (table.PrimaryKey.Length == 0) throw new MissingPrimaryKeyException ("Table doesn't have a primary key."); if (keys == null) throw new ArgumentException ("Expecting " + table.PrimaryKey.Length +" value(s) for the key being indexed, but received 0 value(s)."); Index index = table.GetIndex (table.PrimaryKey, null, rowStateFilter, null, false); int record = index.Find (keys); if (record != -1 || !table._duringDataLoad) return (record != -1 ? table.RecordCache [record] : null); // If the key is not found using Index *and* if DataTable is under BeginLoadData // then, check all the DataRows for the key record = table.RecordCache.NewRecord (); try { for (int i=0; i < table.PrimaryKey.Length; ++i) table.PrimaryKey [i].DataContainer [record] = keys [i]; bool found; foreach (DataRow row in this) { int rowIndex = Key.GetRecord (row, rowStateFilter); if (rowIndex == -1) continue; found = true; for (int columnCnt = 0; columnCnt < table.PrimaryKey.Length; ++columnCnt) { if (table.PrimaryKey [columnCnt].CompareValues (rowIndex, record) == 0) continue; found = false; break; } if (found) return row; } return null; } finally { table.RecordCache.DisposeRecord (record); } }
internal void RecordStateChanged(int record, DataViewRowState oldState, DataViewRowState newState) { SetShadowIndexes(); try{ int numIndexes = shadowIndexes.Count; for (int i = 0; i < numIndexes; i++) { Index ndx = shadowIndexes[i];// shadowindexes may change, see ShadowIndexCopy() if (0 < ndx.RefCount) { ndx.RecordStateChanged(record, oldState, newState); } } } finally{ RestoreShadowIndexes(); } // System.Data.XML.Store.Store.OnROMChanged(record, oldState, newState); }
/// <summary> /// Gets an array of all DataRow objects that match /// the filter in the order of the sort, that match /// the specified state. /// </summary> public DataRow [] Select (string filterExpression, string sort, DataViewRowState recordStates) { if (filterExpression == null) filterExpression = String.Empty; IExpression filter = null; if (filterExpression != String.Empty) { Parser parser = new Parser (); filter = parser.Compile (filterExpression); } DataColumn [] columns = _emptyColumnArray; ListSortDirection [] sorts = null; if (sort != null && !sort.Equals(String.Empty)) columns = ParseSortString (this, sort, out sorts, false); if (Rows.Count == 0) return NewRowArray (0); //if sort order is not given, sort it in Ascending order of the //columns involved in the filter if (columns.Length == 0 && filter != null) { ArrayList list = new ArrayList (); for (int i = 0; i < Columns.Count; ++i) { if (!filter.DependsOn (Columns [i])) continue; list.Add (Columns [i]); } columns = (DataColumn []) list.ToArray (typeof (DataColumn)); } bool addIndex = true; if (filterExpression != String.Empty) addIndex = false; Index index = GetIndex (columns, sorts, recordStates, filter, false, addIndex); int [] records = index.GetAll (); DataRow [] dataRows = NewRowArray (index.Size); for (int i = 0; i < dataRows.Length; i++) dataRows [i] = RecordCache [records [i]]; return dataRows; }
/// <devdoc> /// <para>Returns an array of all <see cref='System.Data.DataRow'/> objects that match the filter in the order of the /// sort, that match the specified state.</para> /// </devdoc> public DataRow[] Select(string filterExpression, string sort, DataViewRowState recordStates) { Bid.Trace("<ds.DataTable.Select|API> %d#, filterExpression='%ls', sort='%ls', recordStates=%d{ds.DataViewRowState}\n", ObjectID, filterExpression, sort, (int)recordStates); return new Select(this, filterExpression, sort, recordStates).SelectRows(); }
public DataView (DataTable table, string RowFilter, string Sort, DataViewRowState RowState) : this (table, null, RowFilter, Sort, RowState) { }