<%@ WebHandler Language="C#" Class="ExternalPerson" %>

using System;
using System.Web;
using Jayrock.Json;
using EB_BLL;
using System.Data;
public class ExternalPerson : IHttpHandler {
    HttpRequest Request = null;
    HttpResponse Response = null;
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        Request = context.Request;
        Response = context.Response;

       if (!String.IsNullOrEmpty(Request["query"]))
        {
            String query = Request["query"].ToString();
            Employee(query);
        }
    }

    private void Employee(String query)
    {
        JsonObject result = new JsonObject();
        JsonArray suggestions = new JsonArray();
            
        N25175_ExternalPerson_BLL goods = new N25175_ExternalPerson_BLL();
        DataTable data = goods.GetAutoComplete(query);

        foreach (DataRow row in data.Rows)
        {
            JsonObject item = new JsonObject();

            item.Accumulate("value", row["dep_name"].ToString());
            item.Accumulate("data", row["dep_id"].ToString());
            item.Accumulate("company", row["cy_name"].ToString());
                
            suggestions.Add(item);
        }
        
        result.Accumulate("suggestions", suggestions);

        Response.Write(result);
        Response.End();
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}