using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using FastReport.Utils;
namespace FastReport.Data
{
///
/// Represents the collection of objects.
///
public class ParameterCollection : FRCollectionBase
{
///
/// Gets or sets a parameter.
///
/// The index of a parameter in this collection.
/// The parameter with specified index.
public Parameter this[int index]
{
get { return List[index] as Parameter; }
set { List[index] = value; }
}
///
/// Finds a parameter by its name.
///
/// The name of a parameter.
/// The object if found; otherwise null.
public Parameter FindByName(string name)
{
foreach (Parameter c in this)
{
// check complete match or match without case sensitivity
if (c.Name == name || c.Name.ToLower() == name.ToLower())
return c;
}
return null;
}
///
/// Returns an unique parameter name based on given name.
///
/// The base name.
/// The unique name.
public string CreateUniqueName(string name)
{
string baseName = name;
int i = 1;
while (FindByName(name) != null)
{
name = baseName + i.ToString();
i++;
}
return name;
}
///
/// Copies the parameters from other collection.
///
/// Parameters to copy from.
public void Assign(ParameterCollection source)
{
Clear();
foreach (Parameter par in source)
{
Parameter thisParam = new Parameter(par.Name);
Add(thisParam);
thisParam.DataType = par.DataType;
thisParam.Value = par.Value;
thisParam.Expression = par.Expression;
thisParam.Description = par.Description;
thisParam.Parameters.Assign(par.Parameters);
}
}
private void EnumParameters(ParameterCollection root, SortedList list)
{
foreach (Parameter p in root)
{
if (!list.ContainsKey(p.FullName))
{
list.Add(p.FullName, p);
EnumParameters(p.Parameters, list);
}
}
}
internal void AssignValues(ParameterCollection source)
{
SortedList this_list = new SortedList();
EnumParameters(this, this_list);
SortedList source_list = new SortedList();
EnumParameters(source, source_list);
foreach (KeyValuePair kv in source_list)
{
if (this_list.ContainsKey(kv.Key))
this_list[kv.Key].Value = kv.Value.Value;
}
}
internal void MoveUp(Parameter par)
{
int order = IndexOf(par);
if (order > 0)
{
RemoveAt(order);
Insert(order - 1, par);
}
}
internal void MoveDown(Parameter par)
{
int order = IndexOf(par);
if (order != -1 && order < Count - 1)
{
RemoveAt(order);
Insert(order + 1, par);
}
}
///
/// Initializes a new instance of the class with default settings.
///
/// The owner of this collection.
public ParameterCollection(Base owner) : base(owner)
{
}
}
}