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

namespace Core.XgMes.Server.JGKC.RollManager
{
    /// <summary>
    /// StuffReceiveManage 的摘要说明。
    /// </summary>
    public class StuffReceiveManage : Core.Mes.ServerFrameWork.IComponent
    {
        public StuffReceiveManage()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        /// <summary>
        /// 垛位信息查询
        /// </summary>
        /// <param name=" _AreaCode">区域代码</param>
        /// <returns></returns>
        public ReturnObject QueryFJButtress(string _ButtressCode, string _AreaCode, string _ButtressType)
        {
            string strOut = "";

            string sql = "select BUTTRESSCODE from kcj_buttress_ZW where isvalid = '1' "
                        + " and buttresstype = '" + _ButtressType + "' ";
            if (_ButtressCode.Length > 0)
            {
                sql += " and buttresscode ='" + _ButtressCode + "'";
            }
            if (_AreaCode.Length > 0)
            {
                sql += " and areacode = '" + _AreaCode + "'";
            }

            //			sql += " order by areacode asc";

            try
            {

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

        }
        
        public ReturnObject TranQuery(string _Where)
        {
            try
            {
                string strOut = "";
                string Sql = "SELECT 'FALSE'  FLAG,B.OLD_SAMPL_NO,B.SLAB_NO,B.ORD_NO," +
                           "B.ORD_SEQ,B.SPEC_STL_GRD,B.COIL_INDIA,B.COIL_OUTDIA, " +
                           "A.ORD_THK COIL_THK,A.ORD_WTH COIL_WTH,A.SPEC_ABBSYM SX_BIAOZHUN," +
                           "B.ACT_WGT CAL_WGT,B.ACT_WGT,'合格' TOT_DEC_GRD," +
                           "B.REM REM,A.DEL_TO_DATE DEVLMT_DTIME," +
                           "B.DLIV_DIRNO SHIP_INVNO,B.TRANS_CAR_NO,T.STOVENO CHARGE_NO,SUBSTR(B.OLD_SAMPL_NO, 1, 10)BAHCT_NUMBER ,B.TRNF_DTIME MOVE_TIME,B.TRNF_REG MOVE_MAN  " +
                           "FROM TBJ02_COIL_COMM T, TBE02_ORD_PRC A, TBH02_COIL_COMM B WHERE B.OLD_SAMPL_NO LIKE 'R%' AND B.ORD_NO  = A.ORD_NO(+) AND B.ORD_SEQ = A.ORD_SEQ(+)  AND  B.OLD_SAMPL_NO=T.OLD_SAMPL_NO (+) AND B.DLIV_DIRNO IS NOT NULL  " + _Where;
                DataSet ds = this.DBManager.ExecuteQuery(Sql, out strOut);
                if (ds != null && ds.Tables.Count == 1)
                {
                    ds.Tables[0].TableName = "KCJ3_TRANSFERINFO";
                    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 TranImportQuery()
        {
            try
            {
                string strOut = "";
                string Sql = "SELECT 'FALSE'  FLAG,B.OLD_SAMPL_NO,B.SLAB_NO,B.ORD_NO," +
                           "B.ORD_SEQ,B.SPEC_STL_GRD,''COIL_INDIA,''COIL_OUTDIA,  " +
                           "B.COIL_THK,B.COIL_WTH,B.SX_BIAOZHUN," +
                           "B.CAL_WGT/1000 CAL_WGT,B.CAL_WGT/1000 ACT_WGT,'合格' TOT_DEC_GRD," +
                           "''REM,B.O_SENDDATE DEVLMT_DTIME," +
                           "B.SHIP_INVNO,B.TRANS_CAR_NO,B.CHARGE_NO,SUBSTR(B.OLD_SAMPL_NO, 1, 10)BAHCT_NUMBER ,B.MOVE_TIME,B.MOVE_MAN    " +
                           "FROM KCJ_JBZWIMPORT B   ";
                DataSet ds = this.DBManager.ExecuteQuery(Sql, out strOut);
                if (ds != null && ds.Tables.Count == 1)
                {
                    ds.Tables[0].TableName = "KCJ3_TRANSFERINFO";
                    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 TranQueryMan(string _Where)
        {
            try
            {
                string strOut = "";
                string Sql = " SELECT 'FALSE'  FLAG, A.OLD_SAMPL_NO,A.SHIP_INVNO,A.COIL_NO,A.SLAB_NO,A.ORD_NO,A.ORD_SEQ, " +
                            "A.DEVLMT_DTIME,A.COIL_INDIA,A.COIL_OUTDIA,COIL_LEN,COIL_THK,COIL_WTH,CAL_WGT, " +
                            "ACT_WGT,TOT_DEC_GRD,REM,TRANS_CAR_NO,ZLZS_NO,SPEC_STL_GRD,STOVENO,BAHCT_NUMBER," +
                            "SX_BIAOZHUN " +
                            "FROM  KCJ3_TRANSFERINFO A WHERE A.MOVE_ST='2' AND A.MOVE_TYPE='1'" + _Where;
                DataSet ds = this.DBManager.ExecuteQuery(Sql, out strOut);
                if (ds != null && ds.Tables.Count == 1)
                {
                    ds.Tables[0].TableName = "KCJ3_TRANSFERINFO";
                    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());
            }

        }
        
        /// <summary>
        /// 查询入库信息
        /// </summary>
        /// <param name="_Where"></param>
        /// <returns></returns>
        public ReturnObject StuffQuery(string _Where)
        {
            try
            {
                string strOut = "";
                string Sql = "SELECT A.OLD_SAMPL_NO,A.SLAB_NO,A.ORD_NO,B.BUTTRESS," +
                            "A.ORD_SEQ,A.STL_GRD,A.COIL_INDIA,A.COIL_OUTDIA,CASE WHEN A.CUST_CD IS NULL THEN (SELECT CUST_NM  FROM TBZ00_CUSTOMER  WHERE  REC_TP='01' AND REC_STS='1' AND CUST_CD=C.CUST_CD ) ELSE (SELECT CUST_NM  FROM TBZ00_CUSTOMER  WHERE  REC_TP='01' AND REC_STS='1' AND CUST_CD=A.CUST_CD)END  HTDW," +
                            "(SELECT CUST_NM  FROM TBZ00_CUSTOMER  WHERE  REC_TP='02' AND REC_STS='1' AND CUST_CD=C.ORDCUST_CD) SHDW, " +
                            "A.COIL_THK,COIL_WTH,A.COIL_LEN,A.STOVENO,A.BAHCT_NUMBER,a.INSTR_COIL_THK,a.INSTR_COIL_WTH," +
                            "A.CAL_WGT,A.ACT_WGT,A.TOT_DEC_GRD,SX_BIAOZHUN,A.ENDBUYER," +
                            "A.ZLZS_NO,A.REM,A.DEVLMT_DTIME,(SELECT NAME_ FROM kcj_basedata WHERE ID_=A.ORD_USE_CD)ORD_USE_CD," +
                            "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.AREA, a.MOVE_TIME,a.MOVE_MAN FROM KCJ3_STUFFLIST_ZW A ,KCJ3_STUFFBUTTRESSLIST_ZW B,TBA01_ORD_COMM C  " +
                            "WHERE A.OLD_SAMPL_NO=B.OLD_SAMPL_NO AND A.STORAGESTATUS='501002' AND A.ISVALID='1' AND A.ORD_NO=C.ORD_NO(+) " + _Where;
                DataSet ds = this.DBManager.ExecuteQuery(Sql, out strOut);
                if (ds != null && ds.Tables.Count == 1)
                {
                    ds.Tables[0].TableName = "KCJ3_STUFFLIST";
                    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());
            }
        }
        
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="_Ship_Invno"></param>
        /// <param name="_OtherInfo"></param>
        /// <returns></returns>
        public ReturnObject SetTran(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("KCJ3_COILMACHININGMANAGE.SET_COIL_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());
            }
        }
        
        /// <summary>
        /// 撤消手工录入
        /// </summary>
        /// <param name="_Ship_Invno"></param>
        /// <returns></returns>
        public ReturnObject DeleteTran(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("KCJ3_COILMACHININGMANAGE.COIL_DETELE", 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 (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, ex.ToString());
            }
        }
        
        /// <summary>
        /// 原料入库
        /// </summary>
        /// <param name="_Ship_Invno"></param>
        /// <param name="_OtherInfo"></param>
        /// <returns></returns>
        public ReturnObject StuffAdd(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("KCJ3_COILMACHININGMANAGE.STUFF_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 StuffAddTran(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.STUFF_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());
            }

        }
        
        #region "原料导入"
        public ReturnObject Storginist_Imp(System.Data.DataTable Tab_Imp, string MakeMan)
        {
            try
            {
                //string Begin_MakeNO = "0";
                string err = "";
                string MakeTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");


                #region"导入Excel原始数据"
                err = "";
                string sSql = "DELETE from KCJ_JBZWIMPORT";
                this.DBManager.ExecuteQuery(sSql, out err);
                string ESql = "SELECT BUYERCODE,ORD_NO,ORD_SEQ,BAHCT_NUMBER,OLD_SAMPL_NO,SLAB_NO,CHARGE_NO,SPEC_STL_GRD,SX_BIAOZHUN,COIL_INDIA,COIL_OUTDIA,O_THICK,O_WTH,COIL_THK,COIL_WTH,COIL_LEN,CAL_WGT,ACT_WGT,O_LX,TOT_DEC_GRD,O_SENDDATE,ZBS_BH,SHIP_INVNO,TRANS_CAR_NO,MOVE_MAN,MOVE_TIME,REM,DLIV_DIRNO,DEST_CD,ORDCUST_CD,PRODNM_CD FROM KCJ_JBZWIMPORT";
                System.Data.DataTable Tab_Commit = DealTab_Imp(Tab_Imp, MakeMan, MakeTime);
                this.DBManager.UpdateTable(Tab_Commit, ESql, out err);
                if (err.Length > 0)
                {
                    return new ReturnObject(null, err);
                }
                //string strPlan = Tab_Commit.Rows[0]["MAKETIME"].ToString();
                #endregion

                #region "处理原始数据 生成坯料设计主从表"
                //err = "";
                //Oracle.DataAccess.Client.OracleParameter pMakeMan = new Oracle.DataAccess.Client.OracleParameter("vMakeMan", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                //Oracle.DataAccess.Client.OracleParameter pMakeTime = new Oracle.DataAccess.Client.OracleParameter("vMakeTime", Oracle.DataAccess.Client.OracleDbType.Varchar2);

                //pMakeMan.Direction = ParameterDirection.Input;
                //pMakeTime.Direction = ParameterDirection.Input;

                //pMakeMan.Value = MakeMan;

                //pMakeTime.Value = strPlan;

                //((STMes.DBManager)DBManagerList["ODPDB"]).ExecuteNonQuery_NoDBSever("Train_IMP_BJ", CommandType.StoredProcedure,
                //    new Oracle.DataAccess.Client.OracleParameter[] { pMakeMan, pMakeTime }, out err);
                //if (err.Length > 0)
                //{
                //    return new ReturnObject(null, 1, err);
                //}
                //else
                //{
                //    return new ReturnObject('1');
                //}
                return new ReturnObject('1');
                #endregion
            }
            catch (System.Exception ex)
            {
                return new ReturnObject(null, ex.ToString());
            }
        }
       
        private System.Data.DataTable DealTab_Imp(System.Data.DataTable Tab_Imp, string MakeMan, string MakeTime)
        {
            try
            {
                #region "临时变量"
                string MakeDate = System.DateTime.Now.ToString("yyyyMMdd");
                //string ch = "";




                //string Memo = "";
                #endregion

                #region "表架构设置"
                Tab_Imp.TableName = "KCJ_JBZWIMPORT"; ;
                Tab_Imp.Columns[0].ColumnName = "BUYERCODE";
                Tab_Imp.Columns[1].ColumnName = "ORD_NO";
                Tab_Imp.Columns[2].ColumnName = "ORD_SEQ";

                Tab_Imp.Columns[3].ColumnName = "BAHCT_NUMBER";
                Tab_Imp.Columns[4].ColumnName = "OLD_SAMPL_NO";

                Tab_Imp.Columns[5].ColumnName = "SLAB_NO";

                Tab_Imp.Columns[6].ColumnName = "CHARGE_NO";


                Tab_Imp.Columns[7].ColumnName = "SPEC_STL_GRD";



                Tab_Imp.Columns[8].ColumnName = "SX_BIAOZHUN";


                //Tab_Imp.Columns.Add(new System.Data.DataColumn("WEIGHT", typeof(System.Double)));
                //Tab_Imp.Columns.Add(new System.Data.DataColumn("MONEY", typeof(System.Double)));
                //Tab_Imp.Columns.Add(new System.Data.DataColumn("PRICE", typeof(System.Double)));

                Tab_Imp.Columns[9].ColumnName = "COIL_INDIA";
                Tab_Imp.Columns[10].ColumnName = "COIL_OUTDIA";
                Tab_Imp.Columns[11].ColumnName = "O_THICK";
                Tab_Imp.Columns[12].ColumnName = "O_WTH";

                Tab_Imp.Columns[13].ColumnName = "COIL_THK";




                Tab_Imp.Columns[14].ColumnName = "COIL_WTH";
                Tab_Imp.Columns[15].ColumnName = "COIL_LEN";
                Tab_Imp.Columns[16].ColumnName = "CAL_WGT";
                Tab_Imp.Columns[17].ColumnName = "ACT_WGT";
                Tab_Imp.Columns[18].ColumnName = "O_LX";
                Tab_Imp.Columns[19].ColumnName = "TOT_DEC_GRD";
                Tab_Imp.Columns[20].ColumnName = "O_SENDDATE";

                Tab_Imp.Columns[21].ColumnName = "ZBS_BH";
                Tab_Imp.Columns[22].ColumnName = "SHIP_INVNO";
                Tab_Imp.Columns[23].ColumnName = "TRANS_CAR_NO";
                Tab_Imp.Columns[24].ColumnName = "MOVE_MAN";
                Tab_Imp.Columns[25].ColumnName = "MOVE_TIME";
                Tab_Imp.Columns[26].ColumnName = "REM";
                Tab_Imp.Columns[27].ColumnName = "DLIV_DIRNO";

                Tab_Imp.Columns[28].ColumnName = "DEST_CD";
                Tab_Imp.Columns[29].ColumnName = "ORDCUST_CD";
                Tab_Imp.Columns[30].ColumnName = "PRODNM_CD";


                Tab_Imp.Columns.Add(new System.Data.DataColumn("INPUTPERSON", typeof(System.String)));
                Tab_Imp.Columns.Add(new System.Data.DataColumn("MAKETIME", typeof(System.String)));






                Tab_Imp.AcceptChanges();


                #endregion

                #region "处理数据"
                foreach (System.Data.DataRow row in Tab_Imp.Rows)
                {
                    if (row["OLD_SAMPL_NO"].ToString() != "")
                    {
                        row.BeginEdit();
                        row["INPUTPERSON"] = MakeMan;
                        row["MAKETIME"] = MakeDate;

                    }







                    row.EndEdit();
                }
                #endregion

                #region "删除非法记录"
                for (int i = Tab_Imp.Rows.Count - 1; i >= 0; i--)
                {
                    if (Tab_Imp.Rows[i]["OLD_SAMPL_NO"].GetType() == typeof(System.DBNull))
                    {
                        Tab_Imp.Rows[i].Delete();
                    }
                }
                Tab_Imp.AcceptChanges();
                #endregion

                #region "生成提交数据"
                System.Data.DataTable Tab_Commit = Tab_Imp.Clone();
                foreach (System.Data.DataRow row in Tab_Imp.Rows)
                {
                    System.Data.DataRow nrow = Tab_Commit.NewRow();

                    nrow.ItemArray = row.ItemArray;
                    Tab_Commit.Rows.Add(nrow);
                }
                #endregion

                return Tab_Commit;
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return null;
            }
        }
        #endregion
        
        public ReturnObject Stuff_DelTran(ArrayList _OLD_SAMPL_NO)
        {
            try
            {
                string err = "";
                Oracle.DataAccess.Client.OracleParameter pShi_Invno = new Oracle.DataAccess.Client.OracleParameter("vOLD_SAMPL_NO", 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 = _OLD_SAMPL_NO.ToArray(typeof(string));

                int[] OSizeInf = new int[_OLD_SAMPL_NO.Count];
                for (int i = 0; i < _OLD_SAMPL_NO.Count; i++)
                {
                    OSizeInf[i] = 200;
                }
                pShi_Invno.Size = _OLD_SAMPL_NO.Count;
                pShi_Invno.ArrayBindSize = OSizeInf;
                pSuccessFlag.Size = 400;

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

        }

        /// <summary>
        /// 撤消原料信息
        /// </summary>
        /// <param name="_OLD_SAMPL_NO"></param>
        /// <returns></returns>
        public ReturnObject Stuff_Del(ArrayList _OLD_SAMPL_NO)
        {
            try
            {
                string err = "";
                Oracle.DataAccess.Client.OracleParameter pShi_Invno = new Oracle.DataAccess.Client.OracleParameter("vOLD_SAMPL_NO", 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 = _OLD_SAMPL_NO.ToArray(typeof(string));

                int[] OSizeInf = new int[_OLD_SAMPL_NO.Count];
                for (int i = 0; i < _OLD_SAMPL_NO.Count; i++)
                {
                    OSizeInf[i] = 200;
                }
                pShi_Invno.Size = _OLD_SAMPL_NO.Count;
                pShi_Invno.ArrayBindSize = OSizeInf;
                pSuccessFlag.Size = 400;

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

        }

        public ReturnObject CommitLoadVecihle(System.Collections.ArrayList LoadInfo, string type)
        {
            try
            {
                string err = "1";
                Oracle.DataAccess.Client.OracleParameter pLoadInfo = new Oracle.DataAccess.Client.OracleParameter("vLoadInfo", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pType = new Oracle.DataAccess.Client.OracleParameter("vType", Oracle.DataAccess.Client.OracleDbType.Varchar2);
                Oracle.DataAccess.Client.OracleParameter pSuccessFlag = new Oracle.DataAccess.Client.OracleParameter("vSuccessFlag", Oracle.DataAccess.Client.OracleDbType.Varchar2);

                pLoadInfo.Direction = ParameterDirection.Input;
                pType.Direction = ParameterDirection.Input;
                pSuccessFlag.Direction = ParameterDirection.Output;

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

                //pLoadInfo.Value = LoadInfo.ToArray(typeof(string));
                if (LoadInfo.Count > 0)
                    pLoadInfo.Value = LoadInfo.ToArray(typeof(string));
                else
                    pLoadInfo.Value = new string[] { "Empty" };


                pType.Value = type;

                int[] OSizeInf = new int[LoadInfo.Count];
                for (int i = 0; i < LoadInfo.Count; i++)
                {
                    OSizeInf[i] = 200;
                }
                pLoadInfo.Size = LoadInfo.Count;
                pLoadInfo.ArrayBindSize = OSizeInf;
                pSuccessFlag.Size = 400;

                ((STMes.DBManager)DBManagerList["ODPDBZW"]).ExecuteNonQuery_NoDBSever("KCJ_STORAGEMANAGER_WX.LOADVECIHLE_JB", CommandType.StoredProcedure,
                new Oracle.DataAccess.Client.OracleParameter[] { pLoadInfo, pType, pSuccessFlag }, out err);
                err = pSuccessFlag.Value.ToString();
                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);
            }
        }

        public ReturnObject UpdateEndBuyer(string ENDBUYER, string OLD_SAMPL_NO)
        {
            try
            {
                string strOut = "";
                string Sql = "update kcj3_stufflist_zw set ENDBUYER = '" + ENDBUYER + "' where OLD_SAMPL_NO = '" + OLD_SAMPL_NO + "';";
                this.DBManager.ExecuteQuery(Sql, out strOut);
				if(strOut.Length == 0)
				{
					return new ReturnObject("1");//success
				}
				else
				{
					return new ReturnObject(strOut.ToString());//cuowu
				}
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return new ReturnObject(null, 10004, ex.ToString());
            }
        }
    }
}
