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()); }
/// <summary> /// make sure the correct transaction number is assigned and the journal.lastTransactionNumber is updated; /// will use the currently selected journal /// </summary> public void NewRowManual(ref GLBatchTDSARecurringTransactionRow ANewRow) { NewRowManual(ref ANewRow, null); }
/// <summary> /// make sure the correct transaction number is assigned and the journal.lastTransactionNumber is updated /// </summary> /// <param name="ANewRow">returns the modified new transaction row</param> /// <param name="ARefJournalRow">this can be null; otherwise this is the journal that the transaction should belong to</param> public void NewRowManual(ref GLBatchTDSARecurringTransactionRow ANewRow, ARecurringJournalRow ARefJournalRow) { if (ARefJournalRow == null) { ARefJournalRow = FJournalRow; } ANewRow.LedgerNumber = ARefJournalRow.LedgerNumber; ANewRow.BatchNumber = ARefJournalRow.BatchNumber; ANewRow.JournalNumber = ARefJournalRow.JournalNumber; ANewRow.TransactionNumber = ++ARefJournalRow.LastTransactionNumber; ANewRow.TransactionDate = FBatchRow.DateEffective; ANewRow.ExchangeRateToBase = FJournalRow.ExchangeRateToBase; if (FPreviouslySelectedDetailRow != null) { ANewRow.CostCentreCode = FPreviouslySelectedDetailRow.CostCentreCode; ANewRow.Narrative = FPreviouslySelectedDetailRow.Narrative; ANewRow.Reference = FPreviouslySelectedDetailRow.Reference; } }
/// <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(GLBatchTDSARecurringTransactionRow ARowToDelete, ref string ACompletionMessage) { //Assign default value(s) bool DeletionSuccessful = false; ACompletionMessage = string.Empty; if (ARowToDelete == null) { return DeletionSuccessful; } bool RowToDeleteIsNew = (ARowToDelete.RowState == DataRowState.Added); if (!RowToDeleteIsNew) { //Reject any changes which may fail validation ARowToDelete.RejectChanges(); ShowDetails(ARowToDelete); if (!((TFrmRecurringGLBatch) this.ParentForm).SaveChanges()) { MessageBox.Show(Catalog.GetString("Error in trying to save prior to deleting current recurring transaction!"), Catalog.GetString("Deletion Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return DeletionSuccessful; } } //Backup the Dataset for reversion purposes GLBatchTDS BackupMainDS = (GLBatchTDS)FMainDS.Copy(); BackupMainDS.Merge(FMainDS); //Pass copy to delete method. GLBatchTDS TempDS = (GLBatchTDS)FMainDS.Copy(); TempDS.Merge(FMainDS); int TransactionNumberToDelete = ARowToDelete.TransactionNumber; int TopMostTransNo = FJournalRow.LastTransactionNumber; try { this.Cursor = Cursors.WaitCursor; if (RowToDeleteIsNew) { ProcessNewlyAddedTransactionRowForDeletion(TransactionNumberToDelete); } else { TempDS.AcceptChanges(); //Clear the transactions and load newly saved dataset FMainDS.ARecurringTransAnalAttrib.Clear(); FMainDS.ARecurringTransaction.Clear(); FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.ProcessRecurringTransAndAttributesForDeletion(TempDS, FLedgerNumber, FBatchNumber, FJournalNumber, TopMostTransNo, TransactionNumberToDelete)); } FPreviouslySelectedDetailRow = null; FPetraUtilsObject.SetChangedFlag(); ACompletionMessage = String.Format(Catalog.GetString("Transaction no.: {0} deleted successfully."), TransactionNumberToDelete); DeletionSuccessful = true; } catch (Exception ex) { ACompletionMessage = ex.Message; MessageBox.Show(ex.Message, Catalog.GetString("Deletion Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); //Revert to previous state FMainDS.Merge(BackupMainDS); } finally { SetTransactionDefaultView(); FFilterAndFindObject.ApplyFilter(); this.Cursor = Cursors.Default; } return DeletionSuccessful; }