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

using System;
using System.Web;
using System.Data;

public class ProPlanMana_OrderImport : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        string type = HttpContext.Current.Request["type"];
        string responseText = "";
        switch (type)
        {

            ///导出excel
            case "dataoutexcel":
                responseText = outexcel();
                break;
            //作业时间查询(根据时间)  20141006 wt
            case "dataProductiveTimeSelect":
                responseText = dataProductiveTimeSelect();
                break;
            //查询订单号
            case "orderNumSelect":
                responseText = orderNumSelect();
                break;


        }
        context.Response.Write(responseText);
    }

    /// <summary>
    ///订单号查询
    /// </summary>
    /// <returns></returns>
    private string orderNumSelect()
    {
        System.Data.DataTable dt = null;
        string dtStartTime = HttpContext.Current.Request["startdate"];
        string dtEndTime = HttpContext.Current.Request["enddate"];
        MES_SPC.QualityData.GetEngineArriveLeave_OrderNum(dtStartTime, dtEndTime, out dt);
        string text = JsonHelper.DataTableToJson(dt);
        return text;
    }

    /// <summary>
    /// 导出excel
    /// </summary>
    /// <returns></returns>
    private string outexcel()
    {
        System.Data.DataTable dt = null;
        string startdate = HttpContext.Current.Request["startdate"];
        string enddate = HttpContext.Current.Request["enddate"];
        bool orderNum_isCheck = Convert.ToBoolean(HttpContext.Current.Request["checkbox_orderNum"]);
        string orderNum = HttpContext.Current.Request["orderNum"];
        MES_SPC.QualityData_ProductiveTimeSelect.Select_ProductiveTimeReport(startdate, enddate, orderNum_isCheck, orderNum, out  dt);

        if (dt != null)
        {
            if (dt.Rows.Count > 0)
            {
                dt.TableName = "测量数据发动机在线状态_作业时间";

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dt.Rows[i]["序号"] = (i + 1).ToString("000000");
                }

                CommonFunction.ExcelTable(dt);
                
            }
        }
        return "";
    }

    /// <summary>
    /// 作业时间查询
    /// </summary>
    /// <returns></returns>
    private string dataProductiveTimeSelect()
    {
        System.Data.DataTable dt = null;
        string startdate = HttpContext.Current.Request["startdate"];
        string enddate = HttpContext.Current.Request["enddate"];
        bool orderNum_isCheck = Convert.ToBoolean(HttpContext.Current.Request["checkbox_orderNum"]);
        string orderNum = HttpContext.Current.Request["orderNum"];
        int ItemCount = 0;
        MES_SPC.QualityData_ProductiveTimeSelect.Select_ProductiveTime(startdate,enddate,orderNum_isCheck,orderNum, out  dt);
        string text = JsonHelper.CreateJsonParameters(dt, false, ItemCount);//这句话是将json数据对象化，并且返回数据总条数
        return text;
    }
    ///// <summary>
    ///// 作业时间查询根据订单号
    ///// </summary>
    ///// <returns></returns>
    //private string dataProductiveTimeSelect_OrderNum()
    //{
    //    System.Data.DataTable dt = null;
    //    string orderNum = HttpContext.Current.Request["orderNum"];
    //    int ItemCount = 0;
    //    MES_SPC.QualityData_ProductiveTimeSelect.Select_ProductiveTime_OrderNum(orderNum, out  dt);
    //    string text = JsonHelper.CreateJsonParameters(dt, false, ItemCount);//这句话是将json数据对象化，并且返回数据总条数
    //    return text;
    //}


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