Exemple #1
0
        public string Execute(Hashtable params_ht)
        {
            Hashtable res = params_ht;

            /* if (!string.IsNullOrEmpty(SiteHelper.GetAppsetString("NearVehicleKM")))
             * {
             *   km = double.Parse(SiteHelper.GetAppsetString("NearVehicleKM"));
             * }
             * if (!string.IsNullOrEmpty(SiteHelper.GetAppsetString("PageNum")))
             * {
             *   pageNum = int.Parse(SiteHelper.GetAppsetString("PageNum"));
             * }*/
            if (res["Latitude"] == null ||
                res["Longitude"] == null ||
                res["PageNum"] == null ||
                res["CurrentPage"] == null ||
                res["Latitude"].ToString().Trim().Length <= 0 ||
                res["Longitude"].ToString().Trim().Length <= 0 ||
                res["PageNum"].ToString().Trim().Length <= 0 ||
                res["CurrentPage"].ToString().Trim().Length <= 0)
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整"));
            }
            else
            {
                try
                {
                    currentPage = int.Parse(res["CurrentPage"].ToString().Trim());
                    weidu       = res["Latitude"].ToString().Trim();
                    jingdu      = res["Longitude"].ToString().Trim();
                }
                catch
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "数据格式不正确"));
                }
                VehicleManager vm       = new VehicleManager();
                DataTable      vehicles = vm.GetNearVehicles(km, weidu, jingdu, currentPage, pageNum);
                if (vehicles == null || vehicles.Rows.Count <= 0)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "亲,没有数据了"));
                }
                else
                {
                    foreach (DataRow dr in vehicles.Rows)
                    {
                        decimal electricity = 0;
                        decimal.TryParse(dr["Electricity"].ToString(), out electricity);
                        int dianliang = Decimal.ToInt32(electricity);
                        dr["Electricity"] = dianliang + "%";
                        string lng = dr["Longitude"].ToString();
                        string lat = dr["Latitude"].ToString();
                        if (!string.IsNullOrEmpty(lng) && !string.IsNullOrEmpty(lat))
                        {
                            LatLng latlng = new LatLng(double.Parse(lat), double.Parse(lng));
                            latlng          = SiteHelper.TransformFromWGSToGCJ(latlng);
                            dr["Longitude"] = latlng.longitude;
                            dr["Latitude"]  = latlng.latitude;
                        }
                    }
                    return(JsonHelper.DataTableToJson("success", "获取数据成功", vehicles, "VehicleInfo"));
                }
            }
        }
        /// <summary>
        /// 获取附近车辆信息
        /// </summary>
        /// <param name="context"></param>
        private void GetNearVehicles(HttpContext context)
        {
            double km          = 100;
            int    pageNum     = 100;
            int    currentPage = 1;
            string weidu       = string.Empty;
            string jingdu      = string.Empty;

            if (!string.IsNullOrEmpty(SiteHelper.GetAppsetString("NearVehicleKM")))
            {
                km = double.Parse(SiteHelper.GetAppsetString("NearVehicleKM"));
            }
            if (!string.IsNullOrEmpty(SiteHelper.GetAppsetString("PageNum")))
            {
                pageNum = int.Parse(SiteHelper.GetAppsetString("PageNum"));
            }
            if (context.Request["Latitude"] == null ||
                context.Request["Longitude"] == null ||
                context.Request["PageNum"] == null ||
                context.Request["CurrentPage"] == null ||
                context.Request["Latitude"].ToString().Trim().Length <= 0 ||
                context.Request["Longitude"].ToString().Trim().Length <= 0 ||
                context.Request["PageNum"].ToString().Trim().Length <= 0 ||
                context.Request["CurrentPage"].ToString().Trim().Length <= 0)
            {
                context.Response.Write(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整"));
            }
            else
            {
                try
                {
                    //pageNum = int.Parse(res["PageNum"].ToString().Trim());
                    currentPage = int.Parse(context.Request["CurrentPage"].ToString().Trim());
                    weidu       = context.Request["Latitude"].ToString().Trim();
                    jingdu      = context.Request["Longitude"].ToString().Trim();
                }
                catch
                {
                    context.Response.Write(SiteHelper.GetJsonFromHashTable(null, "faild", "数据格式不正确"));
                    context.Response.End();
                }
                VehicleManager vm       = new VehicleManager();
                DataTable      vehicles = vm.GetNearVehicles(km, weidu, jingdu, currentPage, pageNum);
                if (vehicles == null || vehicles.Rows.Count <= 0)
                {
                    context.Response.Write(SiteHelper.GetJsonFromHashTable(null, "faild", "亲,没有数据了"));
                    context.Response.End();
                }
                else
                {
                    foreach (DataRow dr in vehicles.Rows)
                    {
                        dr["ThumbImageUrl"] = SiteHelper.GetFileServer() + dr["ThumbImageUrl"].ToString();
                        decimal electricity = 0;
                        decimal.TryParse(dr["Electricity"].ToString(), out electricity);
                        int dianliang = Decimal.ToInt32(electricity);
                        dr["Electricity"] = dianliang + "%";

                        string lng = dr["Longitude"].ToString();
                        string lat = dr["Latitude"].ToString();
                        if (!string.IsNullOrEmpty(lng) && !string.IsNullOrEmpty(lat))
                        {
                            LatLng latlng = SiteHelper.GetBaiduByGPS(lat, lng);
                            if (latlng != null)
                            {
                                dr["Longitude"] = latlng.longitude;
                                dr["Latitude"]  = latlng.latitude;
                                if (dr["Address"].ToString().Trim().Length <= 0)
                                {
                                    dr["Address"] = SiteHelper.GetLocationByGPS(dr["Latitude"].ToString(), dr["Longitude"].ToString());
                                }
                            }
                        }
                    }
                    context.Response.Write(JsonHelper.DataTableToJson("success", "获取数据成功", vehicles, "VehicleInfo"));
                }
            }
        }