⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 highquery0.3.htm

📁 javascript实现一个高级组合查询控件
💻 HTM
📖 第 1 页 / 共 3 页
字号:
		{
			isNoProblem = false;
			alert("所选的条件中存在不明确的字段名,请先选择一个有效字段名!");
			objField.focus();
			arrReturn[0] = "";
			arrReturn[1] = "";
			return arrReturn;
		}

		switch(objCondition.value)
		{
			case "like": // 查询条件为like时
				if(checkDataLike(objBContent, strAlias, emendationType(strType))) 
				{
					strCondition += likeCondition(objBContent, strType, objCondition.value);
					strAliasCondition += likeCondition(objBContent, strType, objCondition.value);
				}
				else
					isNoProblem = false;
				break;
			case "in": // 查询条件为in时
				if(checkDataIn(objBContent, strAlias, emendationType(strType)))
				{
					strCondition += inCondition(objBContent, strType, objCondition.value);
					strAliasCondition += inCondition(objBContent, strType, objCondition.value);
				}
				else
					isNoProblem = false;
				break;
			case "not_in": // 查询条件为not in时
				if(checkDataIn(objBContent, strAlias, emendationType(strType)))
				{
					strCondition += inCondition(objBContent, strType, objCondition.value);
					strAliasCondition += inCondition(objBContent, strType, objCondition.value);
				}
				else
					isNoProblem = false;
				break;
			case "between": // 查询条件为between时
				var objEContent = document.getElementById("eContent_" + id); // between查询时才会出现的第二个条件内容对象
				if(checkDataBetween(new Array(objBContent, objEContent), strAlias, emendationType(strType)))
				{
					strCondition += betweenCondition(objBContent, objEContent, strType, objCondition.value);
					strAliasCondition += betweenCondition(objBContent, objEContent, strType, objCondition.value);
				}
				else
					isNoProblem = false;
				break;
			case "is": // 查询条件为is时
				if(checkDataIs(objBContent, strAlias, "checknull"))
				{
					strCondition += isCondition(objBContent, strType, objCondition.value);
					strAliasCondition += isCondition(objBContent, strType, objCondition.value);
				}
				else
					isNoProblem = false;
				break;
			default: // 查询条件为其他时
				if(checkDataNormal(objBContent, strAlias, emendationType(strType)))
				{
					strCondition += " " + objCondition.value + normalCondition(objBContent, strType);
					strAliasCondition +=  " " + objCondition.value + normalCondition(objBContent, strType);
				}
				else
					isNoProblem = false;
				break;
		}
		if(isNoProblem != true)
		{
			arrReturn[0] = "";
			arrReturn[1] = "";
			return arrReturn;
		}

		// 加上右括号
		strCondition += objRParenthesisPanel.outerText;
		strAliasCondition += objRParenthesisPanel.outerText;
	}
	arrReturn[0] = strAliasCondition;
	arrReturn[1] = strCondition;
	return arrReturn;
}

// 生成like查询条件内容。
function likeCondition(objTemp, strType, strCondition)
{
	var strTemp = normalCondition(objTemp, strType);
	return " " + strCondition + strTemp;
}

// 生成in或not in查询条件内容。
function inCondition(objTemp, strType, strCondition)
{
	var strTemp = normalCondition(objTemp, strType);
	var strReturn = "";
	if(strTemp != " ''")
	{
		strTemp = strTemp.substring(2, strTemp.length - 1); // 除去两边的单引号
		var arrTemp = strTemp.split(',');
		for(var i = 0; i < arrTemp.length; i++)
		{
			if(arrTemp[i] != null)
			{
				strReturn += "'" + arrTemp[i] + "',"
			}
		}
		strReturn = strReturn.substring(0, strReturn.length - 1); // 除去最后一个豆号
		return " " + strCondition.replace("_", " ") + " ( " + strReturn + " )";
	} 
	else
	{
		strReturn = strTemp;
		return " " + strCondition.replace("_", " ") + " ( " + strReturn + " )";
	}
}

// 生成between的查询条件内容。
function betweenCondition(objTemp1, objTemp2, strType, strCondition)
{
	strTemp1 = normalCondition(objTemp1, strType);
	strTemp2 = normalCondition(objTemp2, strType);
	return " " + strCondition + strTemp1 + " and" + strTemp2;
}

// 生成is查询条件内容。
function isCondition(objTemp, strType, strCondition)
{
	var strTemp = objTemp.value;
	strTemp = strTemp.trim();
	return strTemp==""?" " + strCondition + " null":" " + strCondition + " " + strTemp;
}

// 生成一般查询条件内容。
function normalCondition(objTemp, strType)
{
	var strTemp = objTemp.value;
	strTemp = strTemp.trim();
	return strTemp==""?" ''":" '" + strTemp + "'";
}

/******************************以下为字段类型验测函数******************************/

// 根据类型返回相应校正的项目。
function emendationType(strType)
{
	if(strType == 'number')
	{
		return "checknumber";
	}
	else if(strType == 'date' || strType == 'datetime')
	{
		return "";
	}
	return "";
}

/******************************以下为校正函数**********************************/

// 语法校正
function checkExpression()
{
	var strLParenthesis = "";
	var strRParenthesis = "";

	for(var i = 1; i < highQuery.rows.length; i++)
	{
		var id = highQuery.rows[i].id.split("_")[1];
		var objLParenthesisPanel = document.getElementById("lParenthesisPanel_" + id); // 取得左括号面板对象
		var objRParenthesisPanel = document.getElementById("rParenthesisPanel_" + id); // 取得右括号面板对象
		strLParenthesis += objLParenthesisPanel.outerText;
		strRParenthesis += objRParenthesisPanel.outerText;
	}

	if(strLParenthesis.length != strRParenthesis.length)
	{
		alert("\"(\"与\")\"的数量不对应,请检查!");
		return false;
	}
	return true;
}

// 数据校正(like查询专用)。
function checkDataLike(objTemp, strText, action)
{
	var strTemp = objTemp.value;
	//if(strTemp == "" || action == "checkdate")
	//	return true;
	strTemp = strTemp.replace(/\%/g, "");
	strTemp = strTemp.replace(/\_/g, "");
	if(strTemp == "")
		return true;
	return checkS(objTemp, strTemp, strText, action);
}

// 数据校正(in或not in查询专用)。
function checkDataIn(objTemp, strText, action)
{
	var strTemp = objTemp.value;
	var temps = strTemp.split(',');
	var boolOK = true;
	for(var i = 0; i < temps.length; i++)
	{
		if(temps[i] != "")
			boolOK = checkS(objTemp, temps[i], strText, action);
		if(boolOK == false)
			break;
	}
	return boolOK;
}

// 数据校正。(between查询专用)
function checkDataBetween(objTemp, strText, action)
{
	var strTemp = new Array(objTemp[0].value, objTemp[1].value);
	var boolOK = true;
	for(var i = 0; i < objTemp.length; i++)
	{
		if(strTemp[i] != "")
			boolOK = checkS(objTemp[i], strTemp[i], strText, action);
		if(boolOK == false)
			break;
	}
	return boolOK;
}

// 数据校正。(is查询时用)
function checkDataIs(objTemp, strText, action)
{
	var strTemp = objTemp.value;
	return checkS(objTemp, strTemp, strText, action);
}

// 数据校正。(一般查询时用)
function checkDataNormal(objTemp, strText, action)
{
	var strTemp = objTemp.value;
	if(strTemp == "")
		return true;
	return checkS(objTemp, strTemp, strText, action);
}

/******************************以下为触发功能******************************/

// 改变所选字段时,相应改变界面。
function changeField()
{
	var objField = window.event.srcElement; // 取得字段选择控件
	var id = objField.id.split("_")[1];
	var trRow = document.getElementById("row_" + id); // 取得行对象。
	var objCondition = document.getElementById("condition_" + id); // 取得条件运算符选择控件对象
	var objSignPanel = document.getElementById("signPanel_" + id); // 取得查询符号面板对象
	var objBChoicePanel = document.getElementById("bChoicePanel_" + id); // 取得第一个内容文本"选择"面板对象
	var objEContentPanel = document.getElementById("eContentPanel_" + id); // 取得第二个内容文本面板对象
	var objBContent = document.getElementById("bContent_" + id); // 取得第一个条件内容文件控件对象
	var isDate = arrType[objField.selectedIndex] == "date"?true:false;
	var isDateTime = arrType[objField.selectedIndex] == "datetime"?true:false;
	objBContent.value = "";
	objBContent.maxLength = arrLength[objField.selectedIndex]; // 根据字段长度改变文本控件的长度

	if(isDate || isDateTime) // 如果对应的字段类型是date或datetime时,删除like查询条件
	{
		var conditionTemp = objCondition.value;
		if(objCondition.options[objCondition.length-1].value == "like")
		{
			objCondition.options.remove(objCondition.options[objCondition.length-1].index)
			objSignPanel.innerHTML = ""; // 清除查询符号面板内容
		}
		if(conditionTemp != "like")
			objCondition.value = conditionTemp;
	}
	else 
	{
		if(objCondition.options[objCondition.length-1].value != "like")
		{
			objCondition.options.add(new Option('LIKE', 'like'));
		}
	}
	
	switch(objCondition.value)
	{
		case "like": // 查询条件为like时
			objBContent.setAttribute("readOnly", "");
			objSignPanel.innerHTML = getLikeHtml(id);
			objBChoicePanel.innerHTML = ""; // 清除date或datetime查询时留下的第一个内容文本"选择"面板内容(不论是否存在)
			break;
		case "in": // 查询条件为in时
			objBContent.maxLength = '2147483647'; // 设为最大值
			if(isDate || isDateTime) // 如果对应的字段类型是date或datetime时,给用户选择日期

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -