C# } 私有静态字符串formatMapNew(列表映射) { 返回string.Join(“OR”,maps.Select(x=>string.Format(“{0}.STIntersects(GeoLocation)=1,Tipologia='{1}',STpolygon(x.lastPatch.ToString()),x.typology)); } 私有静态数据集GetCoordinateInPolyGon(列表映射) { SqlCommand_coord=新SqlCommand(); Command_coord.CommandType=CommandType.Text; 命令协调连接=连接; 字符串查询=string.Format(@) 选择[Ragione sociale]、地理位置、蒂波罗吉亚、德塔格利 来自地理标签 其中{0},formatMapNew(映射)); Command_coord.CommandText=查询; 数据集坐标DS=新数据集(); SqlDataAdapter coordinatesDA=新的SqlDataAdapter(); coordinaresda.SelectCommand=Command\u坐标; 尝试 { 坐标da.填充(坐标ds); } catch(System.Data.SqlClient.SqlException) { System.Diagnostics.Debug.WriteLine(“错误查询:\n{0}\n Message={1}”,查询,e.Message); } 返回坐标d; } 私有静态bool IsEmpty(数据集) { foreach(dataSet.Tables中的DataTable表) 如果(table.Rows.Count!=0)返回false; 返回true; } 私有静态列表getDBMarkers(数据集协调) { 列表标记=新列表(); 地理点; 标记; 如果(!IsEmpty(坐标ds)) { foreach(CoordinationDS.Tables[0].Rows中的DataRow行) { 点=(SqlGeography)行[1]; 标记=新标记((字符串)行[0],新点(Point.Lat.Value,Point.Long.Value),(字符串)行[2],(字符串)行[3]); 标记。添加(标记); } } 返回标记; } 私有静态列表getMarkers(列表类型、边界) { 返回getDBMarkers(getCoordinateInpolygon(updateMaps(边界,类型)); } 私有静态列表更新映射(边界、列表类型) { 列表映射=新列表(); 地图; foreach(类型学中的字符串类型学) { map=(MapViewed)HttpContext.Current.Session[“MapViewed-”+类型学]; mergeAndGetDiff(getRectangle(bounds)); 地图。添加(地图); } 返回地图; } [System.Web.Services.WebMethod(EnableSession=true)] 公共静态列表GetMarkers(列表类别、边界) { 返回getMarkers(类别、边界); } }

C# } 私有静态字符串formatMapNew(列表映射) { 返回string.Join(“OR”,maps.Select(x=>string.Format(“{0}.STIntersects(GeoLocation)=1,Tipologia='{1}',STpolygon(x.lastPatch.ToString()),x.typology)); } 私有静态数据集GetCoordinateInPolyGon(列表映射) { SqlCommand_coord=新SqlCommand(); Command_coord.CommandType=CommandType.Text; 命令协调连接=连接; 字符串查询=string.Format(@) 选择[Ragione sociale]、地理位置、蒂波罗吉亚、德塔格利 来自地理标签 其中{0},formatMapNew(映射)); Command_coord.CommandText=查询; 数据集坐标DS=新数据集(); SqlDataAdapter coordinatesDA=新的SqlDataAdapter(); coordinaresda.SelectCommand=Command\u坐标; 尝试 { 坐标da.填充(坐标ds); } catch(System.Data.SqlClient.SqlException) { System.Diagnostics.Debug.WriteLine(“错误查询:\n{0}\n Message={1}”,查询,e.Message); } 返回坐标d; } 私有静态bool IsEmpty(数据集) { foreach(dataSet.Tables中的DataTable表) 如果(table.Rows.Count!=0)返回false; 返回true; } 私有静态列表getDBMarkers(数据集协调) { 列表标记=新列表(); 地理点; 标记; 如果(!IsEmpty(坐标ds)) { foreach(CoordinationDS.Tables[0].Rows中的DataRow行) { 点=(SqlGeography)行[1]; 标记=新标记((字符串)行[0],新点(Point.Lat.Value,Point.Long.Value),(字符串)行[2],(字符串)行[3]); 标记。添加(标记); } } 返回标记; } 私有静态列表getMarkers(列表类型、边界) { 返回getDBMarkers(getCoordinateInpolygon(updateMaps(边界,类型)); } 私有静态列表更新映射(边界、列表类型) { 列表映射=新列表(); 地图; foreach(类型学中的字符串类型学) { map=(MapViewed)HttpContext.Current.Session[“MapViewed-”+类型学]; mergeAndGetDiff(getRectangle(bounds)); 地图。添加(地图); } 返回地图; } [System.Web.Services.WebMethod(EnableSession=true)] 公共静态列表GetMarkers(列表类别、边界) { 返回getMarkers(类别、边界); } },c#,asp.net,ajax,json,session,C#,Asp.net,Ajax,Json,Session,使用访问变量: HttpContext.Current.Session 您可以在这样的静态方法中使用会话 //Store value in session HttpContext.Current.Session["mysession"]=value; //Get value from session var sessionvaue=HttpContext.Current.Session["mysession"]; using System; using System.Collections

使用访问变量:

HttpContext.Current.Session

您可以在这样的静态方法中使用会话

//Store value in session
HttpContext.Current.Session["mysession"]=value;

//Get value from session
var sessionvaue=HttpContext.Current.Session["mysession"];
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Globalization;
using Microsoft.SqlServer.Types;
using System.Data.SqlTypes;
using System.Text;

public partial class _Default : System.Web.UI.Page
{
    static SqlConnection conn = new SqlConnection("Server=localhost\\SQLEXPRESS;Database=geotagging;Trusted_Connection=Yes;Integrated Security=SSPI;");

    protected void Page_Load(object sender, EventArgs e)
    {
        string[] typologies = new string[] { "Ricambi", "Concessionario", "Motocicli", "Officina" };
        foreach (string typology in typologies)
        {
            HttpContext.Current.Session["mapViewed-"+typology] = new MapViewed(typology);
        }
    }
    private static string getRectangle(Bounds bounds)
    {
        return string.Format("polygon(({0} {1}, {2} {1}, {2} {3}, {0} {3}, {0} {1}))", bounds.NorthEast.lng.ToString(CultureInfo.InvariantCulture), bounds.NorthEast.lat.ToString(CultureInfo.InvariantCulture), bounds.SouthWest.lng.ToString(CultureInfo.InvariantCulture), bounds.SouthWest.lat.ToString(CultureInfo.InvariantCulture));
    }
    private static string STpolygon(string polygon)
    {
        return string.Format("geography :: STGeomFromText('{0}', 4326)", polygon);
    }
    private string typologiesListString(List<string> typologies)
    {
        return string.Format("({0})", string.Join(",", typologies));
    }
    private static string formatMapNew(List<MapViewed> maps)
    {
        return string.Join(" OR ", maps.Select(x => string.Format("{0}.STIntersects(GeoLocation) = 1 and Tipologia = '{1}'", STpolygon(x.lastPatch.ToString()), x.typology)));
    }
    private static DataSet getCoordinatesInPolygon(List<MapViewed> maps)
    {
        SqlCommand Command_coord = new SqlCommand();
        Command_coord.CommandType = CommandType.Text;
        Command_coord.Connection = conn;
        string query = string.Format(@"
                        select [Ragione sociale], GeoLocation, Tipologia, Dettagli
                        from GEOTAG
                        where {0}", formatMapNew(maps));
        Command_coord.CommandText = query;
        DataSet coordinatesDS = new DataSet();
        SqlDataAdapter coordinatesDA = new SqlDataAdapter();
        coordinatesDA.SelectCommand = Command_coord;
        try
        {
            coordinatesDA.Fill(coordinatesDS);
        }
        catch (System.Data.SqlClient.SqlException e)
        {
            System.Diagnostics.Debug.WriteLine("Error query: \n{0}\n Message = {1}", query, e.Message);
        }
        return coordinatesDS;
    }
    private static bool IsEmpty(DataSet dataSet)
    {
        foreach (DataTable table in dataSet.Tables)
            if (table.Rows.Count != 0) return false;
        return true;
    }
    private static List<Marker> getDBMarkers(DataSet coordinatesDS)
    {
        List<Marker> markers = new List<Marker>();
        SqlGeography point;
        Marker marker;

        if (!IsEmpty(coordinatesDS))
        {
            foreach (DataRow row in coordinatesDS.Tables[0].Rows)
            {
                point = (SqlGeography)row[1];
                marker = new Marker((string)row[0], new Point(point.Lat.Value, point.Long.Value), (string)row[2], (string)row[3]);
                markers.Add(marker);
            }
        }
        return markers;
    }
    private static List<Marker> getMarkers(List<string> typologies, Bounds bounds)
    {
        return getDBMarkers(getCoordinatesInPolygon(updatedMaps(bounds, typologies)));
    }

    private static List<MapViewed> updatedMaps(Bounds bounds, List<string> typologies)
    {
        List<MapViewed> maps = new List<MapViewed>();
        MapViewed map;
        foreach (string typology in typologies)
        {
            map = (MapViewed)HttpContext.Current.Session["mapViewed-" + typology];
            map.mergeAndGetDiff(getRectangle(bounds));
            maps.Add(map);
        }
        return maps;
    }

    [System.Web.Services.WebMethod(EnableSession = true)]
    public static List<Marker> GetMarkers(List<string> categories, Bounds bounds)
    {
        return getMarkers(categories, bounds);
    }
}
HttpContext.Current.Session
//Store value in session
HttpContext.Current.Session["mysession"]=value;

//Get value from session
var sessionvaue=HttpContext.Current.Session["mysession"];