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

using System;
using System.Web;
using System.Web.SessionState;
using EB_BLL;
using System.Data;
using Jayrock.Json;
using EB_Model;
using System.Text;
public class Meeting : IHttpHandler,IRequiresSessionState {

    public void ProcessRequest(HttpContext context)
    {
        N25175_Employee_BLL.NotLoginBack();

        if (!String.IsNullOrEmpty(context.Request["start"])
            && !String.IsNullOrEmpty(context.Request["end"]))
        {
            Guid eid = N25175_Employee_BLL.GetLoginKey();

            DateTime start = Convert.ToDateTime(context.Request["start"]);
            DateTime end = Convert.ToDateTime(context.Request["end"]);

            N25175_Meeting_BLL bll = new N25175_Meeting_BLL();

            DataTable data = null;
            if (String.IsNullOrEmpty(context.Request["zcy"]))
            {
                data = bll.GetEmployeeMeeting(eid, start, end);
            }else
            {
                data = bll.GetEmployeePartakeMeeting(eid, start, end);
            }

            JsonArray result = new JsonArray();

            foreach (DataRow row in data.Rows)
            {
                JsonObject item = new JsonObject();
                item.Accumulate("id", row["m_id"]);
                item.Accumulate("title", row["m_MeetingName"]);
                item.Accumulate("start", ((DateTime)row["m_startDate"]).ToString("yyyy-MM-dd HH:mm:ss"));
                item.Accumulate("end", ((DateTime)row["m_endDate"]).ToString("yyyy-MM-dd HH:mm:ss"));
                result.Add(item);
            }

            context.Response.Write(result);
            context.Response.End();
        }
        else if (!String.IsNullOrEmpty(context.Request["sid"]))
        {
            Guid sid = new Guid(context.Request["sid"]);

            N25175_Meeting_BLL mbll = new N25175_Meeting_BLL();
            N25175_Meeting_Model model = mbll.GetModel(sid);
            JsonObject json = new JsonObject();
            if (model == null)
            {
                json.Accumulate("state", -1);
                context.Response.Write(json);
                context.Response.End();
            }
            json.Accumulate("state", 1);
            json.Accumulate("name", model.m_MeetingName);
            json.Accumulate("start", model.m_startDate.ToString("yyyy-MM-dd HH:mm:ss"));
            json.Accumulate("end", model.m_endDate.ToString("yyyy-MM-dd HH:mm:ss"));
            N25175_Employee_BLL ebll = new N25175_Employee_BLL();
            N25175_Employee_Model eMOdel = ebll.GetModel(model.m_buid);
            json.Accumulate("create", eMOdel.ee_name);
            N25175_Meeting_Employee_BLL mebll = new N25175_Meeting_Employee_BLL();
            DataTable meData = mebll.GetMeetingEmployee(sid);
            StringBuilder sb = new StringBuilder();
            foreach (DataRow item in meData.Rows)
            {
                sb.Append(item["ee_name"]);
                sb.Append("、");
            }
            json.Accumulate("participant", sb.ToString());

            N25175_Meeting_ExternalPerson_BLL mepbll = new N25175_Meeting_ExternalPerson_BLL();
            DataTable mepData = mepbll.GetMeetingExternalPerson(sid);
            StringBuilder mepsb = new StringBuilder();
            foreach (DataRow item in mepData.Rows)
            {
                mepsb.Append(String.Format("{0}/{1}",item["cy_name"],item["dep_name"]));
                mepsb.Append("、");
            }
            json.Accumulate("externalPerson", mepsb.ToString());

            N25175_Room_BLL rbll = new N25175_Room_BLL();
            N25175_Room_Model rModel = rbll.GetModel(model.m_rid);

            json.Accumulate("rname", rModel.r_name);
            context.Response.Write(json);
            context.Response.End();

        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}