webservice 存在新数据时访问数据库,不存在时访问session,减少了对数据库的访问次数
/// <summary>
/// 返回开标信息数据集
/// </summary>
/// <param name="tenderId"></param>
/// <returns></returns>
[WebMethod(EnableSession = true)]
public List<string> GetInformation(string tenderId)
{
string select = "select createtime,operateContent from TB_TenderDirectSeeding where TenderId='" + tenderId + "' order by createtime desc";
SQLServerHelper SQLHelper = new SQLServerHelper();
List<string> myList = new List<string>();
DataTable dt = SQLHelper.SqlGetDataTable(select);
if (Context.Session["Information"] == null) //判断session是否为空,session保存要返回的数据集
{
for (int i = 0; i < dt.Rows.Count; i++)
{
myList.Add("⊙ " + dt.Rows[i][0].ToString() + "<br>" + " " + dt.Rows[i][1].ToString());
}
SQLHelper.SqlExecute("update TB_TenderDirectSeeding set status='1' where TenderId='" + tenderId + "' and status = ''");
Context.Session["Information"] = myList;
}
else
{
if (SQLHelper.SqlGetDataTable("select guid from TB_TenderDirectSeeding where TenderId='" + tenderId + "' and status = ''").Rows.Count > 0) //判断是否有新数据,有新数据时重新读数据库
{
for (int i = 0; i < dt.Rows.Count; i++)
{
myList.Add("⊙ " + dt.Rows[i][0].ToString() + "<br>" + " " + dt.Rows[i][1].ToString());
}
SQLHelper.SqlExecute("update TB_TenderDirectSeeding set status='1' where TenderId='" + tenderId + "' and status = ''");
Context.Session["Information"] = myList;
}
else //不存在新数据时 返回session中的值
{
myList = (List<string>)(Context.Session["Information"]);
}
}
return myList;
}