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

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

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

		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,"+
					"A.ORD_SEQ,A.STL_GRD,A.ZSLAB_PLY,A.ZSLAB_WIDTH,"+
					"A.ZSLAB_LENGTH,A.ZSLAB_NUM,A.STOVENO,A.BAHCT_NUMBER,"+
					"A.ZSLAB_WEIGHT,A.TOT_DEC_GRD,A.SX_BIAOZHUN,"+
                    "a.CRK_CD1," +
                    " A.ZLZS_NO,A.REM,A.DEVLMT_DTIME," +
					"A.SHIP_INVNO,A.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,(SELECT NAME_ FROM KCJ_BASEDATA WHERE ID_=A.GYLX)GYLX ,(SELECT NAME_ FROM KCJ_BASEDATA WHERE ID_=A.STOCKTYPE)STOCKTYPE," +


                    " A.ZSLAB_WEIGHT XJJL " +
                    " FROM KCJ3_ZY_TASKDETAIL_ZW A " +
                    " WHERE  TURNOFFCOLLECT_LOG='0'  " + _Where;
				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 Turn_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.ZSLAB_LENGTH,ZSLAB_NUM,A.STOVENO,A.BAHCT_NUMBER,"+
					"ROUND(A.ZSLAB_WEIGHT,3)ZSLAB_WEIGHT,A.TOT_DEC_GRD,SX_BIAOZHUN,A.SERIAL_NUMBER,"+
                    "(SELECT NAME_ FROM KCJ_BASEDATA WHERE ID_=A.STCOKTYPE)STCOKTYPE,a.XJJL_WEIGHT," +
					"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.INCLASSORDER)INCLASSORDER,"+
                    "(SELECT NAME_ FROM SCM_BASE_INFO D WHERE D.ID_=A.INCLASSTEAM)INCLASSTEAM,A.CREATETIME,A.CREATOR,B.REMARK,(SELECT NAME_ FROM KCJ_BASEDATA WHERE ID_=A.GYLX)GYLX,(SELECT NAME_ FROM SCM_BASE_INFO C WHERE C.ID_= A.DETERMINANTRESULT)DETERMINANTRESULT,(SELECT NAME_ FROM SCM_BASE_INFO C WHERE C.ID_= A.GZQX)GZQX,(SELECT NAME_ FROM SCM_BASE_INFO C WHERE C.ID_= A.GYQX)GYQX 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' AND A.COIL_NO_ID LIKE 'R%' "+_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_CB_Query(string _Where)
        {
            try
            {
                string strOut = "";
                string Sql = "SELECT A.COIL_NO_ID,A.OLD_SAMPL_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," +
                    "ROUND(A.ZSLAB_WEIGHT,3)ZSLAB_WEIGHT," +
                    "(SELECT NAME_ FROM KCJ_BASEDATA WHERE ID_=A.STCOKTYPE)STCOKTYPE,a.XJJL_WEIGHT," +
              
                    "(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,B.REMARK,(SELECT NAME_ FROM KCJ_BASEDATA WHERE ID_=A.GYLX)GYLX 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' AND A.COIL_NO_ID LIKE 'R%' " + _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_CB_JL(string _Where)
        {
            try
            {
                string strOut = "";
                string Sql = "SELECT A.COIL_NO_ID,A.OLD_SAMPL_NO,A.COIL_NO_ID_NEW," +
                    "A.OLD_SAMPL_NO_NEW,A.ZSLAB_NUM,A.ZSLAB_WEIGHT,A.ZSLAB_NUM_NEW," +
                    "A.ZSLAB_WEIGHT_NEW,XJJL_WEIGHT,A.XJJL_WEIGHT_NUM," +
                    "RECODER," +
                    "TIME_ " +

                    "FROM KCJ3_CB_JL A WHERE A.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_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["ODPDBZW"]).ExecuteNonQuery_NoDBSever("KCJ_STORAGEMANAGER_WX.TRUN_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 Turn_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["ODPDBZW"]).ExecuteNonQuery_NoDBSever("KCJ_STORAGEMANAGER_WX.TURN_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());
			}
		}

	}
}
