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

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

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

		/// <summary>
		/// 查询垛位信息
		/// </summary>
		/// <param name=" _Where">条件</param>
		/// <returns></returns>
        public ReturnObject GetStorageButtress(string _Where, string strLX)
		{
			try
			{
				string err = "";
                string sql = "";

                    if (strLX == "1")
                {
                    sql = @"select T1.*  FROM" +
                        "(SELECT C.PACTNO," +
                        "       C.PACTINDEX PLANNO," +
                        "       A.ORDERNO," +

                        "       H.NAME_ PRODUCTLINE," +
                        "       A.ROLLNUMBER," +
                        "       A.MOTHERBOARDNUMBER," +
                        "       A.BILLETID," +
                        "       A.STOVENO," +
                        "       A.PLY," +
                        "       A.WIDTH," +
                        "       A.LENGTH," +
                        "       A.THEORYWEIGHT," +
                        "       D.NAME_ FACEQUALITY," +

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

                        "       A.SOURCEID," +
                        "       TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME, TO_CHAR(m.sendbegindate, 'YYYY-MM-DD') SENDBEGINDATE," +
                        "       B.BUTTRESS," +
                        "       B.CONDOLENUMBER," +
                        "       B.CONDOLELAYER," +
                        "       B.BUTTRESSLAYER,C.SIGNCOLOR,DD.BUYERNAME," +
                        "       TO_CHAR(B.LOGICALLAYER) LOGICALLAYER,E.NAME_ DETECTMARBOOKIN," +
                        "       B.AREA," +
                        "       B.REMARK," +
                        "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET,CC.STATIONNAME," +
                        "       B.HANDREMARK,I.NAME_ ATTESTATIONORGAN,A.ORDERBUYER,(SELECT MAX(TO_CHAR(creattime, 'YYYY-MM-DD HH24:MI:SS')) from kcj_storagemovebuttresslist_ZW z where a.BILLETID = z.BILLETID) creattime  " +
                        "  FROM KCJ_STORAGELIST_ZW         A," +
                        "       KCJ_STORAGEBUTTRESSLIST_ZW B," +
                        "       SEL_PACTDETAIL          C," +
                        "       SCM_BASE_INFO           D," +
                        "       SCM_BASE_INFO           E," +

                        "       SCM_BASE_INFO           F," +

                        "       SCM_BASE_INFO           H,sel_pactdetail m,SCM_BASE_INFO I ,SEL_STATIONINFO CC ,SEL_BUYERBASEINFO DD " +
                        " WHERE A.BILLETID = B.BILLETID" +
                        "   AND A.ORDERNO = C.ORDERNO(+) and a.orderno=m.orderno(+) AND C.BUYERCODE=DD.BUYERCODE(+) " +
                        "   AND A.STORAGESTATUS = '501002'" +
                        "   AND A.ISVALID = '1'" +
                        "   AND A.FACEQUALITY = D.ID_(+) AND   C.STATIONCODE=CC.STATIONCODE(+) " +

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

                        "   AND A.PRODUCTLINE = H.ID_(+) AND A.ATTESTATIONORGAN = I.ID_(+)    AND (A.ROLLNUMBER LIKE 'H%' OR A.ROLLNUMBER LIKE 'Z%'   )  " +
                        _Where +
                        " )T1" +

                        " ORDER BY T1.creattime asc ";
                }
                else
                {
                    sql = @"select T1.*  FROM" +
                       "(SELECT C.PACTNO," +
                       "       C.PACTINDEX PLANNO," +
                       "       A.ORDERNO," +

                       "       H.NAME_ PRODUCTLINE," +
                       "       A.ROLLNUMBER," +
                       "       A.MOTHERBOARDNUMBER," +
                       "       A.BILLETID," +
                       "       A.STOVENO," +
                       "       A.PLY," +
                       "       A.WIDTH," +
                       "       A.LENGTH," +
                       "       A.THEORYWEIGHT," +
                       "       D.NAME_ FACEQUALITY," +

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

                       "       A.SOURCEID," +
                       "       TO_CHAR(A.INTIME, 'YYYY-MM-DD') INTIME, TO_CHAR(m.sendbegindate, 'YYYY-MM-DD') SENDBEGINDATE," +
                       "       B.BUTTRESS," +
                       "       B.CONDOLENUMBER," +
                       "       B.CONDOLELAYER," +
                       "       B.BUTTRESSLAYER,C.SIGNCOLOR," +
                       "       TO_CHAR(B.LOGICALLAYER) LOGICALLAYER,'' DETECTMARBOOKIN," +
                       "       B.AREA," +
                       "       B.REMARK," +
                       "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET,CC.STATIONNAME," +
                       "       B.HANDREMARK,DD.BUYERNAME,I.NAME_ ATTESTATIONORGAN,A.ORDERBUYER,(SELECT MAX(TO_CHAR(creattime, 'YYYY-MM-DD HH24:MI:SS')) from kcj_storagemovebuttresslist_ZW z where a.BILLETID = z.BILLETID) creattime  " +
                       "  FROM KCJ_STORAGELIST_ZW         A," +
                       "       KCJ_STORAGEBUTTRESSLIST_ZW B," +
                       "       SEL_PACTDETAIL          C," +
                       "       SCM_BASE_INFO           D," +

                       "       SCM_BASE_INFO           F," +

                       "       SCM_BASE_INFO           H,sel_pactdetail m,SCM_BASE_INFO I ,SEL_STATIONINFO CC,SEL_BUYERBASEINFO DD " +
                       " WHERE A.BILLETID = B.BILLETID" +
                       "   AND A.ORDERNO = C.ORDERNO(+) and a.orderno=m.orderno(+) AND (A.ROLLNUMBER LIKE 'E%' OR A.ROLLNUMBER LIKE 'Y%'  OR A.ROLLNUMBER LIKE 'B%' )  " +
                       "   AND A.STORAGESTATUS = '501002'" +
                       "   AND A.ISVALID = '1'" +
                       "   AND A.FACEQUALITY = D.ID_(+) AND   C.STATIONCODE=CC.STATIONCODE(+) AND C.BUYERCODE=DD.BUYERCODE(+) " +

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

                       "   AND A.PRODUCTLINE = H.ID_(+) AND A.ATTESTATIONORGAN = I.ID_(+)     " +
                       _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_STORAGEBUTTRESSLIST";
					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 GetStorageButtress_SendType(string _Where, string strlx)
        {
            try
            {
                string err = "";
                string sql = "";
                if (strlx == "1")
                {
                    sql = @"select T1.*  FROM" +
                       "(SELECT C.PACTNO," +
                       "       C.PACTINDEX PLANNO," +
                       "       A.ORDERNO," +

                       "       H.NAME_ PRODUCTLINE," +
                       "       A.ROLLNUMBER," +
                       "       A.MOTHERBOARDNUMBER," +
                       "       A.BILLETID," +
                       "       A.STOVENO," +
                       "       A.PLY," +
                       "       A.WIDTH," +
                       "       A.LENGTH," +
                       "       A.THEORYWEIGHT," +
                       "       A.DETERMINANTCARDNUMBER," +
                       "       F.NAME_ DETERMINANTRESULT," +
                       "       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,E.NAME_ DETECTMARBOOKIN," +
                       "       B.AREA," +
                       "       B.REMARK," +
                       "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET," +
                       "       B.HANDREMARK,I.NAME_ ATTESTATIONORGAN,A.ORDERBUYER,(SELECT MAX(TO_CHAR(creattime, 'YYYY-MM-DD HH24:MI:SS')) from kcj_storagemovebuttresslist_ZW z where a.BILLETID = z.BILLETID) creattime  " +




                        "  FROM KCJ_STORAGELIST_ZW         A," +
                       "       KCJ_STORAGEBUTTRESSLIST_ZW B," +
                       "       SEL_PACTDETAIL          C," +
                       "       SCM_BASE_INFO           D," +
                       "       SCM_BASE_INFO           E," +
                       "       SCM_BASE_INFO           F," +
                       "       SCM_BASE_INFO           H,sel_pactdetail m,SCM_BASE_INFO I,KCJ_TURNOFFLIST_ZW N " +
                       " WHERE A.BILLETID = B.BILLETID(+) AND A.BILLETID = N.BILLETID(+) " +
                       "   AND A.ORDERNO = C.ORDERNO(+) and a.orderno=m.orderno(+) " +
                       "   AND N.SENDTYPE IN('0','1') " +
                       "   AND A.ISVALID = '1'" +
                       "   AND A.FACEQUALITY = D.ID_(+) " +
                       "   AND A.DETECTMARBOOKIN = E.ID_(+) " +
                       "   AND A.DETERMINANTRESULT = F.ID_(+)" +
                       "   AND A.PRODUCTLINE = H.ID_(+) AND A.ATTESTATIONORGAN = I.ID_(+)  AND (A.ROLLNUMBER LIKE 'H%' OR A.ROLLNUMBER LIKE 'Z%') " +
                       _Where +
                       " )T1" +

                       " ORDER BY T1.creattime asc ";
                }
                else
                {
                    sql = @"select T1.*  FROM" +
                       "(SELECT C.PACTNO," +
                       "       C.PACTINDEX PLANNO," +
                       "       A.ORDERNO," +

                       "       H.NAME_ PRODUCTLINE," +
                       "       A.ROLLNUMBER," +
                       "       A.MOTHERBOARDNUMBER," +
                       "       A.BILLETID," +
                       "       A.STOVENO," +
                       "       A.PLY," +
                       "       A.WIDTH," +
                       "       A.LENGTH," +
                       "       A.THEORYWEIGHT," +
                       "       A.DETERMINANTCARDNUMBER," +
                       "       F.NAME_ DETERMINANTRESULT," +
                       "       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,'' DETECTMARBOOKIN," +
                       "       B.AREA," +
                       "       B.REMARK," +
                       "       A.PLY || '*' || A.WIDTH || '*' || A.LENGTH SPET," +
                       "       B.HANDREMARK,I.NAME_ ATTESTATIONORGAN,A.ORDERBUYER,(SELECT MAX(TO_CHAR(creattime, 'YYYY-MM-DD HH24:MI:SS')) from kcj_storagemovebuttresslist_ZW z where a.BILLETID = z.BILLETID) creattime  " +




                       "  FROM KCJ_STORAGELIST_ZW         A," +
                       "       KCJ_STORAGEBUTTRESSLIST_ZW B," +
                       "       SEL_PACTDETAIL          C," +
                       "       SCM_BASE_INFO           D," +
                       "       SCM_BASE_INFO           F," +
                       "       SCM_BASE_INFO           H,sel_pactdetail m,SCM_BASE_INFO I,KCJ_TURNOFFLIST_ZW N " +
                       " WHERE A.BILLETID = B.BILLETID(+) AND A.BILLETID = N.BILLETID(+) " +
                       "   AND A.ORDERNO = C.ORDERNO(+) and a.orderno=m.orderno(+) " +
                       "   AND N.SENDTYPE IN('0','1') " +
                       "   AND A.ISVALID = '1'" +
                       "   AND A.FACEQUALITY = D.ID_(+)   " +
                       "   AND A.DETERMINANTRESULT = F.ID_(+)" +
                       "   AND A.PRODUCTLINE = H.ID_(+) AND A.ATTESTATIONORGAN = I.ID_(+)  AND (A.ROLLNUMBER LIKE 'E%' OR A.ROLLNUMBER LIKE 'Y%'  OR A.ROLLNUMBER LIKE 'B%' ) " +
                       _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_STORAGEBUTTRESSLIST";
                    return new ReturnObject(ds);
                }
                else
                {
                    return new ReturnObject(null);
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, ex.ToString());
            }

        }

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

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

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

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

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

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

				pSuccessFlag.Size = 400;

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


	}
}
