//From PX.Api.OData.Model.GIDataService public static object UnwrapValue(object value) { PXFieldState state = value as PXFieldState; if (state != null) { if (state.Value == null && state.DefaultValue != null) // for a case when field has PXDefault attribute, but null value because of inconsistency in DB { state.Value = state.DefaultValue; } if (state.Value != null && !state.DataType.IsInstanceOfType(state.Value)) // for a case when, for example, some field of int type has PXSelectorAttribute with substitute field of string type, and PXSelectorAttribute can't find corresponding row for substitute field { state.Value = Convert.ChangeType(state.Value, state.DataType); } } PXStringState strState = value as PXStringState; if (strState != null && strState.Value != null && strState.ValueLabelDic != null && strState.ValueLabelDic.ContainsKey((string)strState.Value)) { return(strState.ValueLabelDic[(string)strState.Value]); } PXIntState intState = value as PXIntState; if (intState != null && intState.Value != null && intState.ValueLabelDic != null) { return(intState.ValueLabelDic.ContainsKey((int)intState.Value) ? intState.ValueLabelDic[(int)intState.Value] : intState.Value.ToString()); } return(PXFieldState.UnwrapValue(value)); }
public static object GetNewValueByIncoming(PXCache cache, object row, string fieldName, bool externalCall) { object incoming = null; if (externalCall) { incoming = cache.GetValuePending(row, fieldName); if (incoming != null) { return(incoming); } } try { incoming = cache.GetValueExt(row, fieldName); return(PXFieldState.UnwrapValue(incoming)); } catch { } return(cache.GetValue(row, fieldName)); }
public static void RaiseOrHideError <T>(PXCache cache, object row, bool isIncorrect, string message, PXErrorLevel errorLevel, params object[] parameters) where T : IBqlField { if (isIncorrect) { cache.RaiseExceptionHandling <T>(row, PXFieldState.UnwrapValue(cache.GetValueExt <T>(row)), new PXSetPropertyException(message, errorLevel, parameters)); } else { cache.RaiseExceptionHandling <T>(row, PXFieldState.UnwrapValue(cache.GetValueExt <T>(row)), null); } }
void IPrefetchable <DefinitionParams> .Prefetch(DefinitionParams parameters) { try { PXContext.SetSlot <bool>(PXSelectorAttribute.selectorBypassInit, true); List <object> attributes = new List <object>(); List <string> distinct = new List <string>(); PXView view = null; IBqlSearch srch = null; if (parameters.Selector == null) { PXFieldState state = parameters.Foreign.GetStateExt(null, parameters.Field.Name) as PXFieldState; if (state != null && !String.IsNullOrEmpty(state.ViewName)) { view = parameters.Main.Graph.Views[state.ViewName]; srch = view.BqlSelect as IBqlSearch; } } else { view = new PXView(parameters.Main.Graph, true, parameters.Selector); srch = view.BqlSelect as IBqlSearch; } if (srch != null) { if (!view.AllowSelect) { throw new PXException(ErrorMessages.NotEnoughRightsToAccessObject, view.GetItemType().Name); } object current = parameters.Main.CreateInstance(); foreach (object res in view.SelectMultiBound(new object[] { current })) { object attr = (res is PXResult ? ((PXResult)res)[0] : res); if (attr != null) { string name = view.Cache.GetValue(attr, srch.GetField().Name) as string; if (!String.IsNullOrEmpty(name) && !distinct.Contains(name)) { distinct.Add(name); attributes.Add(attr); } } } // Creating empty graph to get original field state without overridden attributes on CacheAttached in parameters.Main.Graph PXGraph independentGraph = PXGraph.CreateInstance <AttrGraph>(); PXCache independentCache = independentGraph.Caches[parameters.Main.GetItemType()]; foreach (IBqlParameter par in view.BqlSelect.GetParameters()) { if (par.HasDefault && par.GetReferencedType().IsNested&& BqlCommand.GetItemType(par.GetReferencedType()).IsAssignableFrom(parameters.Main.GetItemType())) { PXFieldState state = independentCache.GetStateExt(null, par.GetReferencedType().Name) as PXFieldState; // graph-independent state if (state != null && !String.IsNullOrEmpty(state.ViewName)) { PXView parview = independentGraph.Views[state.ViewName]; List <object> pars = new List <object>(); IBqlSearch parsrch = parview.BqlSelect as IBqlSearch; if (parsrch != null) { foreach (object res in parview.SelectMultiBound(new object[] { current })) { object item = res; if (item is PXResult) { item = PXResult.Unwrap(item, parview.Cache.GetItemType()); } if (item is PXFieldState) { item = PXFieldState.UnwrapValue(item); } object cls = parview.Cache.GetValue(item, parsrch.GetField().Name); if (cls != null) { parameters.Main.SetValue(current, par.GetReferencedType().Name, cls); foreach (object parres in view.SelectMultiBound(new object[] { current })) { object attr = (parres is PXResult ? ((PXResult)parres)[0] : parres); if (attr != null) { string name = view.Cache.GetValue(attr, srch.GetField().Name) as string; if (!String.IsNullOrEmpty(name) && !distinct.Contains(name)) { distinct.Add(name); attributes.Add(attr); } } } } } } } break; } } } List <PXFieldState> fields = new List <PXFieldState>(); foreach (object attr in attributes) { var fs = CreateFieldState(((string)view.Cache.GetValue(attr, srch.GetField().Name)) + '_' + parameters.FieldName, (string)view.Cache.GetValue(attr, parameters.DescriptionField), (int)view.Cache.GetValue(attr, parameters.ControlTypeField), (string)view.Cache.GetValue(attr, parameters.EntryMaskField), (string)view.Cache.GetValue(attr, parameters.ListField)); if (fs != null) { fields.Add(fs); } } Fields = fields.ToArray(); } finally { PXContext.SetSlot <bool>(PXSelectorAttribute.selectorBypassInit, false); } }