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()); }
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; } }