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

简单介绍:
1.完全无刷实现,客户端主要实现生成条件选择或录入控件,并进行录入控制;

2.将字段信息存放于XML文件,便于数据移植

3.通过js脚本,ajax框架引擎获取字段信息

4.通过js脚本生成组合条件;
 
5.运行效果:

下面是代码和实现效果:
1.AjaxSeachMethod.cs

using System;
using System.Xml;
using System.Data;
using System.Data.SqlClient;

namespace WebUI.AjaxSearchSystem
{
    
/// <summary>
    
/// SearchMethod 的摘要说明。
    
/// </summary>

    public class AjaxSearchMethod
    
{
        
private string[] CHAR_OP    = new string[]{"等于|=","不等于|<>","相似于|Like","不相似于|Not Like"};
        
private string[] NUM_OP        = new string[]{"大于|>","大于或等于|>=","等于|=","不等于|<>","小于|<","小于或等于|<="};    
        
private string[] DATE_OP    = new string[]{"等于|=","不等于|<>","先于|<","后于|>"};    

        
public AjaxSearchMethod()
        
{}

        
/// <summary>
        
/// 根据表名获取包含的字段
        
/// </summary>
        
/// <param name="table">表名</param>
        
/// <returns></returns>

        [AjaxPro.AjaxMethod]
        
public string[] GetFields(string table)
        
{
            
string[] strArrFields = null;

            
try
            
{
                XmlDocument xd 
= LoadXml(@"\AjaxSearchDataCollection.xml");
                XmlElement    xe  
=xd.DocumentElement;
                XmlNode        xn 
= xe.SelectSingleNode("descendant::Table[@value='"+table+"']");
                XmlNodeList xnl 
= xn.ChildNodes;
                
int iLen = xnl.Count;
                strArrFields 
= new string[iLen];

                
int iIndex = 0;

                
foreach(XmlNode xnField in xnl)
                
{
                    strArrFields[iIndex] 
= xnField.Attributes["Name"].InnerText + "|" + xnField.Attributes["Value"].InnerText;
                    iIndex 
++;
                }

            }

            
catch(Exception ee)
            
{
                
throw new ArgumentOutOfRangeException(@"AjaxSearchDataCollection.xml","/Table[@value='"+table+"']:指定的接点不存在,请重新定义XML文档!");
            }

            
return strArrFields;
        }


        
/// <summary>
        
/// 根据字段获取对应的操作符列表
        
/// </summary>
        
/// <param name="field"></param>
        
/// <returns></returns>

        [AjaxPro.AjaxMethod]
        
public string[] GetOpts(string table,string field)
        
{
            
string strTypeofField = GetTypeofField(table,field);

            
switch(strTypeofField)
            
{
                
case "char":
                    
return CHAR_OP;
                    
break;
                
case "int":
                    
if(GetEnumField(table,field)==null)
                    
{
                        
return NUM_OP;
                    }

                    
else
                    
{
                        
return (new string[]{"是|=","不是|<>"});
                    }

                    
                    
break;
                
case "decimal":
                    
return NUM_OP;
                    
break;
                
case "datetime":
                    
return DATE_OP;
                    
break;
                
default:
                    
return (new string[]{"等于|="});
                    
break;
            }

        }


        
/// <summary>
        
/// 根据字段获取对应的可能存在的枚举值列表
        
/// </summary>
        
/// <param name="field"></param>
        
/// <returns></returns>

        [AjaxPro.AjaxMethod]
        
public string[] GetEnums(string table,string field)
        
{
            
string strTypeofField = GetTypeofField(table,field);
            
string[] enums = GetEnumField(table,field);

            
int iLen = enums==null?0:enums.Length;

            
string[] result = new string[iLen+1];

            result[
0= strTypeofField;

            
if (iLen == 0)
            
{
                
return result;
            }


            
int iIndex = 1;

            
foreach(string str in enums)
            
{
                result[iIndex] 
= str;
                iIndex 
++;
            }


            
return result;

        }


        
内部支持脚本
    }

}

2.AjaxSearchDataCollection.xml 

<?xml version="1.0" encoding="utf-8" ?>
<Fields>
    
<Table Name="产品表" value="employee">
        
<Field Name="雇佣号" Value="emp_id" DataType="char">
        
</Field>
        
<Field Name="名字" Value="fname" DataType="char">
            
<Enum SqlSyntax="" TextField="" ValueField=""></Enum>
        
</Field>
        
<Field Name="工作号" Value="job_id" DataType="int">
            
<Enum SqlSyntax="SELECT job_id,job_desc FROM jobs" TextField="job_desc" ValueField="job_id"></Enum>
        
</Field>
        
<Field Name="工作**" Value="job_lvl" DataType="int">
        
</Field>
        
<Field Name="雇佣日期" Value="hire_date" DataType="datetime">
        
</Field>
    
</Table>
</Fields>

继续阅读
posted @ 2005-10-19 22:45  冰戈  阅读(3381)  评论(1编辑  收藏  举报