Custom Component

Stimulsoft Reports.NET discussion
Post Reply
Johnt000050
Posts: 3
Joined: Thu Aug 02, 2007 3:11 pm
Location: Philly

Custom Component

Post by Johnt000050 »

If I put a custom component in a databand, how and when (event?) do I get the data? For example, I have the following data

Code: Select all

Product     Price
=================
Product1       10
Product2       20 
I want to get the price in my custom component at render time (it that correct?). How do I do that?

Thanks.
Johnt000050
Posts: 3
Joined: Thu Aug 02, 2007 3:11 pm
Location: Philly

Custom Component

Post by Johnt000050 »

I would like to clarify my intend. Actually, I want not just the Price, but the whole record. I saw an example that comes with Stimul Soft Report that show a custom component with DataSource property. But, how do I get the current record from this DataSource?

Thanks.
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Custom Component

Post by Vital »

What you need for connecting datasource to customer component:

1. You need release interface IStiDataSource. For example:

Code: Select all

private bool IsDataSourceEmpty
		{
			get
			{
				return DataSourceName == null || DataSourceName.Length == 0 || DataSource == null;
			}
		}

		/// 
		/// Get data source that is used for getting data.
		/// 
		[Editor(typeof(StiDataSourceEditor), typeof(UITypeEditor))]
		[TypeConverter(typeof(StiDataSourceConverter))]
		[StiCategory("Data")]
		[StiOrder(StiPropertyOrder.DataDataSource)]
		[Description("Get data source that is used for getting data.")]
		public virtual StiDataSource DataSource
		{
			get
			{
				if (Page == null || 
					Report == null || 
					Report.DataSources == null || 
					DataSourceName == null ||
					DataSourceName.Length == 0)return null;
				return Report.DataSources[DataSourceName];
			}
		}


		private string dataSourceName = string.Empty;
		[Browsable(false)]
		[StiSerializable]
		[DefaultValue("")]
			/// 
			/// Gets or sets name of the Data Source.
			/// 
		public string DataSourceName
		{
			get
			{
				return dataSourceName;
			}
			set
			{
				dataSourceName = value;
			}
		}
2. You need release interface IStiEnumerator:

Code: Select all

private int countData = 0;
		/// 
		/// Gets or sets the count of rows for virtual data.
		/// 
		[StiSerializable]
		[DefaultValue(0)]
		[StiCategory("Data")]
		[StiOrder(StiPropertyOrder.DataCountData)]
		[Description("Gets or sets the count of rows for virtual data.")]
		public virtual int CountData
		{
			get
			{
				return countData;
			}
			set
			{
				countData = value;
			}
		}

		/// 
		/// Sets the position at the beginning.
		/// 
		public virtual void First()
		{
			if (!IsDataSourceEmpty)this.DataSource.First();
			else
			{
				this.isEofValue = false;
				this.isBofValue = true;
				this.positionValue = 0;
			}
		}


		/// 
		/// Move on the previous row.
		/// 
		public virtual void Prior()
		{
			if (!this.IsDataSourceEmpty)this.DataSource.Prior();
			else
			{
				this.isBofValue = false;
				this.isEofValue = false;
				if (this.positionValue 
		/// Move on the next row.
		/// 
		public virtual void Next()
		{
			if (!this.IsDataSourceEmpty)this.DataSource.Next();
			else
			{
				this.isBofValue = false;
				this.isEofValue = false;
				if (this.positionValue >= this.countData - 1)this.isEofValue = true;
				else this.positionValue++;
			}
		}


		/// 
		/// Move on the last row.
		/// 
		public virtual void Last()
		{
			if (!this.IsDataSourceEmpty)this.DataSource.Last();
			else
			{
				this.isEofValue = true;
				this.isBofValue = false;
				this.positionValue = this.countData - 1;
			}
		}


		internal bool isEofValue = false;
		/// 
		/// Gets value indicates that the position indicates to the end of data.
		/// 
		[Browsable(false)]
		public virtual bool IsEof
		{
			get
			{
				if (!this.IsDataSourceEmpty)return DataSource.IsEof;
				else return isEofValue;
			}
			set
			{
				if (!this.IsDataSourceEmpty)DataSource.IsEof = value;
				else isEofValue = value;
			}
		}


		internal bool isBofValue = false;
		/// 
		/// Gets value, indicates that the position indicates to the beginning of data.
		/// 
		[Browsable(false)]
		public virtual bool IsBof
		{
			get
			{
				if (!this.IsDataSourceEmpty)return DataSource.IsBof;
				else return isBofValue;
			}
			set
			{
				if (!this.IsDataSourceEmpty)DataSource.IsBof = value;
				else isBofValue = value;
			}
		}


		/// 
		/// Gets value indicates that no data.
		/// 
		[Browsable(false)]
		public virtual bool IsEmpty
		{
			get
			{
				if (!this.IsDataSourceEmpty)return DataSource.IsEmpty;
				else return CountData == 0;
			}
		}


		internal int positionValue;
		/// 
		/// Gets the current position.
		/// 
		[Browsable(false)]
		public virtual int Position
		{
			get
			{
				if (!this.IsDataSourceEmpty)return DataSource.Position;
				return positionValue;
			}
			set
			{
				if (!this.IsDataSourceEmpty)DataSource.Position = value;
				else positionValue = value;
			}
		}


		/// 
		/// Gets count of rows.
		/// 
		[Browsable(false)]
		public virtual int Count
		{
			get
			{
				if (!this.IsDataSourceEmpty)return DataSource.Count;
				return countData;
			}
		}
3. In method RenderComponent you need call method StiDataHelper.SetData:

Code: Select all

StiDataHelper.SetData(this, true, Parent as StiDataBand);
After then you can enumerate data in method RenderComponent:

Code: Select all

this.First();

for (int posIndex = 0; posIndex 
		/// Gets or sets the array of strings that describes rules of sorting.
		/// 
		[StiSerializable(StiSerializationVisibility.List)]
		[Editor(typeof(StiSortEditor), typeof(UITypeEditor))]
		[TypeConverter(typeof(StiSortConverter))]
		[DefaultValue(null)]
		[StiCategory("Data")]
		[StiOrder(StiPropertyOrder.DataSort)]
		[Description("Gets or sets the array of strings that describes rules of sorting.")]
		public virtual string[] Sort
		{
			get
			{
				return sort;
			}
			set
			{
				sort = value;
			}
		}
2. Filtering:

You need release interface IStiFilter:

Code: Select all

private StiFilterEventHandler filterMethodHandler;
		/// 
		/// Gets or sets a method for filtration.
		/// 
		[Browsable(false)]
		public StiFilterEventHandler FilterMethodHandler
		{
			get
			{
				return filterMethodHandler;
			}
			set
			{
				filterMethodHandler = value;
			}
		}


		private StiFilterMode filterMode = StiFilterMode.And;
		/// 
		/// Gets or sets filter mode.
		/// 
		[DefaultValue(StiFilterMode.And)]
		[StiSerializable]
		[TypeConverter(typeof(StiEnumConverter))]
		[StiCategory("Data")]
		[StiOrder(StiPropertyOrder.DataFilterMode)]
		[Browsable(false)]
		public StiFilterMode FilterMode
		{
			get
			{
				return filterMode;
			}
			set
			{
				filterMode = value;
			}
		}


		private StiFiltersCollection filters = new StiFiltersCollection();
		/// 
		/// Gets or sets the collection of data filters.
		/// 
		[StiSerializable(StiSerializationVisibility.List)]
		[StiCategory("Data")]
		[StiOrder(StiPropertyOrder.DataFilters)]
		[Editor(typeof(StiFiltersCollectionEditor), typeof(UITypeEditor))]
		[TypeConverter(typeof(StiFiltersCollectionConverter))]
		public StiFiltersCollection Filters
		{
			get
			{
				return filters;
			}
			set
			{
				filters = value;
			}
		}


		/// 
		/// Do not use this property.
		/// 
		[Browsable(false)]
		[StiNonSerialized]
		[Obsolete("Filter property is obsolete. Please use Filters property.")]
		public virtual StiExpression Filter
		{
			get
			{
				if (Filters.Count == 0)Filters.Add(new StiFilter());
				Filters[0].Item = StiFilterItem.Expression;
				return Filters[0].Expression;
			}
			set
			{
				if (Filters.Count == 0)Filters.Add(new StiFilter());
				Filters[0].Item = StiFilterItem.Expression;
				Filters[0].Expression = value;
			}
		}


		private bool filterOn = true;
		/// 
		/// Gets or sets value indicates, that filter is turn on.
		/// 
		[TypeConverter(typeof(StiBoolConverter))]
		[StiCategory("Data")]
		[StiOrder(StiPropertyOrder.DataFilterOn)]
		[StiSerializable]
		[DefaultValue(true)]
		[Description("Gets or sets value indicates, that filter is turn on.")]
		public virtual bool FilterOn
		{
			get
			{
				return filterOn;
			}
			set
			{
				filterOn = value;
			}
		}
Please contact us if you have any questions.

Thank you.
Post Reply