Exemplo n.º 1
0
        protected CRBaseMassProcess()
        {
            primaryGraph = new PXPrimaryGraphCollection(this);
            if (ProcessingDataMember == null)
            {
                throw new PXException(Messages.IsNotProcessing, typeof(TGraph).FullName);
            }

            foreach (Type table in ProcessingDataMember.View.BqlSelect.GetTables())
            {
                PXDBAttributeAttribute.Activate(Caches[table]);
            }

            ProcessingDataMember.SetParametersDelegate(delegate
            {
                bool result = AskParameters();
                Unload();
                TGraph process;
                using (new PXPreserveScope())
                {
                    process = CreateInstance <TGraph>();
                    foreach (var key in this.Caches.Keys)
                    {
                        var clonedCache = process.Caches[key];
                    }
                }

                ProcessingDataMember.SetProcessDelegate(item =>
                {
                    PXGraph graph = primaryGraph[item];
                    if (graph == null)
                    {
                        throw new PXException(ErrorMessages.CantDetermineGraphType);
                    }
                    process.ProccessItem(graph, item);
                    graph.Actions.PressSave();
                    PXCache cache = graph.Caches[typeof(TPrimary)];
                    cache.RestoreCopy(item, cache.Current);
                });
                return(result);
            });

            PXUIFieldAttribute.SetDisplayName <BAccount.acctCD>(Caches[typeof(BAccount)], Messages.BAccountCD);
        }
Exemplo n.º 2
0
        protected CRBaseMassProcess()
        {
            primaryGraph = new PXPrimaryGraphCollection(this);
            if (ProcessingDataMember == null)
            {
                throw new PXException(string.Format("{0} is not processing graph", typeof(TGraph).FullName));
            }

            Actions["Schedule"].SetVisible(false);
            foreach (Type table in ProcessingDataMember.View.BqlSelect.GetTables())
            {
                PXDBAttributeAttribute.Activate(Caches[table]);
            }

            ProcessingDataMember.SetParametersDelegate(delegate
            {
                bool result = AskParameters();
                Unload();
                TGraph process;
                using (new PXPreserveScope())
                    process = CreateInstance <TGraph>();

                ProcessingDataMember.SetProcessDelegate(item =>
                {
                    PXGraph graph = primaryGraph[item];
                    if (graph == null)
                    {
                        throw new PXException(ErrorMessages.CantDetermineGraphType);
                    }
                    process.ProccessItem(graph, item);
                    graph.Actions.PressSave();
                });
                return(result);
            });

            PXUIFieldAttribute.SetDisplayName <BAccount.acctCD>(Caches[typeof(BAccount)], Messages.BAccountCD);
        }
Exemplo n.º 3
0
        private static void ProcessValidation(ValidationFilter Filter, Contact record)
        {
            PXPrimaryGraphCollection primaryGraph = new PXPrimaryGraphCollection(new PXGraph());
            PXGraph graph = primaryGraph[record];

            if (graph == null)
            {
                throw new PXException(Messages.UnableToFindGraph);
            }

            PXView        view = graph.Views[graph.PrimaryView];
            int           startRow = 0, totalRows = 0;
            List <object> list_contact = view.Select(null, null, new object[] { record.ContactID }, new string[] { typeof(Contact.contactID).Name }, null, null,
                                                     ref startRow, 1, ref totalRows);

            if (list_contact == null || list_contact.Count < 1)
            {
                throw new PXException(Messages.ContactNotFound);
            }
            Contact contact = PXResult.Unwrap <Contact>(list_contact[0]);

            contact.DuplicateFound = true;
            //Find duplicates view
            PXView viewDuplicates = graph.Views.ToArray().First(v => v.Value.Cache.GetItemType() == typeof(CRDuplicateRecord)).Value;

            if (viewDuplicates == null)
            {
                throw new PXException(Messages.DuplicateViewNotFound);
            }
            viewDuplicates.Clear();
            List <object> duplicates = viewDuplicates.SelectMulti();

            contact = (Contact)view.Cache.CreateCopy(contact);
            string prevStatus = contact.DuplicateStatus;

            contact.DuplicateStatus = DuplicateStatusAttribute.Validated;
            Decimal?score = 0;

            contact.DuplicateFound = duplicates.Count > 0;
            foreach (PXResult <CRDuplicateRecord, Contact, Contact2> r in duplicates)
            {
                Contact2          duplicate    = r;
                CRDuplicateRecord contactScore = r;
                int duplicateWeight            = ContactMaint.GetContactWeight(duplicate);
                int currentWeight = ContactMaint.GetContactWeight(contact);

                if (duplicateWeight > currentWeight ||
                    (duplicateWeight == currentWeight &&
                     duplicate.ContactID < contact.ContactID))
                {
                    contact.DuplicateStatus = DuplicateStatusAttribute.PossibleDuplicated;
                    if (contactScore.Score > score)
                    {
                        score = contactScore.Score;
                    }
                }
            }
            view.Cache.Update(contact);

            if (contact.DuplicateStatus == DuplicateStatusAttribute.PossibleDuplicated &&
                contact.ContactType == ContactTypesAttribute.Lead &&
                contact.Status == LeadStatusesAttribute.New &&
                Filter.CloseNoActivityLeads == true &&
                score > Filter.CloseThreshold)
            {
                CRActivity activity = PXSelect <CRActivity,
                                                Where <CRActivity.contactID, Equal <Required <Contact.contactID> > > > .SelectWindowed(graph, 0, 1, contact.ContactID);

                if (activity == null)
                {
                    PXAction  action  = graph.Actions["Action"];
                    PXAdapter adapter = new PXAdapter(view);
                    adapter.StartRow    = 0;
                    adapter.MaximumRows = 1;
                    adapter.Searches    = new object[] { contact.ContactID };
                    adapter.Menu        = Messages.CloseAsDuplicate;
                    adapter.SortColumns = new[] { typeof(Contact.contactID).Name };
                    foreach (Contact c in action.Press(adapter))
                    {
                        ;
                    }
                    prevStatus = null;
                }
            }
            view.Cache.RestoreCopy(record, view.Cache.Current);
            if (prevStatus != contact.DuplicateStatus)
            {
                graph.Actions.PressSave();
            }
        }