Esempio n. 1
0
        private bool CanBeDeleted(CRCampaign campaign, DAC.Standalone.CRCampaign dacCampaign)
        {
            foreach (var f in new string[]
            {
                nameof(CRCampaign.mailsSent)
            })
            {
                var state = CampaignCurrent.Cache.GetStateExt(campaign, f);
                if (((PXIntState)state).Value != null && (int)((PXIntState)state).Value > 0)
                {
                    return(false);
                }
            }

            foreach (var f in new string[]
            {
                nameof(DAC.Standalone.CRCampaign.closedOpportunities),
                nameof(DAC.Standalone.CRCampaign.contacts),
                nameof(DAC.Standalone.CRCampaign.leadsConverted),
                nameof(DAC.Standalone.CRCampaign.leadsGenerated),
                nameof(DAC.Standalone.CRCampaign.opportunities),
            })
            {
                var state = CalcCampaignCurrent.Cache.GetStateExt(dacCampaign, f);
                if (((PXIntState)state).Value != null && (int)((PXIntState)state).Value > 0)
                {
                    return(false);
                }
            }

            if (PXSelectGroupBy <SOOrder,
                                 Where <SOOrder.campaignID, Equal <Current <CRCampaign.campaignID> > >,
                                 Aggregate <Count> > .Select(this).RowCount > 0)
            {
                return(false);
            }

            if (PXSelectGroupBy <ARInvoice,
                                 Where <ARInvoice.campaignID, Equal <Current <CRCampaign.campaignID> > >,
                                 Aggregate <Count> > .Select(this).RowCount > 0)
            {
                return(false);
            }

            if (PXSelectGroupBy <PMProject,
                                 Where <PMProject.campaignID, Equal <Current <CRCampaign.campaignID> > >,
                                 Aggregate <Count> > .Select(this).RowCount > 0)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        protected virtual void CRCampaign_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            CRCampaign row = e.Row as CRCampaign;

            DAC.Standalone.CRCampaign dacRow = CalcCampaignCurrent.Select();
            if (row != null)
            {
                if (CanBeDeleted(row, dacRow) == false)
                {
                    e.Cancel = true;
                    throw new PXException(Messages.CampaignIsReferenced);
                }
            }
        }