【第0107期2006/12/10】

本週主題

最新消息

 
  • 「IBM Sametime 7.5相關訊息」

CPRO 資傳網---IBM推Lotus Sametime 7.5新企業平台:
http://cpro.com.tw/channel/news/content/index.php?news_id=52502

IBM 軟體- Lotus 軟體- IBM Lotus Sametime 7.5 - Taiwan:
http://www-8.ibm.com/software/tw/lotus/product/sametime75/

iThome---IBM Lotus Sametime首度與公用IM互通:
http://www.ithome.com.tw/itadm/article.php?c=40277


Sametime 7.5產品展示中心:
http://www-8.ibm.com/software/tw/demo/lotus/sametime75_play.html

IBM Demo: Lotus Sametime 7.5: Recorded Demo:
http://demos.dfw.ibm.com/on_demand/Demo/IBM_Demo_Lotus_Sametime_7_5-Aug06.html

為 IBM Lotus Sametime Connect V7.5 設計 Google Maps 插件:
http://www-128.ibm.com/developerworks/cn/lotus/sametime-googlemaps/index.html

擴展 IBM Lotus Sametime Connect V7.5:
http://www-128.ibm.com/developerworks/cn/lotus/sametime-sdk/


IBM Lotus Sametime 7.5 Beta 4 Demonstration Site:

https://stdemo75.dfw.ibm.com/

Register to use this IBM DEMOnet system:
http://stdemo75.dfw.ibm.com/streg.nsf/newacc?openform

Enter the Sametime 7.5 demonstration site:
https://stdemo75.dfw.ibm.com/stcenter.nsf

Top

文章分享

 

在 Microsoft .NET 應用程式中使用 IBM Lotus Domino

 

原文網址: http://www-128.ibm.com/developerworks/cn/lotus/domino-msnet/

 

 

級別: 進階

Tony Patton (aspatton@bellsouth.net), 顧問

2006 10 10  

IBM Lotus Domino Microsoft 工具包按照允許兩個系統互相操作的標準構建。本文講解了用於整合 Lotus Domino Microsoft .NET 的技術和方法,包括元件物件模型(Component Object ModelCOM)和 Lotus Domino 物件、Web Service XML

每個開發人員都知道,要讓完全不同的系統協調工作是一個常見的難題。不論部門大小,許多 IT 部門都沒有標準化到一個開發平臺上。公司並經常會引進不同的元素和完全不同的系統,比如比較舊的應用程式與新的平臺共存。雖然像 IBM Lotus Domino 這樣的產品為開發企業應用程式提供了功能強大的平臺,但是與許多企業級軟體產品一樣,它仍需要與其他系統進行互相操作。

本文學習在 Microsoft .NET 開發平臺上整合 Lotus Domino;重點討論 Lotus Domino 7Microsoft .NET Framework V1.1 Microsoft Visual Studio .NET 2003。本文假設您是一名有經驗的 Notes/Domino 應用程式開發人員,熟悉 LotusScript Domino Web Service設計元素,並瞭解 Microsoft .NET Framework

注意:本文描述的解決方法可以用於 Microsoft .NET Framework V2.0 V1.1

程式設計模型:.NET 和 COM

Lotus Domino 是一個用於企業資料的優秀平臺。可以透過簡單的 Open Database ConnectivityODBC)或者使用 IBM Lotus Enterprise Integrator Domino Enterprise Connection Service 所提供的強大的功能很容易地存取非 Domino 資料源。可是,有時可能需要從其他的應用程式存取 Lotus Domino。所幸的是,可以向其他使用元件物件模型(Component Object ModelCOM)的應用程式開放 Domino 環境,允許外部應用程式透過 COM 使用各種開放的物件和Class很容易地與 Lotus Domino 協同工作。一個很好的例子是在使用 .NET Framework 構建的應用程式中整合 Lotus Domino 功能。

COM 是一種相對比較舊的技術,但是 .NET 提供了可調用的包裝器,允許 .NET COM 進行互相操作。透過執行時可調用的包裝器,可以在 .NET 中使用 COM 元件。這聽起來很複雜,但是使用開發工具(比如 Microsoft Visual Studio)是很簡單的。雖然必須為 COM 元件建立包裝器並在 .NET 應用程式中透過 interop 使用它們,但是當執行以下步驟時, Visual Studio .NET 會自動地建立包裝器:

  1. Visual Studio 中,選擇 Project —— Add Reference
  2. 選擇 Add Reference 對話方塊的 COM 選項頁面,然後點選所列出的合適的 Type Library 文件。
  3. 按下 OK 新增 reference

至此,Visual Studio .NET COM Type Library 檔的物件和成員轉換成對等的 .NET 的集合。當產生 .NET 集合的時候,可以使用它們的Class建立物件並調用成員,就像 COM 對象和成員是原生 .NET Class和成員一樣。也可以與這個過程相反,在基於 COM 的應用程式中使用 .NET 集合。

注意:如果沒有使用 Visual Studio .NET,那麼 .NET Framework 軟體發展包(SDK)提供了 Type Library Importertlbimp.exe)工具,這個命令行工具可以把 COM Type Library 包含的Class和介面轉換成元資料。這個工具為Class型資訊自動地建立一個 interop 集合和命名空間。

說明這個步驟的一個好方法是在 Visual Studio 解決方案中產生可用的 Lotus Domino 物件。圖 1 顯示了 Add Reference 對話方塊,並突出顯示了 Lotus Domino Objects


1. Add Reference 對話方塊

Top


Lotus Domino Objects

Lotus Notes Domino 5.02b 開始,可以使用 Lotus Domino Objects 透過 COM 來存取 Domino 物件,在 Domino 伺服器或者任何一個 Notes 用戶端(IBM Lotus Domino DesignerLotus Domino Administrator 或者 Lotus Notes)的安裝中都包括 Lotus Domino Objects。在基本安裝目錄中可以找到 domobj.tlbLotus Domino 6.x 包括 Lotus Domino Objects 版本 1.1Lotus Domino 7 包括版本 1.2

雖然必須安裝 Lotus Domino,但是它不必執行。另一個關鍵點是透過 COM 存取 Lotus Domino 時只有 backend Class可用,因此沒有可以存取的用戶介面(UIClass

Domino 郵件應用程式

透過 COM 存取 Lotus Domino 資源類似於在 Lotus Domino Designer 中使用 Java 或者 LotusScript 編程語言;任何與 Lotus Domino 的互動都開始於一個對話。Lotus Domino Objects 包括所有透過 COM 使用 Lotus Domino 所必需的Class,而且 COM 物件對於任何使用 LotusScript 或者 Java 語言開發 Domino 物件模型的開發人員來說都是很熟悉的。

包含在 Visual Studio 整合開發環境(IDE)中的是 IntelliSense 特性,它透過在鍵入的時候提供上下文敏感的幫助和自動完成程式碼來幫助使用 COM 物件,也因此減少拼寫錯誤。

第一個例子構建了一個 .NET Windows 應用程式,從 Domino Directory 獲取資料並使用 Lotus Domino 發送電子郵件訊息(參見圖 2)。.NET Windows 應用程式使用了以下 .NET 元素:

  • ComboBox 控制項用於選擇郵件接收者,並用來自 Domino Directory 視界的值填充欄位
  • TextBox 控制項用於輸入郵件訊息的主題
  • RichTextBox 控制項用於郵件訊息的主體
  • Label 控制項用於通知訊息被發送還是遇到錯誤
  • Button 控制項用於發送或者嘗試發送目前的郵件訊息

2. 使用 .NET Windows 應用程式從 Lotus Domino 發送電子郵件

清單 1 顯示了大部分的應用程式碼(省略了為應用程式產生的 Visual Studio 程式碼)。按下 Send 按鈕時調用 btnSend_Click 方法。這個方法建立 NotesSessionNotesDatabaseNotesView NotesDocument 物件,依次用於建立和發送訊息。

應用程式載入時調用 Form_Load 方法。它使用 NotesSessionNotesDatabaseNotesView NotesDocument 物件填充 ComboBox。在視界中把文件的單獨值新增到 ComboBox 控制項中。附加功能變數名稱到選定的人名來協助訊息分發。

Top

 

清單 1. .NET Windows 應用程式

Private Sub btnSend_Click(ByVal sender As System.Object,

ByVal e As System.EventArgs)Handles btnSend.Click

  Try

    Dim ns As New NotesSession

    Dim db As NotesDatabase

    Dim doc As NotesDocument

    If Not (ns Is Nothing) Then

      ns.Initialize("password")

      db = ns.GetDatabase("ServerName//Domain", "names.nsf", False)

      If Not (db Is Nothing) Then

        doc = db.CreateDocument()

        doc.ReplaceItemValue("Form", "Memo")

        doc.ReplaceItemValue("SendTo", cboNames.SelectedText + "//Domain")

        doc.ReplaceItemValue("Subject", txtSubject.Text)

        Dim rt As NotesRichTextItem

          rt = doc.CreateRichTextItem("Body")

          rt.AppendText(rtbBody.Text)

            doc.Send(False)

          rt = Nothing

            doc = Nothing

            lblMessage.Text = "Message Sent."

      End If

      db = Nothing

      ns = Nothing

    End If

    Catch ex As Exception

      lblMessage.Text = "Error: " + ex.Message.ToString()

  End Try

End Sub

 

Private Sub Form1_Load(ByVal sender As System.Object,

ByVal e As System.EventArgs)Handles MyBase.Load

  Dim s As New NotesSession

    s.Initialize()

  Dim db As NotesDatabase

  Dim vw As NotesView

  Dim doc As NotesDocument

    db = s.GetDatabase("ServerName//Domain", "names.nsf", False)

  If Not (db Is Nothing) Then

    vw = db.GetView("_People")

    doc = vw.GetFirstDocument()

    While Not (doc Is Nothing)

      cboNames.Items.Add(doc.GetFirstItem("FirstName").Text + " " +

        doc.GetFirstItem("LastName").Text)

        doc = vw.GetNextDocument(doc)

    End While

  End If

End Sub

 要發送電子郵件訊息,應用程式完成如下步驟:

  1. 實例化 NotesSession 物件。
  2. 使用指定的伺服器資料庫實例化 NotesDatabase 物件。
  3. 使用 NotesDatabase 物件建立一個新的 NotesDocument 物件。
  4. 使用表單中的值填充文件中的欄位。
  5. 使用 NotesDocument 物件為郵件訊息主體建立一個新的 NotesRichTextItem 物件。
  6. 把表單中的文字新增到 NotesRichTextItem
  7. 使用 NotesDocument Send 方法發送電子郵件訊息。
  8. 設定 Label 控制項根據訊息是否被發送來顯示資訊。(另外,如果出現異常則顯示出錯訊息。所有的操作都封裝在一個 try 塊中。)

使用 COM 不僅僅局限在 Windows 應用程式中。還可以在 Web 或者其他的應用程式類型中使用。

Top

下面,我們學習使用其他的方法與 Lotus Domino 通信,比如 Web Service XML

 Domino Web Service

Lotus Domino Objects 提供了一種非常好的在非 Domino 應用程式中存取 Domino 資源的方法,而這並不是惟一可用的方法。另一種整合兩個系統的方法涉及到 Web 標準和在 .NET 程式碼中使用 Domino Web Service

Lotus Domino 7 中新增了一個Web Service設計元素。基於 Domino Web Service與其他標準的 Web Service一樣被使用。利用 Web Service描述語言(Web Services Description LanguageWSDL)可以找到 Web Service中的可用方法。透過帶有 ?wsdl 命令的 Web Service URL 可以使用基於 Domino Web Service WSDL。例如,下面的 URL 獲取名為 testws Web Service WSDL

http://localhost/dominodatabase.nsf/testws?wsdl

**

Visual Studio .NET IDE 使得在專案中使用 Web Service變得很容易。為此,要為項目新增一個 Web Reference,先右鍵按下項目,然後選擇 Add Web Reference,如圖 3 所示。

3. 為項目新增一個 Web Reference

Domino XML 支持

在整合中可以使用的 Domino 的另一個特性是 XML。存取普通 Domino 元素的 XML 比較容易。一個很好的例子是使用 Domino 視界。使用視界的 URL ?ReadViewEntries 命令可以很容易地存取視界的 XML。例如,使用下面的 URL,可以在 Domino Directory 7 中存取 _People 視界的 XML

http://domain/names.nsf/_People?ReadViewEntries

清單 2 提供了一個在 Lotus Domino 7 伺服器的目錄中使用 ?ReadViewEntries 命令產生 XML 的範例。

清單 2. 使用 ?ReadViewEntries 命令產生的 XML

<?xml version="1.0" encoding="UTF-8" ?>

  <viewentries toplevelentries="3">

    <viewentry position="1" unid="A819181402AC862F85257199007D02BC"

     noteid="1342" siblings="3">

    <entrydata columnnumber="0" name="$18">

      <number>0</number>

    </entrydata>

    <entrydata columnnumber="1" name="$17">

      <text>Patton , Tony</text>

    </entrydata>

    <entrydata columnnumber="2" name="$12">

      <text />

    </entrydata>

    <entrydata columnnumber="3" name="CompanyName">

      <text />

    </entrydata>

    <entrydata columnnumber="4" name="$16">

      <text>Tony Patton/Patton@Test</text>

    </entrydata>

    <entrydata columnnumber="5" name="$21">

      <text>TestServer/Test</text>

    </entrydata>

  </viewentry>

</viewentries>

Top

可以將產生的 XML .NET XML 支援相結合,交換或者使用 Domino 資料。例如,可以把產生的 XML Microsoft ASP.NET 資料控制項結合。如清單 3 所示的 ASP.NET 頁面使用 _People 視界的 XML 填充 DropDownList 控制項。

清單 3. 使用 _People 視界中的 XML ASP.NET 頁面

<%@ Import Namespace="System.Net" %>

<%@ Import Namespace="System.IO" %>

<%@ Import Namespace="System.XML" %>

<%@ Page Language="vb" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

  <html>

    <head>

    <title>Populate DropDownList via XML</title>

    <script language="vb" runat="server">

      Private Sub Page_Load(ByVal sender As System.Object,

ByVal e As System.EventArgs)

        If Not (IsPostBack) Then

          Try

            GetData()

            Catch ex As Exception

            Response.Write(ex.ToString())

          End Try

        End If

      End Sub

      Public Sub GetData()

        Dim strResult As String

        Dim objResponse As WebResponse

        Dim objRequest As WebRequest

        objRequest = _

HttpWebRequest.Create("http://192.168.1.103/names.nsf/

_People?ReadViewEntries")

        objResponse = objRequest.GetResponse()

        Dim sr As StreamReader

        sr = New StreamReader(objResponse.GetResponseStream())

          strResult = sr.ReadToEnd()

          Dim doc As New XmlDocument

        sr.Close()

        doc.LoadXml(strResult)

        Dim nodes As XmlNodeList

        nodes = _

          doc.SelectNodes("viewentries/viewentry/entrydata

_[@columnnumber=""1""]")

        ddlNames.DataSource = nodes

        ddlNames.DataTextField = "innertext"

        ddlNames.DataValueField = "innertext"

        ddlNames.DataBind()

      End Sub

    </script>

    </head>

    <body>

      <form id="frmPopulateControlViaXML" method="post" runat="server">

        <asp:DropDownList id="ddlNames" runat="server" Width="336px" />

      </form>

    </body>

  </html>

 

Top

這段程式碼是使用 Microsoft Visual Basic .NET 的標準的 ASP.NET 頁面(沒有 codebehind)。這段程式碼做了如下工作:

  1. 把來自 Domino 視界 URL ?ReadViewEntries 命令的 XML 載入到 .NET XmlDocument 對象(來自 System.XML 的命名空間)。
  2. 實例化來自 XmlDocument XPath 運算式的 XmlNodeList 物件,以選擇來自 XML 的確定的實體。(這段程式碼只關心第一列中的 entrydata 元素,即 columnnumber=1 的屬性。)
  3. 使用 XmlNodeList 作為 DropDownList 控制項的資料源。
  4. 調用 DropDownList 控制項的 databind 方法把資料綁定到控制項中。

Web 頁面上顯示結果,並可以從列表中選擇一個名字。

第一步使用 .NET System.Net System.IO 命名空間,用於網路(Internet)請求和返回的資料。這個頁面使用 WebRequest 物件調用合適的 URL,用 WebResponse 物件獲得響應。

結合 WebResponse 物件的 ResponseStream 屬性,使用 StreamReader 物件讀取 Web 請求返回的 XML。然後,使用 XML 填充並實例化 XMLDocument 物件。從 XMLDocument 物件中選中單獨的節點並存儲在 XMLNodeList 物件中。使用 XPath 運算式,可以選擇合適的節點。

使用選中的節點集填充資料控制項,填充透過指定用於在控制項中顯示值及當用戶選中一個單獨的條目時返回的值的單獨列(innertext)實現。所有操作都和獲取 XML 並填充 GetData 方法的資料控制項有關,並在 ASP.NET Web 表單的 Page_Load 事件中調用。要想僅當頁面最初被請求時填充控制項,需要使用頁面的 IsPostBack 屬性,以確保頁面只載入一次,而不是頁面更新或者重整。最後,頁面使用 try捕獲任何不可預見的錯誤,並在頁面上顯示錯誤描述。圖 4 顯示了 ASP.NET 頁面。


4. Domino 視界的 XML 填充 ASP.NET DropDownList 控制項

為了展示說明,把 Domino 郵件應用程式的例子與 Domino Web Service相結合,透過 Web Service調用獲取並顯示 Domino 資料。但是,在介紹 .NET 應用程式中使用 Web Service之前,必須首先介紹一下 Domino Web Service 

Lotus Domino Web Service獲取 Domino 資料 

Web Service很簡單。它接受一個用戶名稱(格式就像姓後面跟著名,中間用逗號分開 —— 在前面的例子中使用過的格式)並從 Domino Directory 獲取與該用戶相關聯的值。服務在 LotusScript 中編寫。

Top

 

Lotus Domino Web Service的新特性是什麼?
如果您剛開始學習 Domino Web Service,請參考 developerWorks Lotus 文章Lotus Notes/Domino 7 Web Services。這篇文章很好地說明了背景,包括以下使用 LotusScript 編寫 Domino Web Service程式碼的基礎知識:

  • 實現程式碼的Class定義。(這個Class必須成為 PortType Class,在屬性視窗的 Basics 選項頁面上命名,而且它必須是公共的。)
  • Class中,在 Web Service中每個操作的進程(函數、子進程或者方法)定義。(這些進程必須是公共的。)
  • 包含 lsxsd.lss
  • 如果存取 Lotus Domino Objects,就要初始化 NotesSession。(在新塊中,最容易實現。)

 

範例的服務位於一個名為 GetUserInfo 的Class,它包括以下公有方法:
GetPhoneNumber:為用戶返回辦公室電話號碼
GetAddress:為用戶返回辦公室地址
GetCity:為用戶返回辦公室所在城市名稱
GetState:為用戶返回辦公室所在州名稱
GetZip:為用戶返回辦公室所屬郵遞區號
GetCountry:為用戶返回辦公室所在國家名稱

所有方法都接受一個字串參數(用戶名稱)並返回一個字串值。NotesSession、NotesDatabase 和 NotesView 物件用Class的新區塊中發生的初始化定義。清單 4 顯示了 Web Service程式碼。

清單 4. Domino Web Service

%INCLUDE "lsxsd.lss"

Dim session As NotesSession

Dim db As NotesDatabase

Dim vw As NotesView

Dim doc As NotesDocument

Public Class GetUserInfo

  Sub New

    Set s = New NotesSession

    Set db = s.CurrentDatabase

    Set vw = db.GetView("(PeopleLookup)")

  End Sub

  Public Function GetPhoneNumber(uName As String) As String

    Set doc = vw.GetDocumentByKey(uName)

    If Not (doc Is Nothing) Then

      GetPhoneNumber = doc.GetItemValue("OfficePhoneNumber")(0)

      Else

        GetPhoneNumber = ""

    End If

  End Function

  Public Function GetCity(uName As String) As String

    Set doc = vw.GetDocumentByKey(uName)

    If Not (doc Is Nothing) Then

      GetCity = doc.GetItemValue("OfficeCity")(0)

      Else

        GetCity = ""

    End If

  End Function

  Public Function GetState(uName As String) As String

    Set doc = vw.GetDocumentByKey(uName)

    If Not (doc Is Nothing) Then

      GetState = doc.GetItemValue("OfficeState")(0)

      Else

        GetState = ""

    End If

  End Function

  Public Function GetAddress(uName As String) As String

    Set doc = vw.GetDocumentByKey(uName)

    If Not (doc Is Nothing) Then

      GetAddress = doc.GetItemValue("OfficeStreetAddress")(0)

      Else

        GetAddress = ""

    End If

  End Function

  Public function GetZip(uName As String) As String

    Set doc = vw.GetDocumentByKey(uName)

    If Not (doc Is Nothing) Then

      GetZip = doc.GetItemValue("OfficeZip")(0)

      Else

        GetZip = ""

    End If

  End Function

  Public function GetCountry(uName As String) As String

    Set doc = vw.GetDocumentByKey(uName)

    If Not (doc Is Nothing) Then

      GetCountry = doc.GetItemValue("OfficeCountry")(0)

      Else

        GetCountry = ""

    End If

  End Function

  Public Function GetFullName(uName As String) As String

    Set doc = vw.GetDocumentByKey(uName)

    If Not (doc Is Nothing) Then

      GetFullName = doc.GetItemValue("FirstName")(0) + " " + _

        doc.GetItemValue("LastName")(0)

      Else

        GetFullName = ""

      End If

  End Function

End Class

Top

可以在瀏覽器中鍵入 URL http://dominoserver/names.nsf/GerUserInfo?wsdl,很容易地查看到這個 Web Service WSDL

注意:每個方法查找都會新增要用到的一個新的視界。這個隱藏視界稱為 PeopleLookup,只顯示 Person 表單建立的文件,包含用以下公式填充的一列:

@Trim(@Subset(LastName;1))+@If(Firstname !="";" , "+@Trim(@Subset(FirstName;1));"")+@If(MiddleInitial !="";" "+@Trim(@Subset(MiddleInitial;1));"")

ASP.NET 應用程式

可以在 ASP.NET 應用程式中使用這個 Web Service來將 Web Service調用獲取的數值填充到 Web 頁面的欄位中。首先,在 .NET 應用程式中向 Web Service新增 reference。圖 5 顯示了新增的 Web reference,以及用戶輸入服務位址並按下 Go 之後所列出的方法。


5. .NET 應用程式新增 Web Service reference

Add Web Reference 對話方塊的 Web reference 名字欄位中鍵入在程式碼中存取 Web Service所使用的名字。在新增 Web reference 之後,程式碼就會簡單易懂。清單 5 顯示了後面跟著 codebehind 檔的 ASP.NET 頁面的程式碼。

清單 5. 使用 Domino Web Service ASP.NET Web 表單

<%@ Page Language="vb" AutoEventWireup="false"

Codebehind="DominoTest.aspx.vb" Inherits="DominoIntegration.Test2"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

  <html>

    <head>

      <title>Domino Web Service Demo</title>

    </head>

    <body>

      <form id="frmDominoIntegration" method="post" runat="server">

        <asp:Label id="lblSelect" runat="server" Width="144px">

          Select Name:</asp:Label>

        <asp:DropDownList id="ddlNames" runat="server"

          OnSelectedIndexChanged="ddlNames_SelectedIndexChanged"

          AutoPostBack="True" Width="336px"></asp:DropDownList><br>

        <asp:Label id="lblName" runat="server" Width="144px">

          Address:</asp:Label>

        <asp:TextBox id="txtFullName" runat="server" Width="360px" /><br>

        <asp:Label id="lblAddress" runat="server" width="144px">

          Address:</asp:Label>

        <asp:TextBox id="txtAddress" runat="server" Width="360px" /><br>

        <asp:Label id="lblCityState" runat="server" width="144px">

          City, State</asp:Label>

        <asp:TextBox id="txtCity" runat="server" Width="264px" /><br>

        <asp:Label id="lblComma" runat="server" Width="8px" Font-Bold="True">

          ,</asp:Label>

        <asp:TextBox id="txtState" runat="server" Width="80px" /><br>

        <asp:Label id="lblZip" runat="server" Width="144px">

          Zip Code:</asp:Label>

        <asp:TextBox id="txtZip" runat="server" Width="200px" /><br>

        <asp:Label id="lblCountry" runat="server" Width="144px">

          Country:</asp:Label>

        <asp:TextBox id="txtCountry" runat="server" Width="200px" /><br>

        <asp:Label id="lblPhone" runat="server" Width="144px">

          Phone:</asp:Label>

        <asp:TextBox id="txtPhoneNumber" runat="server" Width="200px" /><br>

      </form>

    </body>

  </html>

 

Top

清單 6 顯示了用 Visual Basic 寫的 ASP.NET Web 表單的 codebehind 檔。

清單 6. ASP.NET Web 表單的 Visual Basic. NET 程式碼

Imports System.Net

Imports System.IO

Imports System.Xml

Public Class DominoIntegration

  Inherits System.Web.UI.Page

  Protected WithEvents ddlNames As DropDownList

  Protected WithEvents lblSelect As Label

  Protected WithEvents txtFullName As TextBox

  Protected WithEvents lblName As Label

  Protected WithEvents lblPhone As Label

  Protected WithEvents lblCountry As Label

  Protected WithEvents txtCountry As TextBox

  Protected WithEvents lblZip As Label

  Protected WithEvents lblCityState As Label

  Protected WithEvents txtZip As TextBox

  Protected WithEvents txtState As TextBox

  Protected WithEvents txtCity As TextBox

  Protected WithEvents txtPhoneNumber As TextBox

  Protected WithEvents txtAddress As TextBox

  Protected WithEvents lblAddress As Label

  Protected WithEvents lblComma As Label

  Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) _

    Handles MyBase.Init

    InitializeComponent()

  End Sub

  Public Sub Page_Load(ByVal sender As System.Object,

ByVal e As System.EventArgs)Handles MyBase.Load

    If Not (Me.IsPostBack) Then

      Try

        GetData()

        Catch ex As Exception

        Response.Write(ex.ToString())

      End Try

    End If

  End Sub

  Public Sub GetData()

    Dim strResult As String

    Dim objResponse As WebResponse

    Dim objRequest As WebRequest

    objRequest = System.Net.HttpWebRequest.Create(

      "http://192.168.1.103/names.nsf/_People?ReadViewEntries")

    objResponse = objRequest.GetResponse()

    Dim sr As System.IO.StreamReader

      sr = New StreamReader(objResponse.GetResponseStream())

      strResult = sr.ReadToEnd()

    Dim doc As New XmlDocument

      sr.Close()

      doc.LoadXml(strResult)

    Dim nodes As XmlNodeList

      nodes = doc.SelectNodes("viewentries/viewentry/entrydata

                    _[@columnnumber=""1""]")

      ddlNames.DataSource = nodes

      ddlNames.DataTextField = "innertext"

      ddlNames.DataValueField = "innertext"

      ddlNames.DataBind()

  End Sub

  Public Sub ddlNames_SelectedIndexChanged(ByVal sender As System.Object,

    ByVal e As System.EventArgs)

    Dim ws As New WebReference.GetUserInfoService

      txtFullName.Text = ws.GETFULLNAME(ddlNames.SelectedValue.ToString())

      txtAddress.Text = ws.GETADDRESS(ddlNames.SelectedValue.ToString())

      txtCity.Text = ws.GETCITY(ddlNames.SelectedValue.ToString())

      txtState.Text = ws.GETSTATE(ddlNames.SelectedValue.ToString())

      txtZip.Text = ws.GETZIP(ddlNames.SelectedValue.ToString())

      txtCountry.Text = ws.GETCOUNTRY(ddlNames.SelectedValue.ToString())

      txtPhoneNumber.Text =

        ws.GETPHONENUMBER(ddlNames.SelectedValue.ToString())

  End Sub

End Class

 

Top

Web 表單包括一個清單 3 所描述的 GetData 方法,但是它現在能夠使用文字欄位接收透過 Web Service調用獲取的資料。在 DropDownList 控制項中執行選擇的時候,調用 Web Service。用戶從列表中選擇一個值時,自動調用控制項的 SelectedIndex 事件(控制項的 AutoPostBack 屬性設定為 True)。

在控制項中選中的值傳遞到 Web Service,以獲取單獨調用得到的每一個資料(比如位址和城市)。這段程式碼使用在 Add Web Reference 對話方塊新增的 WebReference 物件存取 Web Service 

 結束語

整合完全不同的系統對於企業開發人員來說是一項常見的開發任務。完成這個工作的一種方法是將 Microsoft .NET 平臺與 Lotus Domino 結合,還可以使用其他方法來實現這種整合,例如使用 COM 技術以及已經可用的 XML Web Service。這些方法使得為了滿足業務需求而整合各種 IT 資源變得十分容易。

參考資料

學習


獲得產品和技術


討論

 

關於作者

Tony Patton 是美國肯塔基州路易斯維爾的一名顧問。他的工作涉及多種技術,包括 Lotus Notes/DominoJava 技術和 Microsoft .NET。他寫了兩本關於 Lotus Notes/Domino 開發的書:Practical LotusScript Domino Development with Java,他還是 CNet.com 的關於 .NET Web 開發 技術的專欄作家。您可以透過 aspatton@bellsouth.net 聯繫 Tony 

Top

Lotus Notes 技術分享

 

如何在Web上利用VML畫出柱狀統計圖?

本次智頡分享報將告訴您如何利用VML技術去繪製柱狀統計圖,此程式範例僅限使用於IE5.5版以上之版本,且不支援非IE之瀏覽器,所以請特別注意.

實作步驟如下:

1.  在資料庫中新增一個代理程式,代理程式名稱為”DrawBar”,代理程式屬性設定如下圖:

2.   在上述代理程式中貼上如下的Lotus Script程式碼:

Sub Initialize

           Dim session As New NotesSession

           Dim db As NotesDatabase

           Dim view As NotesView

           Dim doc As NotesDocument

           Dim dbpath As Variant

           Dim Data()

           Dim DataTitle()

           Dim i As Integer

           i=0

           Set db=session.CurrentDatabase

           Set view=db.GetView("FeatList")

           Print {Content-Type:text/html}

           Print {<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">}

           Print {<head>}

           Print {<title></title>}

           Print {<STYLE>}

           Print "v\:* { Behavior: url(#default#VML) }"

           Print "o\:* { behavior: url(#default#VML) }"

           Print {</STYLE>}

           Print {</head>}

           Print {<body>}    

           Redim Data(i)

           Redim DataTitle(i)

           Set doc = view.GetFirstDocument

           While Not (doc Is Nothing)

                     i=i+1            

                     Redim Preserve Data(i)

                     Redim Preserve DataTitle(i)

                     '條狀圖數據

                     Data(i)=Cdbl(doc.feat(0)/10000)

                     '條狀圖數據名稱           

                     DataTitle(i)=doc.Location(0)             

                     Set doc = view.GetNextDocument(doc)

           Wend          

           Call DrawBar(Data,DataTitle,GetBGColorArray(i),10,10,550,350,"2006年度銷售業績統計圖","","萬元")

           Print {</body>}

           Print {</html>}

End Sub

Function DrawBar(Data_Array As Variant,Title_Array As Variant,bg_color As Variant,table_left As Integer,table_top As Integer,all_width As Integer,all_height As Integer,table_title As String,X_unit As String,Y_unit As String)

           '參數含義(數據陣列,數據標題陣列,條狀圖顏色陣列,橫坐標,縱坐標,圖表的寬度,圖表的高度,圖表標題,X軸單位,Y軸單位)

           If X_unit<>"" Then

                     X_unit=X_unit

           End If

           If Y_unit<>"" Then

                     Y_unit=Y_unit

           End If          

           num =Ubound(Data_Array)

           item_width = Cdbl(18000/num+0.5)

           '每一條狀柱寬度

           item_width1 = Cdbl(15000/num)

           begin_x= Cdbl((item_width-1200)/2)+2200

           value_Max=0       

           For i=1 To num               

                     If value_Max<Data_Array(i) Then value_Max=Data_Array(i)

           Next  

           value_Max = Cdbl(value_Max)

           value_Max_str =Cstr(value_Max)  

           If value_Max>9 Then

                     temp=Mid(value_Max_str,2,1)

                     If temp>4 Then

                                temp2=(Int(value_Max/(10^(Len(value_Max_str)-1)))+1)*10^(Len(value_Max_str)-1)

                     Else

                                temp2=(Int(value_Max/(10^(Len(value_Max_str)-1)))+0.5)*10^(Len(value_Max_str)-1)

                     End If

           Else

                     If value_Max>4 Then temp2=10 Else temp2=5

           End If          

           item_hight = temp2/5    

           Print "<v:shapetype id='Box' coordsize='21600,21600' o:spt='16' adj='5400'></v:shapetype>"

          

           Print "<v:rect id='background' style='position:absolute;left:" & table_left & "px;top:" & table_top & "px;WIDTH:" & all_width & "px;HEIGHT:" & all_height & "px;' fillcolor='#EFEFEF' strokecolor='gray'>"

           Print " <v:shadow on='t' type='single' color='silver' offset='4pt,4pt'/>"

           Print "</v:rect>"

          

           Print "<v:group ID='table' style='position:absolute;left:" & table_left & "px;top:" & table_top & "px;WIDTH:" & all_width & "px;HEIGHT:" & all_height & "px;' coordsize = '23500,12700'>"

           Print " <v:Rect style='position:relative;left:1500;top:200;width:20000;height:800'filled='false' stroked='false'>"

           Print " <v:TextBox inset='0pt,0pt,0pt,0pt'>"

           Print " <table width='100%' border='0' align='center' cellspacing='0'>"

           Print " <tr>"

           Print " <td align='center' valign='middle'><div style='font-size:15pt; font-family:黑體;'><B>" & table_title & "</B></div></td>"

           Print " </tr>"

           Print " </table>"

           Print " </v:TextBox>"

           Print " </v:Rect> "

           Print " <v:rect id='back' style='position:relative;left:1700;top:1200;width:20500; height:10500;' fillcolor='#9cf' strokecolor='#DFDFDF'>"

           Print " <v:fill rotate='t' angle='-45' focus='100%' type='gradient'/>"

           Print " </v:rect>"

           Print " <v:line ID='X' from='1700,11700' to='22700,11700' style='z-index:2' strokecolor='#000000' strokeWeight=1pt><v:stroke EndArrow='Classic'/></v:line>"

           Print " <v:line ID='Y' from='1700,900' to='1700,11700' style='z-index:2' strokecolor='#000000' strokeWeight=1pt><v:stroke StartArrow='Classic'/></v:line>"

           Print " <v:Rect style='position:relative;left:100;top:700;width:1500;height:500' filled='false' stroked='false'>"

           Print " <v:TextBox inset='0pt,0pt,0pt,0pt' style='font-size:9pt;'><div align='right'>" & Y_unit & "</div></v:TextBox>"

           Print " </v:Rect> "

           Print " <v:Rect style='position:relative;left:22200;top:11700;width:2000;height:500' filled='false' stroked='false'>"

           Print " <v:TextBox inset='0pt,0pt,0pt,0pt' style='font-size:9pt;'><div align='left'>" & X_unit & "</div></v:TextBox>"

           Print " </v:Rect> "

           For i=0 To 4

                     Print " <v:line from='1200," & i*2000+1700 & "' to='1700," & i*2000+1700 & "' style='z-index:2' strokecolor='#000000'></v:line>"

                     Print " <v:line from='1700," & i*2000+1700 & "' to='2200," & i*2000+1200 & "' style='z-index:2' strokecolor='#0099FF'></v:line>"

                     Print " <v:line from='2200," & i*2000+1200 & "' to='22200," & i*2000+1200 & "' style='z-index:2' strokecolor='#0099FF'></v:line>"

                     Print " <v:line from='2200," & i*2000+2200 & "' to='22200," & i*2000+2200 & "' style='z-index:2' strokecolor='#0099FF'>"

                     Print " <v:stroke dashstyle='Dot'/>"

                     Print " </v:line>"

                    

                     Print " <v:Rect style='position:relative;left:100;top:" & i*2000+1250 & ";width:1500;height:500' filled='false' stroked='false'>"

                     Print " <v:TextBox inset='0pt,0pt,0pt,0pt' style='font-size:9pt;'><div align='right'>" & item_hight*(5-i) & "</div></v:TextBox>"

                     Print " </v:Rect> "

           Next

           Print " <v:line from='2200,11200' to='22200,11200' style='z-index:2' strokecolor='#0099FF'></v:line>"

           Print " <v:line from='2200,1200' to='2200,11200' style='z-index:2' strokecolor='#0099FF'></v:line>"

           Print " <v:line from='1700,11700' to='2200,11200' style='z-index:2' strokecolor='#0099FF'></v:line>"

          

           For i=1 To num

                     this_hight = Cdbl(Data_Array(i)/(5*item_hight)*10000+420)

                     Print " <v:shape id='Box"  &  i  & "' type='#Box' fillcolor='"  &  bg_color(i)  &  "' strokecolor='#5f5f5f' style='position:relative; left:"  &  (i-1)*item_width+begin_x  &  ";top:"  &  Cdbl(10000-this_hight+1620)  &  ";width:" & item_width1 & ";height:"  &  this_hight  &  ";z-index:10'>"

                     Print " <v:fill o:opacity2='52429f' rotate='t' angle='-45' focus='100%' type='gradient'/>"

                     Print " </v:shape>"

                     Print " <v:Rect style='position:relative;left:"  &  (i-1)*item_width+2200  &  ";top:"  &  Cdbl(10000-this_hight+1150)  &  ";width:"  &  item_width  &  ";height:500' filled='false' stroked='false'>"

                     Print " <v:TextBox inset='0pt,0pt,0pt,0pt' style='font-size:9pt;'><div align='center'>" & Data_Array(i) & "</div></v:TextBox>"

                     Print " </v:Rect> "

                     Print " <v:Rect style='position:relative;left:"  &  (i-1)*item_width+2200  & ";top:11850;width:"  &  item_width  &  ";height:800' filled='false' stroked='false'>"

                     Print " <v:TextBox inset='0pt,0pt,0pt,0pt' style='font-size:9pt;'><div align='center'>" & Title_Array(i) & "</div></v:TextBox>"

                     Print " </v:Rect> "

           Next

           Print "</v:group>"

End Function

 

Function GetBGColorArray(no As Integer) As Variant

'亂數取得HTML RGB 色碼代號

           Dim color()

           Redim color(0)

           For i=1 To no

                     Redim Preserve color(i)

                     Randomize Rnd()           

                     color(i)=GetColorCode(Int(Rnd()*254+1),Int(Rnd()*254+1),Int(Rnd()*254+1))

           Next

           GetBGColorArray=color

End Function

Function D_To_B(Byval Dec As Integer) As String

'十進制轉換二進制

           Do

                     D_To_B = Dec Mod 2 & D_To_B

                     Dec = Dec \ 2

           Loop While Dec

End Function

Function B_To_H(Byval cBin As String) As String

'二進制轉換十六進制

           Dim i As Long

           Dim H As String

           If Len(cBin) Mod 4 <> 0 Then

                     cBin = String(4 - Len(cBin) Mod 4, "0") & cBin

           End If

          

           For i = 1 To Len(cBin) Step 4

                     Select Case Mid(cBin, i, 4)

                     Case "0000": H = H & "0"

                     Case "0001": H = H & "1"

                     Case "0010": H = H & "2"

                     Case "0011": H = H & "3"

                     Case "0100": H = H & "4"

                     Case "0101": H = H & "5"

                     Case "0110": H = H & "6"

                     Case "0111": H = H & "7"

                     Case "1000": H = H & "8"

                     Case "1001": H = H & "9"

                     Case "1010": H = H & "A"

                     Case "1011": H = H & "B"

                     Case "1100": H = H & "C"

                     Case "1101": H = H & "D"

                     Case "1110": H = H & "E"

                     Case "1111": H = H & "F"

                     End Select

           Next i

           B_To_H = H

End Function

 

Function GetColorCode(R As Integer,G As Integer,B As Integer) As String

'轉換 RGB 色碼(十進制)為十六進制碼

           GetColorCode="#" & B_To_H(D_To_B(R)) & B_To_H(D_To_B(G)) & B_To_H(D_To_B(B))

End Function

3.   測試資料請自行模擬測試,如有需要可至本公司網站直接下載範例資料庫即可.

4.  請利用IE去執行上述代理程式即可測試.URL範例與結果畫面如下:

URL:

http://xxx.xx.xx/xxx/VMLBar.nsf/(DrawBar)?OpenAgent

結果畫面:

                           

:如有需要可至智頡科技網站(http://www.wmmate.com)下載範例資料庫。  

Top

近期電子報內容預告

後續陸續會發行相關技術的電子報

內容預告如下:

Lotus Notes系統整合&應用介紹

  內容相當豐富敬請期待...

Top


註:如不想繼續收到本公司之電子報或是要介紹朋友訂閱電子報請至本公司網站線上設定/訂閱


智頡科技股份有限公司

Copyright 1999-2006     版權所有 轉載必究

TEL:03-5326262       FAX:03-5344873        Email:support@wmmate.com