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

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

ContractedBlock.gifExpandedBlockStart.gif代码
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;
}

 

转载于:https://www.cnblogs.com/eva_2010/articles/1931970.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值