Esempio n. 1
0
        public void OnRowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            GLTran tran = (GLTran)e.Row;

            if (tran != null && ((e.Operation & PXDBOperation.Command) != PXDBOperation.Delete))
            {
                PXCache batchCache = sender.Graph.Caches[typeof(Batch)];
                Batch   batch      = (Batch)batchCache.Current;
                if (batch != null && string.IsNullOrEmpty(batch.BatchNbr) == false)
                {
                    string batchNbr = batch.BatchNbr;
                    if (string.IsNullOrEmpty(tran.RefNbr))
                    {
                        string extRefNbr;
                        if (!_batchKeys.TryGetValue(batchNbr, out extRefNbr))
                        {
                            extRefNbr = AutoNumberAttribute.GetNextNumber(sender, tran, extRefNbrNumbering, tran.TranDate);
                            _batchKeys.Add(batchNbr, extRefNbr);
                        }
                        tran.RefNbr = extRefNbr;

                        PXDBLiteDefaultAttribute.SetDefaultForInsert <GLTran.refNbr>(sender, tran, false);
                    }
                }
            }
        }
        /// <summary>
        /// Assigns the <see cref="GLTran.RefNbr"/>.
        /// The method either generates a reference number based on the specified numbering sequence (<see cref="extRefNbrNumbering"/>),
        /// or takes it from the BatchNbr-RefNbr dictionary (<see cref="_batchKeys"/>).
        /// If the number is generated it is also stored in the dictionary.
        /// </summary>
        /// <param name="sender">cache of type <see cref="GLTran"/>. Will be used to get a cache of type <see cref="Batch"/>.</param>
        /// <param name="tran">transaction, to which the RefNbr is assigned</param>
        /// <param name="generateIfNew">specifies whether a RefNbr must be generated based on the sequence if the RefNbr is not found for the current Batch</param>
        private void AssignRefNbr(PXCache sender, GLTran tran, bool generateIfNew)
        {
            PXCache batchCache = sender.Graph.Caches[typeof(Batch)];
            Batch   batch      = (Batch)batchCache.Current;

            if (batch != null && string.IsNullOrEmpty(batch.BatchNbr) == false)
            {
                string batchNbr = batch.BatchNbr;
                if (string.IsNullOrEmpty(tran.RefNbr))
                {
                    string extRefNbr = null;
                    if (!_batchKeys.TryGetValue(batchNbr, out extRefNbr) && generateIfNew)
                    {
                        extRefNbr = AutoNumberAttribute.GetNextNumber(sender, tran, extRefNbrNumbering, tran.TranDate);
                        _batchKeys.Add(batchNbr, extRefNbr);
                    }

                    if (extRefNbr != null)
                    {
                        tran.RefNbr = extRefNbr;
                    }

                    PXDBLiteDefaultAttribute.SetDefaultForInsert <GLTran.refNbr>(sender, tran, false);
                }
            }
        }