/// <summary> /// this supports the batch export files from Petra 2.x. /// Each line starts with a type specifier, B for batch, J for journal, T for transaction /// The code handles importing from file or clipboard /// </summary> public void ImportBatches(TImportDataSourceEnum AImportDataSource) { bool ok = false; bool RefreshGUIAfterImport = false; OpenFileDialog dialog = null; if (FPetraUtilsObject.HasChanges) { // saving failed, therefore do not try to import MessageBox.Show(Catalog.GetString("Please save before calling this function!"), Catalog.GetString( "Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { FMyForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.IMPORTING; bool datesMayBeIntegers = TUserDefaults.GetBooleanDefault(MCommonConstants.USERDEFAULT_IMPORTEDDATESMAYBEINTEGERS, false); FdlgSeparator = new TDlgSelectCSVSeparator(false); FdlgSeparator.DateMayBeInteger = datesMayBeIntegers; if (AImportDataSource == TImportDataSourceEnum.FromClipboard) { string importString = Clipboard.GetText(TextDataFormat.UnicodeText); if ((importString == null) || (importString.Length == 0)) { MessageBox.Show(Catalog.GetString("Please first copy data from your spreadsheet application!"), Catalog.GetString("Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FdlgSeparator.CSVData = importString; } else if (AImportDataSource == TImportDataSourceEnum.FromFile) { dialog = new OpenFileDialog(); string exportPath = TClientSettings.GetExportPath(); string fullPath = TUserDefaults.GetStringDefault("Imp Filename", exportPath + Path.DirectorySeparatorChar + "import.csv"); TImportExportDialogs.SetOpenFileDialogFilePathAndName(dialog, fullPath, exportPath); dialog.Title = Catalog.GetString("Import Batches from CSV File"); dialog.Filter = Catalog.GetString("GL Batch Files (*.csv)|*.csv|Text Files (*.txt)|*.txt"); // This call fixes Windows7 Open File Dialogs. It must be the line before ShowDialog() TWin7FileOpenSaveDialog.PrepareDialog(Path.GetFileName(fullPath)); if (dialog.ShowDialog() == DialogResult.OK) { Boolean fileCanOpen = FdlgSeparator.OpenCsvFile(dialog.FileName); if (!fileCanOpen) { MessageBox.Show(Catalog.GetString("Unable to open file."), Catalog.GetString("Batch Import"), MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } } else { return; } } else { // unknown source!! return; } String impOptions = TUserDefaults.GetStringDefault("Imp Options", ";" + TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN); String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); FdlgSeparator.DateFormat = dateFormatString; FdlgSeparator.NumberFormat = (impOptions.Length > 1) ? impOptions.Substring(1) : TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN; FdlgSeparator.SelectedSeparator = StringHelper.GetCSVSeparator(FdlgSeparator.FileContent) ?? ((impOptions.Length > 0) ? impOptions.Substring(0, 1) : ";"); if (FdlgSeparator.ShowDialog() == DialogResult.OK) { Hashtable requestParams = new Hashtable(); requestParams.Add("ALedgerNumber", FLedgerNumber); requestParams.Add("Delimiter", FdlgSeparator.SelectedSeparator); requestParams.Add("DateFormatString", FdlgSeparator.DateFormat); requestParams.Add("DatesMayBeIntegers", datesMayBeIntegers); requestParams.Add("NumberFormat", FdlgSeparator.NumberFormat); requestParams.Add("NewLine", Environment.NewLine); TVerificationResultCollection AMessages = new TVerificationResultCollection(); Thread ImportThread = new Thread(() => ImportGLBatches( requestParams, FdlgSeparator.FileContent, out AMessages, out ok, out RefreshGUIAfterImport)); using (TProgressDialog ImportDialog = new TProgressDialog(ImportThread)) { ImportDialog.ShowDialog(); } if (TVerificationHelper.ResultsContainErrorCode(AMessages, PetraErrorCodes.ERR_DB_SERIALIZATION_EXCEPTION)) { TConcurrentServerTransactions.ShowTransactionSerializationExceptionDialog(); } else { ShowMessages(AMessages); } } // We save the defaults even if ok is false - because the client will probably want to try and import // the same file again after correcting any errors SaveUserDefaults(dialog); if (ok) { MessageBox.Show(Catalog.GetString("Your data was imported successfully!"), Catalog.GetString("Batch Import"), MessageBoxButtons.OK, MessageBoxIcon.Information); } if (ok) { FMyUserControl.ReloadBatches(); FMyForm.GetBatchControl().SelectRowInGrid(1); FPetraUtilsObject.SetChangedFlag(); FMyForm.SaveChangesManual(FMyForm.FCurrentGLBatchAction); } else if (RefreshGUIAfterImport) { // The import failed and the server needs us to refresh the GUI FMyUserControl.ReloadBatches(true); FMyForm.GetBatchControl().SelectRowInGrid(1); } } finally { FMyForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.NONE; } }
/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ABatchRowToCancel">The row to cancel</param> /// <returns></returns> public bool CancelBatch(ABatchRow ABatchRowToCancel) { //Assign default value(s) bool CancellationSuccessful = false; if ((ABatchRowToCancel == null)) { return(CancellationSuccessful); } int CurrentBatchNumber = ABatchRowToCancel.BatchNumber; if ((MessageBox.Show(String.Format(Catalog.GetString("You have chosen to cancel this batch ({0}).\n\nDo you really want to cancel it?"), CurrentBatchNumber), Catalog.GetString("Confirm Cancel"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)) { return(CancellationSuccessful); } //Backup the Dataset for reversion purposes GLBatchTDS BackupMainDS = (GLBatchTDS)FMainDS.Copy(); BackupMainDS.Merge(FMainDS); bool RowToDeleteIsNew = (ABatchRowToCancel.RowState == DataRowState.Added); if (!RowToDeleteIsNew) { //Remove any changes, which may cause validation issues, before cancelling FMyForm.GetBatchControl().UndoModifiedBatchRow(ABatchRowToCancel, true); if (!(FMyForm.SaveChanges())) { MessageBox.Show(Catalog.GetString("Error in trying to save prior to cancelling current Batch!"), Catalog.GetString("Cancellation Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(CancellationSuccessful); } } try { FMyForm.Cursor = Cursors.WaitCursor; //clear any transactions currently being editied in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(); //clear any journals currently being editied in the Journals Tab FMyForm.GetJournalsControl().ClearCurrentSelection(); //Clear Journals etc for current Batch FMainDS.ATransAnalAttrib.Clear(); FMainDS.ATransaction.Clear(); FMainDS.AJournal.Clear(); //Load tables afresh FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadAJournal(FLedgerNumber, CurrentBatchNumber)); FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransaction(FLedgerNumber, CurrentBatchNumber)); FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransAnalAttribForBatch(FLedgerNumber, CurrentBatchNumber)); FMainDS.AcceptChanges(); //Delete transactions and analysis attributes for (int i = FMainDS.ATransAnalAttrib.Count - 1; i >= 0; i--) { FMainDS.ATransAnalAttrib[i].Delete(); } for (int i = FMainDS.ATransaction.Count - 1; i >= 0; i--) { FMainDS.ATransaction[i].Delete(); } //Update Journal totals and status foreach (AJournalRow journal in FMainDS.AJournal.Rows) { if (journal.BatchNumber == CurrentBatchNumber) { journal.BeginEdit(); journal.JournalStatus = MFinanceConstants.BATCH_CANCELLED; journal.JournalCreditTotal = 0; journal.JournalDebitTotal = 0; journal.LastTransactionNumber = 0; journal.EndEdit(); } } // Edit the batch row ABatchRowToCancel.BeginEdit(); ABatchRowToCancel.BatchCreditTotal = 0; ABatchRowToCancel.BatchDebitTotal = 0; ABatchRowToCancel.BatchControlTotal = 0; ABatchRowToCancel.BatchStatus = MFinanceConstants.BATCH_CANCELLED; ABatchRowToCancel.EndEdit(); FPetraUtilsObject.SetChangedFlag(); //Need to call save if (FMyForm.SaveChanges()) { MessageBox.Show(Catalog.GetString("The batch has been cancelled successfully!"), Catalog.GetString("Success"), MessageBoxButtons.OK, MessageBoxIcon.Information); FMyForm.DisableTransactions(); FMyForm.DisableJournals(); } else { throw new Exception(Catalog.GetString("The batch failed to save after being cancelled! Reopen the form and retry.")); } CancellationSuccessful = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Cancellation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //Revert to previous state FMainDS.Merge(BackupMainDS); } finally { FMyForm.Cursor = Cursors.Default; } return(CancellationSuccessful); }
/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ACurrentBatchRow">The row to cancel</param> /// <param name="ABatchDescriptionTextBox">Pass a reference to a TextBox that is used to display the batch description text. This is required /// to ensure that validation passes when the cancelled batch is saved.</param> /// <returns></returns> public bool CancelBatch(ABatchRow ACurrentBatchRow, TextBox ABatchDescriptionTextBox) { if ((ACurrentBatchRow == null) || !FMyForm.SaveChanges()) { return(false); } int CurrentBatchNumber = ACurrentBatchRow.BatchNumber; if ((MessageBox.Show(String.Format(Catalog.GetString("You have chosen to cancel this batch ({0}).\n\nDo you really want to cancel it?"), CurrentBatchNumber), Catalog.GetString("Confirm Cancel"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)) { try { //clear any transactions currently being editied in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(); //clear any journals currently being editied in the Journals Tab FMyForm.GetJournalsControl().ClearCurrentSelection(); //Clear Journals etc for current Batch FMainDS.ATransAnalAttrib.Clear(); FMainDS.ATransaction.Clear(); FMainDS.AJournal.Clear(); //Load tables afresh FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadAJournal(FLedgerNumber, CurrentBatchNumber)); FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransactionForBatch(FLedgerNumber, CurrentBatchNumber)); FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransAnalAttribForBatch(FLedgerNumber, CurrentBatchNumber)); //Delete transactions for (int i = FMainDS.ATransAnalAttrib.Count - 1; i >= 0; i--) { FMainDS.ATransAnalAttrib[i].Delete(); } for (int i = FMainDS.ATransaction.Count - 1; i >= 0; i--) { FMainDS.ATransaction[i].Delete(); } //Update Journal totals and status foreach (AJournalRow journal in FMainDS.AJournal.Rows) { if (journal.BatchNumber == CurrentBatchNumber) { journal.BeginEdit(); journal.JournalStatus = MFinanceConstants.BATCH_CANCELLED; journal.JournalCreditTotal = 0; journal.JournalDebitTotal = 0; journal.EndEdit(); } } // Edit the batch row ACurrentBatchRow.BeginEdit(); //Ensure validation passes if (ACurrentBatchRow.BatchDescription.Length == 0) { ABatchDescriptionTextBox.Text = " "; } ACurrentBatchRow.BatchCreditTotal = 0; ACurrentBatchRow.BatchDebitTotal = 0; ACurrentBatchRow.BatchControlTotal = 0; ACurrentBatchRow.BatchStatus = MFinanceConstants.BATCH_CANCELLED; ACurrentBatchRow.EndEdit(); FPetraUtilsObject.SetChangedFlag(); //Need to call save if (FMyForm.SaveChanges()) { MessageBox.Show(Catalog.GetString("The batch has been cancelled successfully!"), Catalog.GetString("Success"), MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } else { // saving failed, therefore do not try to post MessageBox.Show(Catalog.GetString( "The batch has been cancelled but there were problems during saving; ") + Environment.NewLine + Catalog.GetString("Please try and save the cancellation immediately."), Catalog.GetString("Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } return(false); }
/// <summary> /// Method to cancel a specified journal /// </summary> /// <param name="AJournalRowToCancel">The row to cancel</param> /// <returns>True if the journal is cancelled.</returns> public bool CancelRow(GLBatchTDSAJournalRow AJournalRowToCancel) { bool CancellationSuccessful = false; if ((AJournalRowToCancel == null) || (AJournalRowToCancel.JournalStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(false); } int CurrentBatchNo = AJournalRowToCancel.BatchNumber; int CurrentJournalNo = AJournalRowToCancel.JournalNumber; bool CurrentJournalTransactionsLoadedAndCurrent = false; string CancelMessage = string.Empty; string CompletionMessage = string.Empty; CancelMessage = String.Format(Catalog.GetString("Are you sure you want to cancel GL Journal {0} in Batch {1}?"), CurrentJournalNo, CurrentBatchNo); if ((MessageBox.Show(CancelMessage, Catalog.GetString("Confirm Cancel"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)) { return(false); } //Backup the Dataset for reversion purposes GLBatchTDS BackupMainDS = null; try { FMyForm.Cursor = Cursors.WaitCursor; //Backup the Dataset for reversion purposes BackupMainDS = (GLBatchTDS)FMainDS.GetChangesTyped(false); //Don't run an inactive fields check on this batch FMyForm.GetBatchControl().UpdateUnpostedBatchDictionary(CurrentBatchNo); //Check if current batch details are currently loaded CurrentJournalTransactionsLoadedAndCurrent = (FMyForm.GetTransactionsControl().FBatchNumber == CurrentBatchNo); //Save and check for inactive values in other unsaved Batches FPetraUtilsObject.SetChangedFlag(); if (!FMyForm.SaveChangesManual(FMyForm.FCurrentGLBatchAction, false, !CurrentJournalTransactionsLoadedAndCurrent)) { FMyForm.GetBatchControl().UpdateUnpostedBatchDictionary(); CompletionMessage = String.Format(Catalog.GetString("Journal {0} in GL Batch {1} has not been cancelled."), CurrentJournalNo, CurrentBatchNo); MessageBox.Show(CompletionMessage, Catalog.GetString("GL Journal Cancellation"), MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } //Remove any changes, which may cause validation issues, before cancelling FMyForm.GetJournalsControl().PrepareJournalDataForCancelling(CurrentBatchNo, CurrentJournalNo, true); if (CurrentJournalTransactionsLoadedAndCurrent) { //Clear any transactions currently being edited in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(CurrentBatchNo); } //Delete transactions and attributes for current jouernal only FMyForm.GetTransactionsControl().DeleteTransactionData(CurrentBatchNo, CurrentJournalNo); //Edit current Journal decimal journalCreditTotal = AJournalRowToCancel.JournalCreditTotal; decimal journalDebitTotal = AJournalRowToCancel.JournalDebitTotal; AJournalRowToCancel.BeginEdit(); AJournalRowToCancel.JournalStatus = MFinanceConstants.BATCH_CANCELLED; AJournalRowToCancel.LastTransactionNumber = 0; AJournalRowToCancel.JournalCreditTotal = 0; AJournalRowToCancel.JournalDebitTotal = 0; AJournalRowToCancel.EndEdit(); //Edit current Batch ABatchRow CurrentBatchRow = FMyForm.GetBatchControl().GetSelectedDetailRow(); decimal batchControlTotal = CurrentBatchRow.BatchControlTotal; CurrentBatchRow.BeginEdit(); CurrentBatchRow.BatchCreditTotal -= journalCreditTotal; CurrentBatchRow.BatchDebitTotal -= journalDebitTotal; CurrentBatchRow.BatchControlTotal -= (batchControlTotal != 0 ? journalCreditTotal : 0); CurrentBatchRow.EndEdit(); FPetraUtilsObject.SetChangedFlag(); FMyForm.SaveChangesManual(); CompletionMessage = String.Format(Catalog.GetString("Journal no.: {0} cancelled successfully."), CurrentJournalNo); MessageBox.Show(CompletionMessage, Catalog.GetString("Journal Cancelled"), MessageBoxButtons.OK, MessageBoxIcon.Information); FMyForm.DisableTransactions(); CancellationSuccessful = true; } catch (Exception ex) { //Revert to previous state if (BackupMainDS != null) { FMainDS.RejectChanges(); FMainDS.Merge(BackupMainDS); FMyForm.GetJournalsControl().ShowDetailsRefresh(); } TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { FMyForm.Cursor = Cursors.Default; } return(CancellationSuccessful); }
/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ACurrentBatchRow"></param> /// <returns></returns> public bool CancelBatch(AGiftBatchRow ACurrentBatchRow) { //Assign default value(s) bool CancellationSuccessful = false; string CancelMessage = string.Empty; string CompletionMessage = string.Empty; List <string> ModifiedDetailKeys = new List <string>(); if ((ACurrentBatchRow == null) || (ACurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(CancellationSuccessful); } int CurrentBatchNo = ACurrentBatchRow.BatchNumber; CancelMessage = String.Format(Catalog.GetString("Are you sure you want to cancel gift batch number: {0}?"), ACurrentBatchRow.BatchNumber); if ((MessageBox.Show(CancelMessage, "Cancel Batch", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)) { return(CancellationSuccessful); } //Backup the Dataset for reversion purposes GiftBatchTDS BackupMainDS = (GiftBatchTDS)FMainDS.Copy(); BackupMainDS.Merge(FMainDS); try { FMyForm.Cursor = Cursors.WaitCursor; //Normally need to set the message parameters before the delete is performed if requiring any of the row values CompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} cancelled successfully."), ACurrentBatchRow.BatchNumber); FMyForm.GetBatchControl().UndoModifiedBatchRow(ACurrentBatchRow, true); //Load all journals for current Batch //clear any transactions currently being editied in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(); //Delete transactions DataView GiftDV = new DataView(FMainDS.AGift); DataView GiftDetailDV = new DataView(FMainDS.AGiftDetail); GiftDV.AllowDelete = true; GiftDetailDV.AllowDelete = true; GiftDV.RowFilter = String.Format("{0}={1}", AGiftTable.GetBatchNumberDBName(), CurrentBatchNo); GiftDV.Sort = AGiftTable.GetGiftTransactionNumberDBName() + " DESC"; GiftDetailDV.RowFilter = String.Format("{0}={1}", AGiftDetailTable.GetBatchNumberDBName(), CurrentBatchNo); GiftDetailDV.Sort = String.Format("{0} DESC, {1} DESC", AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView drv in GiftDetailDV) { AGiftDetailRow gdr = (AGiftDetailRow)drv.Row; // if the gift detail being cancelled is a reversed gift if (gdr.ModifiedDetail && !string.IsNullOrEmpty(gdr.ModifiedDetailKey)) { ModifiedDetailKeys.Add(gdr.ModifiedDetailKey); } gdr.Delete(); } for (int i = 0; i < GiftDV.Count; i++) { GiftDV.Delete(i); } //Batch is only cancelled and never deleted ACurrentBatchRow.BatchTotal = 0; ACurrentBatchRow.LastGiftNumber = 0; ACurrentBatchRow.BatchStatus = MFinanceConstants.BATCH_CANCELLED; FPetraUtilsObject.SetChangedFlag(); // save first if (FMyForm.SaveChanges()) { if (ModifiedDetailKeys.Count > 0) { TRemote.MFinance.Gift.WebConnectors.ReversedGiftReset(FLedgerNumber, ModifiedDetailKeys); } MessageBox.Show(CompletionMessage, "Batch Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { throw new Exception(Catalog.GetString("The batch failed to save after being cancelled! Reopen the form and retry.")); } CancellationSuccessful = true; } catch (Exception ex) { //Revert to previous state FMainDS.Merge(BackupMainDS); CompletionMessage = ex.Message; MessageBox.Show(CompletionMessage, "Cancellation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { FMyForm.Cursor = Cursors.Default; } return(CancellationSuccessful); }
/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ABatchRowToCancel"></param> /// <returns></returns> public bool CancelBatch(AGiftBatchRow ABatchRowToCancel) { bool CancellationSuccessful = false; if ((ABatchRowToCancel == null) || (ABatchRowToCancel.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(false); } int CurrentBatchNo = ABatchRowToCancel.BatchNumber; bool CurrentBatchTransactionsLoadedAndCurrent = false; string CancelMessage = string.Empty; string CompletionMessage = string.Empty; List <string> ModifiedDetailKeys = new List <string>(); CancelMessage = String.Format(Catalog.GetString("Are you sure you want to cancel Gift Batch {0}?"), CurrentBatchNo); if ((MessageBox.Show(CancelMessage, "Cancel Gift Batch", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)) { return(false); } //Backup the Dataset for reversion purposes GiftBatchTDS BackupMainDS = null; try { FMyForm.Cursor = Cursors.WaitCursor; //Backup the Dataset for reversion purposes BackupMainDS = (GiftBatchTDS)FMainDS.GetChangesTyped(false); //Don't run an inactive fields check on this batch FMyForm.GetBatchControl().UpdateUnpostedBatchDictionary(CurrentBatchNo); //Check if current batch gift details are currently loaded CurrentBatchTransactionsLoadedAndCurrent = (FMyForm.GetTransactionsControl().FBatchNumber == CurrentBatchNo); //Save and check for inactive values and ex-workers and anonymous gifts // in other unsaved Batches FPetraUtilsObject.SetChangedFlag(); if (!FMyForm.SaveChangesManual(TExtraGiftBatchChecks.GiftBatchAction.CANCELLING, !CurrentBatchTransactionsLoadedAndCurrent)) { FMyForm.GetBatchControl().UpdateUnpostedBatchDictionary(); CompletionMessage = String.Format(Catalog.GetString("Gift Batch {0} has not been cancelled."), CurrentBatchNo); MessageBox.Show(CompletionMessage, "Gift Batch Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } //Remove any changes to current batch that may cause validation issues FMyForm.GetBatchControl().PrepareBatchDataForCancelling(CurrentBatchNo, true); if (CurrentBatchTransactionsLoadedAndCurrent) { //Clear any transactions currently being edited in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(CurrentBatchNo); } //Delete transactions FMyForm.GetTransactionsControl().DeleteBatchGiftData(CurrentBatchNo, ref ModifiedDetailKeys); //Batch is only cancelled and never deleted ABatchRowToCancel.BeginEdit(); ABatchRowToCancel.BatchTotal = 0; ABatchRowToCancel.LastGiftNumber = 0; ABatchRowToCancel.BatchStatus = MFinanceConstants.BATCH_CANCELLED; ABatchRowToCancel.EndEdit(); if (ModifiedDetailKeys.Count > 0) { TRemote.MFinance.Gift.WebConnectors.ReversedGiftReset(FLedgerNumber, ModifiedDetailKeys); } FPetraUtilsObject.SetChangedFlag(); FMyForm.SaveChangesManual(); CompletionMessage = String.Format(Catalog.GetString("Batch no.: {0} cancelled successfully."), CurrentBatchNo); MessageBox.Show(CompletionMessage, "Gift Batch Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); FMyForm.DisableTransactions(); CancellationSuccessful = true; } catch (Exception ex) { //Revert to previous state if (BackupMainDS != null) { FMainDS.RejectChanges(); FMainDS.Merge(BackupMainDS); FMyForm.GetBatchControl().ShowDetailsRefresh(); } TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { FMyForm.Cursor = Cursors.Default; } return(CancellationSuccessful); }
/// <summary> /// Deletes the current row and optionally populates a completion message /// </summary> /// <param name="ARowToDelete">the currently selected row to delete</param> /// <param name="AFPrevRow">Is FPreviouslySelectedDetailRow</param> /// <param name="ACompletionMessage">if specified, is the deletion completion message</param> /// <returns>true if row deletion is successful</returns> public bool DeleteRowManual(ARecurringGiftBatchRow ARowToDelete, ref ARecurringGiftBatchRow AFPrevRow, ref string ACompletionMessage) { bool DeletionSuccessful = false; ACompletionMessage = string.Empty; if (ARowToDelete == null) { return(false); } int CurrentBatchNo = ARowToDelete.BatchNumber; bool CurrentBatchTransactionsLoadedAndCurrent = false; //Backup the Dataset for reversion purposes GiftBatchTDS BackupMainDS = null; try { FMyForm.Cursor = Cursors.WaitCursor; //Backup the changes to allow rollback BackupMainDS = (GiftBatchTDS)FMainDS.GetChangesTyped(false); //Don't run an inactive fields check on this batch FMyForm.GetBatchControl().UpdateRecurringBatchDictionary(CurrentBatchNo); //Check if current batch gift details are currently loaded CurrentBatchTransactionsLoadedAndCurrent = (FMyForm.GetTransactionsControl().FBatchNumber == CurrentBatchNo); //Save and check for inactive values and ex-workers and anonymous gifts // in other unsaved Batches FPetraUtilsObject.SetChangedFlag(); if (!FMyForm.SaveChangesManual(TExtraGiftBatchChecks.GiftBatchAction.DELETING, !CurrentBatchTransactionsLoadedAndCurrent)) { FMyForm.GetBatchControl().UpdateRecurringBatchDictionary(); string msg = String.Format(Catalog.GetString("Recurring Batch {0} has not been deleted."), CurrentBatchNo); MessageBox.Show(msg, "Recurring Gift Batch Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } //Remove any changes to current batch that may cause validation issues FMyForm.GetBatchControl().PrepareBatchDataForDeleting(CurrentBatchNo, true); if (CurrentBatchTransactionsLoadedAndCurrent) { //Clear any transactions currently being edited in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(CurrentBatchNo); } //Delete transactions FMyForm.GetTransactionsControl().DeleteRecurringBatchGiftData(CurrentBatchNo); // Delete the recurring batch row and save again after deleting the batch row. ARowToDelete.Delete(); ACompletionMessage = String.Format(Catalog.GetString("Recurring Gift Batch no.: {0} deleted successfully."), CurrentBatchNo); AFPrevRow = null; DeletionSuccessful = true; } catch (Exception ex) { //Revert to previous state if (BackupMainDS != null) { FMainDS.RejectChanges(); FMainDS.Merge(BackupMainDS); FMyForm.GetBatchControl().ShowDetailsRefresh(); } TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { FMyForm.Cursor = Cursors.Default; } return(DeletionSuccessful); }
/// <summary> /// Imports budgets from a file /// </summary> /// <param name="ACurrentBudgetYear"></param> /// <param name="AMainDS"></param> public void ImportBudget(int ACurrentBudgetYear, ref BudgetTDS AMainDS) { TVerificationResultCollection Messages = new TVerificationResultCollection(); int BudgetsImported = 0; int BudgetsAdded = 0; int BudgetsUpdated = 0; int BudgetsFailed = 0; if (FPetraUtilsObject.HasChanges) { // saving failed, therefore do not try to post MessageBox.Show(Catalog.GetString("Please save before trying to import!"), Catalog.GetString( "Failure"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } String DateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); OpenFileDialog OFDialog = new OpenFileDialog(); string ExportPath = TClientSettings.GetExportPath(); string FullPath = TUserDefaults.GetStringDefault("Imp Filename", ExportPath + Path.DirectorySeparatorChar + "import.csv"); TImportExportDialogs.SetOpenFileDialogFilePathAndName(OFDialog, FullPath, ExportPath); OFDialog.Title = Catalog.GetString("Import budget(s) from CSV file"); OFDialog.Filter = Catalog.GetString("Text Files(*.txt) | *.txt | Delimited Files(*.csv) | *.csv"); String ImportOptions = TUserDefaults.GetStringDefault("Imp Options", ";" + TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN); // This call fixes Windows7 Open File Dialogs. It must be the line before ShowDialog() TWin7FileOpenSaveDialog.PrepareDialog(Path.GetFileName(FullPath)); if (OFDialog.ShowDialog() == DialogResult.OK) { TFrmStatusDialog dlgStatus = new TFrmStatusDialog(FPetraUtilsObject.GetForm()); FdlgSeparator = new TDlgSelectCSVSeparator(false); try { string fileTitle = OFDialog.SafeFileName; Boolean fileCanOpen = FdlgSeparator.OpenCsvFile(OFDialog.FileName); if (!fileCanOpen) { MessageBox.Show(Catalog.GetString("Unable to open file."), Catalog.GetString("Budget Import"), MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } FdlgSeparator.DateFormat = DateFormatString; if (ImportOptions.Length > 1) { FdlgSeparator.NumberFormat = ImportOptions.Substring(1); } FdlgSeparator.SelectedSeparator = ImportOptions.Substring(0, 1); if (FdlgSeparator.ShowDialog() == DialogResult.OK) { string[] FdlgSeparatorVal = new string[] { FdlgSeparator.SelectedSeparator, FdlgSeparator.DateFormat, FdlgSeparator.NumberFormat }; Application.UseWaitCursor = true; //New set of budgets to be loaded dlgStatus.Show(); dlgStatus.Heading = Catalog.GetString("Budget Import"); dlgStatus.CurrentStatus = Catalog.GetString("Importing budgets from '" + fileTitle + "' ..."); // read contents of file string ImportString = File.ReadAllText(OFDialog.FileName); //TODO return the budget from the year, and -99 for fail BudgetsImported = TRemote.MFinance.Budget.WebConnectors.ImportBudgets(FLedgerNumber, ImportString, OFDialog.FileName, FdlgSeparatorVal, ref AMainDS, out BudgetsAdded, out BudgetsUpdated, out BudgetsFailed, out Messages); dlgStatus.Visible = false; Application.UseWaitCursor = false; ShowMessages(Messages, BudgetsImported, BudgetsAdded, BudgetsUpdated, BudgetsFailed); } // We save the defaults even if ok is false - because the client will probably want to try and import // the same file again after correcting any errors SaveUserDefaults(OFDialog, ImportOptions); } catch (Exception ex) { TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { Application.UseWaitCursor = false; } // update grid if ((BudgetsAdded + BudgetsUpdated) > 0) { try { dlgStatus.CurrentStatus = Catalog.GetString("Updating budget period data..."); dlgStatus.Visible = true; Application.UseWaitCursor = true; UpdateABudgetPeriodAmounts(AMainDS, ACurrentBudgetYear); FUserControl.SetBudgetDefaultView(AMainDS); } finally { Application.UseWaitCursor = false; dlgStatus.Close(); } FPetraUtilsObject.SetChangedFlag(); } else { dlgStatus.Close(); } } }
/// <summary> /// Imports budgets from a file /// </summary> /// <param name="ASelectedBudgetYear"></param> /// <param name="AMainDS"></param> public void ImportBudget(int ASelectedBudgetYear, ref BudgetTDS AMainDS) { TVerificationResultCollection Messages = new TVerificationResultCollection(); int NumBudgetsToImport = 0; int NumRecsUpdated = 0; int NumRowsFailed = 0; if (FPetraUtilsObject.HasChanges) { // saving failed, therefore do not try to post MessageBox.Show(Catalog.GetString("Please save before trying to import!"), Catalog.GetString( "Failure"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } String DateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); OpenFileDialog OFDialog = new OpenFileDialog(); string ExportPath = TClientSettings.GetExportPath(); string FullPath = TUserDefaults.GetStringDefault("Imp Filename", ExportPath + Path.DirectorySeparatorChar + "import.csv"); TImportExportDialogs.SetOpenFileDialogFilePathAndName(OFDialog, FullPath, ExportPath); OFDialog.Title = Catalog.GetString("Import budget(s) from csv file"); OFDialog.Filter = Catalog.GetString("Budget files (*.csv)|*.csv"); String ImportOptions = TUserDefaults.GetStringDefault("Imp Options", ";" + TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN); // This call fixes Windows7 Open File Dialogs. It must be the line before ShowDialog() TWin7FileOpenSaveDialog.PrepareDialog(Path.GetFileName(FullPath)); if (OFDialog.ShowDialog() == DialogResult.OK) { FdlgSeparator = new TDlgSelectCSVSeparator(false); try { FParentForm.UseWaitCursor = true; Boolean fileCanOpen = FdlgSeparator.OpenCsvFile(OFDialog.FileName); if (!fileCanOpen) { throw new Exception(String.Format(Catalog.GetString("File {0} cannot be opened."), OFDialog.FileName)); } FdlgSeparator.DateFormat = DateFormatString; if (ImportOptions.Length > 1) { FdlgSeparator.NumberFormat = ImportOptions.Substring(1); } FdlgSeparator.SelectedSeparator = ImportOptions.Substring(0, 1); if (FdlgSeparator.ShowDialog() == DialogResult.OK) { string[] FdlgSeparatorVal = new string[] { FdlgSeparator.SelectedSeparator, FdlgSeparator.DateFormat, FdlgSeparator.NumberFormat }; // read contents of file string ImportString = File.ReadAllText(OFDialog.FileName); //TODO return the budget from the year, and -99 for fail NumBudgetsToImport = TRemote.MFinance.Budget.WebConnectors.ImportBudgets(FLedgerNumber, ASelectedBudgetYear, ImportString, OFDialog.FileName, FdlgSeparatorVal, ref AMainDS, out NumRecsUpdated, out NumRowsFailed, out Messages); ShowMessages(Messages, NumBudgetsToImport, NumRecsUpdated, NumRowsFailed); } } catch (Exception ex) { NumBudgetsToImport = -1; MessageBox.Show(ex.Message, Catalog.GetString("Budget Import"), MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { // We save the defaults even if ok is false - because the client will probably want to try and import // the same file again after correcting any errors SaveUserDefaults(OFDialog, ImportOptions); FParentForm.UseWaitCursor = false; } // update grid if (NumBudgetsToImport > 0) { FParentForm.UseWaitCursor = true; UpdateABudgetPeriodAmounts(AMainDS, ASelectedBudgetYear); FUserControl.SetBudgetDefaultView(); FParentForm.UseWaitCursor = false; FUserControl.SelectRowInGrid(1); FPetraUtilsObject.SetChangedFlag(); } else if (NumBudgetsToImport <= 0) { FUserControl.SelectRowInGrid(1); } } }
/// <summary> /// Method to cancel a specified journal /// </summary> /// <param name="ACurrentJournalRow">The row to cancel</param> /// <param name="AJournalDescriptionTextBox">Pass a reference to a TextBox that is used to display the journal description text. This is required /// to ensure that validation passes when the cancelled journal is saved.</param> /// <param name="AExchangeRateToBaseTextBox">Pass a reference to a TextBox that is used to display the exchange rate to base. This is required /// to ensure that validation passes when the cancelled journal is saved.</param> /// <returns>True if the journal is cancelled.</returns> public bool CancelRow(GLBatchTDSAJournalRow ACurrentJournalRow, TextBox AJournalDescriptionTextBox, TTxtNumericTextBox AExchangeRateToBaseTextBox) { if ((ACurrentJournalRow == null) || !FMyForm.SaveChanges()) { return(false); } int CurrentBatchNumber = ACurrentJournalRow.BatchNumber; int CurrentJournalNumber = ACurrentJournalRow.JournalNumber; if ((MessageBox.Show(String.Format(Catalog.GetString( "You have chosen to cancel this journal ({0}).\n\nDo you really want to cancel it?"), CurrentJournalNumber), Catalog.GetString("Confirm Cancel"), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)) { try { //clear any transactions currently being editied in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(); //Load any new data FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransactionATransAnalAttrib(FLedgerNumber, CurrentBatchNumber, CurrentJournalNumber)); DataView dvAA = new DataView(FMainDS.ATransAnalAttrib); dvAA.RowFilter = String.Format("{0}={1} AND {2}={3}", ATransAnalAttribTable.GetBatchNumberDBName(), CurrentBatchNumber, ATransAnalAttribTable.GetJournalNumberDBName(), CurrentJournalNumber); //Delete Analysis Attribs foreach (DataRowView dvr in dvAA) { dvr.Delete(); } DataView dvTr = new DataView(FMainDS.ATransaction); dvTr.RowFilter = String.Format("{0}={1} AND {2}={3}", ATransactionTable.GetBatchNumberDBName(), CurrentBatchNumber, ATransactionTable.GetJournalNumberDBName(), CurrentJournalNumber); //Delete Transactions foreach (DataRowView dvr in dvTr) { dvr.Delete(); } ACurrentJournalRow.BeginEdit(); ACurrentJournalRow.JournalStatus = MFinanceConstants.BATCH_CANCELLED; //Ensure validation passes if (ACurrentJournalRow.JournalDescription.Length == 0) { AJournalDescriptionTextBox.Text = " "; } if (ACurrentJournalRow.ExchangeRateToBase == 0) { AExchangeRateToBaseTextBox.NumberValueDecimal = 1; } ABatchRow CurrentBatchRow = FMyForm.GetBatchControl().GetSelectedDetailRow(); CurrentBatchRow.BatchCreditTotal -= ACurrentJournalRow.JournalCreditTotal; CurrentBatchRow.BatchDebitTotal -= ACurrentJournalRow.JournalDebitTotal; if (CurrentBatchRow.BatchControlTotal != 0) { CurrentBatchRow.BatchControlTotal -= ACurrentJournalRow.JournalCreditTotal; } ACurrentJournalRow.JournalCreditTotal = 0; ACurrentJournalRow.JournalDebitTotal = 0; ACurrentJournalRow.EndEdit(); FPetraUtilsObject.SetChangedFlag(); //Need to call save if (FMyForm.SaveChanges()) { MessageBox.Show(Catalog.GetString("The journal has been cancelled successfully!"), Catalog.GetString("Success"), MessageBoxButtons.OK, MessageBoxIcon.Information); FMyForm.DisableTransactions(); } else { // saving failed, therefore do not try to post MessageBox.Show(Catalog.GetString( "The journal has been cancelled but there were problems during saving; ") + Environment.NewLine + Catalog.GetString("Please try and save the cancellation immediately."), Catalog.GetString("Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error); } return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); } } return(false); }
/// <summary> /// this supports the batch export files from Petra 2.x. /// Each line starts with a type specifier, B for batch, J for journal, T for transaction /// </summary> public void ImportBatches(TGiftImportDataSourceEnum AImportSource, GiftBatchTDS AMainDS) { bool ImportOK = false; bool RefreshGUIAfterImport = false; OpenFileDialog OFileDialog = null; if (FPetraUtilsObject.HasChanges) { // saving failed, therefore do not try to import MessageBox.Show(Catalog.GetString("Please save before calling this function!"), Catalog.GetString( "Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ALedgerRow LedgerRow = (ALedgerRow)AMainDS.ALedger.Rows[0]; int CurrentTopBatchNumber = LedgerRow.LastGiftBatchNumber; try { FMyForm.FCurrentGiftBatchAction = Logic.TExtraGiftBatchChecks.GiftBatchAction.IMPORTING; bool datesMayBeIntegers = TUserDefaults.GetBooleanDefault(MCommonConstants.USERDEFAULT_IMPORTEDDATESMAYBEINTEGERS, false); FdlgSeparator = new TDlgSelectCSVSeparator(false); FdlgSeparator.DateMayBeInteger = datesMayBeIntegers; if (AImportSource == TGiftImportDataSourceEnum.FromClipboard) { string ImportString = Clipboard.GetText(TextDataFormat.UnicodeText); if ((ImportString == null) || (ImportString.Length == 0)) { MessageBox.Show(Catalog.GetString("Please first copy data from your spreadsheet application!"), Catalog.GetString("Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FdlgSeparator.CSVData = ImportString; } else if (AImportSource == TGiftImportDataSourceEnum.FromFile) { OFileDialog = new OpenFileDialog(); string exportPath = TClientSettings.GetExportPath(); string fullPath = TUserDefaults.GetStringDefault("Imp Filename", exportPath + Path.DirectorySeparatorChar + "import.csv"); TImportExportDialogs.SetOpenFileDialogFilePathAndName(OFileDialog, fullPath, exportPath); OFileDialog.Title = Catalog.GetString("Import Batches from CSV File"); OFileDialog.Filter = Catalog.GetString("Gift Batch Files(*.csv)|*.csv|Text Files(*.txt)|*.txt"); // This call fixes Windows7 Open File Dialogs. It must be the line before ShowDialog() TWin7FileOpenSaveDialog.PrepareDialog(Path.GetFileName(fullPath)); if (OFileDialog.ShowDialog() == DialogResult.OK) { Boolean fileCanOpen = FdlgSeparator.OpenCsvFile(OFileDialog.FileName); if (!fileCanOpen) { MessageBox.Show(Catalog.GetString("Unable to open file."), Catalog.GetString("Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } } else { return; } } else { // unknown source!! return; } String impOptions = TUserDefaults.GetStringDefault("Imp Options", ";" + TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN); String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); FdlgSeparator.DateFormat = dateFormatString; FdlgSeparator.NumberFormat = (impOptions.Length > 1) ? impOptions.Substring(1) : TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN; FdlgSeparator.SelectedSeparator = StringHelper.GetCSVSeparator(FdlgSeparator.FileContent) ?? ((impOptions.Length > 0) ? impOptions.Substring(0, 1) : ";"); if (FdlgSeparator.ShowDialog() == DialogResult.OK) { Hashtable requestParams = new Hashtable(); requestParams.Add("ALedgerNumber", FLedgerNumber); requestParams.Add("Delimiter", FdlgSeparator.SelectedSeparator); requestParams.Add("DateFormatString", FdlgSeparator.DateFormat); requestParams.Add("DatesMayBeIntegers", datesMayBeIntegers); requestParams.Add("NumberFormat", FdlgSeparator.NumberFormat); requestParams.Add("NewLine", Environment.NewLine); bool Repeat = true; while (Repeat) { Repeat = false; TVerificationResultCollection AMessages = new TVerificationResultCollection(); GiftBatchTDSAGiftDetailTable NeedRecipientLedgerNumber = new GiftBatchTDSAGiftDetailTable(); Thread ImportThread = new Thread(() => ImportGiftBatches( requestParams, FdlgSeparator.FileContent, out AMessages, out ImportOK, out RefreshGUIAfterImport, out NeedRecipientLedgerNumber)); using (TProgressDialog ImportDialog = new TProgressDialog(ImportThread)) { ImportDialog.ShowDialog(); } // If NeedRecipientLedgerNumber contains data then AMessages will only ever contain // one message alerting the user that no data has been imported. // We do not want to show this as we will be displaying another more detailed message. if (NeedRecipientLedgerNumber.Rows.Count == 0) { if (TVerificationHelper.ResultsContainErrorCode(AMessages, PetraErrorCodes.ERR_DB_SERIALIZATION_EXCEPTION)) { TConcurrentServerTransactions.ShowTransactionSerializationExceptionDialog(); } else { ShowMessages(AMessages); } } // if the import contains gifts with Motivation Group 'GIFT' and that have a Family recipient with no Gift Destination // then the import will have failed and we need to alert the user if (NeedRecipientLedgerNumber.Rows.Count > 0) { bool OfferToRunImportAgain = true; bool DoNotShowMessageBoxEverytime = false; TFrmExtendedMessageBox.TResult Result = TFrmExtendedMessageBox.TResult.embrUndefined; int count = 1; // for each gift in which the recipient needs a Git Destination foreach (GiftBatchTDSAGiftDetailRow Row in NeedRecipientLedgerNumber.Rows) { if (!DoNotShowMessageBoxEverytime) { string CheckboxText = string.Empty; // only show checkbox if there is at least one more occurrence of this error if (NeedRecipientLedgerNumber.Rows.Count - count > 0) { CheckboxText = string.Format( Catalog.GetString( "Do this for all further occurrences ({0})?"), NeedRecipientLedgerNumber.Rows.Count - count); } TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FPetraUtilsObject.GetForm()); extendedMessageBox.ShowDialog(string.Format( Catalog.GetString( "Gift Import has been cancelled as the recipient '{0}' ({1}) has no Gift Destination assigned."), Row.RecipientDescription, Row.RecipientKey) + "\n\r\n\r\n\r" + Catalog.GetString("Do you want to assign a Gift Destination to this partner now?"), Catalog.GetString("Import Errors"), CheckboxText, TFrmExtendedMessageBox.TButtons.embbYesNo, TFrmExtendedMessageBox.TIcon.embiWarning); Result = extendedMessageBox.GetResult(out DoNotShowMessageBoxEverytime); } if (Result == TFrmExtendedMessageBox.TResult.embrYes) { // allow the user to assign a Gift Destingation TFrmGiftDestination GiftDestinationForm = new TFrmGiftDestination(FPetraUtilsObject.GetForm(), Row.RecipientKey); GiftDestinationForm.ShowDialog(); } else { OfferToRunImportAgain = false; if (DoNotShowMessageBoxEverytime) { break; } } count++; } // if the user has clicked yes to assigning Gift Destinations then offer to restart the import if (OfferToRunImportAgain && (MessageBox.Show(Catalog.GetString("Would you like to import this Gift Batch again?"), Catalog.GetString("Gift Import"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)) { Repeat = true; } } } } // We save the defaults even if ok is false - because the client will probably want to try and import // the same file again after correcting any errors SaveUserDefaults(OFileDialog); if (ImportOK) { MessageBox.Show(Catalog.GetString("Your data was imported successfully!"), Catalog.GetString("Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Information); } if (ImportOK) { FMyUserControl.LoadBatchesForCurrentYear(); FMyForm.GetBatchControl().SelectRowInBatchGrid(1); DataView allNewBatches = new DataView(AMainDS.AGiftBatch); allNewBatches.RowFilter = String.Format("{0} > {1}", AGiftBatchTable.GetBatchNumberDBName(), CurrentTopBatchNumber); foreach (DataRowView drv in allNewBatches) { drv.Row.SetModified(); } FPetraUtilsObject.SetChangedFlag(); //Force initial inactive values check FMyForm.SaveChangesManual(FMyForm.FCurrentGiftBatchAction); } else if (RefreshGUIAfterImport) { FMyUserControl.LoadBatchesForCurrentYear(); FMyForm.GetBatchControl().SelectRowInBatchGrid(1); } } finally { FMyForm.FCurrentGiftBatchAction = Logic.TExtraGiftBatchChecks.GiftBatchAction.NONE; } }