コード例 #1
0
ファイル: DaoHelper.cs プロジェクト: ssjylsg/crm
 public static NHibernate.IQuery StringLike(this NHibernate.IQuery query, string key, object value)
 {
     if (value == null)
     {
         return(query);
     }
     if (string.IsNullOrEmpty(value.ToString()))
     {
         return(query);
     }
     return(query.SetString(key.Replace(".", string.Empty), string.Format("%{0}%", value.ToString())));
 }
コード例 #2
0
        public IList <Domain.Entitys.TBSysLogEntity> QuerySysLogsByPageInfo(int pageCode, int pageSize, int?logType, string ip,
                                                                            string startTime, string endTime, out long totalSize)
        {
            StringBuilder hqlBuilder = new StringBuilder();

            hqlBuilder.Append(" select count(*) from TBSysLogEntity sl ");
            hqlBuilder.Append(" where 1=1 ");

            if (null != logType)
            {
                hqlBuilder.Append(" and sl.LogTypeId = ?");
            }

            if (!string.IsNullOrEmpty(ip))
            {
                hqlBuilder.Append(" and sl.LogIp like ?");
            }

            if (!string.IsNullOrEmpty(startTime))
            {
                hqlBuilder.Append(" and sl.LogDatetime >= " + "'" + startTime + "'");
            }

            if (!string.IsNullOrEmpty(endTime))
            {
                hqlBuilder.Append(" and sl.LogDatetime <= " + "'" + endTime + "'");
            }


            NHibernate.IQuery query = this.Session.CreateQuery(hqlBuilder.ToString());
            if (null != logType)
            {
                query.SetInt32(0, logType.Value);
                if (!string.IsNullOrEmpty(ip))
                {
                    query.SetString(1, "%" + ip + "%");
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(ip))
                {
                    query.SetString(0, "%" + ip + "%");
                }
            }

            totalSize = query.UniqueResult <long>();

            hqlBuilder = new StringBuilder();
            hqlBuilder.Append(" select sl from TBSysLogEntity sl");
            hqlBuilder.Append(" where 1=1 ");

            if (null != logType)
            {
                hqlBuilder.Append(" and sl.LogTypeId = ?");
            }

            if (!string.IsNullOrEmpty(ip))
            {
                hqlBuilder.Append(" and sl.LogIp like ?");
            }

            if (!string.IsNullOrEmpty(startTime))
            {
                hqlBuilder.Append(" and sl.LogDatetime >= " + "'" + startTime + "'");
            }

            if (!string.IsNullOrEmpty(endTime))
            {
                hqlBuilder.Append(" and sl.LogDatetime <= " + "'" + endTime + "'");
            }

            hqlBuilder.Append(" order by sl.LogDatetime desc");

            query = this.Session.CreateQuery(hqlBuilder.ToString());
            if (null != logType)
            {
                query.SetInt32(0, logType.Value);
                if (!string.IsNullOrEmpty(ip))
                {
                    query.SetString(1, "%" + ip + "%");
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(ip))
                {
                    query.SetString(0, "%" + ip + "%");
                }
            }


            query.SetFirstResult((pageCode - 1) * pageSize);
            query.SetMaxResults(pageSize);

            return(query.List <DASP.Domain.Entitys.TBSysLogEntity>());
        }