using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Web;
using DBUtility;
using Tools;

namespace PaintingScreen.Handler
{
    /// <summary>
    /// ZPPlan 的摘要说明
    /// </summary>
    public class ZPPlan : IHttpHandler
    {
        HttpRequest Request = null;
        HttpResponse Response = null;

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            Request = context.Request;
            Response = context.Response;
            string method = Request.Params["method"];
            switch (method)
            {
                case "GetTableContent":
                    GetTableContent();
                    break;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        void GetTableContent()
        {
            Response.Write(JSONTools.DataTableToJson("result", GetTable()));
            Response.End();
        }

        private static DataTable GetTable()
        {
            DataTable res = new DataTable();
            try
            {
                string sql = @"SELECT dbo.tb_ZPPlan.OrderNo, dbo.tb_ZPPlan.Item, dbo.tb_ZPPlan.PartNo, dbo.tb_Product.ProductName, 
                            dbo.tb_ZPPlan.OrderCount, dbo.tb_ZPPlan.ProductCount, dbo.tb_ZPPlan.BadCount
                            FROM dbo.tb_ZPPlan LEFT OUTER JOIN
                            dbo.tb_Product ON dbo.tb_ZPPlan.PartNo = dbo.tb_Product.PartNo where IsFinish=0 order by CreateTime ";

                res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLogManager(ex);
                LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
            }
            return res;
        }
    }
}