Johnson-由心而发,用心做人

设计人生

 

如何:在OpenText Workflow 6.5模型中保存和读取多行数据

在Captaris Workflow 6.0和之前的版本中,保存多行数据似乎没有被提及,因此大部分(包括我的团队)都要自己建立(利用IDE的向导也算)数据库来保存订单项、物品列表、人员列表这样的多行集合。这一切在6.5都已解决,流程开发者可以保存多行的事省下些脑细胞。不过从应用的情况来看,还是要费一些脑细胞的。下面用示例展示如何保存。

1.在设计流程时加入一个XML对象。

2.新增一行数据:

Teamplate.BLL.IModelXML oXml = this.Process.GetXmlObject("Common"); //”Common”是在前一步加入的XML对象名。
XmlDocument oDoc = new XmlDocument();
oDoc.LoadXml(oXml.XmlString);

XmlNode oE = oDoc.SelectSingleNode("Common/Form/Items");
//创建"Item"元素
XmlElement oEl = oDoc.CreateElement("Item");
//员工编号
oEl.SetAttribute("Code", this.drpEmployees.SelectedItem.Value);
//姓名
oEl.SetAttribute("Name", this.drpEmployees.SelectedItem.Text);
//补卡时间
DateTime time = DateTime.ParseExact(this.txtCheckDate.Text, "yyyy-MM-dd", null);
time = time.AddHours(int.Parse(this.txtCheckHour.Text));
time = time.AddMinutes(int.Parse(this.txtCheckMinute.Text));
oEl.SetAttribute("CheckTime", time.ToString("yyyy-MM-dd HH:mm"));
//原因
oEl.SetAttribute("Purpose", this.txtPurpose.Text);
//本月已补次数
oEl.SetAttribute("Times", this.txtTimes.Text);
//补卡类型
oEl.SetAttribute("CheckType", this.drpCheckType.SelectedItem.Text);

oE.AppendChild(oEl);


oXml.XmlString = oDoc.InnerXml;
oDoc = null;
//更新显示申请人列表
//this.LoadCheckItems();

 

3.显示列表数据:

XmlDocument oDoc = new XmlDocument();
oDoc.LoadXml(this.Process.GetXmlObject("Common").XmlString);
XmlNode nItems = oDoc.SelectSingleNode("Common/Form/Items");
string timesXml = nItems.OuterXml;
oDoc = null;

DataSet ds = new DataSet(“”);
Captaris.Workflow.Xml.DataSetXmlAdapter oA = new Captaris.Workflow.Xml.DataSetXmlAdapter(ds);
oA.ReadXml(xml);

//将数据集绑定到GridView

this.grdTimes.DataSource = ds;
this.grdTimes.DataBind();

4.移除一行:

private void RemoveCheckItem(int i)
{
    Teamplate.BLL.IModelXML oXml = this.Process.GetXmlObject("Common");
    XmlDocument oDoc = new XmlDocument();
    oDoc.LoadXml(oXml.XmlString);
    XmlNode nItems = oDoc.SelectSingleNode("Common/Form/Items");
    string timesXml = nItems.OuterXml;

    DataSet ds = new DataSet();
    Captaris.Workflow.Xml.DataSetXmlAdapter oA = new Captaris.Workflow.Xml.DataSetXmlAdapter(ds);
    oA.ReadXml(timesXml);

    if (ds.Tables.Count < 1)
    {
        ds = null;
        return;
    }

    ds.Tables[0].Rows[i].Delete();
    ds.Tables[0].AcceptChanges();
    //System.IO.StringWriter writer = new System.IO.StringWriter();
    //ds.Tables[0].WriteXml(writer);

    //nItems.InnerXml = writer.ToString();
    nItems.InnerXml = "";
    this.NewCheckItem(oDoc, ds.Tables[0]);
    oXml.XmlString = oDoc.OuterXml;
    //writer.Close();
    oDoc = null;
}

我觉得上面的代码太多了,为了节省您的脑细胞,我对XML操作封装成一个类,可以在此下载它。

posted on 2009-11-17 12:01  软件之美,美在缺陷-Johnson  阅读(582)  评论(0编辑  收藏  举报

导航