繁体   English   中英

如何使用c#和interop.domino.dll的用法在Domino服务器中插入新的注释文档?

[英]how to insert a new notes document in the domino server with c# and the usage of interop.domino.dll?

这是我的第一个问题。

我想知道如果不使用c#在Lotus Notes数据库中插入新注释文档的语法。
我在vb脚本中有一个代码,我对vb脚本和Lotus Notes不了解。

     set doc = vw.GetDocumentByKey(empno)

        if doc is nothing then
          set doc = db.CreateDocument
          doc.Form = "EmployeeRepository"
          doc.Employno = empno
          doc.FirstName = fname
          doc.LastName = lname
          doc.Group = grp
          doc.Department = dept
          doc.officeemailaddress = officemail
          doc.officegeneralline = officegenline
          doc.designation = desig
          doc.officeaddress = officeadd 
        else
          doc.FirstName = fname
          doc.LastName = lname
          doc.Group = grp
          doc.Department = dept
          doc.officeemailaddress = officemail
          doc.officegeneralline = officegenline
          doc.designation = desig
          doc.officeaddress = officeadd     
        end if

        call doc.save(true, true)

如何在C#中实现呢?

if语句的C#语法不同。 代替这个:

if doc is nothing then
  ...
else
  ...
end if

你会需要

if (doc != null)
{
  ...
}
else
{
  ...
}

另外,C#语言不支持缩写符号doc.item =X。因此,需要更改上述代码中该格式的分配,以使用ReplaceItemValue方法。 即,代替此:

  doc.Form = "EmployeeRepository"
  doc.Employno = empno
  doc.FirstName = fname
  doc.LastName = lname

您需要使用此:

  doc.ReplaceItemValue("Form","EmployeeRepository");
  doc.ReplaceItemValue("Employno",empno);
  doc.ReplaceItemValue("FirstName", fname);
  doc.ReplaceItemValue("LastName", lname);

我可能还建议尝试使用ExpandoObject(尽管我还没有尝试过,但是我要尝试一下)。 这是一个动态类型,因此您必须谨慎地创建它,但是您可以继续向其添加其他属性,而不必直接实例化它们:

    dynamic noteDocument = new System.Dynamic.ExpandoObject();

    noteDocument.ShortName = "wonkaWillie";
    noteDocument.Comment = "No Comment";
    noteDocument.MailSystem = "Other";
    noteDocument.PowerLevel = "It's over NINE THOUSAND!!!!!";

我想您可以很容易地(并且可能会更严格地解决方案)准备一个预格式化的类,以便将数据也添加到特定的文档格式中。


因此,ExpandoObject方法可以工作,但是使用带有显式声明的字段/属性的类会更加整洁。...您可以将类的实例传递给可以轻松执行此操作的方法:

   class NotesDocumentItemClass
    {
         public string Form {get; set;} = "Person";
         public string FullName {get; set;} = "Over 9000/Notes/Address/Or/Whatever";
    }

然后将该类的实例传递给类似.....的方法

    private bool AddEntry(NotesDatabase db, NoteDocumentItemClass d)
    {
            NotesDocument newDoc = db.CreateDocument();
            doc.ReplaceItemValue("Form", d.Person);
            doc.ReplaceItemValue("FullName", d.FullName);
            return newDoc.Save();

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM