Пример #1
0
        /// <summary>Called after the operation</summary>
        /// <remarks>Uses an "invoke" to update screen controls.</remarks>
        ///
        public void TidyUpAfterAsyncOperation()
        {
            if (InvokeRequired)
            {
                Invoke(new CrossThreadUpdate(TidyUpAfterAsyncOperation));
                return;
            }

            UseWaitCursor = false;

            if (FOperationResult)
            {
                tbxMessage.Text = Catalog.GetString("Operation did not complete:") +
                                  "\r\n\r\n" +
                                  FverificationResult.BuildVerificationResultString();
            }
            else
            {
                tbxMessage.Text = Catalog.GetString("Operation completed successfully.") +
                                  "\r\n\r\n" +
                                  FverificationResult.BuildVerificationResultString();
            }

            btnPeriodEnd.Visible = false;
            btnCancel.Text       = Catalog.GetString("Done");
        }
Пример #2
0
        public void TestPostGLBatchesArgumentValidation()
        {
            TVerificationResultCollection VerificationResult = null;

            List <Int32> BatchNumbers = new List <int>();

            string Message = "Validation failed for posting a GL Batch with ledger number less than 1.";

            // Post a GL Batch with ledger number less than 1
            try
            {
                TGLPosting.PostGLBatches(-1, BatchNumbers, out VerificationResult);
                if ((VerificationResult.CountCriticalErrors != 1) ||
                    (!VerificationResult.BuildVerificationResultString().Contains("The Ledger number must be greater than 0")))
                {
                    Assert.Fail(Message);
                }
            }
            catch
            {
                Assert.Fail(Message);
            }

            Message = "Validation failed for posting a GL Batch without any batch numbers.";

            // Post a GL Batch without any batch numbers
            try
            {
                TGLPosting.PostGLBatches(1, BatchNumbers, out VerificationResult);

                if ((!VerificationResult.HasCriticalOrNonCriticalErrors) ||
                    (!VerificationResult.BuildVerificationResultString().Contains("No GL Batches to post")))
                {
                    Assert.Fail(Message);
                }
            }
            catch
            {
                Assert.Fail(Message);
            }

            Message = "Validation failed for posting a GL Batch with batch number less than 1.";
            BatchNumbers.Add(-1);

            // Post a GL Batch with batch number less than 1
            try
            {
                TGLPosting.PostGLBatches(1, BatchNumbers, out VerificationResult);

                if ((VerificationResult.CountCriticalErrors != 1) ||
                    (!VerificationResult.BuildVerificationResultString().Contains("The Batch number must be greater than 0")))
                {
                    Assert.Fail(Message);
                }
            }
            catch
            {
                Assert.Fail(Message);
            }
        }
        public void TestBuildVerificationResultString()
        {
            TVerificationResult           res0, res1, res2, res3, res4, res5, res6, res7;
            TVerificationResultCollection coll = new TVerificationResultCollection();

            res0 = new TVerificationResult(null, "test0", TResultSeverity.Resv_Noncritical);
            coll.Add(res0);
            res1 = new TVerificationResult(null, "test1", TResultSeverity.Resv_Info);
            coll.Add(res1);
            TextBox tb1 = new TextBox();

            res2 = new TVerificationResult(tb1, "test2", TResultSeverity.Resv_Critical);
            coll.Add(res2);
            res3 = new TVerificationResult(tb1, "test3", TResultSeverity.Resv_Noncritical);
            coll.Add(res3);
            DataColumn col = new DataColumn("test", typeof(int));

            res4 = new TScreenVerificationResult(null, col, "test4", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res4);
            DataTable  tab  = new DataTable("test");
            DataColumn col2 = new DataColumn("test2", typeof(string));

            tab.Columns.Add(col2);
            DataColumn col3 = new DataColumn("test3", typeof(string));

            tab.Columns.Add(col3);
            res5 = new TScreenVerificationResult(null, col2, "test5", null, TResultSeverity.Resv_Status);
            coll.Add(res5);
            res6 = new TScreenVerificationResult(null, col, "test6", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res6);
            res7 = new TScreenVerificationResult(null, col3, "test7", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res7);

            Console.WriteLine(coll.BuildVerificationResultString());
            Console.WriteLine(coll.BuildVerificationResultString().Replace("\n", "\\n").Replace("\r", "\\r"));

            const string expectedString =
                "\r\n    Problem: test0\r\n    (Non-critical)\r\n\r\n" +
                "\r\n    Status: test1\r\n\r\n\r\nSystem.Windows.Forms.TextBox, Text: " +
                "\r\n    Problem: test2\r\n    (Critical)\r\n\r\nSystem.Windows.Forms.TextBox, Text: " +
                "\r\n    Problem: test3\r\n    (Non-critical)\r\n\r\n" +
                "\r\n    Problem: test4\r\n    (Non-critical)\r\n\r\n" +
                "\r\n    Status: test5\r\n\r\n\r\n" +
                "\r\n    Problem: test6\r\n    (Non-critical)\r\n\r\n" +
                "\r\n    Problem: test7\r\n    (Non-critical)\r\n\r\n";

            Assert.AreEqual(expectedString, coll.BuildVerificationResultString(), "comparing the string");
        }
Пример #4
0
        /// <summary>Called after the operation</summary>
        /// <remarks>Uses an "invoke" to update screen controls.</remarks>
        ///
        public void PeriodEndTidyup()
        {
            if (InvokeRequired)
            {
                Invoke(new CrossThreadUpdate(PeriodEndTidyup));
                return;
            }

            UseWaitCursor = false;

            if (FOperationResult)
            {
                tbxMessage.Text = Catalog.GetString("Operation did not complete:") +
                                  "\r\n\r\n" +
                                  FverificationResult.BuildVerificationResultString();
            }
            else
            {
                tbxMessage.Text = Catalog.GetString("Operation completed successfully.") +
                                  "\r\n\r\n" +
                                  FverificationResult.BuildVerificationResultString();
            }

            btnPeriodEnd.Visible = false;

            if (!FOperationResult)
            {
                TFrmGLPeriodEndReporting PrintDlg = new TFrmGLPeriodEndReporting(this);
                PrintDlg.glBatchNumbers = FglBatchNumbers;
                PrintDlg.FLedgerNumber  = FLedgerNumber;
                PrintDlg.FMonthMode     = blnIsInMonthMode;
                PrintDlg.ShowDialog();

                if (FMonthEndStewardship)
                {
                    //
                    // Show Stewardship Reports screen
                    TFrmStewardshipReports stewardshipForm = new TFrmStewardshipReports(null);
                    stewardshipForm.LedgerNumber = FLedgerNumber;
                    stewardshipForm.Show();
                }
            }

            btnCancel.Text = Catalog.GetString("Done");
        }
Пример #5
0
 /// <summary>
 /// Checks that a <see cref="TVerificationResultCollection" /> is either null or that it doesn't contain
 /// any <see cref="TVerificationResult" /> items . If it isn't null and it contains items an Assert.Fail call
 /// is issued by this Method!
 /// </summary>
 /// <remarks>
 /// Can be used for 'Guard Asserts' to check that the <see cref="TVerificationResultCollection" />
 /// that is returned from server calls is null or empty.
 /// </remarks>
 /// <param name="AVerificationResult"><see cref="TVerificationResultCollection" /> reference (can be null!).</param>
 /// <param name="AMessage">String to append before the Assert message that this Method produces (optional).</param>
 public static void EnsureNullOrEmptyVerificationResult(TVerificationResultCollection AVerificationResult, string AMessage = "")
 {
     if ((AVerificationResult != null) &&
         (AVerificationResult.Count > 0))
     {
         Assert.Fail(AMessage + "*** VerificationResult is NOT EMPTY *** : " +
                     AVerificationResult.BuildVerificationResultString());
     }
 }
        private int ImportAndPostGiftBatch()
        {
            TGiftImporting importer = new TGiftImporting();

            string       testFile    = TAppSettingsManager.GetValue("GiftBatch.file", "../../csharp/ICT/Testing/lib/MFinance/SampleData/sampleGiftBatch.csv");
            StreamReader sr          = new StreamReader(testFile);
            string       FileContent = sr.ReadToEnd();

            FileContent = FileContent.Replace("{ledgernumber}", FLedgerNumber.ToString());
            FileContent = FileContent.Replace("{thisyear}", DateTime.Today.Year.ToString());

            sr.Close();

            Hashtable parameters = new Hashtable();

            parameters.Add("Delimiter", ",");
            parameters.Add("ALedgerNumber", FLedgerNumber);
            parameters.Add("DateFormatString", "yyyy-MM-dd");
            parameters.Add("DatesMayBeIntegers", false);
            parameters.Add("NumberFormat", "American");
            parameters.Add("NewLine", Environment.NewLine);

            TVerificationResultCollection VerificationResult = null;
            GiftBatchTDSAGiftDetailTable  NeedRecipientLedgerNumber;
            bool refreshRequired;

            if (!importer.ImportGiftBatches(parameters, FileContent, out NeedRecipientLedgerNumber, out refreshRequired, out VerificationResult))
            {
                Assert.Fail("Gift Batch was not imported: " + VerificationResult.BuildVerificationResultString());
            }

            int BatchNumber = importer.GetLastGiftBatchNumber();

            Assert.AreNotEqual(-1, BatchNumber, "Should have imported the gift batch and returned a valid batch number");
            Int32 generatedGlBatchNumber;

            if (!TGiftTransactionWebConnector.PostGiftBatch(FLedgerNumber, BatchNumber, out generatedGlBatchNumber, out VerificationResult))
            {
                Assert.Fail("Gift Batch was not posted: " + VerificationResult.BuildVerificationResultString());
            }

            return(BatchNumber);
        }
Пример #7
0
        private void PeriodEndButtonClick(object btn, EventArgs e)
        {
            RunPeriodEnd(CALCULATION_MODE);
            tbxMessage.Text = Catalog.GetString("The server returned this message:") +
                              "\r\n\r\n" +
                              FverificationResult.BuildVerificationResultString();
            btnPeriodEnd.Visible = false;
            btnCancel.Text       = Catalog.GetString("Done");

            // reset valid dates as they may have changed: next time this object is called values are refreshed from server
            TLedgerSelection.ResetValidDates(FLedgerNumber);
        }
Пример #8
0
        public void TestPostGLBatchArgumentValidation()
        {
            TVerificationResultCollection VerificationResult = null;

            string Message = "Validation failed for posting a GL Batch with ledger number less than 1.";

            // Post a GL Batch with ledger number less than 1
            try
            {
                TGLPosting.PostGLBatch(-1, 1, out VerificationResult);

                if ((VerificationResult.CountCriticalErrors != 1) ||
                    (!VerificationResult.BuildVerificationResultString().Contains("The Ledger number must be greater than 0")))
                {
                    Assert.Fail(Message);
                }
            }
            catch
            {
                Assert.Fail(Message);
            }

            Message = "Validation failed for posting a GL Batch with batch number less than 1.";

            // Post a GL Batch with batch number less than 1
            try
            {
                TGLPosting.PostGLBatch(1, -1, out VerificationResult);

                if ((VerificationResult.CountCriticalErrors != 1) ||
                    (!VerificationResult.BuildVerificationResultString().Contains("The Batch number must be greater than 0")))
                {
                    Assert.Fail(Message);
                }
            }
            catch
            {
                Assert.Fail(Message);
            }
        }
        public void TestBuildVerificationResultString()
        {
            TVerificationResult           res0, res1, res4, res5, res6, res7;
            TVerificationResultCollection coll = new TVerificationResultCollection();

            res0 = new TVerificationResult(null, "test0", TResultSeverity.Resv_Noncritical);
            coll.Add(res0);
            res1 = new TVerificationResult(null, "test1", TResultSeverity.Resv_Info);
            coll.Add(res1);
            DataColumn col = new DataColumn("test", typeof(int));

            res4 = new TScreenVerificationResult(null, col, "test4", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res4);
            DataTable  tab  = new DataTable("test");
            DataColumn col2 = new DataColumn("test2", typeof(string));

            tab.Columns.Add(col2);
            DataColumn col3 = new DataColumn("test3", typeof(string));

            tab.Columns.Add(col3);
            res5 = new TScreenVerificationResult(null, col2, "test5", null, TResultSeverity.Resv_Status);
            coll.Add(res5);
            res6 = new TScreenVerificationResult(null, col, "test6", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res6);
            res7 = new TScreenVerificationResult(null, col3, "test7", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res7);

            Console.WriteLine(coll.BuildVerificationResultString());
            Console.WriteLine(coll.BuildVerificationResultString().Replace("\n", "\\n").Replace("\r", "\\r"));

            string expectedString =
                Environment.NewLine + "    Problem: test0" + Environment.NewLine + "    (Non-critical)" + Environment.NewLine + Environment.NewLine +
                Environment.NewLine + "    Status: test1" + Environment.NewLine + Environment.NewLine + Environment.NewLine +
                Environment.NewLine + "    Problem: test4" + Environment.NewLine + "    (Non-critical)" + Environment.NewLine + Environment.NewLine +
                Environment.NewLine + "    Status: test5" + Environment.NewLine + Environment.NewLine + Environment.NewLine +
                Environment.NewLine + "    Problem: test6" + Environment.NewLine + "    (Non-critical)" + Environment.NewLine + Environment.NewLine +
                Environment.NewLine + "    Problem: test7" + Environment.NewLine + "    (Non-critical)" + Environment.NewLine + Environment.NewLine;

            Assert.AreEqual(expectedString, coll.BuildVerificationResultString(), "comparing the string");
        }
Пример #10
0
        public void TestImportCSV_Dates_MDY()
        {
            TVerificationResultCollection VerificationResult = null;
            string doc = String.Empty;

            using (StreamReader sr = new StreamReader("../../csharp/ICT/Testing/lib/MPartner/SampleData/samplePartnerImport_dates_mdy.csv"))
            {
                doc = sr.ReadToEnd();
            }

            PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "mdy", ";", out VerificationResult);

            if (VerificationResult != null)
            {
                if (VerificationResult.HasCriticalErrors)
                {
                    Assert.AreEqual(String.Empty, VerificationResult.BuildVerificationResultString(), "there was an error importing the csv file");
                }
            }

            // there should be 2 partners imported (2 x family)
            Assert.AreEqual(2, MainDS.PPartner.Rows.Count);
            Assert.AreEqual(2, MainDS.PFamily.Rows.Count);

            Assert.AreEqual(new DateTime(1979, 8, 19), MainDS.PFamily[0].DateOfBirth, "date of birth is wrong!");

            // Now try with the wrong date format
            VerificationResult = null;
            MainDS             = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "dmy", ";", out VerificationResult);

            Assert.IsNotNull(VerificationResult, "Expected to get errors");
            int numErrors = 0;

            for (int i = 0; i < VerificationResult.Count; i++)
            {
                if (VerificationResult[i].ResultSeverity != TResultSeverity.Resv_Status)
                {
                    numErrors++;
                }
            }

            Assert.AreEqual(2, numErrors, "Wrong number of errors");
        }
Пример #11
0
        /// <summary>
        /// Checks that a <see cref="TVerificationResultCollection" /> is either null or that it doesn't contain
        /// any <see cref="TVerificationResult" /> items that are CriticalErrors. If it isn't null and it contains such items, an Assert.Fail
        /// call is issued by this Method!
        /// </summary>
        /// <remarks>
        /// Can be used for 'Guard Asserts' to check that the <see cref="TVerificationResultCollection" />
        /// that is returned from server calls is null or holds only non-critical <see cref="TVerificationResult" /> items.
        /// </remarks>
        /// <param name="AVerificationResult"><see cref="TVerificationResultCollection" /> reference (can be null!).</param>
        /// <param name="AMessage">String to append before the Assert message that this Method produces (optional).</param>
        public static void EnsureNullOrOnlyNonCriticalVerificationResults(TVerificationResultCollection AVerificationResult, string AMessage = "")
        {
            string VerificationResultStr;

            if ((AMessage != String.Empty) &&
                (!AMessage.EndsWith(" ")))
            {
                AMessage = AMessage + " ";
            }

            if (!TVerificationHelper.IsNullOrOnlyNonCritical(AVerificationResult))
            {
                VerificationResultStr = AVerificationResult.BuildVerificationResultString();

                TLogging.Log(VerificationResultStr);

                Assert.Fail(AMessage + "*** TVerificationResult HAS CRITICAL ERRORS *** : " +
                            VerificationResultStr);
            }
        }
Пример #12
0
        public static bool MaintainBankAccounts(
            string action,
            Int32 ABankingDetailsKey,
            Int64 APartnerKey,
            string AAccountName,
            string AIban,
            out TVerificationResultCollection AVerificationResult)
        {
            List <string>  Dummy1, Dummy2;
            string         Dummy3, Dummy4, Dummy5;
            PartnerEditTDS MainDS = GetPartnerDetails(APartnerKey, out Dummy1, out Dummy2, out Dummy3, out Dummy4, out Dummy5);

            AVerificationResult = new TVerificationResultCollection();

            AIban = AIban.Replace(" ", "");
            string BIC      = String.Empty;
            string BankName = String.Empty;

            if ((action == "create" || action == "edit"))
            {
                // Validate IBAN, and calculate the BIC
                if (!ValidateIBAN(AIban, out BIC, out BankName, out AVerificationResult))
                {
                    return(false);
                }
            }

            if (action == "create")
            {
                PartnerEditTDSPBankingDetailsRow row = MainDS.PBankingDetails.NewRowTyped();
                row.BankingDetailsKey = -1;
                row.BankingType       = 0; // BANK ACCOUNT
                row.AccountName       = AAccountName;
                row.Iban        = AIban;
                row.BankKey     = FindOrCreateBank(BIC, BankName);
                row.MainAccount = MainDS.PBankingDetails.Count == 0;
                MainDS.PBankingDetails.Rows.Add(row);

                PPartnerBankingDetailsRow pdrow = MainDS.PPartnerBankingDetails.NewRowTyped();
                pdrow.PartnerKey        = APartnerKey;
                pdrow.BankingDetailsKey = -1;
                MainDS.PPartnerBankingDetails.Rows.Add(pdrow);

                DataSet ResponseDS = new PartnerEditTDS();
                TPartnerEditUIConnector uiconnector = new TPartnerEditUIConnector(APartnerKey);

                try
                {
                    TSubmitChangesResult result = uiconnector.SubmitChanges(
                        ref MainDS,
                        ref ResponseDS,
                        out AVerificationResult);

                    return(result == TSubmitChangesResult.scrOK);
                }
                catch (Exception e)
                {
                    TLogging.Log(e.ToString());
                    AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical));
                    return(false);
                }
            }
            else if (action == "edit")
            {
                foreach (PartnerEditTDSPBankingDetailsRow row in MainDS.PBankingDetails.Rows)
                {
                    if (row.BankingDetailsKey == ABankingDetailsKey)
                    {
                        row.AccountName = AAccountName;
                        row.Iban        = AIban;
                        row.BankKey     = FindOrCreateBank(BIC, BankName);
                    }
                }

                DataSet ResponseDS = new PartnerEditTDS();
                TPartnerEditUIConnector uiconnector = new TPartnerEditUIConnector(APartnerKey);

                try
                {
                    TSubmitChangesResult result = uiconnector.SubmitChanges(
                        ref MainDS,
                        ref ResponseDS,
                        out AVerificationResult);

                    return(result == TSubmitChangesResult.scrOK);
                }
                catch (Exception e)
                {
                    TLogging.Log(e.ToString());
                    AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical));
                    return(false);
                }
            }
            else if (action == "delete")
            {
                foreach (PPartnerBankingDetailsRow row in MainDS.PPartnerBankingDetails.Rows)
                {
                    if (row.BankingDetailsKey == ABankingDetailsKey)
                    {
                        row.Delete();
                    }
                }

                bool wasMainAccount = false;
                PartnerEditTDSPBankingDetailsRow otherAccount = null;
                foreach (PartnerEditTDSPBankingDetailsRow row in MainDS.PBankingDetails.Rows)
                {
                    if (row.BankingDetailsKey == ABankingDetailsKey)
                    {
                        if (!row.IsMainAccountNull())
                        {
                            wasMainAccount = row.MainAccount;
                        }
                        row.Delete();
                    }
                    else if (otherAccount == null)
                    {
                        otherAccount = row;
                    }
                }

                // make another bank account the main account
                if (wasMainAccount && (otherAccount != null))
                {
                    otherAccount.MainAccount = true;
                }

                DataSet ResponseDS = new PartnerEditTDS();
                TPartnerEditUIConnector uiconnector = new TPartnerEditUIConnector(APartnerKey);

                try
                {
                    TSubmitChangesResult result = uiconnector.SubmitChanges(
                        ref MainDS,
                        ref ResponseDS,
                        out AVerificationResult);

                    return(result == TSubmitChangesResult.scrOK);
                }
                catch (Exception e)
                {
                    TLogging.Log(e.ToString());
                    AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical));
                    return(false);
                }
            }

            if (!TVerificationHelper.IsNullOrOnlyNonCritical(AVerificationResult))
            {
                TLogging.Log(AVerificationResult.BuildVerificationResultString());
            }

            return(false);
        }
Пример #13
0
        private void ResetPassword(Object Sender, EventArgs e)
        {
            TVerificationResultCollection VerificationResultCollection = null;
            string OneTimePassword = String.Empty;
            bool   RandomSecurePasswordUtilised = false;

            if (FPreviouslySelectedDetailRow == null)
            {
                return;
            }

            if (FPetraUtilsObject.HasChanges)
            {
                MessageBox.Show(
                    Catalog.GetString("It is necessary to save any changes before a user's password can be changed." +
                                      Environment.NewLine + "Please save changes now and then repeat the operation."),
                    CommonDialogsResourcestrings.StrResetUserPasswordTitle,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Stop);
                return;
            }

            string username = GetSelectedDetailRow().UserId;

            var UserChoice = MessageBox.Show(Catalog.GetString(
                                                 "The resetting of a User Password requires the creation of a one-time password that the user will need to enter.\r\n" +
                                                 "OpenPetra can generate a 'random secure' password for this purpose (recommended!). Alternatively, you can come up with such a password manually.\r\n\r\nCreate 'random secure' User Password?"),
                                             Catalog.GetString("User Password Reset"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
                                             MessageBoxDefaultButton.Button1);

            switch (UserChoice)
            {
            case DialogResult.Yes:
                OneTimePassword = TPasswordHelper.GetRandomSecurePassword();
                RandomSecurePasswordUtilised = true;

                break;

            case DialogResult.No:
                // only request the password once, since this is the sysadmin changing it.
                // see http://bazaar.launchpad.net/~openpetracore/openpetraorg/trunkhosted/view/head:/csharp/ICT/Petra/Client/MSysMan/Gui/SysManMain.cs
                // for the change password dialog for the normal user
                PetraInputBox input = new PetraInputBox(
                    CommonDialogsResourcestrings.StrResetUserPasswordTitle,
                    String.Format(Catalog.GetString("Please enter a one-time password for user {0}:"), username),
                    "", true);

                if (input.ShowDialog() == DialogResult.OK)
                {
                    OneTimePassword = input.GetAnswer();

                    break;
                }
                else
                {
                    ShowResettingOfUserPwdCancelledMessage();

                    return;
                }

            case DialogResult.Cancel:
                ShowResettingOfUserPwdCancelledMessage();

                return;
            }

            try
            {
                this.Cursor = Cursors.WaitCursor;
                Application.DoEvents();  // give Windows a chance to update the Cursor

                // Save the new password (server-side checks get performed)
                if (TRemote.MSysMan.Maintenance.WebConnectors.SetUserPassword(username, OneTimePassword, true, true,
                                                                              TClientInfo.ClientComputerName, TClientInfo.ClientIPAddress,
                                                                              out VerificationResultCollection))
                {
                    MessageBox.Show(String.Format(Catalog.GetString(CommonDialogsResourcestrings.StrChangePasswordSuccess +
                                                                    Environment.NewLine +
                                                                    (RandomSecurePasswordUtilised ? Catalog.GetString(
                                                                         "The 'random secure' password will get copied to the clipboard after you have closed this message. Follow the steps lined out in the next message!")
                                                                     +
                                                                     Environment.NewLine : String.Empty) +
                                                                    Environment.NewLine +
                                                                    "(The user must change the new password for a password of his/her choice the next time (s)he logs on.)"),
                                                  username), CommonDialogsResourcestrings.StrResetUserPasswordTitle,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);

                    if (RandomSecurePasswordUtilised)
                    {
                        CopyPasswordIntoClipboard(OneTimePassword);
                    }

                    // This has been saved on the server so my data is out-of-date - re-loading needed to get new
                    // ModificationId etc:
                    FPreviouslySelectedDetailRow = null;
                    Int32 rowIdx = GetSelectedRowIndex();

                    LoadUsers();

                    grdDetails.SelectRowInGrid(rowIdx);
                }
                else
                {
                    MessageBox.Show(String.Format(CommonDialogsResourcestrings.StrChangePasswordError, username) +
                                    Environment.NewLine + Environment.NewLine +
                                    VerificationResultCollection.BuildVerificationResultString(),
                                    CommonDialogsResourcestrings.StrResetUserPasswordTitle,
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Пример #14
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 ExportBatches(object sender, EventArgs e)
        {
            if (File.Exists(txtFilename.Text))
            {
                if (MessageBox.Show(Catalog.GetString("The file already exists. Is it OK to overwrite it?"),
                                    Catalog.GetString("Export Gifts"),
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            StreamWriter sw1 = null;

            try
            {
                sw1 = new StreamWriter(txtFilename.Text,
                                       false,
                                       Encoding.GetEncoding(TAppSettingsManager.GetInt32("ExportGiftBatchEncoding", 1252)));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                Catalog.GetString("Failed to open file"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            try
            {
                if (rbtBatchNumberSelection.Checked)
                {
                    if (!txtBatchNumberStart.NumberValueInt.HasValue)
                    {
                        txtBatchNumberStart.NumberValueInt = 0;
                    }

                    if (!txtBatchNumberEnd.NumberValueInt.HasValue)
                    {
                        txtBatchNumberEnd.NumberValueInt = 999999;
                    }
                }
                else
                {
                    if ((dtpDateFrom.Text == "") || (dtpDateTo.Text == ""))
                    {
                        MessageBox.Show(Catalog.GetString("Start and end dates must be provided."),
                                        Catalog.GetString("Error"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }

                    if ((!dtpDateFrom.ValidDate()) || (!dtpDateTo.ValidDate()))  // If ValidDate fails, it displays a helpful message.
                    {
                        return;
                    }
                }

                String numberFormat = ConvertNumberFormat(cmbNumberFormat);
                String delimiter    = ConvertDelimiter(cmbDelimiter.GetSelectedString(), false);

                if (((numberFormat == "European") && (delimiter == ",")) || ((numberFormat == "American") && (delimiter == ".")))
                {
                    MessageBox.Show(Catalog.GetString("Numeric Decimal cannot be the same as the delimiter."),
                                    Catalog.GetString("Error"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }

                Hashtable requestParams = new Hashtable();
                requestParams.Add("ALedgerNumber", FLedgerNumber);
                requestParams.Add("Delimiter", ConvertDelimiter(cmbDelimiter.GetSelectedString(), false));
                requestParams.Add("DateFormatString", cmbDateFormat.GetSelectedString());
                requestParams.Add("Summary", rbtSummary.Checked);
                requestParams.Add("IncludeUnposted", chkIncludeUnposted.Checked);
                requestParams.Add("bUseBaseCurrency", rbtBaseCurrency.Checked);
                requestParams.Add("TransactionsOnly", chkTransactionsOnly.Checked);
                requestParams.Add("RecipientNumber", Convert.ToInt64(txtDetailRecipientKey.Text));
                requestParams.Add("FieldNumber", Convert.ToInt64(txtDetailFieldKey.Text));
                requestParams.Add("DateForSummary", dtpDateSummary.Date);
                requestParams.Add("NumberFormat", ConvertNumberFormat(cmbNumberFormat));
                requestParams.Add("ExtraColumns", chkExtraColumns.Checked);

                if (rbtBatchNumberSelection.Checked)
                {
                    requestParams.Add("BatchNumberStart", txtBatchNumberStart.NumberValueInt);
                    requestParams.Add("BatchNumberEnd", txtBatchNumberEnd.NumberValueInt);
                }
                else
                {
                    requestParams.Add("BatchDateFrom", dtpDateFrom.Date);
                    requestParams.Add("BatchDateTo", dtpDateTo.Date);
                }

                TVerificationResultCollection AMessages = new TVerificationResultCollection();
                String exportString = null;
                Int32  BatchCount   = 0;

                Thread ExportThread = new Thread(() => ExportAllGiftBatchData(
                                                     requestParams,
                                                     out exportString,
                                                     out AMessages,
                                                     out BatchCount));

                using (TProgressDialog ExportDialog = new TProgressDialog(ExportThread))
                {
                    ExportDialog.ShowDialog();
                }

                if ((AMessages != null) &&
                    (AMessages.Count > 0))
                {
                    if (!TVerificationHelper.IsNullOrOnlyNonCritical(AMessages))
                    {
                        MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Error"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Warnings"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                }

                if (BatchCount == 0)
                {
                    MessageBox.Show(Catalog.GetString("There are no batches matching your criteria"),
                                    Catalog.GetString("Error"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }

                sw1.Write(exportString);
                sw1.Close();

                SaveUserDefaults();
                MessageBox.Show(Catalog.GetString("Gift Batches Exported successfully."),
                                Catalog.GetString("Gift Batch Export"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                TLogging.Log("GiftBatchExport.ManualCode: " + ex.ToString());
                MessageBox.Show(ex.Message,
                                Catalog.GetString("Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            finally
            {
                sw1.Close();
            }
        }
Пример #15
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>
        /// <returns>True if the Export succeeded and a file was created, false otherwise</returns>
        public bool ExportBatches(bool AWithInteractionOnSuccess = true)
        {
            string ExportFileName = txtFilename.Text;

            if (ExportFileName == String.Empty)
            {
                MessageBox.Show(Catalog.GetString("Please choose a location for the Export File."),
                                Catalog.GetString("Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }
            else if (!ExportFileName.EndsWith(".csv",
                                              StringComparison.CurrentCultureIgnoreCase) && !ExportFileName.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase))
            {
                ExportFileName  += ".csv";
                txtFilename.Text = ExportFileName;
            }

            if (!Directory.Exists(Path.GetDirectoryName(ExportFileName)))
            {
                MessageBox.Show(Catalog.GetString("Please select an existing directory for this file!"),
                                Catalog.GetString("Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                txtFilename.Text = string.Empty;
                return(false);
            }

            if (File.Exists(ExportFileName))
            {
                if (MessageBox.Show(Catalog.GetString("The file already exists. Is it OK to overwrite it?"),
                                    Catalog.GetString("Export Gifts"),
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No)
                {
                    return(false);
                }

                try
                {
                    File.Delete(ExportFileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format(
                                        Catalog.GetString(
                                            "Failed to delete the file. Maybe it is already open in another application?  The system message was:{0}{1}"),
                                        Environment.NewLine, ex.Message),
                                    Catalog.GetString("Export Gift Batches"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return(false);
                }
            }

            if (rbtBatchNumberSelection.Checked)
            {
                if (!txtBatchNumberStart.NumberValueInt.HasValue)
                {
                    txtBatchNumberStart.NumberValueInt = 0;
                }

                if (!txtBatchNumberEnd.NumberValueInt.HasValue)
                {
                    txtBatchNumberEnd.NumberValueInt = 999999;
                }
            }
            else
            {
                if ((dtpDateFrom.Text == string.Empty) || (dtpDateTo.Text == string.Empty))
                {
                    MessageBox.Show(Catalog.GetString("Start and end dates must be provided."),
                                    Catalog.GetString("Error"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return(false);
                }

                if ((!dtpDateFrom.ValidDate()) || (!dtpDateTo.ValidDate()))  // If ValidDate fails, it displays a helpful message.
                {
                    return(false);
                }
            }

            String numberFormat = ConvertNumberFormat(cmbNumberFormat);
            String delimiter    = ConvertDelimiter(cmbDelimiter.GetSelectedString(), false);

            if (((numberFormat == "European") && (delimiter == ",")) || ((numberFormat == "American") && (delimiter == ".")))
            {
                MessageBox.Show(Catalog.GetString("Numeric Decimal cannot be the same as the delimiter."),
                                Catalog.GetString("Error"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }

            try
            {
                Hashtable requestParams = new Hashtable();
                requestParams.Add("ALedgerNumber", FLedgerNumber);
                requestParams.Add("Delimiter", delimiter);
                requestParams.Add("DateFormatString", cmbDateFormat.GetSelectedString());
                requestParams.Add("Summary", rbtSummary.Checked);
                requestParams.Add("IncludeUnposted", chkIncludeUnposted.Checked);
                requestParams.Add("bUseBaseCurrency", rbtBaseCurrency.Checked);
                requestParams.Add("TransactionsOnly", chkTransactionsOnly.Checked);
                requestParams.Add("RecipientNumber", Convert.ToInt64(txtDetailRecipientKey.Text));
                requestParams.Add("FieldNumber", Convert.ToInt64(txtDetailFieldKey.Text));
                requestParams.Add("DateForSummary", dtpDateSummary.Date);
                requestParams.Add("NumberFormat", numberFormat);
                requestParams.Add("ExtraColumns", chkExtraColumns.Checked);

                if (rbtBatchNumberSelection.Checked)
                {
                    requestParams.Add("BatchNumberStart", txtBatchNumberStart.NumberValueInt);
                    requestParams.Add("BatchNumberEnd", txtBatchNumberEnd.NumberValueInt);
                }
                else
                {
                    requestParams.Add("BatchDateFrom", dtpDateFrom.Date);
                    requestParams.Add("BatchDateTo", dtpDateTo.Date);
                }

                TVerificationResultCollection AMessages = new TVerificationResultCollection();
                String exportString = null;
                Int32  BatchCount   = 0;

                Thread ExportThread = new Thread(() => ExportAllGiftBatchData(
                                                     requestParams,
                                                     out exportString,
                                                     out AMessages,
                                                     out BatchCount));

                using (TProgressDialog ExportDialog = new TProgressDialog(ExportThread))
                {
                    ExportDialog.ShowDialog();
                }

                if ((AMessages != null) &&
                    (AMessages.Count > 0))
                {
                    if (!TVerificationHelper.IsNullOrOnlyNonCritical(AMessages))
                    {
                        MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Error"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return(false);
                    }
                    else
                    {
                        MessageBox.Show(AMessages.BuildVerificationResultString(), Catalog.GetString("Warnings"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                }

                SaveUserDefaults();

                //Process BatchCount value
                if (BatchCount == 0)
                {
                    MessageBox.Show(Catalog.GetString("There are no batches matching your criteria"),
                                    Catalog.GetString("Export"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                    return(false);
                }
                else if (BatchCount == -1)
                {
                    MessageBox.Show(Catalog.GetString("Gift batch export cancelled"),
                                    Catalog.GetString("Export"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    return(false);
                }
                else if (BatchCount == -2)
                {
                    MessageBox.Show(Catalog.GetString("Gift batch export failed"),
                                    Catalog.GetString("Export"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                    return(false);
                }

                StreamWriter sw1 = new StreamWriter(ExportFileName,
                                                    false,
                                                    Encoding.GetEncoding(TAppSettingsManager.GetInt32("ExportGiftBatchEncoding", 1252)));
                sw1.Write(exportString);
                sw1.Close();
            }
            catch (Exception ex)
            {
                TLogging.LogException(ex, Utilities.GetMethodSignature());
                throw;
            }

            bool ShowExportedFileInExplorer = false;

            if (AWithInteractionOnSuccess)
            {
                if (MessageBox.Show(Catalog.GetString(
                                        "Gift Batches Exported successfully. Would you like to open the file in your default application?"),
                                    Catalog.GetString("Gift Batch Export"),
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Information,
                                    MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
                {
                    try
                    {
                        ProcessStartInfo si = new ProcessStartInfo(ExportFileName);
                        si.UseShellExecute = true;
                        si.Verb            = "open";

                        Process p = new Process();
                        p.StartInfo = si;
                        p.Start();
                    }
                    catch
                    {
                        MessageBox.Show(Catalog.GetString(
                                            "Unable to launch the default application to open: '") + ExportFileName + "'!", Catalog.GetString(
                                            "Gift Export"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                        ShowExportedFileInExplorer = true;
                    }
                }
            }
            else
            {
                ShowExportedFileInExplorer = true;
            }

            if (ShowExportedFileInExplorer)
            {
                //If windows start Windows File Explorer
                TExecutingOSEnum osVersion = Utilities.DetermineExecutingOS();

                if ((osVersion >= TExecutingOSEnum.eosWinXP) &&
                    (osVersion < TExecutingOSEnum.oesUnsupportedPlatform))
                {
                    try
                    {
                        Process.Start("explorer.exe", string.Format("/select,\"{0}\"", ExportFileName));
                    }
                    catch
                    {
                        MessageBox.Show(Catalog.GetString(
                                            "Unable to launch Windows File Explorer to open: '") + ExportFileName + "'!", Catalog.GetString(
                                            "Gift Export"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }

            return(true);
        }