using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace Maps.Web
{
    public class Areas : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            SqlConnection cnn = new SqlConnection();
            cnn.ConnectionString = "Data Source=(local);Initial Catalog=CR;Integrated Security=True";

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cnn;
            cmd.CommandText = "SELECT KrajId, Nazev, Oblast.ToString() as polygon FROM Kraje";

            cnn.Open();

            SqlDataReader rst = cmd.ExecuteReader();
            while (rst.Read())
            {
                context.Response.Write(rst.GetInt32(0));
                context.Response.Write(";");
                context.Response.Write(rst.GetString(1));
                context.Response.Write(";");
                context.Response.Write(rst.GetString(2));
                context.Response.Write(Environment.NewLine);                
            }
            rst.Close();
            cnn.Close();            
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
