using System;
using System.Data;
namespace LotusDbLink
{
public class LotusDB
{
private string _userName;
private string _password;
private string _server;
private string _databaseName;
private string _lotusView;
private string _fieldSet;
public string UserName
{
get { return _userName; }
set { _userName = value; }
}
public string Password
{
get { return _password; }
set { _password = value; }
}
public string Server
{
get { return _server; }
set { _server = value; }
}
public string DatabaseName
{
get { return _databaseName; }
set { _databaseName = value; }
}
public string LotusView
{
get { return _lotusView; }
set { _lotusView = value; }
}
public string FieldSet
{
get { return _fieldSet; }
set { _fieldSet = value; }
}
public DataTable GetDataTable()
{
DataTable dataTable = new DataTable(_lotusView);
Domino.NotesSession s = new Domino.NotesSession();
s.InitializeUsingNotesUserName(_userName, _password);
Domino.NotesDatabase db;
Domino.NotesView vw;
Domino.NotesDocument doc;
db = s.GetDatabase(_server, _databaseName, false);
if (db != null)
{
vw = db.GetView(_lotusView);
doc = vw.GetFirstDocument();
string[] FieldSetTemp = FieldSet.Split(',');
for (int i = 0; i < FieldSetTemp.Length; i++)
{
DataColumn dc = new DataColumn(FieldSetTemp[i], Type.GetType("System.String"));
dataTable.Columns.Add(dc);
}
while (doc != null)
{
DataRow dr = dataTable.NewRow();
for (int i = 0; i < FieldSetTemp.Length; i++)
{
dr[FieldSetTemp[i]] = doc.GetFirstItem(FieldSetTemp[i]).Text;
}
dataTable.Rows.Add(dr);
doc = vw.GetNextDocument(doc);
}
}
return dataTable;
}
public DataTable GetDataTable(int index, int count)
{
DataTable dataTable = new DataTable(_lotusView);
Domino.NotesSession s = new Domino.NotesSession();
s.InitializeUsingNotesUserName(_userName, _password);
Domino.NotesDatabase db;
Domino.NotesView vw;
Domino.NotesDocument doc;
db = s.GetDatabase(_server, _databaseName, false);
if (db != null)
{
vw = db.GetView(_lotusView);
doc = vw.GetFirstDocument();
string[] FieldSetTemp = FieldSet.Split(',');
for (int i = 0; i < FieldSetTemp.Length; i++)
{
DataColumn dc = new DataColumn(FieldSetTemp[i], Type.GetType("System.String"));
dataTable.Columns.Add(dc);
}
int c = 0;
while (doc != null)
{
if (c < index)
{
doc = vw.GetNextDocument(doc);
continue;
}
DataRow dr = dataTable.NewRow();
for (int i = 0; i < FieldSet.Length; i++)
{
dr[FieldSetTemp[i]] = doc.GetFirstItem(FieldSetTemp[i]).Text;
}
dataTable.Rows.Add(dr);
doc = vw.GetNextDocument(doc);
c++;
if (c > count) break;
}
}
return dataTable;
}
}
}
使用方法(实例为WebService中的方法)
[WebMethod(Description = "<br>获取视图的方法,返回一个DataTable结构,以下为各参数说明:<br>username = 用户名<br>password = 密码<br>databasename = 文档库名<br>lotusview = 视图名<br>fieldset = 视图字段(用','分割)<br>")]
public System.Data.DataTable GetLotusTable(string username, string password, string server, string databasename, string lotusview, string fieldset)
{
LotusDbLink.LotusDB ldb = new LotusDbLink.LotusDB();
ldb.UserName = username;
ldb.Password = password;
ldb.Server = server;
ldb.DatabaseName = databasename;
ldb.LotusView = lotusview;
ldb.FieldSet = fieldset;
return ldb.GetDataTable();
}
[WebMethod(Description = "<br>获取视图前N项的方法,返回一个DataTable结构,以下为各参数说明:<br>username = 用户名<br>password = 密码<br>databasename = 文档库名<br>lotusview = 视图名<br>fieldset = 视图字段(用','分割)<br>index = 开始索引<br>count = 前N项<br>")]
public System.Data.DataTable GetLotusTableCount(string username, string password, string server, string databasename, string lotusview, string fieldset, int index, int count)
{
LotusDbLink.LotusDB ldb = new LotusDbLink.LotusDB();
ldb.UserName = username;
ldb.Password = password;
ldb.Server = server;
ldb.DatabaseName = databasename;
ldb.LotusView = lotusview;
ldb.FieldSet = fieldset;
return ldb.GetDataTable(index, count);
}
本文作者:网友 来源:博客园 http://www.cnblogs.com/luckd/archive/2008/08/20/1272420.html