<%@ 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;
            //工位号查询查询
            case "OpnameSelect":
                responseText = OpnameSelect();
                break;
            //物料数据查询
            case "dataMateralSelect":
                responseText = dataMateralSelect();
                break;

            //查询发动机号
            case "engineidSelect":
                responseText = engineidSelect();
                break;
            //查询物料条码批次
            case "BarcodeBatchMaterialsSelect":
                responseText = MaterialBatchSelect();
                break;
            case"materialnameSelect":
                responseText = MaterialnameSelect();
                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_LineMaterial.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 MaterialnameSelect()
    {
        System.Data.DataTable dt = null;
        //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_MaterialSelect.GetQualityData_MaterialnameSelect(EngineType, opName, out dt);

        string text = JsonHelper.DataTableToJson(dt);
        return text;
    }
    
    
    /// <summary>
    ///物料条码批次查询 2014-11-25
    /// </summary>
    /// <returns></returns>
    private string MaterialBatchSelect()
    {
        System.Data.DataTable dt = null;
        string dtStartTime = HttpContext.Current.Request["startdate"];
        string dtEndTime = HttpContext.Current.Request["enddate"];
        string opname = HttpContext.Current.Request["opname"];
        //string engine = HttpContext.Current.Request["engine"];
         MES_SPC.QualityData_MaterialSelect.GetMaterial_BarcodeBatchMaterials(dtStartTime, dtEndTime,opname,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
    /// </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"];


        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_materialname = Convert.ToBoolean(HttpContext.Current.Request["checkbox_materialname"]);
        string materialname = HttpContext.Current.Request["materialname"];

        bool checkbox_MaterialsBatchBarcode = Convert.ToBoolean(HttpContext.Current.Request["checkbox_BarcodeBatchMaterials"]);
        string comboBox_MaterialsBatchBarcode = HttpContext.Current.Request["comboBox_BarcodeBatchMaterials"];

        bool checkbox_QRcode = Convert.ToBoolean(HttpContext.Current.Request["checkbox_QRcode"]);
        string QR_code = HttpContext.Current.Request["QR_code"];
       
        MES_SPC.QualityData_MaterialSelect.SelectMaterialReport(
           checkbox_engineid, engineid, checkbox_enginetype, enginetype, checkbox_materialname, materialname,
           checkbox_opname, opName,checkbox_MaterialsBatchBarcode,comboBox_MaterialsBatchBarcode,checkbox_QRcode,QR_code,
            startdate, enddate,
             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 dataMateralSelect()
    {
        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"];
        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_materialname = Convert.ToBoolean(HttpContext.Current.Request["checkbox_materialname"]);
        string materialname = HttpContext.Current.Request["materialname"];

        bool checkbox_MaterialsBatchBarcode = Convert.ToBoolean(HttpContext.Current.Request["checkbox_BarcodeBatchMaterials"]);
        string comboBox_MaterialsBatchBarcode = HttpContext.Current.Request["comboBox_BarcodeBatchMaterials"];

        bool checkbox_QRcode = Convert.ToBoolean(HttpContext.Current.Request["checkbox_QRcode"]);
        string QR_code = HttpContext.Current.Request["QR_code"];

        MES_SPC.QualityData_MaterialSelect.Select_material(startdate, enddate,checkbox_enginetype,enginetype,
           checkbox_engineid, engineid,checkbox_materialname,materialname,
           checkbox_opname, opName,checkbox_MaterialsBatchBarcode,comboBox_MaterialsBatchBarcode,checkbox_QRcode,QR_code,
           page, rows1, out  PageCount, out  ItemCount,
           out  dt);

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


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