Esempio n. 1
0
        protected virtual IEnumerable curyRateRecordsEntry()
        {
            CuryRateFilter      f   = Filter.Current as CuryRateFilter;
            List <CurrencyRate> ret = new List <CurrencyRate>();

            foreach (CurrencyRate r in PXSelect <CurrencyRate,
                                                 Where <CurrencyRate.toCuryID, Equal <Required <CurrencyRate.toCuryID> >,
                                                        And <CurrencyRate.curyEffDate, Equal <Required <CurrencyRate.curyEffDate> > > > > .Select(this, f.ToCurrency, f.EffDate))
            {
                ret.Add(r);
            }
            foreach (CurrencyRate r in CuryRateRecordsEntry.Cache.Inserted)
            {
                if (!ret.Contains(r))
                {
                    ret.Add(r);
                }
            }
            foreach (CurrencyRate r in CuryRateRecordsEntry.Cache.Updated)
            {
                if (!ret.Contains(r))
                {
                    ret.Add(r);
                }
            }

            return(ret);
        }
Esempio n. 2
0
        protected virtual System.Collections.IEnumerable Next(PXAdapter a)
        {
            PXLongOperation.ClearStatus(this.UID);
            CuryRateFilter current = (CuryRateFilter)Filter.Current;
            PXSelectBase <CurrencyRate> currentSelectStatement;

            if (current.ToCurrency != null)
            {
                CurrencyRate rate;
                if (current.EffDate != null)
                {
                    currentSelectStatement = new PXSelectReadonly <CurrencyRate, Where <CurrencyRate.toCuryID, Equal <Required <CurrencyRate.toCuryID> >,
                                                                                        And <CurrencyRate.curyEffDate, Greater <Required <CurrencyRate.curyEffDate> > > >,
                                                                   OrderBy <Asc <CurrencyRate.curyEffDate> > >(this);
                    rate = (CurrencyRate)currentSelectStatement.View.SelectSingle(current.ToCurrency, current.EffDate);
                }
                else
                {
                    currentSelectStatement = new PXSelectReadonly <CurrencyRate, Where <CurrencyRate.toCuryID, Equal <Required <CurrencyRate.toCuryID> > >,
                                                                   OrderBy <Asc <CurrencyRate.curyEffDate> > >(this);
                    rate = (CurrencyRate)currentSelectStatement.View.SelectSingle(current.ToCurrency);
                }
                if (rate != null)
                {
                    current              = (CuryRateFilter)Filter.Cache.CreateCopy(Filter.Current);
                    current.ToCurrency   = rate.ToCuryID;
                    current.EffDate      = rate.CuryEffDate;
                    current              = Filter.Update(current);
                    Filter.Cache.IsDirty = false;
                }
            }
            yield return(current);
        }
Esempio n. 3
0
        protected virtual void CurrencyRate_FromCuryID_FieldUpdating(PXCache cache, PXFieldUpdatingEventArgs e)
        {
            CuryRateFilter crf = Filter.Current as CuryRateFilter;

            if (e.NewValue != null && crf.ToCurrency != null && String.Compare((string)e.NewValue, crf.ToCurrency, true) == 0)
            {
                cache.RaiseExceptionHandling("FromCuryID", e.Row, e.NewValue, new PXSetPropertyException(Messages.DestShouldDifferFromOrig));
                cache.SetStatus(e.Row, PXEntryStatus.Notchanged);
            }
        }
Esempio n. 4
0
        protected virtual void CuryRateFilter_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            CuryRateFilter filter = (CuryRateFilter)e.Row;

            if (filter == null)
            {
                return;
            }

            bool nextEnabled  = false;
            bool prevEnabled  = false;
            bool lastEnabled  = false;
            bool firstEnabled = false;

            PXSelectBase currentSelectStatement = null;
            CurrencyRate cachesRateNext         = null;
            CurrencyRate cachesRatePrev         = null;

            if (filter.ToCurrency != null && filter.EffDate != null)
            {
                currentSelectStatement = new PXSelectReadonly <CurrencyRate, Where <CurrencyRate.toCuryID, Equal <Required <CurrencyRate.toCuryID> >,
                                                                                    And <CurrencyRate.curyEffDate, Greater <Required <CurrencyRate.curyEffDate> > > >,
                                                               OrderBy <Asc <CurrencyRate.curyEffDate> > >(this);
                cachesRateNext = (CurrencyRate)currentSelectStatement.View.SelectSingle(filter.ToCurrency, filter.EffDate);

                currentSelectStatement = new PXSelectReadonly <CurrencyRate, Where <CurrencyRate.toCuryID, Equal <Required <CurrencyRate.toCuryID> >,
                                                                                    And <CurrencyRate.curyEffDate, Less <Required <CurrencyRate.curyEffDate> > > >,
                                                               OrderBy <Desc <CurrencyRate.curyEffDate> > >(this);
                cachesRatePrev = (CurrencyRate)currentSelectStatement.View.SelectSingle(filter.ToCurrency, filter.EffDate);
                nextEnabled    = cachesRateNext != null;
                prevEnabled    = cachesRatePrev != null;

                if (!IsImport)
                {
                    bool isModified = this.CuryRateRecordsEntry.Cache.IsDirty;
                    PXUIFieldAttribute.SetEnabled <CuryRateFilter.toCurrency>(cache, filter, !isModified);
                    PXUIFieldAttribute.SetEnabled <CuryRateFilter.effDate>(cache, filter, !isModified);
                }
            }

            firstEnabled = prevEnabled;
            lastEnabled  = nextEnabled;

            next.SetEnabled(nextEnabled);
            prev.SetEnabled(prevEnabled);
            first.SetEnabled(firstEnabled);
            last.SetEnabled(lastEnabled);
        }
Esempio n. 5
0
        protected virtual IEnumerable curyRateRecordsEffDate()
        {
            PXSelectBase <CurrencyRate2> sel = new PXSelect <CurrencyRate2,
                                                             Where <CurrencyRate2.toCuryID, Equal <Required <CurrencyRate2.toCuryID> >,
                                                                    And <CurrencyRate2.fromCuryID, Equal <Required <CurrencyRate2.fromCuryID> >,
                                                                         And <CurrencyRate2.curyRateType, Equal <Required <CurrencyRate2.curyRateType> >,
                                                                              And <CurrencyRate2.curyEffDate, Equal <Required <CurrencyRate2.curyEffDate> > > > > > >(this);

            CuryRateFilter       f   = Filter.Current as CuryRateFilter;
            List <CurrencyRate2> ret = new List <CurrencyRate2>();

            foreach (CurrencyRate2 r in PXSelectGroupBy <CurrencyRate2,
                                                         Where <CurrencyRate2.toCuryID, Equal <Current <CuryRateFilter.toCurrency> >,
                                                                And <CurrencyRate2.curyEffDate, LessEqual <Current <CuryRateFilter.effDate> > > >,
                                                         Aggregate <Max <CurrencyRate2.curyEffDate,
                                                                         GroupBy <CurrencyRate2.curyRateType,
                                                                                  GroupBy <CurrencyRate2.fromCuryID> > > > > .Select(this))
            {
                ret.Add((CurrencyRate2)sel.Select(f.ToCurrency, r.FromCuryID, r.CuryRateType, r.CuryEffDate));
            }
            return(ret);
        }
Esempio n. 6
0
        protected virtual void CurrencyRate_CuryEffDate_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            CuryRateFilter crf  = Filter.Current as CuryRateFilter;
            CurrencyRate   rate = (CurrencyRate)e.Row;

            if (rate == null)
            {
                return;
            }
            if (rate.FromCuryID != null && rate.CuryRateType != null && rate.CuryEffDate != null)
            {
                CurrencyRate existRate = PXSelectReadonly <CurrencyRate,
                                                           Where <CurrencyRate.toCuryID, Equal <Required <CurrencyRate.toCuryID> >,
                                                                  And <CurrencyRate.fromCuryID, Equal <Required <CurrencyRate.fromCuryID> >,
                                                                       And <CurrencyRate.curyRateType, Equal <Required <CurrencyRate.curyRateType> >,
                                                                            And <CurrencyRate.curyEffDate, LessEqual <Required <CurrencyRate.curyEffDate> > > > > >,
                                                           OrderBy <Desc <CurrencyRate.curyEffDate> > > .Select(cache.Graph, rate.ToCuryID, rate.FromCuryID, rate.CuryRateType, rate.CuryEffDate);

                if (existRate != null)
                {
                    rate.CuryMultDiv = existRate.CuryMultDiv;
                }
            }
        }
Esempio n. 7
0
        protected virtual void CurrencyRate_RowInserting(PXCache cache, PXRowInsertingEventArgs e)
        {
            CurrencyRate   cr  = e.Row as CurrencyRate;
            CuryRateFilter crf = Filter.Current as CuryRateFilter;

            if (cr.FromCuryID != null && crf.ToCurrency != null && String.Compare(cr.FromCuryID, crf.ToCurrency, true) == 0)
            {
                throw new PXException(Messages.DestShouldDifferFromOrig);
            }

            bool importing = e.Row != null && cache.GetValuePending(e.Row, PXImportAttribute.ImportFlag) != null;

            if (e.ExternalCall && !importing)
            {
                if (cr.CuryEffDate == null)
                {
                    if (crf.EffDate == null)
                    {
                        cr.CuryEffDate = DateTime.Now;
                    }
                    else
                    {
                        cr.CuryEffDate = crf.EffDate;
                    }
                }

                if (cr.CuryRate != null)
                {
                    cr.RateReciprocal = Math.Round((decimal)(1 / cr.CuryRate), 8);
                    if (((CurrencyInfo)cr).CheckRateVariance(cache))
                    {
                        cache.RaiseExceptionHandling <CurrencyRate.curyRate>(cr, cr.CuryRate, new PXSetPropertyException(Messages.RateVarianceExceeded, PXErrorLevel.Warning));
                    }
                }

                if (cr.CuryMultDiv == " " &&
                    cr.FromCuryID != null &&
                    cr.ToCuryID != null &&
                    cr.CuryRateType != null &&
                    cr.CuryEffDate != null)
                {
                    CurrencyRate existRateMultDiv = PXSelectReadonly <CurrencyRate,
                                                                      Where <CurrencyRate.fromCuryID, Equal <Required <CurrencyRate.fromCuryID> >,
                                                                             And <CurrencyRate.toCuryID, Equal <Required <CurrencyRate.toCuryID> >,
                                                                                  And <CurrencyRate.curyRateType, Equal <Required <CurrencyRate.curyRateType> >,
                                                                                       And <CurrencyRate.curyEffDate, LessEqual <Required <CurrencyRate.curyEffDate> > > > > >,
                                                                      OrderBy <Desc <CurrencyRate.curyEffDate> > > .Select(cache.Graph, cr.FromCuryID, cr.ToCuryID, cr.CuryRateType, cr.CuryEffDate);

                    if (existRateMultDiv != null)
                    {
                        cr.CuryMultDiv = existRateMultDiv.CuryMultDiv;
                    }
                }
            }
            if (cr.FromCuryID != null &&
                cr.CuryRateType != null &&
                cr.CuryRateType != null &&
                cr.CuryEffDate != null &&
                cr.CuryRate != null)
            {
                CurrencyRate existRate = PXSelectReadonly <CurrencyRate,
                                                           Where <CurrencyRate.toCuryID, Equal <Required <CurrencyRate.toCuryID> >,
                                                                  And <CurrencyRate.fromCuryID, Equal <Required <CurrencyRate.fromCuryID> >,
                                                                       And <CurrencyRate.curyRateType, Equal <Required <CurrencyRate.curyRateType> >,
                                                                            And <CurrencyRate.curyEffDate, Equal <Required <CurrencyRate.curyEffDate> > > > > > > .Select(cache.Graph, cr.ToCuryID, cr.FromCuryID, cr.CuryRateType, cr.CuryEffDate);

                if (existRate != null)
                {
                    e.Cancel = true;
                    CurrencyRate newExistRate = (CurrencyRate)CuryRateRecordsEntry.Cache.CreateCopy(existRate);
                    newExistRate.CuryRate       = cr.CuryRate;
                    newExistRate.CuryMultDiv    = cr.CuryMultDiv;
                    newExistRate.RateReciprocal = cr.RateReciprocal;
                    CuryRateRecordsEntry.Update(newExistRate);
                    cache.RaiseExceptionHandling <CurrencyRate.curyRate>(cr, cr.CuryRate, new PXSetPropertyException(Messages.SuchRateTypeAlreadyExist, PXErrorLevel.Warning));
                }
            }
        }