using Inet.Viewer.Resources;
/*
i-net software provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties
of merchantability and/or fitness for a particular purpose. This programming example
assumes that you are familiar with the programming language being demonstrated and
the tools used to create and debug procedures. i-net software support professionals
can help explain the functionality of a particular procedure, but they will not modify
these examples to provide added functionality or construct procedures to meet your
specific needs.
© i-net software 1998-2013
*/
using System;
namespace Inet.Viewer.Data
{
///
/// This class represents a range prompt value with one or two limits, each of which can be set to be included in the range or to be excluded from the range.
/// @author LarsF
///
public class RangePromptValue : PromptValue
{
private Range range;
///
/// Creates an "empty" range prompt value with the given type
/// type of range prompt value
internal RangePromptValue(int type)
: base(type)
{
range = new Range(null, null, false, false);
InitValue();
}
///
/// The constructor.
/// The start value of the range.
/// The end value of the range.
/// include the start value.
/// include the end Value.
/// value type of range.
internal RangePromptValue(SinglePromptValue startValue, SinglePromptValue endValue, bool includeLow, bool includeHigh, int type)
: base("", type)
{
range = new Range(startValue, endValue, includeLow, includeHigh);
}
///
/// Constructor using a Range object
/// Range object to use to create a RangePromptValue based on the given range
/// value type of the range
public RangePromptValue(Range range, int type)
: base("", type)
{
this.range = range;
}
/// Is the upper limit included in the range?
public bool IncludeHigh
{
get
{
return range.IncludeUpper;
}
set
{
range.IncludeUpper = value;
}
}
/// Is the lower limit included in the range?
public bool IncludeLow
{
get
{
return range.IncludeLower;
}
set
{
range.IncludeLower = value;
}
}
/// Upper limit to the range, or null if there is no upper limit
public virtual SinglePromptValue EndValue
{
get
{
return (SinglePromptValue)range.UpperValue;
}
set
{
range.UpperValue = value;
}
}
/// Lower limit to the range, or null if there is no lower limit
public virtual SinglePromptValue StartValue
{
get
{
return (SinglePromptValue)range.LowerValue;
}
set
{
range.LowerValue = value;
}
}
// --------------------------------
///
/// init the range values.
///
internal override void InitValue()
{
if (range != null)
{
range.LowerValue = new SinglePromptValue(this.Type);
range.UpperValue = new SinglePromptValue(this.Type);
}
}
///
///
///
public override object Value
{
get
{
return this;
}
}
///
///
///
internal override string ValueString
{
get
{
string resultString = range.LowerValue.ToString();
resultString += " ";
if (!IncludeLow)
{
resultString += "("+strings.Prompt_Excl+") ";
}
resultString += strings.Prompt_To;
resultString += " ";
resultString += range.UpperValue.ToString();
if (!IncludeHigh)
{
resultString += " (" + strings.Prompt_Excl + ")";
}
return resultString;
}
}
///
///
/// Returns the i-net Clear Reports formula syntax representation of this range.
///
public override string StringRepresentation
{
get
{
if (StartValue.Value == null && EndValue.Value == null)
{
return "null";
}
return StartValue.StringRepresentation + " " + (IncludeLow ? "" : "_") + "to" + (IncludeHigh ? "" : "_") + " " + EndValue.StringRepresentation;
}
}
///
///
///
public override bool Equals(object obj)
{
if (obj is RangePromptValue)
{
RangePromptValue value = (RangePromptValue)obj;
return value.IncludeHigh == IncludeHigh && value.IncludeLow == IncludeLow && value.EndValue.Equals(EndValue) && value.StartValue.Equals(StartValue) && value.Description.Equals(Description) && value.OnlyDescription == OnlyDescription;
}
else
{
return false;
}
}
///
///
///
public override int GetHashCode()
{
string idString = Description + OnlyDescription + StartValue + EndValue + IncludeLow + IncludeHigh;
return idString.GetHashCode();
}
///
///
///
///
public string CheckRange()
{
object l = range.LowerValue;
if (l is SinglePromptValue)
{
l = ((SinglePromptValue)l).Value;
}
object r = range.UpperValue;
if (r is SinglePromptValue)
{
r = ((SinglePromptValue)r).Value;
}
if (l != null && r != null)
{
switch (this.Type)
{
case PromptData.Boolean:
case PromptData.Binary:
return null;
case PromptData.Currency:
case PromptData.Number:
if (((double)l).CompareTo((double)r) <= 0)
{
return null;
}
break;
case PromptData.Date:
case PromptData.Datetime:
DateTime left = new DateTime();
if (l is DateTime)
{
left = (DateTime)l;
}
else
{
return "Invalid value: " + l;
}
if (left.CompareTo(r) <= 0)
{
return null;
}
break;
case PromptData.Time:
if (((TimeSpan)l).CompareTo((TimeSpan)r) <= 0)
{
return null;
}
break;
case PromptData.String:
if (((string)l).CompareTo((string)r) <= 0)
{
return null;
}
break;
}
}
else if (l == null && r == null)
{
return null;
}
return strings.Prompt_Error_InvalidRange;
}
}
}