Example #1
0
        /// <summary>
        /// Is Used to Get or Create  Instance of MInoutLineMA (Attribute)
        /// </summary>
        /// <param name="line"></param>
        /// <param name="M_AttributeSetInstance_ID"></param>
        /// <param name="MovementQty"></param>
        /// <param name="DateMaterialPolicy"></param>
        /// <returns></returns>
        public static MInOutLineMA GetOrCreate(MInOutLine line, int M_AttributeSetInstance_ID, Decimal MovementQty, DateTime?DateMaterialPolicy)
        {
            MInOutLineMA retValue = null;
            String       sql      = "SELECT * FROM M_InoutLineMA " +
                                    @" WHERE  M_InOutLine_ID = " + line.GetM_InOutLine_ID() +
                                    @" AND MMPolicyDate = " + GlobalVariable.TO_DATE(DateMaterialPolicy, true) + @" AND ";

            if (M_AttributeSetInstance_ID == 0)
            {
                sql += "(M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID + " OR M_AttributeSetInstance_ID IS NULL)";
            }
            else
            {
                sql += "M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID;
            }
            DataTable   dt  = null;
            IDataReader idr = null;

            try
            {
                idr = DB.ExecuteReader(sql, null, line.Get_Trx());
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    retValue = new MInOutLineMA(line.GetCtx(), dr, line.Get_Trx());
                }
            }
            catch (Exception ex)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, ex);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                }
                dt = null;
            }
            if (retValue == null)
            {
                retValue = new MInOutLineMA(line, M_AttributeSetInstance_ID, MovementQty, DateMaterialPolicy);
            }
            else
            {
                retValue.SetMovementQty(Decimal.Add(retValue.GetMovementQty(), MovementQty));
            }
            return(retValue);
        }
Example #2
0
        /**
         *  Get Material Allocations for Line
         *	@param ctx context
         *	@param M_InOutLine_ID line
         *	@param trxName trx
         *	@return allocations
         */
        public static MInOutLineMA[] Get(Ctx ctx, int M_InOutLine_ID, Trx trxName)
        {
            List <MInOutLineMA> list = new List <MInOutLineMA>();
            String  sql = "SELECT * FROM M_InOutLineMA WHERE M_InOutLine_ID=" + M_InOutLine_ID;
            DataSet ds  = null;

            try
            {
                ds = DataBase.DB.ExecuteDataset(sql, null, trxName);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    list.Add(new MInOutLineMA(ctx, dr, trxName));
                }
                ds = null;
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }
            MInOutLineMA[] retValue = new MInOutLineMA[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }