Professional InfoPath 2003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Professional InfoPath 2003 [Electronic resources] - نسخه متنی

Ian Williams, Pierre Greborio

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید











Completing the Creator and Identifiers Data


When the editor approves the story, InfoPath must update and complete the following meta elements and attributes:



Complete the creator element: url and byline attributes



Set the meta/@id and meta/identifier



meta/@id is calculated as deskID concatenated with an auto increment integer saved in a database table. The meta/identifier is given by the concatenation of the date, deskID, and story file extension (see meta/content/@file to get the filename).


Defining Identifiers


The identifiers, meta/identifier and meta/@id, are subject to a little elaboration. The former is just a concatenation of several elements contained in the meta element:


function CalculateIdentifier(meta)
{
var identifier = metaNode.selectSingleNode("identifier");
var deskID = metaNode.selectSingleNode("//formHeader/@deskID");
var file = metaNode.selectSingleNode("content/@file");
var date = metaNode.selectSingleNode("modificationTime");

// get the file extension
var ext = file.text.substr(file.text.length - 3);

// set identifier
identifier.noteTypedValue = date.text + deskID.text + ext;
}

The meta/@id content is the result of the concatenation of deskID and a unique identifier. A script that uses a database table that stores the last identifier used produces that unique identifier:


function GetUniqueID()
{
// Constants
adOpenForwardOnly = 0;
adLockReadOnly = 1;
adCmdText = 1;

// db values
var id;

try
{
// Connection string
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=D:\Documents\Books\InfoPath\Samples\case\DataBase.mdb;" ;
var objRs = new ActiveXObject("ADODB.Recordset");

// Command text
var strComm = "SELECT ID FROM IDs";

// Open the connection to database and execute the SQL statement
objRs.Open(strComm, stroConn,adOpenForwardOnly, adLockReadOnly, adCmdText);

// Move to the first (and unique) record
objRs.MoveFirst();

// Load the id
id = objRs("ID");

// Close the recordset
objRs.Close();

// Increment by one
id += 1;

// Command text
var strComm = "UPDATE IDs SET ID = " + id;

// Open the connection to database and execute the SQL statement
objRs.Open(strComm, stroConn,adOpenForwardOnly, adLockReadOnly, adCmdText);
// Close the recordset
objRs.Close();

objRs = null;

return id;
}
catch(e)
{
XDocument.UI.Alert("An error occurred during the rating calculation.");
return 0;
}
}

As you can see from the preceding code, you connect to the database table IDs and load the last ID value used, and then you increment by one and update the value’s table. The new ID is returned by the function. To complete meta/@id attribute, you need to concatenate the ID created and deskID as follows:


function SetId(metaNode)
{
var deskID = metaNode.selectSingleNode("//formHeader/@deskID");
var id = metaNode.selectSingleNode("@id");
id.nodeTypedValue = deskID + GetUniqueID();
}

The code must be applied for each story of the source XML document as shown before:

function msoxd__status::OnAfterChange(eventObj)
{
if(eventObj.Operation == "Insert" && eventObj.Site.text == "Filed")
{
var objMetaNodes = XDocument.DOM.selectNodes("//meta");
for (var i = 0; i < objMetaNodes.length; i++)
{
UpdateModificationTime(objMetaNodes.item(i));
CalculateIdentifier(objMetaNodes.item(i));
SetId(objMetaNodes.item(i));
}
}
if(eventObj.Operation == "Insert" && eventObj.Site.text == "Embargoed")
{
var objMetaNodes = XDocument.DOM.selectNodes("//meta");
for (var i = 0; i < objMetaNodes.length; i++)
{
UpdateModificationTime(objMetaNodes.item(i));
}
}
}


Completing Creator Data


When the contributor mails his or stories, the contributor provides a user identifier. The editor, during the approval process, needs to convert that information to a url and byline, as specified in Chapter 13. This information is part of the table Contracts and can be recovered through a query:


function UpdateCreator(meta)
{
var creatorID = metaNode.selectSingleNode("creator/@userID");

// Constants
adOpenForwardOnly = 0;
adLockReadOnly = 1;
adCmdText = 1;

// db values
var byline;
var url;

try
{
// Connection string
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
+Data Source=D:\Documents\Books\InfoPath\Samples\case\DataBase.mdb; ";
var objRs = new ActiveXObject("ADODB.Recordset");

// Command text
var strComm = "SELECT byline, url FROM Contracts WHERE ContractNumber = " + creatorID;

// Open the connection to database and execute the SQL statement
objRs.Open(strComm, stroConn,adOpenForwardOnly, adLockReadOnly, adCmdText);

// Move to the first (and unique) record
objRs.MoveFirst();

// Load the data
byline = objRs("byline");
url = objRs("url");

// Close the connection
objRs.Close();
objRs = null;

// Update the fields
metaNode.selectSingleNode("creator/@byline").nodeTypedValue = byline;
metaNode.selectSingleNode("creator/@url").nodeTypedValue = url;
}
catch(e)
{
XDocument.UI.Alert("An error occurred during the rating calculation.");
return 0;
}
}

Since the preceding function must be computed for each story, you have to update the msoxd__ status::OnAfterChange function as well:

function msoxd__status::OnAfterChange(eventObj)
{
if(eventObj.Operation == "Insert" && eventObj.Site.text == "Filed")
{
var objMetaNodes = XDocument.DOM.selectNodes("//meta");

for (var i = 0; i < objMetaNodes.length; i++)
{
UpdateModificationTime(objMetaNodes.item(i));
UpdateCreator(objMetaNodes.item(i));
}
}
if(eventObj.Operation == "Insert" && eventObj.Site.text == "Embargoed")
{
var objMetaNodes = XDocument.DOM.selectNodes("//meta");
for (var i = 0; i < objMetaNodes.length; i++)
{
UpdateModificationTime(objMetaNodes.item(i));
}
}
}

This way, anytime you modify the status, you get all contributor information correctly set.

/ 166