예제 #1
0
        protected virtual void CustSalesPeople_RowInserting(PXCache cache, PXRowInsertingEventArgs e)
        {
            CustSalesPeople row = (CustSalesPeople)e.Row;

            if (row != null && row.BAccountID.HasValue)
            {
                List <CustSalesPeople> current = new List <CustSalesPeople>();
                bool duplicated = false;
                foreach (CustSalesPeople iSP in this.SPCustomers.Select())
                {
                    if (row.BAccountID == iSP.BAccountID)
                    {
                        current.Add(iSP);
                        if (row.LocationID == iSP.LocationID)
                        {
                            duplicated = true;
                        }
                    }
                }
                if (duplicated)
                {
                    Location freeLocation       = null;
                    PXSelectBase <Location> sel = new PXSelect <Location, Where <Location.bAccountID, Equal <Required <Location.bAccountID> > > >(this);
                    foreach (Location iLoc in sel.Select(row.BAccountID))
                    {
                        bool found = current.Exists(new Predicate <CustSalesPeople>(delegate(CustSalesPeople op) { return(op.LocationID == iLoc.LocationID); }));
                        if (!found)
                        {
                            freeLocation = iLoc;
                            break;
                        }
                    }
                    if (freeLocation != null)
                    {
                        row.LocationID = freeLocation.LocationID;
                    }
                    else
                    {
                        throw new PXException(Messages.AllCustomerLocationsAreAdded);
                        //cache.RaiseExceptionHandling<CustSalesPeople.locationID>(e.Row, null, new PXException(Messages.SalesPersonAddedForAllLocations));
                        //e.Cancel = true;
                    }
                }
            }
        }
예제 #2
0
        protected virtual void CustSalesPeople_LocationID_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
        {
            CustSalesPeople row = (CustSalesPeople)e.Row;
            int?            id  = (int?)e.NewValue;

            if (id.HasValue)
            {
                foreach (CustSalesPeople iSP in this.SPCustomers.Select())
                {
                    if (object.ReferenceEquals(e.Row, iSP))
                    {
                        continue;
                    }
                    if ((iSP.BAccountID == row.BAccountID) && (iSP.LocationID == id))
                    {
                        throw new PXException("This Customer&Location  is already included");
                    }
                }
            }
        }