Exemplo n.º 1
0
        public static ACurrencyLanguageRow GetCurrencyLanguage(string ACurrencyCode)
        {
            ACurrencyLanguageRow ReturnValue = null;
            string Language = TUserDefaults.GetStringDefault(MSysManConstants.USERDEFAULT_UILANGUAGE);

            if (Language.Length > 2)
            {
                // need to get the two digit language code of p_language: de-DE => DE, en-EN => EN
                Language = Language.Substring(Language.Length - 2).ToUpper();
            }

            TDBTransaction Transaction = new TDBTransaction();
            TDataBase      db          = DBAccess.Connect("GetCurrencyLanguage");

            db.ReadTransaction(
                ref Transaction,
                delegate
            {
                ACurrencyLanguageTable CurrencyLanguageTable = ACurrencyLanguageAccess.LoadByPrimaryKey(ACurrencyCode, Language, Transaction);

                if ((CurrencyLanguageTable != null) && (CurrencyLanguageTable.Rows.Count > 0))
                {
                    ReturnValue = CurrencyLanguageTable[0];
                }
            });

            db.CloseDBConnection();

            return(ReturnValue);
        }
Exemplo n.º 2
0
        private void InitialiseUI()
        {
            if (FPartnerClass != "")
            {
                cmbPartnerClass.SetSelectedString(FPartnerClass);
            }
            else
            {
                // Default value: FAMILY
                cmbPartnerClass.SetSelectedString(FDefaultPartnerClass);
            }

            txtPartnerKey.PartnerClass = cmbPartnerClass.GetSelectedString();

            if (FAcquisitionCode != "")
            {
                cmbAcquisitionCode.SetSelectedString(FAcquisitionCode);
            }
            else
            {
                // Default value: UserDefault PARTNER_ACQUISITIONCODE
                cmbAcquisitionCode.SetSelectedString(TUserDefaults.GetStringDefault(TUserDefaults.PARTNER_ACQUISITIONCODE, "MAILROOM"));
            }

            // Default value: false (from SetParameters default)
            chkPrivatePartner.Checked = FPrivatePartner;

            if (FPartnerKey != -1)
            {
                txtPartnerKey.PartnerKey = FPartnerKey;

                // suppress setting of PartnerKey through DataGrid_FocusRowEntered...
                FDataGridRowEnteredRepeatedly = true;
            }
        }
        public static bool GetLanguageAndCulture(ref string ALanguageCode, ref string ACultureCode)
        {
            ALanguageCode = TUserDefaults.GetStringDefault(MSysManConstants.USERDEFAULT_UILANGUAGE, ALanguageCode);
            ACultureCode  = TUserDefaults.GetStringDefault(MSysManConstants.USERDEFAULT_UICULTURE, ACultureCode);

            return(true);
        }
Exemplo n.º 4
0
        public static ACurrencyLanguageRow GetCurrencyLanguage(string ACurrencyCode)
        {
            ACurrencyLanguageRow ReturnValue = null;
            string Language = TUserDefaults.GetStringDefault(MSysManConstants.USERDEFAULT_UILANGUAGE);

            if (Language.Length > 2)
            {
                // need to get the two digit language code of p_language: de-DE => DE, en-EN => EN
                Language = Language.Substring(Language.Length - 2).ToUpper();
            }

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                      TEnforceIsolationLevel.eilMinimum,
                                                                      ref Transaction,
                                                                      delegate
            {
                ACurrencyLanguageTable CurrencyLanguageTable = ACurrencyLanguageAccess.LoadByPrimaryKey(ACurrencyCode, Language, Transaction);

                if ((CurrencyLanguageTable != null) && (CurrencyLanguageTable.Rows.Count > 0))
                {
                    ReturnValue = CurrencyLanguageTable[0];
                }
            });

            return(ReturnValue);
        }
        /// <summary>
        /// load or reload the navigation
        /// </summary>
        public void LoadNavigationUI(bool ADontUseDefaultLedger = false)
        {
            // Force re-calculation of available Ledgers and correct setting of FCurrentLedger
            FLedgersAvailableToUser = null;

            XmlNode MainMenuNode   = BuildNavigationXml(ADontUseDefaultLedger);
            XmlNode DepartmentNode = MainMenuNode.FirstChild;

            lstFolders.MultiLedgerSite    = FMultiLedgerSite;
            lstFolders.CurrentLedger      = FCurrentLedger;
            lstFolders.ConferenceSelected = FConferenceSelected;

            lstFolders.ClearFolders();

            lstFolders.SubmoduleChanged += delegate(TTaskList ATaskList, XmlNode ATaskListNode, LinkLabel AItemClicked, object AOtherData)
            {
                OnSubmoduleChanged(ATaskList, ATaskListNode, AItemClicked);
            };
            lstFolders.LedgerChanged += delegate(int ALedgerNr, string ALedgerName)
            {
                OnLedgerChanged(ALedgerNr, ALedgerName);
            };

            TPnlModuleNavigation.SubSystemLinkStatus += delegate(int ALedgerNr, TPnlCollapsible APnlCollapsible)
            {
                UpdateSubsystemLinkStatus(ALedgerNr, APnlCollapsible);
            };

            TFrmGLEnableSubsystems.FinanceSubSystemLinkStatus += delegate()
            {
                UpdateFinanceSubsystemLinkStatus();
            };

            TLstTasks.Init(UserInfo.GUserInfo.UserID, HasAccessPermission, FTaxDeductiblePercentageEnabled);

            while (DepartmentNode != null)
            {
                lstFolders.AddFolder(DepartmentNode, UserInfo.GUserInfo.UserID, HasAccessPermission);

                DepartmentNode = DepartmentNode.NextSibling;
            }

            lstFolders.Dashboard = this.dsbContent;
            lstFolders.Statusbar = this.stbMain;

            SetTaskTileSize(TUserDefaults.GetInt16Default(TUserDefaults.MAINMENU_VIEWOPTIONS_TILESIZE, 2));

            SetTasksSingleClickExecution(TUserDefaults.GetBooleanDefault(TUserDefaults.MAINMENU_VIEWOPTIONS_SINGLECLICKEXECUTION, false));

            if (TUserDefaults.GetStringDefault(TUserDefaults.MAINMENU_VIEWOPTIONS_VIEWTASKS, VIEWTASKS_TILES) == VIEWTASKS_TILES)
            {
                ViewTasksAsTiles(this, null);
            }
            else
            {
                ViewTasksAsList(this, null);
            }

            lstFolders.SelectFirstAvailableFolder();
        }
        private void InitializeManualCode()
        {
            // Hide invalid Acquisition Codes
            cmbAcquisitionCode.Filter = PAcquisitionTable.GetValidAcquisitionDBName() + " <> 0";

            // set values for controls
            cmbAcquisitionCode.SetSelectedString(TUserDefaults.GetStringDefault(TUserDefaults.PARTNER_ACQUISITIONCODE, "MAILROOM"));
            cmbLanguageCode.SetSelectedString(TUserDefaults.GetStringDefault(MSysManConstants.PARTNER_LANGUAGECODE, "99"));

            FShowMoneyAsCurrency   = TUserDefaults.GetBooleanDefault(StringHelper.PARTNER_CURRENCY_FORMAT_AS_CURRENCY, false);
            chkMoneyFormat.Checked = FShowMoneyAsCurrency;

            FShowDecimalsAsCurrency  = TUserDefaults.GetBooleanDefault(StringHelper.PARTNER_DECIMAL_FORMAT_AS_CURRENCY, false);
            chkDecimalFormat.Checked = FShowDecimalsAsCurrency;

            FShowThousands           = TUserDefaults.GetBooleanDefault(StringHelper.PARTNER_CURRENCY_SHOW_THOUSANDS, true);
            chkShowThousands.Checked = FShowThousands;

            // Examples
            txtCostExample.Context            = ".MPartner";
            txtCostExample.CurrencyCode       = "USD";
            txtCostExample.NumberValueDecimal = 1234.56m;

            txtNumericExample.Context            = ".MPartner";
            txtNumericExample.NumberValueDecimal = 1.75m;
        }
Exemplo n.º 7
0
        /// <summary>
        /// If the Email preferences are not already in UserDefaults, this loads them.
        /// </summary>
        public static void LoadEmailDefaults()
        {
            if (!TUserDefaults.HasDefault("SmtpFromAccount") || (TUserDefaults.GetStringDefault("SmtpFromAccount") == ""))
            {
                TUserDefaults.SetDefault("SmtpFromAccount", TAppSettingsManager.GetValue("SmtpFromAccount", ""));
            }

            if (!TUserDefaults.HasDefault("SmtpDisplayName") || (TUserDefaults.GetStringDefault("SmtpDisplayName") == ""))
            {
                TUserDefaults.SetDefault("SmtpDisplayName", TAppSettingsManager.GetValue("SmtpDisplayName", ""));
            }

            if (!TUserDefaults.HasDefault("SmtpReplyTo"))
            {
                TUserDefaults.SetDefault("SmtpReplyTo", TAppSettingsManager.GetValue("SmtpReplyTo", ""));
            }

            if (!TUserDefaults.HasDefault("SmtpCcTo"))
            {
                TUserDefaults.SetDefault("SmtpCcTo", TAppSettingsManager.GetValue("SmtpCcTo", ""));
            }

            if (!TUserDefaults.HasDefault("SmtpEmailBody"))
            {
                TUserDefaults.SetDefault("SmtpEmailBody", TAppSettingsManager.GetValue("SmtpEmailBody", ""));
            }

            if (!TUserDefaults.HasDefault("SmtpSendAsAttachment"))
            {
                TUserDefaults.SetDefault("SmtpSendAsAttachment", TAppSettingsManager.GetValue("SmtpSendAsAttachment", ""));
            }
        }
Exemplo n.º 8
0
        private void InitializeManualCode()
        {
            var RecentAddrs = new StringCollection();

            RecentAddrs.AddRange(TUserDefaults.GetStringDefault(TSmtpSender.RECENTADDRS).Split('|'));
            cmbEmail.SetDataSourceStringList(RecentAddrs);
            cmbEmail.AcceptNewValues = true;
        }
        private void InitializeManualCode()
        {
            // Hide invalid Acquisition Codes
            cmbAcquisitionCode.Filter = PAcquisitionTable.GetValidAcquisitionDBName() + " <> 0";

            // set values for controls
            cmbAcquisitionCode.SetSelectedString(TUserDefaults.GetStringDefault(TUserDefaults.PARTNER_ACQUISITIONCODE, "MAILROOM"));
            cmbLanguageCode.SetSelectedString(TUserDefaults.GetStringDefault(MSysManConstants.PARTNER_LANGUAGECODE, "99"));
        }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="AExchangeRateDT">The corporate or daily exchange rate table</param>
        /// <param name="AImportMode">Determines whether corporate or daily exchange rates specified - either 'Daily' or 'Corporate'</param>
        /// <param name="AResultCollection">A validation collection to which errors will be added</param>
        /// <returns>The number of rows that were actually imported.  Rows that duplicate existing rows do not count.
        /// This is usually because this is an attempt to import again after a failed previous attempt.</returns>
        public static int ImportCurrencyExRates(TTypedDataTable AExchangeRateDT, string AImportMode, TVerificationResultCollection AResultCollection)
        {
            OpenFileDialog DialogBox = new OpenFileDialog();

            DialogBox.Title = Catalog.GetString("Import exchange rates from spreadsheet file");
            DialogBox.Filter = Catalog.GetString("Spreadsheet files (*.csv)|*.csv");

            if (DialogBox.ShowDialog() == DialogResult.OK)
            {
                String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY");
                String impOptions = TUserDefaults.GetStringDefault("Imp Options", ";" + TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN);

                bool dateMayBeAnInteger = TUserDefaults.GetBooleanDefault(MCommonConstants.USERDEFAULT_IMPORTEDDATESMAYBEINTEGERS, false);
                TDlgSelectCSVSeparator DlgSeparator = new TDlgSelectCSVSeparator(false);
                DlgSeparator.DateMayBeInteger = dateMayBeAnInteger;
                Boolean fileCanOpen = DlgSeparator.OpenCsvFile(DialogBox.FileName);

                if (!fileCanOpen)
                {
                    MessageBox.Show(Catalog.GetString("Unable to open file."),
                        Catalog.GetString("Import Exchange Rates"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Stop);
                    return 0;
                }

                DlgSeparator.DateFormat = dateFormatString;
                DlgSeparator.NumberFormat = (impOptions.Length > 1) ? impOptions.Substring(1) : TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN;
                DlgSeparator.SelectedSeparator = StringHelper.GetCSVSeparator(DlgSeparator.FileContent) ??
                                                 ((impOptions.Length > 0) ? impOptions.Substring(0, 1) : ";");

                if (DlgSeparator.ShowDialog() == DialogResult.OK)
                {
                    // Save the settings that we specified
                    SaveOptions(DlgSeparator);

                    // Do the import and return the number of rows imported and any messages
                    return ImportCurrencyExRatesFromCSV(AExchangeRateDT,
                        DlgSeparator.FileContent,
                        DlgSeparator.SelectedSeparator,
                        DlgSeparator.NumberFormat,
                        DlgSeparator.DateFormat,
                        dateMayBeAnInteger,
                        AImportMode,
                        AResultCollection,
                        Path.GetFileNameWithoutExtension(DialogBox.FileName));
                }
                else
                {
                    // Save the options anyway
                    SaveOptions(DlgSeparator);
                }
            }

            return 0;
        }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="AExchangeRateDT">The corporate or daily exchange rate table</param>
        /// <param name="AImportMode">Determines whether corporate or daily exchange rates specified - either 'Daily' or 'Corporate'</param>
        /// <param name="AResultCollection">A validation collection to which errors will be added</param>
        /// <returns>The number of rows that were actually imported.  Rows that duplicate existing rows do not count.
        /// This is usually because this is an attempt to import again after a failed previous attempt.</returns>
        public static int ImportCurrencyExRates(TTypedDataTable AExchangeRateDT, string AImportMode, TVerificationResultCollection AResultCollection)
        {
            OpenFileDialog DialogBox = new OpenFileDialog();

            DialogBox.Title  = Catalog.GetString("Import exchange rates from spreadsheet file");
            DialogBox.Filter = Catalog.GetString("Spreadsheet files (*.csv)|*.csv");

            if (DialogBox.ShowDialog() == DialogResult.OK)
            {
                String dateFormatString = TUserDefaults.GetStringDefault("Imp Date", "MDY");
                String impOptions       = TUserDefaults.GetStringDefault("Imp Options", ";" + TDlgSelectCSVSeparator.NUMBERFORMAT_AMERICAN);

                TDlgSelectCSVSeparator DlgSeparator = new TDlgSelectCSVSeparator(false);
                Boolean fileCanOpen = DlgSeparator.OpenCsvFile(DialogBox.FileName);

                if (!fileCanOpen)
                {
                    MessageBox.Show(Catalog.GetString("Unable to open file."),
                                    Catalog.GetString("Import Exchange Rates"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Stop);
                    return(0);
                }

                DlgSeparator.DateFormat = dateFormatString;

                if (impOptions.Length > 1)
                {
                    DlgSeparator.NumberFormat = impOptions.Substring(1);
                }

                DlgSeparator.SelectedSeparator = impOptions.Substring(0, 1);

                if (DlgSeparator.ShowDialog() == DialogResult.OK)
                {
                    // Save the settings that we specified
                    impOptions  = DlgSeparator.SelectedSeparator;
                    impOptions += DlgSeparator.NumberFormat;
                    TUserDefaults.SetDefault("Imp Options", impOptions);
                    TUserDefaults.SetDefault("Imp Date", DlgSeparator.DateFormat);
                    TUserDefaults.SaveChangedUserDefaults();

                    // Do the import and retuen the number of rows imported and any messages
                    return(ImportCurrencyExRatesFromCSV(AExchangeRateDT,
                                                        DialogBox.FileName,
                                                        DlgSeparator.SelectedSeparator,
                                                        DlgSeparator.NumberFormat,
                                                        DlgSeparator.DateFormat,
                                                        AImportMode,
                                                        AResultCollection));
                }
            }

            return(0);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        /// <summary></summary>
        public void InitializeManualCode()
        {
            txtEmailBody.AcceptsReturn = true;

            LoadEmailDefaults();
            txtSenderAddress.Text          = TUserDefaults.GetStringDefault("SmtpFromAccount");
            txtDisplayName.Text            = TUserDefaults.GetStringDefault("SmtpDisplayName");
            txtReplyTo.Text                = TUserDefaults.GetStringDefault("SmtpReplyTo");
            txtCopyMessagesTo.Text         = TUserDefaults.GetStringDefault("SmtpCcTo");
            txtEmailBody.Text              = TUserDefaults.GetStringDefault("SmtpEmailBody");
            chkReportsAsAttachment.Checked = TUserDefaults.GetBooleanDefault("SmtpSendAsAttachment");
        }
Exemplo n.º 14
0
        /// <summary>
        /// This returns a StringCollection with the names of recently used settings
        /// for the given report
        ///
        /// </summary>
        /// <returns>the list of names of recently used settings, which exist at the moment
        /// </returns>
        public StringCollection GetRecentlyUsedSettings()
        {
            StringCollection ReturnValue;
            String           SettingName;
            StringCollection AvailableSettings;

            System.Int32 Counter;
            ReturnValue = new StringCollection();

            if (("RptStg" + FReportName).Length > 32)
            {
                throw new Exception(String.Format("Report name ({0}) is too long for the settings",
                                                  FReportName));
            }

            // get names of recently used settings from the database
            ReturnValue = StringHelper.StrSplit(TUserDefaults.GetStringDefault("RptStg" + FReportName, ""), ",");

            // remove settings that are not available anymore
            AvailableSettings = GetAvailableSettings();
            Counter           = 0;

            while (Counter < ReturnValue.Count)
            {
                SettingName = ReturnValue[Counter];

                if (!AvailableSettings.Contains(SettingName))
                {
                    ReturnValue.Remove(SettingName);
                }
                else
                {
                    Counter = Counter + 1;
                }
            }

            // we might to fill up with reports from the directory, that have not been used yet
            Counter = 0;

            while ((Counter < AvailableSettings.Count) && (ReturnValue.Count < MAX_NUMBER_OF_RECENT_SETTINGS))
            {
                SettingName = AvailableSettings[Counter];

                if (!ReturnValue.Contains(SettingName))
                {
                    ReturnValue.Add(SettingName);
                }

                Counter = Counter + 1;
            }

            return(ReturnValue);
        }
        public static bool LoadLanguageAndCultureFromUserDefaults()
        {
            if (TUserDefaults.HasDefault(MSysManConstants.USERDEFAULT_UILANGUAGE))
            {
                string LanguageCode = TUserDefaults.GetStringDefault(MSysManConstants.USERDEFAULT_UILANGUAGE);
                string CultureCode  = TUserDefaults.GetStringDefault(MSysManConstants.USERDEFAULT_UICULTURE);
                TLanguageCulture.SetLanguageAndCulture(LanguageCode, CultureCode);
                return(true);
            }

            return(false);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Sets up various Colours of all Filter and Find instances from UserDefaults.
        /// </summary>
        /// <returns>void</returns>
        private static TUcoFilterAndFind.ColourInformation SetFilterFindColoursFromUserDefaults()
        {
            TUcoFilterAndFind.ColourInformation ReturnValue = new TUcoFilterAndFind.ColourInformation();

            ReturnValue.FilterColour = System.Drawing.ColorTranslator.FromHtml(
                TUserDefaults.GetStringDefault(TUserDefaults.NamedDefaults.COLOUR_FILTER_PANEL,
                                               System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.LightBlue)));

            ReturnValue.FindColour = System.Drawing.ColorTranslator.FromHtml(
                TUserDefaults.GetStringDefault(TUserDefaults.NamedDefaults.COLOUR_FIND_PANEL,
                                               System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.BurlyWood)));

            return(ReturnValue);
        }
Exemplo n.º 17
0
        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 ImportNewStatement(object sender, EventArgs e)
        {
            TFrmImportNewBankStatement DlgImport = new TFrmImportNewBankStatement(this);

            DlgImport.LedgerNumber = FLedgerNumber;

            if (DlgImport.ShowDialog() == DialogResult.OK)
            {
                // look for available plugin for importing a bank statement.
                // the plugin will upload the data into the tables a_ep_statement and a_ep_transaction on the server/database

                string FormatName = TUserDefaults.GetStringDefault(TUserDefaults.FINANCE_BANKIMPORT_PLUGIN);
                string BankStatementImportPlugin = TFrmImportNewBankStatement.PluginNamespace + FormatName + ".Client";

                // namespace of the class TBankStatementImport, eg. Plugin.BankImportFromCSV
                // the dll has to be in the normal application directory
                string Namespace   = BankStatementImportPlugin;
                string NameOfDll   = TAppSettingsManager.ApplicationDirectory + Path.DirectorySeparatorChar + BankStatementImportPlugin + ".dll";
                string NameOfClass = Namespace + ".TBankStatementImport";

                if (!File.Exists(NameOfDll))
                {
                    MessageBox.Show(Catalog.GetString("Please select a valid plugin for the import of bank statements!"));
                    return;
                }

                // dynamic loading of dll
                System.Reflection.Assembly assemblyToUse = System.Reflection.Assembly.LoadFrom(NameOfDll);
                System.Type CustomClass = assemblyToUse.GetType(NameOfClass);

                if (CustomClass == null)
                {
                    MessageBox.Show(Catalog.GetString("Invalid plugin " + NameOfDll + Environment.NewLine +
                                                      "Cannot find class " + NameOfClass));
                    return;
                }

                IImportBankStatement ImportBankStatement = (IImportBankStatement)Activator.CreateInstance(CustomClass);

                if (ImportBankStatement.ImportBankStatement(out FStatementKey, FLedgerNumber, DlgImport.FAccountCode))
                {
                    if (FStatementKey > -1)
                    {
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                }
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// add new value of combobox to the user defaults, or move existing value to the front;
        /// limits the number of values to MAX_COMBOBOX_HISTORY
        /// </summary>
        /// <param name="Sender"></param>
        /// <param name="e"></param>
        public void AddComboBoxHistory(System.Object Sender, TAcceptNewEntryEventArgs e)
        {
            string           keyName = "CmbHistory" + ((Control)Sender).Name;
            StringCollection values  = StringHelper.StrSplit(TUserDefaults.GetStringDefault(keyName, ""), ",");

            values.Remove(e.ItemString);
            values.Insert(0, e.ItemString);

            while (values.Count > MAX_COMBOBOX_HISTORY)
            {
                values.RemoveAt(values.Count - 1);
            }

            TUserDefaults.SetDefault(keyName, StringHelper.StrMerge(values, ','));
        }
Exemplo n.º 20
0
        private void TFindOptionsForm_Load(System.Object sender, System.EventArgs e)
        {
            // Form initially shows itself collapsed
            this.Height = grpDisplayedSearchCriteria.Height +
                          pnlBtnOKCancelHelpLayout.Height + stbMain.Height + 22;

            FSaveChangedOptions = false;

            // The following Buttons are only for debugging...
            btnShowRightListItems.Visible = false;
            btnShowLeftListItems.Visible  = false;

            // The rearranging of Find Criteria isn't quite stable yet, so we don't show the Button that enables the rearranging...
            btnMore.Visible = false;

            // Define default order in which the items in the left and right columns should appear
            // This is used to determine the place where added fields should appear in the columns
            FCriteriaFieldsLeftDefaultOrder = new ArrayList(new String[]
                                                            { "PartnerName", "PersonalName",
                                                              "PreviousName", "Email",
                                                              "Address1", "Address2", "Address3", "City",
                                                              "PostCode", "County",
                                                              "Country", "MailingAddressOnly", "PhoneNumber" });

            FCriteriaFieldsRightDefaultOrder = new ArrayList(new String[]
                                                             { "PartnerClass", "PartnerKey",
                                                               "OMSSKey", "LocationKey", "PartnerStatus",
                                                               "PersonnelCriteria" });

            // Load items that should go into the left and right columns from User Defaults
            FCriteriaFieldsLeft =
                new ArrayList(TUserDefaults.GetStringDefault(TUserDefaults.PARTNER_FINDOPTIONS_CRITERIAFIELDSLEFT,
                                                             PARTNER_FINDOPTIONS_CRITERIAFIELDSLEFT_DEFAULT).Split(new Char[] { (';') }));
            FCriteriaFieldsRight =
                new ArrayList(TUserDefaults.GetStringDefault(TUserDefaults.PARTNER_FINDOPTIONS_CRITERIAFIELDSRIGHT,
                                                             PARTNER_FINDOPTIONS_CRITERIAFIELDSRIGHT_DEFAULT).Split(new Char[] { (';') }));
            RemoveInvalidCriteria();

            // Populate the three CheckedListBoxes and check the correct items
            SetupFindCriteriaLists();
            chkShowMatchButtons.Checked           = TUserDefaults.GetBooleanDefault(TUserDefaults.PARTNER_FINDOPTIONS_SHOWMATCHBUTTONS, true);
            chkExactPartnerKeyMatchSearch.Checked = TUserDefaults.GetBooleanDefault(TUserDefaults.PARTNER_FINDOPTIONS_EXACTPARTNERKEYMATCHSEARCH,
                                                                                    true);

            // Hook up FindCriteriaSelectionChanged that is fired by ucoPartnerFindCriteriaSetup
            ucoPartnerFindCriteriaSetup.FindCriteriaSelectionChanged += new FindCriteriaSelectionChangedHandler(
                this.UcoPartnerFindCriteriaSetup_FindCriteriaSelectionChanged);
        }
Exemplo n.º 21
0
        private void InitializeManualCode()
        {
            string MySettings = TSystemDefaults.GetSystemDefault("IntranetExportSettings", "pswd,45,");

            string[] Setting = MySettings.Split(',');

            if (Setting.Length > 2)
            {
                FPswd     = Setting[0];
                FGiftDays = Convert.ToInt32(Setting[1]);
                FExtra    = Setting[2];
            }

            FReplyToEmail  = TUserDefaults.GetStringDefault("ReplyToEmail");
            FServerAddress = TUserDefaults.GetStringDefault("IntranetServerAddress");
        }
        // read user default filter from SUserDefaults (if it exists) and apply it to form
        private void SetupFilter()
        {
            FUserDefaultFilter = TUserDefaults.GetStringDefault(TUserDefaults.PERSONNEL_APPLICATION_STATUS);
            string[] FilterArray = FUserDefaultFilter.Split(',');

            // No filter
            if (FUserDefaultFilter == "")
            {
                return;
            }
            // General filter
            else if (FUserDefaultFilter.Substring(0, 1) == ",")
            {
                rbtGeneral.Checked = true;

                foreach (string Filter in FilterArray)
                {
                    if (Filter == "A")
                    {
                        chkAccepted.Checked = true;
                    }
                    else if (Filter == "C")
                    {
                        chkCancelled.Checked = true;
                    }
                    else if (Filter == "H")
                    {
                        chkHold.Checked = true;
                    }
                    else if (Filter == "E")
                    {
                        chkEnquiry.Checked = true;
                    }
                    else if (Filter == "R")
                    {
                        chkRejected.Checked = true;
                    }
                }
            }
            // Detailed filter
            else
            {
                rbtDetailed.Checked = true;
                SetDetailedStatuses(FUserDefaultFilter);
            }
        }
Exemplo n.º 23
0
        /// <summary></summary>
        public void InitializeManualCode()
        {
            txtEmailBody.AcceptsReturn           = true;
            txtAccountPswd.UseSystemPasswordChar = true;

            LoadEmailDefaults();
            txtServerName.Text             = TUserDefaults.GetStringDefault("SmtpHost");
            txtPort.Text                   = TUserDefaults.GetInt16Default("SmtpPort").ToString();
            chkUseSsl.Checked              = TUserDefaults.GetBooleanDefault("SmtpUseSsl");
            txtAccountName.Text            = TUserDefaults.GetStringDefault("SmtpUser");
            txtAccountPswd.Text            = TUserDefaults.GetStringDefault("SmtpPassword");
            txtSenderAddress.Text          = TUserDefaults.GetStringDefault("SmtpFromAccount");
            txtDisplayName.Text            = TUserDefaults.GetStringDefault("SmtpDisplayName");
            txtReplyTo.Text                = TUserDefaults.GetStringDefault("SmtpReplyTo");
            txtCopyMessagesTo.Text         = TUserDefaults.GetStringDefault("SmtpCcTo");
            txtEmailBody.Text              = TUserDefaults.GetStringDefault("SmtpEmailBody");
            chkReportsAsAttachment.Checked = TUserDefaults.GetBooleanDefault("SmtpSendAsAttachment");
        }
Exemplo n.º 24
0
        private void RunOnceOnActivationManual()
        {
            // Load the settings from user preferences
            string[] options = TUserDefaults.GetStringDefault(PARTNER_IMPORT_TAX_CODE_OPTIONS, string.Empty).Split(';');

            if (options.Length >= 11)
            {
                rbtFromFile.Checked         = Convert.ToInt16(options[0]) != 0;
                nudPartnerKeyColumn.Value   = Convert.ToInt16(options[1]);
                nudTaxCodeColumn.Value      = Convert.ToInt16(options[2]);
                chkFirstRowIsHeader.Checked = Convert.ToInt16(options[3]) != 0;
                int taxCodeOption = Convert.ToInt16(options[4]);
                rbtSkipEmptyTaxCode.Checked         = taxCodeOption == 1;
                rbtDeleteEmptyTaxCode.Checked       = taxCodeOption == 2;
                chkFailIfNotPerson.Checked          = Convert.ToInt16(options[5]) != 0;
                chkFailInvalidPartner.Checked       = Convert.ToInt16(options[6]) != 0;
                chkOverwriteExistingTaxCode.Checked = Convert.ToInt16(options[7]) != 0;
                chkCreateExtract.Checked            = Convert.ToInt16(options[8]) != 0;
                chkCreateOutFile.Checked            = Convert.ToInt16(options[9]) != 0;
                chkIncludePartnerDetails.Checked    = Convert.ToInt16(options[10]) != 0;
            }
            else
            {
                chkFailIfNotPerson.Checked       = true;
                chkFailInvalidPartner.Checked    = true;
                chkCreateOutFile.Checked         = true;
                chkIncludePartnerDetails.Checked = true;
                nudTaxCodeColumn.Value           = 2;
            }

            txtFileName.Text       = TUserDefaults.GetStringDefault(PARTNER_IMPORT_TAX_CODE_INFILE, string.Empty);
            txtOutputFileName.Text = TUserDefaults.GetStringDefault(PARTNER_IMPORT_TAX_CODE_OUTFILE, string.Empty);

            // Force the updates on the enabled states
            OnDataSourceChange(null, null);
            chkCreateExtract_CheckedChanged(null, null);
            chkCreateOutFile_CheckedChanged(null, null);

            if (rbtFromFile.Checked)
            {
                rbtFromFile.Focus();
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Sets up various Colours of all SourceGrid DataGrid instances from UserDefaults.
        /// </summary>
        /// <returns>void</returns>
        private static TSgrdDataGrid.ColourInformation SetDataGridColoursFromUserDefaults()
        {
            string SelectionColourUserDefault;

            TSgrdDataGrid.ColourInformation ReturnValue = new TSgrdDataGrid.ColourInformation();

            // Note: The UserDefaults store the colours as HTML representations of colours. Example: "#FFFFFF" = System.Drawing.Color.White
            ReturnValue.BackColour = System.Drawing.ColorTranslator.FromHtml(
                TUserDefaults.GetStringDefault(TUserDefaults.NamedDefaults.COLOUR_GRID_BACKGROUND,
                                               System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.White)));
            ReturnValue.CellBackgroundColour = System.Drawing.ColorTranslator.FromHtml(
                TUserDefaults.GetStringDefault(TUserDefaults.NamedDefaults.COLOUR_GRID_CELLBACKGROUND,
                                               System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.White)));

            ReturnValue.AlternatingBackgroundColour = System.Drawing.ColorTranslator.FromHtml(
                TUserDefaults.GetStringDefault(TUserDefaults.NamedDefaults.COLOUR_GRID_ALTERNATE,
                                               System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(230, 230, 230))));
            ReturnValue.GridLinesColour = System.Drawing.ColorTranslator.FromHtml(
                TUserDefaults.GetStringDefault(TUserDefaults.NamedDefaults.COLOUR_GRID_GRIDLINES,
                                               System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(211, 211, 211))));

            // The UserDefault for the Selection colour stores a decimal Alpha value appended to the HTML representation of the colour
            // because the Selection needs to be transparent to a certain degree in order to let the data of a selected Grid Row shine through!
            // Example: "#00FFAA;50": A=140 (decimal 140), R=15 (hex 0F), G=255 (hex FF), B=170 (hex AA)
            // Note 17/02/2017: We are trying an alternative way of drawing the highlight, which means that we no longer need the 'A' value.
            // Now we always use a value of 0 but the setting is still retained in the user defaults table in case we need it again.
            SelectionColourUserDefault = TUserDefaults.GetStringDefault(TUserDefaults.NamedDefaults.COLOUR_GRID_SELECTION, String.Empty);

            if (SelectionColourUserDefault.Length > 0)
            {
                ReturnValue.SelectionColour = System.Drawing.ColorTranslator.FromHtml(SelectionColourUserDefault.Split(';')[0]);
                ReturnValue.SelectionColour = System.Drawing.Color.FromArgb(0, ReturnValue.SelectionColour);    // Fully transparent
            }
            else
            {
                // No UserDefault for the Selection in the DB; use a hard-coded default
                ReturnValue.SelectionColour =
                    System.Drawing.Color.FromArgb(0, System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.Highlight));    // Fully transparent
            }

            return(ReturnValue);
        }
Exemplo n.º 26
0
        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);
        }
Exemplo n.º 27
0
        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"));
        }
Exemplo n.º 28
0
        public static ACurrencyLanguageRow GetCurrencyLanguage(string ACurrencyCode)
        {
            ACurrencyLanguageRow ReturnValue = null;
            string Language = TUserDefaults.GetStringDefault(MSysManConstants.USERDEFAULT_UILANGUAGE);

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                      TEnforceIsolationLevel.eilMinimum,
                                                                      ref Transaction,
                                                                      delegate
            {
                ACurrencyLanguageTable CurrencyLanguageTable = ACurrencyLanguageAccess.LoadByPrimaryKey(ACurrencyCode, Language, Transaction);

                if ((CurrencyLanguageTable != null) && (CurrencyLanguageTable.Rows.Count > 0))
                {
                    ReturnValue = CurrencyLanguageTable[0];
                }
            });

            return(ReturnValue);
        }
Exemplo n.º 29
0
        /// <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();
            }
        }
Exemplo n.º 30
0
        /// <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);
        }