<%@ 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)
        {
               ///分线导出
            case "dataPartoutexcel":
                responseText = dataPartoutexcel();
                break;
            //查询发动机号
            case "engineidSelect":
                responseText = engineidSelect();
                break;
           //分线数据查询
            case "datapartExtentSelect":
                responseText = datapartExtentSelect();
                break;


        }
        context.Response.Write(responseText);
    }

    /// <summary>
    /// 分线质量数据查询
    /// </summary>
    /// <returns></returns>
    private string datapartExtentSelect ( )
    {
        System.Data.DataTable dt = null;
        int PageCount = 0;
        int ItemCount = 0;
        int page = Convert.ToInt32(HttpContext.Current.Request ["page"]);//请求的当前页码
        int rows1 = Convert.ToInt32(HttpContext.Current.Request ["rows"]);//请求一页显示的数据条数。
        string startdate = HttpContext.Current.Request ["startdate"];
        string enddate = HttpContext.Current.Request ["enddate"];

        bool checkbox_enginetype = Convert.ToBoolean(HttpContext.Current.Request ["checkbox_enginetype"]);
        string enginetype = HttpContext.Current.Request ["enginetype"];

        int radio_isgoodbad = Convert.ToInt32(HttpContext.Current.Request ["radio_isgoodbad"]);


        bool checkbox_opname = Convert.ToBoolean(HttpContext.Current.Request ["checkbox_opname"]);
        string opName = HttpContext.Current.Request ["opName"];

        bool checkbox_engineid = Convert.ToBoolean(HttpContext.Current.Request ["checkbox_engineid"]);
        string engineid = HttpContext.Current.Request ["engineid"];

        bool checkbox_position = Convert.ToBoolean(HttpContext.Current.Request ["checkbox_position"]);
        string position = HttpContext.Current.Request ["position"];

        bool checkbox_project = Convert.ToBoolean(HttpContext.Current.Request ["checkbox_project"]);
        string project = HttpContext.Current.Request ["project"];

        bool checkbox_orderNumber = Convert.ToBoolean(HttpContext.Current.Request ["checkbox_OrderNumber"]);
        string orderNumber = HttpContext.Current.Request ["orderNumber"];

        bool checkbox_SerialsNum = Convert.ToBoolean(HttpContext.Current.Request ["checkbox_SerialsNum"]);
        string SerialsNum = HttpContext.Current.Request ["SerialsNum"];

        MES_SPC.QualityData_LineQuality.GetQualityPartData(startdate, enddate,
            checkbox_enginetype, enginetype, checkbox_engineid, engineid,
           checkbox_opname, opName,
            checkbox_position, position,
            checkbox_project, project, checkbox_orderNumber, orderNumber, checkbox_SerialsNum, SerialsNum, radio_isgoodbad,
              page, rows1, false, out PageCount, out ItemCount, out dt);

        string text = JsonHelper.CreateJsonParameters(dt, true, ItemCount);//这句话是将json数据对象化，并且返回数据总条数
        return text;
    }

    /// <summary>
    /// 导出分线excel 2014-11-20加入工位名称列，11-21加入订单号查询
    /// </summary>
    /// <returns></returns>
    private string dataPartoutexcel()
    {
        System.Data.DataTable dt = null;
        string startdate = HttpContext.Current.Request["startdate"];
        string enddate = HttpContext.Current.Request["enddate"];

        bool checkbox_enginetype = Convert.ToBoolean(HttpContext.Current.Request["checkbox_enginetype"]);
        string enginetype = HttpContext.Current.Request["enginetype"];

        int radio_isgoodbad = Convert.ToInt32(HttpContext.Current.Request["radio_isgoodbad"]);


        bool checkbox_opname = Convert.ToBoolean(HttpContext.Current.Request["checkbox_opname"]);
        string opName = HttpContext.Current.Request["opName"];

        bool checkbox_engineid = Convert.ToBoolean(HttpContext.Current.Request["checkbox_engineid"]);
        string engineid = HttpContext.Current.Request["engineid"];

        bool checkbox_position = Convert.ToBoolean(HttpContext.Current.Request["checkbox_position"]);
        string position = HttpContext.Current.Request["position"];

        bool checkbox_project = Convert.ToBoolean(HttpContext.Current.Request["checkbox_project"]);
        string project = HttpContext.Current.Request["project"];

        bool checkbox_orderNumber_Excel = Convert.ToBoolean(HttpContext.Current.Request["checkbox_OrderNumber"]);
        string orderNumber_Execl = HttpContext.Current.Request["orderNumber"];

        bool checkbox_SerialsNum = Convert.ToBoolean(HttpContext.Current.Request["checkbox_SerialsNum"]);
        string SerialsNum = HttpContext.Current.Request["SerialsNum"];
        MES_SPC.QualityData_LineQuality.SelectGoodDataPartReport(
            checkbox_enginetype, enginetype,
           checkbox_engineid, engineid,
           checkbox_opname, opName,
            checkbox_position, position,
            checkbox_project, project, checkbox_orderNumber_Excel, orderNumber_Execl,
            checkbox_SerialsNum, SerialsNum,
            startdate, enddate,
            radio_isgoodbad, false, 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_QualityData_Query(dt);
            }
        }
        return "";
    }


    /// <summary>
    ///发动机号查询
    /// </summary>
    /// <returns></returns>
    private string engineidSelect()
    {
        System.Data.DataTable dt = null;
        string dtStartTime = HttpContext.Current.Request["startdate"];
        string dtEndTime = HttpContext.Current.Request["enddate"];
        bool EngineTypeID_isCheck = Convert.ToBoolean(HttpContext.Current.Request["checkbox_enginetype"]);
        string EngineType = HttpContext.Current.Request["enginetype"];
        bool checkbox_opname = Convert.ToBoolean(HttpContext.Current.Request["checkbox_opname"]);
        string opName = HttpContext.Current.Request["opName"];
        MES_SPC.QualityData_LineMaterial.GetQualityData_EngineID_Small(dtStartTime, dtEndTime, EngineTypeID_isCheck, EngineType, checkbox_opname, opName, 2, out dt);

        string text = JsonHelper.DataTableToJson(dt);
        return text;
    }

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