using System;
using Core.Mes.ServerFrameWork;
using Core.Mes.IBaseInterface;
using System.Data;
using System.Collections;

namespace Core.XgMes.Server.JGKC.SteelPlateManager
{
	/// <summary>
	/// TurnoffMoveButtress 的摘要说明。
	/// </summary>
	public class TurnoffMoveButtress : Core.Mes.ServerFrameWork.IComponent
	{
		public TurnoffMoveButtress()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}

		public override int maxValue
		{
			get
			{
				return 100;
			}
		}
		public override int minValue
		{
			get
			{
				return 50;
			}
		}

		/// <summary>
		/// 查询垛位信息
		/// </summary>
		/// <param name=" _Where">条件</param>
		/// <returns></returns>
		public ReturnObject GetTurnoffButtress(string _Where,string strRoleID,string strlx)
		{
			try
			{
				string err = "";
                string sql = "";
                if (strlx == "1")
                {
                    sql = @"select T1.*,T3.OSPET,T3.INSTEEL  FROM" +
                        "(SELECT C.PACTNO," +
                        "       C.PACTINDEX PLANNO," +
                        "       A.ORDERNO," +
                        "       H.NAME_ PRODUCTLINE," +
                        "       A.ROLLNUMBER," +
                        "       A.MOTHERBOARDNUMBER," +
                        
                        "       A.BILLETID," +
                        "       A.STOVENO," +
                        "       A.PLY," +
                        "       A.WIDTH," +
                        "       A.LENGTH," +
                        "       A.THEORYWEIGHT," +
                        "       D.NAME_ FACEQUALITY," +
                    
                        "       A.DETERMINANTCARDNUMBER," +
                        "       F.NAME_ DETERMINANTRESULT," +
                       
                        "       A.SOURCEID," +
                        "       TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME," +
                        "       B.BUTTRESS," +
                        "       B.CONDOLENUMBER," +
                        "       B.CONDOLELAYER," +
                        "       B.BUTTRESSLAYER," +
                        "       TO_CHAR(B.LOGICALLAYER) LOGICALLAYER," +
                        "       B.AREA," +
                        "       B.REMARK," +
                        "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET," +
                        "       B.HANDREMARK," +
                        
                        "      BB.BUYERNAME,CC.STATIONNAME " +
                        "  FROM KCJ_TURNOFFLIST_ZW         A," +
                        "       KCJ_TURNOFFBUTTRESSLIST_ZW B," +
                        "       SEL_PACTDETAIL          C," +
                        "       SCM_BASE_INFO           D," +
                       
                        "       SCM_BASE_INFO           F," +
                      
                        "       SCM_BASE_INFO           H,SCM_BASE_INFO           M  ,SEL_BUYERBASEINFO BB,SEL_STATIONINFO CC " +
                        " WHERE A.BILLETID = B.BILLETID AND (A.BILLETID LIKE 'H%' OR A.BILLETID LIKE 'Z%')" +
                        "   AND A.ORDERNO = C.ORDERNO(+)" +
                        "   AND A.STORAGESTATUS = '501602'" +
                        "   AND A.ISVALID = '1'" +
                        "   AND A.FACEQUALITY = D.ID_(+) " +
                        
                        "   AND A.DETERMINANTRESULT = F.ID_(+)" +
                        
                        "   AND A.PRODUCTLINE = H.ID_(+) AND A.DETECTMARBOOKIN = M.ID_(+) AND C.BUYERCODE=BB.BUYERCODE(+) AND C.STATIONCODE=CC.STATIONCODE(+)  " +
                        _Where +
                        " )T1" +
                        " LEFT JOIN (SELECT PLY || '*' || WIDTH || '*' || LENGTH OSPET,BILLETID,INSTEEL FROM KCJ_STORAGELIST_ZW)T3 ON T1.BILLETID = T3.BILLETID ";
                }
                else
                {
                    sql = @"select T1.*,T3.OSPET,T3.INSTEEL  FROM" +
                       "(SELECT C.PACTNO," +
                       "       C.PACTINDEX PLANNO," +
                       "       A.ORDERNO," +
                       "       H.NAME_ PRODUCTLINE," +
                       "       A.ROLLNUMBER," +
                       "       A.MOTHERBOARDNUMBER," +

                       "       A.BILLETID," +
                       "       A.STOVENO," +
                       "       A.PLY," +
                       "       A.WIDTH," +
                       "       A.LENGTH," +
                       "       A.THEORYWEIGHT," +
                       "       D.NAME_ FACEQUALITY," +

                       "       A.DETERMINANTCARDNUMBER," +
                       "       F.NAME_ DETERMINANTRESULT," +

                       "       A.SOURCEID," +
                       "       TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME," +
                       "       B.BUTTRESS," +
                       "       B.CONDOLENUMBER," +
                       "       B.CONDOLELAYER," +
                       "       B.BUTTRESSLAYER," +
                       "       TO_CHAR(B.LOGICALLAYER) LOGICALLAYER," +
                       "       B.AREA," +
                       "       B.REMARK," +
                       "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET," +
                       "       B.HANDREMARK," +

                       "      BB.BUYERNAME,CC.STATIONNAME " +
                       "  FROM KCJ_TURNOFFLIST_ZW         A," +
                       "       KCJ_TURNOFFBUTTRESSLIST_ZW B," +
                       "       SEL_PACTDETAIL          C," +
                       "       SCM_BASE_INFO           D," +

                       "       SCM_BASE_INFO           F," +

                       "       SCM_BASE_INFO           H,SCM_BASE_INFO           M  ,SEL_BUYERBASEINFO BB,SEL_STATIONINFO CC " +
                       " WHERE A.BILLETID = B.BILLETID AND (A.BILLETID LIKE 'E%' OR A.BILLETID LIKE 'B%' OR A.BILLETID LIKE 'Y%' ) " +
                       "   AND A.ORDERNO = C.ORDERNO(+)" +
                       "   AND A.STORAGESTATUS = '501602'" +
                       "   AND A.ISVALID = '1'" +
                       "   AND A.FACEQUALITY = D.ID_(+) " +

                       "   AND A.DETERMINANTRESULT = F.ID_(+)" +

                       "   AND A.PRODUCTLINE = H.ID_(+) AND A.DETECTMARBOOKIN = M.ID_(+) AND C.BUYERCODE=BB.BUYERCODE(+) AND C.STATIONCODE=CC.STATIONCODE(+)  " +
                       _Where +
                       " )T1" +
                       " LEFT JOIN (SELECT PLY || '*' || WIDTH || '*' || LENGTH OSPET,BILLETID,INSTEEL FROM KCJ_STORAGELIST_ZW)T3 ON T1.BILLETID = T3.BILLETID ";
                }
               
				System.Data.DataSet ds = this.DBManager.ExecuteQuery(sql,out err);
				if(ds!=null && ds.Tables.Count==1 && ds.Tables[0].Rows.Count>0)
				{
					ds.Tables[0].TableName = "KCJ_TURNOFFBUTTRESSLIST";
					return new ReturnObject(ds);
				}
				else
				{
					return new ReturnObject(null);
				}
			}
			catch(System.Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(null,ex.ToString());
			}

		}



        public ReturnObject GetTurnoffButtress_PS(string _Where, string sstyle)
        {
            try
            {
                string err = "";
                string sql = "";
                //				string sql = "SELECT C.PACTNO,C.PACTINDEX PLANNO, A.ORDERNO,H.NAME_ PRODUCTLINE,A.ROLLNUMBER,A.MOTHERBOARDNUMBER,A.BILLETID,"
                //					+"A.STOVENO,A.PLY,A.WIDTH,A.LENGTH,A.THEORYWEIGHT,D.NAME_ FACEQUALITY,E.NAME_ BUGREASON,A.DETERMINANTCARDNUMBER,"
                //					+"F.NAME_ DETERMINANTRESULT,G.NAME_ CLIPTYPEPROCESS,A.SOURCEID,TO_CHAR(A.INTIME,'YYYY-MM-DD') INTIME,"
                //					+"B.BUTTRESS,B.CONDOLENUMBER,B.CONDOLELAYER ,B.BUTTRESSLAYER,"
                //					+"TO_CHAR(B.LOGICALLAYER) LOGICALLAYER,B.AREA,B.REMARK,A.PLY||'×'||A.WIDTH||'×'||A.LENGTH SPET,B.HANDREMARK "
                //					+"FROM KCJ_TURNOFFLIST A,KCJ_TURNOFFBUTTRESSLIST B,SEL_PACTDETAIL C,SCM_BASE_INFO D,SCM_BASE_INFO E,"
                //					+"SCM_BASE_INFO F,SCM_BASE_INFO G,SCM_BASE_INFO H "
                //					+"WHERE A.BILLETID=B.BILLETID AND A.ORDERNO=C.ORDERNO(+) AND A.STORAGESTATUS='501602' "
                //					+"AND A.ISVALID='1' AND A.FACEQUALITY=D.ID_(+) AND A.BUGREASON=E.ID_(+) "
                //					+"AND A.DETERMINANTRESULT=F.ID_(+) AND A.CLIPTYPEPROCESS=G.ID_(+) AND A.PRODUCTLINE=H.ID_(+) "
                //					+_Where ;

                //string sql=@"select T1.*, TO_CHAR(T2.creattime, 'YYYY-MM-DD HH24:MI:SS') creattime,T3.OSPET,T3.INSTEEL  FROM" +
                if (sstyle == "2")
                {
                    sql = @"select T1.*,T3.OSPET,T3.INSTEEL  FROM" +
                       "(SELECT C.PACTNO," +
                    
                       "       CASE WHEN A.BILLETID LIKE 'Z%' THEN (SELECT PLANORDERNO FROM KCZ_TURNOFFLIST WHERE BILLETID=A.BILLETID) " +
                       "       WHEN A.BILLETID LIKE 'H%' THEN (SELECT PLANORDERFORM FROM KCH_TURNOFFLIST WHERE BILLETID=A.BILLETID) " +
                       "       END PLANNO," +
                       "       CASE WHEN A.BILLETID LIKE 'Z%' THEN (SELECT PLANPLANNO FROM KCZ_TURNOFFLIST WHERE BILLETID=A.BILLETID) " +
                       "       WHEN A.BILLETID LIKE 'H%' THEN (SELECT PLANNUMBER FROM KCH_TURNOFFLIST WHERE BILLETID=A.BILLETID) " +
                       "       END ORDERNO, " +
                       "       H.NAME_ PRODUCTLINE," +
                       "       A.ROLLNUMBER," +
                       "       A.MOTHERBOARDNUMBER," +
                       "       A.YPLANNO," +
                       "       A.YORDERNO," +
                       "       A.BILLETID," +
                       "       A.STOVENO," +
                       "       A.PLY," +
                       "       A.WIDTH," +
                       "       A.LENGTH," +
                       "       A.THEORYWEIGHT," +
                       "       D.NAME_ FACEQUALITY," +
                       "       E.NAME_ BUGREASON," +
                       "       A.DETERMINANTCARDNUMBER," +
                       "       F.NAME_ DETERMINANTRESULT," +
                       "       G.NAME_ CLIPTYPEPROCESS," +
                       "       A.SOURCEID," +
                       "       TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME," +
                       "       B.BUTTRESS," +
                       "       B.CONDOLENUMBER," +
                       "       B.CONDOLELAYER," +
                       "       B.BUTTRESSLAYER," +
                       "       TO_CHAR(B.LOGICALLAYER) LOGICALLAYER," +
                       "       B.AREA," +
                       "       B.REMARK," +
                       "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET," +
                       "       B.HANDREMARK," +
                       "       TO_CHAR(C.SENDBEGINDATE, 'YYYY-MM-DD') SENDBEGINDATE,A.ORDERBUYER,K.NAME_ PRODUCT_NAME,M.NAME_ DETECTMARBOOKIN," +
                       "(SELECT TO_CHAR(MAX(CREATTIME),'YYYY-MM-DD HH24:MI:SS') FROM KCJ_TURNOFFMOVEBUTTRESSLIST W WHERE  W.BILLETID=A.BILLETID) CREATTIME, " +
                       "       CASE WHEN A.BILLETID LIKE 'Z%' THEN (SELECT CASE WHEN ZHPDBH LIKE 'ZHB%' THEN SUBSTR(ZHPDBH,5,6) ELSE SUBSTR(ZHPDBH,3,6) END ZHPDBH FROM KCZ_TURNOFFLIST WHERE BILLETID=A.BILLETID)  " +
                       "            WHEN A.BILLETID LIKE 'H%' THEN (SELECT CASE WHEN ZHPDBH LIKE 'ZC%' OR ZHPDBH LIKE 'ZJ%' OR ZHPDBH LIKE 'ZA%' THEN SUBSTR(ZHPDBH,3,6) ELSE  SUBSTR(ZHPDBH,5,6) END ZHPDBH FROM KCH_TURNOFFLIST WHERE BILLETID=A.BILLETID)  " +
                       "       END ZHPDBH,            " +
                       "       CASE WHEN A.BILLETID LIKE 'Z%' THEN (SELECT DETERMINANTREASON FROM KCZ_TURNOFFLIST WHERE BILLETID=A.BILLETID) " +
                       "            WHEN A.BILLETID LIKE 'H%' THEN (SELECT DETERMINANTREASON FROM KCH_TURNOFFLIST WHERE BILLETID=A.BILLETID) " +
                       "       END MEMO,BB.BUYERNAME,CC.STATIONNAME, " +
                       "       CASE WHEN A.BILLETID LIKE 'Z%' THEN (SELECT PLANCARDNUMBER FROM KCZ_TURNOFFLIST WHERE BILLETID=A.BILLETID) " +
                       "       WHEN A.BILLETID LIKE 'H%' THEN (SELECT PLANCARDNUMBER FROM KCH_TURNOFFLIST WHERE BILLETID=A.BILLETID) " +
                       "       END OSTEEL ," +
                       "       CASE WHEN A.BILLETID LIKE 'Z%' THEN (SELECT AA.HEIGHT FROM KCZ_TURNOFFLIST,sel_pactdetail AA  WHERE BILLETID=A.BILLETID AND PLANORDERNO = AA.ORDERNO) " +
                       "       WHEN A.BILLETID LIKE 'H%' THEN (SELECT AA.HEIGHT FROM KCH_TURNOFFLIST ,sel_pactdetail AA WHERE BILLETID=A.BILLETID AND PLANORDERFORM = AA.ORDERNO ) " +
                       "       END OPLY," +
                       "       CASE WHEN A.BILLETID LIKE 'Z%' THEN (SELECT AA.WIDTH FROM KCZ_TURNOFFLIST,sel_pactdetail AA  WHERE BILLETID=A.BILLETID AND PLANORDERNO = AA.ORDERNO) " +
                       "       WHEN A.BILLETID LIKE 'H%' THEN (SELECT AA.WIDTH FROM KCH_TURNOFFLIST ,sel_pactdetail AA WHERE BILLETID=A.BILLETID AND PLANORDERFORM = AA.ORDERNO ) " +
                       "       END OWIDTH," +
                       "       CASE WHEN A.BILLETID LIKE 'Z%' THEN (SELECT AA.LENGTH FROM KCZ_TURNOFFLIST,sel_pactdetail AA  WHERE BILLETID=A.BILLETID AND PLANORDERNO = AA.ORDERNO) " +
                       "       WHEN A.BILLETID LIKE 'H%' THEN (SELECT AA.LENGTH FROM KCH_TURNOFFLIST ,sel_pactdetail AA WHERE BILLETID=A.BILLETID AND PLANORDERFORM = AA.ORDERNO ) " +
                       "       END OLENGTH " +
                       "  FROM KCJ_TURNOFFLIST         A," +
                       "       KCJ_TURNOFFBUTTRESSLIST B," +
                       "       SEL_PACTDETAIL          C," +
                       "       SCM_BASE_INFO           D," +
                       "       SCM_BASE_INFO           E," +
                       "       SCM_BASE_INFO           F," +
                       "       SCM_BASE_INFO           G," +
                       "       SCM_BASE_INFO           H,SCM_BASE_INFO           K,SCM_BASE_INFO           M,SEL_BUYERBASEINFO BB,SEL_STATIONINFO CC  " +
                       " WHERE A.BILLETID = B.BILLETID" +
                       "   AND A.ORDERNO = C.ORDERNO(+)" +
                       "   AND A.STORAGESTATUS = '501602'" +
                       "   AND A.ISVALID = '1'" +
                       "   AND A.FACEQUALITY = D.ID_(+) AND  A.PRODUCT_NAME = K.ID_(+) AND C.BUYERCODE=BB.BUYERCODE(+) AND C.STATIONCODE=CC.STATIONCODE(+) " +
                       "   AND A.BUGREASON = E.ID_(+)" +
                       "   AND A.DETERMINANTRESULT = F.ID_(+)" +
                       "   AND A.CLIPTYPEPROCESS = G.ID_(+)" +
                       "   AND A.PRODUCTLINE = H.ID_(+) AND A.DETECTMARBOOKIN = M.ID_(+) AND B.AREA ='配送中心（新钢库）'" +
                       _Where +
                       " )T1" +
                        //" LEFT JOIN" + 
                        //" (SELECT MAX(creattime) CREATTIME,BILLETID from KCJ_TURNOFFMOVEBUTTRESSLIST GROUP BY BILLETID ) T2" + 
                        //" ON T1.BILLETID=T2.BILLETID" + 
                       " LEFT JOIN (SELECT PLY || '*' || WIDTH || '*' || LENGTH OSPET,BILLETID,INSTEEL FROM KCP_STORAGELIST)T3 ON T1.BILLETID = T3.BILLETID ";
                    //" ORDER BY T2.creattime asc ";
                }
                else
                {
                    sql = @"select T1.*,T3.OSPET,T3.INSTEEL  FROM" +
                        "(SELECT C.PACTNO," +
                        "       C.PACTINDEX PLANNO," +
                        "       A.ORDERNO," +
                        "       H.NAME_ PRODUCTLINE," +
                        "       A.ROLLNUMBER," +
                        "       A.MOTHERBOARDNUMBER," +
                        "       A.YPLANNO," +
                        "       A.YORDERNO," +
                        "       A.BILLETID," +
                        "       A.STOVENO," +
                        "       A.PLY," +
                        "       A.WIDTH," +
                        "       A.LENGTH," +
                        "       A.THEORYWEIGHT," +
                        "       D.NAME_ FACEQUALITY," +
                        "       E.NAME_ BUGREASON," +
                        "       A.DETERMINANTCARDNUMBER," +
                        "       F.NAME_ DETERMINANTRESULT," +
                        "       G.NAME_ CLIPTYPEPROCESS," +
                        "       A.SOURCEID," +
                        "       TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME," +
                        "       B.BUTTRESS," +
                        "       B.CONDOLENUMBER," +
                        "       B.CONDOLELAYER," +
                        "       B.BUTTRESSLAYER," +
                        "       TO_CHAR(B.LOGICALLAYER) LOGICALLAYER," +
                        "       B.AREA," +
                        "       B.REMARK," +
                        "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET," +
                        "       B.HANDREMARK," +
                        "       TO_CHAR(C.SENDBEGINDATE, 'YYYY-MM-DD') SENDBEGINDATE,A.ORDERBUYER,K.NAME_ PRODUCT_NAME,M.NAME_ DETECTMARBOOKIN," +
                        "(SELECT TO_CHAR(MAX(CREATTIME),'YYYY-MM-DD HH24:MI:SS') FROM KCJ_TURNOFFMOVEBUTTRESSLIST W WHERE  W.BILLETID=A.BILLETID) CREATTIME, " +
                        "       CASE WHEN A.BILLETID LIKE 'Z%' THEN (SELECT CASE WHEN ZHPDBH LIKE 'ZHB%' THEN SUBSTR(ZHPDBH,5,6) ELSE SUBSTR(ZHPDBH,3,6) END ZHPDBH FROM KCZ_TURNOFFLIST WHERE BILLETID=A.BILLETID)  " +
                        "            WHEN A.BILLETID LIKE 'H%' THEN (SELECT CASE WHEN ZHPDBH LIKE 'ZC%' OR ZHPDBH LIKE 'ZJ%' OR ZHPDBH LIKE 'ZA%' THEN SUBSTR(ZHPDBH,3,6) ELSE  SUBSTR(ZHPDBH,5,6) END ZHPDBH FROM KCH_TURNOFFLIST WHERE BILLETID=A.BILLETID)  " +
                        "       END ZHPDBH,            " +
                        "       CASE WHEN A.BILLETID LIKE 'Z%' THEN (SELECT DETERMINANTREASON FROM KCZ_TURNOFFLIST WHERE BILLETID=A.BILLETID) " +
                        "            WHEN A.BILLETID LIKE 'H%' THEN (SELECT DETERMINANTREASON FROM KCH_TURNOFFLIST WHERE BILLETID=A.BILLETID) " +
                        "       END MEMO,BB.BUYERNAME,CC.STATIONNAME " +
                        "  FROM KCJ_TURNOFFLIST         A," +
                        "       KCJ_TURNOFFBUTTRESSLIST B," +
                        "       SEL_PACTDETAIL          C," +
                        "       SCM_BASE_INFO           D," +
                        "       SCM_BASE_INFO           E," +
                        "       SCM_BASE_INFO           F," +
                        "       SCM_BASE_INFO           G," +
                        "       SCM_BASE_INFO           H,SCM_BASE_INFO           K,SCM_BASE_INFO           M  ,SEL_BUYERBASEINFO BB,SEL_STATIONINFO CC " +
                        " WHERE A.BILLETID = B.BILLETID" +
                        "   AND A.ORDERNO = C.ORDERNO(+)" +
                        "   AND A.STORAGESTATUS = '501602'" +
                        "   AND A.ISVALID = '1'" +
                        "   AND A.FACEQUALITY = D.ID_(+) AND  A.PRODUCT_NAME = K.ID_(+)" +
                        "   AND A.BUGREASON = E.ID_(+)" +
                        "   AND A.DETERMINANTRESULT = F.ID_(+)" +
                        "   AND A.CLIPTYPEPROCESS = G.ID_(+)" +
                        "   AND A.PRODUCTLINE = H.ID_(+) AND A.DETECTMARBOOKIN = M.ID_(+) AND C.BUYERCODE=BB.BUYERCODE(+) AND C.STATIONCODE=CC.STATIONCODE(+) AND B.AREA ='配送中心（线棒库）' " +
                        _Where +
                        " )T1" +
                        //" LEFT JOIN" + 
                        //" (SELECT MAX(creattime) CREATTIME,BILLETID from KCJ_TURNOFFMOVEBUTTRESSLIST GROUP BY BILLETID ) T2" + 
                        //" ON T1.BILLETID=T2.BILLETID" + 
                        " LEFT JOIN (SELECT PLY || '*' || WIDTH || '*' || LENGTH OSPET,BILLETID,INSTEEL FROM KCP_STORAGELIST)T3 ON T1.BILLETID = T3.BILLETID ";
                    //" ORDER BY T2.creattime asc ";}
                }

                System.Data.DataSet ds = this.DBManager.ExecuteQuery(sql, out err);
                if (ds != null && ds.Tables.Count == 1 && ds.Tables[0].Rows.Count > 0)
                {
                    ds.Tables[0].TableName = "KCJ_TURNOFFBUTTRESSLIST";
                    return new ReturnObject(ds);
                }
                else
                {
                    return new ReturnObject(null);
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, ex.ToString());
            }

        }

        public ReturnObject GetTurnoffButtress_SendType(string _Where, string strRoleID,string strlx)
        {
            try
            {
                string err = "";
                string sql = "";
                if (strlx == "1")
                {

                    sql = @"select T1.*,T3.OSPET,T3.INSTEEL  FROM" +
                        "(SELECT C.PACTNO," +
                        "       C.PACTINDEX PLANNO," +
                        "       A.ORDERNO," +
                        "       H.NAME_ PRODUCTLINE," +
                        "       A.ROLLNUMBER," +
                        "       A.MOTHERBOARDNUMBER," +
                       
                        "       A.BILLETID," +
                        "       A.STOVENO," +
                        "       A.PLY," +
                        "       A.WIDTH," +
                        "       A.LENGTH," +
                        "       A.THEORYWEIGHT," +
                        "       D.NAME_ FACEQUALITY," +
                      
                        "       A.DETERMINANTCARDNUMBER," +
                        "       F.NAME_ DETERMINANTRESULT," +
                        
                        "       A.SOURCEID," +
                        "       TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME," +
                        "       B.BUTTRESS," +
                        "       B.CONDOLENUMBER," +
                        "       B.CONDOLELAYER," +
                        "       B.BUTTRESSLAYER," +
                        "       TO_CHAR(B.LOGICALLAYER) LOGICALLAYER," +
                        "       B.AREA," +
                        "       B.REMARK," +
                        "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET," +
                        "       B.HANDREMARK," +
                        "       TO_CHAR(C.SENDBEGINDATE, 'YYYY-MM-DD') SENDBEGINDATE,A.ORDERBUYER,M.NAME_ DETECTMARBOOKIN" +
                  
               
                        "  FROM KCJ_TURNOFFLIST_ZW         A," +
                        "       KCJ_TURNOFFBUTTRESSLIST_ZW B," +
                        "       SEL_PACTDETAIL          C," +
                        "       SCM_BASE_INFO           D," +
                       
                        "       SCM_BASE_INFO           F," +
                        
                        "       SCM_BASE_INFO           H,SCM_BASE_INFO           M  " +
                        " WHERE A.BILLETID = B.BILLETID(+)   AND (A.BILLETID LIKE 'H%' OR A.BILLETID LIKE 'Z%') " +
                        "   AND A.ORDERNO = C.ORDERNO(+)" +
                        "   AND (A.SENDTYPE = '0' OR A.SENDTYPE ='1') " +
                        "   AND A.ISVALID = '1'" +
                        "   AND A.FACEQUALITY = D.ID_(+) " +
                 
                        "   AND A.DETERMINANTRESULT = F.ID_(+)" +
                       
                        "   AND A.PRODUCTLINE = H.ID_(+) AND A.DETECTMARBOOKIN = M.ID_(+) " +
                        _Where +
                        " )T1" +
                        " LEFT JOIN (SELECT PLY || '*' || WIDTH || '*' || LENGTH OSPET,BILLETID,INSTEEL FROM KCJ_STORAGELIST_ZW)T3 ON T1.BILLETID = T3.BILLETID ";
                }
                else
                {
                    sql = @"select T1.*,T3.OSPET,T3.INSTEEL  FROM" +
                         "(SELECT C.PACTNO," +
                         "       C.PACTINDEX PLANNO," +
                         "       A.ORDERNO," +
                         "       H.NAME_ PRODUCTLINE," +
                         "       A.ROLLNUMBER," +
                         "       A.MOTHERBOARDNUMBER," +

                         "       A.BILLETID," +
                         "       A.STOVENO," +
                         "       A.PLY," +
                         "       A.WIDTH," +
                         "       A.LENGTH," +
                         "       A.THEORYWEIGHT," +
                         "       D.NAME_ FACEQUALITY," +

                         "       A.DETERMINANTCARDNUMBER," +
                         "       F.NAME_ DETERMINANTRESULT," +

                         "       A.SOURCEID," +
                         "       TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME," +
                         "       B.BUTTRESS," +
                         "       B.CONDOLENUMBER," +
                         "       B.CONDOLELAYER," +
                         "       B.BUTTRESSLAYER," +
                         "       TO_CHAR(B.LOGICALLAYER) LOGICALLAYER," +
                         "       B.AREA," +
                         "       B.REMARK," +
                         "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET," +
                         "       B.HANDREMARK," +
                         "       TO_CHAR(C.SENDBEGINDATE, 'YYYY-MM-DD') SENDBEGINDATE,A.ORDERBUYER,M.NAME_ DETECTMARBOOKIN" +


                         "  FROM KCJ_TURNOFFLIST_ZW         A," +
                         "       KCJ_TURNOFFBUTTRESSLIST_ZW B," +
                         "       SEL_PACTDETAIL          C," +
                         "       SCM_BASE_INFO           D," +

                         "       SCM_BASE_INFO           F," +

                         "       SCM_BASE_INFO           H,SCM_BASE_INFO           M  " +
                         " WHERE A.BILLETID = B.BILLETID(+)   AND (A.BILLETID LIKE 'E%' OR A.BILLETID LIKE 'Y%' OR OR A.BILLETID LIKE 'Y%' ) " +
                         "   AND A.ORDERNO = C.ORDERNO(+)" +
                         "   AND (A.SENDTYPE = '0' OR A.SENDTYPE ='1') " +
                         "   AND A.ISVALID = '1'" +
                         "   AND A.FACEQUALITY = D.ID_(+) " +

                         "   AND A.DETERMINANTRESULT = F.ID_(+)" +

                         "   AND A.PRODUCTLINE = H.ID_(+) AND A.DETECTMARBOOKIN = M.ID_(+) " +
                         _Where +
                         " )T1" +
                         " LEFT JOIN (SELECT PLY || '*' || WIDTH || '*' || LENGTH OSPET,BILLETID,INSTEEL FROM KCJ_STORAGELIST_ZW)T3 ON T1.BILLETID = T3.BILLETID ";
                }

                System.Data.DataSet ds = this.DBManager.ExecuteQuery(sql, out err);
                if (ds != null && ds.Tables.Count == 1 && ds.Tables[0].Rows.Count > 0)
                {
                    ds.Tables[0].TableName = "KCJ_TURNOFFBUTTRESSLIST";
                    return new ReturnObject(ds);
                }
                else
                {
                    return new ReturnObject(null);
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, ex.ToString());
            }

        }



      

		/// <summary>
		/// 成品板块垛位信息调整
		/// </summary>
		/// <param name=" "></param>
		/// <returns></returns>
		public ReturnObject TurnoffButtressAdjust(ArrayList OButtress,ArrayList NButtress,ArrayList HandleInfo,string Remark,string RemarkType)
		{
			try
			{
				string err = "";
				Oracle.DataAccess.Client.OracleParameter pOButtress = new Oracle.DataAccess.Client.OracleParameter("vOButtress", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				Oracle.DataAccess.Client.OracleParameter pNButrress = new Oracle.DataAccess.Client.OracleParameter("vNButrress", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				Oracle.DataAccess.Client.OracleParameter pHandleInfo = new Oracle.DataAccess.Client.OracleParameter("vHandleInfo", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				Oracle.DataAccess.Client.OracleParameter pRemark = new Oracle.DataAccess.Client.OracleParameter("vRemark", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				Oracle.DataAccess.Client.OracleParameter pRemarkType = new Oracle.DataAccess.Client.OracleParameter("vRemarkType", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				Oracle.DataAccess.Client.OracleParameter pSuccessFlag = new Oracle.DataAccess.Client.OracleParameter("vSuccessFlag", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				
				pOButtress.Direction = ParameterDirection.Input;
				pNButrress.Direction = ParameterDirection.Input;
				pHandleInfo.Direction = ParameterDirection.Input;
				pRemark.Direction = ParameterDirection.Input;
				pRemarkType.Direction = ParameterDirection.Input;
				pSuccessFlag.Direction = ParameterDirection.Output;

				pOButtress.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;
				pNButrress.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;
				pHandleInfo.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;

				pOButtress.Value = OButtress.ToArray(typeof(string));
				pNButrress.Value = NButtress.ToArray(typeof(string));
				pHandleInfo.Value = HandleInfo.ToArray(typeof(string));
				pRemark.Value = Common.CheckNullStr(Remark);
				pRemarkType.Value = Common.CheckNullStr(RemarkType);

				int []OSizeInf = new int[OButtress.Count];
				for(int i =0;i< OButtress.Count;i++)
				{
					OSizeInf[i ] = 200;
				}
				pOButtress.Size = OButtress.Count;
				pOButtress.ArrayBindSize = OSizeInf;

				int []NSizeInf = new int[NButtress.Count];
				for(int i =0;i< NButtress.Count;i++)
				{
					NSizeInf[i ] = 200;
				}
				pNButrress.Size = NButtress.Count;
				pNButrress.ArrayBindSize = NSizeInf;

				int []HSizeInf = new int[HandleInfo.Count];
				for(int i =0;i< HandleInfo.Count;i++)
				{
					HSizeInf[i ] = 200;
				}
				pHandleInfo.Size = HandleInfo.Count;
				pHandleInfo.ArrayBindSize = HSizeInf;

				pSuccessFlag.Size = 400;
                ((STMes.DBManager)DBManagerList["ODPDBZW"]).ExecuteNonQuery_NoDBSever("KCJ_STORAGEMANAGER_WX.TurnoffMoveButtress", CommandType.StoredProcedure,
					new Oracle.DataAccess.Client.OracleParameter[]
					{pOButtress,pNButrress,pHandleInfo,pRemark,pRemarkType,pSuccessFlag}, out err);
				if(Common.CheckNullStr(pSuccessFlag.Value).Length>0 | Common.CheckNullStr(err).Length>0)
				{
					return new ReturnObject(null,1,pSuccessFlag.Value.ToString()+err);
				}
				else
				{
					return new ReturnObject('1');
				}
			}
			catch(System.Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(null,ex.ToString());
			}
		}





	}
}
