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

using System;
using MES_SPC;
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;
            ///机型查询
            case "enginetypeSelect":
                responseText = enginetypeSelect();
                break;
            //工位号查询查询
            case "OpnameSelect":
                responseText = OpnameSelect();
                break;
            //质量数据查询
            case "dataExtentSelect":
                responseText = dataExtentSelect();
                break;
            //测量位置查询
            case "positionSelect":
                responseText = positionSelect();
                break;
            //测量项目查询
            case "projectSelect":
                responseText = projectSelect();
                break;
            //查询发动机号
            case "engineidSelect":
                responseText = engineidSelect();
                break;
            //查询订单号
            case "orderNumberSelect":
                responseText = orderNumberSelect();
                break;
            //二维码查询
            case "QRSelect":
                responseText = QRSelect();
                break;
        }
        context.Response.Write(responseText);
    }
    /// <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.GetQualityData_EngineID_Small(dtStartTime, dtEndTime, EngineTypeID_isCheck, EngineType, checkbox_opname, opName,1, out dt);

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

    /// <summary>
    ///二维码查询
    /// </summary>
    /// <returns></returns>
    private string QRSelect()
    {
        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 Opname_isCheck = Convert.ToBoolean(HttpContext.Current.Request["checkbox_opname"]);
        string Opname = HttpContext.Current.Request["opName"];
        MES_SPC.QualityData.QRSelect(dtStartTime, dtEndTime, EngineTypeID_isCheck, EngineType, Opname_isCheck, Opname,1, out dt);

        string text = JsonHelper.DataTableToJson(dt);
        return text;
    }
    
    
    /// <summary>
    ///测量项目查询
    /// </summary>
    /// <returns></returns>
    private string projectSelect()
    {
        System.Data.DataTable dt = null;
        string opName = HttpContext.Current.Request["opName"];
        string position = HttpContext.Current.Request["position"];
        MES_SPC.QualityData.GetItemName(opName, position, out dt);
        string text = JsonHelper.DataTableToJson(dt);
        return text;
    }
    /// <summary>
    ///测量位置查询
    /// </summary>
    /// <returns></returns>
    private string positionSelect()
    {
        System.Data.DataTable dt = null;
        string opName = HttpContext.Current.Request["opName"];
        MES_SPC.QualityData.GetShaftName(opName, out dt);
        string text = JsonHelper.DataTableToJson(dt);
        return text;
    }
    /// <summary>
    ///工位查询
    /// </summary>
    /// <returns></returns>
    private string OpnameSelect()
    {
        System.Data.DataTable dt = null;
        MES_SPC.CraftMana_step.OpnameSelect(out dt);
        string text = JsonHelper.DataTableToJson(dt);
        return text;
    }
    /// <summary>
    ///机型查询
    /// </summary>
    /// <returns></returns>
    private string enginetypeSelect()
    {
        System.Data.DataTable dt = null;
        MES_SPC.QualityData.GetEngineType_Data_Small(out dt);
        string text = JsonHelper.DataTableToJson(dt);
        return text;
    }



    /// <summary>
    /// 导出excel 2014-11-20加入工位名称列，11-21加入订单号查询
    /// </summary>
    /// <returns></returns>
    private string outexcel()
    {
        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.SelectGoodDataReport(
            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> 2014-11-20加入工位名称列，11-21加入订单号查询
    /// <returns></returns>
    private string dataExtentSelect()
    {
        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.GetQualityDataEveryOpNameDataListTable_Small(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;
    }


    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    /// <summary>
    ///查询订单号 2014-11-21
    /// </summary>
    /// <returns></returns>
    private string orderNumberSelect()
    {
        System.Data.DataTable dt = null;
        string startTime = HttpContext.Current.Request["startdate"];
        string endTime = HttpContext.Current.Request["enddate"];
        MES_SPC.QualityData.GetQualityData_orderNumber(startTime, endTime, 2, out dt);

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