Page 1 of 1

How to do lookup?

Posted: Tue Jul 17, 2007 6:34 am
by Peter Illes
Hi,

I'd like to have a Text in the report to be filled out by the name of an "enum" if I know the ID (pseudo code: CURRENCY[VOUCHER.CURRENCY_ID].ABBREVIATION, where CURRENCY_ID is the primary key of CURRENCY).

How is this best done?

Thanks,
Peter

How to do lookup?

Posted: Tue Jul 17, 2007 8:51 am
by Peter Illes
What I figured out is this: {CURRENCY.DataTable.Rows.Find(VOUCHER.CURRENCY_ID)["ABBREVIATION"]}

Is there anything better?

How to do lookup?

Posted: Tue Jul 17, 2007 8:53 am
by Edward
Peter wrote:I'd like to have a Text in the report to be filled out by the name of an "enum" if I know the ID (pseudo code: CURRENCY[VOUCHER.CURRENCY_ID].ABBREVIATION, where CURRENCY_ID is the primary key of CURRENCY).
So we have two DataSources in report. Here they are:
CURRENCY with CURRENCY_ID filed as a primary key
and
VOUCHER with CURRENCY_ID field as a primary key

The simplest way to connect these two tables is to create a relation between them.
Parent: CURRENCY (as I understand it is a dictionary for currencies)
Child: VOUCHER (here you need to show the ABBREVIATION for each Currency)

When the DataSource is connected with a DataBand (in our case it is VOUCHER DataSource) then the scrolling is done from record to record automatically. But you also can find a record you need manually via
DataSource.Next() or
DataSource.Prior() methods.

The relation for VOUCHER will point to record you need from the Detail (Currency.ABBREVIATION) datasource automatically.

In report you refer such fields via relation directly:

{CURRENCY.VOUCHER_Relation_Name.ABBREVIATION}

Thank you.

How to do lookup?

Posted: Sat Jul 21, 2007 5:35 am
by Peter Illes
Edward,

Thanks for the reply. I ended up using the following function:

Code: Select all

		public System.String Lookup(string key, Stimulsoft.Report.Dictionary.StiDataTableSource ds, string valueCol)
		{
			try
			{
				return ds.DataTable.Rows.Find(key)[valueCol].ToString();
			}
			catch
			{
				return "";
			}
		}
This way the code is quite clean and self-explanatory. One may define additional overloaded versions, if their key is not string (e.g. decimal, etc.), or use .ToString() accordingly.

Cheers,
Peter

How to do lookup?

Posted: Mon Jul 23, 2007 3:48 am
by Edward
It is really smart solution for your task.

Thank you.