Filters in document
foreach (FilterItem fld in _reportClientDocument.DataDefinition.RecordFilter.FilterItems)
{
Trace.Write("FilterItem name: "+ fld.ComputeText());
}
Looking at the huge number of links, my code snippets and samples that I've accumulated during my journey with Crystal Reports and Report Server (RAS), I've realized that something should be done with all that. So, for all who are struggling with similar problems I've faced while pursuing that elusive goal of putting Crystal Reports on the web, I will put as much information here as I can ...
foreach (FilterItem fld in _reportClientDocument.DataDefinition.RecordFilter.FilterItems)
{
Trace.Write("FilterItem name: "+ fld.ComputeText());
}
private Field ConvertFieldStringToFieldClass(string fieldString)
{
// get the period index
char period = '.';
int periodIndex = fieldString.IndexOf(period);
// parse out table and field name
string tableName = fieldString.Substring(1, periodIndex-1);
string fieldName = fieldString.Substring(periodIndex+1, fieldString.Length-(periodIndex+2));
Tables tables = _reportClientDocument.DatabaseController.Database.Tables;
int tableIndex = tables.FindByAlias(tableName);
CrystalDecisions.ReportAppServer.DataDefModel.Table table =
(CrystalDecisions.ReportAppServer.DataDefModel.Table)tables[tableIndex];
Fields fields = table.DataFields;
int fieldIndex = fields.Find(fieldName, CrFieldDisplayNameTypeEnum.crFieldDisplayNameName,
CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleEnglishUS);
Field field = (Field)fields[fieldIndex];
return field;
}
//'---------------------------------------------------------
//
// GetCurrentlyUsedDatabaseFields
//
// ICollection
// Get all used db fields from the report.
//
//'---------------------------------------------------------
private ICollection GetCurrentlyUsedDatabaseFields()
{
SortedList sortedlist = new SortedList();
string strShortFieldName;
Fields fields = _reportClientDocument.DataDefinition.ResultFields;
foreach(Field field in fields)
{
if(field.Kind == CrFieldKindEnum.crFieldKindDBField)
{
char period = '.';
int periodIndex = field.FormulaForm.IndexOf(period);
// parse out table and field name
strShortFieldName = field.FormulaForm.Substring(periodIndex+1, field.FormulaForm.Length-(periodIndex+2));
sortedlist.Add(field.FormulaForm, strShortFieldName);
}
}
return sortedlist;
}
public SortedList GetAvailableDatabaseFields()
{
string strShortFieldName;
SortedList sortedList = new SortedList();
Tables tables = _reportClientDocument.DatabaseController.Database.Tables;
foreach(CrystalDecisions.ReportAppServer.DataDefModel.Table table in tables)
{
foreach(Field field in table.DataFields)
{
char period = '.';
int periodIndex = field.FormulaForm.IndexOf(period);
// parse out table and field name
strShortFieldName = field.FormulaForm.Substring(periodIndex+1, field.FormulaForm.Length-(periodIndex+2));
sortedList.Add(field.FormulaForm, strShortFieldName);
}
}
return sortedList;
}
private void lstAvailableDatabaseFields_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
lstAvailableDatabaseFields.DataSource = GetAvailableDatabaseFields();
lstAvailableDatabaseFields.DataTextField = "value";
lstAvailableDatabaseFields.DataValueField ="key";
lstAvailableDatabaseFields.DataBind();
}
}