private void grdCommitmentStatusChoices_ReadControls(TRptCalculator ACalc, TReportActionEnum AReportAction)
        {
            // TODO
            //   The reason that the status choices listbox is not
            //   filled in with saved data is that Parameter.Save()
            //   and Parameter.Load() do not use
            //   TVariant.EncodeToString() and
            //   TVariant.DecodeFromString() when storing a saved set
            //   of parameters. Composites survive fine over the
            //   remoting interface, though. I (binki) am allowed to
            //   change the behavior of TParameterList.Save() and
            //   TParameterList.Load() _if_ I change the
            //   XmlReports/Settings/.../standard.xml files to support
            //   DecodeFromString().
            TVariant param_grdCommitmentStatusChoices = new TVariant();

            foreach (DataRow ARow in FCommitmentStatusTable.Rows)
            {
                if ((bool)ARow["Selection"])
                {
                    param_grdCommitmentStatusChoices.Add(new TVariant((String)ARow[PmCommitmentStatusTable.GetCodeDBName()]), "", false);
                }
            }

            ACalc.AddParameter("param_commitment_status_choices", param_grdCommitmentStatusChoices);
        }
Exemplo n.º 2
0
        public static List <TVariant>TestPostGLBatch(Int32 ALedgerNumber, Int32 ABatchNumber, out TVerificationResultCollection AVerifications)
        {
            GLPostingTDS MainDS = null;
            TVerificationResultCollection Verifications = null;

            int BatchPeriod = -1;

            TDBTransaction Transaction = null;
            bool SubmissionOK = false;
            bool Success = false;

            DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable,
                ref Transaction,
                ref SubmissionOK,
                delegate
                {
                    Success = TGLPosting.TestPostGLBatch(ALedgerNumber,
                        ABatchNumber,
                        Transaction,
                        out Verifications,
                        out MainDS,
                        ref BatchPeriod);
                });

            AVerifications = Verifications;

            List <TVariant>Result = new List <TVariant>();

            if (Success)
            {
                MainDS.AGeneralLedgerMaster.DefaultView.RowFilter = string.Empty;
                MainDS.AAccount.DefaultView.RowFilter = string.Empty;
                MainDS.ACostCentre.DefaultView.RowFilter = string.Empty;
                MainDS.AGeneralLedgerMaster.DefaultView.Sort = AGeneralLedgerMasterTable.GetGlmSequenceDBName();
                MainDS.ACostCentre.DefaultView.Sort = ACostCentreTable.GetCostCentreCodeDBName();
                MainDS.AAccount.DefaultView.Sort = AAccountTable.GetAccountCodeDBName();

                foreach (AGeneralLedgerMasterPeriodRow glmpRow in MainDS.AGeneralLedgerMasterPeriod.Rows)
                {
                    if ((glmpRow.PeriodNumber == BatchPeriod) && (glmpRow.RowState != DataRowState.Unchanged))
                    {
                        AGeneralLedgerMasterRow masterRow =
                            (AGeneralLedgerMasterRow)MainDS.AGeneralLedgerMaster.Rows.Find(glmpRow.GlmSequence);

                        ACostCentreRow ccRow = (ACostCentreRow)MainDS.ACostCentre.Rows.Find(new object[] { ALedgerNumber, masterRow.CostCentreCode });

                        // only consider the posting cost centres
                        // TODO or consider only the top cost centre?
                        if (ccRow.PostingCostCentreFlag)
                        {
                            AAccountRow accRow =
                                (AAccountRow)
                                MainDS.AAccount.DefaultView[MainDS.AAccount.DefaultView.Find(masterRow.AccountCode)].Row;

                            // only modified accounts have been loaded to the dataset, therefore report on all accounts available
                            if (accRow.PostingStatus)
                            {
                                decimal CurrentValue = 0.0m;

                                if (glmpRow.RowState == DataRowState.Modified)
                                {
                                    CurrentValue = (decimal)glmpRow[AGeneralLedgerMasterPeriodTable.ColumnActualBaseId, DataRowVersion.Original];
                                }

                                decimal DebitCredit = 1.0m;

                                if (accRow.DebitCreditIndicator
                                    && (accRow.AccountType != MFinanceConstants.ACCOUNT_TYPE_ASSET)
                                    && (accRow.AccountType != MFinanceConstants.ACCOUNT_TYPE_EXPENSE))
                                {
                                    DebitCredit = -1.0m;
                                }

                                // only return values, the client compiles the message, with Catalog.GetString
                                TVariant values = new TVariant(accRow.AccountCode);
                                values.Add(new TVariant(accRow.AccountCodeShortDesc), "", false);
                                values.Add(new TVariant(ccRow.CostCentreCode), "", false);
                                values.Add(new TVariant(ccRow.CostCentreName), "", false);
                                values.Add(new TVariant(CurrentValue * DebitCredit), "", false);
                                values.Add(new TVariant(glmpRow.ActualBase * DebitCredit), "", false);

                                Result.Add(values);
                            }
                        }
                    }
                }
            }

            return Result;
        }
Exemplo n.º 3
0
        public void TestVariantComposite()
        {
            CultureInfo oldCulture;
            TVariant v;
            TVariant v2;
            TVariant v3;
            String encodedString;
            String s;

            oldCulture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB", false);
            v = new TVariant("test");
            Assert.AreEqual("eString:test", v.EncodeToString(), "before EncodeToString1");
            v.Add(new TVariant(true));
            Assert.AreEqual("eComposite::\"eString:test|eBoolean:true\"", v.EncodeToString(), "EncodeToString1");
            v.Add(new TVariant(2.23M, "Currency"));
            v.Add(new TVariant(2.23M));
            v.Add(new TVariant(2));
            Assert.AreEqual(
                "eComposite::\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2\"",
                v.EncodeToString(),
                "EncodeToString2");
            v.Add(new TVariant(" test "));
            Assert.AreEqual(
                "eComposite::\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|eString: test \"",
                v.EncodeToString(),
                "EncodeToString3");
            v.Add(new TVariant(new DateTime(2004, 03, 29)));
            v2 = new TVariant(v); // copy constructor
            Assert.AreEqual(
                "eComposite::\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|eString: test |\"\"eDateTime:\"\"\"\"2004-03-29T00:00:00\"\"\"\"\"\"\"",
                v2.EncodeToString(),
                "EncodeToString4");
            Assert.AreEqual("eComposite::\"eString:test|eBoolean:true\"", TVariant.DecodeFromString(
                    "eComposite::\"eString:test|eBoolean:true\"").EncodeToString(), "DecodeFromString");
            Assert.AreEqual("eComposite::\"eString: test |eBoolean:true\"", TVariant.DecodeFromString(
                    "eComposite::\"eString: test |eBoolean:true\"").EncodeToString(), "DecodeFromString with spaces in string");
            Assert.AreEqual(v2.EncodeToString(), TVariant.DecodeFromString(v2.EncodeToString()).EncodeToString(), "DecodeFromString2");
            v = new TVariant();
            v.Add(new TVariant(2));
            Assert.AreEqual(2.00, v.ToDouble(), "Variant Composite Double");
            v.Add(new TVariant(" test "));
            v3 = new TVariant();
            v3.Add(new TVariant(1));
            v3.Add(v);
            v3.Add(v2);
            s =
                "eInteger:1|\"eComposite::\"\"eInteger:2|\"\"\"\"eString:\"\"\"\"\"\"\"\" test \"\"\"\"\"\"\"\"\"\"\"\"\"\"\"|\"eComposite::\"\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|\"\"\"\"eString:\"\"\"\"\"\"\"\" test \"\"\"\"\"\"\"\"\"\"\"\"|\"\"\"\"eDateTime:\"\"\"\"\"\"\"\"2004-03-29T00:00:00\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"";
            Assert.AreEqual("eInteger:1", StringHelper.GetNextCSV(ref s, "|"), "split composite CSV 1");
            Assert.AreEqual("eComposite::\"eInteger:2|\"\"eString:\"\"\"\" test \"\"\"\"\"\"\"", StringHelper.GetNextCSV(ref s,
                    "|"), "split composite CSV 2");
            Assert.AreEqual(
                "\"eComposite::\"\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|\"\"\"\"eString:\"\"\"\"\"\"\"\" test \"\"\"\"\"\"\"\"\"\"\"\"|\"\"\"\"eDateTime:\"\"\"\"\"\"\"\"2004-03-29T00:00:00\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"",
                s,
                "split composite CSV 4");
            Assert.AreEqual(
                "eComposite::\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|\"\"eString:\"\"\"\" test \"\"\"\"\"\"|\"\"eDateTime:\"\"\"\"2004-03-29T00:00:00\"\"\"\"\"\"\"",
                StringHelper.GetNextCSV(ref s, "|"),
                "split composite CSV 6");
            Assert.AreEqual(
                "eComposite::\"eInteger:1|\"\"eComposite::\"\"\"\"eInteger:2|eString: test \"\"\"\"\"\"|\"\"eComposite::\"\"\"\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|eString: test |\"\"\"\"\"\"\"\"eDateTime:\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"2004-03-29T00:00:00\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"",
                v3.EncodeToString(),
                "EncodeToString1 with Composite containing Composite");
            Assert.AreEqual(v3.EncodeToString(), TVariant.DecodeFromString(
                    v3.EncodeToString()).EncodeToString(), "DecodeFromString with Composite containing Composite");
            v = new TVariant();
            v.Add(new TVariant(2));
            v.Add(new TVariant(" test"));
            v3 = new TVariant();
            v3.Add(v);
            v3.Add(v2);
            Assert.AreEqual(
                "eComposite::\"eInteger:2|eString: test|\"\"eComposite::\"\"\"\"eString:test|eBoolean:true|eCurrency:Currency:4612203932384535511|eDecimal:4612203932384535511|eInteger:2|eString: test |\"\"\"\"\"\"\"\"eDateTime:\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"2004-03-29T00:00:00\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"",
                v3.EncodeToString(),
                "EncodeToString2 with Composite containing Composite");
            Assert.AreEqual(v3.EncodeToString(), TVariant.DecodeFromString(
                    v3.EncodeToString()).EncodeToString(), "DecodeFromString with Composite containing Composite");
            v = new TVariant("test\"1");
            v.Add(new TVariant(" test\"2"));
            v2 = new TVariant("test\"3");
            v2.Add(new TVariant("test\"4"));
            Assert.AreEqual("eString:\"test\"\"3test\"\"4\"", v2.EncodeToString(), "Test Cascading Composite 1");
            Assert.AreEqual("eString:\"test\"\"3test\"\"4\"", TVariant.DecodeFromString(
                    v2.EncodeToString()).EncodeToString(), "Test Cascading Composite 2");
            v.Add(v2);
            Assert.AreEqual("eString:\"test\"\"1 test\"\"2test\"\"3test\"\"4\"", v.EncodeToString(), "Test Cascading Composite 3");
            Assert.AreEqual("eString:\"test\"\"1 test\"\"2test\"\"3test\"\"4\"", TVariant.DecodeFromString(
                    v.EncodeToString()).EncodeToString(), "Test Cascading Composite 4");
            v = new TVariant("test1\"");
            v.Add(new TVariant(" test2\""));
            v2 = new TVariant();
            v2.Add(new TVariant("2900"));
            v.Add(v2);
            v.Add(new TVariant("test3"));
            Assert.AreEqual("eComposite::\"\"\"eString:\"\"\"\"test1\"\"\"\"\"\"\"\" test2\"\"\"\"\"\"\"\"\"\"\"\"\"\"|eInteger:2900|eString:test3\"",
                v.EncodeToString(), "Test Cascading Composite2");
            Assert.AreEqual("eString:\"\"\" )  ))\"", TVariant.DecodeFromString("eString:\"\"\" )  ))\"").EncodeToString(), "problem decoding string");
            v = new TVariant();
            v.Add(new TVariant("test\""));
            v.Add(new TVariant("2900"));
            v.Add(new TVariant("test"));
            Assert.AreEqual("eComposite::\"\"\"eString:\"\"\"\"test\"\"\"\"\"\"\"\"\"\"\"\"\"\"|eInteger:2900|eString:test\"",
                v.EncodeToString(), "problem encoding 1b");
            Assert.AreEqual(v.EncodeToString(), TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(), "problem encoding1a");
            v = new TVariant();
            v.Add(new TVariant("SELECT DISTINCT  WHERE (  ( cc.a_cost_centre_code_c = \""));
            v.Add(new TVariant("2900"));
            v.Add(new TVariant("\" )  ))"));
            encodedString = "eComposite::\"\"\"eString:\"\"\"\"SELECT DISTINCT " +
                            " WHERE (  ( cc.a_cost_centre_code_c = \"\"\"\"\"\"\"\"\"\"\"\"\"\"|eInteger:2900|\"\"eString:\"\"\"\"\"\"\"\"\"\"\"\" )  ))\"\"\"\"\"\"\"";
            Assert.AreEqual(encodedString, v.EncodeToString(), "problem encoding1");
            Assert.AreEqual(v.EncodeToString(), TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(), "problem encoding2");
            Assert.AreEqual(encodedString, TVariant.DecodeFromString(encodedString).EncodeToString(), "problem encoding3");
            v = new TVariant();
            v.Add(new TVariant("29001234", "partnerkey"));
            v.Add(new TVariant("29001235", "partnerkey"));
            v.Add(new TVariant("29001236", "partnerkey"));
            v.FormatString = "csvlistslash";
            Assert.AreEqual("eComposite:csvlistslash:\"eInteger:partnerkey:29001234|eInteger:partnerkey:29001235|eInteger:partnerkey:29001236\"",
                v.EncodeToString(),
                "format list with slash separator 1");
            Assert.AreEqual("0029001234/0029001235/0029001236", v.ToFormattedString(""), "format list with slash separator 2");
            v = new TVariant(435082450);
            Assert.AreEqual("eInteger:435082450", v.EncodeToString(), "test integer with text format 1");
            v.ApplyFormatString("text");
            Assert.AreEqual("eString:text:435082450", v.EncodeToString(), "test integer with text format 2");
            Assert.AreEqual("eString:text:435082450", TVariant.DecodeFromString(
                    v.EncodeToString()).EncodeToString(), "test integer with text format 3");
            v2 = new TVariant(v);
            Assert.AreEqual("eString:text:435082450", v2.EncodeToString(), "test integer with text format 4");
            v = new TVariant();
            v.Add(new TVariant((Object)(29015041.0)));
            v.Add(new TVariant((Object)(29017453.0)));
            Assert.AreEqual("eComposite:Currency:\"eCurrency:Currency:4718553875991232512|eCurrency:Currency:4718554523457552384\"",
                v.EncodeToString(), "test composite partner key");
            Assert.AreEqual("eComposite:Currency:\"eCurrency:Currency:4718553875991232512|eCurrency:Currency:4718554523457552384\"",
                TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(),
                "test composite partner key 4");
            v.ApplyFormatString("csvlistslash:partnerkey");
            Assert.AreEqual("eComposite:csvlistslash:\"eInt64:partnerkey:29015041|eInt64:partnerkey:29017453\"",
                v.EncodeToString(), "test composite partner key 2");
            Assert.AreEqual("0029015041/0029017453", v.ToFormattedString(" "), "test composite partner key 3");
            v = TVariant.DecodeFromString("eComposite:csvlistslash:\"eString:text:de Vries, Rianne|eString:text:Visser, W. and K.K.J.\"");
            Assert.AreEqual("de Vries, Rianne/Visser, W. and K.K.J.", v.ToFormattedString(""));
            Assert.AreEqual("de Vries, Rianne/Visser, W. and K.K.J.", v.ToFormattedString("", "CSV"));
            v = new TVariant();
            v.Add(new TVariant("From Gift-Batch#: "));
            v.Add(new TVariant(8351));
            Assert.AreEqual("From Gift-Batch#: 8351", v.ToFormattedString(""), "colon in text");
            Assert.AreEqual("eComposite::\"\"\"eString:\"\"\"\"From Gift-Batch#: \"\"\"\"\"\"|eInteger:8351\"", v.EncodeToString(), "colon in text2");
            Assert.AreEqual("From Gift-Batch#: 8351", TVariant.DecodeFromString(v.EncodeToString()).ToFormattedString(""), "colon in text3");
            v = new TVariant();
            v.Add(new TVariant("Total for Account "));
            v.Add(new TVariant(1000));
            v.Add(new TVariant(':'));
            Assert.AreEqual("Total for Account 1000:", v.ToFormattedString(), "colon in text on its own");
            Assert.AreEqual(v.EncodeToString(), TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(), "colon in text on its own 2");
            Assert.AreEqual(TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(),
                v.EncodeToString(), "Composite with two empty strings encoding decoding encoding");
            v = new TVariant();
            v.Add(new TVariant("t"), "", false);
            v.Add(new TVariant("|"), "", false);
            Assert.AreEqual("eComposite::\"eString:t|\"\"eString:|\"\"\"",
                v.EncodeToString(), "Composite with pipe encoding");
            Assert.AreEqual(TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(),
                v.EncodeToString(), "Composite with pipe encoding decoding encoding");
            v = new TVariant("", true);
            Assert.AreEqual("eString:text:", v.EncodeToString(), "empty string encoding");
            Assert.AreEqual(v.EncodeToString(), TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(), "empty string decoding");
            Assert.AreEqual(v.ToString(), "", "empty string identity");
            Assert.AreEqual("", TVariant.DecodeFromString(v.EncodeToString()).ToString(), "empty string decoding identity");
            Assert.AreEqual(eVariantTypes.eString, TVariant.DecodeFromString(v.EncodeToString()).TypeVariant, "empty string decoding type");
            v = new TVariant(" ", true);
            Assert.AreEqual(v.ToString(), " ", "one-space string identity");
            Assert.AreEqual("eString:text: ", v.EncodeToString(), "one-space string encoding");
            Assert.AreEqual(v.EncodeToString(), TVariant.DecodeFromString(v.EncodeToString()).EncodeToString(), "one-space string decoding");
            Assert.AreEqual(" ", TVariant.DecodeFromString(v.EncodeToString()).ToString(), "one-space string decoding identity");
            Assert.AreEqual(eVariantTypes.eString, TVariant.DecodeFromString(v.EncodeToString()).TypeVariant, "one-space string decoding type");
            Thread.CurrentThread.CurrentCulture = oldCulture;
        }
Exemplo n.º 4
0
        public void TestVariantCurrencies()
        {
            CultureInfo oldCulture;
            ArrayList cultures;
            String DecimalSeparator;
            String ThousandsOperator;
            TVariant v;

            oldCulture = Thread.CurrentThread.CurrentCulture;
            cultures = new ArrayList();
            cultures.Add("en-GB");
            cultures.Add("en-US");
            cultures.Add("de-DE");

            /* opposite meaning of , and . */
            cultures.Add("ru-RU");

            /* funny thousand separator: space */
            foreach (string s in cultures)
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo(s, false);
                DecimalSeparator = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;
                ThousandsOperator = CultureInfo.CurrentCulture.NumberFormat.CurrencyGroupSeparator;
                Assert.AreEqual("#,##0;(#,##0);0;0", StringHelper.GetFormatString("Currency",
                        "CurrencyWithoutDecimals"), "find correct format string, CurrencyWithoutDecimals");
                Assert.AreEqual("#,#;(#,#);0;0", StringHelper.GetFormatString("Currency",
                        "CurrencyThousands"), "find correct format string thousands");
                Assert.AreEqual("#,##0.00;(#,##0.00);0.00;0", StringHelper.GetFormatString("", "Currency"), "Problem currency string");

                /* console.writeLine(CultureInfo.CurrentCulture.TwoLetterISOLanguageName); */
                Assert.AreEqual("0", new TVariant(0.00M, "Currency").ToFormattedString(
                        "CurrencyWithoutDecimals"), "format currency 0 without decimals");
                Assert.AreEqual("0", new TVariant(0.00M, "Currency").ToFormattedString("CurrencyThousands"), "format currency 0 thousands");
                Assert.AreEqual("0", new TVariant(0.00M, "->>>,>>>,>>>,>>9.99").ToFormattedString(
                        "CurrencyWithoutDecimals"), "format progress currency 0 without decimals");
                Assert.AreEqual("0", new TVariant(0.00M, "->>>,>>>,>>>,>>9.99").ToFormattedString(
                        "CurrencyThousands"), "format progress currency 0 thousands");
                Assert.AreEqual("", new TVariant("", true).ToFormattedString(
                        "Currency"), "format empty string in the column heading of a column that has currency values");
                Assert.AreEqual("eString:text:", new TVariant(new TVariant("",
                            true)).EncodeToString(), "format empty string in the column heading of a column that has currency values 2");
                Assert.AreEqual("", new TVariant(new TVariant("", true)).ToFormattedString(
                        "Currency"), "format empty string in the column heading of a column that has currency values 3");
                Assert.AreEqual("eString:text:", new TVariant("",
                        true).EncodeToString(), "format empty string in the column heading of a column that has currency values 4");
                v = new TVariant("", true);
                Assert.AreEqual("eString:text:",
                    v.EncodeToString(), "format empty string in the column heading of a column that has currency values 5");
                v = new TVariant();
                v.Add(new TVariant("", true));
                Assert.AreEqual("eEmpty:text:",
                    v.EncodeToString(), "format empty string in the column heading of a column that has currency values 6");
                Assert.AreEqual("", v.ToFormattedString(
                        "Currency"), "format empty string in the column heading of a column that has currency values 7");
                v = new TVariant();
                v.ApplyFormatString("partnerkey");
                Assert.AreEqual("eInt64:partnerkey:-1", v.EncodeToString(), "format empty partnerkey 1");
                Assert.AreEqual("0000000000", v.ToFormattedString(), "format empty partnerkey 2");
                v = new TVariant(0.00M, "Currency");
                v.ApplyFormatString("partnerkey");
                Assert.AreEqual("eInt64:partnerkey:0", v.EncodeToString(), "format empty partnerkey 3");
                Assert.AreEqual("0000000000", v.ToFormattedString(), "format empty partnerkey 4");
                Assert.AreEqual("100" + DecimalSeparator + "00%", TVariant.DecodeFromString(
                        "eDecimal:percentage2decimals:4636737291354636288").ToFormattedString(), "format percentage");
                v = new TVariant(-1003.25M, "Currency");
                Assert.AreEqual("eCurrency:Currency:-4571336140711264256",
                    v.EncodeToString(), "format negative number with format that only prints negative values 1");
                Assert.AreEqual("(1" + ThousandsOperator + "003" + DecimalSeparator + "25)",
                    v.ToFormattedString(), "format negative number with format that only prints negative values 2");
                v.ApplyFormatString("#,##0.00; ; ; ;");
                Assert.AreEqual("eEmpty:#,##0.00; ; ; ;:",
                    v.EncodeToString(), "format negative number with format that only prints negative values 3");
                Assert.AreEqual("", v.ToFormattedString(), "format negative number with format that only prints negative values 4");
                Assert.AreEqual("12" + ThousandsOperator + "346", new TVariant(12345.67M, "Currency").ToFormattedString(
                        "CurrencyWithoutDecimals"), "Problem D format currency");
                Assert.AreEqual("eCurrency:Currency:4668012718187306025", new TVariant(12345.67M,
                        "Currency").EncodeToString(), "Problem E format currency");
                Assert.AreEqual("12" + ThousandsOperator + "345" + DecimalSeparator + "67",
                    StringHelper.FormatCurrency(new TVariant(12345.67), "Currency"), "Problem F format currency");
                Assert.AreEqual("12345" + DecimalSeparator + "67", new TVariant(12345.67).ToString(), "Problem G format currency");
                Assert.AreEqual("12" + ThousandsOperator + "345" + DecimalSeparator + "67",
                    TVariant.DecodeFromString(new TVariant(12345.67M, "Currency").EncodeToString()).ToFormattedString(
                        "Currency"), "Problem H format currency");
                Assert.AreEqual("12",
                    TVariant.DecodeFromString(new TVariant(12345.67M, "Currency").EncodeToString()).ToFormattedString(
                        "CurrencyThousands"), "Problem I format currency");
                Assert.AreEqual("12", TVariant.DecodeFromString(new TVariant(12345.67M, "CurrencyThousands").EncodeToString()).ToFormattedString(
                        ""), "Problem J format currency");
                Assert.AreEqual("12", TVariant.DecodeFromString(new TVariant(12345.67M,
                            "#,##0.00;(#,##0.00);0.00;0").EncodeToString()).ToFormattedString(
                        "CurrencyThousands"), "Problem J2 access format currency thousands");

                /* we don't support thousands only with the progress format, too complicated */
                /* Assert.AreEqual('12', TVariant.DecodeFromString(TVariant.CreateCurrency(12345.67,'>>>,>>>,>>>,>>9.99').EncodeToString("CurrencyThousands")).toFormattedString(''), 'Problem J3 progress format currency thousands'); */
                Assert.AreEqual("12" + ThousandsOperator + "346",
                    TVariant.DecodeFromString(new TVariant(12345.67M,
                            "#,##0.00;(#,##0.00);0.00;0").EncodeToString()).ToFormattedString(
                        "CurrencyWithoutDecimals"), "Problem J2 access format currency w/o decimals");
                Assert.AreEqual("12" + ThousandsOperator + "346",
                    TVariant.DecodeFromString(new TVariant(12345.67M, "->>>,>>>,>>>,>>9.99").EncodeToString()).ToFormattedString(
                        "CurrencyWithoutDecimals"), "Problem J3 progress format currency w/o decimals");
                Assert.AreEqual("12" + ThousandsOperator + "346",
                    TVariant.DecodeFromString(new TVariant(12345.67M, "CurrencyWithoutDecimals").EncodeToString()).ToFormattedString(
                        ""), "Problem K format currency");
            }

            Thread.CurrentThread.CurrentCulture = oldCulture;
        }
Exemplo n.º 5
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="rptGrpValue"></param>
        /// <param name="AWithSpaceBetweenValues"></param>
        /// <returns></returns>
        public TVariant Calculate(List <TRptValue>rptGrpValue, Boolean AWithSpaceBetweenValues)
        {
            TVariant ReturnValue;
            String listValue;
            String listText;
            Boolean first;
            TRptDataCalcCalculation rptDataCalcCalculation;

            ReturnValue = new TVariant();

            foreach (TRptValue rptValue in rptGrpValue)
            {
                if (EvaluateCondition(rptValue.strCondition))
                {
                    if ((AWithSpaceBetweenValues == true) && (ReturnValue.TypeVariant != eVariantTypes.eEmpty))
                    {
                        ReturnValue.Add(new TVariant(' '));
                    }

                    if (rptValue.strFunction == "csv")
                    {
                        // this is only for sql queries
                        listValue = Parameters.Get(rptValue.strVariable, column, Depth).ToString();

                        if ((listValue.Length > 3) && (listValue.Substring(0, 4) == "CSV:"))
                        {
                            listValue = listValue.Substring(4);
                        }

                        first = true;
                        ReturnValue.Add(new TVariant(" ("));

                        if (listValue.Length == 0)
                        {
                            // this would make the sql query invalid; so insert a false condition to at least make it run, and return no records
                            ReturnValue.Add(new TVariant(" 1 = 0 "));
                        }

                        while (listValue.Length != 0)
                        {
                            bool IsFirstPair = true;
                            string value = StringHelper.GetNextCSV(ref listValue).Trim();

                            if (first)
                            {
                                first = false;
                            }
                            else
                            {
                                ReturnValue.Add(new TVariant(" OR "));
                            }

                            if (rptValue.strText.IndexOf(',') != -1)
                            {
                                // there are two things to compare (e.g. motivation group and motivation detail)

                                // motivation group and detail come in pairs, separated by comma, enclosed by quotes (getNextCSV strips the quotes)
                                string valuePair = value;
                                listText = rptValue.strText;
                                string calculationText = rptValue.strCalculation;

                                // if the format is defined in the xml file, it overwrites the value we get from (new TVariant(value).TypeVariant == eVariantTypes.xxx
                                bool ValueIsNumber = (rptValue.strFormat == "Number");
                                bool ValueIsText = (rptValue.strFormat == "Text");

                                ReturnValue.Add(new TVariant('('));

                                while (listText.Length != 0)
                                {
                                    if (IsFirstPair)
                                    {
                                        // we have taken out the first value already from listValue
                                        value = valuePair;
                                        IsFirstPair = false;
                                    }
                                    else
                                    {
                                        value = StringHelper.GetNextCSV(ref listValue).Trim();
                                    }

                                    if (listText.Length < rptValue.strText.Length)
                                    {
                                        if (calculationText.Length > 0)
                                        {
                                            ReturnValue.Add(new TVariant(" " + calculationText + " "));
                                        }
                                        else
                                        {
                                            ReturnValue.Add(new TVariant(" AND "));
                                        }
                                    }

                                    //todo: allow integer as well; problem with motivation detail codes that are just numbers;
                                    //todo: specify type with text, variable names and type
                                    //if (new TVariant(value).TypeVariant == eVariantTypes.eString)
                                    if (!ValueIsNumber || ValueIsText)
                                    {
                                        ReturnValue.Add(new TVariant(StringHelper.GetNextCSV(ref listText).Trim() + " = '"));
                                        ReturnValue.Add(new TVariant(value));
                                        ReturnValue.Add(new TVariant("' "));
                                    }
                                    else
                                    {
                                        ReturnValue.Add(new TVariant(StringHelper.GetNextCSV(ref listText).Trim() + " = "));
                                        ReturnValue.Add(new TVariant(value));
                                        ReturnValue.Add(new TVariant(' '));
                                    }
                                }

                                ReturnValue.Add(new TVariant(')'));
                            }
                            else
                            {
                                // if the format is defined in the xml file, it overwrites the value we get from (new TVariant(value).TypeVariant == eVariantTypes.xxx
                                bool ValueIsNumber = (rptValue.strFormat == "Number");
                                bool ValueIsText = (rptValue.strFormat == "Text");

                                if ((ValueIsText || (new TVariant(value).TypeVariant == eVariantTypes.eString))
                                    && !ValueIsNumber)
                                {
                                    ReturnValue.Add(new TVariant(' ' + rptValue.strText + " = '"));
                                    ReturnValue.Add(new TVariant(value));
                                    ReturnValue.Add(new TVariant("' "));
                                }
                                else
                                {
                                    ReturnValue.Add(new TVariant(' ' + rptValue.strText + " = "));
                                    ReturnValue.Add(new TVariant(value));
                                    ReturnValue.Add(new TVariant(' '));
                                }
                            }
                        }

                        ReturnValue.Add(new TVariant(") "));
                    }
                    else
                    {
                        if (rptValue.strText.Length != 0)
                        {
                            ReturnValue.Add(new TVariant(rptValue.strText), rptValue.strFormat);
                        }

                        if (rptValue.strVariable.Length != 0)
                        {
                            ReturnValue.Add(Parameters.Get(rptValue.strVariable, column, Depth), rptValue.strFormat);
                        }

                        if (rptValue.strCalculation.Length != 0)
                        {
                            rptDataCalcCalculation = new TRptDataCalcCalculation(this);
                            ReturnValue.Add(rptDataCalcCalculation.EvaluateHelperCalculation(rptValue.strCalculation), rptValue.strFormat);
                        }

                        if (rptValue.strFunction.Length != 0)
                        {
                            ReturnValue.Add(EvaluateFunctionString(rptValue.strFunction), rptValue.strFormat);
                        }
                    }
                }
            }

            return ReturnValue;
        }
Exemplo n.º 6
0
        public static List <TVariant>TestPostGLBatch(Int32 ALedgerNumber, Int32 ABatchNumber, out TVerificationResultCollection AVerifications)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Ledger number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }
            else if (ABatchNumber <= 0)
            {
                throw new EFinanceSystemInvalidBatchNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Batch number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber, ABatchNumber);
            }

            #endregion Validate Arguments

            GLPostingTDS MainDS = null;
            TVerificationResultCollection Verifications = null;

            int BatchPeriod = -1;

            TDBTransaction Transaction = null;
            bool SubmissionOK = false;
            bool Success = false;

            try
            {
                DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable,
                    ref Transaction,
                    ref SubmissionOK,
                    delegate
                    {
                        Success = TGLPosting.TestPostGLBatch(ALedgerNumber,
                            ABatchNumber,
                            Transaction,
                            out Verifications,
                            out MainDS,
                            ref BatchPeriod);
                    });
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            AVerifications = Verifications;

            List <TVariant>Result = new List <TVariant>();

            if (Success)
            {
                MainDS.AGeneralLedgerMaster.DefaultView.RowFilter = string.Empty;
                MainDS.AGeneralLedgerMaster.DefaultView.Sort = AGeneralLedgerMasterTable.GetGlmSequenceDBName();
                MainDS.AAccount.DefaultView.RowFilter = string.Empty;
                MainDS.AAccount.DefaultView.Sort = AAccountTable.GetAccountCodeDBName();
                MainDS.ACostCentre.DefaultView.RowFilter = string.Empty;
                MainDS.ACostCentre.DefaultView.Sort = ACostCentreTable.GetCostCentreCodeDBName();

                foreach (AGeneralLedgerMasterPeriodRow glmpRow in MainDS.AGeneralLedgerMasterPeriod.Rows)
                {
                    if ((glmpRow.PeriodNumber == BatchPeriod) && (glmpRow.RowState != DataRowState.Unchanged))
                    {
                        AGeneralLedgerMasterRow masterRow =
                            (AGeneralLedgerMasterRow)MainDS.AGeneralLedgerMaster.Rows.Find(glmpRow.GlmSequence);

                        #region Validate Data 1

                        if ((MainDS.AGeneralLedgerMaster == null) || (MainDS.AGeneralLedgerMaster.Count == 0) || (masterRow == null))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - General Ledger Master data for GLM sequence {1} does not exist or could not be accessed!"),
                                    Utilities.GetMethodName(true),
                                    glmpRow.GlmSequence));
                        }

                        #endregion Validate Data 1

                        ACostCentreRow ccRow = (ACostCentreRow)MainDS.ACostCentre.Rows.Find(new object[] { ALedgerNumber, masterRow.CostCentreCode });

                        #region Validate Data 2

                        if ((MainDS.ACostCentre == null) || (MainDS.ACostCentre.Count == 0) || (ccRow == null))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Function:{0} - Cost Centre data for Cost Centre {1} does not exist or could not be accessed!"),
                                    Utilities.GetMethodName(true),
                                    masterRow.CostCentreCode));
                        }

                        #endregion Validate Data 2

                        // only consider the posting cost centres
                        // TODO or consider only the top cost centre?
                        if (ccRow.PostingCostCentreFlag)
                        {
                            AAccountRow accRow =
                                (AAccountRow)
                                MainDS.AAccount.DefaultView[MainDS.AAccount.DefaultView.Find(masterRow.AccountCode)].Row;

                            #region Validate Data 3

                            if ((MainDS.AAccount == null) || (MainDS.AAccount.Count == 0) || (accRow == null))
                            {
                                throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                            "Function:{0} - Account data for Account {1} does not exist or could not be accessed!"),
                                        Utilities.GetMethodName(true),
                                        masterRow.AccountCode));
                            }

                            #endregion Validate Data 3

                            // only modified accounts have been loaded to the dataset, therefore report on all accounts available
                            if (accRow.PostingStatus)
                            {
                                decimal CurrentValue = 0.0m;

                                if (glmpRow.RowState == DataRowState.Modified)
                                {
                                    CurrentValue = (decimal)glmpRow[AGeneralLedgerMasterPeriodTable.ColumnActualBaseId, DataRowVersion.Original];
                                }

                                decimal DebitCredit = 1.0m;

                                if (accRow.DebitCreditIndicator
                                    && (accRow.AccountType != MFinanceConstants.ACCOUNT_TYPE_ASSET)
                                    && (accRow.AccountType != MFinanceConstants.ACCOUNT_TYPE_EXPENSE))
                                {
                                    DebitCredit = -1.0m;
                                }

                                // only return values, the client compiles the message, with Catalog.GetString
                                TVariant values = new TVariant(accRow.AccountCode);
                                values.Add(new TVariant(accRow.AccountCodeShortDesc), "", false);
                                values.Add(new TVariant(ccRow.CostCentreCode), "", false);
                                values.Add(new TVariant(ccRow.CostCentreName), "", false);
                                values.Add(new TVariant(CurrentValue * DebitCredit), "", false);
                                values.Add(new TVariant(glmpRow.ActualBase * DebitCredit), "", false);

                                Result.Add(values);
                            }
                        }
                    }
                }
            }

            return Result;
        }
Exemplo n.º 7
0
        /// <summary>
        /// calculate the value of a switch
        /// </summary>
        /// <param name="rptSwitch"></param>
        /// <returns></returns>
        public TVariant Calculate(TRptSwitch rptSwitch)
        {
            TVariant ReturnValue;
            TRptDataCalcField rptDataCalcField;
            TRptDataCalcValue rptDataCalcValue;
            TRptDataCalcSwitch rptDataCalcSwitch;
            TRptCase rptCase;

            ReturnValue = new TVariant();
            rptCase = GetFittingCase(rptSwitch);

            if (rptCase == null)
            {
                return ReturnValue;
            }

            if (rptCase.rptSwitch != null)
            {
                rptDataCalcSwitch = new TRptDataCalcSwitch(this);
                ReturnValue.Add(rptDataCalcSwitch.Calculate(rptCase.rptSwitch));
            }
            else
            {
                if (rptCase.rptGrpField != null)
                {
                    rptDataCalcField = new TRptDataCalcField(this);
                    rptDataCalcField.Calculate(rptCase.rptGrpField);
                }

                if (rptCase.rptGrpValue != null)
                {
                    rptDataCalcValue = new TRptDataCalcValue(this);
                    ReturnValue.Add(rptDataCalcValue.Calculate(rptCase.rptGrpValue));
                }
            }

            return ReturnValue;
        }
Exemplo n.º 8
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="rptGrpFieldDetail"></param>
        /// <returns></returns>
        public TVariant Calculate(List <TRptFieldDetail>rptGrpFieldDetail)
        {
            TVariant ReturnValue;
            TRptDataCalcValue rptDataCalcValue;
            TRptDataCalcSwitch rptDataCalcSwitch;

            ReturnValue = new TVariant();

            foreach (TRptFieldDetail rptFieldDetail in rptGrpFieldDetail)
            {
                if (EvaluateCondition(rptFieldDetail.strCondition))
                {
                    if (rptFieldDetail.rptGrpValue != null)
                    {
                        rptDataCalcValue = new TRptDataCalcValue(this);
                        ReturnValue.Add(rptDataCalcValue.Calculate(rptFieldDetail.rptGrpValue));
                    }
                    else
                    {
                        rptDataCalcSwitch = new TRptDataCalcSwitch(this);
                        ReturnValue.Add(rptDataCalcSwitch.Calculate(rptFieldDetail.rptSwitch));
                    }
                }
            }

            return ReturnValue;
        }
Exemplo n.º 9
0
        /// <summary>
        /// this function can be used in calculations and other places as well
        /// </summary>
        public TVariant Calculate(List <TRptSwitch>rptGrpSwitch)
        {
            TVariant ReturnValue;

            ReturnValue = new TVariant();

            foreach (TRptSwitch rptSwitch in rptGrpSwitch)
            {
                ReturnValue.Add(Calculate(rptSwitch));
            }

            return ReturnValue;
        }
Exemplo n.º 10
0
        /// <summary>
        /// This procedure adds the returned values from the sql query to the Parameters,
        /// according to the returns attribute of the calculation
        /// </summary>
        /// <returns>void</returns>
        public void AddResultsToParameter(String AStrReturns, String AStrReturnsFormat, DataRow ARow, Int32 ADepth)
        {
            // the results of each column should be added to one variable per column

            String strReturns = AStrReturns;
            Boolean AddToList = AStrReturnsFormat.ToLower() == "list";

            while (strReturns.Length != 0)
            {
                String strName = StringHelper.GetNextCSV(ref strReturns).Trim();

                // in sqlite, eg. accountdetailcommon.xml, select j.a_transaction_currency_c will keep the j; other db's will remove the table name
                if (!ARow.Table.Columns.Contains(strName))
                {
                    foreach (DataColumn col in ARow.Table.Columns)
                    {
                        if (col.ColumnName.Contains("." + strName))
                        {
                            strName = col.ColumnName;
                        }
                    }
                }

                TVariant value;

                // the parameters are stored first
                if (ARow[strName].GetType() == typeof(String))
                {
                    value = new TVariant(Convert.ToString(ARow[strName]));
                }
                else
                {
                    value = new TVariant(ARow[strName]);
                }

                Boolean ClearParameter = true;

                if ((AddToList) && (!value.IsNil()))
                {
                    TVariant newValue = new TVariant(Parameters.Get(strName, -1, ADepth));
                    newValue.Add(value, "", false);

                    // no format given, that needs to be done in the column calculation or field value
                    Parameters.Add(strName, newValue, -1, ADepth, null, null, ReportingConsts.CALCULATIONPARAMETERS);
                    ClearParameter = false;
                }
                else
                {
                    value.ApplyFormatString(AStrReturnsFormat);

                    // only add values that are displayed on the sheet; required for the credit and debit columns on an account detail report; the sum would be wrong
                    if (value.ToFormattedString().Length != 0)
                    {
                        if (value.IsNil())
                        {
                            // eg. Sql Sum should return 0, not null. AStrReturnsFormat is Currency
                            value = new TVariant(value.ToFormattedString());
                        }

                        Parameters.Add(strName, value, -1, ADepth, null, null, ReportingConsts.CALCULATIONPARAMETERS);
                        ClearParameter = false;
                    }
                }

                if (ClearParameter == true)
                {
                    // make sure that the variable is empty; otherwise the calculator would perhaps use the values from previous rows.
                    // this is important for all columns that are directly based on results from the query
                    Parameters.Add(strName, "", -1, ADepth, null, null, ReportingConsts.CALCULATIONPARAMETERS);
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="rptCalculation"></param>
        /// <param name="rptGrpParameter"></param>
        /// <param name="rptGrpTemplate"></param>
        /// <param name="rptGrpQuery"></param>
        /// <returns></returns>
        public TVariant EvaluateCalculationAll(TRptCalculation rptCalculation,
            List <TRptParameter>rptGrpParameter,
            List <TRptQuery>rptGrpTemplate,
            List <TRptQuery>rptGrpQuery)
        {
            TVariant ReturnValue;
            TRptDataCalcValue rptDataCalcValue;
            TRptDataCalcSwitch rptDataCalcSwitch;

            ReturnValue = new TVariant();

            if (rptGrpQuery == null)
            {
                return ReturnValue;
            }

            foreach (TRptQuery rptQuery in rptGrpQuery)
            {
                if (EvaluateCondition(rptQuery.strCondition))
                {
                    if (rptQuery.rptGrpValue != null)
                    {
                        rptDataCalcValue = new TRptDataCalcValue(this);

                        if (!ReturnValue.IsZeroOrNull())
                        {
                            ReturnValue.Add(new TVariant(" "));
                        }

                        ReturnValue.Add(rptDataCalcValue.Calculate(rptQuery.rptGrpValue, true));
                    }

                    if (rptQuery.rptGrpParameter != null)
                    {
                        // insert template with parameters
                        ReturnValue.Add(new TVariant(" "));
                        ReturnValue.Add(EvaluateCalculationAll(rptCalculation, rptQuery.rptGrpParameter, null, rptGrpTemplate));
                    }

                    if (rptQuery.rptGrpSwitch != null)
                    {
                        if (!ReturnValue.IsZeroOrNull())
                        {
                            ReturnValue.Add(new TVariant(" "));
                        }

                        rptDataCalcSwitch = new TRptDataCalcSwitch(this);
                        ReturnValue.Add(new TVariant(rptDataCalcSwitch.Calculate(rptQuery.rptGrpSwitch)));
                    }
                }
            }

            if ((ReturnValue.TypeVariant == eVariantTypes.eString) || (ReturnValue.ToString().IndexOf("{") != -1))
            {
                ReturnValue = new TVariant(ApplyParametersToQuery(rptGrpParameter, ReturnValue.ToString()), true); // explicit string
                ReturnValue = ReplaceVariables(ReturnValue.ToString(), true);
            }

            // TLogging.log('Result of TRptDataCalcCalculation.evaluateCalculationAll: '+result.encodetostring());
            return ReturnValue;
        }
Exemplo n.º 12
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="calculation"></param>
        /// <returns></returns>
        public TVariant EvaluateHelperCalculation(String calculation)
        {
            TVariant ReturnValue;
            TRptCalculation rptCalculation;
            DataTable tab;
            string strReturns;
            Boolean firstRow;

            ReturnValue = new TVariant();
            rptCalculation = ReportStore.GetCalculation(CurrentReport, calculation);

            if (rptCalculation == null)
            {
                TLogging.Log("calculation " + calculation + " could not be found.");
                return ReturnValue;
            }

            ReturnValue = Calculate(rptCalculation, null);

            if (ReturnValue.IsZeroOrNull() || (ReturnValue.ToString().Trim().ToUpper().IndexOf("SELECT") != 0))
            {
                return ReturnValue;
            }

            if (rptCalculation.strReturnsFormat.ToLower() == "list")
            {
                // reset the variables, so we are able to start a new list
                strReturns = rptCalculation.strReturns;

                while (strReturns.Length != 0)
                {
                    Parameters.Add(StringHelper.GetNextCSV(ref strReturns).Trim(), "", -1, Depth, null, null, ReportingConsts.CALCULATIONPARAMETERS);
                }
            }

            String strSql = ReturnValue.ToString();
            strSql = ReplaceQuotesForSql(strSql, rptCalculation.strId);
            tab = DatabaseConnection.SelectDT(strSql, "EvaluateHelperCalculation", DatabaseConnection.Transaction);

            if ((tab == null) || (tab.Rows.Count == 0))
            {
                // reset the variables, we don't want to display the results of the previous calculation
                strReturns = rptCalculation.strReturns;

                while (strReturns.Length != 0)
                {
                    Parameters.Add(StringHelper.GetNextCSV(ref strReturns).Trim(), "", -1, Depth, null, null, ReportingConsts.CALCULATIONPARAMETERS);
                }
            }

            ReturnValue = new TVariant();
            firstRow = true;

            foreach (DataRow row in tab.Rows)
            {
                if (!firstRow)
                {
                    ReturnValue.Add(new TVariant(", "));
                }

                firstRow = false;

                if (Convert.ToString(row[0]) != new TVariant(row[0]).ToString())
                {
                    ReturnValue.Add(new TVariant(Convert.ToString(row[0])));
                }
                else
                {
                    ReturnValue.Add(new TVariant(row[0]));
                }

                AddResultsToParameter(rptCalculation.strReturns, rptCalculation.strReturnsFormat, row, Depth);
            }

            return ReturnValue;
        }
Exemplo n.º 13
0
        /// <summary>
        /// This static function is used to create a variant with the correct type,
        /// when the variant is restored from an encoded string,
        /// that could e.g. be stored in a datatable (only strings)
        ///
        /// </summary>
        /// <returns>void</returns>
        public static TVariant DecodeFromString(String encodedValue)
        {
            TVariant ReturnValue;
            TVariant value;
            String typestr;
            String valuestr;
            String currencyFormat;
            String originalEncodedValue;
            String BeforeTryingFormat;
            String compositeEncodedValue;

            ReturnValue = new TVariant();
            originalEncodedValue = encodedValue;
            try
            {
                typestr = StringHelper.GetNextCSV(ref encodedValue, ":");
                currencyFormat = "";

                if (typestr == eVariantTypes.eComposite.ToString())
                {
                    currencyFormat = StringHelper.GetNextCSV(ref encodedValue, ":");
                    valuestr = StringHelper.GetNextCSV(ref encodedValue, ":");
                    value = new TVariant();

                    while (valuestr.Length > 0)
                    {
                        compositeEncodedValue = StringHelper.GetNextCSV(ref valuestr, "|");
                        value.Add(DecodeFromString(compositeEncodedValue), "", false);

                        // don't add strings up when decoding
                    }
                }
                else
                {
                    BeforeTryingFormat = encodedValue;
                    currencyFormat = StringHelper.GetNextCSV(ref encodedValue, ":");

                    // if there was no format in the encoded value, undo the previous step
                    if (encodedValue.Length == 0)
                    {
                        // there was no format
                        encodedValue = BeforeTryingFormat;
                        currencyFormat = "";
                    }

                    valuestr = StringHelper.GetNextCSV(ref encodedValue, ":");

                    if (typestr == eVariantTypes.eDateTime.ToString())
                    {
                        try
                        {
                            value =
                                new TVariant(DateTime.ParseExact(valuestr, DATETIME_UNAMBIGUOUS_FORMAT, DateTimeFormatInfo.InvariantInfo,
                                        DateTimeStyles.AssumeLocal));
                        }
                        catch (Exception)
                        {
                            value = new TVariant(DateTime.MinValue);
                        }
                        value.FormatString = currencyFormat;
                    }
                    else if ((typestr == eVariantTypes.eDecimal.ToString()) || (typestr == "eDouble"))
                    {
                        value = new TVariant(BitConverter.Int64BitsToDouble(Convert.ToInt64(valuestr)));
                    }
                    else if (typestr == eVariantTypes.eCurrency.ToString())
                    {
                        value = new TVariant((decimal)BitConverter.Int64BitsToDouble(Convert.ToInt64(valuestr)), "Currency");
                    }
                    else if (typestr == eVariantTypes.eInteger.ToString())
                    {
                        value = new TVariant(Convert.ToInt32(valuestr));
                    }
                    else if (typestr == eVariantTypes.eInt64.ToString())
                    {
                        value = new TVariant(Convert.ToInt64(valuestr));
                    }
                    else if (typestr == eVariantTypes.eBoolean.ToString())
                    {
                        value = new TVariant(Convert.ToBoolean(valuestr));
                    }
                    else if (typestr == eVariantTypes.eString.ToString())
                    {
                        value = new TVariant((String)valuestr, true);
                    }
                    else if (typestr == eVariantTypes.eEmpty.ToString())
                    {
                        value = new TVariant();
                    }
                    else
                    {
                        value = new TVariant(valuestr);
                    }
                }

                value.FormatString = currencyFormat;
                ReturnValue = value;
            }
            catch (Exception e)
            {
                TLogging.Log("problem decoding " + originalEncodedValue + Environment.NewLine + e.Message);
                ReturnValue = new TVariant();
            }
            return ReturnValue;
        }