• 聊天室显示数据


       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("⊙&nbsp;&nbsp;" + dt.Rows[i][0].ToString() + "<br>" + "&nbsp;&nbsp;&nbsp;&nbsp;" + 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("⊙&nbsp;&nbsp;" + dt.Rows[i][0].ToString() + "<br>" + "&nbsp;&nbsp;&nbsp;&nbsp;" + 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;
        }

  • 相关阅读:
    java中的常用内存区域总结
    访问权限修饰符-static-final-this-super-匿名对象
    Scanner-String-StringBuilder-API
    This application failed to start because it could not find or load the Qt platform plugin “windows”错误解决方法
    如何优雅的写C++代码(一)
    Color Map的生成方法
    加色法和减色法
    无线电入门书籍推荐
    玩业余无线电的前期准备
    iPhone 上拨号键盘的发音规律
  • 原文地址:https://www.cnblogs.com/ajun/p/2421645.html
Copyright © 2020-2023  润新知