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

using System;
using System.Web;
using EB_BLL;
using System.Data;
using Jayrock.Json;
using System.Collections.Generic;
public class isOverlap : IHttpHandler {

    public void ProcessRequest(HttpContext context)
    {
        if (!String.IsNullOrEmpty(context.Request["dates"]) && !String.IsNullOrEmpty(context.Request["eid"]))
        {
            String[] dates = context.Request["dates"].Split(',');

            Guid eid = new Guid(context.Request["eid"].ToString());

            List<DateTime> starts = new List<DateTime>();
            List<DateTime> ends = new List<DateTime>();

            foreach (String date in dates)
            {
                String[] d = date.Split('|');
                starts.Add(Convert.ToDateTime(d[0]));
                ends.Add(Convert.ToDateTime(d[1]));
            }

            N25175_EquipmentUse_BLL eubll = new N25175_EquipmentUse_BLL();

            String msg = eubll.isOverlap(eid, starts, ends);

            JsonObject result = new JsonObject();
            if (msg != String.Empty)
            {
                result.Accumulate("state", -1);
                result.Accumulate("data", msg);
            }
            else
            {
                result.Accumulate("state", 1);
            }

            context.Response.Write(result);
            context.Response.End();
        }
        if (!String.IsNullOrEmpty(context.Request["start"]) 
                && !String.IsNullOrEmpty(context.Request["end"]) 
                && !String.IsNullOrEmpty(context.Request["eid"]))
        {
            Guid eid = new Guid(context.Request["eid"].ToString());

            String startVal = context.Request["start"];
            String endVal = context.Request["end"];

            DateTime start = DateTime.MinValue;
            DateTime end = DateTime.MinValue;

            JsonObject result = new JsonObject();
            if (!DateTime.TryParse(startVal, out start))
            {
                result.Accumulate("state", -1);
                result.Accumulate("data", "无效的起始日期！");
                context.Response.Write(result);
                context.Response.End();
            }

            if (!DateTime.TryParse(endVal, out end))
            {
                result.Accumulate("state", -1);
                result.Accumulate("data", "无效的截止日期！");
                context.Response.Write(result);
                context.Response.End();
            }

            N25175_EquipmentUse_BLL eubll = new N25175_EquipmentUse_BLL();

            String msg = eubll.isOverlap(eid, start, end);

            if (msg != String.Empty)
            {
                result.Accumulate("state", -1);
                result.Accumulate("data", msg);
            }
            else
            {
                result.Accumulate("state", 1);
            }

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

    public bool IsReusable {
        get {
            return false;
        }
    }

}