Tutorials to .com

Tutorials to .com » Asp » Encoding » ASP in the general conditions of the project Query Module

ASP in the general conditions of the project Query Module

Print View , by: iSee ,Total views: 3 ,Word Count: 2240 ,Date: Wed, 3 Jun 2009 Time: 2:25 AM

First, ask questions:
asp in the large-scale projects, all inquiries related to the conditions of this feature. User requirements can be field-specific query. For some data is removed from the multiple tables, and therefore should be able to query multiple tables.
In general, the majority of the practice is done for each process a query function, because each query table is different, involving different fields. However, if the ASP in the large-scale projects to do so, not only increased the workload, the impact of the development progress, and can not make the system modular, reusable code, an increase of the difficulty of system maintenance. Therefore, we need to make inquiries modular conditions.

Second, to address the ideas:
We designed the function of the conditions of inquiry are:
1, select the query fields (field);
2, select the query (<,>,=,<=,>=,<>, Null, Not Null, Like);
3, the value of input conditions;
4, the relationship between choice of operator (Or, And);
5, the query is added to the list box, or delete from the list box.
The chart below details of the interface see:


We have information table (dbNews) as an example, assuming that the news sheet contains the title, time, content, publisher.
Query the database, we are generally used such as:
"Select * from News Where time ='2002-05-22 'and User =' Tom '", if we are able to return to the query terms "time ='2002-05-22' and User = 'Tom'" conditions string, the problem is resolved. However, if the procedures are different, how different tables do? This is to see in what ways is the definition of query fields.
Here, we query the process of writing as a field in the proceedings, call in the query module, so that the query field is generated dynamically.
The user to choose a good query field, as well as the matching condition, add it to <select> </ select> box, the user can continue to select additional query and then add it to <select>, the complete button on the point of inquiry. Module generated by inquiries such as: "time ='2002-05-22 'and User =' Tom '" the statement, this program can be deployed.

Three solutions:
ASP Query Module General conditions please refer to the source code (d, source code).
1, the definition of the process of
For inquiries, call the conditions in the former module, first of all to define a process SearchField () process:
Sub SearchField ()
Response.Write "<option Value='1Title'> title </ option>"
Response.Write "<option Value='1Time'> time </ option>"
Response.Write "<option Value='1Content'> content </ option>"
Response.Write "<option Value='1User'> publisher </ option>"
End Sub
One, Value for the field name, if the field is character, the former in the field plus 1, to increase the number of type 2. Such as: "1Title".
Note: If data is out of multiple tables, such as: select * from News, User; it is necessary to add value Value of the table, such as: 1News.Title. This will query data from multiple tables.

2, call query conditions:
<!--# include file ="../ Public / Condition_Search.asp "->

3, by adding the button event:
Adding "conditions for query" button, and add the onClick = "search_dis (s1)" event:
<Input Type="Button" name=ConSearch onClick="search_dis(s1)">

By default, the conditions hidden in the page query module, when point "query terms" button on the display, so the page that is beautiful, it would not impede the user's browser.

In this way, we completed the "conditions for" the call module
When selecting a query, execute the query, the program will return to getSql text box query, such as: "title = 'Chian' and user = 'tom'", using request.form ( "getSql") made! Put it in the SQL statement into a new query on the generated.

IV, ASP General Conditions Query Module source code

<Script LANGUAGE=javaScript>
<! --
/ / Hide or show the conditions of Query Module
function search_dis (ob) (
if (ob.style.display == "none")
(ob.style.display = ""; window.location.href ( '# down');)
else
(ob.style.display = "none";)
)

/ / Query the conditions added to the list box query <select>;
function AddSe () (
var val, val_tmp, Sql, oAdd, TextType;
var Field, Condition, TextVal, Relation;
Field = frm_Search.Field.options [frm_Search.Field.selectedIndex]. Text;
TextVal ="'"+ frm_Search.TextVal.value + " '";
Condition = frm_Search.Condition.options [frm_Search.Condition.selectedIndex]. Text;
Relation = frm_Search.Relation.options [frm_Search.Relation.selectedIndex]. Text;
val_tmp = frm_Search.Field.value;
val_tmp = val_tmp.substring (0,1);
/ / Determine the field's data type, if 1 is character, date, type; for 2, that is, value-based;
if (val_tmp == 1)
(TextType ="'"+ frm_Search.TextVal.value + " '";)
else
(TextType = "" + frm_Search.TextVal.value + "";)
val_Field = frm_Search.Field.value;
val_Field = val_Field.substr (1);
val = val_Field + frm_Search.Condition.value + TextType + frm_Search.Relation.value;
Sql = Field + Condition + TextVal + Relation;
oAdd = document.createElement ( "option")
oAdd.value = val;
oAdd.text = Sql;
frm_Search.seSql.add (oAdd);
)

/ / Query to the conditions of the list from the query box <select> deleted;
function moveSe () (
for (i = 1; i <frm_Search.seSql.options.length; i + +) (
if (frm_Search.seSql.options [i]. selected) (
frm_Search.seSql.remove (frm_Search.seSql.selectedIndex);
)
)
)

/ / access to query and submit it;
function getVal () (
var gettxt, Setable;
gettxt = "";
var path = window.location.pathname; / / get the page links and file name
var line = path.lastIndexOf ("/"); / / get the last one '/' location
var dot = path.indexOf ("."); / / get the first '.' position
var Name = path.substring (line +1, dot); / / get file name
var fileName = Name + ". asp";
for (i = 1; i <frm_Search.seSql.options.length; i + +) (
gettxt = gettxt + "" + frm_Search.seSql.options [i]. value;)
var valLeng = gettxt.lastIndexOf ( "");
gettxt = gettxt.substr (0, valLeng); / / to remove the conditions of the last clause of the relational operators
Setable = frm_Search.Setable.value;
/ / window.open (fileName + '? gettxt =' + gettxt, '_self'); / / to send the current page query clause
frm_Search.getSql.value = gettxt;
frm_Search.action = fileName;
frm_Search.submit ();
)
//-->
</ Script>
<a Name="down"> </ a>
<Form Name="frm_Search" method="post" action="">
<input type="hidden" Name=getSql Value="">
<table bgcolor=#6699CC width=100%>
<tr> <td>
<table width = "617" border = "0" cellspacing = "1" cellpAdding = "2" bgcolor = "# CCCCCC"

align = "center">
<tbody id=s1 style=display:none>
<tr>
<td width="134" height="25" bgcolor="#006699">
<div align="right"> <font color="#FFFFFF" style="font-size:10pt"> query field:

</ font> </ div>
</ td>
<td width="159" bgcolor="#F2F2F2">
<select Name="Field" style="font-size:12px"> <% Call SearchField ()%></ select>
</ td>
<td width="102" bgcolor="#E1E1E1">
<div align="center">
<input type="button" Name="AddSql" Value=">>> "onClick =" AddSe () "

style = "BACKGROUND: # ffdead; BORDER-BOTTOM: # 665b8e 1px solid; BORDER-LEFT: # ffffff 1px

solid; BORDER-RIGHT: # 665b8e 1px solid; BORDER-TOP: # ffffff 1px solid; COLOR: # 333333; CURSOR:

hand; FONT-SIZE: 12px; HEIGHT: 20px; PAddING-BOTTOM: 1px; PAddING-LEFT: 1px; PAddING-RIGHT:

1px; PAddING-TOP: 1px ">
</ div>
</ td>
<td rowspan="4" bgcolor="#F2F2F2" width="221">
<select id="seSql" size="6">
<option Value=""> ------------ query -----------</ option>
</ select>
</ td>
</ tr>
<tr>
<td width="134" height="25" bgcolor="#006699">
<div align="right"> <font color="#FFFFFF" style="font-size:10pt"> query:

</ font> </ div>
</ td>
<td width="159" bgcolor="#F2F2F2">
<select Name="Condition" style="font-size:12px">
<option Value="="> equal </ option>
<option Value="> "> greater than </ option>
<option Value="> = "> greater than or equal to </ option>
<option Value ="<"> less than </ option>
<option Value ="<="> less than or equal to </ option>
<option Value ="<>"> does not mean </ option>
<option Value=" NULL "> empty </ option>
<option Value=" NOT NULL "> not empty </ option>
<option Value=" LIKE "> match </ option>
</ select>
</ td>
<td width="102" bgcolor="#E1E1E1">
<div align="center">
<input type = "button" Name = "delSql" Value ="<<< delete "onClick =" moveSe () "

style = "BACKGROUND: # ffdead; BORDER-BOTTOM: # 665b8e 1px solid; BORDER-LEFT: # ffffff 1px

solid; BORDER-RIGHT: # 665b8e 1px solid; BORDER-TOP: # ffffff 1px solid; COLOR: # 333333; CURSOR:

hand; FONT-SIZE: 12px; HEIGHT: 20px; PAddING-BOTTOM: 1px; PAddING-LEFT: 1px; PAddING-RIGHT:

1px; PAddING-TOP: 1px ">
</ div>
</ td>
</ tr>
<tr>
<td width="134" height="25" bgcolor="#006699">
<div align="right"> <font color="#FFFFFF" style="font-size:10pt"> value conditions:

</ font> </ div>
</ td>
<td width="159" bgcolor="#F2F2F2">
<input type = "text" id = "TextVal" size = "15" style = "BACKGROUND-COLOR: white; BORDER -

BOTTOM: # 000000 1px solid; BORDER-LEFT: # 000000 1px solid; BORDER-RIGHT: # 000000 1px solid; BORDER -

TOP: # 000000 1px solid; FONT-SIZE: 9pt ">
</ td>
<td width="102" bgcolor="#E1E1E1"> </ td>
</ tr>
<tr>
<td width="134" height="25" bgcolor="#006699">
<div align="right"> <font color="#FFFFFF" style="font-size:10pt"> relational operators:

</ font> </ div>
</ td>
<td width="159" bgcolor="#F2F2F2">
<select Name="Relation" style="font-size:12px">
<option Value="and"> and </ option>
<option Value="or"> or </ option>
</ select>
</ td>
<td width="102" bgcolor="#E1E1E1">
<div align="center">
<input type = "button" Name = "search_ok" Value = "query" onClick = "getVal ()"

style = "BACKGROUND: # deb887; BORDER-BOTTOM: # 665b8e 1px solid; BORDER-LEFT: # ffffff 1px

solid; BORDER-RIGHT: # 665b8e 1px solid; BORDER-TOP: # ffffff 1px solid; COLOR: # 333333; CURSOR:

hand; FONT-SIZE: 12px; HEIGHT: 20px; PAddING-BOTTOM: 1px; PAddING-LEFT: 1px; PAddING-RIGHT:

1px; PAddING-TOP: 1px ">
</ div>
</ td>
</ tr>
</ tbody>
</ table>
</ td> </ tr>
</ table>
</ Form>


Asp Script encoding Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.