Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / System / data / design / DesignColumnCollection.cs / 1 / DesignColumnCollection.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All Rights Reserved. // Information Contained Herein is Proprietary and Confidential. // //----------------------------------------------------------------------------- namespace System.Data.Design { using System; using System.Data; using System.Collections; using System.Diagnostics; using System.Globalization; using System.ComponentModel; ////// internal class DesignColumnCollection : DataSourceCollectionBase { private DesignTable table; private DesignTable designTable; protected override Type ItemType { get { return typeof(DesignColumn); } } public DesignColumnCollection(DesignTable designTable) : base(designTable) { this.designTable = designTable; if (designTable != null) { Debug.Assert(designTable.DataTable != null, "How can the designTable does not have a data table?"); if (designTable.DataTable != null) { foreach (DataColumn dataColumn in designTable.DataTable.Columns) { this.Add(new DesignColumn(dataColumn)); } } } table = designTable; } protected override INameService NameService { get { return DataSetNameService.DefaultInstance; } } public void Add(DesignColumn designColumn) { if (designColumn.DesignTable != null && designColumn.DesignTable != designTable) { throw new InternalException("Cannot insert a DesignColumn object in two collections."); } designColumn.DesignTable = designTable; List.Add(designColumn); if (designColumn.DataColumn != null && this.designTable != null) { if (this.designTable.DataTable != null && !this.designTable.DataTable.Columns.Contains(designColumn.Name)) { this.designTable.DataTable.Columns.Add(designColumn.DataColumn); } } } public void Remove(DesignColumn column) { List.Remove(column); } public int IndexOf(DesignColumn column) { return List.IndexOf(column); } public DesignColumn this[string columnName] { get { return (DesignColumn)FindObject(columnName); } } ////// Note: this function need to call base first /// to ensure the undo model work! /// protected override void OnInsert(int index, object value) { base.OnInsert(index, value); ValidateType(value); DesignColumn newColumn = (DesignColumn)value; if ((newColumn.DataColumn != null) && (this.table != null)) { Debug.Assert(this.table.DataTable != null); if (!this.table.DataTable.Columns.Contains(newColumn.DataColumn.ColumnName)) { this.table.DataTable.Columns.Add(newColumn.DataColumn); } } newColumn.DesignTable = designTable; } ////// Note: this function need to call base first /// to ensure the undo model work! /// protected override void OnSet(int index, object oldValue, object newValue) { base.OnSet(index, oldValue, newValue); ValidateType(newValue); ValidateType(oldValue); DesignColumn oldColumn = (DesignColumn)oldValue; DesignColumn newColumn = (DesignColumn)newValue; if (this.table != null && oldValue != newValue) { Debug.Assert(this.table.DataTable != null); if (oldColumn.DataColumn != null) { this.table.DataTable.Columns.Remove(oldColumn.DataColumn); oldColumn.DesignTable = null; } if (newColumn.DataColumn != null && !this.table.DataTable.Columns.Contains(newColumn.DataColumn.ColumnName)) { this.table.DataTable.Columns.Add(newColumn.DataColumn); newColumn.DesignTable = designTable; } } } ////// Note: this function need to call base first /// to ensure the undo model work! /// protected override void OnRemove(int index, object value) { // Remove the constraint first. // As we have wrap everything in transaction and the action is // undoable, we now like to add this feature: // Remove the constraints before remove the column // base.OnRemove(index, value); ValidateType(value); DesignColumn column = (DesignColumn)value; if ((this.table != null) && (column.DataColumn != null)) { Debug.Assert(this.table.DataTable != null); this.table.DataTable.Columns.Remove(column.DataColumn); } column.DesignTable = null; } #if not ////// Helper function used to remove constraints first when removing a column /// /// private void RemoveConstraints(DesignColumn designColumn) { DesignTable designTable = designColumn.DesignTable; if (designTable == null) { return; } // Remove uniqueConstraint first ArrayList constraints = designTable.GetRelatedDataConstraints(new DesignColumn[]{designColumn}, false); foreach (Constraint constraint in constraints) { if (constraint is UniqueConstraint) { if (((UniqueConstraint)constraint).IsPrimaryKey) { // Well, we are going to remove the primary key // Call Table.PrimaryKeyColumns = null to let it recored in undo // designTable.PrimaryKeyColumns = null; } else { designTable.RemoveKey(constraint as UniqueConstraint); } } } constraints = designTable.GetRelatedDataConstraints(new DesignColumn[] { designColumn }, false); foreach (Constraint constraint in constraints) { designTable.RemoveConstraint(constraint); } } #endif public DesignColumn this[int index] { get { int count = 0; foreach (DesignColumn designColumn in InnerList) { if (index == count) { return designColumn; } count++; } throw new InternalException(VSDExceptions.DataSource.INVALID_COLUMN_INDEX_MSG, VSDExceptions.DataSource.INVALID_COLUMN_INDEX_CODE); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataBoundControlHelper.cs
- ClrPerspective.cs
- TemplatePagerField.cs
- ModifyActivitiesPropertyDescriptor.cs
- ManagementObject.cs
- ArgIterator.cs
- WebHttpEndpointElement.cs
- BasicCommandTreeVisitor.cs
- DataReaderContainer.cs
- Activity.cs
- PointUtil.cs
- ChannelTracker.cs
- HierarchicalDataBoundControlAdapter.cs
- PassportAuthentication.cs
- SocketAddress.cs
- AddInBase.cs
- StackSpiller.Temps.cs
- DataGridColumnHeaderCollection.cs
- TrackingCondition.cs
- SatelliteContractVersionAttribute.cs
- BinaryReader.cs
- KnownBoxes.cs
- IISMapPath.cs
- IdentitySection.cs
- RenderDataDrawingContext.cs
- WSDualHttpBindingCollectionElement.cs
- HostExecutionContextManager.cs
- SubstitutionList.cs
- ContractsBCL.cs
- XmlSiteMapProvider.cs
- MetadataUtilsSmi.cs
- ScalarConstant.cs
- InputMethodStateChangeEventArgs.cs
- HttpWebResponse.cs
- JulianCalendar.cs
- KeyboardNavigation.cs
- DataGridViewColumnStateChangedEventArgs.cs
- SqlDataSource.cs
- CodeRegionDirective.cs
- SingleAnimation.cs
- DataServiceHostFactory.cs
- DbMetaDataFactory.cs
- XamlTreeBuilderBamlRecordWriter.cs
- MultiAsyncResult.cs
- MoveSizeWinEventHandler.cs
- DbModificationClause.cs
- DataRecordInternal.cs
- DriveInfo.cs
- ConstructorBuilder.cs
- XmlMemberMapping.cs
- MediaCommands.cs
- SupportsPreviewControlAttribute.cs
- DataGridViewHeaderCell.cs
- DesignTimeXamlWriter.cs
- FrameworkContextData.cs
- DataGridViewComboBoxCell.cs
- ZipIOModeEnforcingStream.cs
- GridViewAutoFormat.cs
- RegisteredArrayDeclaration.cs
- RequestCacheManager.cs
- ScriptingScriptResourceHandlerSection.cs
- ClaimTypes.cs
- LogEntrySerializationException.cs
- SqlBinder.cs
- FontUnit.cs
- ReferencedAssemblyResolver.cs
- HitTestWithPointDrawingContextWalker.cs
- SystemWebCachingSectionGroup.cs
- IntPtr.cs
- ActivitiesCollection.cs
- SqlClientFactory.cs
- XmlAttribute.cs
- FtpRequestCacheValidator.cs
- AsymmetricKeyExchangeDeformatter.cs
- WorkItem.cs
- FrameAutomationPeer.cs
- EntityContainerEntitySet.cs
- COSERVERINFO.cs
- EventSinkHelperWriter.cs
- ParameterReplacerVisitor.cs
- _LocalDataStoreMgr.cs
- LinkedList.cs
- DataSourceCache.cs
- SharedPerformanceCounter.cs
- ExpandedWrapper.cs
- SessionStateItemCollection.cs
- BordersPage.cs
- ToolstripProfessionalRenderer.cs
- RelationshipFixer.cs
- ContextMenuStripGroupCollection.cs
- CornerRadiusConverter.cs
- ReplyAdapterChannelListener.cs
- SemanticKeyElement.cs
- PanelStyle.cs
- CertificateManager.cs
- ModelVisual3D.cs
- TrackPoint.cs
- DateTimeConverter2.cs
- VectorValueSerializer.cs
- SingleObjectCollection.cs