/// <summary> /// Get Material Allocations for Line /// </summary> /// <param name="ctx">context</param> /// <param name="M_MovementLine_ID">id</param> /// <param name="trxName">transaction</param> /// <returns>allocations</returns> public static MMovementLineMA[] Get(Ctx ctx, int M_MovementLine_ID, Trx trxName) { List <MMovementLineMA> list = new List <MMovementLineMA>(); String sql = "SELECT * FROM M_MovementLineMA WHERE M_MovementLine_ID=@mlid"; try { SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@mlid", M_MovementLine_ID); DataSet ds = DataBase.DB.ExecuteDataset(sql, param, trxName); foreach (DataRow dr in ds.Tables[0].Rows) { list.Add(new MMovementLineMA(ctx, dr, trxName)); } } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } MMovementLineMA[] retValue = new MMovementLineMA[list.Count]; retValue = list.ToArray(); return(retValue); }
/// <summary> /// Is Used to Get or Create Instance of MMovementLineMA (Attribute) /// </summary> /// <param name="line"></param> /// <param name="M_AttributeSetInstance_ID"></param> /// <param name="MovementQty"></param> /// <param name="DateMaterialPolicy"></param> /// <returns></returns> public static MMovementLineMA GetOrCreate(MMovementLine line, int M_AttributeSetInstance_ID, Decimal MovementQty, DateTime?DateMaterialPolicy) { MMovementLineMA retValue = null; String sql = "SELECT * FROM M_MovementLineMA " + @" WHERE M_MovementLine_ID = " + line.GetM_MovementLine_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 MMovementLineMA(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 MMovementLineMA(line, M_AttributeSetInstance_ID, MovementQty, DateMaterialPolicy); } else { retValue.SetMovementQty(Decimal.Add(retValue.GetMovementQty(), MovementQty)); } return(retValue); }