/// <summary> /// Parse Variable /// </summary> /// <param name="variable">variable</param> /// <param name="po">po object</param> /// <returns>translated variable or if not found the original tag</returns> private String ParseVariable(String variable, PO po) { int index = po.Get_ColumnIndex(variable); if (index == -1) { return("@" + variable + "@"); // keep for next } // Object value = po.Get_Value(index); //Get lookup display column name for ID if (_poInfo != null && _poInfo.getAD_Table_ID() == po.Get_Table_ID() && _poInfo.IsColumnLookup(index) && value != null) { VLookUpInfo lookup = _poInfo.GetColumnLookupInfo(index); //create lookup info for column DataSet ds = DB.ExecuteDataset(lookup.queryDirect.Replace("@key", DB.TO_STRING(value.ToString())), null); //Get Name from data if (ds != null && ds.Tables[0].Rows.Count > 0) { value = ds.Tables[0].Rows[0][2]; //Name Value } } if (value == null) { return(""); } return(value.ToString()); }
/// <summary> /// Dispose /// </summary> public override void Dispose() { if (_vInfo != null) { log.Fine(_vInfo.keyColumn + ": dispose"); } if (_loader != null && _loader.IsAlive) { _loader.Interrupt(); } _loader = null; // if (_lookup != null) { _lookup.Clear(); } _lookup = null; if (_lookupDirect != null) { _lookupDirect.Clear(); } _lookupDirect = null; // _vInfo = null; base.Dispose(); // } // dispose
} // loadStart /// <summary> ///MLookup Loader ends loading, so add it to cache /// </summary> /// <param name="info"></param> /// <param name="lookup"></param> public static void LoadEnd(VLookUpInfo info, Dictionary <Object, NamePair> lookup, bool allLoaded, bool hasInActive) { if (info.isValidated && lookup.Count > 0) { string key = GetKey(info); s_loadedLookups.Add(key, lookup); s_loadedLookupsParam.Add(key, new KeyValuePair <bool, bool>(allLoaded, hasInActive)); } }
/// <summary> /// Get Storage Key /// </summary> /// <param name="info"></param> /// <returns></returns> private static String GetKey(VLookUpInfo info) { if (info == null) { return(CommonFunctions.CurrentTimeMillis().ToString()); } // StringBuilder sb = new StringBuilder(); sb.Append(info.column_ID).Append(":") .Append(info.keyColumn) .Append(info.AD_Reference_Value_ID) .Append(info.query) .Append(info.validationCode); // does not include ctx return(sb.ToString()); }
/// <summary> ///Load from Cache if applicable /// Called from MLookup constructor /// </summary> /// <param name="info"></param> /// <param name="lookupTarget">Target Dictionary</param> /// <returns></returns> public static bool LoadFromCache(VLookUpInfo info, Dictionary <Object, NamePair> lookupTarget, out bool allLoaded, out bool hasInActive) { String key = GetKey(info); Dictionary <object, NamePair> cache = null; allLoaded = false; hasInActive = false; s_loadedLookups.TryGetValue(key, out cache); if (cache == null) { return(false); } // Nothing cached if (cache.Count == 0) { s_loadedLookups.Remove(key); return(false); } // we can use iterator, as the lookup loading is complete (i.e. no additional entries) IEnumerator <Object> iterator = cache.Keys.GetEnumerator(); while (iterator.MoveNext()) { Object cacheKey = iterator.Current; NamePair cacheData = cache[cacheKey]; lookupTarget.Add(cacheKey, cacheData); } if (s_loadedLookupsParam.ContainsKey(key)) { KeyValuePair <bool, bool> o = s_loadedLookupsParam[key]; allLoaded = o.Key; hasInActive = o.Value; } _log.Fine("#" + lookupTarget.Count); return(true); }
/// <summary> /// Get lookup Info /// </summary> /// <param name="index">index of column</param> /// <returns>Lookup info</returns> /// <remarks> /// Used for MMailTemplate for fetch text against Id Column /// </remarks> public VLookUpInfo GetColumnLookupInfo(int index) { if (!IsColumnLookup(index)) { return(null); } // int WindowNo = 0; // List, Table, TableDir VLookUpInfo lookup = null; try { lookup = VLookUpFactory.GetLookUpInfo(m_ctx, WindowNo, m_columns[index].DisplayType, m_columns[index].AD_Column_ID, Env.GetLanguage(m_ctx), m_columns[index].ColumnName, m_columns[index].AD_Reference_Value_ID, m_columns[index].IsParent, m_columns[index].ValidationCode); } catch { lookup = null; // cannot create Lookup } return(lookup); }
/// <summary> /// Parse Variable /// </summary> /// <param name="variable">variable</param> /// <param name="po">po object</param> /// <returns>translated variable or if not found the original tag</returns> private static string ParseVariable(String variable, PO po) { int index = po.Get_ColumnIndex(variable); if (index == -1) { return("@" + variable + "@"); // keep for next } // Object value = po.Get_Value(index); if (value == null) { return(""); } POInfo _poInfo = POInfo.GetPOInfo(po.GetCtx(), po.Get_Table_ID()); MColumn column = (new MTable(po.GetCtx(), po.Get_Table_ID(), null)).GetColumn(variable); if (column.GetAD_Reference_ID() == DisplayType.Location) { StringBuilder sb = new StringBuilder(); DataSet ds = DB.ExecuteDataset(@"SELECT l.address1, l.address2, l.address3, l.address4, l.city, CASE WHEN l.C_City_ID IS NOT NULL THEN ( SELECT NAME FROM C_City ct WHERE ct.C_City_ID=l.C_City_ID ) ELSE NULL END CityName, (SELECT NAME FROM C_Country c WHERE c.C_Country_ID=l.C_Country_ID ) AS CountryName FROM C_Location l WHERE l.C_Location_ID=" + value); if (ds != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["address1"] != null && ds.Tables[0].Rows[0]["address1"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["address1"]).Append(","); } if (ds.Tables[0].Rows[0]["address2"] != null && ds.Tables[0].Rows[0]["address2"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["address2"]).Append(","); } if (ds.Tables[0].Rows[0]["address3"] != null && ds.Tables[0].Rows[0]["address3"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["address3"]).Append(","); } if (ds.Tables[0].Rows[0]["address4"] != null && ds.Tables[0].Rows[0]["address4"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["address4"]).Append(","); } if (ds.Tables[0].Rows[0]["city"] != null && ds.Tables[0].Rows[0]["city"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["city"]).Append(","); } if (ds.Tables[0].Rows[0]["CityName"] != null && ds.Tables[0].Rows[0]["CityName"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["CityName"]).Append(","); } if (ds.Tables[0].Rows[0]["CountryName"] != null && ds.Tables[0].Rows[0]["CountryName"] != DBNull.Value) { sb.Append(ds.Tables[0].Rows[0]["CountryName"]).Append(","); } return(sb.ToString().TrimEnd(',')); } else { return(""); } } //Get lookup display column name for ID if (_poInfo != null && _poInfo.getAD_Table_ID() == po.Get_Table_ID() && _poInfo.IsColumnLookup(index) && value != null) { VLookUpInfo lookup = _poInfo.GetColumnLookupInfo(index); //create lookup info for column DataSet ds = DB.ExecuteDataset(lookup.queryDirect.Replace("@key", DB.TO_STRING(value.ToString())), null); //Get Name from data if (ds != null && ds.Tables[0].Rows.Count > 0) { value = ds.Tables[0].Rows[0][2]; //Name Value } } if (column.GetAD_Reference_ID() == DisplayType.Date) { return(Util.GetValueOfDateTime(value).Value.Date.ToShortDateString()); } return(value.ToString()); }
/// <summary> /// MLookup Loader starts loading - ignore for now /// </summary> /// <param name="info"></param> public static void loadStart(VLookUpInfo info) { } // loadStart
} // getPOInfo /// <summary> /// Get SQL Query for table /// </summary> /// <returns>SQL Query (String)</returns> public string GetSQLQuery() { StringBuilder _querySQL = new StringBuilder(""); if (m_columns.Length > 0) { _querySQL.Append("SELECT "); MTable tbl = new MTable(m_ctx, _AD_Table_ID, null); // append all columns from table and get comma separated string _querySQL.Append(tbl.GetSelectColumns()); foreach (var column in m_columns) { // check if column name length is less than 26, then only add this column in selection column // else only ID will be displayed // as limitation in oracle to restrict column name to 30 characters if ((column.ColumnName.Length + 4) < 30) { // for Lookup type of columns if (DisplayType.IsLookup(column.DisplayType)) { VLookUpInfo lookupInfo = VLookUpFactory.GetLookUpInfo(m_ctx, 0, column.DisplayType, column.AD_Column_ID, Env.GetLanguage(m_ctx), column.ColumnName, column.AD_Reference_Value_ID, column.IsParent, column.ValidationCode); if (lookupInfo != null && lookupInfo.displayColSubQ != null && lookupInfo.displayColSubQ.Trim() != "") { if (lookupInfo.queryDirect.Length > 0) { // create columnname as columnname_TXT for lookup type of columns lookupInfo.displayColSubQ = " (SELECT MAX(" + lookupInfo.displayColSubQ + ") " + lookupInfo.queryDirect.Substring(lookupInfo.queryDirect.LastIndexOf(" FROM " + lookupInfo.tableName + " "), lookupInfo.queryDirect.Length - (lookupInfo.queryDirect.LastIndexOf(" FROM " + lookupInfo.tableName + " "))) + ") AS " + column.ColumnName + "_TXT"; lookupInfo.displayColSubQ = lookupInfo.displayColSubQ.Replace("@key", tbl.GetTableName() + "." + column.ColumnName); } _querySQL.Append(", " + lookupInfo.displayColSubQ); } } // case for Location type of columns else if (column.DisplayType == DisplayType.Location) { _querySQL.Append(", " + column.ColumnName + " AS " + column.ColumnName + "_LOC"); } // case for Locator type of columns else if (column.DisplayType == DisplayType.Locator) { _querySQL.Append(", " + column.ColumnName + " AS " + column.ColumnName + "_LTR"); } // case for Attribute Set Instance & General Attribute columns else if (column.DisplayType == DisplayType.PAttribute || column.DisplayType == DisplayType.GAttribute) { _querySQL.Append(", " + column.ColumnName + " AS " + column.ColumnName + "_ASI"); } // case for Account type of columns else if (column.DisplayType == DisplayType.Account) { _querySQL.Append(", " + column.ColumnName + " AS " + column.ColumnName + "_ACT"); } } } // Append FROM table name to query _querySQL.Append(" FROM " + tbl.GetTableName()); } return(_querySQL.ToString()); }
/// <summary> /// Initialize LookUp Data /// </summary> /// <param name="info"></param> /// <returns></returns> public MLookup Initialize(VLookUpInfo info) { // _vInfo = info; // log.Fine(_vInfo.keyColumn); // // load into local lookup, if already cached // //if (MLookupCache.LoadFromCache(_vInfo, _lookup,out this._allLoaded, out this._hasInactive)) // // { // // return this; // // } // // Don't load Search or CreatedBy/UpdatedBy // if (GetDisplayType() == DisplayType.Search || _vInfo.isCreadedUpdatedBy) // { // return this; // } // // Don't load Parents/Keys // if (_vInfo.isParent || _vInfo.isKey) // { // _hasInactive = true; // creates focus listener for dynamic loading // return this; // required when parent needs to be selected (e.g. price from product) // } // // Load(); // // _loader = new System.Threading.Thread (new System.Threading.ThreadStart(Load)); // // _loader.Start(); // // Load(); // return this; //Lakhwinder _vInfo = info; log.Fine(_vInfo.keyColumn); // load into local lookup, if already cached //if (MLookupCache.LoadFromCache(_vInfo, _lookup)) //{ // return this; //} if (_vInfo.isCreadedUpdatedBy) { return(this); } //if (GetDisplayType() == DisplayType.Search || _vInfo.isParent) //{ // //FillDirectList(); // return this; //} if (_vInfo.isParent || _vInfo.isKey) { _hasInactive = true; // creates focus listener for dynamic loading return(this); // required when parent needs to be selected (e.g. price from product) } //_loader = new System.Threading.Thread(new System.Threading.ThreadStart(Load)); //_loader.IsBackground = true; //_loader.CurrentCulture = Utility.Env.GetLanguage(Utility.Envs.GetContext()).GetCulture(Utility.Env.GetLoginLanguage(Utility.Envs.GetContext()).GetAD_Language()); //_loader.CurrentUICulture = Utility.Env.GetLanguage(Utility.Envs.GetContext()).GetCulture(Utility.Env.GetLoginLanguage(Utility.Envs.GetContext()).GetAD_Language()); //_loader.Start(); //if (!_vIn---fo.isValidated) //{ // FillDirectList(); //} //else //{ //Load(); //} return(this); }