using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Globalization;
using System.Runtime.Serialization;
using System.Windows.Forms;
using System.Xml.Serialization;
using QC.QsprShared.Trace;
using QC.QsprTestObjects.TestConditions;
using QC.QTMInterface;

namespace QC.QsprTestObjects.Parameters;

[Serializable]
public class ParameterCls : ISerializable
{
	private enum SearchState
	{
		state1,
		state2,
		state3,
		state4,
		state5,
		state6,
		state7,
		state8
	}

	public const string DEFAULT_OUTPUT_VALUE = "-99999";

	public const string DEFAULT_UPPER_LIMIT = "99999";

	public const string DEFAULT_LOWER_LIMIT = "-99999";

	public const string STRING_ARRAY_SEPARATOR = "_\"_";

	private string parentName = "";

	private bool isNullable;

	private string paramName;

	private string realName;

	private string paramValue;

	private string originalValue = "-99999";

	private DataType paramType;

	private IOType paramIOType;

	private string paramUL = "";

	private string paramLL = "";

	private int iNoOfElts;

	private bool isDynamicArray;

	private string paramUOM = "";

	private ArrayList enableDataLogging = new ArrayList();

	private ConditionMgr loggingCondition;

	private ArrayList enableCharting = new ArrayList();

	private string paramDesc = "";

	private string paramConstraint = "";

	private int paramDispHint;

	private bool bUseRunTimeLimits;

	private long paramRID = -1L;

	private ArrayList arrayParameterRIDs = new ArrayList();

	private bool selected = true;

	private string globalVariableName = "";

	private string globalVariableNameOther = "";

	private string globalVariableForLL = "";

	private string globalVariableForUL = "";

	private DataTable paramDataTable;

	private bool isEditableInTestPlan;

	[NonSerialized]
	[XmlIgnore]
	public bool SavingTree;

	[NonSerialized]
	public ParameterCls[] children;

	[NonSerialized]
	private ParameterCollection _childrenCollection;

	private bool bCharting;

	private bool bDataLogging;

	[ReadOnly(true)]
	public string Name
	{
		get
		{
			return paramName;
		}
		set
		{
			paramName = value;
		}
	}

	public string RealName
	{
		get
		{
			return realName;
		}
		set
		{
			realName = value;
		}
	}

	[Browsable(false)]
	[ReadOnly(true)]
	public int NoOfElements
	{
		get
		{
			return iNoOfElts;
		}
		set
		{
			if (value < 1)
			{
				IsDynamicArray = true;
			}
			iNoOfElts = value;
		}
	}

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

	[Browsable(false)]
	[DefaultValue(false)]
	[ReadOnly(true)]
	public bool IsEditableInTestPlan
	{
		get
		{
			return isEditableInTestPlan;
		}
		set
		{
			isEditableInTestPlan = value;
		}
	}

	[DefaultValue(false)]
	[Browsable(false)]
	[ReadOnly(true)]
	public bool CanEditResultValue { get; set; }

	public string Value
	{
		get
		{
			if (SavingTree && paramIOType == IOType.Output)
			{
				string text = "-99999";
				if (IsNullable)
				{
					text = "";
				}
				for (int i = 0; i < NoOfElements; i++)
				{
					if (i > 0)
					{
						text = ((!IsNullable) ? (text + ",-99999") : (text + ","));
					}
				}
				return text;
			}
			return paramValue;
		}
		set
		{
			paramValue = value;
		}
	}

	[Category("Settings")]
	[Browsable(false)]
	[XmlIgnore]
	public string OriginalValue
	{
		get
		{
			return originalValue;
		}
		set
		{
			originalValue = value;
		}
	}

	[ReadOnly(true)]
	[DefaultValue("")]
	public string Unit
	{
		get
		{
			return paramUOM;
		}
		set
		{
			paramUOM = value;
		}
	}

	[DefaultValue("")]
	[Browsable(false)]
	public string UpperLimit
	{
		get
		{
			return paramUL;
		}
		set
		{
			paramUL = value;
		}
	}

	[Category("Children")]
	[XmlIgnore]
	public ParameterCollection Children
	{
		get
		{
			if (_childrenCollection == null || _childrenCollection.Count != children.Length)
			{
				_childrenCollection = new ParameterCollection();
				_childrenCollection.AddRange(children);
			}
			return _childrenCollection;
		}
	}

	[Browsable(false)]
	[DefaultValue("")]
	public string LowerLimit
	{
		get
		{
			return paramLL;
		}
		set
		{
			paramLL = value;
		}
	}

	[ReadOnly(true)]
	[Browsable(false)]
	public DataType DataType
	{
		get
		{
			return paramType;
		}
		set
		{
			paramType = value;
		}
	}

	[Browsable(false)]
	[XmlIgnore]
	[ReadOnly(true)]
	public string DataTypeAsString => paramType switch
	{
		DataType.Int => "int", 
		DataType.Hex => "hex", 
		DataType.Single => "Single", 
		DataType.Decimal => "Decimal", 
		DataType.Double => "double", 
		DataType.Boolean => "Boolean", 
		DataType.Byte => "Byte", 
		DataType.UInt32 => "UInt32", 
		DataType.UInt16 => "UInt16", 
		DataType.UInt64 => "UInt64", 
		DataType.Int16 => "Int16", 
		DataType.Int64 => "Int64", 
		DataType.Char => "Char", 
		DataType.SByte => "SByte", 
		DataType.DataTable => "DataTable", 
		DataType.String => "String", 
		_ => "string", 
	};

	[ReadOnly(true)]
	[Browsable(false)]
	public IOType Type
	{
		get
		{
			return paramIOType;
		}
		set
		{
			paramIOType = value;
		}
	}

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

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

	[Browsable(false)]
	public DataTable DataTableValue
	{
		get
		{
			return paramDataTable;
		}
		set
		{
			paramDataTable = value;
		}
	}

	[ReadOnly(true)]
	[Browsable(false)]
	[XmlIgnore]
	public string IOTypeAsString
	{
		get
		{
			IOType iOType = paramIOType;
			if (iOType == IOType.Output)
			{
				return "Output";
			}
			return "Input";
		}
	}

	[XmlIgnore]
	[Browsable(false)]
	public CheckState chkEnableDataLogging
	{
		get
		{
			int num = 0;
			foreach (bool item in enableDataLogging)
			{
				if (item)
				{
					num++;
				}
			}
			if (num == 0)
			{
				return CheckState.Unchecked;
			}
			if (num == NoOfElements)
			{
				return CheckState.Checked;
			}
			return CheckState.Indeterminate;
		}
	}

	[Browsable(false)]
	[XmlIgnore]
	public CheckState chkEnableCharting
	{
		get
		{
			int num = 0;
			foreach (bool item in enableCharting)
			{
				if (item)
				{
					num++;
				}
			}
			if (num == 0)
			{
				return CheckState.Unchecked;
			}
			if (num == NoOfElements)
			{
				return CheckState.Checked;
			}
			return CheckState.Indeterminate;
		}
	}

	[XmlIgnore]
	[Browsable(false)]
	public ArrayList EnableDataLogging
	{
		get
		{
			return enableDataLogging;
		}
		set
		{
			if (value.Count == NoOfElements)
			{
				enableDataLogging = value;
				return;
			}
			CheckState checkState = GetCheckState(value);
			if (checkState != CheckState.Indeterminate)
			{
				for (int i = 0; i < NoOfElements; i++)
				{
					enableDataLogging[i] = checkState == CheckState.Checked;
				}
				return;
			}
			int num = NoOfElements;
			if (value.Count < NoOfElements)
			{
				num = value.Count;
			}
			for (int j = 0; j < num; j++)
			{
				enableDataLogging[j] = value[j];
			}
		}
	}

	[Browsable(false)]
	public string EnableDataLoggingAsString
	{
		get
		{
			string text = "";
			if (enableDataLogging.Count > 0)
			{
				for (int i = 0; i < enableDataLogging.Count - 1; i++)
				{
					text = text + (((bool)enableDataLogging[i]) ? "T" : "F") + ",";
				}
				text += (((bool)enableDataLogging[enableDataLogging.Count - 1]) ? "T" : "F");
			}
			return text;
		}
		set
		{
			try
			{
				string[] array = value.Split(',');
				enableDataLogging.Clear();
				if (array.Length == NoOfElements)
				{
					string[] array2 = array;
					foreach (string text in array2)
					{
						if (text.Trim() != "")
						{
							string text2 = text;
							if (text2 == "T")
							{
								text2 = "True";
							}
							else if (text2 == "F")
							{
								text2 = "False";
							}
							enableDataLogging.Add(bool.Parse(text2));
						}
						else
						{
							enableDataLogging.Add(false);
						}
					}
				}
				else
				{
					for (int j = 0; j < NoOfElements; j++)
					{
						enableDataLogging.Add(false);
					}
				}
			}
			catch (Exception ex)
			{
				TraceMessage.Write(ToString(), "EnableDataLoggingAsString " + ex.Message, TraceMessageType.Exception);
			}
		}
	}

	[Browsable(false)]
	public ConditionMgr DataLoggingCondition
	{
		get
		{
			return loggingCondition;
		}
		set
		{
			loggingCondition = value;
		}
	}

	[XmlIgnore]
	[Browsable(false)]
	public ArrayList EnableCharting
	{
		get
		{
			return enableCharting;
		}
		set
		{
			if (value.Count == NoOfElements)
			{
				enableCharting = value;
				return;
			}
			CheckState checkState = GetCheckState(value);
			if (checkState != CheckState.Indeterminate)
			{
				for (int i = 0; i < NoOfElements; i++)
				{
					enableCharting[i] = checkState == CheckState.Checked;
				}
				return;
			}
			int num = NoOfElements;
			if (value.Count < NoOfElements)
			{
				num = value.Count;
			}
			for (int j = 0; j < num; j++)
			{
				enableCharting[j] = value[j];
			}
		}
	}

	[Browsable(false)]
	public string EnableChartingAsString
	{
		get
		{
			string text = "";
			if (enableCharting.Count > 0)
			{
				for (int i = 0; i < enableCharting.Count - 1; i++)
				{
					text = text + (((bool)enableCharting[i]) ? "T" : "F") + ",";
				}
				text += (((bool)enableCharting[enableCharting.Count - 1]) ? "T" : "F");
			}
			return text;
		}
		set
		{
			try
			{
				string[] array = value.Split(',');
				enableCharting.Clear();
				if (array.Length == NoOfElements)
				{
					string[] array2 = array;
					foreach (string text in array2)
					{
						if (text.Trim() != "")
						{
							string text2 = text;
							if (text2 == "T")
							{
								text2 = "True";
							}
							else if (text2 == "F")
							{
								text2 = "False";
							}
							enableCharting.Add(bool.Parse(text2));
						}
						else
						{
							enableCharting.Add(false);
						}
					}
				}
				else
				{
					for (int j = 0; j < NoOfElements; j++)
					{
						enableCharting.Add(false);
					}
				}
			}
			catch (Exception ex)
			{
				TraceMessage.Write(ToString(), "EnableChartingAsString " + ex.Message, TraceMessageType.Exception);
			}
		}
	}

	[XmlIgnore]
	[Browsable(false)]
	public bool bEnableCharting
	{
		get
		{
			return bCharting;
		}
		set
		{
			enableCharting.Clear();
			if (NoOfElements < 1)
			{
				enableCharting.Add(value);
			}
			else
			{
				for (int i = 0; i < NoOfElements; i++)
				{
					enableCharting.Add(value);
				}
			}
			bCharting = value;
		}
	}

	[XmlIgnore]
	[Browsable(false)]
	public bool bEnableDataLogging
	{
		get
		{
			return bDataLogging;
		}
		set
		{
			enableDataLogging.Clear();
			if (NoOfElements < 1)
			{
				enableDataLogging.Add(value);
			}
			else
			{
				for (int i = 0; i < NoOfElements; i++)
				{
					enableDataLogging.Add(value);
				}
			}
			bDataLogging = false;
		}
	}

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

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

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

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

	[Browsable(false)]
	[DefaultValue(-1)]
	public long ParamRID
	{
		get
		{
			return (int)paramRID;
		}
		set
		{
			paramRID = value;
		}
	}

	[Browsable(false)]
	[XmlIgnore]
	public ArrayList ArrayParameterRIDs
	{
		get
		{
			return arrayParameterRIDs;
		}
		set
		{
			arrayParameterRIDs = value;
		}
	}

	[Browsable(false)]
	[DefaultValue("-1")]
	public string ArrayParameterRIDsAsString
	{
		get
		{
			string text = "";
			if (arrayParameterRIDs.Count > 0)
			{
				for (int i = 0; i < arrayParameterRIDs.Count - 1; i++)
				{
					text = string.Concat(text, arrayParameterRIDs[i], ",");
				}
				text += arrayParameterRIDs[arrayParameterRIDs.Count - 1];
			}
			return text;
		}
		set
		{
			try
			{
				string[] array = value.Split(',');
				arrayParameterRIDs.Clear();
				if (array.Length == NoOfElements)
				{
					string[] array2 = array;
					foreach (string text in array2)
					{
						if (text.Trim() != "")
						{
							arrayParameterRIDs.Add(int.Parse(text));
						}
						else
						{
							arrayParameterRIDs.Add(-1);
						}
					}
				}
				else
				{
					for (int j = 0; j < NoOfElements; j++)
					{
						arrayParameterRIDs.Add(-1);
					}
				}
			}
			catch (Exception ex)
			{
				TraceMessage.Write(ToString(), "EnableChartingAsString " + ex.Message, TraceMessageType.Exception);
			}
		}
	}

	[Browsable(false)]
	[DefaultValue(true)]
	public bool Selected
	{
		get
		{
			return selected;
		}
		set
		{
			selected = value;
		}
	}

	[XmlIgnore]
	[Browsable(false)]
	public bool IsInput
	{
		get
		{
			if (Type == IOType.Input)
			{
				return true;
			}
			return false;
		}
	}

	[XmlIgnore]
	[Browsable(false)]
	public bool IsOutput
	{
		get
		{
			IOType type = Type;
			if (type == IOType.Output)
			{
				return true;
			}
			return false;
		}
	}

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

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

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

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

	[Browsable(false)]
	public bool ParameterValueInLimits
	{
		get
		{
			bool flag = true;
			try
			{
				if (UpperLimit.Trim() == "" && LowerLimit.Trim() == "")
				{
					return true;
				}
				string[] array = LowerLimit.Split(',');
				string[] array2 = Value.Split(',');
				string[] array3 = UpperLimit.Split(',');
				if (DataType == 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 == DataType.String || DataType == DataType.Char) ? CheckInLimitsForString(text, text2, text3) : ((DataType != DataType.Boolean) ? CheckInLimits(text, text2, text3) : CheckInLimitsForBool(text, text2, text3)));
						if (!flag)
						{
							return false;
						}
					}
					catch
					{
					}
				}
			}
			catch
			{
			}
			return flag;
		}
	}

	public ParameterCls(string str, DataType typ, int iElts, string val, IOType Type, string UL, string LL, string Unit, string Desc, string Constraint, int Hint, bool bUseRuntimeLimits)
		: this(str, typ, iElts, val, Type, UL, LL, Unit, Desc, Constraint, Hint, bUseRuntimeLimits, NULLABLE: false, "", isDynamicArray: false)
	{
	}

	public ParameterCls(string str, DataType typ, int iElts, string val, IOType Type, string UL, string LL, string Unit, string Desc, string Constraint, int Hint, bool bUseRuntimeLimits, bool NULLABLE, string parentName, bool isDynamicArray, string realNameVal = "")
	{
		realName = realNameVal;
		paramName = str;
		paramValue = val;
		paramType = typ;
		if (paramType == DataType.Decimal || paramType == DataType.Double)
		{
			paramUL = RemoveTrailingZeroes(UL);
			paramLL = RemoveTrailingZeroes(LL);
		}
		else
		{
			paramUL = UL;
			paramLL = LL;
		}
		IsDynamicArray = isDynamicArray;
		if (iElts < 1)
		{
			iElts = 1;
		}
		NoOfElements = iElts;
		paramUOM = Unit;
		paramIOType = Type;
		paramDesc = Desc;
		paramConstraint = Constraint;
		paramDispHint = Hint;
		bUseRunTimeLimits = bUseRuntimeLimits;
		IsNullable = NULLABLE;
		ParentName = parentName;
		if (IsOutput)
		{
			for (int i = 0; i < iElts; i++)
			{
				enableDataLogging.Add(true);
			}
		}
		else
		{
			for (int j = 0; j < iElts; j++)
			{
				enableDataLogging.Add(false);
			}
		}
		for (int k = 0; k < iElts; k++)
		{
			enableCharting.Add(false);
			arrayParameterRIDs.Add(-1);
		}
	}

	public ParameterCls()
	{
	}

	public static bool GetIsArray(ParameterCls param, bool isDotNet, string realName, string containerName)
	{
		bool flag = !param.IsParamDataTable() && param.NoOfElements > 1;
		if (!flag && isDotNet)
		{
			flag = param.IsDynamicArray;
		}
		return flag;
	}

	public static string[] SplitStringArrayParameter(string paramString)
	{
		ArrayList arrayList = new ArrayList();
		if (paramString != null && paramString.Length > 0)
		{
			bool flag = false;
			bool flag2 = true;
			string text = paramString;
			SearchState searchState = SearchState.state1;
			int num = 0;
			while (!flag)
			{
				if (num >= text.Length - 1)
				{
					searchState = SearchState.state8;
					flag = true;
				}
				switch (searchState)
				{
				case SearchState.state1:
					if (text[num] == '_')
					{
						searchState = SearchState.state2;
					}
					else if (text[num] == ',')
					{
						searchState = SearchState.state8;
					}
					break;
				case SearchState.state2:
					searchState = ((text[num] != '"') ? ((text[num] == ',') ? SearchState.state8 : SearchState.state1) : SearchState.state3);
					break;
				case SearchState.state3:
					if (text[num] == '_')
					{
						searchState = SearchState.state4;
						flag2 = false;
					}
					else
					{
						searchState = ((text[num] == ',') ? SearchState.state8 : SearchState.state1);
					}
					break;
				case SearchState.state4:
					if (text[num] == '_')
					{
						searchState = SearchState.state5;
					}
					break;
				case SearchState.state5:
					searchState = ((text[num] != '"') ? SearchState.state4 : SearchState.state6);
					break;
				case SearchState.state6:
					if (text[num] == '_')
					{
						searchState = SearchState.state7;
						flag2 = true;
					}
					else
					{
						searchState = SearchState.state4;
					}
					break;
				case SearchState.state7:
					if (text[num] == ',')
					{
						searchState = SearchState.state8;
					}
					break;
				case SearchState.state8:
					if (num < text.Length)
					{
						if (num == text.Length - 1)
						{
							flag = true;
						}
						if (num != 0 && text[num - 1] == ',')
						{
							string value = text.Substring(0, num).Trim(',').Replace("_\"_", "");
							arrayList.Add(value);
							text = text.Substring(num);
							num = -1;
							searchState = SearchState.state1;
						}
					}
					else
					{
						flag = true;
					}
					if (flag)
					{
						if (text.Length == 0)
						{
							arrayList.Add("");
						}
						else if (text.EndsWith(",") && flag2)
						{
							arrayList.Add(text.Trim(',').Replace("_\"_", ""));
							arrayList.Add("");
						}
						else
						{
							arrayList.Add(text.Replace("_\"_", ""));
						}
					}
					break;
				}
				num++;
			}
		}
		if (arrayList.Count == 0)
		{
			arrayList.Add("");
		}
		string[] array = new string[arrayList.Count];
		for (int i = 0; i < arrayList.Count; i++)
		{
			array[i] = arrayList[i].ToString();
		}
		return array;
	}

	public static string ConvertStrArrayToParamString(string[] strArray)
	{
		string text = "";
		for (int i = 0; i < strArray.Length; i++)
		{
			string text2 = strArray[i];
			text = ((!text2.Contains(",")) ? (text + text2) : (text + "_\"_" + text2 + "_\"_"));
			if (i < strArray.Length - 1)
			{
				text += ',';
			}
		}
		return text;
	}

	public string RemoveTrailingZeroes(string value)
	{
		try
		{
			if (value != null && value.Contains("."))
			{
				if (value.ToLower().Contains("e"))
				{
					string[] array = value.ToLower().Split('e');
					array[0] = RemoveTrailingZeroes(array[0]);
					array[1] = RemoveTrailingZeroes(array[1]);
					value = array[0] + "e" + array[1];
				}
				else
				{
					while (value.Length > 0 && value[value.Length - 1] == '0')
					{
						value = value.Remove(value.Length - 1);
					}
				}
			}
			if (value.Length > 0 && value.EndsWith("."))
			{
				value += "0";
			}
		}
		catch
		{
		}
		return value;
	}

	public string GetDisplayValue(string currentValue)
	{
		try
		{
			if (currentValue == null)
			{
				currentValue = "";
			}
			currentValue = currentValue.Trim();
			switch (DisplayHint)
			{
			case 8:
			{
				if (!ParameterCollection.CreateNameValueList(Constraints, out var names, out var values))
				{
					break;
				}
				for (int i = 0; i < values.Count; i++)
				{
					if (values[i].ToString() == currentValue)
					{
						currentValue = names[i].ToString();
						break;
					}
				}
				break;
			}
			case 12288:
				currentValue = ((!(currentValue == "1")) ? ((!(currentValue == "")) ? "False" : "") : "True");
				break;
			case 2:
			{
				string[] array = Constraints.Trim().Split(';');
				if (array.Length < 2)
				{
					array = new string[2] { "False", "True" };
				}
				currentValue = ((!(currentValue == "1")) ? array[0].Trim() : array[1].Trim());
				break;
			}
			case 8192:
				currentValue = ((!(currentValue == "1")) ? ((!(currentValue == "")) ? "Off" : "") : "On");
				break;
			case 4096:
				currentValue = ((!(currentValue == "1")) ? ((!(currentValue == "")) ? "No" : "") : "Yes");
				break;
			}
		}
		catch
		{
		}
		return currentValue;
	}

	public bool GetParamValue(ParameterCollection parameters, out ParamValue p)
	{
		p = default(ParamValue);
		try
		{
			ArrayList arrayList = new ArrayList();
			string[] array = new string[1] { "" };
			if (Value == null)
			{
				Value = "";
			}
			if (DataType != DataType.String && NoOfElements > 1)
			{
				array = Value.Split(',');
			}
			else if (NoOfElements > 1 || IsDynamicArray)
			{
				array = SplitStringArrayParameter(Value);
			}
			else
			{
				array[0] = Value;
			}
			string[] array2 = array;
			foreach (string currentValue in array2)
			{
				arrayList.Add(GetDisplayValue(currentValue));
			}
			p.Value = (ArrayList)arrayList.Clone();
			if (IsParamDataTable() && DataTableValue != null)
			{
				p.DataTableValue = DataTableValue.Copy();
			}
			else
			{
				p.DataTableValue = null;
			}
			array = LowerLimit.Split(',');
			arrayList.Clear();
			string[] array3 = array;
			foreach (string value in array3)
			{
				arrayList.Add(value);
			}
			p.LL = (ArrayList)arrayList.Clone();
			array = UpperLimit.Split(',');
			arrayList.Clear();
			string[] array4 = array;
			foreach (string value2 in array4)
			{
				arrayList.Add(value2);
			}
			p.UL = (ArrayList)arrayList.Clone();
			p.Desc = Description;
			p.DispHint = DisplayHint;
			p.GvGetName = GlobalVariableName;
			p.GvGetLowerLimit = GlobalVariableForLL;
			p.GvGetUpperLimit = GlobalVariableForUL;
			p.GvSetName = GlobalVariableNameOther;
			p.UseRunTimeLimits = UseRunTimeLimits;
			p.Unit = Unit;
			p.ParamName = Name;
			p.RealName = RealName;
			p.IOType = Type;
			p.NumElements = NoOfElements;
			p.dataType = DataType;
			p.EnabledCharting = EnableCharting;
			p.Constraint = Constraints;
			if (DataLoggingCondition == null || !DataLoggingCondition.Enabled || !DataLoggingCondition.IsConditionMet(parameters, TestResult.Passed))
			{
				p.EnabledDataLogging = EnableDataLogging;
			}
			else
			{
				ArrayList arrayList2 = new ArrayList();
				for (int l = 0; l < NoOfElements; l++)
				{
					arrayList2.Add(false);
				}
				p.EnabledDataLogging = arrayList2;
			}
			p.ParentName = ParentName;
			p.ParamRID = (int)ParamRID;
			p.ParamArrayRIDs = ArrayParameterRIDs;
			return true;
		}
		catch (Exception ex)
		{
			TraceMessage.Write(ToString(), "GetParameterExportList " + ex.Message, TraceMessageType.Exception);
		}
		return false;
	}

	public ParameterCls Clone()
	{
		ParameterCls parameterCls = new ParameterCls();
		parameterCls.Type = Type;
		parameterCls.Unit = Unit;
		parameterCls.UpperLimit = UpperLimit;
		parameterCls.Value = Value;
		parameterCls.Name = Name;
		parameterCls.NoOfElements = NoOfElements;
		parameterCls.IsDynamicArray = IsDynamicArray;
		parameterCls.IsEditableInTestPlan = IsEditableInTestPlan;
		parameterCls.CanEditResultValue = CanEditResultValue;
		parameterCls.DataType = DataType;
		parameterCls.DataTableValue = DataTableValue;
		parameterCls.LowerLimit = LowerLimit;
		parameterCls.Description = Description;
		parameterCls.DisplayHint = DisplayHint;
		parameterCls.Constraints = Constraints;
		parameterCls.UseRunTimeLimits = UseRunTimeLimits;
		parameterCls.paramRID = paramRID;
		parameterCls.arrayParameterRIDs = (ArrayList)arrayParameterRIDs.Clone();
		parameterCls.enableCharting = (ArrayList)enableCharting.Clone();
		parameterCls.enableDataLogging = (ArrayList)enableDataLogging.Clone();
		parameterCls.selected = selected;
		parameterCls.globalVariableName = globalVariableName;
		parameterCls.globalVariableNameOther = globalVariableNameOther;
		parameterCls.globalVariableForLL = globalVariableForLL;
		parameterCls.globalVariableForUL = globalVariableForUL;
		if (loggingCondition != null)
		{
			parameterCls.loggingCondition = loggingCondition.Clone();
		}
		parameterCls.IsNullable = IsNullable;
		parameterCls.RealName = RealName;
		parameterCls.ParentName = ParentName;
		return parameterCls;
	}

	public void Copy(ParameterCls param)
	{
		Unit = param.Unit;
		UpperLimit = param.UpperLimit;
		Value = param.Value;
		DataTableValue = param.DataTableValue;
		LowerLimit = param.LowerLimit;
		Description = param.Description;
		bEnableCharting = param.bEnableCharting;
		bEnableDataLogging = param.bEnableDataLogging;
		selected = param.Selected;
		globalVariableName = param.GlobalVariableName;
		globalVariableNameOther = param.GlobalVariableNameOther;
		globalVariableForLL = param.GlobalVariableForLL;
		globalVariableForUL = param.GlobalVariableForUL;
		if (param.loggingCondition != null)
		{
			loggingCondition = param.loggingCondition.Clone();
		}
		RealName = param.RealName;
	}

	public CheckState GetCheckState(ArrayList values)
	{
		int num = 0;
		for (int i = 0; i < values.Count; i++)
		{
			if ((bool)values[i])
			{
				num++;
			}
		}
		if (num == 0)
		{
			return CheckState.Unchecked;
		}
		if (num == values.Count)
		{
			return CheckState.Checked;
		}
		return CheckState.Indeterminate;
	}

	public bool IsValueValid(string newParamValue)
	{
		bool result = false;
		try
		{
			if (NoOfElements > 1)
			{
				result = true;
			}
			else
			{
				bool flag = false;
				if ((DisplayHint & 8) == 8)
				{
					flag = true;
				}
				double doubleVal;
				switch (DataType)
				{
				case DataType.Int:
				{
					if (int.TryParse(newParamValue, out var _))
					{
						result = true;
					}
					else if (flag && QsprUtility.GetParamEnumValueAsDouble(newParamValue, Constraints, out doubleVal))
					{
						result = true;
					}
					break;
				}
				case DataType.Hex:
				{
					if (int.TryParse(newParamValue, NumberStyles.HexNumber, null, out var _))
					{
						result = true;
					}
					break;
				}
				case DataType.Byte:
				{
					if (byte.TryParse(newParamValue, out var _))
					{
						result = true;
					}
					break;
				}
				case DataType.Double:
				{
					if (double.TryParse(newParamValue, out var _))
					{
						result = true;
					}
					else if (flag && QsprUtility.GetParamEnumValueAsDouble(newParamValue, Constraints, out doubleVal))
					{
						result = true;
					}
					break;
				}
				case DataType.Boolean:
				{
					string stringValue = GetStringValue(newParamValue);
					if (bool.TryParse(stringValue, out var _))
					{
						result = true;
					}
					break;
				}
				case DataType.String:
					result = true;
					break;
				case DataType.DataTable:
					result = true;
					break;
				default:
					if (newParamValue.Trim().Length > 0)
					{
						result = true;
					}
					break;
				}
			}
		}
		catch
		{
		}
		return result;
	}

	public bool IsParamDataTable()
	{
		return paramType == DataType.DataTable;
	}

	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 CheckInLimitsForBool(string strLL, string strValue, string strUL)
	{
		bool result;
		bool flag = bool.TryParse(strLL, out result);
		bool.TryParse(strValue, out var result2);
		bool result3;
		bool flag2 = bool.TryParse(strUL, out result3);
		if (flag && result2 != result)
		{
			return false;
		}
		if (flag2 && result2 != result3)
		{
			return false;
		}
		return true;
	}

	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);
			bool flag2 = double.TryParse(strValue, out var result2);
			double result3;
			bool flag3 = double.TryParse(strUL, out result3);
			if (DisplayHint == 8)
			{
				if (!flag2)
				{
					flag2 = QsprUtility.GetParamEnumValueAsDouble(strValue, Constraints, out result2);
				}
				if (!flag)
				{
					flag = QsprUtility.GetParamEnumValueAsDouble(strLL, Constraints, out result);
				}
				if (!flag3)
				{
					flag3 = QsprUtility.GetParamEnumValueAsDouble(strUL, Constraints, out result3);
				}
			}
			if (flag && flag3)
			{
				if (result <= result2 && result2 <= result3)
				{
					return true;
				}
				return false;
			}
			if (flag)
			{
				if (result <= result2)
				{
					return true;
				}
				return false;
			}
			if (flag3)
			{
				if (result2 <= result3)
				{
					return true;
				}
				return false;
			}
		}
		catch
		{
		}
		return true;
	}

	protected ParameterCls(SerializationInfo info, StreamingContext context)
	{
		paramName = info.GetString("Name");
		paramValue = info.GetString("Value");
	}

	public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
	{
		info.AddValue("Name", paramName);
		info.AddValue("Value", paramValue);
		info.AddValue("Type", paramType);
	}

	internal string GetStringValue(string newParamValue)
	{
		if (newParamValue == null)
		{
			return newParamValue;
		}
		string result = newParamValue;
		if (DataType == DataType.Boolean)
		{
			switch (DisplayHint)
			{
			case 8192:
				if (newParamValue.ToLower() == "on" || newParamValue == "1")
				{
					result = "True";
				}
				else if (newParamValue.ToLower() == "off" || newParamValue == "0")
				{
					result = "False";
				}
				break;
			case 12288:
				if (newParamValue == "1")
				{
					result = "True";
				}
				else if (newParamValue == "0")
				{
					result = "False";
				}
				break;
			case 4096:
				if (newParamValue.ToLower() == "yes" || newParamValue == "1")
				{
					result = "True";
				}
				else if (newParamValue.ToLower() == "no" || newParamValue == "0")
				{
					result = "False";
				}
				break;
			}
		}
		return result;
	}

	internal string GetDisplayString(string gvValue)
	{
		string result = gvValue;
		if (DataType == DataType.Boolean)
		{
			switch (DisplayHint)
			{
			case 4096:
				result = ((!(gvValue.ToLower() == "true") && !(gvValue == "1") && !(gvValue.ToLower() == "yes")) ? "No" : "Yes");
				break;
			case 12288:
				result = ((!(gvValue.ToLower() == "true") && !(gvValue == "1")) ? "False" : "True");
				break;
			case 8192:
				result = ((!(gvValue.ToLower() == "true") && !(gvValue == "1") && !(gvValue.ToLower() == "on")) ? "Off" : "On");
				break;
			}
		}
		return result;
	}
}
