首页  ·  知识 ·  
Label
      编辑:  图片来源:网络

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
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读
也许感兴趣的
我们推荐的
主题最新
看看其它的
收藏至微信