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


namespace Core.XgMes.Server.JGKC.RollManager
{
	/// <summary>
	/// ProcduceTurnManage 的摘要说明。
	/// </summary>
	public class ProcduceTurnManage : Core.Mes.ServerFrameWork.IComponent
	{
		public ProcduceTurnManage()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		public override int minValue
		{
			get
			{
				return 20;
			}
		}
		public override int maxValue
		{
			get
			{
				return 120;
			}
		}
		public ReturnObject Plan_XF_Qery(string _Where)
		{
			try
			{
				string strOut="";
				string Sql="SELECT 'FALSE'  FLAG,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,(SELECT NAME_ FROM KCJ_BASEDATA WHERE ID_=A.STOCKTYPE)STOCKTYPE,"+
					"A.ZSLAB_WEIGHT,A.TOT_DEC_GRD,SX_BIAOZHUN,(SELECT NAME_ FROM KCJ_BASEDATA WHERE ID_=A.STOCKTYPEZF)STOCKTYPEZF,"+
					"A.CRK_CD1,A.CRK_CD2,A.CRK_CD3,A.CRK_CD4,"+
					"A.CRK_CD5,A.ZLZS_NO,A.REM,A.DEVLMT_DTIME,"+
					"A.SHIP_INVNO,TRANS_CAR_NO,(SELECT NAME_ FROM SCM_BASE_INFO C WHERE C.ID_= A.CLASSORDER)INCLASSORDER,"+
					"(SELECT NAME_ FROM SCM_BASE_INFO D WHERE D.ID_=A.CLASSTEAM)INCLASSTEAM,A.CREATETIME,A.CREATOR FROM KCJ3_ZY_ZFPLAN A ,KCJ3_TURNOFFBUTTRESSLIST B "+
					"WHERE A.COIL_NO_ID=B.COIL_NO_ID AND A.DOWN_FLAG='1'AND AFFIRLOG='0' "+_Where+" ORDER BY A.SCID DESC";
				DataSet ds=this.DBManager.ExecuteQuery(Sql,out strOut);
				if(ds!=null&&ds.Tables.Count==1)
				{
					ds.Tables[0].TableName="KCJ3_ZY_ZFPLAN";
					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());
			}

		}


        //分卷开平计划查询 add by lyp 20101026
        public ReturnObject Plan_FJXF_Qery(string _Where)
        {
            try
            {
                string strOut = "";
                string Sql = "SELECT 'FALSE'  FLAG, A.OLD_SAMPL_NO,A.SLAB_NO,A.ORD_NO,b.BUTTRESS," +
                    "A.ORD_SEQ,A.STL_GRD,A.COIL_INDIA,A.COIL_OUTDIA," +
                    "A.COIL_THK,COIL_WTH,COIL_LEN,A.STOVENO,A.BAHCT_NUMBER," +
                    
                    "A.CRK_CD1,A.CRK_CD2,A.CRK_CD3,A.CRK_CD4,SX_BIAOZHUN," +
                    "A.ZLZS_NO,A.REM,A.DEVLMT_DTIME," +
                    "A.SHIP_INVNO,TRANS_CAR_NO,(SELECT NAME_ FROM SCM_BASE_INFO C WHERE C.ID_= A.CLASSORDER)CLASSORDER," +
                    "(SELECT NAME_ FROM SCM_BASE_INFO D WHERE D.ID_=A.CLASSTEAM)CLASSTEAM,A.CREATETIME,A.CREATOR,(SELECT NAME_ FROM KCJ_BASEDATA WHERE ID_=A.GYLX)GYLX FROM KCJ3_ZY_PLAN_ZW A ,KCJ3_STUFFBUTTRESSLIST_ZW B " +
                    "WHERE  A.OLD_SAMPL_NO=B.OLD_SAMPL_NO and DOWN_FLAG='1' AND A.GYLX='8077001' AND AFFIRLOG='0'    " + _Where + " ORDER BY A.WORKORDER_ID, A.SCID DESC";
                DataSet ds = this.DBManager.ExecuteQuery(Sql, out strOut);
                if (ds != null && ds.Tables.Count == 1)
                {
                    ds.Tables[0].TableName = "KCJ3_ZY_ZFPLAN";
                    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 Procdute_Query(string _Where)
		{
			try
			{
				string strOut="";
                string Sql = "SELECT 'FALSE'  FLAG,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.TURNOFFCOLLECT_LOG," +
                    "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,SERIAL_NUMBER," +
                    " (SELECT NAME_ FROM KCJ_BASEDATA WHERE ID_ = A.ord_use_cd)ord_use_cd," +
                    " A.DEVLMT_DTIME,(SELECT NAME_ FROM KCJ_BASEDATA WHERE ID_=A.STOCKTYPE)STOCKTYPE," +
                    "A.SHIP_INVNO,TRANS_CAR_NO,(SELECT NAME_ FROM SCM_BASE_INFO C WHERE C.ID_= A.PCLASSORDER)PCLASSORDER," +
                    "(SELECT NAME_ FROM SCM_BASE_INFO D WHERE D.ID_=A.PCLASSTEAM)PCLASSTEAM,A.CREATETIME,A.CREATOR,DECODE(A.ISFJH,'1','是','0','否')ISFJH,(SELECT NAME_ FROM KCJ_BASEDATA WHERE ID_=A.GYLX)GYLX  FROM KCJ3_ZY_TASKDETAIL_ZW A  ,KCJ3_STUFFBUTTRESSLIST_ZW B " +
                    "WHERE  A.OLD_SAMPL_NO=B.OLD_SAMPL_NO   AND A.GYLX='8077001'  " + _Where + " ORDER BY A.WORKORDER_ID, A.SCID DESC";
				DataSet ds=this.DBManager.ExecuteQuery(Sql,out strOut);
				if(ds!=null&&ds.Tables.Count==1)
				{
					ds.Tables[0].TableName="KCJ3_ZY_TASKDETAIL";
					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 Procduce_Add(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["ODPDB"]).ExecuteNonQuery_NoDBSever("KCJ_STORAGEMANAGER_WX.ZFPROCDUE_ADD", 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 Procduce_FJAdd(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["ODPDB"]).ExecuteNonQuery_NoDBSever("KCJ_STORAGEMANAGER_WX.ZFPROCDUE_FJADD", 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 ZFPress_Del(ArrayList _Ship_Invno)
		{
			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 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 = _Ship_Invno.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;

				pSuccessFlag.Size = 400;

				((STMes.DBManager)DBManagerList["ODPDB"]).ExecuteNonQuery_NoDBSever("KCJ_STORAGEMANAGER_WX.ZFPROCDE_DEL", 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(System.Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(null,ex.ToString());
			}
		}
		public ReturnObject Press_QUEREN4(ArrayList _Ship_Invno)
		{
			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 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 = _Ship_Invno.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;

				pSuccessFlag.Size = 400;

				((STMes.DBManager)DBManagerList["ODPDB"]).ExecuteNonQuery_NoDBSever("KCJ_STORAGEMANAGER_WX.QUENREN4", 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(System.Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(null,ex.ToString());
			}
		}
	}
}
