此頁沒有內(nèi)容條目
內(nèi)容

地址簿應(yīng)用程序源代碼

下列代碼是地址簿范例應(yīng)用程序的完整源代碼。

<HTML>

<HEAD>

<TITLE>Corporate Address Book</TITLE>

</HEAD>

<!--

   目的:   為 Web 用戶提供公司目錄搜索服務(wù)。

   編寫者:   Microsoft Remote Data Service 工作組,Microsoft Corp.。

   日期:   1997 年 4 月

-->

<BODY BACKGROUND="Arcadia.gif" LANGUAGE="VBScript" onload="Load">

<tr>

   <td align="center" width="40%">

      <table border="2" cellpadding="7" cellspacing="7">

         <tr>

            <td width="100%"><font color="#160B5A"><font

            size="4"><strong>Arcadia Bay Corporate Phone

            Directory</strong></font></font></td>

         </tr>

      </table>

      </td>

</tr>

<hr>

<h2><font color = "#160B5A">Search Parameters</h2>

<h5><font color = "#160B5A">Please enter one or more search patterns and press FIND to search.</h5>

<FONT COLOR = "#160B5A"><B>

<PRE> First Name   <INPUT NAME=SFirst SIZE=30> </PRE>

<PRE> Last Name  <INPUT NAME=SLast  SIZE=30> </PRE>

<PRE> Title    <INPUT NAME=STitle SIZE=30> </PRE>

<PRE> E-mail Alias <INPUT NAME=SEmail SIZE=30> </PRE>

<!--

   “命令”按鈕選項(xiàng):

   -----------------------

   查找      將搜索請(qǐng)求提交給數(shù)據(jù)庫。

   清除      清除 QBE 字段(僅為任務(wù)保存功能)。

   更新配置文件   發(fā)送已更新的“地址配置文件”回?cái)?shù)據(jù)庫。

   取消更改   取消自從上次“更新配置文件”以來的所有更改。

-->

<INPUT TYPE=BUTTON NAME="Find"    VALUE="Find">

<INPUT TYPE=BUTTON NAME="Clear"    VALUE="Clear">

<INPUT TYPE=BUTTON NAME="Update"    VALUE="Update Profile">

<INPUT TYPE=BUTTON NAME="Cancel"    VALUE="Cancel Changes">

<hr>

<h2><font color = "#400040">Search Results</h2>

</B>

<br>

<!--

   This Sheridan DataGrid control (SGrid) is initialized to

   allow changes to the data - these changes will be saved

   to the database when the Update Profile button is pressed.

-->

<Object CLASSID="clsid:AC05DC80-7DF1-11d0-839E-00A024A94B3A"

   CODEBASE="http://<%=Request.ServerVariables("SERVER_NAME")%>/MSADC/Samples/ssdatb32.cab"

   ID=GRID1

    datasrc=#SControl

    HEIGHT=125

    WIDTH=495>

   <PARAM NAME="AllowAddNew" VALUE="TRUE">

   <PARAM NAME="AllowDelete" VALUE="TRUE">

   <PARAM NAME="AllowUpdate" VALUE="TRUE">

   <PARAM NAME="BackColor"   VALUE="-2147483643">

   <PARAM NAME="BackColorOdd"  VALUE="-2147483643">

   <PARAM NAME="ForeColorEven" VALUE="0">

</OBJECT>

<br>

<br>

<INPUT TYPE=BUTTON NAME="First"    VALUE="First">

<INPUT TYPE=BUTTON NAME="Prev"    VALUE="Previous">

<INPUT TYPE=BUTTON NAME="Next"   VALUE="Next">

<INPUT TYPE=BUTTON NAME="Last"   VALUE="Last">

<hr>

<!-- Non-visual controls - RDS.DataControl -->

<OBJECT classid="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33"

   ID=SControl

   WIDTH=1 HEIGHT=1>

   <PARAM NAME="SERVER" VALUE="http://<%=Request.ServerVariables("SERVER_NAME")%>">

   <PARAM NAME="CONNECT" VALUE="dsn=ADCDemo;UID=ADCDemo;PWD=ADCDemo;">

</OBJECT>

<!-- VBS 腳本:撰寫查詢,更新配置文件,并檢索搜索結(jié)果。 -->

<SCRIPT LANGUAGE="VBScript">

Dim myQuery

Sub Load

   Grid1.CAPTION = "Arcadia Bay Corporate Phone Directory"

   ' 僅使用列名稱初始化數(shù)據(jù)網(wǎng)格。

   SControl.SQL = "Select FirstName, LastName, Title, Email, Building, Room, Phone from Employee where 2 < 1"

   SControl.Refresh

End Sub

' 執(zhí)行“清除”按鈕 – 清除所有 QBE 字段以準(zhǔn)備新的 “查找”。

Sub Clear_OnClick

   SFirst.Value=""

   SLast.Value=""

   STitle.Value=""

   SEmail.Value=""

End Sub

' 執(zhí)行“查找”按鈕 – 撰寫由數(shù)據(jù)庫處理的動(dòng)態(tài) SQL 查詢,并返回將要綁定到 Sgrid 對(duì)象的匹配記錄。

Sub Find_OnClick

   myQuery = "Select FirstName, LastName, Title, Type, Email, ManagerEmail, Building, Room, Phone from Employee"

   ' 檢查 QBE 字段并撰寫動(dòng)態(tài)的 SQL 查詢。

   IF (SFirst.Value <> "") THEN

      myQuery = myQuery + " where FirstName like '" + SFirst.Value + "%'"

   End IF

   IF (SLast.Value <> "") THEN

      myQuery = myQuery + " where LastName like '" + SLast.Value + "%'"

   End IF

   IF (STitle.Value <> "") THEN

      myQuery = myQuery + " where Title like '" + STitle.Value + "%'"

   End IF

   IF (SEmail.Value <> "") THEN

      myQuery = myQuery + " where Email like '" + SEmail.Value + "%'"

   End IF

   ' 設(shè)置新查詢?nèi)缓笏⑿?SControl 以便顯示新結(jié)果。

   SControl.SQL = myQuery

   SControl.Refresh

End Sub

' 定位子程序 – 基于 RDS.DataControl (SControl) 的貨幣變更。

' 在綁定的記錄集中移動(dòng)到第一個(gè)記錄。

Sub First_OnClick

     SControl.Recordset.MoveFirst

End Sub

' 在綁定的記錄集中從當(dāng)前位置移動(dòng)到下一個(gè)記錄。Sub Next_OnClick

   If SControl.Recordset.EOF Then   ' 移動(dòng)無法超出末端記錄

      SControl.Recordset.MoveFirst

      SControl.Recordset.MoveNext

      Exit Sub

   End If

   SControl.Recordset.MoveNext

End Sub

' 在綁定的記錄集中從當(dāng)前位置移動(dòng)到上一個(gè)記錄.

Sub Prev_OnClick

If SControl.Recordset.BOF Then   ' 移動(dòng)無法超出頂端記錄

      SControl.Recordset.MoveLast   ' 移出 BOF 緩沖區(qū)

      SControl.Recordset.MovePrevious

      Exit Sub

   End If

   SControl.Recordset.MovePrevious

End Sub

' 在綁定的記錄集中移動(dòng)到最后一個(gè)記錄。

Sub Last_OnClick

     SControl.Recordset.MoveLast

End Sub

' 提交所做編輯并獲取新數(shù)據(jù)的干凈拷貝。

Sub Update_OnClick

     SControl.SubmitChanges

   SControl.Refresh    ' SubmitChanges 之后的 ADC 1.5 不要求刷新,但它保證刷新的數(shù)據(jù)。

End Sub

' 取消編輯并恢復(fù)初始值。

Sub Cancel_OnClick

     SControl.CancelUpdate

End Sub

</SCRIPT>

<BR>

<font color = "#400040">This site powered by Microsoft Remote Data Service. </font>

</BODY>

</HTML>