private static VLogger _log = VLogger.GetVLogger(typeof(MAd).FullName);//.class); /// <summary> /// Get Next of this Category, this Procedure will return the next Ad in a category and expire it if needed /// </summary> /// <param name="ctx">context</param> /// <param name="CM_Ad_Cat_ID">id</param> /// <param name="trxName">trx</param> /// <returns>MAD</returns> public static MAd GetNext(Ctx ctx, int CM_Ad_Cat_ID, Trx trxName) { MAd thisAd = null; String sql = "SELECT * FROM CM_Ad WHERE IsActive='Y' AND (ActualImpression+StartImpression<MaxImpression OR MaxImpression=0) AND CM_Ad_Cat_ID=@param ORDER BY ActualImpression+StartImpression"; SqlParameter[] param = new SqlParameter[1]; IDataReader idr = null; try { //pstmt = DataBase.prepareStatement(sql, trxName); //pstmt.setInt(1, CM_Ad_Cat_ID); param[0] = new SqlParameter("@param", CM_Ad_Cat_ID); idr = DataBase.DB.ExecuteReader(sql, param, trxName); if (idr.Read()) { thisAd = new MAd(ctx, idr, trxName); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } _log.Log(Level.SEVERE, sql, e); } if (thisAd != null) { thisAd.AddImpression(); } return(thisAd); }
} // afterDelete /// <summary> /// Get's all the Ads from Template AD Cat (including all subtemplates) /// </summary> /// <returns>array of MAd</returns> public MAd[] GetAds() { int[] AdCats = null; String sql = "SELECT count(*) FROM CM_Template_AD_Cat WHERE CM_Template_ID IN (" + _adTemplates.ToString().Substring(0, _adTemplates.Length - 1) + ")"; IDataReader idr = null; try { int numberAdCats = 0; //pstmt = DataBase.prepareStatement (sql, get_TrxName ()); idr = DataBase.DB.ExecuteReader(sql, null, Get_TrxName()); if (idr.Read()) { numberAdCats = Utility.Util.GetValueOfInt(idr[0]);// rs.getInt(1); } idr.Close(); AdCats = new int[numberAdCats]; int i = 0; sql = "SELECT CM_Ad_Cat_ID FROM CM_Template_AD_Cat WHERE CM_Template_ID IN (" + _adTemplates.ToString().Substring(0, _adTemplates.Length - 1) + ")"; //pstmt = DataBase.prepareStatement (sql, get_TrxName ()); idr = DataBase.DB.ExecuteReader(sql, null, Get_TrxName()); while (idr.Read()) { AdCats[i] = Utility.Util.GetValueOfInt(idr[0]);// rs.getInt(1); i++; } idr.Close(); } catch (Exception ex) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, sql, ex); } if (AdCats != null && AdCats.Length > 0) { MAd[] returnAds = new MAd[AdCats.Length]; for (int i = 0; i < AdCats.Length; i++) { MAd thisAd = MAd.GetNext(GetCtx(), AdCats[i], Get_TrxName()); if (thisAd != null) { returnAds[i] = thisAd; } } return(returnAds); } else { return(null); } } // getAds