Пример #1
0
        protected virtual void Contact_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            Contact row = e.Row as Contact;

            if (row == null)
            {
                return;
            }
            PXUIFieldAttribute.SetEnabled <Contact.contactID>(sender, row, true);

            CRContactClass leadClass = row.ClassID.
                                       With(_ => (CRContactClass)PXSelectReadonly <CRContactClass,
                                                                                   Where <CRContactClass.classID, Equal <Required <CRContactClass.classID> > > > .
                                            Select(this, _));

            if (leadClass != null)
            {
                Activities.DefaultEMailAccountId = leadClass.DefaultEMailAccountID;
            }

            if (row.DuplicateStatus == DuplicateStatusAttribute.PossibleDuplicated || row.DuplicateFound == true)
            {
                sender.RaiseExceptionHandling <Contact.duplicateStatus>(row,
                                                                        null, new PXSetPropertyException(Messages.LeadHavePossibleDuplicates, PXErrorLevel.Warning, row.ContactID));
            }
        }
Пример #2
0
        protected virtual void AccountsFilter_AccountClass_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            Contact contact = sender.Graph.Caches <Contact>().Current as Contact;

            if (contact == null)
            {
                return;
            }
            CRContactClass ctcls = PXSelect <CRContactClass,
                                             Where <CRContactClass.classID,
                                                    Equal <Required <Contact.classID> > > > .Select(this, contact.ClassID);

            if (ctcls != null)
            {
                if (ctcls.TargetBAccountClassID == null)
                {
                    CRCustomerClass cls = PXSelect <CRCustomerClass, Where <CRCustomerClass.cRCustomerClassID, Equal <Required <Contact.classID> > > > .Select(this, contact.ClassID);

                    if (cls != null)
                    {
                        e.NewValue = cls.CRCustomerClassID;
                    }
                }
                else
                {
                    e.NewValue = ctcls.TargetBAccountClassID;
                }
            }
        }
Пример #3
0
        public virtual void AddOpportunity()
        {
            var row = ContactCurrent.Current;

            if (row == null || row.ContactID == null)
            {
                return;
            }

            CRContactClass ctcls = PXSelect <CRContactClass, Where <CRContactClass.classID, Equal <Required <Contact.classID> > > > .Select(this, row.ClassID);

            var graph          = PXGraph.CreateInstance <OpportunityMaint>();
            var newOpportunity = graph.Opportunity.Insert();

            newOpportunity.BAccountID = row.BAccountID;
            if (ctcls != null && ctcls.TargetOpportunityClassID != null)
            {
                newOpportunity.CROpportunityClassID = ctcls.TargetOpportunityClassID;
            }
            newOpportunity.ContactID = row.ContactID;
            graph.Opportunity.Update(newOpportunity);

            if (!this.IsContractBasedAPI)
            {
                PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow);
            }

            graph.Save.Press();
        }
Пример #4
0
        public override object Evaluate(PXCache cache, object item, Dictionary <Type, object> pars)
        {
            string         classID = (string)pars[typeof(ClassID)];
            CRContactClass cls     = PXSelect <CRContactClass, Where <CRContactClass.classID, Equal <Required <CRContactClass.classID> > > > .Select(cache.Graph, classID);

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

            PXSelectBase <EPCompanyTreeMember> cmd = new PXSelectJoin <EPCompanyTreeMember,
                                                                       InnerJoin <EPCompanyTreeH, On <EPCompanyTreeMember.workGroupID, Equal <EPCompanyTreeH.workGroupID> > >,
                                                                       Where <EPCompanyTreeMember.userID, Equal <Required <EPCompanyTreeMember.userID> > > >(cache.Graph);

            if (cls.DefaultWorkgroupID != null && cls.OwnerIsCreatedUser != true)
            {
                return(cls.DefaultWorkgroupID);
            }
            else if (cls.DefaultWorkgroupID != null && cls.OwnerIsCreatedUser == true)
            {
                cmd.WhereAnd <Where <EPCompanyTreeH.parentWGID, Equal <Required <EPCompanyTreeH.parentWGID> > > >();
                EPCompanyTreeMember m = cmd.SelectSingle(cache.Graph.Accessinfo.UserID, cls.DefaultWorkgroupID);
                return(m.With(_ => _.WorkGroupID));
            }
            else if (cls.DefaultWorkgroupID == null && cls.OwnerIsCreatedUser == true && cls.DefaultOwnerWorkgroup == true)
            {
                EPCompanyTreeMember m = cmd.SelectSingle(cache.Graph.Accessinfo.UserID);
                return(m.With(_ => _.WorkGroupID));
            }
            else
            {
                return(null);
            }
        }
Пример #5
0
        public override void Verify(PXCache cache, object item, List <object> pars, ref bool?result, ref object value)
        {
            string         classID = (string)Calculate <ClassID>(cache, item);
            CRContactClass cls     = PXSelect <CRContactClass, Where <CRContactClass.classID, Equal <Required <CRContactClass.classID> > > > .Select(cache.Graph, classID);

            if (cls == null)
            {
                return;
            }

            PXSelectBase <EPCompanyTreeMember> cmd = new PXSelectJoin <EPCompanyTreeMember,
                                                                       InnerJoin <EPCompanyTreeH, On <EPCompanyTreeMember.workGroupID, Equal <EPCompanyTreeH.workGroupID> > >,
                                                                       Where <EPCompanyTreeMember.userID, Equal <Required <EPCompanyTreeMember.userID> > > >(cache.Graph);

            if (cls.DefaultWorkgroupID != null && cls.OwnerIsCreatedUser != true)
            {
                value = cls.DefaultWorkgroupID;
            }
            else if (cls.DefaultWorkgroupID != null && cls.OwnerIsCreatedUser == true)
            {
                cmd.WhereAnd <Where <EPCompanyTreeH.parentWGID, Equal <Required <EPCompanyTreeH.parentWGID> > > >();
                EPCompanyTreeMember m = cmd.SelectSingle(cache.Graph.Accessinfo.UserID, cls.DefaultWorkgroupID);
                value = m.With(_ => _.WorkGroupID);
            }
            else if (cls.DefaultWorkgroupID == null && cls.OwnerIsCreatedUser == true && cls.DefaultOwnerWorkgroup == true)
            {
                EPCompanyTreeMember m = cmd.SelectSingle(cache.Graph.Accessinfo.UserID);
                value = m.With(_ => _.WorkGroupID);
            }
            else
            {
                value = null;
            }
        }
Пример #6
0
        public virtual IEnumerable ConvertToOpportunity(PXAdapter adapter)
        {
            bool           isOpportunityAutoNumberOn = this.IsNumberingAutonumbered(Setup.Current.OpportunityNumberingID);
            List <Contact> contacts = new List <Contact>(adapter.Get().Cast <Contact>());

            foreach (Contact lead in contacts)
            {
                OpportunityMaint opportunityMaint = PXGraph.CreateInstance <OpportunityMaint>();
                CROpportunity    opportunity      = (CROpportunity)opportunityMaint.Opportunity.Cache.CreateInstance();

                if (!isOpportunityAutoNumberOn)
                {
                    if (OpportunityInfo.AskExt() != WebDialogResult.OK || !OpportunityInfo.VerifyRequired())
                    {
                        return(contacts);
                    }
                    CROpportunity existing = PXSelect <CROpportunity, Where <CROpportunity.opportunityID, Equal <Required <CROpportunity.opportunityID> > > > .SelectSingleBound(this, null, OpportunityInfo.Current.OpportunityID);

                    if (existing != null)
                    {
                        OpportunityInfo.Cache.RaiseExceptionHandling <OpportunityFilter.opportunityID>(OpportunityInfo.Current, OpportunityInfo.Current.OpportunityID, new PXSetPropertyException(Messages.OpportunityAlreadyExists, OpportunityInfo.Current.OpportunityID));
                        return(contacts);
                    }

                    object cd = OpportunityInfo.Current.OpportunityID;
                    opportunityMaint.Opportunity.Cache.RaiseFieldUpdating <CROpportunity.opportunityID>(null, ref cd);
                    opportunity.OpportunityID = (string)cd;
                }
                PXLongOperation.StartOperation(this, delegate()
                {
                    CRContactClass cls = PXSelect <CRContactClass, Where <CRContactClass.classID, Equal <Current <Contact.classID> > > > .SelectSingleBound(this, new object[] { lead });
                    if (cls != null && cls.OwnerToOpportunity == true)
                    {
                        opportunity.WorkgroupID = lead.WorkgroupID;
                        opportunity.OwnerID     = lead.OwnerID;
                    }

                    if (lead.BAccountID != null)
                    {
                        opportunity.BAccountID = lead.BAccountID;
                    }
                    opportunity.ContactID = lead.ContactID;
                    opportunity           = (CROpportunity)opportunityMaint.Opportunity.Cache.Insert(opportunity);

                    ContactMaint contactGraph = PXGraph.CreateInstance <ContactMaint>();
                    lead.ContactType          = ContactTypesAttribute.Person;
                    contactGraph.Contact.Update(lead);
                    contactGraph.Save.Press();

                    opportunityMaint.Opportunity.Search <CROpportunity.opportunityID>(opportunity.OpportunityID);

                    throw new PXRedirectRequiredException(opportunityMaint, "Opportunity", true);
                });
            }
            return(contacts);
        }
Пример #7
0
        public virtual void AddOpportunityForContact()
        {
            var row = CampaignCurrent.Current;

            if (row == null || row.CampaignID == null)
            {
                return;
            }

            var member = CampaignMembers.Current;

            if (member == null || member.ContactID == null)
            {
                return;
            }

            var contact = (Contact)ContactByContactId.Select(member.ContactID);

            var graph          = PXGraph.CreateInstance <OpportunityMaint>();
            var newOpportunity = (CROpportunity)graph.Opportunity.Cache.CreateInstance();

            newOpportunity = graph.Opportunity.Insert(newOpportunity);
            newOpportunity.CampaignSourceID = row.CampaignID;
            newOpportunity.BAccountID       = contact?.BAccountID;
            if (contact?.ContactType != ContactTypesAttribute.BAccountProperty)
            {
                newOpportunity.ContactID = member.ContactID;
            }

            CRContactClass cls = PXSelect <CRContactClass, Where <CRContactClass.classID, Equal <Current <Contact.classID> > > >
                                 .SelectSingleBound(this, new object[] { contact });

            if (cls?.OwnerToOpportunity == true)
            {
                newOpportunity.WorkgroupID = contact?.WorkgroupID;
                newOpportunity.OwnerID     = contact?.OwnerID;
            }
            if (cls?.TargetOpportunityClassID != null)
            {
                newOpportunity.ClassID = cls.TargetOpportunityClassID;
            }
            if (row.ProjectID != null)
            {
                newOpportunity.ProjectID = row.ProjectID;
            }

            newOpportunity           = graph.Opportunity.Update(newOpportunity);
            newOpportunity.ContactID = member.ContactID;
            PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow);
        }
Пример #8
0
        protected virtual void Contact_ClassID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            Contact        row = (Contact)e.Row;
            CRContactClass cc  = (CRContactClass)PXSelectorAttribute.Select <Contact.classID>(sender, row, e.NewValue);

            this.doCopyClassSettings = false;
            if (cc != null)
            {
                this.doCopyClassSettings = true;
                if (sender.GetStatus(row) != PXEntryStatus.Inserted)
                {
                    if (e.ExternalCall && Lead.Ask(Messages.Warning, Messages.ContactClassChangeWarning, MessageButtons.YesNo) == WebDialogResult.No)
                    {
                        this.doCopyClassSettings = false;
                    }
                }
            }
        }
Пример #9
0
        public override object Evaluate(PXCache cache, object item, Dictionary <Type, object> pars)
        {
            string         classID = (string)pars[typeof(ClassID)];
            CRContactClass cls     = PXSelect <CRContactClass, Where <CRContactClass.classID, Equal <Required <CRContactClass.classID> > > > .Select(cache.Graph, classID);

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

            var rec = (PXResult <Users, Contact, BAccountR>)
                      PXSelectJoin <Users,
                                    InnerJoin <Contact, On <Contact.userID, Equal <Users.pKID> >,
                                               InnerJoin <BAccountR, On <Contact.contactID, Equal <BAccountR.defContactID>, And <Contact.bAccountID, Equal <BAccountR.parentBAccountID> > > > >,
                                    Where <Users.pKID, Equal <Current <AccessInfo.userID> > > > .SelectSingleBound(cache.Graph, null, null);

            BAccountR bAccount = rec;

            return(bAccount != null && !string.IsNullOrEmpty(bAccount.AcctCD) && cls.OwnerIsCreatedUser == true
                                ? bAccount.AcctCD
                                : null);
        }
        public static void ConvertToAccount(Contact contact, AccountsFilter param)
        {
            BusinessAccountMaint accountMaint = CreateInstance <BusinessAccountMaint>();
            object cd = param.BAccountID;

            accountMaint.BAccount.Cache.RaiseFieldUpdating <BAccount.acctCD>(null, ref cd);
            BAccount account = new BAccount
            {
                AcctCD           = (string)cd,
                AcctName         = param.AccountName,
                Type             = BAccountType.ProspectType,
                ClassID          = param.AccountClass,
                ParentBAccountID = contact.ParentBAccountID
            };

            #region Set Contact and Address fields
            CRContactClass cls = PXSelect <CRContactClass, Where <CRContactClass.classID, Equal <Current <Contact.classID> > > > .SelectSingleBound(accountMaint, new object[] { contact });

            if (cls != null && cls.OwnerToBAccount == true)
            {
                account.WorkgroupID = contact.WorkgroupID;
                account.OwnerID     = contact.OwnerID;
            }

            try
            {
                object newValue = account.OwnerID;
                accountMaint.BAccount.Cache.RaiseFieldVerifying <BAccount.ownerID>(account, ref newValue);
            }
            catch (PXSetPropertyException)
            {
                account.OwnerID = null;
            }

            account = accountMaint.BAccount.Insert(account);

            accountMaint.Answers.CopyAllAttributes(account, contact);

            Contact defContact = PXCache <Contact> .CreateCopy(PXSelect <Contact, Where <Contact.contactID, Equal <Current <BAccount.defContactID> > > > .SelectSingleBound(accountMaint, new object[] { account }));

            var defContactNoteID = defContact.NoteID;
            PXCache <Contact> .RestoreCopy(defContact, contact);

            defContact.ContactType     = ContactTypesAttribute.BAccountProperty;
            defContact.FullName        = account.AcctName;
            defContact.ContactID       = account.DefContactID;
            defContact.BAccountID      = account.BAccountID;
            defContact.DuplicateStatus = DuplicateStatusAttribute.NotValidated;
            defContact.DuplicateFound  = false;
            defContact.WorkgroupID     = null;
            defContact.OwnerID         = null;
            defContact.NoteID          = defContactNoteID;
            defContact = accountMaint.DefContact.Update(defContact);

            Address contactAddress = PXSelect <Address, Where <Address.addressID, Equal <Required <Contact.defAddressID> > > > .Select(accountMaint, contact.DefAddressID);

            if (contactAddress == null)
            {
                throw new PXException(Messages.DefAddressNotExists, contact.DisplayName);
            }
            contactAddress.BAccountID = account.BAccountID;
            accountMaint.AddressCurrent.Cache.Clear();

            defContact.DefAddressID = contactAddress.AddressID;
            defContact = accountMaint.DefContact.Update(defContact);

            contactAddress = accountMaint.AddressCurrent.Update(contactAddress);

            account.DefAddressID = contactAddress.AddressID;
            accountMaint.BAccount.Update(account);

            contact.BAccountID      = account.BAccountID;
            contact.DuplicateStatus = DuplicateStatusAttribute.NotValidated;
            contact.DuplicateFound  = false;
            if (contact.QualificationDate == null)
            {
                contact.QualificationDate = PXTimeZoneInfo.Now;
            }
            accountMaint.Contacts.Cache.SetStatus(contact, PXEntryStatus.Updated);
            CR.Location location = accountMaint.DefLocation.Select();
            location.DefAddressID = contactAddress.AddressID;
            accountMaint.DefLocation.Update(location);

            account.NoteID = PXNoteAttribute.GetNoteID <CRActivity.noteID>(accountMaint.CurrentBAccount.Cache, account);
            foreach (CRPMTimeActivity a in PXSelect <CRPMTimeActivity, Where <CRPMTimeActivity.refNoteID, Equal <Required <Contact.noteID> > > > .Select(accountMaint, contact.NoteID))
            {
                a.BAccountID = account.BAccountID;
                accountMaint.Activities.Cache.Update(a);
            }
            #endregion

            // Copy Note text and Files references
            CRSetup setup = PXSetupOptional <CRSetup> .Select(accountMaint);

            PXNoteAttribute.CopyNoteAndFiles(accountMaint.Contacts.Cache, contact, accountMaint.CurrentBAccount.Cache, account, setup);

            throw new PXRedirectRequiredException(accountMaint, "Business Account");
        }
        public virtual IEnumerable ConvertToOpportunity(PXAdapter adapter)
        {
            Save.Press();
            bool           isOpportunityAutoNumberOn = this.IsNumberingAutonumbered(Setup.Current.OpportunityNumberingID);
            List <Contact> contacts = new List <Contact>(adapter.Get().Cast <Contact>());

            foreach (Contact l in contacts)
            {
                OpportunityMaint opportunityMaint = CreateInstance <OpportunityMaint>();
                CROpportunity    opportunity      = (CROpportunity)opportunityMaint.Opportunity.Cache.Insert();

                if (!isOpportunityAutoNumberOn)
                {
                    if (OpportunityInfo.AskExt() != WebDialogResult.OK || !OpportunityInfo.VerifyRequired())
                    {
                        return(contacts);
                    }
                    CROpportunity existing = PXSelect <CROpportunity, Where <CROpportunity.opportunityID, Equal <Required <CROpportunity.opportunityID> > > > .SelectSingleBound(this, null, OpportunityInfo.Current.OpportunityID);

                    if (existing != null)
                    {
                        OpportunityInfo.Cache.RaiseExceptionHandling <OpportunityFilter.opportunityID>(OpportunityInfo.Current, OpportunityInfo.Current.OpportunityID, new PXSetPropertyException(Messages.OpportunityAlreadyExists, OpportunityInfo.Current.OpportunityID));
                        return(contacts);
                    }

                    object cd = OpportunityInfo.Current.OpportunityID;
                    opportunityMaint.Opportunity.Cache.RaiseFieldUpdating <CROpportunity.opportunityID>(null, ref cd);
                    opportunity.OpportunityID = (string)cd;
                }
                Contact lead = l;
                PXLongOperation.StartOperation(this, delegate()
                {
                    CRContactClass cls = PXSelect <CRContactClass, Where <CRContactClass.classID, Equal <Current <Contact.classID> > > > .SelectSingleBound(this, new object[] { lead });
                    if (cls != null && cls.OwnerToOpportunity == true)
                    {
                        opportunity.WorkgroupID = lead.WorkgroupID;
                        opportunity.OwnerID     = lead.OwnerID;
                    }
                    if (cls != null && cls.TargetOpportunityClassID != null)
                    {
                        opportunity.CROpportunityClassID = cls.TargetOpportunityClassID;
                    }

                    if (lead.BAccountID != null)
                    {
                        opportunity.BAccountID = lead.BAccountID;
                    }

                    if (lead.ParentBAccountID != null)
                    {
                        opportunity.ParentBAccountID = lead.ParentBAccountID;
                    }

                    if (lead.CampaignID != null)
                    {
                        opportunity.CampaignSourceID = lead.CampaignID;
                    }
                    opportunity.ContactID       = lead.ContactID;
                    opportunity.ConvertedLeadID = lead.ContactID;
                    opportunity.OpportunityName = string.IsNullOrEmpty(lead.FullName) ? lead.DisplayName : lead.FullName;
                    opportunity = (CROpportunity)opportunityMaint.Opportunity.Cache.Update(opportunity);

                    ContactMaint contactGraph = CreateInstance <ContactMaint>();
                    lead.ContactType          = ContactTypesAttribute.Person;
                    lead.QualificationDate    = PXTimeZoneInfo.Now;
                    lead.ConvertedBy          = Accessinfo.UserID;
                    lead = contactGraph.Contact.Update(lead);

                    opportunityMaint.Opportunity.Search <CROpportunity.opportunityID>(opportunity.OpportunityID);
                    lead = opportunityMaint.Leads.Update(lead);

                    // Copy Note text and Files references
                    CRSetup setup = PXSetupOptional <CRSetup> .Select(opportunityMaint);
                    PXNoteAttribute.CopyNoteAndFiles(opportunityMaint.Leads.Cache, lead, opportunityMaint.OpportunityCurrent.Cache, opportunity, setup);

                    throw new PXRedirectRequiredException(opportunityMaint, "Opportunity", true);
                });
            }
            return(contacts);
        }
Пример #12
0
        protected virtual void Contact_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            Contact row = e.Row as Contact;

            if (row == null)
            {
                return;
            }

            var isNotInserted = sender.GetStatus(row) != PXEntryStatus.Inserted;

            Contact.AllowDelete = row.ContactType == ContactTypesAttribute.Person;
            PXUIFieldAttribute.SetEnabled <Contact.isActive>(Contact.Cache, row, row.ContactType == ContactTypesAttribute.Person);
            PXUIFieldAttribute.SetEnabled <Contact.classID>(Contact.Cache, row, row.ContactType == ContactTypesAttribute.Person);
            PXUIFieldAttribute.SetEnabled <Contact.isAddressSameAsMain>(Contact.Cache, row, row.ContactType == ContactTypesAttribute.Person);

            copyBAccountContactInfo.SetEnabled(row.ContactType == ContactTypesAttribute.Person);
            Answers.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person;
            Answers.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Answers.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            Activities.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person;
            Activities.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Activities.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            Relations.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person && isNotInserted;
            Relations.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Relations.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            Opportunities.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person && isNotInserted;
            Opportunities.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Opportunities.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            Cases.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person && isNotInserted;
            Cases.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Cases.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            Members.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person && isNotInserted;
            Members.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Members.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            Subscriptions.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person && isNotInserted;
            Subscriptions.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Subscriptions.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            NWatchers.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person && isNotInserted;
            NWatchers.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            NWatchers.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;

            User.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person;
            User.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            User.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;
            User.Cache.AllowSelect = row.ContactType == ContactTypesAttribute.Person;
            User.Cache.ClearQueryCache();

            Roles.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person;
            Roles.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            Roles.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;
            Roles.Cache.AllowSelect = row.ContactType == ContactTypesAttribute.Person;
            Roles.Cache.ClearQueryCache();

            UserRoles.Cache.AllowInsert = row.ContactType == ContactTypesAttribute.Person;
            UserRoles.Cache.AllowUpdate = row.ContactType == ContactTypesAttribute.Person;
            UserRoles.Cache.AllowDelete = row.ContactType == ContactTypesAttribute.Person;
            UserRoles.Cache.AllowSelect = row.ContactType == ContactTypesAttribute.Person;
            UserRoles.Cache.ClearQueryCache();

            var bAccount = row.BAccountID.
                           With <int?, BAccount>(_ => (BAccount)PXSelect <BAccount,
                                                                          Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > .
                                                 Select(this, _));
            var isCustomerOrProspect = bAccount == null ||
                                       bAccount.Type == BAccountType.CustomerType ||
                                       bAccount.Type == BAccountType.ProspectType ||
                                       bAccount.Type == BAccountType.CombinedType;

            addOpportunity.SetEnabled(isNotInserted && isCustomerOrProspect);
            addCase.SetEnabled(isNotInserted && isCustomerOrProspect);

            PXUIFieldAttribute.SetEnabled <Contact.contactID>(sender, row, true);
            PXUIFieldAttribute.SetEnabled <Contact.bAccountID>(sender, row, row.ContactType == ContactTypesAttribute.Person);

            CRContactClass contactClass = row.ClassID.
                                          With(_ => (CRContactClass)PXSelectReadonly <CRContactClass,
                                                                                      Where <CRContactClass.classID, Equal <Required <CRContactClass.classID> > > > .
                                               Select(this, _));

            if (contactClass != null)
            {
                Activities.DefaultEMailAccountId = contactClass.DefaultEMailAccountID;
            }

            bool isUserInserted = row.UserID == null || User.Cache.GetStatus(User.Current) == PXEntryStatus.Inserted;
            bool hasLoginType   = isUserInserted && User.Current != null && User.Current.LoginTypeID != null;

            PXUIFieldAttribute.SetEnabled <Users.loginTypeID>(User.Cache, User.Current, isUserInserted && row.IsActive == true);
            PXUIFieldAttribute.SetEnabled <Users.username>(User.Cache, User.Current, this.IsContractBasedAPI || hasLoginType);
            PXUIFieldAttribute.SetEnabled <Users.generatePassword>(User.Cache, User.Current, this.IsContractBasedAPI || hasLoginType);
            PXUIFieldAttribute.SetEnabled <Users.password>(User.Cache, User.Current, this.IsContractBasedAPI || (hasLoginType && User.Current.GeneratePassword != true));

            var employeeHasUserAttached = row.ContactType == ContactTypesAttribute.Employee && User.Current != null;

            PXDefaultAttribute.SetPersistingCheck <Contact.eMail>(sender, row,
                                                                  employeeHasUserAttached || (hasLoginType && User.Current.Username != null)
                ? PXPersistingCheck.NullOrBlank
                : PXPersistingCheck.Nothing);
            PXUIFieldAttribute.SetRequired <Contact.eMail>(sender, employeeHasUserAttached || (hasLoginType && User.Current.Username != null));

            User.Current = (Users)User.View.SelectSingleBound(new[] { e.Row });

            if (row.DuplicateStatus == DuplicateStatusAttribute.PossibleDuplicated || row.DuplicateFound == true)
            {
                sender.RaiseExceptionHandling <Contact.duplicateStatus>(row,
                                                                        null, new PXSetPropertyException(Messages.ContactHavePossibleDuplicates, PXErrorLevel.Warning, row.ContactID));
            }
        }