/// <summary> /// Get Data Direct from Table /// </summary> /// <param name="keyValue">integer key value</param> /// <param name="saveInCache">saveInCache save in cache</param> /// <param name="trxName"></param> /// <returns></returns> public NamePair GetDirect(Object keyValue, bool saveInCache, Trx trxName) { MLocator loc = GetMLocator(keyValue, trxName); if (loc == null) { return(null); } // int key = loc.GetM_Locator_ID(); KeyNamePair retValue = new KeyNamePair(key, loc.ToString()); if (saveInCache) { _lookup.Add(key, retValue); } return(retValue); }
/// <summary> ///Load Lookup /// </summary> private void Load() { // log.config("MLocatorLookup Loader.run " + m_AD_Column_ID); // Set Info - see VLocator.actionText int only_Warehouse_ID = GetOnly_Warehouse_ID(); int only_Product_ID = GetOnly_Product_ID(); bool?only_IsSOTrx = IsOnly_Outgoing(); //int sqlParaCount = 0; StringBuilder sql = new StringBuilder("SELECT * FROM M_Locator ") .Append(" WHERE IsActive='Y'"); if (only_Warehouse_ID != 0) { sql.Append(" AND M_Warehouse_ID=@w"); } if (only_Product_ID != 0) { sql.Append(" AND (IsDefault='Y' "); // Default Locator // Something already stored sql.Append("OR EXISTS (SELECT * FROM M_Storage s ") // Storage Locator .Append("WHERE s.M_Locator_ID=M_Locator.M_Locator_ID AND s.M_Product_ID=@p)"); if (only_IsSOTrx == null || !only_IsSOTrx.Value) { // Default Product sql.Append("OR EXISTS (SELECT * FROM M_Product p ") // Default Product Locator .Append("WHERE p.M_Locator_ID=M_Locator.M_Locator_ID AND p.M_Product_ID=@p)"); // Product Locators sql.Append("OR EXISTS (SELECT * FROM M_ProductLocator pl ") // Product Locator .Append("WHERE pl.M_Locator_ID=M_Locator.M_Locator_ID AND pl.M_Product_ID=@p)"); // No locators defined for the warehouse sql.Append("OR 0 = (SELECT COUNT(*) "); sql.Append("FROM M_ProductLocator pl"); sql.Append(" INNER JOIN M_Locator l2 ON (pl.M_Locator_ID=l2.M_Locator_ID) "); sql.Append("WHERE pl.M_Product_ID=@p AND l2.M_Warehouse_ID=M_Locator.M_Warehouse_ID )"); } sql.Append(" ) "); } String finalSql = MRole.GetDefault((Context)GetCtx(), false).AddAccessSQL( sql.ToString(), "M_Locator", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO); //if (_loader.ThreadState == ThreadState.Suspended) //{ // log.log(Level.SEVERE, "Interrupted"); // return; //} // Reset _lookup.Clear(); int rows = 0; try { List <System.Data.SqlClient.SqlParameter> para = new List <System.Data.SqlClient.SqlParameter>(); // int index = 1; if (only_Warehouse_ID != 0) { // pstmt.setInt(index++, only_Warehouse_ID); para.Add(new System.Data.SqlClient.SqlParameter("@w", only_Warehouse_ID)); } if (only_Product_ID != 0) { para.Add(new System.Data.SqlClient.SqlParameter("@p", only_Product_ID)); } DataSet ds = DataBase.DB.ExecuteDataset(finalSql, para.ToArray(), null); // foreach (DataRow dr in ds.Tables[0].Rows) { // Max out if (rows++ > _maxRows) { log.Warning("Over Max Rows - " + rows); break; } MLocator loc = new MLocator((Context)GetCtx(), dr, null); int M_Locator_ID = loc.GetM_Locator_ID(); KeyNamePair pp = new KeyNamePair(M_Locator_ID, loc.ToString()); _lookup.Add(M_Locator_ID, pp); } ds.Dispose(); ds = null; } catch (Exception e) { log.Log(Level.SEVERE, finalSql, e); } log.Fine("Complete #" + _lookup.Count); if (_lookup.Count == 0) { log.Finer(finalSql); } }