SQL Server数据库中数据绑定到InfoPath的RepeatingTable中(二)

SQL Server数据库中数据绑定到InfoPath的RepeatingTable中。这样,可以上传到SharePoint站点而没有冲突。

代码
public void InternalStartup()
{
EventManager.FormEvents.Loading
+= new LoadingEventHandler(FormEvents_Loading);
EventManager.FormEvents.ViewSwitched
+= new ViewSwitchedEventHandler(FormEvents_ViewSwitched);
}


/// <summary>
///将查出的数据绑定到InfoPath的RepeatingTable中
/// </summary>
/// <param name="progressID">progressID</param>
/// <returns>listHistory</returns>
private void QueryHistory(int progressID)
{
XPathNavigator root
= MainDataSource.CreateNavigator();
XPathNavigator table
= root.SelectSingleNode("/my:myFields/my:table", this.NamespaceManager);
XPathNavigator row1
= table.SelectSingleNode("/my:myFields/my:table/my:row1", this.NamespaceManager);
List
<ApproveHistory> appList = GetAppHistory(progressID);
int j = appList.Count;
{
if (j == 1)//只有一条数据记录
{
row1.SelectSingleNode(
"/my:myFields/my:table/my:row1/my:txtAppStep", this.NamespaceManager).SetValue(appList[j - 1].AppStep);
row1.SelectSingleNode(
"/my:myFields/my:table/my:row1/my:txtAppName", this.NamespaceManager).SetValue(appList[j - 1].AppName);
row1.SelectSingleNode(
"/my:myFields/my:table/my:row1/my:txtAppResult", this.NamespaceManager).SetValue(appList[j - 1].AppResult.ToString());
row1.SelectSingleNode(
"/my:myFields/my:table/my:row1/my:txtRejReason", this.NamespaceManager).SetValue(appList[j - 1].RejReason);
row1.SelectSingleNode(
"/my:myFields/my:table/my:row1/my:txtAppTime", this.NamespaceManager).SetValue(appList[j - 1].AppTime.ToString());

}
else//有多条数据时候。在流程运行中,确认一步增加一条数据。查询时候只要绑定最后一条数据就可以了。逐条增加绑定
{
table.AppendChild(row1);
XPathNavigator newRow
= row1.Clone();
newRow.SelectSingleNode(
"/my:myFields/my:table/my:row1/my:txtAppStep", this.NamespaceManager).SetValue(appList[j - 1].AppStep);
newRow.SelectSingleNode(
"/my:myFields/my:table/my:row1/my:txtAppName", this.NamespaceManager).SetValue(appList[j - 1].AppName);
newRow.SelectSingleNode(
"/my:myFields/my:table/my:row1/my:txtAppResult", this.NamespaceManager).SetValue(appList[j - 1].AppResult.ToString());
newRow.SelectSingleNode(
"/my:myFields/my:table/my:row1/my:txtRejReason", this.NamespaceManager).SetValue(appList[j - 1].RejReason);
newRow.SelectSingleNode(
"/my:myFields/my:table/my:row1/my:txtAppTime", this.NamespaceManager).SetValue(appList[j - 1].AppTime.ToString());
table.AppendChild(newRow);
row1.DeleteSelf();
}
}
}

/// <summary>
/// Get Approval History by progressID
/// </summary>
/// <param name="progressID">progressID</param>
/// <returns>listHistory</returns>
private static List<ApproveHistory> GetAppHistory(int progressID)
{
List
<ApproveHistory> listHistory = new List<ApproveHistory>();
SqlConnection _con
= new SqlConnection(@"Data Source=SOFTTEK-WALMART;Initial Catalog=ProjectDefinitionBev;Persist Security Info=True;User ID=ap;Password=user1@dmin");
SqlCommand cmd
= new SqlCommand();
cmd.Connection
= _con;
cmd.CommandText
= @"SELECT appStep,appName,appResult,appTime,rejReason FROM ApproveHistory
WHERE progressID=@progressID
";
cmd.Parameters.AddWithValue(
"@progressID", progressID);
_con.Open();
SqlDataReader reader
= cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
ApproveHistory appHistory
= new ApproveHistory();
appHistory.AppName
= reader["appName"].ToString();
appHistory.AppResult
= reader["appResult"].ToString();
appHistory.AppStep
= reader["appStep"].ToString();
appHistory.AppTime
= Convert.ToDateTime(reader["appTime"]);
appHistory.RejReason
= reader["rejReason"].ToString();
lstHistory.Add(appHistory);
}
if (reader != null)
{
reader.Close();
}
}
_con.Close();
return listHistory;
}

 

posted @ 2011-01-10 14:45  eva.xiao  阅读(265)  评论(0编辑  收藏  举报