예제 #1
0
 public static List <object> ChildSelect(PXCache cache, object row, Type ParentType)
 {
     foreach (PXEventSubscriberAttribute attr in cache.GetAttributes(null))
     {
         if (attr is PXParentAttribute && ((PXParentAttribute)attr).ParentType.IsAssignableFrom(ParentType))
         {
             PXView view = ((PXParentAttribute)attr).GetChildrenSelect(cache);
             return(view.SelectMultiBound(new object[] { row }));
         }
     }
     return(null);
 }
        private static object SelectSingleBound(PXView view, object[] currents, params object[] pars)
        {
            List <object> ret = view.SelectMultiBound(currents, pars);

            if (ret.Count > 0)
            {
                if (ret[0] is PXResult)
                {
                    return(((PXResult)ret[0])[0]);
                }
                return(ret[0]);
            }

            return(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);
                }
            }
        protected virtual IEnumerable activity()
        {
            List <object>        args      = new List <object>();
            PMTimeActivityFilter filterRow = Filter.Current;

            if (filterRow == null)
            {
                return(null);
            }

            BqlCommand cmd;

            cmd = BqlCommand.CreateInstance(typeof(Select2 <
                                                       EPActivityApprove,
                                                       LeftJoin <EPEarningType,
                                                                 On <EPEarningType.typeCD, Equal <EPActivityApprove.earningTypeID> >,
                                                                 LeftJoin <CRActivityLink,
                                                                           On <CRActivityLink.noteID, Equal <EPActivityApprove.refNoteID> >,
                                                                           LeftJoin <CRCase,
                                                                                     On <CRCase.noteID, Equal <CRActivityLink.refNoteID> >,
                                                                                     LeftJoin <ContractEx,
                                                                                               On <CRCase.contractID, Equal <ContractEx.contractID> > > > > >,
                                                       Where
                                                       <EPActivityApprove.ownerID, Equal <Current <PMTimeActivityFilter.ownerID> >,
                                                        And <EPActivityApprove.trackTime, Equal <True>,
                                                             And <EPActivityApprove.isCorrected, Equal <False> > > >,
                                                       OrderBy <Desc <EPActivityApprove.date> > >));


            if (filterRow.ProjectID != null)
            {
                cmd = cmd.WhereAnd <Where <EPActivityApprove.projectID, Equal <Current <PMTimeActivityFilter.projectID> > > >();
            }

            if (filterRow.ProjectTaskID != null)
            {
                cmd = cmd.WhereAnd <Where <EPActivityApprove.projectTaskID, Equal <Current <PMTimeActivityFilter.projectTaskID> > > >();
            }

            if (filterRow.FromWeek != null || filterRow.TillWeek != null)
            {
                List <Type> cmdList = new List <Type>();

                if (filterRow.IncludeReject == true)
                {
                    cmdList.Add(typeof(Where <, ,>));
                    cmdList.Add(typeof(EPActivityApprove.approvalStatus));
                    cmdList.Add(typeof(Equal <CR.ActivityStatusListAttribute.rejected>));
                    cmdList.Add(typeof(Or <>));
                }

                if (filterRow.FromWeek != null)
                {
                    if (filterRow.TillWeek != null)
                    {
                        cmdList.Add(typeof(Where <, ,>));
                    }
                    else
                    {
                        cmdList.Add(typeof(Where <,>));
                    }
                    cmdList.Add(typeof(EPActivityApprove.weekID));
                    cmdList.Add(typeof(GreaterEqual <Required <PMTimeActivityFilter.fromWeek> >));
                    args.Add(filterRow.FromWeek);
                    if (filterRow.TillWeek != null)
                    {
                        cmdList.Add(typeof(And <>));
                    }
                }

                if (filterRow.TillWeek != null)
                {
                    cmdList.Add(typeof(Where <EPActivityApprove.weekID, LessEqual <Required <PMTimeActivityFilter.tillWeek> > >));
                    args.Add(filterRow.TillWeek);
                }

                cmd = cmd.WhereAnd(BqlCommand.Compose(cmdList.ToArray()));
            }

            PXView view = new PXView(this, false, cmd);

            return(view.SelectMultiBound(new object[] { Filter.Current }, args.ToArray()));
        }