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

📄 highquery.js

📁 在很多项目中
💻 JS
📖 第 1 页 / 共 4 页
字号:
	var objHighQueryPanel = document.getElementById("highQueryPanel");
	if(objHighQueryPanel != null)
	{
		objHighQueryPanel.innerHTML = strHtml;
		// 初始化第一行。
		initFristRow();
	} 
	else
		alert("没有发现highQueryPanel!");
}

// 初始化第一行。
function initFristRow()
{
	highQuery.insertRow();
	var newRow = highQuery.rows[highQuery.rows.length - 1];
	
	newRow.id = "row_" + autoId;

	newRow.insertCell();
	newRow.cells[0].className = "HQ_TD";
	newRow.cells[0].innerHTML = "        ";

	newRow.insertCell();
	newRow.cells[1].className = "HQ_TD";
	newRow.cells[1].width = 60;
	newRow.cells[1].innerHTML = initLParenthesisPanel(autoId);
	
	newRow.insertCell();
	newRow.cells[2].className = "HQ_TD";
	newRow.cells[2].innerHTML = initField(autoId);
	
	newRow.insertCell();
	newRow.cells[3].className = "HQ_TD";
	newRow.cells[3].innerHTML = initCondition(autoId);
	
	newRow.insertCell();
	newRow.cells[4].className = "HQ_TD";
	newRow.cells[4].innerHTML = initContent(autoId);

	newRow.insertCell();
	newRow.cells[5].className = "HQ_TD";
	newRow.cells[5].width = 60;
	newRow.cells[5].innerHTML = initRParenthesisPanel(autoId);

	newRow.insertCell();
	newRow.cells[6].className = "HQ_TD";
	newRow.cells[6].innerHTML = initSort(autoId);
	
	newRow.insertCell();
	newRow.cells[7].className = "HQ_TD";
	newRow.cells[7].innerHTML = "<input type='button' class='HQ_BUTTON' value='增加' onClick='addRow()'>";
	
	var objField = document.getElementById("field_" + autoId); // 取得当前的字段选择控件对象
	if(objField.options.length > 0)
		objField.options.selectedIndex = objField.options.length - 1; // 选中字段列表的最后一个"请选择一个字段"

	autoId += 1; // autoId加1
}

/******************************以下为条件增删部分******************************/

// 新添加一行。
function addRow()
{
	highQuery.insertRow();
	var newRow = highQuery.rows[highQuery.rows.length - 1];

	newRow.id = "row_" + autoId;
	
	newRow.insertCell();
	newRow.cells[0].className = "HQ_TD";
	newRow.cells[0].innerHTML = initJoin(autoId);
	
	newRow.insertCell();
	newRow.cells[1].className = "HQ_TD";
	newRow.cells[1].width = 60;
	newRow.cells[1].innerHTML = initLParenthesisPanel(autoId);

	newRow.insertCell();
	newRow.cells[2].className = "HQ_TD";
	newRow.cells[2].innerHTML = initField(autoId);
	
	newRow.insertCell();
	newRow.cells[3].className = "HQ_TD";
	newRow.cells[3].innerHTML = initCondition(autoId);
	
	newRow.insertCell();
	newRow.cells[4].className = "HQ_TD";
	newRow.cells[4].innerHTML = initContent(autoId);
	
	newRow.insertCell();
	newRow.cells[5].className = "HQ_TD";
	newRow.cells[5].width = 60;
	newRow.cells[5].innerHTML = initRParenthesisPanel(autoId);

	newRow.insertCell();
	newRow.cells[6].className = "HQ_TD";
	newRow.cells[6].innerHTML = initSort(autoId);

	newRow.insertCell();
	newRow.cells[7].className = "HQ_TD";
	newRow.cells[7].innerHTML = "<input type='button' class='HQ_BUTTON' value='删除' onClick=removeRow('" + newRow.id + "')>";
	
	var objField = document.getElementById("field_" + autoId); // 取得当前的字段选择控件对象
	if(objField.options.length > 0)
		objField.options.selectedIndex = objField.options.length - 1; // 选中字段列表的最后一个"请选择一个字段"

	autoId += 1; // autoId加1
}

// 删除行。
function removeRow(rowId)
{
	var trRow = document.getElementById(rowId);
	trRow.removeNode(true);
}

// 生成条件查询语句。
function interpreter()
{
	var arrReturn = new Array();
	var strCondition = "";
	var strAliasCondition = "";
	var strSort = "";
	var strAliasSort = "";
	var isNoProblem = true;
	
	// 语法检测
	if(!checkExpression())
	{
		isNoProblem = false;
		arrReturn[0] = "";
		arrReturn[1] = "";
		arrReturn[2] = "";
		arrReturn[3] = "";
		return arrReturn;
	}

	for(var i = 1; i < highQuery.rows.length; i++)
	{
		var id = highQuery.rows[i].id.split("_")[1];
		var objField = document.getElementById("field_" + id); // 取得字段选择控件对象
		var objCondition = document.getElementById("condition_" + id); // 取得条件运算符选择控件对象
		var objBContent = document.getElementById("bContent_" + id); // 取得第一个条件内容文件控件对象
		var objHibBContent = document.getElementById("hibBContent_" + id); // 取得第一个条件内容文件控件对象(隐藏的)
		var objLParenthesisPanel = document.getElementById("lParenthesisPanel_" + id); // 取得左括号面板对象
		var objRParenthesisPanel = document.getElementById("rParenthesisPanel_" + id); // 取得右括号面板对象
		var objSort = document.getElementById("sort_" + id); // 取得排序选择控件对象
		var isHasDict = FieldList.fields[objField.selectedIndex].dictCode == ""?false:true; // 是否有字典
		var isHasEvent = FieldList.fields[objField.selectedIndex].event == ""?false:true; // 是否有事件
		var strType = FieldList.fields[objField.selectedIndex].type; // 内容类别
		var strAlias = FieldList.fields[objField.selectedIndex].alias; // 字段别名
		
		/*******生成条件部分*******/
		
		// 如果不是第一个条件并且运算符不为空就要加上连接条件符号(AND,OR)。
		if(i > 1 && objCondition.value != "") 
		{
			var objJoin = document.getElementById("join_" + id); // 条件相连的运算符
			strCondition += " " + objJoin.value + " ";
			strAliasCondition +=  " " + objJoin.value + " ";
		}

		// 加上左括号
		strCondition += objLParenthesisPanel.outerText;
		strAliasCondition += objLParenthesisPanel.outerText;

		if (objCondition.value != "") // 运算符不为空(处理运算符为不查询)
		{
			strCondition += objField.value;
			strAliasCondition += strAlias;
		}

		switch(objCondition.value)
		{
			case "": // 不查询时不做任何事情
				break;
			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(((isHasDict || isHasEvent)?objHibBContent:objBContent), strAlias, emendationType(strType)))
				{
					strCondition += inCondition(((isHasDict || isHasEvent)?objHibBContent:objBContent), strType, objCondition.value);
					strAliasCondition += inCondition(objBContent, strType, objCondition.value);
				}
				else
					isNoProblem = false;
				break;
			case "not_in": // 查询条件为not in时
				if(checkDataIn(((isHasDict || isHasEvent)?objHibBContent:objBContent), strAlias, emendationType(strType)))
				{
					strCondition += inCondition(((isHasDict || isHasEvent)?objHibBContent:objBContent), strType, objCondition.value);
					strAliasCondition += inCondition(objBContent, strType, objCondition.value);
				}
				else
					isNoProblem = false;
				break;
			case "between": // 查询条件为between时
				var objEContent = document.getElementById("eContent_" + id); // between查询时才会出现的第二个条件内容对象
				var objHibEContent = document.getElementById("hibEContent_" + id); // between查询时才会出现的第二个条件内容对象(隐藏的)
				if(checkDataBetween(((isHasDict || isHasEvent)?new Array(objHibBContent, objHibEContent):new Array(objBContent, objEContent)), strAlias, emendationType(strType)))
				{
					strCondition += betweenCondition(((isHasDict || isHasEvent)?objHibBContent:objBContent), ((isHasDict || isHasEvent)?objHibEContent: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(((isHasDict || isHasEvent)?objHibBContent:objBContent), strAlias, emendationType(strType)))
				{
					strCondition += " " + objCondition.value + normalCondition(((isHasDict || isHasEvent)?objHibBContent: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;

		/*******生成排序部分*******/

		if(objSort.value != "")
		{
			strSort += objField.value + " " + objSort.value + ",";
			strAliasSort += strAlias + " " + objSort.options[objSort.selectedIndex].text + ",";
		}
	}
	arrReturn[0] = strAliasCondition;
	arrReturn[1] = strCondition;
	arrReturn[2] = (strAliasSort == ""?"":strAliasSort.substring(0, strAliasSort.length - 1));
	arrReturn[3] = (strSort == ""?"":strSort.substring(0, strSort.length - 1));
	return arrReturn;
}

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

// 根据类型返回相应校正的项目。
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 objField = document.getElementById("field_" + id); // 取得字段选择控件对象
		var objCondition = document.getElementById("condition_" + id); // 取得条件运算符选择控件对象
		var objLParenthesisPanel = document.getElementById("lParenthesisPanel_" + id); // 取得左括号面板对象
		var objRParenthesisPanel = document.getElementById("rParenthesisPanel_" + id); // 取得右括号面板对象
		
		if(objField.value == "") // 字段是否为空
		{
			alert("所选的条件中存在不明确的字段名,请先选择一个有效字段名!");

⌨️ 快捷键说明

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