地址簿应用程序源代码

下列代码是地址簿范例应用程序的完整源代码。

<HTML>
<HEAD>
<TITLE>Corporate Address Book</TITLE>
</HEAD>

<!--
   目的:   为 Web 用户提供公司目录搜索服务。
   编写者:   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>

<!-- 
   “命令”按钮选项:
   -----------------------
   查找      将搜索请求提交给数据库。
   清除      清除 QBE 字段(仅为任务保存功能)。
   更新配置文件   发送已更新的“地址配置文件”回数据库。
   取消更改   取消自从上次“更新配置文件”以来的所有更改。
-->

<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 脚本:撰写查询,更新配置文件,并检索搜索结果。 -->

<SCRIPT LANGUAGE="VBScript">

Dim myQuery

Sub Load
   Grid1.CAPTION = "Arcadia Bay Corporate Phone Directory"

   ' 仅使用列名称初始化数据网格。
   SControl.SQL = "Select FirstName, LastName, Title, Email, Building, Room, Phone from Employee where 2 < 1"
   SControl.Refresh

End Sub

' 执行“清除”按钮 – 清除所有 QBE 字段以准备新的 “查找”。

Sub Clear_OnClick
   SFirst.Value=""
   SLast.Value=""
   STitle.Value=""
   SEmail.Value=""
End Sub


' 执行“查找”按钮 – 撰写由数据库处理的动态 SQL 查询,并返回将要绑定到 Sgrid 对象的匹配记录。

Sub Find_OnClick

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

   ' 检查 QBE 字段并撰写动态的 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

   ' 设置新查询然后刷新 SControl 以便显示新结果。

   SControl.SQL = myQuery
   SControl.Refresh
   
End Sub

' 定位子程序 – 基于 RDS.DataControl (SControl) 的货币变更。
' 在绑定的记录集中移动到第一个记录。

Sub First_OnClick
     SControl.Recordset.MoveFirst
End Sub

' 在绑定的记录集中从当前位置移动到下一个记录。Sub Next_OnClick
   If SControl.Recordset.EOF Then   ' 移动无法超出末端记录
      SControl.Recordset.MoveFirst 
      SControl.Recordset.MoveNext
      Exit Sub
   End If   

   SControl.Recordset.MoveNext

End Sub

' 在绑定的记录集中从当前位置移动到上一个记录.

Sub Prev_OnClick
If SControl.Recordset.BOF Then   ' 移动无法超出顶端记录
      SControl.Recordset.MoveLast   ' 移出 BOF 缓冲区
      SControl.Recordset.MovePrevious
      Exit Sub
   End If
   SControl.Recordset.MovePrevious
End Sub

' 在绑定的记录集中移动到最后一个记录。

Sub Last_OnClick
     SControl.Recordset.MoveLast
End Sub

' 提交所做编辑并获取新数据的干净拷贝。

Sub Update_OnClick
     SControl.SubmitChanges
   SControl.Refresh    ' SubmitChanges 之后的 ADC 1.5 不要求刷新,但它保证刷新的数据。
End Sub

' 取消编辑并恢复初始值。

Sub Cancel_OnClick
     SControl.CancelUpdate
End Sub

</SCRIPT>

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