コード例 #1
0
        protected static void Approve(List <EPOwned> items)
        {
            EntityHelper helper = new EntityHelper(new PXGraph());
            var          graphs = new Dictionary <Type, PXGraph>();

            bool errorOccured = false;

            foreach (EPOwned item in items)
            {
                try
                {
                    PXProcessing <EPApproval> .SetCurrentItem(item);

                    if (item.RefNoteID == null)
                    {
                        throw new PXException(Messages.ApprovalRefNoteIDNull);
                    }
                    object row = helper.GetEntityRow(item.RefNoteID.Value, true);

                    if (row == null)
                    {
                        throw new PXException(Messages.ApprovalRecordNotFound);
                    }

                    Type    cahceType = row.GetType();
                    Type    graphType = helper.GetPrimaryGraphType(row, false);
                    PXGraph graph;
                    if (!graphs.TryGetValue(graphType, out graph))
                    {
                        graphs.Add(graphType, graph = PXGraph.CreateInstance(graphType));
                    }
                    graph.Clear();
                    graph.Caches[cahceType].Current = row;
                    graph.Caches[cahceType].SetStatus(row, PXEntryStatus.Notchanged);
                    PXAutomation.GetView(graph);
                    string approved = typeof(EPExpenseClaim.approved).Name;
                    if (graph.AutomationView != null)
                    {
                        PXAutomation.GetStep(graph,
                                             new object[] { graph.Views[graph.AutomationView].Cache.Current },
                                             BqlCommand.CreateInstance(
                                                 typeof(Select <>),
                                                 graph.Views[graph.AutomationView].Cache.GetItemType())
                                             );
                    }

                    if (graph.Actions.Contains("Approve"))
                    {
                        graph.Actions["Approve"].Press();
                    }
                    else if (graph.AutomationView != null)
                    {
                        PXView     view    = graph.Views[graph.AutomationView];
                        BqlCommand select  = view.BqlSelect;
                        PXAdapter  adapter = new PXAdapter(new DummyView(graph, select, new List <object> {
                            row
                        }));
                        adapter.Menu = "Approve";
                        if (graph.Actions.Contains("Action"))
                        {
                            if (!CheckRights(graphType, cahceType))
                            {
                                throw new PXException(Messages.DontHaveAppoveRights);
                            }
                            foreach (var i in graph.Actions["Action"].Press(adapter))
                            {
                                ;
                            }
                        }
                        else
                        {
                            throw new PXException("Automation for screen/graph {0} exists but is not configured properly. Failed to find action - 'Action'", graph);
                        }
                        //PXAutomation.ApplyAction(graph, graph.Actions["Action"], "Approve", row, out rollback);
                    }
                    else if (graph.Caches[cahceType].Fields.Contains(approved))
                    {
                        object upd = graph.Caches[cahceType].CreateCopy(row);
                        graph.Caches[cahceType].SetValue(upd, approved, true);
                        graph.Caches[cahceType].Update(upd);
                    }
                    graph.Persist();
                    PXProcessing <EPApproval> .SetInfo(ActionsMessages.RecordProcessed);
                }
                catch (Exception ex)
                {
                    errorOccured = true;
                    PXProcessing <EPApproval> .SetError(ex);
                }
            }
            if (errorOccured)
            {
                throw new PXOperationCompletedWithErrorException(ErrorMessages.SeveralItemsFailed);
            }
        }
        protected static void Approve(List <EPOwned> items, bool approve)
        {
            EntityHelper helper = new EntityHelper(new PXGraph());
            var          graphs = new Dictionary <Type, PXGraph>();

            bool errorOccured = false;

            foreach (EPOwned item in items)
            {
                try
                {
                    PXProcessing <EPApproval> .SetCurrentItem(item);

                    if (item.RefNoteID == null)
                    {
                        throw new PXException(Messages.ApprovalRefNoteIDNull);
                    }
                    object row = helper.GetEntityRow(item.RefNoteID.Value, true);

                    if (row == null)
                    {
                        throw new PXException(Messages.ApprovalRecordNotFound);
                    }

                    Type    cahceType = row.GetType();
                    Type    graphType = helper.GetPrimaryGraphType(row, false);
                    PXGraph graph;
                    if (!graphs.TryGetValue(graphType, out graph))
                    {
                        graphs.Add(graphType, graph = PXGraph.CreateInstance(graphType));
                    }

                    EPApproval approval = PXSelectReadonly <EPApproval,
                                                            Where <EPApproval.approvalID, Equal <Current <EPOwned.approvalID> > > >
                                          .SelectSingleBound(graph, new object[] { item });

                    if (approval.Status == EPApprovalStatus.Pending)
                    {
                        graph.Clear();
                        graph.Caches[cahceType].Current = row;
                        graph.Caches[cahceType].SetStatus(row, PXEntryStatus.Notchanged);
                        PXAutomation.GetView(graph);
                        string approved = typeof(EPExpenseClaim.approved).Name;
                        if (graph.AutomationView != null)
                        {
                            PXAutomation.GetStep(graph,
                                                 new object[] { graph.Views[graph.AutomationView].Cache.Current },
                                                 BqlCommand.CreateInstance(
                                                     typeof(Select <>),
                                                     graph.Views[graph.AutomationView].Cache.GetItemType())
                                                 );
                        }
                        string actionName = approve ? nameof(Approve) : nameof(Reject);
                        if (graph.Actions.Contains(actionName))
                        {
                            graph.Actions[actionName].Press();
                        }
                        else if (graph.AutomationView != null)
                        {
                            PXView     view    = graph.Views[graph.AutomationView];
                            BqlCommand select  = view.BqlSelect;
                            PXAdapter  adapter = new PXAdapter(new PXView.Dummy(graph, select, new List <object> {
                                row
                            }));
                            adapter.Menu = actionName;
                            if (graph.Actions.Contains("Action"))
                            {
                                if (!CheckRights(graphType, cahceType))
                                {
                                    throw new PXException(Messages.DontHaveAppoveRights);
                                }
                                foreach (var i in graph.Actions["Action"].Press(adapter))
                                {
                                    ;
                                }
                            }
                            else
                            {
                                throw new PXException(PXMessages.LocalizeFormatNoPrefixNLA(Messages.AutomationNotConfigured, graph));
                            }
                            //PXAutomation.ApplyAction(graph, graph.Actions["Action"], "Approve", row, out rollback);
                        }
                        else if (graph.Caches[cahceType].Fields.Contains(approved))
                        {
                            object upd = graph.Caches[cahceType].CreateCopy(row);
                            graph.Caches[cahceType].SetValue(upd, approved, true);
                            graph.Caches[cahceType].Update(upd);
                        }
                        graph.Persist();
                    }
                    PXProcessing <EPApproval> .SetInfo(ActionsMessages.RecordProcessed);
                }
                catch (Exception ex)
                {
                    errorOccured = true;
                    PXProcessing <EPApproval> .SetError(ex);
                }
            }
            if (errorOccured)
            {
                throw new PXOperationCompletedWithErrorException(ErrorMessages.SeveralItemsFailed);
            }
        }
コード例 #3
0
 private static void SetupAutomationStep(SubcontractEntry graph, POOrder subcontract)
 {
     PXAutomation.GetView(graph);
     PXAutomation.GetStep(graph, subcontract.CreateArray(),
                          BqlCommand.CreateInstance(typeof(Select <>), typeof(POOrder)));
 }