using System;
using System.Data;
using Core.Mes.ServerFrameWork;
using Core.Mes.IBaseInterface;
using System.Collections;
using Core.XgMes.Server.JGKC.TurnoffSendManager;
using Core.XgMes.Server.StorageCommon;

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

		public override int minValue
		{
			get
			{
				return 20;
			}
		}
		public override int maxValue
		{
			get
			{
				return 120;
			}
		}
        public ReturnObject GetOutStorageData(string where, System.Collections.ArrayList ps, System.Collections.ArrayList pg)
        {
            try
            {
                System.Data.DataSet rtndst = new DataSet();
                if (ps.Count > 0)
                {
                    for (int i = 0; i < ps.Count; i++)
                    {
                        string err = "";
                        string sql = ps[i].ToString() + where + pg[i].ToString();
                        System.Data.DataSet tmpdst = this.DBManager.ExecuteQuery(sql, out err);

                        if (tmpdst != null && tmpdst.Tables.Count == 1 && tmpdst.Tables[0].Rows.Count > 0)
                        {
                            //tmpdst.Tables[0].TableName = "KCJ_TURNOFFOUTSTORAGE";
                            rtndst.Merge(tmpdst.Copy());
                        }
                        if (err.Length > 0)
                        {
                            System.Diagnostics.Debug.WriteLine(err);
                            err = "";
                        }
                    }
                    if (rtndst.Tables.Count == 1)
                    {
                        return new ReturnObject(rtndst);
                    }
                }
                return new ReturnObject(null);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null);
            }
        }
        /// <summary>
        /// 获取明细编码
        /// </summary>
        /// <param name="type"></param>
        /// <param name="Year"></param>
        /// <returns></returns>
        public ReturnObject GetListCoding(string type, string Year)
        {
            try
            {
                string err = "";
                Oracle.DataAccess.Client.OracleParameter ptype = new Oracle.DataAccess.Client.OracleParameter("vtype", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pYear = new Oracle.DataAccess.Client.OracleParameter("vYear", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pListCoding = new Oracle.DataAccess.Client.OracleParameter("vListCoding", Oracle.DataAccess.Client.OracleDbType.Varchar2);

                ptype.Direction = ParameterDirection.Input;
                pYear.Direction = ParameterDirection.Input;
                pListCoding.Direction = ParameterDirection.Output;

                ptype.Value = type;
                pYear.Value = Year;

                pListCoding.Size = 400;
                ((STMes.DBManager)DBManagerList["ODPDBZW"]).ExecuteNonQuery_NoDBSever("KCJJB_GetListCoding", CommandType.StoredProcedure,
                    new Oracle.DataAccess.Client.OracleParameter[] { ptype, pYear, pListCoding }, out err);
                return new ReturnObject(FixDBManager.CheckNullStr(pListCoding.Value));
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null);
            }
        }
		public ReturnObject Turn_ZH(string _Where)
		{
			try
			{
				string strOut="";
               string Sql = "SELECT  decode(A.ISVALID,'2','√','')ISVALID," +
                    "A.INSTR_ROUTE ,A.CAL_WGT, " +
                    "A.ROUTE,A.PLANVEHICLEID,A.TRANS_CAR_NO, A.TRAINWAGON_NZ,A.TRANSFERLINE," +
					"A.LISTNUMBER,A.COIL_NO_ID,A.OLD_SAMPL_NO,A.STL_GRD,ORD_NO,A.CLEARFLAG,"+
					"A.ZSLAB_PLY,A.ZSLAB_WIDTH,A.ZSLAB_LENGTH,"+
                    "A.ZSLAB_NUM,ROUND(A.ZSLAB_WEIGHT*0.001,3)ZSLAB_WEIGHT,A.PICKSTORAGETIME,A.BJ_PACTNO,ROUND(a.XJJL_WEIGHT*0.001,3)XJJL_WEIGHT," +
                    "A.STOVENO,B.BUTTRESS,A.REMARK,A.CREATOR CREATETIME,A.PICKSTORAGEMAN,''TRANSTYPE FROM KCJ3_TURNOFFSENDLIST_ZW A," +
                    "KCJ3_TURNOFFBUTTRESSLIST_ZW B WHERE A.COIL_NO_ID=B.COIL_NO_ID  " + _Where;
				DataSet ds=this.DBManager.ExecuteQuery(Sql,out strOut);
				if(ds!=null&&ds.Tables.Count==1)
				{
					ds.Tables[0].TableName="KCJ3_TURNOFFSENDLIST";
					return new ReturnObject(ds,strOut);
				}
				return new ReturnObject(null);
			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(null,10004,ex.ToString());
			}
		}

        //去掉重复明细号
        public ReturnObject DistsctListnumber(string list)
        {
            try
            {
                string strOut = "";
                string Sql = "select distinct listnumber,SUM(ROUND(t.Xjjl_Weight*0.001,4))LNZL,T.BJ_PACTNO ,c.CUST_NM USERBM from KCJ3_TURNOFFSENDLIST_ZW t ,tbz00_customer@LINK_SQ c,tba01_ord_comm@LINK_SQ d where t.listnumber like  '%" + list + "%'  and  d.CUST_CD = c.CUST_CD(+) and T.ord_no = d.ord_no(+)  GROUP BY T.listnumber,T.BJ_PACTNO,c.CUST_NM ";
                DataSet ds = this.DBManager.ExecuteQuery(Sql, out strOut);
                if (ds != null && ds.Tables.Count == 1)
                {
                   
                    return new ReturnObject(ds, strOut);
                }
                return new ReturnObject(null);

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, 10004, ex.ToString());
            }

        }

        public ReturnObject DistsctListnumber2(string list)
        {
            try
            {
                string strOut = "";
                string Sql = "select distinct listnumber,SUM(ROUND(t.ZSLAB_WEIGHT*0.001,4))LNZL,T.BJ_PACTNO ,c.CUST_NM USERBM from KCJ3_TURNOFFSENDLIST_ZW t ,tbz00_customer@LINK_SQ c,tba01_ord_comm@LINK_SQ d where t.listnumber like  '%" + list + "%'  and  d.CUST_CD = c.CUST_CD(+) and T.ord_no = d.ord_no(+)  GROUP BY T.listnumber,T.BJ_PACTNO,c.CUST_NM ";
                DataSet ds = this.DBManager.ExecuteQuery(Sql, out strOut);
                if (ds != null && ds.Tables.Count == 1)
                {

                    return new ReturnObject(ds, strOut);
                }
                return new ReturnObject(null);

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, 10004, ex.ToString());
            }

        }

        public ReturnObject DistsctListnumber1(string list)
        {
            try
            {
                string strOut = "";
                string Sql = "select distinct listnumber,sum(T.cal_wgt)cal_wgt,T.BJ_PACTNO,c.CUST_NM USERBM from KCJ3_TURNOFFSENDLIST_ZW t,tbz00_customer c,tba01_ord_comm d where t.listnumber like  '" + list + "%'   and  d.CUST_CD = c.CUST_CD(+) and T.ord_no = d.ord_no(+) group by listnumber,T.BJ_PACTNO, c.CUST_NM ";//AND T.cal_wgt <>0
                DataSet ds = this.DBManager.ExecuteQuery(Sql, out strOut);
                if (ds != null && ds.Tables.Count == 1)
                {

                    return new ReturnObject(ds, strOut);
                }
                return new ReturnObject(null);

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, 10004, ex.ToString());
            }

        }
        public ReturnObject GetStorageButtress(string _Where, string strRoleID)
        {
            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_STORAGELIST A,KCJ_STORAGEBUTTRESSLIST 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='501002' "
                //					+"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 ;
                if (strRoleID == "bjbck")
                {
                    sql = @"select T1.*  FROM" +
                       "(SELECT C.PACTNO," +
                       "       C.PACTINDEX PLANNO," +
                       "       A.ORDERNO," +
                       "       A.YORDERNO," +
                       "       A.YPLANNO, " +
                       "       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,FUN_ISYXN_BJ(A.BILLETID,A.ORDERNO)YXN," +
                       "       G.NAME_ CLIPTYPEPROCESS," +
                       "       A.SOURCEID," +
                       "       TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME, TO_CHAR(m.sendbegindate, 'YYYY-MM-DD') SENDBEGINDATE," +
                       "       B.BUTTRESS," +
                       "       B.CONDOLENUMBER," +
                       "       B.CONDOLELAYER," +
                       "       B.BUTTRESSLAYER,C.SIGNCOLOR," +
                       "       TO_CHAR(B.LOGICALLAYER) LOGICALLAYER,codes2names(A.DETECTMARBOOKIN)DETECTMARBOOKIN," +
                       "       B.AREA," +
                       "       B.REMARK," +
                       "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET," +
                       "       B.HANDREMARK,I.NAME_ ATTESTATIONORGAN,A.ORDERBUYER,K.NAME_ PRODUCT_NAME,(SELECT MAX(TO_CHAR(creattime, 'YYYY-MM-DD HH24:MI:SS')) from kcj_storagemovebuttresslist z where a.BILLETID = z.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)  " +
                       "       FUN_GetJudgeTime(A.BILLETID) 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 DETERMINANTREASON " +
                       "  FROM KCJ_STORAGELIST         A," +
                       "       KCJ_STORAGEBUTTRESSLIST B," +
                       "       SEL_PACTDETAIL          C," +
                       "       SCM_BASE_INFO           D," +
                       "       SCM_BASE_INFO           E," +
                       "       SCM_BASE_INFO           F," +
                       "       SCM_BASE_INFO           G," +
                       "       SCM_BASE_INFO           H,sel_pactdetail m,SCM_BASE_INFO I,SCM_BASE_INFO           K  " +
                       " WHERE A.BILLETID = B.BILLETID" +
                       "   AND A.ORDERNO = C.ORDERNO(+) and a.orderno=m.orderno(+) " +
                       "   AND A.STORAGESTATUS = '501002'" +
                       "   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.ATTESTATIONORGAN = I.ID_(+)  AND B.AREA IN ('北京办库区','北京办(长沙库)','北京办库区5#','北京办区域','北京办区域5#库') " +
                       _Where +
                       " )T1" +

                       " ORDER BY T1.creattime asc ";
                }
                else if (strRoleID == "pszxck")
                {sql = @"select T1.*  FROM" +
                       "(SELECT C.PACTNO," +
                       "       C.PACTINDEX PLANNO," +
                       "       A.ORDERNO," +
                       "       A.YORDERNO," +
                       "       A.YPLANNO, " +
                       "       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,FUN_ISYXN_BJ(A.BILLETID,A.ORDERNO)YXN," +
                       "       G.NAME_ CLIPTYPEPROCESS," +
                       "       A.SOURCEID," +
                       "       TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME, TO_CHAR(m.sendbegindate, 'YYYY-MM-DD') SENDBEGINDATE," +
                       "       B.BUTTRESS," +
                       "       B.CONDOLENUMBER," +
                       "       B.CONDOLELAYER," +
                       "       B.BUTTRESSLAYER,C.SIGNCOLOR," +
                       "       TO_CHAR(B.LOGICALLAYER) LOGICALLAYER,codes2names(A.DETECTMARBOOKIN)DETECTMARBOOKIN," +
                       "       B.AREA," +
                       "       B.REMARK," +
                       "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET," +
                       "       B.HANDREMARK,I.NAME_ ATTESTATIONORGAN,A.ORDERBUYER,K.NAME_ PRODUCT_NAME,(SELECT MAX(TO_CHAR(creattime, 'YYYY-MM-DD HH24:MI:SS')) from kcj_storagemovebuttresslist z where a.BILLETID = z.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)  " +
                       "       FUN_GetJudgeTime(A.BILLETID) 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 DETERMINANTREASON " +
                       "  FROM KCP_STORAGELIST         A," +
                       "       KCJ_STORAGEBUTTRESSLIST B," +
                       "       SEL_PACTDETAIL          C," +
                       "       SCM_BASE_INFO           D," +
                       "       SCM_BASE_INFO           E," +
                       "       SCM_BASE_INFO           F," +
                       "       SCM_BASE_INFO           G," +
                       "       SCM_BASE_INFO           H,sel_pactdetail m,SCM_BASE_INFO I,SCM_BASE_INFO           K  " +
                       " WHERE A.BILLETID = B.BILLETID" +
                       "   AND A.ORDERNO = C.ORDERNO(+) and a.orderno=m.orderno(+) " +
                       "   AND A.STORAGESTATUS = '501002'" +
                       "   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.ATTESTATIONORGAN = I.ID_(+)  AND B.AREA ='配送中心（新钢库）' " +
                       _Where +
                       " " +

                       "  "
                       +" UNION "
                       + @"" +
                       " SELECT C.PACTNO," +
                       "       C.PACTINDEX PLANNO," +
                       "       A.ORDERNO," +
                       "       A.YORDERNO," +
                       "       A.YPLANNO, " +
                       "       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,FUN_ISYXN_BJ(A.BILLETID,A.ORDERNO)YXN," +
                       "       G.NAME_ CLIPTYPEPROCESS," +
                       "       A.SOURCEID," +
                       "       TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME, TO_CHAR(m.sendbegindate, 'YYYY-MM-DD') SENDBEGINDATE," +
                       "       B.BUTTRESS," +
                       "       B.CONDOLENUMBER," +
                       "       B.CONDOLELAYER," +
                       "       B.BUTTRESSLAYER,C.SIGNCOLOR," +
                       "       TO_CHAR(B.LOGICALLAYER) LOGICALLAYER,codes2names(A.DETECTMARBOOKIN)DETECTMARBOOKIN," +
                       "       B.AREA," +
                       "       B.REMARK," +
                       "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET," +
                       "       B.HANDREMARK,I.NAME_ ATTESTATIONORGAN,A.ORDERBUYER,K.NAME_ PRODUCT_NAME,(SELECT MAX(TO_CHAR(creattime, 'YYYY-MM-DD HH24:MI:SS')) from kcj_storagemovebuttresslist z where a.BILLETID = z.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)  " +
                       "       FUN_GetJudgeTime(A.BILLETID) 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 DETERMINANTREASON " +
                      "  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,sel_pactdetail m,SCM_BASE_INFO I,SCM_BASE_INFO           K  " +
                       " WHERE A.BILLETID = B.BILLETID" +
                       "   AND A.ORDERNO = C.ORDERNO(+) and a.orderno=m.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.ATTESTATIONORGAN = I.ID_(+)  AND B.AREA ='配送中心（新钢库）' " +
                       _Where +
                       " )T1" +

                       " ORDER BY T1.creattime asc "
                       ;}
                else if (strRoleID == "bjbxs" || strRoleID == "BCJGZX002" || strRoleID == "0011")
                {
                    sql = @"select T1.*  FROM" +
                       "(SELECT C.PACTNO," +
                       "       C.PACTINDEX PLANNO," +
                       "       A.ORDERNO," +
                       "       A.YORDERNO," +
                       "       A.YPLANNO, " +
                       "       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,FUN_ISYXN_BJ(A.BILLETID,A.ORDERNO)YXN," +
                       "       F.NAME_ DETERMINANTRESULT," +
                       "       G.NAME_ CLIPTYPEPROCESS," +
                       "       A.SOURCEID," +
                       "       TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME, TO_CHAR(m.sendbegindate, 'YYYY-MM-DD') SENDBEGINDATE," +
                       "       B.BUTTRESS," +
                       "       B.CONDOLENUMBER," +
                       "       B.CONDOLELAYER," +
                       "       B.BUTTRESSLAYER,C.SIGNCOLOR," +
                       "       TO_CHAR(B.LOGICALLAYER) LOGICALLAYER,codes2names(A.DETECTMARBOOKIN)DETECTMARBOOKIN," +
                       "       B.AREA," +
                       "       B.REMARK," +
                       "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET," +
                       "       B.HANDREMARK,I.NAME_ ATTESTATIONORGAN,A.ORDERBUYER,K.NAME_ PRODUCT_NAME,(SELECT MAX(TO_CHAR(creattime, 'YYYY-MM-DD HH24:MI:SS')) from kcj_storagemovebuttresslist z where a.BILLETID = z.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)  " +
                       "       FUN_GetJudgeTime(A.BILLETID) 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 DETERMINANTREASON " +
                       "  FROM KCJ_STORAGELIST         A," +
                       "       KCJ_STORAGEBUTTRESSLIST B," +
                       "       SEL_PACTDETAIL          C," +
                       "       SCM_BASE_INFO           D," +
                       "       SCM_BASE_INFO           E," +
                       "       SCM_BASE_INFO           F," +
                       "       SCM_BASE_INFO           G," +
                       "       SCM_BASE_INFO           H,sel_pactdetail m,SCM_BASE_INFO I,SCM_BASE_INFO           K  " +
                       " WHERE A.BILLETID = B.BILLETID" +
                       "   AND A.ORDERNO = C.ORDERNO(+) and a.orderno=m.orderno(+) " +
                       "   AND A.STORAGESTATUS = '501002'" +
                       "   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.ATTESTATIONORGAN = I.ID_(+)   " +
                       _Where +
                       " )T1" +

                       " ORDER BY T1.creattime asc ";
                }
                else
                {
                    sql = @"select T1.*  FROM" +
                        "(SELECT C.PACTNO," +
                        "       C.PACTINDEX PLANNO," +
                        "       A.ORDERNO," +
                        "       A.YORDERNO," +
                        "       A.YPLANNO, " +
                        "       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,FUN_ISYXN_BJ(A.BILLETID,A.ORDERNO)YXN," +
                        "       G.NAME_ CLIPTYPEPROCESS," +
                        "       A.SOURCEID," +
                        "       TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME, TO_CHAR(m.sendbegindate, 'YYYY-MM-DD') SENDBEGINDATE," +
                        "       B.BUTTRESS," +
                        "       B.CONDOLENUMBER," +
                        "       B.CONDOLELAYER," +
                        "       B.BUTTRESSLAYER,C.SIGNCOLOR," +
                        "       TO_CHAR(B.LOGICALLAYER) LOGICALLAYER,codes2names(A.DETECTMARBOOKIN)DETECTMARBOOKIN," +
                        "       B.AREA," +
                        "       B.REMARK," +
                        "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET," +
                        "       B.HANDREMARK,I.NAME_ ATTESTATIONORGAN,A.ORDERBUYER,K.NAME_ PRODUCT_NAME,(SELECT MAX(TO_CHAR(creattime, 'YYYY-MM-DD HH24:MI:SS')) from kcj_storagemovebuttresslist z where a.BILLETID = z.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 DETERMINANTREASON " +
                        "  FROM KCJ_STORAGELIST         A," +
                        "       KCJ_STORAGEBUTTRESSLIST B," +
                        "       SEL_PACTDETAIL          C," +
                        "       SCM_BASE_INFO           D," +
                        "       SCM_BASE_INFO           E," +
                        "       SCM_BASE_INFO           F," +
                        "       SCM_BASE_INFO           G," +
                        "       SCM_BASE_INFO           H,sel_pactdetail m,SCM_BASE_INFO I,SCM_BASE_INFO           K  " +
                        " WHERE A.BILLETID = B.BILLETID" +
                        "   AND A.ORDERNO = C.ORDERNO(+) and a.orderno=m.orderno(+) " +
                        "   AND A.STORAGESTATUS = '501002'" +
                        "   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.ATTESTATIONORGAN = I.ID_(+)   AND (B.AREA <> '北京办库区' OR B.AREA IS NULL)" +
                        _Where +
                        " )T1" +

                        " ORDER BY T1.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 Turn_Query(string _Where)
		{
			try
			{
					string strOut="";
                    /*string Sql = "SELECT  'FALSE' CHK,A.COIL_NO_ID,A.OLD_SAMPL_NO,A.SLAB_NO,A.ORD_NO,B.BUTTRESS," +
					"A.ORD_SEQ,A.STL_GRD,A.ZSLAB_PLY,A.ZSLAB_WIDTH,"+
					"A.ZSLAB_LENGTH,ZSLAB_NUM,A.STOVENO,A.BAHCT_NUMBER,"+
                    "ROUND(A.ZSLAB_WEIGHT*0.001,3)ZSLAB_WEIGHT,A.TOT_DEC_GRD,SX_BIAOZHUN,A.SERIAL_NUMBER,a.XJJL_WEIGHT," +
					"A.CRK_CD1,A.ZLZS_NO,"+
					"TRANS_CAR_NO,(SELECT NAME_ FROM SCM_BASE_INFO C WHERE C.ID_= A.INCLASSORDER)INCLASSORDER,"+
					"(SELECT NAME_ FROM SCM_BASE_INFO D WHERE D.ID_=A.INCLASSTEAM)INCLASSTEAM,A.CREATETIME,A.CREATOR FROM KCJ3_TURNOFFLIST_ZW A ,KCJ3_TURNOFFBUTTRESSLIST_ZW B "+
					"WHERE A.COIL_NO_ID=B.COIL_NO_ID AND A.STORAGESTATUS='501602' AND ISVALID='1' "+_Where;*/
                    string Sql = "SELECT  'FALSE' CHK,A.COIL_NO_ID,A.OLD_SAMPL_NO,A.SLAB_NO,A.ORD_NO,B.BUTTRESS," +
                       "A.ORD_SEQ,A.STL_GRD,A.ZSLAB_PLY,A.ZSLAB_WIDTH," +
                       "A.ZSLAB_LENGTH,ZSLAB_NUM,A.STOVENO,A.BAHCT_NUMBER," +
                       "ROUND(A.ZSLAB_WEIGHT*0.001,3)ZSLAB_WEIGHT,A.TOT_DEC_GRD,SX_BIAOZHUN,A.SERIAL_NUMBER,a.XJJL_WEIGHT," +
                       "A.CRK_CD1,A.ZLZS_NO," +
                       "TRANS_CAR_NO,(SELECT NAME_ FROM SCM_BASE_INFO C WHERE C.ID_= A.INCLASSORDER)INCLASSORDER," +
                       "(SELECT NAME_ FROM SCM_BASE_INFO D WHERE D.ID_=A.INCLASSTEAM)INCLASSTEAM,A.CREATETIME,A.CREATOR FROM KCJ3_TURNOFFLIST_ZW A ,KCJ3_TURNOFFBUTTRESSLIST_ZW B " +
                       "WHERE A.COIL_NO_ID=B.COIL_NO_ID AND A.STORAGESTATUS='501602' AND ISVALID='1' " + _Where;
				DataSet ds=this.DBManager.ExecuteQuery(Sql,out strOut);
				if(ds!=null&&ds.Tables.Count==1)
				{
					ds.Tables[0].TableName="KCJ3_TURNOFFLIST";
					return new ReturnObject(ds,strOut);
				}
				return new ReturnObject(null);

			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(null,10004,ex.ToString());
			}

		}

        public ReturnObject Turn_DY1(string _Where)
        {
            try
            {
                string strOut = "";
                string Sql = "SELECT count(*) OVER() cont, sum(ROUND(A.XJJL_WEIGHT*0.001,4))LNZL,''INSTR_ROUTE, " +
                           "''ROUTE,A.PLANVEHICLEID,A.TRANS_CAR_NO, ROUND(A.XJJL_WEIGHT*0.001,4)XJJL_WEIGHT,'' USERBM,'' AS USERNAME,A.CLEARFLAG," +
                           "A.LISTNUMBER,A.COIL_NO_ID,A.OLD_SAMPL_NO,A.STL_GRD,ORD_NO," +
                           "(A.ZSLAB_PLY||'*'||A.ZSLAB_WIDTH||'*'||A.ZSLAB_LENGTH)HUIGE,A.REMARK," +
                           "A.ZSLAB_NUM,ROUND(A.XJJL_WEIGHT*0.001,3)XJJL_WEIGHT, to_char(A.PICKSTORAGETIME,'YYYY-MM-DD')PICKSTORAGETIME,SX_BIAOZHUN," +
                           "A.STOVENO ,A.BJ_PACTNO FROM KCJ3_TURNOFFSENDLIST_ZW A," +
                           "KCJ3_TURNOFFBUTTRESSLIST_ZW B WHERE A.COIL_NO_ID=B.COIL_NO_ID AND A.ISVALID<>'0'" + _Where +
                           "group by A.INSTR_ROUTE,A.ROUTE,A.PLANVEHICLEID,A.TRANS_CAR_NO,A.LISTNUMBER,A.COIL_NO_ID,A.OLD_SAMPL_NO,A.STL_GRD,ORD_NO,A.BJ_PACTNO," +
                           "A.ZSLAB_PLY,A.ZSLAB_WIDTH,A.ZSLAB_LENGTH,A.REMARK,A.ZSLAB_NUM,A.XJJL_WEIGHT,A.PICKSTORAGETIME,SX_BIAOZHUN," +
                           " A.STOVENO,A.PRODNM_CD,A.CUST_CD,A.CAL_WGT,A.CLEARFLAG order by A.COIL_NO_ID ";
                DataSet ds = this.DBManager.ExecuteQuery(Sql, out strOut);
                if (ds != null && ds.Tables.Count == 1)
                {
                    ds.Tables[0].TableName = "DATA";
                    return new ReturnObject(ds, strOut);
                }
                return new ReturnObject(null);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, 10004, ex.ToString());
            }
        }

        public ReturnObject Turn_DY2(string _Where)
        {
            try
            {
                string strOut = "";
                string Sql = "SELECT count(*) OVER() cont, sum(ROUND(A.ZSLAB_WEIGHT*0.001,4))LNZL,''INSTR_ROUTE, " +
                           "''ROUTE,A.PLANVEHICLEID,A.TRANS_CAR_NO, ROUND(A.XJJL_WEIGHT*0.001,4)XJJL_WEIGHT,'' USERBM,'' AS USERNAME,A.CLEARFLAG," +
                           "A.LISTNUMBER,A.COIL_NO_ID,A.OLD_SAMPL_NO,A.STL_GRD,ORD_NO," +
                           "(A.ZSLAB_PLY||'*'||A.ZSLAB_WIDTH||'*'||A.ZSLAB_LENGTH)HUIGE,A.REMARK," +
                           "A.ZSLAB_NUM,ROUND(A.XJJL_WEIGHT*0.001,3)XJJL_WEIGHT, to_char(A.PICKSTORAGETIME,'YYYY-MM-DD')PICKSTORAGETIME,SX_BIAOZHUN," +
                           "A.STOVENO ,A.BJ_PACTNO FROM KCJ3_TURNOFFSENDLIST_ZW A," +
                           "KCJ3_TURNOFFBUTTRESSLIST_ZW B WHERE A.COIL_NO_ID=B.COIL_NO_ID AND A.ISVALID<>'0'" + _Where +
                           "group by A.INSTR_ROUTE,A.ROUTE,A.PLANVEHICLEID,A.TRANS_CAR_NO,A.LISTNUMBER,A.COIL_NO_ID,A.OLD_SAMPL_NO,A.STL_GRD,ORD_NO,A.BJ_PACTNO," +
                           "A.ZSLAB_PLY,A.ZSLAB_WIDTH,A.ZSLAB_LENGTH,A.REMARK,A.ZSLAB_NUM,A.XJJL_WEIGHT,A.PICKSTORAGETIME,SX_BIAOZHUN," +
                           " A.STOVENO,A.PRODNM_CD,A.CUST_CD,A.CAL_WGT,A.CLEARFLAG order by A.COIL_NO_ID ";
                DataSet ds = this.DBManager.ExecuteQuery(Sql, out strOut);
                if (ds != null && ds.Tables.Count == 1)
                {
                    ds.Tables[0].TableName = "DATA";
                    return new ReturnObject(ds, strOut);
                }
                return new ReturnObject(null);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, 10004, ex.ToString());
            }
        }


		public ReturnObject Turn_DY(string _Where)
		{
			try
			{
				string strOut="";
				string Sql="SELECT count(*) OVER() cont, sum(A.CAL_WGT)LNZL,''INSTR_ROUTE, "+
                           "''ROUTE,A.PLANVEHICLEID,A.TRANS_CAR_NO,sum(A.CAL_WGT)ZSLAB_WEIGHT,'' USERBM,'' USERNAME,A.CLEARFLAG," +
					       "A.LISTNUMBER,A.COIL_NO_ID,A.OLD_SAMPL_NO,A.STL_GRD,ORD_NO,"+
					       "(A.ZSLAB_PLY||'*'||A.ZSLAB_WIDTH||'*'||A.ZSLAB_LENGTH)HUIGE,A.REMARK,"+
					       "A.ZSLAB_NUM,ROUND(A.ZSLAB_WEIGHT*0.001,3)ZSLAB_WEIGHT, to_char(A.PICKSTORAGETIME,'YYYY-MM-DD')PICKSTORAGETIME,SX_BIAOZHUN,"+
					       "A.STOVENO ,A.BJ_PACTNO FROM KCJ3_TURNOFFSENDLIST_ZW A,"+
                           "KCJ3_TURNOFFBUTTRESSLIST_ZW B WHERE A.COIL_NO_ID=B.COIL_NO_ID AND A.ISVALID<>'0'" + _Where +
                           "group by A.INSTR_ROUTE,A.ROUTE,A.PLANVEHICLEID,A.TRANS_CAR_NO,A.LISTNUMBER,A.COIL_NO_ID,A.OLD_SAMPL_NO,A.STL_GRD,ORD_NO,A.BJ_PACTNO," +
                           "A.ZSLAB_PLY,A.ZSLAB_WIDTH,A.ZSLAB_LENGTH,A.REMARK,A.ZSLAB_NUM,A.ZSLAB_WEIGHT,A.PICKSTORAGETIME,SX_BIAOZHUN,"+
                           " A.STOVENO,A.PRODNM_CD,A.CUST_CD,A.CAL_WGT,A.CLEARFLAG order by A.COIL_NO_ID ";
				DataSet ds=this.DBManager.ExecuteQuery(Sql,out strOut);
				if(ds!=null&&ds.Tables.Count==1)
				{
					ds.Tables[0].TableName="DATA";
					return new ReturnObject(ds,strOut);
				}
				return new ReturnObject(null);
			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(null,10004,ex.ToString());
			}
		}
		public ReturnObject TranSend(ArrayList _SendInfo)
		{
			try
			{
				string err = "";
				Oracle.DataAccess.Client.OracleParameter pShi_Invno = new Oracle.DataAccess.Client.OracleParameter("vSendInfo", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				Oracle.DataAccess.Client.OracleParameter pSuccessFlag = new Oracle.DataAccess.Client.OracleParameter("vSuccessFlag", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				
				pShi_Invno.Direction = ParameterDirection.Input;
				pSuccessFlag.Direction = ParameterDirection.Output;

				pShi_Invno.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;
		
				pShi_Invno.Value = _SendInfo.ToArray(typeof(string));

				int []OSizeInf = new int[_SendInfo.Count];
				for(int i =0;i< _SendInfo.Count;i++)
				{
					OSizeInf[i ] = 200;
				}
				pShi_Invno.Size = _SendInfo.Count;
				pShi_Invno.ArrayBindSize = OSizeInf;
				pSuccessFlag.Size = 400;

                ((STMes.DBManager)DBManagerList["ODPDBZW"]).ExecuteNonQuery_NoDBSever("KCJ_STORAGEMANAGER_WX.TurnSendCand", CommandType.StoredProcedure,
					new Oracle.DataAccess.Client.OracleParameter[]
					{pShi_Invno,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(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(null,ex.ToString());
			}
		}



        public ReturnObject TranSend_Train(ArrayList _SendInfo)
        {
            try
            {
                string err = "";
                Oracle.DataAccess.Client.OracleParameter pShi_Invno = new Oracle.DataAccess.Client.OracleParameter("vSendInfo", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pSuccessFlag = new Oracle.DataAccess.Client.OracleParameter("vSuccessFlag", Oracle.DataAccess.Client.OracleDbType.Varchar2);

                pShi_Invno.Direction = ParameterDirection.Input;
                pSuccessFlag.Direction = ParameterDirection.Output;

                pShi_Invno.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;

                pShi_Invno.Value = _SendInfo.ToArray(typeof(string));

                int[] OSizeInf = new int[_SendInfo.Count];
                for (int i = 0; i < _SendInfo.Count; i++)
                {
                    OSizeInf[i] = 200;
                }
                pShi_Invno.Size = _SendInfo.Count;
                pShi_Invno.ArrayBindSize = OSizeInf;
                pSuccessFlag.Size = 400;

                ((STMes.DBManager)DBManagerList["ODPDB"]).ExecuteNonQuery_NoDBSever("KCJ3_COILMACHININGMANAGE.TurnSendCand_Train", CommandType.StoredProcedure,
                    new Oracle.DataAccess.Client.OracleParameter[] { pShi_Invno, 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 (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, ex.ToString());
            }
        }

        public ReturnObject Allicate(ArrayList OBilletId,string strOrderNo,string strName,string strPlid)
        {
            try
            {
                string err = "";
                Oracle.DataAccess.Client.OracleParameter pShi_Invno = new Oracle.DataAccess.Client.OracleParameter("vOBilletId", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pOrderNo = new Oracle.DataAccess.Client.OracleParameter("vOrderNo", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pName = new Oracle.DataAccess.Client.OracleParameter("vName", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pCx = new Oracle.DataAccess.Client.OracleParameter("vPlid", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pSuccessFlag = new Oracle.DataAccess.Client.OracleParameter("vSuccessFlag", Oracle.DataAccess.Client.OracleDbType.Varchar2);

                pShi_Invno.Direction = ParameterDirection.Input;
                pOrderNo.Direction = ParameterDirection.Input;
                pName.Direction = ParameterDirection.Input;
                pCx.Direction = ParameterDirection.Input;
                pSuccessFlag.Direction = ParameterDirection.Output;

                pShi_Invno.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;

                pShi_Invno.Value = OBilletId.ToArray(typeof(string));
                pOrderNo.Value = strOrderNo;
                pName.Value = strName;
                pCx.Value = strPlid;
                int[] OSizeInf = new int[OBilletId.Count];
                for (int i = 0; i < OBilletId.Count; i++)
                {
                    OSizeInf[i] = 200;
                }
                pShi_Invno.Size = OBilletId.Count;
                pShi_Invno.ArrayBindSize = OSizeInf;
                pOrderNo.Size = 40;

                pSuccessFlag.Size = 400;
                pName.Size = 40;
                ((STMes.DBManager)DBManagerList["ODPDB"]).ExecuteNonQuery_NoDBSever("KCJ3_COILMACHININGMANAGE.Allicate", CommandType.StoredProcedure,
                    new Oracle.DataAccess.Client.OracleParameter[] { pShi_Invno, pOrderNo,pName,pCx, 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 (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, ex.ToString());
            }
        }

		public ReturnObject SendCan_DEL(ArrayList _Ship_Invno,ArrayList _OtherInfo)
		{
			try
			{
				string err = "";
				Oracle.DataAccess.Client.OracleParameter pShi_Invno = new Oracle.DataAccess.Client.OracleParameter("vSHIP_INVNO", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				Oracle.DataAccess.Client.OracleParameter pOtherInfo = new Oracle.DataAccess.Client.OracleParameter("vOtherInfo", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				Oracle.DataAccess.Client.OracleParameter pSuccessFlag = new Oracle.DataAccess.Client.OracleParameter("vSuccessFlag", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				
				pShi_Invno.Direction = ParameterDirection.Input;
				pOtherInfo.Direction = ParameterDirection.Input;
				pSuccessFlag.Direction = ParameterDirection.Output;

				pShi_Invno.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;
				pOtherInfo.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;

				pShi_Invno.Value = _Ship_Invno.ToArray(typeof(string));
				pOtherInfo.Value = _OtherInfo.ToArray(typeof(string));

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

				int []NOSizeInf = new int[_OtherInfo.Count];
				for(int i =0;i< _OtherInfo.Count;i++)
				{
					NOSizeInf[i ] = 200;
				}
				pOtherInfo.Size = _OtherInfo.Count;
				pOtherInfo.ArrayBindSize = NOSizeInf;
				pSuccessFlag.Size = 400;

                ((STMes.DBManager)DBManagerList["ODPDBZW"]).ExecuteNonQuery_NoDBSever("KCJ_STORAGEMANAGER_WX.TurnSendCand_DEL", CommandType.StoredProcedure,
					new Oracle.DataAccess.Client.OracleParameter[]
					{pShi_Invno,pOtherInfo,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());
			}
		}
		public ReturnObject GetData(string _Data)
		{
			try
			{
				string strOut="";
				string Sql="SELECT A.INSTR_ROUTE,A.CAL_WGT, "+
					"A.ROUTE,A.PLANVEHICLEID,A.TRANS_CAR_NO, "+
					"A.LISTNUMBER,A.COIL_NO_ID,A.OLD_SAMPL_NO,A.STL_GRD,ORD_NO,A.CLEARFLAG,"+
					"A.ZSLAB_PLY,A.ZSLAB_WIDTH,A.ZSLAB_LENGTH,"+
					"A.ZSLAB_NUM,A.ZSLAB_WEIGHT,A.PICKSTORAGETIME,"+
					"(SELECT NAME_ FROM KCJ_BASEDATA E WHERE E.ID_=A.PICKSTORAGEMAN )PICKSTORAGEMAN,"+
					"(SELECT NAME_ FROM SCM_BASE_INFO D WHERE D.ID_=A.CLASSORDER)CLASSORDER,"+
					"(SELECT NAME_ FROM SCM_BASE_INFO T WHERE T.ID_=A.CLASSTEAM)CLASSTEAM,"+
					"A.STOVENO FROM KCJ3_TURNOFFSENDLIST A "+
					"WHERE A.LISTNUMBER='"+_Data+"'"+
					" AND A.ISVALID<>'0' AND ROWNUM=1 ";
				DataSet ds=this.DBManager.ExecuteQuery(Sql,out strOut);
				if(ds!=null&&ds.Tables.Count==1)
				{
					ds.Tables[0].TableName="KCJ3_TURNOFFSENDLIST";
					return new ReturnObject(ds,strOut);
				}
				return new ReturnObject(null);
			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(null,10004,ex.ToString());
			}
		}
		public ReturnObject CanUpdate(ArrayList _SendInfo)
		{
			try
			{
				string err = "";
				Oracle.DataAccess.Client.OracleParameter pShi_Invno = new Oracle.DataAccess.Client.OracleParameter("vSendInfo", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				Oracle.DataAccess.Client.OracleParameter pSuccessFlag = new Oracle.DataAccess.Client.OracleParameter("vSuccessFlag", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				
				pShi_Invno.Direction = ParameterDirection.Input;
				pSuccessFlag.Direction = ParameterDirection.Output;

				pShi_Invno.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;
		
				pShi_Invno.Value = _SendInfo.ToArray(typeof(string));

				int []OSizeInf = new int[_SendInfo.Count];
				for(int i =0;i< _SendInfo.Count;i++)
				{
					OSizeInf[i ] = 200;
				}
				pShi_Invno.Size = _SendInfo.Count;
				pShi_Invno.ArrayBindSize = OSizeInf;
				pSuccessFlag.Size = 400;

				((STMes.DBManager)DBManagerList["ODPDB"]).ExecuteNonQuery_NoDBSever("KCJ3_COILMACHININGMANAGE.CANUPDATE", CommandType.StoredProcedure,
					new Oracle.DataAccess.Client.OracleParameter[]
					{pShi_Invno,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(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(null,ex.ToString());
			}
        }


        public ReturnObject ZLUpdate(ArrayList _SendInfo)
        {
            try
            {
                string err = "";
                Oracle.DataAccess.Client.OracleParameter pShi_Invno = new Oracle.DataAccess.Client.OracleParameter("vSendInfo", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pSuccessFlag = new Oracle.DataAccess.Client.OracleParameter("vSuccessFlag", Oracle.DataAccess.Client.OracleDbType.Varchar2);

                pShi_Invno.Direction = ParameterDirection.Input;
                pSuccessFlag.Direction = ParameterDirection.Output;

                pShi_Invno.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;

                pShi_Invno.Value = _SendInfo.ToArray(typeof(string));

                int[] OSizeInf = new int[_SendInfo.Count];
                for (int i = 0; i < _SendInfo.Count; i++)
                {
                    OSizeInf[i] = 200;
                }
                pShi_Invno.Size = _SendInfo.Count;
                pShi_Invno.ArrayBindSize = OSizeInf;
                pSuccessFlag.Size = 400;

                ((STMes.DBManager)DBManagerList["ODPDB"]).ExecuteNonQuery_NoDBSever("KCJ3_COILMACHININGMANAGE.ZLUPDATE", CommandType.StoredProcedure,
                    new Oracle.DataAccess.Client.OracleParameter[] { pShi_Invno, 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 (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, ex.ToString());
            }
        }

        #region "订单申报查询 add by lyp 2010-11-23"
        public ReturnObject GetOrderData(string _Where)
        {
            try
            {
                string strOut = "";
                string DeClareDate = "";
                if (System.DateTime.Now.Hour < 9)
                {
                    DeClareDate = System.DateTime.Now.ToString("yyyyMMdd");
                }
                else
                    DeClareDate = System.DateTime.Now.AddDays(1).ToString("yyyyMMdd");


                string sql = "SELECT 'FALSE' FLAG,T1.*,T2.*,T3.*,NVL(T1.WEIGHT,0)-NVL(T2.SENDWEIGHT,0) QLWEIGHT,0 SBWEIGHT "
                           + "  FROM "
                           + "("
                           + " SELECT c.SM_CFNM DEST_CD, f.CUST_NM ORDCUST_CD,'' SYLX, b.ORD_NO, b.ORD_NO || b.ORD_SEQ ORDERNO, b.DEL_TO_DATE,"
                           + "b.H_SPEC_STL_GRD,b.ORD_THK,b.ORD_WTH,b.ORD_LEN LENGTH,ROUND(b.ORD_WGT * 0.001, 3) WEIGHT,"
                           + " NVL(TO_CHAR(b.ORD_THK_MIN),DECODE(b.ORD_THK,0,'无',NULL,'无',TO_CHAR(b.ORD_THK)))||'~'||NVL(TO_CHAR(b.ORD_THK_MAX),DECODE(b.ORD_THK,0,'无',NULL,'无',TO_CHAR(b.ORD_THK))) THICK,"
                           + " NVL(TO_CHAR(b.ORD_WTH_MIN),DECODE(b.ORD_WTH,0,'无',NULL,'无',TO_CHAR(b.ORD_WTH)))||'~'||NVL(TO_CHAR(b.ORD_WTH_MAX),DECODE(b.ORD_WTH,0,'无',NULL,'无',TO_CHAR(b.ORD_WTH))) WIDTH, "
                           + " NVL(TO_CHAR(b.ORD_LEN_MIN),DECODE(b.ORD_LEN,0,'无',NULL,'无',TO_CHAR(b.ORD_LEN)))||'~'||NVL(TO_CHAR(b.ORD_LEN_MAX),DECODE(b.ORD_LEN,0,'无',NULL,'无',TO_CHAR(b.ORD_LEN))) LENGTHUPPER,"
                           + " B.ORD_UNIT_WGT_MAX, b.ORD_UNIT_WGT_MIN,decode(b.prd_ty,'KP','开平','FJ','分卷','HK','花纹开平')CPLX,'' TXYQ,'' USEDSTAND,'' REMARK "
                           + "from tbe02_ord_prc@link_sq b ,tbz00_commcd@LINK_SQ    C,tbz00_customer@LINK_SQ  F "
                           + "where 1=1 AND B.DEST_CD = c.SM_CD(+) AND B.ORDCUST_CD = f.CUST_CD(+) "
                           + _Where
                           + " ) T1 "
                           + "LEFT JOIN "
                           + "("
                           + "SELECT L.ORD_NO || L.ORD_SEQ ORDERNO, SUM(ROUND(L.CAL_WGT*0.001,3)) SENDWEIGHT  "
                           + "FROM KCJ3_TURNOFFSENDLIST L, tbe02_ord_prc@link_sq b  "
                           + "WHERE L.ISVALID<>'0'   "
                           + "AND L.ORD_NO || L.ORD_SEQ = b.ORD_NO || b.ORD_SEQ  "
                            + _Where +
                            "GROUP BY L.ORD_NO || L.ORD_SEQ "
                          
                           +") T2 ON T1.ORDERNO=T2.ORDERNO "
                           + " LEFT JOIN "
                           + "("
                           + "SELECT "
                           + "SUM(CASE WHEN A.STORAGESTATUS='501602' THEN ROUND(A.ZSLAB_WEIGHT*0.001,3) ELSE 0 END) KCWEIGHT,"
                           + "A.ORD_NO || a.ORD_SEQ KCORDERNO ,"



                           + "SUM(CASE WHEN A.STORAGESTATUS='501602' AND A.DETERMINANTRESULT LIKE '401401%' THEN ROUND(A.ZSLAB_WEIGHT*0.001,3) ELSE 0 END) HGWEIGHT,"


                           + "SUM(CASE WHEN A.STORAGESTATUS='501602' AND A.DETERMINANTRESULT IS NULL THEN ROUND(A.ZSLAB_WEIGHT*0.001,3) ELSE 0 END) DPWEIGHT,"

                           + "SUM(CASE WHEN A.STORAGESTATUS='501602' AND A.DETERMINANTRESULT  LIKE '401403%' THEN ROUND(A.ZSLAB_WEIGHT*0.001,3) ELSE 0 END) BHGWEIGHT "
                           + "FROM KCJ3_TURNOFFLIST A,KCJ3_STUFFBUTTRESSLIST B WHERE A.STORAGESTATUS='501602' AND A.OLD_SAMPL_NO=B.OLD_SAMPL_NO AND "
                           + "(B.AREA<>'临时区域' AND B.AREA<>'1#库' AND B.AREA<>'2#库' ) GROUP BY A.ORD_NO || a.ORD_SEQ "
                           + " ) T3 ON T3.KCORDERNO=T1.ORDERNO "
                         
                       
                           + " LEFT JOIN "
                           + "( "
                           + "SELECT N.ORD_NO || N.ORD_SEQ ORDERFORMNUMBER,SUM(ROUND(N.CAL_WGT*0.001,3)) NSENDWEIGHT,SUM(1) NSENDNUM "
                           + "FROM KCJ3_TURNOFFSENDLIST N, tbe02_ord_prc@link_sq b "
                           + "WHERE N.ISVALID<>'0'  AND N.ORD_NO || N.ORD_SEQ = b.ORD_NO || b.ORD_SEQ  "
                           + "  "
                            + _Where
                           + "GROUP BY N.ORD_NO ||N.ORD_SEQ "

                           + ") T6 ON T1.ORDERNO= T6.ORDERFORMNUMBER";
                //string sql =
                //    @" SELECT  'FALSE'  FLAG, " +
                //    "               T1.*, " +
                //    "               T2.*, " +
                //    "               T3.*, " +
                //    "               T4.*, " +
                //    "               NVL(T1.QUANTITY,  0)  -  NVL(T2.SENDNUM,  0)  -  NVL(T6.NSENDNUM,  0)  QLNUM, " +
                //    "               NVL(T1.WEIGHT,  0)  -  NVL(T2.SENDWEIGHT,  0)  -  NVL(T6.NSENDWEIGHT,  0)  QLWEIGHT, " +
                //    "               0  SBNUM, " +
                //    "               0  SBWEIGHT, " +
                //    "               T6.NSENDNUM, " +
                //    "               T6.NSENDWEIGHT " +
                //    "     FROM  (SELECT  C.STATIONNAME, " +
                //    "                               B.INCEPTCORPNAME, " +
                //    "                               A.PACTNO, " +
                //    "                               A.PACTINDEX, " +
                //    "                               A.ORDERNO, " +
                //    "                               A.STEELCODE, " +
                //    "                               A.HEIGHT, " +
                //    "                               A.WIDTH, " +
                //    "                               A.LENGTH, " +
                //    "                               H.NAME_  FIXSIZE, " +
                //    "                               D.NAME_  PRI, " +
                //    "                               E.NAME_  SENDTYPE, " +
                //    "                               A.QUANTITY, " +
                //    "                               A.WEIGHT, " +
                //    "                               (CASE " +
                //    "                                   WHEN  A.SENDTYPE  =  '102102'  THEN " +
                //    "                                     (1  -  NVL(A.WEIGHTLOWER,  0))  *  A.WEIGHT " +
                //    "                                   ELSE " +
                //    "                                     (CASE " +
                //    "                                   WHEN  NVL(A.WEIGHTLOWER,  0)  >  1  THEN " +
                //    "                                     A.QUANTITY  -  WEIGHTLOWER " +
                //    "                                   ELSE " +
                //    "                                     ROUND((1  -  NVL(A.WEIGHTLOWER,  0))  *  A.QUANTITY,  0) " +
                //    "                               END)  END)  WEIGHTLOWER, " +
                //    "                               (CASE " +
                //    "                                   WHEN  A.SENDTYPE  =  '102102'  THEN " +
                //    "                                     (1  +  NVL(A.WEIGHTUPPER,  0))  *  A.WEIGHT " +
                //    "                                   ELSE " +
                //    "                                     (CASE " +
                //    "                                   WHEN  NVL(A.WEIGHTUPPER,  0)  >  1  THEN " +
                //    "                                     A.QUANTITY  +  WEIGHTUPPER " +
                //    "                                   ELSE " +
                //    "                                     ROUND((1  +  NVL(A.WEIGHTUPPER,  0))  *  A.QUANTITY,  0) " +
                //    "                               END)  END)  WEIGHTUPPER, " +
                //    "                               G.NAME_  USEDSTAND, " +
                //    "                               A.REMARK, " +
                //    "                               A.SIGNCOLOR, " +
                //    "                               KCH_TURNOFFSEND_K.GetOrderEspRequset_P(A.ORDERNO)  ESPINFO, " +
                //    "                               I.NAME_  SENDSTATUS, " +
                //    "                               TO_CHAR(A.SENDBEGINDATE,  'YY-MM-DD')  SENDBEGINDATE, " +
                //    "                               SEL_ZBBALANCE.GetSendStatus(A.STANDROLLER)  STANDROLLER, " +
                //    "                               J.NAME_  CHECKORG, " +
                //    "                               DECODE(K.LOADDOCK  ||  K.UNLOADDOCK, " +
                //    "                                             NULL, " +
                //    "                                             NULL, " +
                //    "                                             K.LOADDOCK  ||  '-'  ||  K.UNLOADDOCK)  SYLX " +
                //    "                     FROM  SEL_PACTDETAIL          A, " +
                //    "                               SEL_INCEPTCORPINFO  B, " +
                //    "                               SEL_STATIONINFO        C, " +
                //    "                               SCM_BASE_INFO            D, " +
                //    "                               SCM_BASE_INFO            E, " +
                //    "                               SCM_BASE_INFO            F, " +
                //    "                               SCM_BASE_INFO            G, " +
                //    "                               SCM_BASE_INFO            H, " +
                //    "                               SCM_BASE_INFO            I, " +
                //    "                               SCM_BASE_INFO            J, " +
                //    "                               SEL_STATIONINFO        K " +
                //    "                   WHERE  A.INCEPTCORPCODE  =  B.INCEPTCORPCODE(+) " +
                //    "                       AND  A.STATIONCODE  =  C.STATIONCODE(+) " +
                //    "                       AND  A.PRI  =  D.ID_(+) " +
                //    "                       AND  A.ORDERSTATUS  <  '103820' " +
                //    "                       AND  A.SENDTYPE  =  E.ID_(+) " +
                //    "                       AND  A.ISCHECKSCAR  =  F.ID_(+) " +
                //    "                       AND  A.USEDSTAND  =  G.ID_(+) " +
                //    "                       AND  A.FIXSIZE  =  H.ID_(+) " +
                //    "                       AND  A.SENDSTATUS  =  I.ID_(+) " +
                //    "                       AND  A.SALEAFFIRMFLAG  =  '1' " +
                //    "                       AND  A.CHECKORG  =  J.ID_(+) " +
                //    "                       AND  A.DOCKCODE  =  K.STATIONCODE(+) " +
                //    _Where +
                //    ") T1 " +
                //    "     LEFT  JOIN  (SELECT  L.ORDERFORMNUMBER, " +
                //    "                                         COUNT(L.SERIALNUMBER)  SENDNUM, " +
                //    "                                         SUM(L.ADDWEIGHT)  SENDWEIGHT " +
                //    "                               FROM  KCJ_TURNOFFSENDLIST  L, " +
                //    "                                         SEL_PACTDETAIL            A, " +
                //    "                                         SEL_INCEPTCORPINFO    B, " +
                //    "                                         SEL_STATIONINFO          C " +
                //    "                             WHERE  L.ISVALID  <>  '0' " +
                //    "                                 AND  L.DUMMYSENDFLAG  <>  '1' " +
                //    "                                 AND  L.SENDTYPE  =  '0' " +
                //    "                                 AND  L.ORDERFORMNUMBER  =  A.ORDERNO " +
                //    "                                 AND  A.INCEPTCORPCODE  =  B.INCEPTCORPCODE " +
                //    "                                 AND  A.STATIONCODE  =  C.STATIONCODE " +
                //    "                                 AND  A.SALEAFFIRMFLAG  =  '1' " +
                //    "                                 AND  A.ORDERSTATUS  <  '103820' " +
                //    _Where +
                //    "                             GROUP  BY  L.ORDERFORMNUMBER)  T2  ON  T1.ORDERNO = T2.ORDERFORMNUMBER " +
                //    "     LEFT  JOIN  (SELECT  SUM(1)  KCNUM, " +
                //    "                                         SUM(A.THEORYWEIGHT)  KCWEIGHT, " +
                //    "                                         A.ORDERNO  KCORDERNO, " +
                //    "                                         SUM(CASE " +
                //    "                                                     WHEN  A.DETERMINANTRESULT  LIKE  '401401%'  THEN " +
                //    "                                                       1 " +
                //    "                                                     ELSE " +
                //    "                                                       0 " +
                //    "                                                 END)  HGNUM, " +
                //    "                                         SUM(CASE " +
                //    "                                                     WHEN  A.DETERMINANTRESULT  LIKE  '401401%'  THEN " +
                //    "                                                       A.THEORYWEIGHT " +
                //    "                                                     ELSE " +
                //    "                                                       0 " +
                //    "                                                 END)  HGWEIGHT, " +
                //    "                                         SUM(CASE " +
                //    "                                                     WHEN  A.DETERMINANTRESULT  =  '40140103'  THEN " +
                //    "                                                       1 " +
                //    "                                                     ELSE " +
                //    "                                                       0 " +
                //    "                                                 END)  RZNUM, " +
                //    "                                         SUM(CASE " +
                //    "                                                     WHEN  A.DETERMINANTRESULT  =  '40140103'  THEN " +
                //    "                                                       A.THEORYWEIGHT " +
                //    "                                                     ELSE " +
                //    "                                                       0 " +
                //    "                                                 END)  RZWEIGHT, " +
                //    "                                         SUM(CASE " +
                //    "                                                     WHEN  A.DETERMINANTRESULT  IS  NULL  THEN " +
                //    "                                                       1 " +
                //    "                                                     ELSE " +
                //    "                                                       0 " +
                //    "                                                 END)  DPNUM, " +
                //    "                                         SUM(CASE " +
                //    "                                                     WHEN  A.DETERMINANTRESULT  IS  NULL  THEN " +
                //    "                                                       A.THEORYWEIGHT " +
                //    "                                                     ELSE " +
                //    "                                                       0 " +
                //    "                                                 END)  DPWEIGHT, " +
                //    "                                         SUM(CASE " +
                //    "                                                     WHEN  A.DETERMINANTRESULT  NOT  LIKE  '401401%'  THEN " +
                //    "                                                       1 " +
                //    "                                                     ELSE " +
                //    "                                                       0 " +
                //    "                                                 END)  BHGNUM, " +
                //    "                                         SUM(CASE " +
                //    "                                                     WHEN  A.DETERMINANTRESULT  NOT  LIKE  '401401%'  THEN " +
                //    "                                                       A.THEORYWEIGHT " +
                //    "                                                     ELSE " +
                //    "                                                       0 " +
                //    "                                                 END)  BHGWEIGHT " +
                //    "                               FROM  KCJ_TURNOFFLIST  A,  KCJ_TURNOFFBUTTRESSLIST  B " +
                //    "                             WHERE  A.STORAGESTATUS  =  '501602' " +
                //    "                                 AND  A.BILLETID  =  B.BILLETID " +
                //    "                             GROUP  BY  A.ORDERNO)  T3  ON  T3.KCORDERNO  =  T1.ORDERNO " +
                //    "     LEFT  JOIN  (SELECT  SUM(DISTRIBUTEMASSNUMBER)  DCLNUM, " +
                //    "                                         SUM(DISTRIBUTEWEIGHT)  DCLWEIGHT," +
                //    "                                         ORDERFORMNUMBER  DCLORDERNO " +
                //    "                               FROM  KCJ_TURNOFFCANSENDLIST " +
                //    "                             WHERE  ISVALID  =  '1' " +
                //    "                               AND  DECLARENUMBER  LIKE  '" + DeClareDate + "%' " +
                //    "                             GROUP  BY  ORDERFORMNUMBER)  T4  ON  T1.ORDERNO  =  T4.DCLORDERNO " +
                //    "     LEFT  JOIN  (SELECT  N.ORDERFORMNUMBER, " +
                //    "                                         COUNT(N.SERIALNUMBER)  NSENDNUM, " +
                //    "                                         SUM(N.ADDWEIGHT)  NSENDWEIGHT " +
                //    "                               FROM  KCJ_TURNOFFSENDLIST  N, " +
                //    "                                         SEL_PACTDETAIL            A, " +
                //    "                                         SEL_INCEPTCORPINFO    B, " +
                //    "                                         SEL_STATIONINFO          C " +
                //    "                             WHERE  N.ISVALID  <>  '0' " +
                //    "                                 AND  N.DUMMYSENDFLAG  <>  '1' " +
                //    "                                   AND  N.SENDTYPE  =  '1' " +
                //    "                                 AND  N.ORDERFORMNUMBER  =  A.ORDERNO " +
                //    "                                 AND  A.INCEPTCORPCODE  =  B.INCEPTCORPCODE " +
                //    "                                 AND  A.STATIONCODE  =  C.STATIONCODE " +
                //    "                                 AND  A.SALEAFFIRMFLAG  =  '1' " +
                //    "                                 AND  A.ORDERSTATUS  <  '103820' " +
                //    _Where +
                //    "                             GROUP  BY  N.ORDERFORMNUMBER)  T6  ON  T1.ORDERNO = T6.ORDERFORMNUMBER ";

                DataSet ds = this.DBManager.ExecuteQuery(sql, out strOut);
                ds.Tables[0].TableName = "SEL_ORDER";
                return new ReturnObject(ds, strOut);

            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, "数据库连接错");
            }
        }
        #endregion
        #region "订单申报 add by lyp 2010-11-23"
        public ReturnObject CommitDeclare(ArrayList Declare,ArrayList Pactno, ArrayList Weight, string type, string remark, string user, string DeclareDate, string Line)
        {
            try
            {
                string err = "";
                Oracle.DataAccess.Client.OracleParameter pDeclareInfo = new Oracle.DataAccess.Client.OracleParameter("vDeclareInfo", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pPactno = new Oracle.DataAccess.Client.OracleParameter("vPactno", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pDeclareWeight = new Oracle.DataAccess.Client.OracleParameter("vDeclareWeight", Oracle.DataAccess.Client.OracleDbType.Decimal);
                Oracle.DataAccess.Client.OracleParameter pDeclareType = new Oracle.DataAccess.Client.OracleParameter("vDeclareType", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pDeclareRemark = new Oracle.DataAccess.Client.OracleParameter("vDeclareRemark", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pDeclareMan = new Oracle.DataAccess.Client.OracleParameter("vDeclareMan", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pDDate = new Oracle.DataAccess.Client.OracleParameter("vDDate", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pLine = new Oracle.DataAccess.Client.OracleParameter("vPline", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pSuccessFlag = new Oracle.DataAccess.Client.OracleParameter("vSuccessFlag", Oracle.DataAccess.Client.OracleDbType.Varchar2);

                pDeclareInfo.Direction = ParameterDirection.Input;
                pPactno.Direction = ParameterDirection.Input;
                pDeclareWeight.Direction = ParameterDirection.Input;
                pDeclareType.Direction = ParameterDirection.Input;
                pDeclareRemark.Direction = ParameterDirection.Input;
                pDeclareMan.Direction = ParameterDirection.Input;
                pDDate.Direction = ParameterDirection.Input;
                pLine.Direction = ParameterDirection.Input;
                pSuccessFlag.Direction = ParameterDirection.Output;

                pDeclareInfo.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;
                pPactno.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;
                pDeclareWeight.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;

                pDeclareInfo.Value = Declare.ToArray(typeof(string));
                pPactno.Value = Pactno.ToArray(typeof(string));
                pDeclareWeight.Value = Weight.ToArray(typeof(System.Decimal));
                pDeclareType.Value = type;
                pDeclareRemark.Value = remark;
                pDeclareMan.Value = user;
                pDDate.Value = DeclareDate;
                pLine.Value = Line;

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



                int[] OSizeInf1 = new int[Pactno.Count];
                for (int i = 0; i < Pactno.Count; i++)
                {
                    OSizeInf1[i] = 200;
                }
                pPactno.Size = Pactno.Count;
                pPactno.ArrayBindSize = OSizeInf1;


                int[] WSizeInf = new int[Weight.Count];
                for (int i = 0; i < Weight.Count; i++)
                {
                    WSizeInf[i] = 200;
                }
                pDeclareWeight.Size = Weight.Count;
                pDeclareWeight.ArrayBindSize = WSizeInf;


                pSuccessFlag.Size = 400;
                ((STMes.DBManager)DBManagerList["ODPDB"]).ExecuteNonQuery_NoDBSever("KCJ3_COILMACHININGMANAGE.CANSENDDECLARE_P", CommandType.StoredProcedure,
                    new Oracle.DataAccess.Client.OracleParameter[] { pDeclareInfo,pPactno, pDeclareWeight, pDeclareType, pDeclareRemark, pDeclareMan, pDDate, pLine, pSuccessFlag }, out err);
                if (FixDBManager.CheckNullStr(pSuccessFlag.Value).Length > 0 | FixDBManager.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);
            }
        }
        #endregion
        #region "修改、删除申报信息 add by lyp 2010-11-23"
        public ReturnObject AdjustDeclare(ArrayList DeclareNO, ArrayList DeclareDate,  ArrayList Weight, string type, string user)
        {
            try
            {
                string err = "";
                Oracle.DataAccess.Client.OracleParameter pDeclareNO = new Oracle.DataAccess.Client.OracleParameter("vDeclareNO", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pDeclareDate = new Oracle.DataAccess.Client.OracleParameter("vDeclareDate", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                //Oracle.DataAccess.Client.OracleParameter pAdjustNum = new Oracle.DataAccess.Client.OracleParameter("vAdjustNum", Oracle.DataAccess.Client.OracleDbType.Decimal);
                Oracle.DataAccess.Client.OracleParameter pAdjustWeight = new Oracle.DataAccess.Client.OracleParameter("vAdjustWeight", Oracle.DataAccess.Client.OracleDbType.Decimal);
                Oracle.DataAccess.Client.OracleParameter pAdjustType = new Oracle.DataAccess.Client.OracleParameter("vAdjustType", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pAdjustMan = new Oracle.DataAccess.Client.OracleParameter("vAdjustMan", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pSuccessFlag = new Oracle.DataAccess.Client.OracleParameter("vSuccessFlag", Oracle.DataAccess.Client.OracleDbType.Varchar2);

                pDeclareNO.Direction = ParameterDirection.Input;
                pDeclareDate.Direction = ParameterDirection.Input;
               // pAdjustNum.Direction = ParameterDirection.Input;
                pAdjustWeight.Direction = ParameterDirection.Input;
                pAdjustType.Direction = ParameterDirection.Input;
                pAdjustMan.Direction = ParameterDirection.Input;
                pSuccessFlag.Direction = ParameterDirection.Output;

                pDeclareNO.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;
                pDeclareDate.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;
                //pAdjustNum.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;
                pAdjustWeight.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray;

                pDeclareNO.Value = DeclareNO.ToArray(typeof(string));
                pDeclareDate.Value = DeclareDate.ToArray(typeof(string));
                //pAdjustNum.Value = Num.ToArray(typeof(System.Decimal));
                pAdjustWeight.Value = Weight.ToArray(typeof(System.Decimal));
                pAdjustType.Value = type;
                pAdjustMan.Value = user;

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

                int[] DSizeInf = new int[DeclareDate.Count];
                for (int i = 0; i < DeclareDate.Count; i++)
                {
                    DSizeInf[i] = 200;
                }
                pDeclareDate.Size = DeclareDate.Count;
                pDeclareDate.ArrayBindSize = DSizeInf;

                //int[] NSizeInf = new int[Num.Count];
                //for (int i = 0; i < Num.Count; i++)
                //{
                //    NSizeInf[i] = 200;
                //}
                //pAdjustNum.Size = Weight.Count;
                //pAdjustNum.ArrayBindSize = NSizeInf;

                int[] WSizeInf = new int[Weight.Count];
                for (int i = 0; i < Weight.Count; i++)
                {
                    WSizeInf[i] = 200;
                }
                pAdjustWeight.Size = Weight.Count;
                pAdjustWeight.ArrayBindSize = WSizeInf;


                pSuccessFlag.Size = 400;
                ((STMes.DBManager)DBManagerList["ODPDB"]).ExecuteNonQuery_NoDBSever("KCJ3_COILMACHININGMANAGE.CANSENDADJUST_P", CommandType.StoredProcedure,
                    new Oracle.DataAccess.Client.OracleParameter[] { pDeclareNO, pDeclareDate, pAdjustWeight, pAdjustType, pAdjustMan, pSuccessFlag }, out err);
                if (FixDBManager.CheckNullStr(pSuccessFlag.Value).Length > 0 | FixDBManager.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);
            }
        }
        #endregion
        #region "申报信息查询 add by lyp 2010-11-23"
        public ReturnObject GetDeclareData(string _Where)
        {
            try
            {
                string strOut = "";
                string sql =
                    @" SELECT  'FALSE'  FLAG, " +
                    "               c.SM_CFNM STATIONNAME,    " +
                    "               f.CUST_NM INCEPTCORPNAME, " +
                    "               a.ORD_NO PACTNO,    " +
               
                    "               A.ORD_NO || a.ORD_SEQ ORDERNO,   " +
                    "               a.SPEC_STL_GRD STEELCODE, " +
                    "               a.ORD_THK HEIGHT, " +
                    "               a.ORD_WTH WIDTH, " +
                    "               a.ORD_LEN LENGTH,  " +



                    "               ROUND(a.ORD_WGT *0.001,3) WEIGHT, " +
                    "              a.ORD_DEVLMT_DATE SENDBEGINDATE,  " +
           
                    "               D.DISTRIBUTEWEIGHT, " +
                    "               D.DECLARENUMBER, " +
                    "               TO_CHAR(D.SYSTIME,  'YYYY-MM-DD HH24:MI:SS')  SYSTIME, " +
      
                    "               D.REMARK " +
                    "     FROM  tba01_ord_line@LINK_SQ                  A, " +
                    "                tbe02_ord_prc@LINK_SQ           B, " +
                    "                tbz00_commcd@LINK_SQ             C, " +
                    "               KCJ3_TURNOFFCANSENDLIST  D, " +

                    "                tbz00_customer@LINK_SQ                     F " +
                    //"               tbz00_commcd@LINK_SQ                         G " +

                    "   WHERE  a.ORD_NO = b.ORD_NO " +
                    "         AND  a.DEST_PCD= c.SM_CD(+)  " +
                    "       AND  a.RE_CUST_CD= f.CUST_CD(+)    " +
                    "      AND  a.ORD_NO || a.ORD_SEQ  =  D.ORDERFORMNUMBER   " +

                    "         and a.ORD_SEQ = b.ORD_SEQ    " +
           
          
                    "      AND  D.ISVALID  =  '1' "
                    + _Where;
                //and b.ORD_PROG_CD IN ('A', 'C', 'D', 'E', 'H', 'F') 
                DataSet ds = this.DBManager.ExecuteQuery(sql, out strOut);
                ds.Tables[0].TableName = "KCJ_CANSENDLIST";
                return new ReturnObject(ds, strOut);

            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, "数据库连接错");
            }
        }
        public ReturnObject GetTurnoffButtress_HB(string _Where)
        {
            try
            {
                string err = "";
                //				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" +
                string sql = @"select T1.*  FROM" +
                    "(SELECT C.PACTNO," +
                 "C.PACTINDEX PLANNO, " +
                 "A.ALLOTORDERFORM ORDERNO,  " +
                 "H.NAME_ PRODUCTLINE,  " +
                 "A.ROLLNUMBER, " +
                 "A.MOTHERBOARDNUMBER,  " +
                 "'' YPLANNO," +
                 "A.PLANORDERFORM YORDERNO," +
                 "A.BILLETID,  " +
                 "A.STOVENO," +
                 "A.PLY,  " +
                 "A.WIDTH,  " +
                 "A.LENGTH, " +
                 "A.THEORYWEIGHT,  " +
                " D.NAME_ FACEQUALITY," +
                " E.NAME_ BUGREASON,  " +
                " A.DETERMINANTCARDNUMBER,  " +
                " F.NAME_ DETERMINANTRESULT," +
                " '' CLIPTYPEPROCESS,  " +
                " '' SOURCEID,  " +
                " TO_CHAR(A.INSTORAGETIME, 'YYYY-MM-DD') INTIME,  " +
                " B.BUTTRESS,  " +
                " B.CONDOLENUMBER, " +
                " B.CONDOLELAYER,  " +
                " B.BUTTRESSLAYER, FUN_ISYXN_BJ(A.BILLETID,A.ALLOTORDERFORM)YXN, " +
                 "TO_CHAR(B.LOGICALLAYER) LOGICALLAYER, " +
                          " B.AREA,(SELECT MEMO FROM ZJH_COLL_JUDGE WHERE BH=A.ZHPDBH UNION SELECT JUDGEMEMO MEMO FROM ZJZ_COLL_JUDGE WHERE BH=A.ZHPDBH)MEMO,  " +
                 "B.REMARK,  " +
                " A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET,  " +
                " '' 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  " +
            " FROM KCH_TURNOFFLIST         A,  " +
               "  KCH_TURNOFFBUTTRESSLIST B,  " +
               "  SEL_PACTDETAIL          C, " +
              "   SCM_BASE_INFO           D,  " +
               "  SCM_BASE_INFO           E,  " +
                " SCM_BASE_INFO           F,  " +
               
                      "     SCM_BASE_INFO           H,SCM_BASE_INFO           K,SCM_BASE_INFO           M    " +
          " WHERE A.BILLETID = B.BILLETID  AND A.PLANORDERFORM IS NULL " +
           "  AND A.ALLOTORDERFORM = C.ORDERNO(+)  " +
            " AND A.STORAGESTATUS = '501602'  " +
           
                  "     AND A.FACEQUALITY = D.ID_(+) AND  A.PRODUCT_NAME = K.ID_(+)  " +
            " AND A.BUGREASON = E.ID_(+)  " +
           "  AND A.DETERMINANTRESULT = F.ID_(+)  " +
          
                   "   AND A.PRODUCTLINE = H.ID_(+) AND A.DETECTMARBOOKIN = M.ID_(+)" +
                    _Where +
                    " )T1";


                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=" _Where">条件</param>
        /// <returns></returns>
        public ReturnObject GetTurnoffButtress(string _Where, string strRoleID)
        {
            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 (strRoleID == "bjbck")
                {
                    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,FUN_ISYXN_BJ(A.BILLETID,T.ORDERNO)YXN," +
                       "       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 " +
                       "  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  " +
                       " 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 B.AREA in ('北京办区域','北京办(长沙库)') " +
                       _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 KCJ_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,FUN_ISYXN_BJ(A.BILLETID,T.ORDERNO)YXN," +
                        "       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 " +
                        "  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  " +
                        " 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_(+) " +
                        _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 KCJ_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_ZB(string _Where)
        {
            try
            {
                string err = "";
                //				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" +
                string sql = @"select T1.*  FROM" +
                    "(SELECT C.PACTNO," +
                 "C.PACTINDEX PLANNO, " +
                 "A.ORDERNO,  " +
                 "H.NAME_ PRODUCTLINE,  " +
                 "A.ROLLNUMBER, " +
                 "A.MOTHERBOARDNUMBER,  " +
                 "'' YPLANNO," +
                 "A.PLANORDERNO YORDERNO," +
                 "A.BILLETID,  " +
                 "A.STOVENO," +
                 "A.PLY,  " +
                 "A.WIDTH,  " +
                 "A.LENGTH, " +
                 "A.THEORYWEIGHT,  " +
                " D.NAME_ FACEQUALITY," +
                " E.NAME_ BUGREASON,  " +
                " A.DETERMINANTCARDNUMBER,  " +
                " F.NAME_ DETERMINANTRESULT," +
                " '' CLIPTYPEPROCESS,  " +
                " '' SOURCEID,  " +
                " TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME,  " +
                " B.BUTTRESS,  " +
                " B.CONDOLENUMBER, " +
                " B.CONDOLELAYER,  " +
                " B.BUTTRESSLAYER,  " +
                 "TO_CHAR(B.LOGICALLAYER) LOGICALLAYER, FUN_ISYXN_BJ(a.BILLETID,a.PLY)YXN," +
                          " B.AREA,(SELECT MEMO FROM ZJH_COLL_JUDGE WHERE BH=A.ZHPDBH UNION SELECT JUDGEMEMO MEMO FROM ZJZ_COLL_JUDGE WHERE BH=A.ZHPDBH)MEMO,  " +
                 "B.REMARK,  " +
                " A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET,  " +
                " '' 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  " +
            " FROM KCZ_TURNOFFLIST         A,  " +
               "  KCZ_TURNOFFBUTTRESSLIST B,  " +
               "  SEL_PACTDETAIL          C, " +
              "   SCM_BASE_INFO           D,  " +
               "  SCM_BASE_INFO           E,  " +
                " SCM_BASE_INFO           F,  " +

                      "     SCM_BASE_INFO           H,SCM_BASE_INFO           K,SCM_BASE_INFO           M    " +
          " WHERE A.BILLETID = B.BILLETID  AND A.PLANORDERNO IS NULL " +
           "  AND A.ORDERNO = C.ORDERNO(+)  " +
            " AND A.STORAGESTATUS = '501602'  " +

                  "     AND A.FACEQUALITY = D.ID_(+) AND  A.PRODUCT_NAME = K.ID_(+)  " +
            " AND A.BUGREASON = E.ID_(+)  " +
           "  AND A.DETERMINANTRESULT = F.ID_(+)  " +

                   "   AND A.PRODUCTLINE = H.ID_(+) AND A.DETECTMARBOOKIN = M.ID_(+)" +
                    _Where +
                    " )T1";


                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());
            }

        }
        #endregion

        #region "排车信息查询 ADD BY LYP 20101123"
        //获得排车计划
        public ReturnObject GetAskPlanData(string where)
        {
            try
            {
                string err = "";



                string CSql = " SELECT T1.ASKPLAN_ID,T1.PACTNO,(SELECT C.SM_CFNM FROM TBA01_ORD_LINE B,TBZ00_COMMCD C  WHERE B.DEST_PCD=C.SM_CD(+) AND B.ORD_NO=T1.PACTNO AND ROWNUM=1)STATIONNAME,(SELECT CUST_NM  FROM TBZ00_CUSTOMER D WHERE  REC_TP='01' AND REC_STS='1' AND D.CUST_CD=T1.BUYERCODE) BUYERCODE,(SELECT CUST_NM  FROM TBZ00_CUSTOMER D WHERE  REC_TP='02' AND REC_STS='1' AND D.CUST_CD=T1.INCEPTCORPCODE ) INCEPTCORPCODE,T1.INCEPTDATE,T1.WEIGHT,T1.TRANSNO,T1.REMARK "
                        + " FROM KCJ_PLAN T1 WHERE "
                        + " T1.ISVALID='1' AND T1.PL='2' " + where;
                        
                System.Data.DataSet tmpdst = this.DBManager.ExecuteQuery(CSql, out err);
                if (tmpdst != null && tmpdst.Tables.Count == 1 && tmpdst.Tables[0].Rows.Count > 0)
                {
                    
                    return new ReturnObject(tmpdst);
                }
                return new ReturnObject(null);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, 10000, ex.ToString());
            }
        }
        #endregion
    }
}
