iT邦幫忙

DAY 37
2

鐵之 Just Do Lotus Notes系列 第 37

使用CSharp在Notes日曆新增一筆資料

  • 分享至 

  • xImage
  •  

整合議題是必須的再出現Google日曆之後常常會有高層主管想要做整個,那我們就來看看如果用CSharp日如何將資料寫入Notes日曆.

我們測試一下跟Notes日曆的互通性,測試成功就可做同步整合的方案囉.
Step01:執行測試程式

Step02:成功寫入訊息

Step03: 查看Notes日曆資料

using System;
using System.Windows.Forms;
//This DLL you've got to add under Projekt-> Add Reference --> COM Tab --> Lotus Domino Objects
//Standard Path for this DLL is: "C:\Program Files\Notes\domobj.tlb"
using Domino;   //domobj.tlb*
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
//try&catch
try
{
    //-------------------------------------------
    //!!Important!!
    //Befor you start, you have to check 2 things
    //1.) Lotus Notes has to run when you start this application
    //2.)The files "notes.ini" and "user.id" 
    //("user" stands for your username) have to be in the folder 
    // "C:\Program Files\Notes" or "C:\Program Files\IBM\Notes" 
    //--------------------------------------------        
    //First, create a new Lotus Notes Session Object
    Domino.NotesSession LNSession = new Domino.NotesSession();
    //Next add a Database and a Document Object (not new)
    Domino.NotesDatabase LNDatabase;
    Domino.NotesDocument LNDocument;
    //Initialize your Session with your Password
    //LNSession.Initialize("password");
    LNSession.Initialize("");   
    //Connect to your Notes Server and the path of your 
    //.nsf File (in my case its in a subfolder 'mail').
    //LNDatabase = LNSession.GetDatabase("Notes-Server", "mail\\user.nsf", false);       
    //Create an in memory document in the server database
    LNDocument = LNDatabase.CreateDocument();
    //-------Assign Field Values-------
    //Define Start&End Date+Time of your appointment
    //Year, Month, Day, Hour, Minute and Second
    System.DateTime StartDate = new DateTime(2011, 11, 23, 8, 2, 0);
    System.DateTime EndDate = new DateTime(2011, 11, 24, 8, 5, 0);
    //This Defines that it is an Calendar Entry
    LNDocument.ReplaceItemValue("Form", "Appointment");
    //Type of the appointment, means:
    LNDocument.ReplaceItemValue("AppointmentType", "0");
    //0 = Date, Appointment           
    //1 = Anniversary
    //2 = All Day Event (Do Not Set Time Here!)
    //3 = Meeting
    //4 = Reminder
    //5 = Date (Special, experimental!)    
    // Title of your entry
    LNDocument.ReplaceItemValue("Subject", "hello KAKASHI");
    // Set Confidential Level (Public=1 or Private=0) 
    LNDocument.ReplaceItemValue("$PublicAccess","1");     
    //Add Start&End Time of your event
    LNDocument.ReplaceItemValue("CALENDARDATETIME", StartDate);
    LNDocument.ReplaceItemValue("StartDateTime", StartDate);
    LNDocument.ReplaceItemValue("EndDateTime", EndDate);
    LNDocument.ReplaceItemValue("StartDate", StartDate);
    LNDocument.ReplaceItemValue("MeetingType", "1");
    //Infos in The Body
    LNDocument.ReplaceItemValue("Body", "Body Text Body Text ...");
    //Add an alarm to your appointment
    LNDocument.ReplaceItemValue("$Alarm", 1);
    LNDocument.ReplaceItemValue("$AlarmDescription", "hello KAKASHI (alarm)");
    LNDocument.ReplaceItemValue("$AlarmMemoOptions", "" );
    //5 = Time (in minutes) before alarm goes on
    LNDocument.ReplaceItemValue("$AlarmOffset", 5);
    LNDocument.ReplaceItemValue("$AlarmSound", "tada");
    LNDocument.ReplaceItemValue("$AlarmUnit", "M");
    //This saves your Document in the Notes Calendar
    LNDocument.ComputeWithForm(true, false);
    LNDocument.Save(true, false, false);
    //On success, you'll see an info message;
    MessageBox.Show("Calendar Entry Successfully Added!", "Info", 
    MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception e1)
{
    //On error you'll see an error message
    MessageBox.Show(e1.Message);
}
        }
    }
}

資料來源

http://stackoverflow.com/questions/9058478/access-calendar-data-lotus-notes-c-sharp


上一篇
目錄鏈結與資料庫鏈結
下一篇
使用CSharp列出所有Notes資料庫名稱
系列文
鐵之 Just Do Lotus Notes41
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

我要留言

立即登入留言