Ejemplo n.º 1
0
        public string GetData(HttpContext context)
        {
            HttpReSultMode resultMode = new HttpReSultMode();

            try
            {
                int     pageIndex = int.Parse(context.Request["Pageindex"]);
                int     pageSize  = int.Parse(context.Request["Pagesize"]);
                DataSet ds;
                #region 条件
                StringBuilder Where = new StringBuilder();
                Where.Append(" isDeleted=0 and States>0");
                if (context.Request["keyWords"] != null)//关键词
                {
                    string KeyWords = FilterTools.FilterSpecial(context.Request["keyWords"].ToString());
                    Where.Append(" and( TName like '%" + KeyWords + "%'");
                    Where.Append(" or  Address like '%" + KeyWords + "%' ");
                    Where.Append(" or  Details like '%" + KeyWords + "%') ");
                }
                if (context.Request["Category"] != null)//分类
                {
                    string Category = FilterTools.FilterSpecial(context.Request["Category"].ToString());
                    Where.Append(" and  ( Category like '" + Category + "%')");
                }
                #endregion
                #region   坐标 有距离
                if (context.Request["Lng"] != null && context.Request["Lat"] != null)//传有坐标按距离排序
                {
                    string Longitude = context.Request["Lng"].ToString();
                    string Latitude  = context.Request["Lat"].ToString();
                    //分页 按距离排序
                    string geohashWhere = Geohash.getsqlGeoHash(5, Latitude, Longitude, "geohash");
                    string sqlWhere     = Where.ToString() + " and " + geohashWhere;//条件加geohash
                    ds = OPBiz.GetPagingOrderByLL(sqlWhere, pageIndex, pageSize, Longitude, Latitude);
                }
                else //简单分页无排序
                {
                    ds = OPBiz.GetPagingDataSet(Where.ToString(), pageIndex, pageSize, "CreateTime desc");
                }
                #endregion
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    resultMode.Code = 11;
                    resultMode.Msg  = "获取成功";
                    resultMode.Data = JsonHelper.ToJson(ds.Tables[0], true);
                }
                else
                {
                    resultMode.Code = 0;
                    resultMode.Msg  = "没有数据";
                    resultMode.Data = "[]";
                }
            }
            catch (Exception ex)
            {
                resultMode.Code = -11;
                resultMode.Data = ex.ToString();
            }
            string result = JsonHelper.ToJson(resultMode, true);
            return(result);

            ;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 分类分页获取
        /// </summary>
        /// <param name="context"></param>
        /// <param name="httpObject"></param>
        /// <param name="resultMode"></param>
        private void GetByCategory(HttpContext context, JObject httpObject, HttpReSultMode resultMode)
        {
            int     pageIndex = 1;
            int     pageSize  = 10000;
            DataSet ds;

            #region
            if (httpObject["pageIndex"] != null)
            {
                pageIndex = int.Parse(httpObject["pageIndex"].ToString());
            }

            if (httpObject["pageSize"] != null)
            {
                pageSize = int.Parse(httpObject["pageSize"].ToString());
            }
            #region 条件
            StringBuilder Where = new StringBuilder();
            Where.Append(" isDeleted=0 and States>0 ");
            //if (httpObject["jsonEntity"]["KeyWords"] != null)//关键词
            //{
            //     string KeyWords = FilterTools.FilterSpecial(httpObject["jsonEntity"]["KeyWords"].ToString());
            //    Where.Append(" and( TName like '%" + KeyWords + "%'");
            //    Where.Append(" or  Address like '%" + KeyWords + "%') ");
            //}
            if (httpObject["jsonEntity"]["Category"] != null)//分类
            {
                string Category = FilterTools.FilterSpecial(httpObject["jsonEntity"]["Category"].ToString());
                Where.Append(" and  ( Category like '" + Category + "%')");
            }
            if (httpObject["jsonEntity"]["ProvinceCode"] != null)//省
            {
                string ProvinceCode = FilterTools.FilterSpecial(httpObject["jsonEntity"]["ProvinceCode"].ToString());
                Where.Append(" and  ( ProvinceCode like '" + ProvinceCode + "%')");
            }
            if (httpObject["jsonEntity"]["CityCode"] != null)//城市
            {
                string CityCode = FilterTools.FilterSpecial(httpObject["jsonEntity"]["CityCode"].ToString());
                Where.Append(" and  ( CityCode like '" + CityCode + "%')");
            }
            if (httpObject["jsonEntity"]["AreaCode"] != null)//区
            {
                string AreaCode = FilterTools.FilterSpecial(httpObject["jsonEntity"]["AreaCode"].ToString());
                Where.Append(" and  ( AreaCode like '" + AreaCode + "%')");
            }
            #endregion
            #region   坐标 有距离
            if (httpObject["jsonEntity"]["Longitude"] != null && httpObject["jsonEntity"]["Latitude"] != null)//传有坐标按距离排序
            {
                string Longitude = httpObject["jsonEntity"]["Longitude"].ToString();
                string Latitude  = httpObject["jsonEntity"]["Latitude"].ToString();

                string geohashWhere = Geohash.getsqlGeoHash(5, Latitude, Longitude, "geohash");
                string sqlWhere     = Where.ToString() + " and " + geohashWhere;                            //条件加geohash

                if (httpObject["jsonEntity"]["minKM"] != null && httpObject["jsonEntity"]["maxKM"] != null) //有最小最大距离约定 不分页
                {
                    float minKM = float.Parse(httpObject["jsonEntity"]["minKM"].ToString());
                    float maxKM = float.Parse(httpObject["jsonEntity"]["maxKM"].ToString());
                    ds = OPBiz.GetByDistancesOrderByLL(sqlWhere, minKM, maxKM, Longitude, Latitude);
                }
                else //分页 按距离排序
                {
                    ds = OPBiz.GetPagingOrderByLL(sqlWhere, pageIndex, pageSize, Longitude, Latitude);
                }
            }
            else //简单分页无排序
            {
                ds = OPBiz.GetPagingDataSet(Where.ToString(), pageIndex, pageSize, "CreateTime desc");
            }
            #endregion
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                resultMode.Code = 11;
                resultMode.Msg  = "获取成功";
                resultMode.Data = JsonHelper.ToJson(ds.Tables[0], true);
            }
            else
            {
                resultMode.Code = 0;
                resultMode.Msg  = "没有数据";
                resultMode.Data = "[]";
            }
            #endregion
            context.Response.Write(JsonHelper.ToJson(resultMode, true));
            context.Response.End();
        }