private void LoadUserDefaults() { // This is for compatibility with old Petra txtFilename.Text = TUserDefaults.GetStringDefault("Imp Filename", TClientSettings.GetExportPath() + Path.DirectorySeparatorChar + "export.csv"); String expOptions = TUserDefaults.GetStringDefault("Exp Options", "DTrans"); // This is for compatibility with old Petra if (expOptions.StartsWith("D")) { rbtDetail.Select(); } else { rbtSummary.Select(); } if (expOptions.EndsWith("Trans")) { rbtOriginalTransactionCurrency.Select(); } else { rbtBaseCurrency.Select(); } String impOptions = TUserDefaults.GetStringDefault("Imp Options", ";American"); if (impOptions.Length > 0) { cmbDelimiter.SelectedItem = ConvertDelimiter(impOptions.Substring(0, 1), true); } if (impOptions.Length > 1) { cmbNumberFormat.SelectedIndex = impOptions.Substring(1) == "American" ? 0 : 1; } string DateFormatDefault = TUserDefaults.GetStringDefault("Imp Date", "yyyy-MM-dd"); // mdy and dmy have been the old default settings in Petra 2.x if (DateFormatDefault.ToLower() == "mdy") { DateFormatDefault = "MM/dd/yyyy"; } if (DateFormatDefault.ToLower() == "dmy") { DateFormatDefault = "dd/MM/yyyy"; } cmbDateFormat.SetSelectedString(DateFormatDefault); }
private void LoadUserDefaults() { // This is for compatibility with old Petra txtFilename.Text = TUserDefaults.GetStringDefault("Imp Filename", TClientSettings.GetExportPath() + Path.DirectorySeparatorChar + "export.csv"); String expOptions = TUserDefaults.GetStringDefault("Exp Options", "DTrans"); // This is for compatibility with old Petra if (expOptions.StartsWith("D")) { rbtDetail.Select(); } else { rbtSummary.Select(); } if (expOptions.EndsWith("Trans")) { rbtOriginalTransactionCurrency.Select(); } else { rbtBaseCurrency.Select(); } CultureInfo myCulture = Thread.CurrentThread.CurrentCulture; string defaultImpOptions = myCulture.TextInfo.ListSeparator + "European"; if (myCulture.EnglishName.EndsWith("-US")) { defaultImpOptions = myCulture.TextInfo.ListSeparator + "American"; } String impOptions = TUserDefaults.GetStringDefault("Imp Options", defaultImpOptions); if (impOptions.Length > 0) { cmbDelimiter.SetSelectedString(ConvertDelimiter(impOptions.Substring(0, 1), true)); } if (impOptions.Length > 1) { cmbNumberFormat.SelectedIndex = impOptions.Substring(1) == "American" ? 0 : 1; } cmbDateFormat.SetSelectedString(TUserDefaults.GetStringDefault("Imp Date", myCulture.EnglishName.EndsWith("-US") ? "MDY" : "DMY")); }
private void Form_Load(Object sender, EventArgs e) { if (FWhatToOpen.Equals("Server.log")) { //the client doen't know the serverlog file - unless in standalone use and development environment //-> check if there is a Server.log in the same location where the client log is and then display it FLogFileLocation = TClientSettings.GetPathLog() + Path.DirectorySeparatorChar + "Server.log"; Clipboard.SetDataObject(FLogFileLocation); try { StreamReader TLogFileReader = new StreamReader(FLogFileLocation); FLogFileContent = TLogFileReader.ReadToEnd(); TLogFileReader.Close(); txtLogFileContent.AppendText(Catalog.GetString( "The Server log file:") + "\r\n " + FLogFileLocation + "\r\n\r\n" + FLogFileContent); } catch (Exception) { txtLogFileContent.AppendText(Catalog.GetString( "Problem on opening logfile. The server log can (at the moment) only be displayed in this window if you are using the standalone version or the development environment.")); } } else if (FWhatToOpen.Equals("PetraClient.log")) { FLogFileLocation = TClientSettings.GetPathLog() + Path.DirectorySeparatorChar + "PetraClient.log"; try { StreamReader TLogFileReader = new StreamReader(FLogFileLocation); FLogFileContent = TLogFileReader.ReadToEnd(); TLogFileReader.Close(); txtLogFileContent.AppendText(Catalog.GetString( "The Client log file:") + "\r\n " + FLogFileLocation + "\r\n\r\n" + FLogFileContent); } catch (Exception) { txtLogFileContent.AppendText(Catalog.GetString("Problem on opening logfile")); } } else { txtLogFileContent.AppendText( String.Format(Catalog.GetString("An error ocurred. The logfile you are looking for \r\n({0})\r\nis not available!"), FWhatToOpen)); } }
private void LoadUserDefaults() { // This is for compatibility with old Petra txtFilename.Text = TUserDefaults.GetStringDefault("Exp Filename", TClientSettings.GetExportPath() + Path.DirectorySeparatorChar + "BudgetExport.csv"); CultureInfo myCulture = Thread.CurrentThread.CurrentCulture; string defaultImpOptions = myCulture.TextInfo.ListSeparator + TDlgSelectCSVSeparator.NUMBERFORMAT_EUROPEAN; if (myCulture.EnglishName.EndsWith("-US")) { defaultImpOptions = myCulture.TextInfo.ListSeparator + TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN; } String impOptions = TUserDefaults.GetStringDefault("Imp Options", defaultImpOptions); if (impOptions.Length > 0) { cmbDelimiter.SetSelectedString(ConvertDelimiter(impOptions.Substring(0, 1), true)); } if (impOptions.Length > 1) { cmbNumberFormat.SelectedIndex = impOptions.Substring(1) == TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN ? 0 : 1; } string DateFormat = TUserDefaults.GetStringDefault("Imp Date", "yyyy-MM-dd"); // mdy and dmy have been the old default settings in Petra 2.x if (DateFormat.ToLower() == "mdy") { DateFormat = "MM/dd/yyyy"; } if (DateFormat.ToLower() == "dmy") { DateFormat = "dd/MM/yyyy"; } cmbDateFormat.SetSelectedString(DateFormat); }
private void LoadUserDefaults() { // This is for compatibility with old Petra txtFilename.Text = TUserDefaults.GetStringDefault("Exp Filename", TClientSettings.GetExportPath() + Path.DirectorySeparatorChar + "BudgetExport.csv"); //String expOptions = TUserDefaults.GetStringDefault("Exp Options", "DTrans"); String expOptions = TUserDefaults.GetStringDefault("Exp Options", ";American"); if (expOptions.Length > 0) { cmbDelimiter.SetSelectedString(ConvertDelimiter(expOptions.Substring(0, 1), true)); } if (expOptions.Length > 1) { cmbNumberFormat.SelectedIndex = expOptions.Substring(1) == "American" ? 0 : 1; } cmbDateFormat.SetSelectedString(TUserDefaults.GetStringDefault("Exp Date", "DMY")); }
/// <summary> /// Import a transactions file or a clipboard equivalent /// </summary> /// <param name="ACurrentBatchRow">The batch to import to</param> /// <param name="AImportSource">The import source - eg File or Clipboard</param> /// <returns>True if the import was successful</returns> public bool ImportTransactions(AGiftBatchRow ACurrentBatchRow, TGiftImportDataSourceEnum AImportSource) { bool ok = false; String importString; String impOptions; OpenFileDialog dialog = null; Boolean IsPlainText = false; if (FPetraUtilsObject.HasChanges) { // saving failed, therefore do not try to import MessageBox.Show(Catalog.GetString("Please save before calling this function!"), Catalog.GetString( "Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if ((ACurrentBatchRow == null) || (ACurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { MessageBox.Show(Catalog.GetString("Please select an unposted batch to import transactions."), Catalog.GetString( "Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (ACurrentBatchRow.LastGiftNumber > 0) { if (MessageBox.Show(Catalog.GetString( "The current batch already contains some gift transactions. Do you really want to add more transactions to this batch?"), Catalog.GetString("Gift Transaction Import"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) { return(false); } } FdlgSeparator = new TDlgSelectCSVSeparator(false); if (AImportSource == TGiftImportDataSourceEnum.FromClipboard) { 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(false); } impOptions = TUserDefaults.GetStringDefault("Imp Options", ";American"); String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); FdlgSeparator = new TDlgSelectCSVSeparator(false); FdlgSeparator.SelectedSeparator = "\t"; FdlgSeparator.CSVData = importString; FdlgSeparator.DateFormat = dateFormatString; if (impOptions.Length > 1) { FdlgSeparator.NumberFormat = impOptions.Substring(1); } } else if (AImportSource == TGiftImportDataSourceEnum.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 Transactions from CSV File"); dialog.Filter = Catalog.GetString("Gift Transactions files (*.csv)|*.csv|Text Files (*.txt)|*.txt"); impOptions = 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 (dialog.ShowDialog() == DialogResult.OK) { Boolean fileCanOpen = FdlgSeparator.OpenCsvFile(dialog.FileName); if (!fileCanOpen) { MessageBox.Show(Catalog.GetString("Unable to open file."), Catalog.GetString("Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } importString = File.ReadAllText(dialog.FileName, Encoding.Default); IsPlainText = (Path.GetExtension(dialog.FileName).ToLower() == ".txt"); String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); FdlgSeparator.DateFormat = dateFormatString; if (impOptions.Length > 1) { FdlgSeparator.NumberFormat = impOptions.Substring(1); } FdlgSeparator.SelectedSeparator = impOptions.Substring(0, 1); } else { return(false); } } else { // unknown source!! The following need a value... impOptions = String.Empty; importString = String.Empty; } if (IsPlainText || (FdlgSeparator.ShowDialog() == DialogResult.OK)) { Hashtable requestParams = new Hashtable(); requestParams.Add("ALedgerNumber", FLedgerNumber); requestParams.Add("Delimiter", FdlgSeparator.SelectedSeparator); requestParams.Add("DateFormatString", FdlgSeparator.DateFormat); 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(() => ImportGiftTransactions( requestParams, importString, ACurrentBatchRow.BatchNumber, out AMessages, out ok, out NeedRecipientLedgerNumber)); using (TProgressDialog ImportDialog = new TProgressDialog(ImportThread)) { ImportDialog.ShowDialog(); } 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; // for each gift in which the recipient needs a Git Destination foreach (GiftBatchTDSAGiftDetailRow Row in NeedRecipientLedgerNumber.Rows) { if (MessageBox.Show(string.Format( Catalog.GetString( "Gift Import has been cancelled as the recipient '{0}' ({1}) has no Gift Destination assigned."), Row.RecipientDescription, Row.RecipientKey) + "\n\n" + Catalog.GetString("Do you want to assign a Gift Destination to this partner now?"), Catalog.GetString("Gift Import"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { // allow the user to assign a Gift Destingation TFrmGiftDestination GiftDestinationForm = new TFrmGiftDestination(FPetraUtilsObject.GetForm(), Row.RecipientKey); GiftDestinationForm.ShowDialog(); } else { OfferToRunImportAgain = false; } } // 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 these Gift Transactions again?"), Catalog.GetString("Gift Import"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == 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(dialog, impOptions); } if (ok) { MessageBox.Show(Catalog.GetString("Your data was imported successfully!"), Catalog.GetString("Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Information); //FMyUserControl.LoadBatchesForCurrentYear(); FPetraUtilsObject.DisableSaveButton(); } return(ok); }
/// <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> /// this supports the transaction export files from Petra 2.x. /// Lines do NOT start with T for transaction /// </summary> public void ImportTransactions(ABatchRow ACurrentBatchRow, AJournalRow ACurrentJournalRow, TImportDataSourceEnum AImportDataSource) { bool ok = false; bool RefreshGUIAfterImport = false; OpenFileDialog dialog = null; if (FPetraUtilsObject.HasChanges && !FMyForm.SaveChanges()) { // saving failed, therefore do not try to import MessageBox.Show(Catalog.GetString("Please save your changes before Importing new transactions"), Catalog.GetString( "Import GL Transactions"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if ((ACurrentBatchRow == null) || (ACurrentJournalRow == null) || (ACurrentJournalRow.JournalStatus != MFinanceConstants.BATCH_UNPOSTED)) { MessageBox.Show(Catalog.GetString("Please select an unposted journal to import transactions."), Catalog.GetString("Import GL Transactions")); return; } if (ACurrentJournalRow.LastTransactionNumber > 0) { if (MessageBox.Show(Catalog.GetString( "The current journal already contains some transactions. Do you really want to add more transactions to this journal?"), Catalog.GetString("Import GL Transactions"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) { return; } } 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 Transactions from CSV File"); dialog.Filter = Catalog.GetString("GL Transactions 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("Transaction 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); requestParams.Add("LastTransactionNumber", ACurrentJournalRow.LastTransactionNumber); TVerificationResultCollection AMessages = new TVerificationResultCollection(); Thread ImportThread = new Thread(() => ImportGLTransactions(requestParams, FdlgSeparator.FileContent, ACurrentBatchRow.BatchNumber, ACurrentJournalRow.JournalNumber, out AMessages, out ok, out RefreshGUIAfterImport)); using (TProgressDialog ImportDialog = new TProgressDialog(ImportThread)) { ImportDialog.ShowDialog(); } ShowMessages(AMessages); } // It is important to save user defaults here, even if there were errors // because in that case the user will want to import the same file again after fixing it. SaveUserDefaults(dialog); if (ok || RefreshGUIAfterImport) { if (ok) { MessageBox.Show(Catalog.GetString("Your data was imported successfully!"), Catalog.GetString("Transactions Import"), MessageBoxButtons.OK, MessageBoxIcon.Information); } // Update the client side with new information from the server FMyForm.Cursor = Cursors.WaitCursor; FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadABatchAJournal(FLedgerNumber, ACurrentBatchRow.BatchNumber)); FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransactionAndRelatedTablesForJournal(FLedgerNumber, ACurrentBatchRow.BatchNumber, ACurrentJournalRow.JournalNumber)); FMainDS.AcceptChanges(); FMyForm.Cursor = Cursors.Default; FMyForm.GetTransactionsControl().SelectRow(1); } }
/// <summary> /// Import a transactions file or a clipboard equivalent /// </summary> /// <param name="ACurrentBatchRow">The batch to import to</param> /// <param name="AImportSource">The import source - eg File or Clipboard</param> /// <returns>True if the import was successful</returns> public bool ImportTransactions(AGiftBatchRow ACurrentBatchRow, TGiftImportDataSourceEnum AImportSource) { bool ok = false; bool RefreshGUIAfterImport = false; OpenFileDialog dialog = null; Boolean IsPlainText = false; if (FPetraUtilsObject.HasChanges) { // saving failed, therefore do not try to import MessageBox.Show(Catalog.GetString("Please save any changes before calling this function!"), Catalog.GetString( "Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if ((ACurrentBatchRow == null) || (ACurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { MessageBox.Show(Catalog.GetString("Please select an unposted batch to import transactions."), Catalog.GetString( "Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (ACurrentBatchRow.LastGiftNumber > 0) { if (MessageBox.Show(Catalog.GetString( "The current batch already contains some gift transactions. Do you really want to add more transactions to this batch?"), Catalog.GetString("Gift Transaction Import"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) { return(false); } } FdlgSeparator = new TDlgSelectCSVSeparator(false); FdlgSeparator.DateMayBeInteger = TUserDefaults.GetBooleanDefault(MCommonConstants.USERDEFAULT_IMPORTEDDATESMAYBEINTEGERS, false); 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(false); } FdlgSeparator.CSVData = importString; } else if (AImportSource == TGiftImportDataSourceEnum.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 Transactions from CSV File"); dialog.Filter = Catalog.GetString("Gift Transactions 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("Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } IsPlainText = (Path.GetExtension(dialog.FileName).ToLower() == ".txt"); } else { return(false); } } else { // unknown source!! The following need a value... return(false); } 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 (IsPlainText || (FdlgSeparator.ShowDialog() == DialogResult.OK)) { Hashtable requestParams = new Hashtable(); requestParams.Add("ALedgerNumber", FLedgerNumber); requestParams.Add("Delimiter", FdlgSeparator.SelectedSeparator); requestParams.Add("DateFormatString", FdlgSeparator.DateFormat); 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(() => ImportGiftTransactions( requestParams, FdlgSeparator.FileContent, ACurrentBatchRow.BatchNumber, out AMessages, out ok, out RefreshGUIAfterImport, out NeedRecipientLedgerNumber)); using (TProgressDialog ImportDialog = new TProgressDialog(ImportThread)) { ImportDialog.ShowDialog(); } // 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 int numberOfMissingGiftDestinations = NeedRecipientLedgerNumber.Rows.Count; if (numberOfMissingGiftDestinations == 0) { if (TVerificationHelper.ResultsContainErrorCode(AMessages, PetraErrorCodes.ERR_DB_SERIALIZATION_EXCEPTION)) { TConcurrentServerTransactions.ShowTransactionSerializationExceptionDialog(); } else { ShowMessages(AMessages); } } if (numberOfMissingGiftDestinations > 0) { bool offerToRunImportAgain = true; int currentMissingGiftDestinationNo = 1; // for each gift in which the recipient needs a Git Destination foreach (GiftBatchTDSAGiftDetailRow Row in NeedRecipientLedgerNumber.Rows) { //Lookup the partner shortname string partnerShortName = string.Empty; TPartnerClass partnerClass; if (TServerLookup.TMPartner.GetPartnerShortName(Row.RecipientKey, out partnerShortName, out partnerClass)) { Row.RecipientDescription = partnerShortName; } if (MessageBox.Show(string.Format( Catalog.GetString( "Error: {0:0000} of {1:0000} - Recipient '{2}' ({3}) has no Gift Destination assigned."), currentMissingGiftDestinationNo, numberOfMissingGiftDestinations, Row.RecipientDescription, Row.RecipientKey) + "\n\n" + Catalog.GetString("Do you want to assign a Gift Destination to this partner now?"), Catalog.GetString("Gift Import Cancelled"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { // allow the user to assign a Gift Destingation TFrmGiftDestination GiftDestinationForm = new TFrmGiftDestination(FPetraUtilsObject.GetForm(), Row.RecipientKey); GiftDestinationForm.ShowDialog(); } else { offerToRunImportAgain = false; } currentMissingGiftDestinationNo++; } // 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 these Gift Transactions again?"), Catalog.GetString("Gift Import"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == 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 if (!IsPlainText) { SaveUserDefaults(dialog); } if (ok) { MessageBox.Show(Catalog.GetString("Your data was imported successfully!"), Catalog.GetString("Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Information); } if (ok || RefreshGUIAfterImport) { FMyUserControl.LoadBatchesForCurrentYear(); FPetraUtilsObject.DisableSaveButton(); return(true); // This completes the refresh } return(false); }
/// <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> /// 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; String importString; String impOptions; 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; } FdlgSeparator = new TDlgSelectCSVSeparator(false); if (AImportDataSource == TImportDataSourceEnum.FromClipboard) { 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; } impOptions = TUserDefaults.GetStringDefault("Imp Options", ";American"); String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); FdlgSeparator = new TDlgSelectCSVSeparator(false); FdlgSeparator.SelectedSeparator = "\t"; FdlgSeparator.CSVData = importString; FdlgSeparator.DateFormat = dateFormatString; if (impOptions.Length > 1) { FdlgSeparator.NumberFormat = impOptions.Substring(1); } } 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("Text Files(*.txt) | *.txt | GL Batch Files(*.csv) | *.csv"); impOptions = 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 (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; } importString = File.ReadAllText(dialog.FileName, Encoding.Default); String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); FdlgSeparator.DateFormat = dateFormatString; if (impOptions.Length > 1) { FdlgSeparator.NumberFormat = impOptions.Substring(1); } FdlgSeparator.SelectedSeparator = impOptions.Substring(0, 1); } else { return; } } else { // unknown source!! The following need a value... impOptions = String.Empty; importString = String.Empty; } 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("NumberFormat", FdlgSeparator.NumberFormat); requestParams.Add("NewLine", Environment.NewLine); TVerificationResultCollection AMessages = new TVerificationResultCollection(); Thread ImportThread = new Thread(() => ImportGLBatches( requestParams, importString, out AMessages, out ok)); using (TProgressDialog ImportDialog = new TProgressDialog(ImportThread)) { ImportDialog.ShowDialog(); } // 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, impOptions); ShowMessages(AMessages); } if (ok) { MessageBox.Show(Catalog.GetString("Your data was imported successfully!"), Catalog.GetString("Batch Import"), MessageBoxButtons.OK, MessageBoxIcon.Information); FMyUserControl.ReloadBatches(); FPetraUtilsObject.DisableSaveButton(); } }
private void LoadUserDefaults() { // This is for compatibility with old Petra txtFilename.Text = TUserDefaults.GetStringDefault("Imp Filename", TClientSettings.GetExportPath() + Path.DirectorySeparatorChar + "export.csv"); String expOptions = TUserDefaults.GetStringDefault("Exp Options", "DU-T-X-DTrans"); // This is for compatibility with old Petra if (expOptions.StartsWith("D")) { rbtDetail.Checked = true; } else { rbtSummary.Checked = true; } if (expOptions.EndsWith("Trans")) { rbtOriginalTransactionCurrency.Checked = true; } else { rbtBaseCurrency.Checked = true; } if (expOptions.Length > 11) { // Extended options if (expOptions[1] == 'U') { chkIncludeUnposted.Checked = (expOptions[2] == '+'); } if (expOptions[3] == 'T') { chkTransactionsOnly.Checked = (expOptions[4] == '+'); } if (expOptions[5] == 'X') { FGiftExtraColumnsUserDefault = expOptions[6]; } if (expOptions[7] == 'N') { rbtBatchNumberSelection.Checked = true; } else { rbtDateRange.Checked = true; } } CultureInfo myCulture = Thread.CurrentThread.CurrentCulture; string defaultImpOptions = myCulture.TextInfo.ListSeparator + TDlgSelectCSVSeparator.NUMBERFORMAT_EUROPEAN; if (myCulture.EnglishName.EndsWith("-US")) { defaultImpOptions = myCulture.TextInfo.ListSeparator + TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN; } String impOptions = TUserDefaults.GetStringDefault("Imp Options", defaultImpOptions); if (impOptions.Length > 0) { cmbDelimiter.SelectedItem = ConvertDelimiter(impOptions.Substring(0, 1), true); } if (impOptions.Length > 1) { cmbNumberFormat.SelectedIndex = impOptions.Substring(1) == TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN ? 0 : 1; } string DateFormat = TUserDefaults.GetStringDefault("Imp Date", "yyyy-MM-dd"); // mdy and dmy have been the old default settings in Petra 2.x if (DateFormat.ToLower() == "mdy") { DateFormat = "MM/dd/yyyy"; } if (DateFormat.ToLower() == "dmy") { DateFormat = "dd/MM/yyyy"; } cmbDateFormat.SetSelectedString(DateFormat); }
/// <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; } }
/// <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) { bool ok = false; String importString; String impOptions; OpenFileDialog dialog = null; if (FPetraUtilsObject.HasChanges) { // saving failed, therefore do not try to post MessageBox.Show(Catalog.GetString("Please save before calling this function!"), Catalog.GetString( "Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FdlgSeparator = new TDlgSelectCSVSeparator(false); if (AImportSource == TGiftImportDataSourceEnum.FromClipboard) { 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; } impOptions = TUserDefaults.GetStringDefault("Imp Options", ";American"); String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); FdlgSeparator = new TDlgSelectCSVSeparator(false); FdlgSeparator.SelectedSeparator = "\t"; FdlgSeparator.CSVData = importString; FdlgSeparator.DateFormat = dateFormatString; if (impOptions.Length > 1) { FdlgSeparator.NumberFormat = impOptions.Substring(1); } } else if (AImportSource == TGiftImportDataSourceEnum.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("Gift Batches files (*.csv)|*.csv"); impOptions = 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 (dialog.ShowDialog() == DialogResult.OK) { Boolean fileCanOpen = FdlgSeparator.OpenCsvFile(dialog.FileName); if (!fileCanOpen) { MessageBox.Show(Catalog.GetString("Unable to open file."), Catalog.GetString("Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } importString = File.ReadAllText(dialog.FileName, Encoding.Default); String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); FdlgSeparator.DateFormat = dateFormatString; if (impOptions.Length > 1) { FdlgSeparator.NumberFormat = impOptions.Substring(1); } FdlgSeparator.SelectedSeparator = impOptions.Substring(0, 1); } else { return; } } else { // unknown source!! The following need a value... impOptions = String.Empty; importString = String.Empty; } 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("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, importString, out AMessages, out ok, 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) { 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 occurance of this error if (NeedRecipientLedgerNumber.Rows.Count - count > 0) { CheckboxText = string.Format( Catalog.GetString("Do this for all further occurances ({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(dialog, impOptions); } if (ok) { MessageBox.Show(Catalog.GetString("Your data was imported successfully!"), Catalog.GetString("Gift Import"), MessageBoxButtons.OK, MessageBoxIcon.Information); FMyUserControl.LoadBatchesForCurrentYear(); FPetraUtilsObject.DisableSaveButton(); } }
/// <summary> /// start the client /// </summary> public static void StartUp() { // for the moment default to english, because translations are not fully supported, and the layout does not adjust string UsersLanguageCode = "en-EN"; string UsersCultureCode = CultureInfo.CurrentCulture.Name; try { new TAppSettingsManager(); ExceptionHandling.GApplicationShutdownCallback = Shutdown.SaveUserDefaultsAndDisconnectAndStop; TLogging Logger = new TLogging(TClientSettings.GetPathLog() + Path.DirectorySeparatorChar + "PetraClient.log"); String LogFileMsg; if (!Logger.CanWriteLogFile(out LogFileMsg)) { MessageBox.Show(LogFileMsg, Catalog.GetString("Failed to open logfile"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } Catalog.Init(); #if DEBUG TApplicationVCSInfo.DetermineApplicationVCSInfo(); #endif // Register Types that can throw Error Codes (Ict.Common.CommonErrorCodes is automatically added) ErrorCodeInventory.RegisteredTypes.Add(new Ict.Petra.Shared.PetraErrorCodes().GetType()); ErrorCodeInventory.RegisteredTypes.Add(new Ict.Common.Verification.TStringChecks().GetType()); // Initialize the client TClientTasksQueue.ClientTasksInstanceType = typeof(TClientTaskInstance); TConnectionManagementBase.ConnectorType = typeof(TConnector); TConnectionManagementBase.GConnectionManagement = new TConnectionManagement(); new TCallForwarding(); // System.Windows.Forms.MessageBox.Show(ErrorCodes.GetErrorInfo("GENC.00001V").ShortDescription + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GENC.00001V").FullDescription + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GENC.00001V").Category.ToString("G") + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GENC.00001V").HelpID); // System.Windows.Forms.MessageBox.Show(ErrorCodes.GetErrorInfo("GENC.00002V").ShortDescription + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GENC.00002V").FullDescription + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GENC.00002V").ErrorMessageText + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GENC.00002V").ErrorMessageTitle + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GENC.00002V").Category.ToString("G") + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GENC.00002V").HelpID); // System.Windows.Forms.MessageBox.Show(ErrorCodes.GetErrorInfo("GEN.00004E").ShortDescription + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GEN.00004E").FullDescription + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GEN.00004E").Category.ToString("G") + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GEN.00004E").HelpID); // System.Windows.Forms.MessageBox.Show(ErrorCodes.GetErrorInfo("PARTN.00005V").ShortDescription + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("PARTN.00005V").FullDescription + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("PARTN.00005V").Category.ToString("G") + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("PARTN.00005V").HelpID); // System.Windows.Forms.MessageBox.Show(ErrorCodes.GetErrorInfo("GENC.00017V").ShortDescription + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GENC.00017V").FullDescription + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GENC.00017V").Category.ToString("G") + Environment.NewLine + Environment.NewLine + // ErrorCodes.GetErrorInfo("GENC.00017V").HelpID); //MessageBox.Show(ErrorCodes.GetErrorInfo(ERR_EMAILADDRESSINVALID).ShortDescription); // TODO another Catalog.Init("org", "./locale") for organisation specific words? } catch (Exception e) { MessageBox.Show(e.ToString()); return; } /* Show Splash Screen. * This is non-blocking since it is done in a separate Thread, that means * that the startup procedure continues while the Splash Screen is initialised and shown!!! */ FSplashScreen = new TSplashScreenManager(new TSplashScreenCallback(SplashScreenInfoCallback)); FSplashScreen.Show(); /* * IMPORTANT: Always use FSplashScreen.ShowMessageBox instead of MessageBox.Show * as long as the Splash Screen is displayed to show the MessageBox on the correct * Thread and in front of the Splash Screen!!! */ try { InitialiseClasses(); } catch (Exception e) { FSplashScreen.Close(); TLogging.Log(e.ToString()); MessageBox.Show(e.Message); Shutdown.StopPetraClient(); } if (!LoadClientSettings()) { Environment.Exit(0); } /* * Initialise Application Help */ Ict.Common.HelpLauncher.LocalHTMLHelp = TClientSettings.LocalHTMLHelp; if (TClientSettings.LocalHTMLHelp) { Ict.Common.HelpLauncher.HelpHTMLBaseURL = TClientSettings.HTMLHelpBaseURLLocal; } else { Ict.Common.HelpLauncher.HelpHTMLBaseURL = TClientSettings.HTMLHelpBaseURLOnInternet; if (Ict.Common.HelpLauncher.HelpHTMLBaseURL.EndsWith("/")) { Ict.Common.HelpLauncher.HelpHTMLBaseURL = Ict.Common.HelpLauncher.HelpHTMLBaseURL.Substring(0, Ict.Common.HelpLauncher.HelpHTMLBaseURL.Length - 1); } } Ict.Common.HelpLauncher.DetermineHelpTopic += new Ict.Common.HelpLauncher.TDetermineHelpTopic( Ict.Petra.Client.App.Core.THelpContext.DetermineHelpTopic); /* * Specific information about this Petra installation can only be shown in the * Splash Screen after Client settings are loaded (done in LoadClientSettings). */ FSplashScreen.UpdateTexts(); // only do automatic patch installation on remote situation // needs to be done before login, because the login connects to the updated server, and could go wrong because of changed interfaces if (TClientSettings.RunAsRemote == true) { try { CheckForPatches(); } catch (Exception e) { TLogging.Log("Problem during checking for patches: " + e.Message); TLogging.Log(e.StackTrace); } } if (TClientSettings.RunAsStandalone == true) { FSplashScreen.ProgressText = "Starting OpenPetra Server Environment..."; if (!StartServer()) { Environment.Exit(0); } } FSplashScreen.ProgressText = "Connecting to your OpenPetra.org Server..."; /* * Show Petra Login screen. * Connections to PetraServer are established in here as well. */ try { PerformLogin(); } catch (Exception) { #if TESTMODE // in Testmode, if no connection to applink, just stop here Environment.Exit(0); #endif #if TESTMODE #else throw; #endif } if (FLoginSuccessful) { try { // Set Application Help language to the User's preferred language TRemote.MSysMan.Maintenance.WebConnectors.GetLanguageAndCulture(ref UsersLanguageCode, ref UsersCultureCode); if (UsersLanguageCode != String.Empty) { Ict.Common.HelpLauncher.HelpLanguage = UsersLanguageCode; } if (TClientSettings.RunAsStandalone == true) { ProcessReminders.StartStandaloneRemindersProcessing(); } DataTable CurrencyFormatTable = TDataCache.TMPartner.GetCacheablePartnerTable(TCacheablePartnerTablesEnum.CurrencyCodeList); StringHelper.CurrencyFormatTable = CurrencyFormatTable; // This loads the Main Window of Petra Form MainWindow; MainWindow = new TFrmMainWindowNew(null); // TODO: user defined constructor with more details // FProcessID, FWelcomeMessage, FSystemEnabled); Application.Run(MainWindow); } catch (Exception e) { MessageBox.Show(e.Message); TLogging.Log(e.Message); TLogging.Log(e.StackTrace); } finally { /* * This code gets executed only after the Main Window of Petra has * closed. * At the moment, we will never get here, since we call Environment.Exit in the MainWindow (both old and new navigation) */ Shutdown.SaveUserDefaultsAndDisconnect(); } } else { // No successful login // APPLICATION STOPS IN THIS PROCEDURE !!! Shutdown.StopPetraClient(); } // APPLICATION STOPS IN THIS PROCEDURE !!! Shutdown.StopPetraClient(); }
/// <summary> /// this supports the transaction export files from Petra 2.x. /// Lines do NOT start with T for transaction /// </summary> public void ImportTransactions(ABatchRow ACurrentBatchRow, AJournalRow ACurrentJournalRow, TImportDataSourceEnum AImportDataSource) { bool ok = false; String importString; String impOptions; OpenFileDialog dialog = null; if (FPetraUtilsObject.HasChanges && !FMyForm.SaveChanges()) { // saving failed, therefore do not try to import MessageBox.Show(Catalog.GetString("Please save your changes before Importing new transactions"), Catalog.GetString( "Import GL Transactions"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if ((ACurrentBatchRow == null) || (ACurrentJournalRow == null) || (ACurrentJournalRow.JournalStatus != MFinanceConstants.BATCH_UNPOSTED)) { MessageBox.Show(Catalog.GetString("Please select an unposted journal to import transactions."), Catalog.GetString("Import GL Transactions")); return; } if (ACurrentJournalRow.LastTransactionNumber > 0) { if (MessageBox.Show(Catalog.GetString( "The current journal already contains some transactions. Do you really want to add more transactions to this journal?"), Catalog.GetString("Import GL Transactions"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) { return; } } FdlgSeparator = new TDlgSelectCSVSeparator(false); if (AImportDataSource == TImportDataSourceEnum.FromClipboard) { 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; } impOptions = TUserDefaults.GetStringDefault("Imp Options", ";American"); String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); FdlgSeparator = new TDlgSelectCSVSeparator(false); FdlgSeparator.SelectedSeparator = "\t"; FdlgSeparator.CSVData = importString; FdlgSeparator.DateFormat = dateFormatString; if (impOptions.Length > 1) { FdlgSeparator.NumberFormat = impOptions.Substring(1); } } else if (AImportDataSource == TImportDataSourceEnum.FromFile) { dialog = new OpenFileDialog(); dialog.FileName = TUserDefaults.GetStringDefault("Imp Filename", TClientSettings.GetExportPath() + Path.DirectorySeparatorChar + "import.csv"); dialog.Title = Catalog.GetString("Import Transactions from CSV File"); dialog.Filter = Catalog.GetString("GL Transactions files (*.csv)|*.csv"); impOptions = TUserDefaults.GetStringDefault("Imp Options", ";American"); if (dialog.ShowDialog() == DialogResult.OK) { Boolean fileCanOpen = FdlgSeparator.OpenCsvFile(dialog.FileName); if (!fileCanOpen) { MessageBox.Show(Catalog.GetString("Unable to open file."), Catalog.GetString("Transaction Import"), MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } importString = File.ReadAllText(dialog.FileName); String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY"); FdlgSeparator.DateFormat = dateFormatString; if (impOptions.Length > 1) { FdlgSeparator.NumberFormat = impOptions.Substring(1); } FdlgSeparator.SelectedSeparator = impOptions.Substring(0, 1); } else { return; } } else { // unknown source!! The following need a value... impOptions = String.Empty; importString = String.Empty; } 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("NumberFormat", FdlgSeparator.NumberFormat); requestParams.Add("NewLine", Environment.NewLine); TVerificationResultCollection AMessages = new TVerificationResultCollection(); Thread ImportThread = new Thread(() => ImportGLTransactions(requestParams, importString, ACurrentBatchRow.BatchNumber, ACurrentJournalRow.JournalNumber, out AMessages, out ok)); using (TProgressDialog ImportDialog = new TProgressDialog(ImportThread)) { ImportDialog.ShowDialog(); } ShowMessages(AMessages); } if (ok) { MessageBox.Show(Catalog.GetString("Your data was imported successfully!"), Catalog.GetString("Transactions Import"), MessageBoxButtons.OK, MessageBoxIcon.Information); SaveUserDefaults(dialog, impOptions); // Update the client side with new information from the server FMyForm.Cursor = Cursors.WaitCursor; FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadABatchAJournal(FLedgerNumber, ACurrentBatchRow.BatchNumber)); FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransactionATransAnalAttrib(FLedgerNumber, ACurrentBatchRow.BatchNumber, ACurrentJournalRow.JournalNumber)); FMainDS.AcceptChanges(); FMyForm.Cursor = Cursors.Default; FMyForm.GetTransactionsControl().SelectRow(1); } }