Ejemplo n.º 1
0
        private void DeleteNewRecords(int ABatchNumber, int AJournalNumber)
        {
            // Delete the associated recurring transaction analysis attributes
            DataView viewRecurringTransAnalAttrib = new DataView(FMainDS.ARecurringTransAnalAttrib);

            viewRecurringTransAnalAttrib.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                                                                   ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                                   ABatchNumber,
                                                                   ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                                   AJournalNumber
                                                                   );

            foreach (DataRowView row in viewRecurringTransAnalAttrib)
            {
                row.Delete();
            }

            // Delete the associated recurring transactions
            DataView viewRecurringTransaction = new DataView(FMainDS.ARecurringTransaction);

            viewRecurringTransaction.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                                                               ARecurringTransactionTable.GetBatchNumberDBName(),
                                                               ABatchNumber,
                                                               ARecurringTransactionTable.GetJournalNumberDBName(),
                                                               AJournalNumber
                                                               );

            foreach (DataRowView row in viewRecurringTransaction)
            {
                row.Delete();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes the current row and optionally populates a completion message
        /// </summary>
        /// <param name="ARowToDelete">the currently selected row to delete</param>
        /// <param name="ACompletionMessage">if specified, is the deletion completion message</param>
        /// <returns>true if row deletion is successful</returns>
        private bool DeleteRowManual(ARecurringBatchRow ARowToDelete, ref string ACompletionMessage)
        {
            int BatchNumber = ARowToDelete.BatchNumber;

            // Delete on client side data through views that is already loaded. Data that is not
            // loaded yet will be deleted with cascading delete on server side so we don't have
            // to worry about this here.

            ACompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} deleted successfully."),
                                               BatchNumber);

            // Delete the associated recurring transaction analysis attributes
            DataView viewRecurringTransAnalAttrib = new DataView(FMainDS.ARecurringTransAnalAttrib);

            viewRecurringTransAnalAttrib.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                                                                   ARecurringTransAnalAttribTable.GetLedgerNumberDBName(),
                                                                   FLedgerNumber,
                                                                   ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                                   BatchNumber);

            foreach (DataRowView row in viewRecurringTransAnalAttrib)
            {
                row.Delete();
            }

            // Delete the associated recurring transactions
            DataView viewRecurringTransaction = new DataView(FMainDS.ARecurringTransaction);

            viewRecurringTransaction.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                                                               ARecurringTransactionTable.GetLedgerNumberDBName(),
                                                               FLedgerNumber,
                                                               ARecurringTransactionTable.GetBatchNumberDBName(),
                                                               BatchNumber);

            foreach (DataRowView row in viewRecurringTransaction)
            {
                row.Delete();
            }

            // Delete the associated recurring journals
            DataView viewRecurringJournal = new DataView(FMainDS.ARecurringJournal);

            viewRecurringJournal.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                                                           ARecurringJournalTable.GetLedgerNumberDBName(),
                                                           FLedgerNumber,
                                                           ARecurringJournalTable.GetBatchNumberDBName(),
                                                           BatchNumber);

            foreach (DataRowView row in viewRecurringJournal)
            {
                row.Delete();
            }

            // Delete the recurring batch row.
            ARowToDelete.Delete();

            UpdateRecordNumberDisplay();

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Used for the validation of Analysis Attributes
        /// </summary>
        /// <param name="ATransactionNumber"></param>
        /// <param name="AAccountCode"></param>
        /// <param name="AGLBatchDS"></param>
        /// <param name="AValueRequiredForType"></param>
        /// <returns></returns>
        public bool AccountRecurringAnalysisAttributesValuesExist(int ATransactionNumber,
                                                                  string AAccountCode,
                                                                  GLBatchTDS AGLBatchDS,
                                                                  out String AValueRequiredForType)
        {
            AValueRequiredForType = string.Empty;

            if (string.IsNullOrEmpty(AAccountCode) || (AGLBatchDS.ATransAnalAttrib.DefaultView.Count == 0))
            {
                return(true);
            }

            StringCollection RequiredAnalAttrCodes = TRemote.MFinance.Setup.WebConnectors.RequiredAnalysisAttributesForAccount(FLedgerNumber,
                                                                                                                               AAccountCode, false);

            string AnalysisCodeFilterValues = TAnalysisAttributes.ConvertStringCollectionToCSV(RequiredAnalAttrCodes, "'");

            DataView analAttrib = new DataView(AGLBatchDS.ARecurringTransAnalAttrib);

            analAttrib.RowFilter = String.Format("{0}={1} AND {2}={3} AND {4}={5} AND {6} IN ({7})",
                                                 ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                 FBatchNumber,
                                                 ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                 FJournalNumber,
                                                 ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                                 ATransactionNumber,
                                                 ARecurringTransAnalAttribTable.GetAnalysisTypeCodeDBName(),
                                                 AnalysisCodeFilterValues);

            foreach (DataRowView drv in analAttrib)
            {
                ARecurringTransAnalAttribRow rw = (ARecurringTransAnalAttribRow)drv.Row;

                string analysisCode = rw.AnalysisTypeCode;

                if (TRemote.MFinance.Setup.WebConnectors.AccountAnalysisAttributeRequiresValues(FLedgerNumber, analysisCode, false))
                {
                    if (rw.IsAnalysisAttributeValueNull() || (rw.AnalysisAttributeValue == string.Empty))
                    {
                        AValueRequiredForType = rw.AnalysisTypeCode;
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Used for the validation of Analysis Attributes
        /// </summary>
        /// <param name="ATransactionNumber"></param>
        /// <param name="AAccountCode"></param>
        /// <param name="AGLBatchDS"></param>
        /// <returns></returns>
        public bool AccountRecurringAnalysisAttributeCountIsCorrect(int ATransactionNumber,
                                                                    string AAccountCode,
                                                                    GLBatchTDS AGLBatchDS)
        {
            bool RetVal = true;

            if (string.IsNullOrEmpty(AAccountCode))
            {
                return(RetVal);
            }

            int NumberOfAttributes = 0;

            TRemote.MFinance.Setup.WebConnectors.AccountHasAnalysisAttributes(FLedgerNumber, AAccountCode, out NumberOfAttributes, false);

            if (NumberOfAttributes == 0)
            {
                return(RetVal);
            }

            DataView analAttrib = new DataView(AGLBatchDS.ARecurringTransAnalAttrib);

            analAttrib.RowFilter = String.Format("{0}={1} AND {2}={3} AND {4}={5} AND {6}={7}",
                                                 ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                 FBatchNumber,
                                                 ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                 FJournalNumber,
                                                 ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                                 ATransactionNumber,
                                                 ARecurringTransAnalAttribTable.GetAccountCodeDBName(),
                                                 AAccountCode);

            RetVal = (analAttrib.Count == NumberOfAttributes);

            return(RetVal);
        }
        /// <summary>
        /// Undo all changes to the specified batch ready to cancel it.
        ///  This avoids unecessary validation errors when cancelling.
        /// </summary>
        /// <param name="ACurrentBatch"></param>
        /// <param name="AJournalToDelete"></param>
        /// <param name="ARedisplay"></param>
        public void PrepareJournalDataForDeleting(Int32 ACurrentBatch, Int32 AJournalToDelete, Boolean ARedisplay)
        {
            //This code will only be called when the Batch tab is active.

            DataView JournalDV   = new DataView(FMainDS.ARecurringJournal);
            DataView TransDV     = new DataView(FMainDS.ARecurringTransaction);
            DataView TransAnalDV = new DataView(FMainDS.ARecurringTransAnalAttrib);

            JournalDV.RowFilter = String.Format("{0}={1} And {2}={3}",
                                                ARecurringJournalTable.GetBatchNumberDBName(),
                                                ACurrentBatch,
                                                ARecurringJournalTable.GetJournalNumberDBName(),
                                                AJournalToDelete);

            TransDV.RowFilter = String.Format("{0}={1} And {2}={3}",
                                              ARecurringTransactionTable.GetBatchNumberDBName(),
                                              ACurrentBatch,
                                              ARecurringTransactionTable.GetJournalNumberDBName(),
                                              AJournalToDelete);

            TransAnalDV.RowFilter = String.Format("{0}={1} And {2}={3}",
                                                  ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                  ACurrentBatch,
                                                  ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                  AJournalToDelete);

            //Work from lowest level up
            if (TransAnalDV.Count > 0)
            {
                TransAnalDV.Sort = String.Format("{0}, {1}, {2}",
                                                 ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                 ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                                 ARecurringTransAnalAttribTable.GetAnalysisTypeCodeDBName());

                foreach (DataRowView drv in TransAnalDV)
                {
                    ARecurringTransAnalAttribRow transAnalRow = (ARecurringTransAnalAttribRow)drv.Row;

                    if (transAnalRow.RowState == DataRowState.Added)
                    {
                        //Do nothing
                    }
                    else if (transAnalRow.RowState != DataRowState.Unchanged)
                    {
                        transAnalRow.RejectChanges();
                    }
                }
            }

            if (TransDV.Count > 0)
            {
                TransDV.Sort = String.Format("{0}, {1}",
                                             ARecurringTransactionTable.GetJournalNumberDBName(),
                                             ARecurringTransactionTable.GetTransactionNumberDBName());

                foreach (DataRowView drv in TransDV)
                {
                    ARecurringTransactionRow transRow = (ARecurringTransactionRow)drv.Row;

                    if (transRow.RowState == DataRowState.Added)
                    {
                        //Do nothing
                    }
                    else if (transRow.RowState != DataRowState.Unchanged)
                    {
                        transRow.RejectChanges();
                    }
                }
            }

            if (JournalDV.Count > 0)
            {
                GLBatchTDSARecurringJournalRow journalRow = (GLBatchTDSARecurringJournalRow)JournalDV[0].Row;

                //No need to check for Added state as new batches are always saved
                // on creation

                if (journalRow.RowState != DataRowState.Unchanged)
                {
                    journalRow.RejectChanges();
                }

                if (ARedisplay)
                {
                    ShowDetails(journalRow);
                }
            }

            if (TransDV.Count == 0)
            {
                //Load all related data for batch ready to delete/cancel
                FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadARecurringTransactionAndRelatedTablesForJournal(FLedgerNumber, ACurrentBatch,
                                                                                                                    AJournalToDelete));
            }
        }
Ejemplo n.º 6
0
        public static GLBatchTDS LoadARecurringBatchAndContent(Int32 ALedgerNumber, Int32 ABatchNumber)
        {
            Boolean NewTransaction = false;

            TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                out NewTransaction);


            GLBatchTDS MainDS = new GLBatchTDS();

            ARecurringBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, Transaction);
            ARecurringJournalAccess.LoadViaARecurringBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction);

            ARecurringTransactionTable TransactionTable = new ARecurringTransactionTable();
            ARecurringTransactionRow TemplateTransactionRow = TransactionTable.NewRowTyped(false);
            TemplateTransactionRow.LedgerNumber = ALedgerNumber;
            TemplateTransactionRow.BatchNumber = ABatchNumber;
            ARecurringTransactionAccess.LoadUsingTemplate(MainDS, TemplateTransactionRow, Transaction);

            ARecurringTransAnalAttribTable TransAnalAttribTable = new ARecurringTransAnalAttribTable();
            ARecurringTransAnalAttribRow TemplateTransAnalAttribRow = TransAnalAttribTable.NewRowTyped(false);
            TemplateTransAnalAttribRow.LedgerNumber = ALedgerNumber;
            TemplateTransAnalAttribRow.BatchNumber = ABatchNumber;
            ARecurringTransAnalAttribAccess.LoadUsingTemplate(MainDS, TemplateTransAnalAttribRow, Transaction);

            if (NewTransaction)
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }

            return MainDS;
        }
Ejemplo n.º 7
0
        private static TSubmitChangesResult SaveRecurringGLBatchTDS(ref GLBatchTDS AInspectDS)
        {
            Int32 LedgerNumber;
            Int32 BatchNumber;
            Int32 JournalNumber;
            Int32 TransactionNumber;
            Int32 Counter;

            bool recurrBatchTableInDataSet = (AInspectDS.ARecurringBatch != null);
            bool recurrJournalTableInDataSet = (AInspectDS.ARecurringJournal != null);
            bool recurrTransactionTableInDataSet = (AInspectDS.ARecurringTransaction != null);
            bool recurrTransAnalTableInDataSet = (AInspectDS.ARecurringTransAnalAttrib != null);

            TSubmitChangesResult SubmissionResult = new TSubmitChangesResult();

            ARecurringJournalTable JournalTable = new ARecurringJournalTable();
            ARecurringJournalRow TemplateJournalRow = JournalTable.NewRowTyped(false);

            ARecurringTransactionTable TransactionTable = new ARecurringTransactionTable();
            ARecurringTransactionRow TemplateTransactionRow = TransactionTable.NewRowTyped(false);

            ARecurringTransAnalAttribTable TransAnalAttribTable = new ARecurringTransAnalAttribTable();
            ARecurringTransAnalAttribRow TemplateTransAnalAttribRow = TransAnalAttribTable.NewRowTyped(false);

            GLBatchTDS DeletedDS = new GLBatchTDS();
            ARecurringTransAnalAttribTable DeletedTransAnalAttribTable;

            // in this method we also think about deleted batches, journals, transactions where subsequent information
            // had not been loaded yet: a type of cascading delete is being used (real cascading delete currently does
            // not go down the number of levels needed).

            TDBTransaction Transaction = null;
            GLBatchTDS InspectDS = AInspectDS;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.Serializable,
                ref Transaction,
                delegate
                {
                    if (recurrBatchTableInDataSet)
                    {
                        foreach (ARecurringBatchRow batch in InspectDS.ARecurringBatch.Rows)
                        {
                            if (batch.RowState == DataRowState.Deleted)
                            {
                                // need to use this way of retrieving data from deleted rows
                                LedgerNumber = (Int32)batch[ARecurringBatchTable.ColumnLedgerNumberId, DataRowVersion.Original];
                                BatchNumber = (Int32)batch[ARecurringBatchTable.ColumnBatchNumberId, DataRowVersion.Original];

                                // load all depending journals, transactions and attributes and make sure they are also deleted via the dataset
                                TemplateTransAnalAttribRow.LedgerNumber = LedgerNumber;
                                TemplateTransAnalAttribRow.BatchNumber = BatchNumber;
                                DeletedTransAnalAttribTable =
                                    ARecurringTransAnalAttribAccess.LoadUsingTemplate(TemplateTransAnalAttribRow, Transaction);

                                for (Counter = DeletedTransAnalAttribTable.Count - 1; Counter >= 0; Counter--)
                                {
                                    DeletedTransAnalAttribTable.Rows[Counter].Delete();
                                }

                                InspectDS.Merge(DeletedTransAnalAttribTable);

                                TemplateTransactionRow.LedgerNumber = LedgerNumber;
                                TemplateTransactionRow.BatchNumber = BatchNumber;
                                ARecurringTransactionAccess.LoadUsingTemplate(DeletedDS, TemplateTransactionRow, Transaction);

                                for (Counter = DeletedDS.ARecurringTransaction.Count - 1; Counter >= 0; Counter--)
                                {
                                    DeletedDS.ARecurringTransaction.Rows[Counter].Delete();
                                }

                                InspectDS.Merge(DeletedDS.ARecurringTransaction);

                                TemplateJournalRow.LedgerNumber = LedgerNumber;
                                TemplateJournalRow.BatchNumber = BatchNumber;
                                ARecurringJournalAccess.LoadUsingTemplate(DeletedDS, TemplateJournalRow, Transaction);

                                for (Counter = DeletedDS.ARecurringJournal.Count - 1; Counter >= 0; Counter--)
                                {
                                    DeletedDS.ARecurringJournal.Rows[Counter].Delete();
                                }

                                InspectDS.Merge(DeletedDS.ARecurringJournal);
                            }
                        }
                    }

                    if (recurrJournalTableInDataSet)
                    {
                        foreach (ARecurringJournalRow journal in InspectDS.ARecurringJournal.Rows)
                        {
                            if (journal.RowState == DataRowState.Deleted)
                            {
                                // need to use this way of retrieving data from deleted rows
                                LedgerNumber = (Int32)journal[ARecurringJournalTable.ColumnLedgerNumberId, DataRowVersion.Original];
                                BatchNumber = (Int32)journal[ARecurringJournalTable.ColumnBatchNumberId, DataRowVersion.Original];
                                JournalNumber = (Int32)journal[ARecurringJournalTable.ColumnJournalNumberId, DataRowVersion.Original];

                                // load all depending transactions and attributes and make sure they are also deleted via the dataset
                                TemplateTransAnalAttribRow.LedgerNumber = LedgerNumber;
                                TemplateTransAnalAttribRow.BatchNumber = BatchNumber;
                                TemplateTransAnalAttribRow.JournalNumber = JournalNumber;
                                DeletedTransAnalAttribTable =
                                    ARecurringTransAnalAttribAccess.LoadUsingTemplate(TemplateTransAnalAttribRow, Transaction);

                                for (Counter = DeletedTransAnalAttribTable.Count - 1; Counter >= 0; Counter--)
                                {
                                    DeletedTransAnalAttribTable.Rows[Counter].Delete();
                                }

                                InspectDS.Merge(DeletedTransAnalAttribTable);

                                TemplateTransactionRow.LedgerNumber = LedgerNumber;
                                TemplateTransactionRow.BatchNumber = BatchNumber;
                                TemplateTransactionRow.JournalNumber = JournalNumber;
                                ARecurringTransactionAccess.LoadUsingTemplate(DeletedDS, TemplateTransactionRow, Transaction);

                                for (Counter = DeletedDS.ARecurringTransaction.Count - 1; Counter >= 0; Counter--)
                                {
                                    DeletedDS.ARecurringTransaction.Rows[Counter].Delete();
                                }

                                InspectDS.Merge(DeletedDS.ARecurringTransaction);
                            }
                        }
                    }

                    if (recurrTransactionTableInDataSet)
                    {
                        foreach (ARecurringTransactionRow transaction in InspectDS.ARecurringTransaction.Rows)
                        {
                            if (transaction.RowState == DataRowState.Deleted)
                            {
                                // need to use this way of retrieving data from deleted rows
                                LedgerNumber = (Int32)transaction[ARecurringTransactionTable.ColumnLedgerNumberId, DataRowVersion.Original];
                                BatchNumber = (Int32)transaction[ARecurringTransactionTable.ColumnBatchNumberId, DataRowVersion.Original];
                                JournalNumber = (Int32)transaction[ARecurringTransactionTable.ColumnJournalNumberId, DataRowVersion.Original];
                                TransactionNumber = (Int32)transaction[ARecurringTransactionTable.ColumnTransactionNumberId, DataRowVersion.Original];

                                // load all depending transactions and attributes and make sure they are also deleted via the dataset
                                TemplateTransAnalAttribRow.LedgerNumber = LedgerNumber;
                                TemplateTransAnalAttribRow.BatchNumber = BatchNumber;
                                TemplateTransAnalAttribRow.JournalNumber = JournalNumber;
                                TemplateTransAnalAttribRow.TransactionNumber = TransactionNumber;
                                DeletedTransAnalAttribTable =
                                    ARecurringTransAnalAttribAccess.LoadUsingTemplate(TemplateTransAnalAttribRow, Transaction);

                                for (Counter = DeletedTransAnalAttribTable.Count - 1; Counter >= 0; Counter--)
                                {
                                    DeletedTransAnalAttribTable.Rows[Counter].Delete();
                                }

                                InspectDS.Merge(DeletedTransAnalAttribTable);
                            }
                        }
                    }
                });

            // now submit the changes
            GLBatchTDSAccess.SubmitChanges(AInspectDS);

            SubmissionResult = TSubmitChangesResult.scrOK;

            if (recurrTransactionTableInDataSet)
            {
                //Accept deletion of Attributes to allow deletion of transactions
                if (recurrTransAnalTableInDataSet)
                {
                    AInspectDS.ARecurringTransAnalAttrib.AcceptChanges();
                }

                AInspectDS.ARecurringTransaction.AcceptChanges();

                if (AInspectDS.ARecurringTransaction.Count > 0)
                {
                    ARecurringTransactionRow tranR = (ARecurringTransactionRow)AInspectDS.ARecurringTransaction.Rows[0];

                    Int32 currentLedger = tranR.LedgerNumber;
                    Int32 currentBatch = tranR.BatchNumber;
                    Int32 currentJournal = tranR.JournalNumber;
                    Int32 transToDelete = 0;

                    try
                    {
                        //Check if any records have been marked for deletion
                        DataRow[] foundTransactionForDeletion = AInspectDS.ARecurringTransaction.Select(String.Format("{0} = '{1}'",
                                ARecurringTransactionTable.GetSubTypeDBName(),
                                MFinanceConstants.MARKED_FOR_DELETION));

                        if (foundTransactionForDeletion.Length > 0)
                        {
                            ARecurringTransactionRow transRowClient = null;

                            for (int i = 0; i < foundTransactionForDeletion.Length; i++)
                            {
                                transRowClient = (ARecurringTransactionRow)foundTransactionForDeletion[i];

                                transToDelete = transRowClient.TransactionNumber;
                                TLogging.Log(String.Format("Recurring transaction to Delete: {0} from Journal: {1} in Batch: {2}",
                                        transToDelete,
                                        currentJournal,
                                        currentBatch));

                                transRowClient.Delete();
                            }

                            //save changes
                            GLBatchTDSAccess.SubmitChanges(AInspectDS);

                            SubmissionResult = TSubmitChangesResult.scrOK;
                        }
                    }
                    catch (Exception ex)
                    {
                        TLogging.Log("Saving DataSet: " + ex.Message);

                        TLogging.Log(String.Format("Error trying to save transaction: {0} in Journal: {1}, Batch: {2}",
                                transToDelete,
                                currentJournal,
                                currentBatch
                                ));

                        SubmissionResult = TSubmitChangesResult.scrError;
                    }
                }
            }

            return SubmissionResult;
        }
Ejemplo n.º 8
0
        private bool AllowInactiveFieldValues()
        {
            bool RetVal = false;

            DataView TransDV  = new DataView(FMainDS.ARecurringTransaction);
            DataView AttribDV = new DataView(FMainDS.ARecurringTransAnalAttrib);

            try
            {
                TransDV.RowFilter = String.Format("{0}={1}",
                                                  ARecurringTransactionTable.GetBatchNumberDBName(),
                                                  FSelectedBatchNumber);
                AttribDV.RowFilter = String.Format("{0}={1}",
                                                   ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                   FSelectedBatchNumber);

                //Check for inactive data field values
                foreach (DataRowView drv in TransDV)
                {
                    ARecurringTransactionRow transRow = (ARecurringTransactionRow)drv.Row;

                    if (!AccountIsActive(transRow.AccountCode) || !CostCentreIsActive(transRow.CostCentreCode))
                    {
                        if (MessageBox.Show(String.Format(Catalog.GetString(
                                                              "Recurring batch no. {0} contains an inactive account or cost centre code in journal {1}, transaction {2}. Do you still want to submit the batch?"),
                                                          FSelectedBatchNumber,
                                                          transRow.JournalNumber,
                                                          transRow.TransactionNumber),
                                            Catalog.GetString("Inactive Account/Cost Centre Code"), MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Warning) == DialogResult.No)
                        {
                            return(RetVal);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                foreach (DataRowView drv2 in AttribDV)
                {
                    ARecurringTransAnalAttribRow analAttribRow = (ARecurringTransAnalAttribRow)drv2.Row;

                    if (!AnalysisCodeIsActive(analAttribRow.AccountCode,
                                              analAttribRow.AnalysisTypeCode) ||
                        !AnalysisAttributeValueIsActive(analAttribRow.AnalysisTypeCode, analAttribRow.AnalysisAttributeValue))
                    {
                        if (MessageBox.Show(String.Format(Catalog.GetString(
                                                              "Recurring batch no. {0} contains an inactive analysis attribute code/value in journal {1}, transaction {2}. Do you still want to submit the batch?"),
                                                          FSelectedBatchNumber,
                                                          analAttribRow.JournalNumber,
                                                          analAttribRow.TransactionNumber),
                                            Catalog.GetString("Inactive Analysis Attribute Code/Value"), MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Warning) == DialogResult.No)
                        {
                            return(RetVal);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                RetVal = true;
            }
            catch (Exception)
            {
                throw;
            }

            return(RetVal);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Deletes the current row and optionally populates a completion message
        /// </summary>
        /// <param name="ARowToDelete">the currently selected row to delete</param>
        /// <param name="ACompletionMessage">if specified, is the deletion completion message</param>
        /// <returns>true if row deletion is successful</returns>
        private bool DeleteRowManual(ARecurringBatchRow ARowToDelete, ref string ACompletionMessage)
        {
            //Assign default value(s)
            bool DeletionSuccessful = false;

            if (ARowToDelete == null)
            {
                return(DeletionSuccessful);
            }

            int BatchNumber = ARowToDelete.BatchNumber;

            //Backup the Dataset for reversion purposes
            GLBatchTDS BackupMainDS = (GLBatchTDS)FMainDS.Copy();

            BackupMainDS.Merge(FMainDS);

            if (ARowToDelete.RowState != DataRowState.Added)
            {
                //Reject any changes which may fail validation
                ARowToDelete.RejectChanges();
                ShowDetails(ARowToDelete);
            }

            try
            {
                this.Cursor = Cursors.WaitCursor;

                ACompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} deleted successfully."),
                                                   BatchNumber);

                // Delete the associated recurring transaction analysis attributes
                DataView viewRecurringTransAnalAttrib = new DataView(FMainDS.ARecurringTransAnalAttrib);
                viewRecurringTransAnalAttrib.RowFilter = String.Format("{0}={1} AND {2}={3}",
                                                                       ARecurringTransAnalAttribTable.GetLedgerNumberDBName(),
                                                                       FLedgerNumber,
                                                                       ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                                       BatchNumber);

                foreach (DataRowView row in viewRecurringTransAnalAttrib)
                {
                    row.Delete();
                }

                // Delete the associated recurring transactions
                DataView viewRecurringTransaction = new DataView(FMainDS.ARecurringTransaction);
                viewRecurringTransaction.RowFilter = String.Format("{0}={1} AND {2}={3}",
                                                                   ARecurringTransactionTable.GetLedgerNumberDBName(),
                                                                   FLedgerNumber,
                                                                   ARecurringTransactionTable.GetBatchNumberDBName(),
                                                                   BatchNumber);

                foreach (DataRowView row in viewRecurringTransaction)
                {
                    row.Delete();
                }

                // Delete the associated recurring journals
                DataView viewRecurringJournal = new DataView(FMainDS.ARecurringJournal);
                viewRecurringJournal.RowFilter = String.Format("{0}={1} AND {2}={3}",
                                                               ARecurringJournalTable.GetLedgerNumberDBName(),
                                                               FLedgerNumber,
                                                               ARecurringJournalTable.GetBatchNumberDBName(),
                                                               BatchNumber);

                foreach (DataRowView row in viewRecurringJournal)
                {
                    row.Delete();
                }

                // Delete the recurring batch row.
                ARowToDelete.Delete();

                DeletionSuccessful = true;
            }
            catch (Exception ex)
            {
                ACompletionMessage = ex.Message;
                MessageBox.Show(ACompletionMessage,
                                "Deletion Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                //Revert to previous state
                FMainDS.Merge(BackupMainDS);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }

            UpdateRecordNumberDisplay();

            return(DeletionSuccessful);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="AGLBatchDS"></param>
        /// <param name="ATransactionNumber"></param>
        /// <param name="AAnalysisCodeFilterValues"></param>
        public void SetRecurringTransAnalAttributeDefaultView(GLBatchTDS AGLBatchDS,
                                                              Int32 ATransactionNumber         = 0,
                                                              String AAnalysisCodeFilterValues = "")
        {
            if (FBatchNumber != -1)
            {
                if (ATransactionNumber > 0)
                {
                    if (AAnalysisCodeFilterValues.Length > 0)
                    {
                        AGLBatchDS.ARecurringTransAnalAttrib.DefaultView.RowFilter = String.Format("{0}={1} AND {2}={3} AND {4}={5} AND {6} IN ({7})",
                                                                                                   ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                                                                   FBatchNumber,
                                                                                                   ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                                                                   FJournalNumber,
                                                                                                   ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                                                                                   ATransactionNumber,
                                                                                                   ARecurringTransAnalAttribTable.GetAnalysisTypeCodeDBName(),
                                                                                                   AAnalysisCodeFilterValues);
                    }
                    else
                    {
                        AGLBatchDS.ARecurringTransAnalAttrib.DefaultView.RowFilter = String.Format("{0}={1} AND {2}={3} AND {4}={5}",
                                                                                                   ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                                                                   FBatchNumber,
                                                                                                   ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                                                                   FJournalNumber,
                                                                                                   ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                                                                                   ATransactionNumber);
                    }
                }
                else
                {
                    AGLBatchDS.ARecurringTransAnalAttrib.DefaultView.RowFilter = String.Format("{0}={1} AND {2}={3}",
                                                                                               ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                                                               FBatchNumber,
                                                                                               ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                                                               FJournalNumber);
                }

                AGLBatchDS.ARecurringTransAnalAttrib.DefaultView.Sort = String.Format("{0} ASC, {1} ASC",
                                                                                      ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                                                                      ARecurringTransAnalAttribTable.GetAnalysisTypeCodeDBName()
                                                                                      );
            }
        }
Ejemplo n.º 11
0
        public static GLBatchTDS LoadARecurringJournalAndContent(Int32 ALedgerNumber, Int32 ABatchNumber)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Ledger number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }
            else if (ABatchNumber <= 0)
            {
                throw new EFinanceSystemInvalidBatchNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Batch number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber, ABatchNumber);
            }

            #endregion Validate Arguments

            GLBatchTDS MainDS = new GLBatchTDS();

            TDBTransaction Transaction = null;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                    TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        ARecurringJournalAccess.LoadViaARecurringBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction);

                        ARecurringTransactionTable TransactionTable = new ARecurringTransactionTable();
                        ARecurringTransactionRow TemplateTransactionRow = TransactionTable.NewRowTyped(false);
                        TemplateTransactionRow.LedgerNumber = ALedgerNumber;
                        TemplateTransactionRow.BatchNumber = ABatchNumber;
                        ARecurringTransactionAccess.LoadUsingTemplate(MainDS, TemplateTransactionRow, Transaction);

                        ARecurringTransAnalAttribTable TransAnalAttribTable = new ARecurringTransAnalAttribTable();
                        ARecurringTransAnalAttribRow TemplateTransAnalAttribRow = TransAnalAttribTable.NewRowTyped(false);
                        TemplateTransAnalAttribRow.LedgerNumber = ALedgerNumber;
                        TemplateTransAnalAttribRow.BatchNumber = ABatchNumber;
                        ARecurringTransAnalAttribAccess.LoadUsingTemplate(MainDS, TemplateTransAnalAttribRow, Transaction);

                        #region Validate Data

                        if ((MainDS.ARecurringJournal.Count == 0) && (MainDS.ARecurringTransaction.Count > 0))
                        {
                            throw new ApplicationException(String.Format(Catalog.GetString(
                                        "Function:{0} - Orphaned GL Transactions exist in Recurring GL Batch {1} in Ledger {2}!"),
                                    Utilities.GetMethodName(true),
                                    ABatchNumber,
                                    ALedgerNumber));
                        }
                        else if (((MainDS.ARecurringJournal.Count == 0)
                                  || (MainDS.ARecurringTransaction.Count == 0)) && (MainDS.ARecurringTransAnalAttrib.Count > 0))
                        {
                            throw new ApplicationException(String.Format(Catalog.GetString(
                                        "Function:{0} - Orphaned GL Transaction Analysis Attributes exist in Recurring GL Batch {1} in Ledger {2}!"),
                                    Utilities.GetMethodName(true),
                                    ABatchNumber,
                                    ALedgerNumber));
                        }

                        #endregion Validate Data
                    });

                MainDS.AcceptChanges();
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return MainDS;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Deletes the current row and optionally populates a completion message
        /// </summary>
        /// <param name="ARowToDelete">the currently selected row to delete</param>
        /// <param name="ACompletionMessage">if specified, is the deletion completion message</param>
        /// <returns>true if row deletion is successful</returns>
        private bool DeleteRowManual(ARecurringJournalRow ARowToDelete, ref string ACompletionMessage)
        {
            int batchNumber = ARowToDelete.BatchNumber;

            FJournalNumberToDelete = ARowToDelete.JournalNumber;
            bool deletionSuccessful = false;

            // Delete on client side data through views that is already loaded. Data that is not
            // loaded yet will be deleted with cascading delete on server side so we don't have
            // to worry about this here.

            ACompletionMessage = String.Format(Catalog.GetString("Journal no.: {0} deleted successfully."),
                                               FJournalNumberToDelete);

            try
            {
                //clear any transactions currently being editied in the Transaction Tab
                ((TFrmRecurringGLBatch)ParentForm).GetTransactionsControl().ClearCurrentSelection();

                // Delete the associated recurring transaction analysis attributes
                DataView viewRecurringTransAnalAttrib = new DataView(FMainDS.ARecurringTransAnalAttrib);
                viewRecurringTransAnalAttrib.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                                                                       ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                                       batchNumber,
                                                                       ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                                       FJournalNumberToDelete
                                                                       );

                foreach (DataRowView row in viewRecurringTransAnalAttrib)
                {
                    row.Delete();
                }

                // Delete the associated recurring transactions
                DataView viewRecurringTransaction = new DataView(FMainDS.ARecurringTransaction);
                viewRecurringTransaction.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                                                                   ARecurringTransactionTable.GetBatchNumberDBName(),
                                                                   batchNumber,
                                                                   ARecurringTransactionTable.GetJournalNumberDBName(),
                                                                   FJournalNumberToDelete
                                                                   );

                foreach (DataRowView row in viewRecurringTransaction)
                {
                    row.Delete();
                }

                // Delete the recurring batch row.
                ARowToDelete.Delete();

                FPreviouslySelectedDetailRow = null;

                deletionSuccessful = true;
            }
            catch (Exception ex)
            {
                ACompletionMessage = ex.Message;
                MessageBox.Show(ex.Message,
                                "Deletion Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }

            return(deletionSuccessful);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// load the transactions into the grid
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ABatchNumber"></param>
        /// <param name="AJournalNumber"></param>
        /// <param name="ATransactionNumber"></param>
        public void LoadAttributes(Int32 ALedgerNumber, Int32 ABatchNumber, Int32 AJournalNumber, Int32 ATransactionNumber)
        {
            //Check if the same batch and journal is selected, so no need to apply filter
            if ((FLedgerNumber == ALedgerNumber) && (FBatchNumber == ABatchNumber) && (FJournalNumber == AJournalNumber) &&
                (FTransactionNumber == ATransactionNumber) && (FMainDS.ATransAnalAttrib.DefaultView.Count > 0))
            {
                GetDataFromControls();
                return;
            }

            FLedgerNumber                = ALedgerNumber;
            FBatchNumber                 = ABatchNumber;
            FJournalNumber               = AJournalNumber;
            FTransactionNumber           = ATransactionNumber;
            FPreviouslySelectedDetailRow = null;

            //This is always false for recurring batches, as need to allow the showing of old data.
            FActiveOnly = false;

            if (!cmbDetailAnalysisAttributeValue.Enabled)
            {
                cmbDetailAnalysisAttributeValue.Enabled = true;
            }

            // only load from server if there are no attributes loaded yet for this journal
            // otherwise we would overwrite attributes that have already been modified

            FMainDS.ARecurringTransAnalAttrib.DefaultView.RowFilter = string.Empty;
            FMainDS.ARecurringTransAnalAttrib.DefaultView.Sort      = StringHelper.StrMerge(TTypedDataTable.GetPrimaryKeyColumnStringList(
                                                                                                ARecurringTransactionTable.TableId), ',');

            if (FMainDS.ARecurringTransAnalAttrib.DefaultView.Find(new object[] { FLedgerNumber, FBatchNumber, FJournalNumber,
                                                                                  FTransactionNumber }) == -1)
            {
                FMainDS.ARecurringTransAnalAttrib.Clear();
                FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadARecurringTransAnalAttrib(ALedgerNumber, ABatchNumber, AJournalNumber,
                                                                                              ATransactionNumber));
            }

            CheckFCacheInitialised();

            FMainDS.ARecurringTransAnalAttrib.DefaultView.RowFilter = String.Format("{0}={1} AND {2}={3} AND {4}={5}",
                                                                                    ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                                                    FBatchNumber,
                                                                                    ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                                                    FJournalNumber,
                                                                                    ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                                                                    FTransactionNumber);

            FMainDS.ARecurringTransAnalAttrib.DefaultView.Sort = String.Format("{0} ASC",
                                                                               ARecurringTransAnalAttribTable.GetAnalysisTypeCodeDBName()
                                                                               );

            grdDetails.DataSource = null;
            grdDetails.DataSource = new DevAge.ComponentModel.BoundDataView(FMainDS.ARecurringTransAnalAttrib.DefaultView);

            FMainDS.ARecurringTransAnalAttrib.DefaultView.AllowNew = false;

            if (FMainDS.ARecurringTransAnalAttrib.DefaultView.Count > 0)
            {
                SelectRowInGrid(1);
                pnlDetails.Enabled = !FPetraUtilsObject.DetailProtectedMode && !pnlDetailsProtected;
                UpdateLabels();
            }
            else
            {
                ClearControls();
            }
        }
Ejemplo n.º 14
0
        public static Boolean CanDetachTypeCodeFromAccount(Int32 ALedgerNumber, String AAccountCode, String ATypeCode, out String Message)
        {
            TDBTransaction ReadTrans = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            try
            {
                {
                    AApAnalAttribTable tbl = new AApAnalAttribTable();
                    AApAnalAttribRow Template = tbl.NewRowTyped(false);
                    Template.LedgerNumber = ALedgerNumber;
                    Template.AccountCode = AAccountCode;
                    Template.AnalysisTypeCode = ATypeCode;
                    tbl = AApAnalAttribAccess.LoadUsingTemplate(Template, ReadTrans);

                    if (tbl.Rows.Count > 0)
                    {
                        Message = String.Format(Catalog.GetString("Cannot remove {0} from {1}: "), ATypeCode, AAccountCode) +
                                  String.Format(Catalog.GetString("Analysis Type is used in AP documents ({0} entries)."), tbl.Rows.Count);
                        return false;
                    }
                }

                {
                    ATransAnalAttribTable tbl = new ATransAnalAttribTable();
                    ATransAnalAttribRow Template = tbl.NewRowTyped(false);
                    Template.LedgerNumber = ALedgerNumber;
                    Template.AccountCode = AAccountCode;
                    Template.AnalysisTypeCode = ATypeCode;
                    tbl = ATransAnalAttribAccess.LoadUsingTemplate(Template, ReadTrans);

                    if (tbl.Rows.Count > 0)
                    {
                        Message = String.Format(Catalog.GetString("Cannot remove {0} from {1}: "), ATypeCode, AAccountCode) +
                                  String.Format(Catalog.GetString("Analysis Type is used in Transactions ({0} entries)."), tbl.Rows.Count);
                        return false;
                    }
                }
                {
                    ARecurringTransAnalAttribTable tbl = new ARecurringTransAnalAttribTable();
                    ARecurringTransAnalAttribRow Template = tbl.NewRowTyped(false);
                    Template.LedgerNumber = ALedgerNumber;
                    Template.AccountCode = AAccountCode;
                    Template.AnalysisTypeCode = ATypeCode;
                    tbl = ARecurringTransAnalAttribAccess.LoadUsingTemplate(Template, ReadTrans);

                    if (tbl.Rows.Count > 0)
                    {
                        Message = String.Format(Catalog.GetString("Cannot remove {0} from {1}: "), ATypeCode, AAccountCode) +
                                  String.Format(Catalog.GetString("Analysis Type is used in recurring Transactions ({0} entries)."), tbl.Rows.Count);
                        return false;
                    }
                }
            }
            finally
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }
            Message = "";
            return true;
        }
        private void ProcessNewlyAddedJournalRowForDeletion(int AJournalNumberToDelete)
        {
            GLBatchTDS BackupDS = (GLBatchTDS)FMainDS.Copy();

            BackupDS.Merge(FMainDS);

            try
            {
                // Delete the associated recurring transaction analysis attributes
                DataView attributesDV = new DataView(FMainDS.ARecurringTransAnalAttrib);
                attributesDV.RowFilter = string.Format("{0}={1} And {2}={3}",
                                                       ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                       FBatchNumber,
                                                       ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                       AJournalNumberToDelete
                                                       );

                foreach (DataRowView attrDRV in attributesDV)
                {
                    ARecurringTransAnalAttribRow attrRow = (ARecurringTransAnalAttribRow)attrDRV.Row;
                    attrRow.Delete();
                }

                // Delete the associated recurring transactions
                DataView transactionsDV = new DataView(FMainDS.ARecurringTransaction);
                transactionsDV.RowFilter = String.Format("{0}={1} And {2}={3}",
                                                         ARecurringTransactionTable.GetBatchNumberDBName(),
                                                         FBatchNumber,
                                                         ARecurringTransactionTable.GetJournalNumberDBName(),
                                                         AJournalNumberToDelete
                                                         );

                foreach (DataRowView transDRV in transactionsDV)
                {
                    ARecurringTransactionRow tranRow = (ARecurringTransactionRow)transDRV.Row;
                    tranRow.Delete();
                }

                // Delete the recurring journal
                DataView journalDV = new DataView(FMainDS.ARecurringJournal);
                journalDV.RowFilter = String.Format("{0}={1} And {2}={3}",
                                                    ARecurringJournalTable.GetBatchNumberDBName(),
                                                    FBatchNumber,
                                                    ARecurringJournalTable.GetJournalNumberDBName(),
                                                    AJournalNumberToDelete
                                                    );

                foreach (DataRowView journalDRV in journalDV)
                {
                    ARecurringJournalRow jrnlRow = (ARecurringJournalRow)journalDRV.Row;
                    jrnlRow.Delete();
                }

                //Renumber the journals, transactions and attributes
                DataView attributesDV2 = new DataView(FMainDS.ARecurringTransAnalAttrib);
                attributesDV2.RowFilter = string.Format("{0}={1} And {2}>{3}",
                                                        ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                        FBatchNumber,
                                                        ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                        AJournalNumberToDelete);
                attributesDV2.Sort = String.Format("{0} ASC", ARecurringTransAnalAttribTable.GetJournalNumberDBName());

                foreach (DataRowView attrDRV in attributesDV2)
                {
                    ARecurringTransAnalAttribRow attrRow = (ARecurringTransAnalAttribRow)attrDRV.Row;
                    attrRow.JournalNumber--;
                }

                DataView transactionsDV2 = new DataView(FMainDS.ARecurringTransaction);
                transactionsDV2.RowFilter = string.Format("{0}={1} And {2}>{3}",
                                                          ARecurringTransactionTable.GetBatchNumberDBName(),
                                                          FBatchNumber,
                                                          ARecurringTransactionTable.GetJournalNumberDBName(),
                                                          AJournalNumberToDelete);
                transactionsDV2.Sort = String.Format("{0} ASC", ARecurringTransactionTable.GetJournalNumberDBName());

                foreach (DataRowView transDRV in transactionsDV2)
                {
                    ARecurringTransactionRow tranRow = (ARecurringTransactionRow)transDRV.Row;
                    tranRow.JournalNumber--;
                }

                DataView journalDV2 = new DataView(FMainDS.ARecurringJournal);
                journalDV2.RowFilter = string.Format("{0}={1} And {2}>{3}",
                                                     ARecurringJournalTable.GetBatchNumberDBName(),
                                                     FBatchNumber,
                                                     ARecurringJournalTable.GetJournalNumberDBName(),
                                                     AJournalNumberToDelete);
                journalDV2.Sort = String.Format("{0} ASC", ARecurringJournalTable.GetJournalNumberDBName());

                foreach (DataRowView jrnlDRV in journalDV2)
                {
                    ARecurringJournalRow jrnlRow = (ARecurringJournalRow)jrnlDRV.Row;
                    jrnlRow.JournalNumber--;
                }
            }
            catch (Exception ex)
            {
                FMainDS.Merge(BackupDS);

                TLogging.LogException(ex, Utilities.GetMethodSignature());
                throw;
            }
        }
        private void RenumberJournals()
        {
            bool JournalsRenumbered = false;

            DataView JrnlView  = new DataView(FMainDS.ARecurringJournal);
            DataView TransView = new DataView(FMainDS.ARecurringTransaction);
            DataView AttrView  = new DataView(FMainDS.ARecurringTransAnalAttrib);

            //Reduce all trans and journal data by 1 in JournalNumber field
            //Reduce those with higher transaction number by one
            JrnlView.RowFilter = String.Format("{0}={1} AND {2}>{3}",
                                               ARecurringJournalTable.GetBatchNumberDBName(),
                                               FBatchNumber,
                                               ARecurringJournalTable.GetJournalNumberDBName(),
                                               FJournalNumberToDelete);

            JrnlView.Sort = String.Format("{0} ASC",
                                          ARecurringJournalTable.GetJournalNumberDBName());

            JournalsRenumbered = (JrnlView.Count > 0);

            // Delete the associated transaction analysis attributes
            //  if attributes do exist, and renumber those above
            foreach (DataRowView jV in JrnlView)
            {
                GLBatchTDSARecurringJournalRow jrnlRowCurrent = (GLBatchTDSARecurringJournalRow)jV.Row;

                int currentJnrlNumber = jrnlRowCurrent.JournalNumber;

                //Copy current row down to fill gap and then delete it
                GLBatchTDSARecurringJournalRow newJrnlRow = FMainDS.ARecurringJournal.NewRowTyped(true);

                newJrnlRow.ItemArray = jrnlRowCurrent.ItemArray;

                //reduce journal number by 1 in the new row
                newJrnlRow.JournalNumber--;

                FMainDS.ARecurringJournal.Rows.Add(newJrnlRow);

                //Process Transactions
                TransView.RowFilter = String.Format("{0}={1} AND {2}={3}",
                                                    ARecurringTransactionTable.GetBatchNumberDBName(),
                                                    FBatchNumber,
                                                    ARecurringTransactionTable.GetJournalNumberDBName(),
                                                    currentJnrlNumber);

                TransView.Sort = String.Format("{0} ASC, {1} ASC",
                                               ARecurringTransactionTable.GetJournalNumberDBName(),
                                               ARecurringTransactionTable.GetTransactionNumberDBName());

                //Iterate through higher number attributes and transaction numbers and reduce by one
                ARecurringTransactionRow transRowCurrent = null;

                foreach (DataRowView gv in TransView)
                {
                    transRowCurrent = (ARecurringTransactionRow)gv.Row;

                    GLBatchTDSARecurringTransactionRow newTransRow = FMainDS.ARecurringTransaction.NewRowTyped(true);

                    newTransRow.ItemArray = transRowCurrent.ItemArray;

                    //reduce journal number by 1 in the new row
                    newTransRow.JournalNumber--;

                    FMainDS.ARecurringTransaction.Rows.Add(newTransRow);

                    //Repeat process for attributes that belong to current transaction
                    AttrView.RowFilter = String.Format("{0}={1} And {2}={3} And {4}={5}",
                                                       ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                       FBatchNumber,
                                                       ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                       currentJnrlNumber,
                                                       ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                                       transRowCurrent.TransactionNumber);

                    AttrView.Sort = String.Format("{0} ASC, {1} ASC, {2} ASC",
                                                  ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                  ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                                  ARecurringTransAnalAttribTable.GetAnalysisTypeCodeDBName());

                    // Delete the associated transaction analysis attributes
                    //  if attributes do exist, and renumber those above
                    if (AttrView.Count > 0)
                    {
                        //Iterate through higher number attributes and transaction numbers and reduce by one
                        ARecurringTransAnalAttribRow attrRowCurrent = null;

                        foreach (DataRowView rV in AttrView)
                        {
                            attrRowCurrent = (ARecurringTransAnalAttribRow)rV.Row;

                            ARecurringTransAnalAttribRow newAttrRow = FMainDS.ARecurringTransAnalAttrib.NewRowTyped(true);

                            newAttrRow.ItemArray = attrRowCurrent.ItemArray;

                            //reduce journal number by 1
                            newAttrRow.JournalNumber--;

                            FMainDS.ARecurringTransAnalAttrib.Rows.Add(newAttrRow);

                            attrRowCurrent.Delete();
                        }
                    }

                    transRowCurrent.Delete();
                }

                jrnlRowCurrent.Delete();
            }

            if (JournalsRenumbered)
            {
                FPetraUtilsObject.SetChangedFlag();
            }

            //Need to refresh FPreviouslySelectedDetailRow else it points to a deleted row
            SelectRowInGrid(grdDetails.GetFirstHighlightedRowIndex());
        }
Ejemplo n.º 17
0
        private bool AllowInactiveFieldValues(int ABatchNumber)
        {
            bool RetVal = false;

            TVerificationResultCollection VerificationResult = new TVerificationResultCollection();
            string VerificationMessage = string.Empty;

            DataView TransDV  = new DataView(FMainDS.ARecurringTransaction);
            DataView AttribDV = new DataView(FMainDS.ARecurringTransAnalAttrib);

            int TotalNumInactiveValues   = 0;
            int NumInactiveAccounts      = 0;
            int NumInactiveCostCentres   = 0;
            int NumInactiveAccountTypes  = 0;
            int NumInactiveAccountValues = 0;

            try
            {
                //Check for inactive account or cost centre codes
                TransDV.RowFilter = String.Format("{0}={1}",
                                                  ARecurringTransactionTable.GetBatchNumberDBName(),
                                                  ABatchNumber);
                TransDV.Sort = String.Format("{0} ASC, {1} ASC",
                                             ARecurringTransactionTable.GetJournalNumberDBName(),
                                             ARecurringTransactionTable.GetTransactionNumberDBName());

                foreach (DataRowView drv in TransDV)
                {
                    ARecurringTransactionRow transRow = (ARecurringTransactionRow)drv.Row;

                    if (!AccountIsActive(transRow.AccountCode))
                    {
                        VerificationMessage += String.Format(" Account '{0}' in Journal:{1} Transaction:{2}.{3}",
                                                             transRow.AccountCode,
                                                             transRow.JournalNumber,
                                                             transRow.TransactionNumber,
                                                             Environment.NewLine);

                        NumInactiveAccounts++;
                    }

                    if (!CostCentreIsActive(transRow.CostCentreCode))
                    {
                        VerificationMessage += String.Format(" Cost Centre '{0}' in Journal:{1} Transaction:{2}.{3}",
                                                             transRow.CostCentreCode,
                                                             transRow.JournalNumber,
                                                             transRow.TransactionNumber,
                                                             Environment.NewLine);

                        NumInactiveCostCentres++;
                    }
                }

                //Check anlysis attributes
                AttribDV.RowFilter = String.Format("{0}={1}",
                                                   ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                   ABatchNumber);
                AttribDV.Sort = String.Format("{0} ASC, {1} ASC, {2} ASC",
                                              ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                              ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                              ARecurringTransAnalAttribTable.GetAnalysisTypeCodeDBName());

                foreach (DataRowView drv2 in AttribDV)
                {
                    ARecurringTransAnalAttribRow analAttribRow = (ARecurringTransAnalAttribRow)drv2.Row;

                    if (!AnalysisCodeIsActive(analAttribRow.AccountCode, analAttribRow.AnalysisTypeCode))
                    {
                        VerificationMessage += String.Format(" Analysis Code '{0}' in Journal:{1} Transaction:{2}.{3}",
                                                             analAttribRow.AnalysisTypeCode,
                                                             analAttribRow.JournalNumber,
                                                             analAttribRow.TransactionNumber,
                                                             Environment.NewLine);

                        NumInactiveAccountTypes++;
                    }

                    if (!AnalysisAttributeValueIsActive(analAttribRow.AnalysisTypeCode, analAttribRow.AnalysisAttributeValue))
                    {
                        VerificationMessage += String.Format(" Analysis Value '{0}' in Journal:{1} Transaction:{2}.{3}",
                                                             analAttribRow.AnalysisAttributeValue,
                                                             analAttribRow.JournalNumber,
                                                             analAttribRow.TransactionNumber,
                                                             Environment.NewLine);

                        NumInactiveAccountValues++;
                    }
                }
            }
            catch (Exception ex)
            {
                TLogging.LogException(ex, Utilities.GetMethodSignature());
                throw;
            }

            TotalNumInactiveValues = (NumInactiveAccounts + NumInactiveCostCentres + NumInactiveAccountTypes + NumInactiveAccountValues);

            if (TotalNumInactiveValues > 0)
            {
                VerificationResult.Add(new TVerificationResult(string.Format(Catalog.GetString("Inactive Values:{0}"), Environment.NewLine),
                                                               VerificationMessage,
                                                               TResultSeverity.Resv_Noncritical));

                StringBuilder errorMessages = new StringBuilder();

                errorMessages.AppendFormat(Catalog.GetString("{0} inactive value(s) found in Recurring GL Batch {1}. Do you still want to submit?{2}"),
                                           TotalNumInactiveValues,
                                           ABatchNumber,
                                           Environment.NewLine);

                foreach (TVerificationResult message in VerificationResult)
                {
                    errorMessages.AppendFormat("{0}{1}",
                                               Environment.NewLine,
                                               message.ResultText);
                }

                TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FPetraUtilsObject.GetForm());

                RetVal = (extendedMessageBox.ShowDialog(errorMessages.ToString(),
                                                        Catalog.GetString("Submit Batch"), string.Empty,
                                                        TFrmExtendedMessageBox.TButtons.embbYesNo,
                                                        TFrmExtendedMessageBox.TIcon.embiQuestion) == TFrmExtendedMessageBox.TResult.embrYes);
            }
            else
            {
                RetVal = true;
            }

            return(RetVal);
        }