using System;
using System.ComponentModel;
using System.Data;
using System.Globalization;
using System.Xml.Serialization;

namespace QC.QSPRTreeSchemaLibrary;

[Serializable]
[XmlType(AnonymousType = true)]
public class TestParameter
{
	private string name;

	private int numberOfElemets;

	private bool isDynamicArray;

	private string paramValue;

	private string unit;

	private string upperLimit;

	private string lowerLimit;

	private string dataType;

	private string type;

	private string parentName = "";

	private bool isNullable;

	private DataTable paramDataTable;

	private string enableDataLoggingAsString;

	private ConditionMgr loggingCondition;

	private string enableChartingAsString;

	private bool bUseRunTimeLimits;

	private string description;

	private string constraints;

	private int displayHint;

	private long paramRID;

	private string arrayParameterRIDsAsString;

	private string selected;

	private string globalVariableName;

	private string globalVariableForLL;

	private string globalVariableForUL;

	private string globalVariableNameOther;

	public string Name
	{
		get
		{
			return name;
		}
		set
		{
			name = value;
		}
	}

	public int NoOfElements
	{
		get
		{
			return numberOfElemets;
		}
		set
		{
			numberOfElemets = value;
		}
	}

	[DefaultValue(false)]
	public bool IsDynamicArray
	{
		get
		{
			return isDynamicArray;
		}
		set
		{
			isDynamicArray = value;
		}
	}

	public string Value
	{
		get
		{
			return paramValue;
		}
		set
		{
			paramValue = value;
		}
	}

	public string Unit
	{
		get
		{
			return unit;
		}
		set
		{
			unit = value;
		}
	}

	public string UpperLimit
	{
		get
		{
			return upperLimit;
		}
		set
		{
			upperLimit = value;
		}
	}

	public string LowerLimit
	{
		get
		{
			return lowerLimit;
		}
		set
		{
			lowerLimit = value;
		}
	}

	public string DataType
	{
		get
		{
			return dataType;
		}
		set
		{
			dataType = value;
		}
	}

	public string Type
	{
		get
		{
			return type;
		}
		set
		{
			type = value;
		}
	}

	[DefaultValue("")]
	public string ParentName
	{
		get
		{
			return parentName;
		}
		set
		{
			parentName = value;
		}
	}

	[DefaultValue(false)]
	public bool IsNullable
	{
		get
		{
			return isNullable;
		}
		set
		{
			isNullable = value;
		}
	}

	public DataTable DataTableValue
	{
		get
		{
			return paramDataTable;
		}
		set
		{
			paramDataTable = value;
		}
	}

	public string EnableDataLoggingAsString
	{
		get
		{
			return enableDataLoggingAsString;
		}
		set
		{
			enableDataLoggingAsString = value;
		}
	}

	public ConditionMgr DataLoggingCondition
	{
		get
		{
			return loggingCondition;
		}
		set
		{
			loggingCondition = value;
		}
	}

	public string EnableChartingAsString
	{
		get
		{
			return enableChartingAsString;
		}
		set
		{
			enableChartingAsString = value;
		}
	}

	[DefaultValue(false)]
	public bool UseRunTimeLimits
	{
		get
		{
			return bUseRunTimeLimits;
		}
		set
		{
			bUseRunTimeLimits = value;
		}
	}

	[DefaultValue("")]
	public string Description
	{
		get
		{
			return description;
		}
		set
		{
			description = value;
		}
	}

	[DefaultValue("")]
	public string Constraints
	{
		get
		{
			return constraints;
		}
		set
		{
			constraints = value;
		}
	}

	[DefaultValue(0)]
	public int DisplayHint
	{
		get
		{
			return displayHint;
		}
		set
		{
			displayHint = value;
		}
	}

	public long ParamRID
	{
		get
		{
			return (int)paramRID;
		}
		set
		{
			paramRID = value;
		}
	}

	public string ArrayParameterRIDsAsString
	{
		get
		{
			return arrayParameterRIDsAsString;
		}
		set
		{
			arrayParameterRIDsAsString = value;
		}
	}

	[DefaultValue("true")]
	public string Selected
	{
		get
		{
			return selected;
		}
		set
		{
			selected = value;
		}
	}

	[DefaultValue("")]
	public string GlobalVariableName
	{
		get
		{
			return globalVariableName;
		}
		set
		{
			globalVariableName = value;
		}
	}

	[DefaultValue("")]
	public string GlobalVariableForLL
	{
		get
		{
			return globalVariableForLL;
		}
		set
		{
			globalVariableForLL = value;
		}
	}

	[DefaultValue("")]
	public string GlobalVariableForUL
	{
		get
		{
			return globalVariableForUL;
		}
		set
		{
			globalVariableForUL = value;
		}
	}

	[DefaultValue("")]
	public string GlobalVariableNameOther
	{
		get
		{
			return globalVariableNameOther;
		}
		set
		{
			globalVariableNameOther = value;
		}
	}

	public bool ParameterValueInLimits
	{
		get
		{
			bool flag = true;
			try
			{
				if (UpperLimit.Trim() == "" && LowerLimit.Trim() == "")
				{
					return true;
				}
				if (DataType == "Boolean")
				{
					return true;
				}
				string[] array = LowerLimit.Split(',');
				string[] array2 = Value.Split(',');
				string[] array3 = UpperLimit.Split(',');
				if (DataType == "Int")
				{
					ConvertHexToInt(array);
					ConvertHexToInt(array3);
				}
				for (int i = 0; i < NoOfElements; i++)
				{
					try
					{
						string text = "";
						string text2 = "";
						string text3 = "";
						try
						{
							text = array[i];
						}
						catch
						{
						}
						try
						{
							text2 = array2[i];
						}
						catch
						{
						}
						try
						{
							text3 = array3[i];
						}
						catch
						{
						}
						flag = ((!(DataType == "String") && !(DataType == "Char")) ? CheckInLimits(text, text2, text3) : CheckInLimitsForString(text, text2, text3));
						if (!flag)
						{
							return false;
						}
					}
					catch
					{
					}
				}
			}
			catch
			{
			}
			return flag;
		}
	}

	private void ConvertHexToInt(string[] limits)
	{
		for (int i = 0; i < limits.Length; i++)
		{
			if (limits[i].ToUpper().StartsWith("0X"))
			{
				string text = limits[i].Remove(0, 2);
				if (text.Length > 0)
				{
					limits[i] = int.Parse(text, NumberStyles.HexNumber).ToString();
				}
				else
				{
					limits[i] = "0";
				}
			}
		}
	}

	private bool CheckInLimitsForString(string LL, string value, string UL)
	{
		if (LL != string.Empty && string.Compare(LL, value) > 0)
		{
			return false;
		}
		if (UL != string.Empty && string.Compare(UL, value) < 0)
		{
			return false;
		}
		return true;
	}

	private bool CheckInLimits(string strLL, string strValue, string strUL)
	{
		try
		{
			double result;
			bool flag = double.TryParse(strLL, out result);
			double.TryParse(strValue, out var result2);
			double result3;
			bool flag2 = double.TryParse(strUL, out result3);
			if (flag && flag2)
			{
				if (result <= result2 && result2 <= result3)
				{
					return true;
				}
				return false;
			}
			if (flag)
			{
				if (result <= result2)
				{
					return true;
				}
				return false;
			}
			if (flag2)
			{
				if (result2 <= result3)
				{
					return true;
				}
				return false;
			}
		}
		catch
		{
		}
		return true;
	}
}
