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

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

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

		/// <summary>
		/// 板块登记信息查询
		/// </summary>
		/// <param name=" _OrderNO">订单号</param>
		/// <param name=" _BilletID">序号</param>
		/// <param name=" _ShopSign">牌号</param>
		/// <param name=" _Where">附加条件</param>
		/// <returns></returns>
		public ReturnObject QueryInStorageInfo(string _OrderNO,string _BilletID,string _ShopSign,string _Where,string sstyle)
		{
			string strOut = "";
            string sql = "";
            DataSet ds = new DataSet();
            
           
                if (sstyle == "2")
                {
                    sql = "Select A.BILLETID ,F.NAME_ PRODUCTLINE,A.ROLLNUMBER,A.PLANNO,A.ORDERNO,G.NAME_ BILLETTYP,"

                     + "A.PLY,A.WIDTH,A.LENGTH,A.THEORYWEIGHT,B.NAME_ FACEQUALITY,A.DETERMINANTCARDNUMBER,"


                     + "I.BUTTRESS,"//切边

                     + "E.NAME_ DETERMINANTRESULT,A.SOURCEID,TO_CHAR(A.INTIME,'YYYY-MM-DD') INTIME,H.NAME_ RULE,I.CONDOLENUMBER,TO_CHAR(A.PTIME,'YYYY-MM-DD') PTIME  "//++

                     + "From  KCJ_TURNOFFLIST_ZW A,SCM_BASE_INFO B,SCM_BASE_INFO E, SCM_BASE_INFO F,KCJ_BASEDATA G,SCM_BASE_INFO H,KCJ_TURNOFFBUTTRESSLIST_ZW I  "

                     + "Where A.FACEQUALITY=B.ID_(+)   AND A.DETERMINANTRESULT=E.ID_(+) AND A.PRODUCTLINE=F.ID_(+) AND A.BILLETTYP=G.ID_(+) AND A.RULE=H.ID_(+)  "//++

                     + "AND A.STORAGESTATUS = '501602' AND A.ISVALID = '1'  AND A.BILLETID=I.BILLETID   AND (A.BILLETID LIKE 'E%' OR A.BILLETID LIKE 'Y%' OR A.BILLETID LIKE 'B%') ";
                }
                else
                {
                    sql = "Select A.BILLETID ,F.NAME_ PRODUCTLINE,A.ROLLNUMBER,A.PLANNO,A.ORDERNO,G.NAME_ BILLETTYP,"

                     + "A.PLY,A.WIDTH,A.LENGTH,A.THEORYWEIGHT,B.NAME_ FACEQUALITY,A.DETERMINANTCARDNUMBER,"


                     + "I.BUTTRESS,"//切边

                     + "E.NAME_ DETERMINANTRESULT,A.SOURCEID,TO_CHAR(A.INTIME,'YYYY-MM-DD') INTIME,H.NAME_ RULE,I.CONDOLENUMBER,TO_CHAR(A.PTIME,'YYYY-MM-DD') PTIME  "//++

                     + "From  KCJ_TURNOFFLIST_ZW A,SCM_BASE_INFO B,SCM_BASE_INFO E, SCM_BASE_INFO F,KCJ_BASEDATA G,SCM_BASE_INFO H,KCJ_TURNOFFBUTTRESSLIST_ZW I  "

                     + "Where A.FACEQUALITY=B.ID_(+)   AND A.DETERMINANTRESULT=E.ID_(+) AND A.PRODUCTLINE=F.ID_(+) AND A.BILLETTYP=G.ID_(+) AND A.RULE=H.ID_(+)  "//++

                     + "AND A.STORAGESTATUS = '501602' AND A.ISVALID = '1'  AND A.BILLETID=I.BILLETID   AND (A.BILLETID LIKE 'H%' OR A.BILLETID LIKE 'Z%' ) ";
                }
            
			
           
                ds = this.DBManager.ExecuteQuery(sql, out strOut);
                ds.Tables[0].TableName = "KCJ_TURNOFFLIST";
                return new ReturnObject(ds, strOut);
         
            
           
           


		}



        //计划查询
        public ReturnObject QueryPlan( string _Where)
        {
            string strOut = "";
            string sql = "";
            DataSet ds = new DataSet();


            sql = "SELECT A.ASKPLAN_ID,A.PL,A.TRANSNO,A.INCEPTCORPCODE,A.BUYERCODE,A.WEIGHT,TO_CHAR(A.INCEPTDATE,'YY-MM-DD')INCEPTDATE,A.REMARK,A.RECODER,A.PACTNO, "
                  +" CASE WHEN A.PL='2' THEN "
                  +" (SELECT COUNT(T.COIL_NO_ID) FROM KCJ3_TURNOFFSENDLIST_ZW T WHERE T.PLANVEHICLEID=A.ASKPLAN_ID AND T.ISVALID<>'0') "
                  +" ELSE"
                  +" 0"
                  +" END "
                  +" FYBS ,"
                  +" CASE WHEN A.PL='2' THEN "
                  +" (SELECT SUM(T.ZSLAB_NUM) FROM KCJ3_TURNOFFSENDLIST_ZW T WHERE T.PLANVEHICLEID=A.ASKPLAN_ID AND T.ISVALID<>'0')"
                  +" ELSE"
                  + " (SELECT count(T.SERIALNUMBER) FROM KCJ_TURNOFFSENDLIST_ZW T WHERE T.PLANVEHICLEID=A.ASKPLAN_ID AND T.ISVALID<>'0')"
                  +" END "
                  +" FYNUM,"
                  +" CASE WHEN A.PL='2' THEN "
                  +" (SELECT CASE WHEN SUM(T.XJJL_WEIGHT) IS NULL THEN SUM(T.CAL_WGT) ELSE SUM(T.XJJL_WEIGHT) END  FROM KCJ3_TURNOFFSENDLIST_ZW T WHERE T.PLANVEHICLEID=A.ASKPLAN_ID AND T.ISVALID<>'0')"
                  +" ELSE"
                  + " (SELECT SUM(T.WEIGHT) FROM KCJ_TURNOFFSENDLIST_ZW T WHERE T.PLANVEHICLEID=A.ASKPLAN_ID AND T.ISVALID<>'0')"
                  +" END "
                  +" FYZL"
                + " FROM KCJ_PLAN A WHERE 1=1 AND ISVALID='1' " + _Where;
          



            ds = this.DBManager.ExecuteQuery(sql, out strOut);

            return new ReturnObject(ds, strOut);






        }

		/// <summary>
		/// 从原料库获取板块信息
		/// </summary>
		/// <param name=" _Where">条件</param>
		/// <returns></returns>
		public ReturnObject GetBilletInfo(string _Where,string sstyle)
		{
			string strOut = "";

			string sql="";
                if(sstyle=="1")
            {
                sql="Select A.BILLETID,A.PRODUCTLINE,A.ROLLNUMBER,A.MOTHERBOARDNUMBER,A.STOVENO,A.PLANNO,A.ORDERNO,"
 
				+"A.PLY,A.WIDTH,A.LENGTH,A.THEORYWEIGHT,A.FACEQUALITY,A.DETERMINANTCARDNUMBER,"
	
                + "A.DETERMINANTRESULT,A.SOURCEID ,(SELECT SENDSTATUS FROM sel_pactdetail WHERE ORDERNO = A.ORDERNO)SENDSTATUS,(SELECT FIXSIZE FROM sel_pactdetail WHERE ORDERNO = A.ORDERNO)FIXSIZE "//++
						
				+"From  KCJ_STORAGELIST_ZW A "

                + "Where A.STORAGESTATUS = '501002' AND A.ISVALID = '1' AND (A.BILLETID LIKE 'H%' OR A.BILLETID LIKE 'Z%') ";	
            }
            else
            {
                sql = "Select A.BILLETID,A.PRODUCTLINE,A.ROLLNUMBER,A.MOTHERBOARDNUMBER,A.STOVENO,A.PLANNO,A.ORDERNO,"

               + "A.PLY,A.WIDTH,A.LENGTH,A.THEORYWEIGHT,A.FACEQUALITY,A.DETERMINANTCARDNUMBER,"

               + "A.DETERMINANTRESULT,A.SOURCEID ,(SELECT SENDSTATUS FROM sel_pactdetail WHERE ORDERNO = A.ORDERNO)SENDSTATUS,(SELECT FIXSIZE FROM sel_pactdetail WHERE ORDERNO = A.ORDERNO)FIXSIZE "//++

               + "From  KCJ_STORAGELIST_ZW A "

               + "Where A.STORAGESTATUS = '501002' AND A.ISVALID = '1'  AND (A.BILLETID LIKE 'E%' OR A.BILLETID LIKE 'Y%' OR A.BILLETID LIKE 'B%') ";	
            }

			sql = sql + _Where;

			try
			{
			
				DataSet ds = this.DBManager.ExecuteQuery(sql,out strOut);
				ds.Tables[0].TableName = "KCJ_STORAGELIST";
				return new ReturnObject(ds,strOut);
			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(null,"数据库连接错");
			}

		}



		/// <summary>
		/// 成品收集入库
		/// </summary>
		/// <param name=""></param>
		/// <returns></returns>
		public ReturnObject AddInStorage(System.Collections.ArrayList _CollectInfo)
		{
			try
			{
				string err = "";
				Oracle.DataAccess.Client.OracleParameter pBilletInfo = new Oracle.DataAccess.Client.OracleParameter("vBilletInfo", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				Oracle.DataAccess.Client.OracleParameter pSuccessFlag = new Oracle.DataAccess.Client.OracleParameter("vSuccessFlag", Oracle.DataAccess.Client.OracleDbType.Varchar2);
				
				pBilletInfo.Direction = ParameterDirection.Input;
				pSuccessFlag.Direction = ParameterDirection.Output;

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

				pBilletInfo.Value = _CollectInfo.ToArray(typeof(string));

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

				pSuccessFlag.Size = 400;
                ((STMes.DBManager)DBManagerList["ODPDBZW"]).ExecuteNonQuery_NoDBSever("KCJ_STORAGEMANAGER_WX.TurnoffInStorage", CommandType.StoredProcedure,
					new Oracle.DataAccess.Client.OracleParameter[]{pBilletInfo,pSuccessFlag}, out err);
				if(Common.CheckNullStr(pSuccessFlag.Value) != "1" || Common.CheckNullStr(err).Length>0)
				{
					return new ReturnObject(Common.CheckNullStr(pSuccessFlag.Value)+err);
				}
				else
				{
					return new ReturnObject('1');
				}

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

		}



        public ReturnObject AddPlan(System.Collections.ArrayList _CollectInfo)
        {
            try
            {
                string err = "";
                Oracle.DataAccess.Client.OracleParameter pBilletInfo = new Oracle.DataAccess.Client.OracleParameter("vBilletInfo", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pSuccessFlag = new Oracle.DataAccess.Client.OracleParameter("vSuccessFlag", Oracle.DataAccess.Client.OracleDbType.Varchar2);

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

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


                pBilletInfo.Value = _CollectInfo.ToArray(typeof(string));

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

                pSuccessFlag.Size = 400;
                ((STMes.DBManager)DBManagerList["ODPDBZW"]).ExecuteNonQuery_NoDBSever("KCJ_STORAGEMANAGER_WX.PlanAdd", CommandType.StoredProcedure,
                    new Oracle.DataAccess.Client.OracleParameter[] { pBilletInfo, pSuccessFlag }, out err);
                if (Common.CheckNullStr(pSuccessFlag.Value) != "1" || Common.CheckNullStr(err).Length > 0)
                {
                    return new ReturnObject(Common.CheckNullStr(pSuccessFlag.Value) + err);
                }
                else
                {
                    return new ReturnObject('1');
                }

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

        }
		/// <summary>
		/// 撤销成品入库
		/// </summary>
		/// <param name=""></param>
		/// <returns></returns>
		public ReturnObject CancelTurnoffIn(string _BilletId,string _CreatMan)
		{
			ArrayList OutPutValues = new ArrayList();
			object [] values = new object[3];			
			string strOut="";

			try
			{
				#region "param"
				System.Data.OracleClient.OracleParameter[] param = new System.Data.OracleClient.OracleParameter[3];
				param[0] = new System.Data.OracleClient.OracleParameter();
				param[0].ParameterName = "vBilletId";
				param[0].Direction = System.Data.ParameterDirection.Input;

				param[1] = new System.Data.OracleClient.OracleParameter();
				param[1].ParameterName = "vCreateMan";
				param[1].Direction = System.Data.ParameterDirection.Input;

				param[2] = new System.Data.OracleClient.OracleParameter();
				param[2].ParameterName = "vSuccessFlag"; 
				param[2].DbType = System.Data.DbType.String;
				param[2].Direction = System.Data.ParameterDirection.Output;

				#endregion

				#region "values"
				values[0] = _BilletId;		
				values[1] = _CreatMan;	
				values[2] = "";		
				values = Common.FixValues(values);
				#endregion

                string sql = "KCJ_STORAGEMANAGER_WX.CancelInSotrage";
                this.DBManager.ExecuteQuery(sql, System.Data.CommandType.StoredProcedure, param, values, ref OutPutValues, out strOut);
				
				if(strOut.Length > 0)
				{
					return new ReturnObject(strOut);
				}
				if(OutPutValues.Count > 0 &&  Common.CheckNullStr(OutPutValues[0]).Length > 0)
				{
					return new ReturnObject(OutPutValues[0].ToString());//返回操作结果
				}
				return new ReturnObject("传递参数错误，操作失败");
			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				return new ReturnObject(ex.ToString());
			}

		}






	}
}
