)C#調用DominoAPI串連LOTUS Domino的類

來源:互聯網
上載者:User

http://hi.baidu.com/xuehuaweb/blog/item/4af7d212f7e83a866438dbe1.html

   1:  using System;
   2:  using System.Data;
   3:   
   4:  namespace LotusDbLink
   5:  {
   6:      public class LotusDB
   7:      {
   8:          private string _userName;
   9:          private string _password;
  10:          private string _server;
  11:          private string _databaseName;
  12:          private string _lotusView;
  13:   
  14:          private string _fieldSet;
  15:   
  16:   
  17:          public string UserName
  18:          {
  19:              get { return _userName; }
  20:              set { _userName = value; }
  21:          }
  22:   
  23:          public string Password
  24:          {
  25:              get { return _password; }
  26:              set { _password = value; }
  27:          }
  28:   
  29:          public string Server
  30:          {
  31:              get { return _server; }
  32:              set { _server = value; }
  33:          }
  34:   
  35:          public string DatabaseName
  36:          {
  37:              get { return _databaseName; }
  38:              set { _databaseName = value; }
  39:          }
  40:   
  41:          public string LotusView
  42:          {
  43:              get { return _lotusView; }
  44:              set { _lotusView = value; }
  45:          }
  46:   
  47:          public string FieldSet
  48:          {
  49:              get { return _fieldSet; }
  50:              set { _fieldSet = value; }
  51:          }
  52:   
  53:   
  54:          public DataTable GetDataTable()
  55:          {
  56:              DataTable dataTable = new DataTable(_lotusView);
  57:              Domino.NotesSession s = new Domino.NotesSession();
  58:   
  59:              s.InitializeUsingNotesUserName(_userName, _password);
  60:              Domino.NotesDatabase db;
  61:              Domino.NotesView vw;
  62:              Domino.NotesDocument doc;
  63:              db = s.GetDatabase(_server, _databaseName, false);
  64:              if (db != null)
  65:              {
  66:                  vw = db.GetView(_lotusView);
  67:                  doc = vw.GetFirstDocument();
  68:                  string[] FieldSetTemp = FieldSet.Split(',');
  69:                  for (int i = 0; i < FieldSetTemp.Length; i++)
  70:                  {
  71:                      DataColumn dc = new DataColumn(FieldSetTemp[i], Type.GetType("System.String"));
  72:                      dataTable.Columns.Add(dc);
  73:                  }
  74:   
  75:                  while (doc != null)
  76:                  {
  77:                      DataRow dr = dataTable.NewRow();
  78:                      for (int i = 0; i < FieldSetTemp.Length; i++)
  79:                      {
  80:                          dr[FieldSetTemp[i]] = doc.GetFirstItem(FieldSetTemp[i]).Text;
  81:                      }
  82:                      dataTable.Rows.Add(dr);
  83:                      doc = vw.GetNextDocument(doc);
  84:                  }
  85:              }
  86:   
  87:              return dataTable;
  88:          }
  89:   
  90:          public DataTable GetDataTable(int index, int count)
  91:          {
  92:              DataTable dataTable = new DataTable(_lotusView);
  93:              Domino.NotesSession s = new Domino.NotesSession();
  94:   
  95:              s.InitializeUsingNotesUserName(_userName, _password);
  96:              Domino.NotesDatabase db;
  97:              Domino.NotesView vw;
  98:              Domino.NotesDocument doc;
  99:              db = s.GetDatabase(_server, _databaseName, false);
 100:              if (db != null)
 101:              {
 102:                  vw = db.GetView(_lotusView);
 103:                  doc = vw.GetFirstDocument();
 104:                  string[] FieldSetTemp = FieldSet.Split(',');
 105:                  for (int i = 0; i < FieldSetTemp.Length; i++)
 106:                  {
 107:                      DataColumn dc = new DataColumn(FieldSetTemp[i], Type.GetType("System.String"));
 108:                      dataTable.Columns.Add(dc);
 109:                  }
 110:   
 111:                  int c = 0;
 112:                  while (doc != null)
 113:                  {
 114:                      if (c < index)
 115:                      {
 116:                          doc = vw.GetNextDocument(doc);
 117:                          continue;
 118:                      }
 119:                      DataRow dr = dataTable.NewRow();
 120:                      for (int i = 0; i < FieldSet.Length; i++)
 121:                      {
 122:                          dr[FieldSetTemp[i]] = doc.GetFirstItem(FieldSetTemp[i]).Text;
 123:                      }
 124:                      dataTable.Rows.Add(dr);
 125:                      doc = vw.GetNextDocument(doc);
 126:                      c++;
 127:                      if (c > count) break;
 128:                  }
 129:              }
 130:   
 131:              return dataTable;
 132:          }
 133:   
 134:      }
 135:  }
 136:   
 137:   
 138:  使用方法(執行個體為WebService中的方法)
 139:   
 140:      [WebMethod(Description = "<br>擷取視圖的方法,返回一個DataTable結構,以下為各參數說明:<br>username = 使用者名稱<br>password = 密碼<br>databasename = 文件庫名<br>lotusview = 視圖名<br>fieldset = 視圖欄位(用','分割)<br>")]
 141:      public System.Data.DataTable GetLotusTable(string username, string password, string server, string databasename, string lotusview, string fieldset)
 142:      {
 143:          LotusDbLink.LotusDB ldb = new LotusDbLink.LotusDB();
 144:          ldb.UserName = username;
 145:          ldb.Password = password;
 146:          ldb.Server = server;
 147:          ldb.DatabaseName = databasename;
 148:          ldb.LotusView = lotusview;
 149:          ldb.FieldSet = fieldset;
 150:          return ldb.GetDataTable();
 151:      }
 152:   
 153:      [WebMethod(Description = "<br>擷取視圖前N項的方法,返回一個DataTable結構,以下為各參數說明:<br>username = 使用者名稱<br>password = 密碼<br>databasename = 文件庫名<br>lotusview = 視圖名<br>fieldset = 視圖欄位(用','分割)<br>index = 開始索引<br>count = 前N項<br>")]
 154:      public System.Data.DataTable GetLotusTableCount(string username, string password, string server, string databasename, string lotusview, string fieldset, int index, int count)
 155:      {
 156:          LotusDbLink.LotusDB ldb = new LotusDbLink.LotusDB();
 157:          ldb.UserName = username;
 158:          ldb.Password = password;
 159:          ldb.Server = server;
 160:          ldb.DatabaseName = databasename;
 161:          ldb.LotusView = lotusview;
 162:          ldb.FieldSet = fieldset;
 163:          return ldb.GetDataTable(index, count);
 164:      }
 165:   
 166:   
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.