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

using System;
using System.Data;
using System.Web;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using Model;

public class Handler : IHttpHandler {

    protected int typeId = 0;
    protected string str = "";
    protected string brand = "";
    protected bool flag = false;
    public void ProcessRequest (HttpContext context) {
        str = "";
        try
        {
            typeId = int.Parse(context.Request["typeId"].ToString());
            if(context.Request["brand"]!=null){
                brand = context.Request["brand"].ToString(); ;
            }
        }
        catch (Exception exc)
        {
            if (brand != "")
            {
                str = "<input id='brand' type='text' value='" + brand + "' class='input' onblur='selectBrand()' size='13'/>";
            }
            else
            {
                str = "<input id='brand' type='text' class='input' onblur='selectBrand()' size='13'/>";
            }
            context.Response.Write(str);
            System.Threading.Thread.Sleep(500);
            return;
        }
        BLLBrand bllBrand = new BLLBrand();
        DataSet ds = bllBrand.select(typeId);
        if (ds.Tables[0].Rows.Count == 0)
        {
            
            System.Threading.Thread.Sleep(200);
            if (brand != "")
            {
                str = "<input id='brand' type='text' value='" + brand + "' class='input' onblur='selectBrand()' size='13'/>";
            }
            else
            {
                str = "<input id='brand' type='text' class='input' onblur='selectBrand()' size='13'/>";
            }
            context.Response.Write(str);
            System.Threading.Thread.Sleep(500);
            return;
        }
        else
        {
            str = "<select id='brand' onchange='selectBrand()' >";
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                str += "<option value='" + ds.Tables[0].Rows[i]["bname"] + "' >" + ds.Tables[0].Rows[i]["bname"] + "</option> ";
                System.Threading.Thread.Sleep(100);
            }
            if (brand != "")
                {
                    str += "<option value='" + brand + "' selected >" + brand + "</option> ";
                }
            str += "</select>";
        }
        
        context.Response.Write(str);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}