发布一个原创的基于Ajax的通用(组合)查询(续)

3.AjaxSearchClientScript.js
None.gif var  tbPanel             =   null ;         // 用于展示组合条件的表控件
None.gif
var  tableName         =   null ;         // 记录查询的表
None.gif
var  fieldsInfo         =   null ;         // 保存从服务端取得的对应表的字段信息
None.gif
var  no                 =   0 ;         // 为防止出现重复id保存的计数器
None.gif//
添加条件编辑行
None.gif

None.gif
function  addTerm(tbPanelId)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    tbPanel 
= document.getElementById(tbPanelId);
InBlock.gif    
if(tableName == null) tableName = document.getElementById("transValue").value;
InBlock.gif    
InBlock.gif    
// 添加一待填模板行
InBlock.gif
    var row    = tbPanel.insertRow();
InBlock.gif    no
++;
InBlock.gif    row.id 
= "row"+no;
InBlock.gif    
InBlock.gif    
//*****************************step 1:添加字段选择部分*****************************
InBlock.gif
    var cell            = row.insertCell();
InBlock.gif    
var fieldInputId    = "field"+row.id;
InBlock.gif    
var newElement        = document.createElement("<SELECT ID='"+fieldInputId+"' οnchange='javascript:getOpts("+row.id+");getInput("+row.id+")'></SELECT>");
InBlock.gif    
InBlock.gif    cell.insertBefore(newElement);
InBlock.gif    
InBlock.gif    
//取出字段信息,首次从服务端取得
InBlock.gif
    if(fieldsInfo == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        fieldsInfo 
= WebUI.AjaxSearchSystem.AjaxSearchMethod.GetFields(tableName.toString()).value;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
//分解字段信息,格式为“字段中文名|字段名”
InBlock.gif

InBlock.gif    
var fieldsInfoLen;
InBlock.gif    
var i,index;
InBlock.gif    
var fieldValue;
InBlock.gif    
InBlock.gif    fieldsInfoLen 
= fieldsInfo.length
InBlock.gif    
InBlock.gif    
for(i=0;i<fieldsInfoLen;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        fieldValue 
= fieldsInfo[i];
InBlock.gif        index 
= fieldValue.indexOf("|");
InBlock.gif        newElement.options[newElement.options.length] 
= new Option(fieldValue.substring(0,index),fieldValue.substring(index+1,fieldValue.length));
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
//*****************************step 2:提取默认(首个)字段对应的运算符*************
InBlock.gif
    cell = row.insertCell();
InBlock.gif    
var optInputId = "opt" +row.id;
InBlock.gif    newElement 
= document.createElement("<SELECT ID='"+optInputId+"' style='WIDTH: 88px'></SELECT>");
InBlock.gif    cell.insertBefore(newElement);
InBlock.gif    
InBlock.gif    getOpts(row);
InBlock.gif    
InBlock.gif    
//*****************************step 3:设置字段条件值的录入(选择)框***************
InBlock.gif
    getInput(row);
InBlock.gif    
InBlock.gif    
//*****************************step 4:生成连接条件选择框***************************
InBlock.gif
    cell = row.insertCell();
InBlock.gif    
var relateInputId = "relate"+row.id;
InBlock.gif    newElement 
= document.createElement("<SELECT ID='"+relateInputId+"'></SELECT>");
InBlock.gif    cell.insertBefore(newElement);
InBlock.gif    newElement.options[newElement.options.length] 
= new Option("并且","And");
InBlock.gif    newElement.options[newElement.options.length] 
= new Option("或者","Or");
InBlock.gif    
InBlock.gif    
//*****************************step 5:生成删除当前行按纽***************************
InBlock.gif
    cell = row.insertCell();
InBlock.gif    
var deleteBtnId = "delete"+row.id;
InBlock.gif    newElement 
= document.createElement("<INPUT ID='"+deleteBtnId+"' type='Button' class='redButtonCss' value='删除' οnclick='javascript:DelRow("+row.id+")'>");
InBlock.gif    cell.insertBefore(newElement);
InBlock.gif    
InBlock.gif    
//*****************************step 6:生成增加下一行按纽***************************
InBlock.gif
    cell = row.insertCell();
InBlock.gif    
var addBtnId = "add"+row.id;
InBlock.gif    newElement 
= document.createElement("<INPUT ID='"+addBtnId+"' type='Button' class='redButtonCss' value='新增' οnclick='javascript:addRow("+row.id+")'>");
InBlock.gif    cell.insertBefore(newElement);
ExpandedBlockEnd.gif}

None.gif
None.gif
// 取得并设置运算符
None.gif
function  getOpts(row)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var rowId = row.id;
InBlock.gif    
InBlock.gif    
var fieldSelId = "field"+rowId;
InBlock.gif    
var field = document.getElementById(fieldSelId);
InBlock.gif    
InBlock.gif    
var elemID = "opt"+rowId;
InBlock.gif    
var element = document.getElementById(elemID);
InBlock.gif    
InBlock.gif    
var optInfo = WebUI.AjaxSearchSystem.AjaxSearchMethod.GetOpts(tableName.toString(),field.value).value;
InBlock.gif    
var optValue;
InBlock.gif    
var j,index;
InBlock.gif
InBlock.gif    
//先移除原有项
InBlock.gif
    while (element.options.length > 0
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{    
InBlock.gif        element.options.remove(element.options.length
-1);
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
for(j=0;j<optInfo.length;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        optValue 
= optInfo[j];
InBlock.gif        index 
= optValue.indexOf("|");
InBlock.gif        element.options[element.options.length] 
= new Option(optValue.substring(0,index),optValue.substring(index+1,optValue.length));
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
None.gif
// 设置值录入控件,取得可能存在的枚举值
None.gif

None.gif
function  getInput(row)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var rowId = row.id;
InBlock.gif    
InBlock.gif    
var fieldSelId = "field"+rowId;
InBlock.gif    
var field = document.getElementById(fieldSelId);
InBlock.gif    
InBlock.gif    
var inputId = "input"+rowId;
InBlock.gif    
var inputElement = document.getElementById(inputId);
InBlock.gif    
InBlock.gif    
if (inputElement != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        row.deleteCell(
2);
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
//获取可能存在的枚举值
InBlock.gif

InBlock.gif    
var enums = WebUI.AjaxSearchSystem.AjaxSearchMethod.GetEnums(tableName.toString(),field.value).value;
InBlock.gif    
var oCell;
InBlock.gif    
InBlock.gif    
if (enums.length <= 1)//不存在枚举值,使用text
ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
InBlock.gif        
var elementSyntax = "<INPUT ID='"+elemID+"' type='text' style='WIDTH: 144px'>";
InBlock.gif        oCell 
= row.insertCell(2);
InBlock.gif        
var elemID = "input"+rowId;
InBlock.gif        
InBlock.gif        
switch(enums[0])
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
case "int":
InBlock.gif                elementSyntax 
= "<INPUT ID='"+elemID+"' type='text' style='WIDTH: 144px' onKeyPress='javascript:return controlNumberKeyPress(this)' onKeyUp='return controlNumberOnKeyUp(this)' οnfοcus='this.select()' style='TEXT-ALIGN:right' οnpaste='return !clipboardData.getData(\"text\").match(/\D/);'>"
InBlock.gif                
break;
InBlock.gif            
case "decimal":
InBlock.gif                elementSyntax 
= "<INPUT ID='"+elemID+"' type='text' style='WIDTH: 144px' onKeyPress='javascript:return controlMoneyKeyPress(this)' onKeyUp='return controlMoneyOnKeyUp(this,10,4)' οnfοcus='this.select()' style='TEXT-ALIGN:right' οnpaste='return !clipboardData.getData(\"text\").match(/\D/);'>"
InBlock.gif                
break;
InBlock.gif            
case "datetime":
InBlock.gif                elementSyntax 
= "<INPUT ID='"+elemID+"' type='text' style='WIDTH: 144px' οnfοcus='setday(this)'οnkeypress='return false' onselectstart='return false;' readonly='true' οnpaste='return false;' >"
InBlock.gif                
break;
InBlock.gif            
default:
InBlock.gif                elementSyntax 
= "<INPUT ID='"+elemID+"' type='text' style='WIDTH: 144px'>"
InBlock.gif                
break;
ExpandedSubBlockEnd.gif        }

InBlock.gif                
InBlock.gif        
var oNewItem = document.createElement(elementSyntax);
InBlock.gif        oCell.insertBefore(oNewItem);
ExpandedSubBlockEnd.gif    }

InBlock.gif    
else //存在枚举值,使用select
ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
InBlock.gif        oCell 
= row.insertCell(2);
InBlock.gif        
var elemID = "input"+rowId;
InBlock.gif        
var oNewItem = document.createElement("<SELECT ID='"+elemID+"' style='WIDTH: 144px'></SELECT>");
InBlock.gif        oCell.insertBefore(oNewItem);
InBlock.gif        
InBlock.gif        
var enumValue;
InBlock.gif        
var j,index;
InBlock.gif        
var element = document.getElementById(elemID);
InBlock.gif        
InBlock.gif        
for(j=1;j<enums.length;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            enumValue 
= enums[j];
InBlock.gif            index 
= enumValue.indexOf("|");
InBlock.gif            element.options[element.options.length] 
= new Option(enumValue.substring(0,index),enumValue.substring(index+1,enumValue.length));
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
//用于值的数据类型
InBlock.gif
    var fieldType= document.createElement("<INPUT id='type"+rowId+"'type='hidden'>");
InBlock.gif    oCell.insertBefore(fieldType);
InBlock.gif    document.getElementById(
"type"+rowId).value = enums[0];
ExpandedBlockEnd.gif}

None.gif
None.gif
// 删除当前行
None.gif

None.gif
function  DelRow(row)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var rowOfIndex = row.rowIndex;
InBlock.gif    
InBlock.gif    
if(tbPanel.rows.length == 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
return
ExpandedSubBlockEnd.gif    }

InBlock.gif    
else if (rowOfIndex == tbPanel.rows.length-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
//删除最后一行时,保持增加按纽在最后一行
InBlock.gif

InBlock.gif        
var cell = tbPanel.rows[rowOfIndex-1].insertCell();
InBlock.gif        
var addBtnId = "add"+tbPanel.rows[rowOfIndex-1].id;
InBlock.gif        newElement 
= document.createElement("<INPUT ID='"+addBtnId+"' type='Button' class='redButtonCss' value='新增' οnclick='javascript:addRow("+tbPanel.rows[rowOfIndex-1].id+")'>");
InBlock.gif        cell.insertBefore(newElement);
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    tbPanel.deleteRow(rowOfIndex);
ExpandedBlockEnd.gif}

None.gif
None.gif
// 新增行
None.gif

None.gif
function  addRow(row)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    row.deleteCell(
5);
InBlock.gif    addTerm(tbPanel.id);
ExpandedBlockEnd.gif}

None.gif
None.gif
// 得到组合条件
None.gif
function  getCombinTerm()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var lenOfRows = tbPanel.rows.length;
InBlock.gif    
var i=0;
InBlock.gif    
var combinTerm = "";
InBlock.gif    
var field="",opt="",inputValue="",jointMode="",fieldType="";
InBlock.gif    
InBlock.gif    
for(i=0;i<lenOfRows;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        field        
= tbPanel.rows[i].cells[0].childNodes[0].value;
InBlock.gif        opt            
= tbPanel.rows[i].cells[1].childNodes[0].value;
InBlock.gif        inputValue    
= tbPanel.rows[i].cells[2].childNodes[0].value;
InBlock.gif        
InBlock.gif        
//判断字段类型
InBlock.gif
        fieldType =tbPanel.rows[i].cells[2].childNodes[1].value;
InBlock.gif        
switch(fieldType)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
case "char":
InBlock.gif                
if (inputValue == ""|| inputValue == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if(opt.toLowerCase() == "like" || opt.toLowerCase() == "not like")
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        inputValue 
= "'%%'";
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        inputValue 
= "''";
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if(opt.toLowerCase() == "like" || opt.toLowerCase() == "not like")
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        inputValue 
= "'%"+inputValue+"%'"
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        inputValue 
= "'"+inputValue+"'"
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
ExpandedSubBlockEnd.gif                }

InBlock.gif                
break;
InBlock.gif            
case "int":
InBlock.gif                
if (inputValue == ""|| inputValue == null) inputValue = 0;
InBlock.gif                
break;
InBlock.gif            
case "decimal":
InBlock.gif                
if (inputValue == ""|| inputValue == null) inputValue = 0;
InBlock.gif                
break;
InBlock.gif            
case "datetime":
InBlock.gif                
if (inputValue == ""|| inputValue == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    inputValue 
= "''";
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    inputValue 
= "'"+inputValue+"'"
ExpandedSubBlockEnd.gif                }

InBlock.gif                
break;
InBlock.gif            
default:
InBlock.gif                
break;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
//拼接条件
InBlock.gif
        combinTerm += " "+tableName+"."+field + " " + opt + " " + inputValue;
InBlock.gif        
InBlock.gif        
if (i<lenOfRows-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            jointMode    
= tbPanel.rows[i].cells[3].childNodes[0].value;
InBlock.gif            combinTerm 
+= " " + jointMode
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    document.getElementById(
"transValue").value = combinTerm;
InBlock.gif    
//return combinTerm;
ExpandedBlockEnd.gif
}

None.gif
None.gif
//
None.gif
var  oldValue  =   "" ;
None.gif
var  MONEY_FLAG  =   "" ;
None.gif
var  THOUSAND_FLAG  =   " , " ;
None.gif
None.gif
function  controlNumberKeyPress(textbox)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    oldValue 
= textbox.value.replace(MONEY_FLAG,'');
InBlock.gif    
InBlock.gif    
return /\d/.test(String.fromCharCode(event.keyCode))||(textbox.value.indexOf('+')<0?String.fromCharCode(event.keyCode)=="+":false);
ExpandedBlockEnd.gif}

None.gif
None.gif
//
None.gif
function  controlMoneyKeyPress(textbox)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var val = textbox.value.replace(MONEY_FLAG,'');
InBlock.gif
InBlock.gif    
if(isNumber(event.keyCode))
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
return true;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
if (textbox.value.indexOf('+') < 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if ( String.fromCharCode(event.keyCode)=="+" && val.length < 1)
InBlock.gif            
return true;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
if ( textbox.value.indexOf('.') < 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (String.fromCharCode(event.keyCode)==".")
InBlock.gif            
return true;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
return false;
ExpandedBlockEnd.gif}

None.gif
None.gif
// 控制金额录入keyUp事件
None.gif
function  controlNumberOnKeyUp(textbox)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
//处理"后退"键
InBlock.gif
    //alert(event.keyCode);
InBlock.gif
    if (event.keyCode == 8)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
return true;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
if (String.fromCharCode(event.keyCode) != '\t' && event.keyCode != 13)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if!/\d/.test(String.fromCharCode(event.keyCode)) &&
ExpandedSubBlockStart.gifContractedSubBlock.gif            event.keyCode 
!= 190/**//* 如果录入"."则不执行 */ )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//textbox.value = "";
InBlock.gif
            textbox.value = oldValue;
InBlock.gif            oldValue 
= textbox.value;
InBlock.gif            
return false;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
return true;
ExpandedBlockEnd.gif}

None.gif
None.gif
None.gif
None.gif
// 控制金额录入keyUp事件
None.gif
function  controlMoneyOnKeyUp(textbox, intBit , dotBit)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
//处理"后退"键
InBlock.gif

InBlock.gif    
if (event.keyCode == 8)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (textbox.value.indexOf(MONEY_FLAG) < 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            textbox.value 
= MONEY_FLAG + textbox.value;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
return true;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
if (String.fromCharCode(event.keyCode) != '\t' && event.keyCode != 13)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if! isNumber (event.keyCode) &&
ExpandedSubBlockStart.gifContractedSubBlock.gif            event.keyCode 
!= 190/**//* 如果录入"."则不执行 */ )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//textbox.value = "";
InBlock.gif
            textbox.value = MONEY_FLAG + oldValue;
InBlock.gif            oldValue 
= textbox.value.replace(MONEY_FLAG,"");
InBlock.gif            
return false;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        textbox.value 
= MONEY_FLAG + textbox.value.replace(MONEY_FLAG,'');
InBlock.gif
InBlock.gif        
var val = textbox.value;
InBlock.gif        
var dotBehind = "";
InBlock.gif
InBlock.gif        
InBlock.gif        val 
= val.replace(MONEY_FLAG,'').replace(/\,/g,'');
InBlock.gif        
var iIndex = val.indexOf('.');
InBlock.gif        
if (iIndex > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
var valDot = val.substring(val.indexOf('.') + 1,val.length);
InBlock.gif            
if (iIndex > intBit)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                val 
= val.substring(0,intBit);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif            
if (valDot.length > dotBit)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                textbox.value 
= addThousandFlag(val.substring(0,val.indexOf('.'))) + '.' + valDot.substring(0,dotBit);
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            dotBehind 
= val.substring(val.indexOf('.'),val.length);
InBlock.gif            val 
= val.substring(0,val.indexOf('.'));
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else if (val.length >= intBit)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (val.length > intBit)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                val 
= val.substring(0,intBit);
InBlock.gif                val 
= addThousandFlag(val);
ExpandedSubBlockEnd.gif            }

InBlock.gif            textbox.value 
= val + '.';
InBlock.gif            
return;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//val = noOtherInfoNumber;
InBlock.gif
        textbox.value = addThousandFlag(val) + dotBehind;
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
None.gif
None.gif
// 添加千分位号
None.gif
function  addThousandFlag(val)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var strTemp = MONEY_FLAG;
InBlock.gif    
if (val.length < 4)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
return MONEY_FLAG + val;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
var flag = false;
InBlock.gif    
if (val.length % 3 != 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        strTemp 
+= val.substring(0,(val.length % 3));
ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
InBlock.gif        flag 
= true;
InBlock.gif
InBlock.gif    
for(var i = val.length; i > 0; i = i - 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (i % 3 != 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
continue;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
if (flag)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            strTemp 
+= val.substring(val.length - i,val.length - i + 3);
InBlock.gif            flag 
= false;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            strTemp 
+= THOUSAND_FLAG + val.substring(val.length - i,val.length - i + 3);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
if (strTemp.indexOf(MONEY_FLAG) > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        strTemp 
= MONEY_FLAG + strTemp.replace(//g,'');
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
return strTemp;
ExpandedBlockEnd.gif}

None.gif
None.gif
// 判断是否是数字
None.gif

None.gif
function  isNumber(param)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
return /\d/.test(String.fromCharCode(param)) ||  (param >= 96 && param <= 105);//加上小键盘处理
InBlock.gif

ExpandedBlockEnd.gif}
4.AjaxSeachPage.aspx
ExpandedBlockStart.gif ContractedBlock.gif <% dot.gif @ Page language="c#" Codebehind="AjaxSeachPage.aspx.cs" AutoEventWireup="false" Inherits="WebUI.AjaxSearchSystem.AjaxSeachPage"  %>
None.gif
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"  >
None.gif
< HTML >
None.gif    
< HEAD >
None.gif        
< title > 查询条件 </ title >
None.gif        
< meta  content ="Microsoft Visual Studio .NET 7.1"  name ="GENERATOR" >
None.gif        
< meta  content ="C#"  name ="CODE_LANGUAGE" >
None.gif        
< meta  content ="JavaScript"  name ="vs_defaultClientScript" >
None.gif        
< meta  content ="http://schemas.microsoft.com/intellisense/ie5"  name ="vs_targetSchema" >
None.gif        
< base  target ="_self" >
None.gif        
< LINK  href ="BasicStyle.css"  type ="text/css"  rel ="stylesheet" >
ExpandedBlockStart.gifContractedBlock.gif        
< script  language ="javascript"  src ="AjaxSearchClientScript.js" > dot.gif
ExpandedBlockEnd.gif        
</ script >
None.gif        
< script  language ="javascript"  src ="Calendar.js" ></ script >
None.gif    
</ HEAD >
None.gif    
< body  onload ="javascript:addTerm('tbPanel');"  MS_POSITIONING ="GridLayout" >
None.gif        
< form  id ="Form1"  method ="post"  runat ="server" >
None.gif            
< TABLE  id ="Table1"  style ="Z-INDEX: 101; LEFT: 0px; POSITION: absolute; TOP: 0px"  cellSpacing ="0"
None.gif                cellPadding
="0"  width ="100%"  border ="0" >
None.gif                
< TR >
None.gif                    
< TD  style ="HEIGHT: 23px"  align ="center" >< asp:button  id ="btnOK"  runat ="server"  CssClass ="redButtonCss"  Text ="确定" ></ asp:button >< INPUT  class ="redButtonCss"  type ="button"  value ="取消"  onclick ="javascript:window.close();" >
None.gif                    
</ TD >
None.gif                
</ TR >
None.gif                
< TR >
None.gif                    
< TD  align ="center" >
None.gif                        
< TABLE  id ="tbPanel"  cellSpacing ="0"  borderColorDark ="aliceblue"  cellPadding ="0"  border ="1" >
None.gif                        
</ TABLE >
None.gif                    
</ TD >
None.gif                
</ TR >
None.gif                
< TR >
None.gif                    
< TD  align ="center" ></ TD >
None.gif                
</ TR >
None.gif            
</ TABLE >
None.gif            
< INPUT  id ="transValue"  style ="Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 64px"  type ="hidden"
None.gif                name
="Hidden1"  runat ="server" >
None.gif        
</ form >
None.gif    
</ body >
None.gif
</ HTML >
None.gif

AjaxSeachPage.aspx.cs
None.gif using System;
None.gifusing System.Collections;
None.gifusing System.ComponentModel;
None.gifusing System.Data;
None.gifusing System.Drawing;
None.gifusing System.Web;
None.gifusing System.Web.SessionState;
None.gifusing System.Web.UI;
None.gifusing System.Web.UI.WebControls;
None.gifusing System.Web.UI.HtmlControls;
None.gifusing System.Text;
None.gif
None.gifnamespace WebUI.AjaxSearchSystem
None.gif{
None.gif    /// 
< summary >
None.gif    /// AjaxSeachPage 的摘要说明。
None.gif    /// 
</ summary >
None.gif    public class AjaxSeachPage : System.Web.UI.Page
None.gif    {
None.gif        protected System.Web.UI.HtmlControls.HtmlInputHidden transValue;
None.gif        protected System.Web.UI.WebControls.Button btnOK;
None.gif        public const string SEARCH_WHERE_SESSION = "SearchWhere";
None.gif    
None.gif        private void Page_Load(object sender, System.EventArgs e)
None.gif        {
None.gif            if (!IsPostBack)
None.gif            {
None.gif                try
None.gif                {
None.gif                    //tableName.Value = Request.QueryString["table"].Trim();
None.gif                    transValue.Value = "employee";
None.gif                }
None.gif                catch(NullReferenceException ee)
None.gif                {
None.gif                    throw new ArgumentOutOfRangeException("table","参数不正确,请传入预先定义的表名");
None.gif                }
None.gif            
None.gif
None.gif                AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxSearchMethod));
None.gif            
None.gif                this.btnOK.Attributes.Add("OnClick","getCombinTerm()");
None.gif            }
None.gif        }
None.gif
None.gif        #region Web 窗体设计器生成的代码
None.gif        override protected void OnInit(EventArgs e)
None.gif        {
None.gif            //
None.gif            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
None.gif            //
None.gif            InitializeComponent();
None.gif            base.OnInit(e);
None.gif        }
None.gif        
None.gif        /// 
< summary >
None.gif        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
None.gif        /// 此方法的内容。
None.gif        /// 
</ summary >
None.gif        private void InitializeComponent()
None.gif        {    
None.gif            this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
None.gif            this.Load += new System.EventHandler(this.Page_Load);
None.gif
None.gif        }
None.gif        #endregion
None.gif
None.gif        private void btnOK_Click(object sender, System.EventArgs e)
None.gif        {
None.gif            Session[SEARCH_WHERE_SESSION] = transValue.Value.Trim();
None.gif
None.gif            Response.Write(ClosePage());
None.gif        }
None.gif
None.gif        private string ClosePage()
None.gif        {
None.gif            StringBuilder js = new StringBuilder();
ExpandedBlockStart.gifContractedBlock.gif            js.Append("
< script  language =\"JavaScript\" > dot.gif ");
InBlock.gif            js.Append(
"window.close();");
ExpandedBlockEnd.gif            js.Append(
"
</ script > ");
None.gif            return js.ToString();
None.gif        }
None.gif    }
None.gif}
None.gif

运行效果:
ajaxsearch.jpg
下载源码 AjaxGeneralSearch.rar
请大家提出宝贵意见,在此感谢我的同事 命运有自己的梦!提供的帮助!感谢日历控件提供者meizz

转载于:https://www.cnblogs.com/Hedonister/archive/2005/10/19/258228.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值