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

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

		public override int maxValue
		{
			get
			{
				return 100;
			}
		}
		public override int minValue
		{
			get
			{
				return 50;
			}
		}
		public ReturnObject Plan_XF_Qery(string _Where)
		{
			try
			{
                string err = "";
                string Sql = " SELECT 'FALSE' FLAG,a.OLD_SAMPL_NO,a.WORKORDER_ID,a.ORD_NO,A.STL_GRD FROM kcj3_zy_plan_main A " +
                             " WHERE a.XF_FLAG = '1' and a.ISVALID <> '0' "+ _Where;
                DataSet ds = DBManager.ExecuteQuery(Sql, out err);
                ds.Tables[0].TableName = "XF-1";

                string StrSQL_Detail = "";
                /*StrSQL_Detail = " SELECT a.OLD_SAMPL_NO,A.ORD_NO,A.STL_GRD,B.COIL_THK,B.COIL_WTH,B.COIL_LEN,  " +
                                " B.COIL_NUM,B.WORKORDER_ID,B.DETAIL_TIME " +
                                " FROM kcj3_zy_plan_main a,KCJ3_ZY_PLAN_DETAIL b "+
				                " WHERE a.WORKORDER_ID = b.Workorder_Id "+
				                " and b.old_sampl_no like '%'||a.old_sampl_no||'%' "+
					            " and a.XF_FLAG = '1' and a.ISVALID <> '0' and b.isvalid <> '0' "+
                                _Where +
                                " group by a.OLD_SAMPL_NO,a.ord_no,a.stl_grd,B.COIL_THK,B.COIL_WTH,B.COIL_LEN, " +
					            " b.coil_num,b.workorder_id,a.OLD_SAMPL_NO,b.DETAIL_TIME "+
                                " order by b.DETAIL_TIME ";
                DataSet ds_Detail = DBManager.ExecuteQuery(StrSQL_Detail, out err);*/
                //2024年1.10日修改为多选时带信息
                StrSQL_Detail = " SELECT a.OLD_SAMPL_NO,'' COIL_NO_ID,A.ORD_NO,A.STL_GRD,B.COIL_THK,B.COIL_WTH,B.COIL_LEN,  " +
                                " B.COIL_NUM,round(to_number(B.COIL_THK)*to_number(B.COIL_WTH)*to_number(B.COIL_LEN)*(case when REGEXP_LIKE(B.COIL_NUM, '^[0-9]$') then to_number(B.COIL_NUM) else 0 end)*0.00000000785,3) WEIGHT," +
                                " B.WORKORDER_ID,B.DETAIL_TIME,'' BC,'' BZ " +
                                " FROM kcj3_zy_plan_main a,KCJ3_ZY_PLAN_DETAIL b " +
                                " WHERE a.WORKORDER_ID = b.Workorder_Id " +
                                " and b.old_sampl_no like '%'||a.old_sampl_no||'%' " +
                                " and a.XF_FLAG = '1' and a.ISVALID <> '0' and b.isvalid <> '0' " +
                                _Where +
                                " group by a.OLD_SAMPL_NO,a.ord_no,a.stl_grd,B.COIL_THK,B.COIL_WTH,B.COIL_LEN, " +
                                " b.coil_num,b.workorder_id,a.OLD_SAMPL_NO,b.DETAIL_TIME " +
                                " order by b.DETAIL_TIME ";
                DataSet ds_Detail = DBManager.ExecuteQuery(StrSQL_Detail, out err);
                ds_Detail.Tables[0].TableName = "XF-2";
                ds.Tables.Add(ds_Detail.Tables[0].Copy());
                /*ds.Relations.Add("ReltnXF", 
                                        new System.Data.DataColumn[] {ds.Tables["dtXF_Main"].Columns["OLD_SAMPL_NO"], ds.Tables["dtXF_Main"].Columns["WORKORDER_ID"]},
                                        new System.Data.DataColumn[] {ds.Tables["dtXF_Detail"].Columns["OLD_SAMPL_NO"], ds.Tables["dtXF_Detail"].Columns["WORKORDER_ID"]});*/
                ds.Relations.Add("Relation1",
                                        new System.Data.DataColumn[] { ds.Tables["XF-1"].Columns["OLD_SAMPL_NO"], ds.Tables["XF-1"].Columns["WORKORDER_ID"], ds.Tables["XF-1"].Columns["ORD_NO"], ds.Tables["XF-1"].Columns["STL_GRD"] },
                                        new System.Data.DataColumn[] { ds.Tables["XF-2"].Columns["OLD_SAMPL_NO"], ds.Tables["XF-2"].Columns["WORKORDER_ID"], ds.Tables["XF-2"].Columns["ORD_NO"], ds.Tables["XF-2"].Columns["STL_GRD"] });
                return new ReturnObject(ds, err);
			}
			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,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,(SELECT NAME_ FROM KCJ_BASEDATA WHERE ID_=A.GYLX)GYLX," +
					"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  FROM KCJ3_ZY_TASKDETAIL_ZW A ,KCJ3_STUFFBUTTRESSLIST_ZW B " +
                    "WHERE A.OLD_SAMPL_NO=B.OLD_SAMPL_NO   " + _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 Press_Set(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.PRODUE_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 UnPack_Add(ArrayList _OtherInfo)
        {
            try
            {
                string err = "";

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

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

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

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

      

                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.UnPack_ADD", CommandType.StoredProcedure,
                    new Oracle.DataAccess.Client.OracleParameter[] {  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 Press_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.PROCDE_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_QUEREN(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.QUENREN", 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_QUERENDEL(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.QUENRENDEL", 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());
            }
        }
	}
}
