﻿LeadingMIS.ValueType = function(){}

LeadingMIS.ValueType.isInt = function(expression,minTemp,maxTemp)
{
	if(typeof(expression) != "number")
	{
	//	LeadingMIS.Error.setInfo(0,this.isInt,"传入的参数[expression]不是数字","LeadingMIS.ValueType.isInt","");
		LeadingMIS.Error.setInfo(0,this.isInt,"应该是整数","LeadingMIS.ValueType.isInt","");
		return false;
	}
	else if(typeof(minTemp) != "number")
	{
		LeadingMIS.Error.setInfo(0,this.isInt,"传入的参数[minTemp]不是数字","LeadingMIS.ValueType.isInt","");
		return false;
	}
	else if(typeof(maxTemp) != "number")
	{
		LeadingMIS.Error.setInfo(0,this.isInt,"传入的参数[maxTemp]不是数字","LeadingMIS.ValueType.isInt","");
		return false;
	}
	else
	{
		if(expression.toString().indexOf(".") != -1)
		{
		//	LeadingMIS.Error.setInfo(0,this.isInt,"传入的参数[expression]不是整数","LeadingMIS.ValueType.isInt","");
			LeadingMIS.Error.setInfo(0,this.isInt,"应该是整数","LeadingMIS.ValueType.isInt","");
			return false;
		}
		else if(minTemp.toString().indexOf(".") != -1)
		{
			LeadingMIS.Error.setInfo(0,this.isInt,"传入的参数[minTemp]不是整数","LeadingMIS.ValueType.isInt","");
			return false;
		}
		else if(maxTemp.toString().indexOf(".") != -1)
		{
			LeadingMIS.Error.setInfo(0,this.isInt,"传入的参数[maxTemp]不是整数","LeadingMIS.ValueType.isInt","");
			return false;
		}
		else
		{
			if(expression < minTemp)
			{
				LeadingMIS.Error.setInfo(0,this.isInt,"超出最小范围","LeadingMIS.ValueType.isInt","");
				return false;
			}
			else if(expression > maxTemp)
			{
				LeadingMIS.Error.setInfo(0,this.isInt,"超出最大范围","LeadingMIS.ValueType.isInt","");
				return false;
			}
			else
			{
				return true;
			}
		}
	}
}
/*
expression	: 数据值
maxTemp		: 精度	
decimalTemp	: 小数位数
*/
LeadingMIS.ValueType.isDecimal = function(expression,maxTemp,decimalTemp)
{
	if(LeadingMIS.ValueType.isInt(maxTemp,1,38) == false)
	{
		LeadingMIS.Error.setInfo(0,this.isDecimal,"输入参数[maxTemp]的范围必须在[1~38]之间","LeadingMIS.ValueType.isDecimal","");
		return false;
	}
	else if(LeadingMIS.ValueType.isInt(decimalTemp,0,38) == false)
	{
		LeadingMIS.Error.setInfo(0,this.isDecimal,"输入参数[decimalTemp]的范围必须在[0~38]之间","LeadingMIS.ValueType.isDecimal","");
		return false;
	}
	else
	{
		if(maxTemp < decimalTemp)
		{
			LeadingMIS.Error.setInfo(0,this.isDecimal,"输入参数[maxTemp]不能小于[decimalTemp]","LeadingMIS.ValueType.isDecimal","");
			return false;
		}
		else
		{
			if(typeof(expression) != "number")
			{
			//	LeadingMIS.Error.setInfo(0,this.isDecimal,"输入参数[expression]必须为数字","LeadingMIS.ValueType.isDecimal","");
				LeadingMIS.Error.setInfo(0,this.isDecimal,"应该是数字","LeadingMIS.ValueType.isDecimal","");
				return false;
			}
			else
			{
				var arrTemp = expression.toString().split(".");
				
				//整数位长度
				var intLen = arrTemp[0].length ;
				
				//小数位数长度
				var decimalLen = ((arrTemp[1]==null) ? 0 : arrTemp[1].length)
				
				if((intLen + decimalLen) > maxTemp)
				{
					LeadingMIS.Error.setInfo(0,this.isDecimal,"超出范围[最大精度为" + maxTemp + "位(除小数点外的数据长度)]","LeadingMIS.ValueType.isDecimal","");
					return false;
				}
				else if(decimalLen > decimalTemp)
				{
					LeadingMIS.Error.setInfo(0,this.isDecimal,"超出范围[最大小数位数为" + decimalTemp + "位]","LeadingMIS.ValueType.isDecimal","");
					return false;
				}
				else
				{
					return true;
				}
				
				/*				
				if(arrTemp[0].length > maxTemp - decimalTemp)
				{
					LeadingMIS.Error.setInfo(0,this.isDecimal,"超出范围","LeadingMIS.ValueType.isDecimal","");
					return false;
				}
				*/
				
			}
		}
	}
}

LeadingMIS.ValueType.isDateTime = function(expression,minTemp,maxTemp)
{
	if((typeof(minTemp) == "undefined") && (typeof(maxTemp) == "undefined"))
	{
		if(vbIsDate(expression) == false)
		{
		//	LeadingMIS.Error.setInfo(0,this.isDateTime,"输入参数[expression]应该是日期型","LeadingMIS.ValueType.isDateTime","");
			LeadingMIS.Error.setInfo(0,this.isDateTime,"应该是日期","LeadingMIS.ValueType.isDateTime","");
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		if(vbIsDate(expression) == false)
		{
		//	LeadingMIS.Error.setInfo(0,this.isDateTime,"输入参数[expression]应该是日期型","LeadingMIS.ValueType.isDateTime","");
			LeadingMIS.Error.setInfo(0,this.isDateTime,"应该是日期","LeadingMIS.ValueType.isDateTime","");
			return false;
		}
		else if(vbIsDate(minTemp) == false)
		{
			LeadingMIS.Error.setInfo(0,this.isDateTime,"输入参数[minTemp]应该是日期型","LeadingMIS.ValueType.isDateTime","");
			return false;
		}
		else if(vbIsDate(maxTemp) == false)
		{
			LeadingMIS.Error.setInfo(0,this.isDateTime,"输入参数[maxTemp]应该是日期型","LeadingMIS.ValueType.isDateTime","");
			return false;
		}
		else
		{
			if(DateDiff("d",expression,minTemp) > 0)
			{
				LeadingMIS.Error.setInfo(0,this.isDateTime,"超出最小日期范围","LeadingMIS.ValueType.isDateTime","");
				return false;
			}
			else if(DateDiff("d",expression,maxTemp) < 0)
			{
				LeadingMIS.Error.setInfo(0,this.isDateTime,"超出最大日期范围","LeadingMIS.ValueType.isDateTime","");
				return false;
			}
			else
			{
				return true;
			}
		}
	}
}

LeadingMIS.ValueType.isInt8 = function(expression)
{
	return LeadingMIS.ValueType.isInt(expression,-Math.pow(2,7),Math.pow(2,7) - 1);
}

LeadingMIS.ValueType.isInt16 = function(expression)
{
	return LeadingMIS.ValueType.isInt(expression,-Math.pow(2,15),Math.pow(2,15) - 1);
}

LeadingMIS.ValueType.isInt32 = function(expression)
{
	return LeadingMIS.ValueType.isInt(expression,-Math.pow(2,31),Math.pow(2,31) - 1);
}

LeadingMIS.ValueType.isInt64 = function(expression)
{
	return LeadingMIS.ValueType.isInt(expression,-Math.pow(2,63),Math.pow(2,63) - 1);
}

LeadingMIS.ValueType.isUInt8 = function(expression)
{
	return LeadingMIS.ValueType.isInt(expression,0,Math.pow(2,8) - 1);
}

LeadingMIS.ValueType.isUInt16 = function(expression)
{
	return LeadingMIS.ValueType.isInt(expression,0,Math.pow(2,16) - 1);
}

LeadingMIS.ValueType.isUInt32 = function(expression)
{
	return LeadingMIS.ValueType.isInt(expression,0,Math.pow(2,32) - 1);
}

LeadingMIS.ValueType.isUInt64 = function(expression)
{
	return LeadingMIS.ValueType.isInt(expression,0,Math.pow(2,64) - 1);
}

LeadingMIS.ValueType.isDouble = function(expression)
{
	if(typeof(expression) != "number")
	{
	//	LeadingMIS.Error.setInfo(0,this.isDouble,"输入参数[expression]必须是数字","LeadingMIS.ValueType.isDouble","");
		LeadingMIS.Error.setInfo(0,this.isDouble,"应该是数字","LeadingMIS.ValueType.isDouble","");
		return false;
	}
	else
	{
		if(expression < -(1.79 * Math.pow(10,308)))
		{
			LeadingMIS.Error.setInfo(0,this.isDouble,"超出最小范围","LeadingMIS.ValueType.isDouble","");
			return false;
		}
		else if(expression > (1.79 * Math.pow(10,308)))
		{
			LeadingMIS.Error.setInfo(0,this.isDouble,"超出最大范围","LeadingMIS.ValueType.isDouble","");
			return false;
		}
		else
		{
			return true;
		}
	}
}

LeadingMIS.ValueType.isReal = function(expression)
{
	if(typeof(expression) != "number")
	{
	//	LeadingMIS.Error.setInfo(0,this.isReal,"输入参数[expression]必须是数字","LeadingMIS.ValueType.isReal","");
		LeadingMIS.Error.setInfo(0,this.isReal,"应该是数字","LeadingMIS.ValueType.isReal","");
		return false;
	}
	else
	{
		if(expression < -(3.4 * Math.pow(10,38)))
		{
			LeadingMIS.Error.setInfo(0,this.isReal,"超出最小范围","LeadingMIS.ValueType.isReal","");
			return false;
		}
		else if(expression > (3.4 * Math.pow(10,38)))
		{
			LeadingMIS.Error.setInfo(0,this.isReal,"超出最大范围","LeadingMIS.ValueType.isReal","");
			return false;
		}
		else
		{
			return true;
		}
	}
}
//////////////////////////////////////////////////
LeadingMIS.ValueType.ToInt = function(expression,defaultValue,radix)
{
	radix = (typeof(radix) == "undefined")?10:radix;
	var tempInt = 0;
	try
	{
		tempInt = parseInt(expression,radix);
		if(isNaN(tempInt) != true)
		{
			return tempInt;
		}
		else
		{
			return defaultValue;
		}
	}
	catch(e)
	{
		return defaultValue;
	}
}

LeadingMIS.ValueType.FromNull = function(expression,defaultValue)
{
	try
	{
		if((expression == null) || (expression.trim().length == 0))
		{
			return defaultValue;
		}
		else
		{
			return expression;
		}
	}
	catch(e)
	{
		return defaultValue;
	}
}

LeadingMIS.ValueType.ToObject = function(expression,array)
{
	var object = null;
	object = expression.toObject(array);
	if(object == null)
	{
		return new Object();
	}
	else
	{
		return object;
	}
}