Exemple #1
0
 /// <summary>
 /// this function should be overwritten; sets the environment for running the function
 /// </summary>
 public virtual Boolean FunctionSelector(TRptSituation ASituation, String f, TVariant[] ops, out TVariant AValue)
 {
     this.situation = ASituation;
     parameters = situation.GetParameters();
     AValue = null;
     return false;
 }
        public void TestGeneralParametersProcessing()
        {
            TParameterList parameters = new TParameterList();

            TVariant value = new TVariant();

            value.ApplyFormatString("Currency");
            Assert.AreEqual("0", value.ToFormattedString(), "null value for currency should be 0");
            value = new TVariant(value.ToFormattedString());
            parameters.Add("amountdue", value, -1, 2, null, null, ReportingConsts.CALCULATIONPARAMETERS);
            parameters.Save("testDebug.csv", true);
            Assert.AreEqual(true, parameters.Exists("amountdue", -1, 1, eParameterFit.eBestFitEvenLowerLevel), "can find added parameter");
            Assert.AreEqual("0", parameters.Get("amountdue", -1, 2,
                    eParameterFit.eBestFit).ToFormattedString(), "currency parameter is stored not correctly");
            //Assert.AreEqual("0", parameters.Get("amountdue", -1, 1, eParameterFit.eBestFit).ToFormattedString(), "currency parameter is stored not correctly");
            Assert.AreEqual("0", parameters.Get("amountdue", -1, 1,
                    eParameterFit.eBestFitEvenLowerLevel).ToFormattedString(), "currency parameter cannot be accessed from level up");

            parameters.Add("IntegerList", "300,400");
            parameters.Save("test.csv", false);
            parameters.Load(Path.GetFullPath("test.csv"));
            Assert.AreEqual("eString:300,400", parameters.Get(
                    "IntegerList").EncodeToString(), "integers separated by comma should be treated as string");
            parameters.Save("test2.csv", true);
        }
Exemple #3
0
        /// <summary>
        /// functions need to be registered here
        /// </summary>
        /// <param name="ASituation"></param>
        /// <param name="f"></param>
        /// <param name="ops"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override Boolean FunctionSelector(TRptSituation ASituation, String f, TVariant[] ops, out TVariant value)
        {
            if (base.FunctionSelector(ASituation, f, ops, out value))
            {
                return true;
            }

            if (StringHelper.IsSame(f, "getGiftStatistics"))
            {
                value = new TVariant();
                GetGiftStatistics(ops[1].ToInt(), ops[2].ToString(), ops[3].ToString(), ops[4].ToInt(), ops[5].ToInt(), ops[6].ToInt());
                return true;
            }

            if (StringHelper.IsSame(f, "IsLapsedDonor"))
            {
                value =
                    new TVariant(IsLapsedDonor(ops[1].ToInt64(), ops[2].ToInt64(), ops[3].ToDate(), ops[4].ToDate(), ops[5].ToString(), ops[6].ToInt(),
                            ops[7].ToInt(), ops[8].ToString(), ops[9].ToString(), ops[10].ToBool()));
                return true;
            }

            if (StringHelper.IsSame(f, "SelectLastGift"))
            {
                value = new TVariant(SelectLastGift(ops[1].ToInt64(), ops[2].ToInt64(), ops[3].ToDate(), ops[4].ToDate(), ops[5].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "IsTopDonor"))
            {
                value = new TVariant(IsTopDonor(ops[1].ToDecimal(), ops[2].ToDecimal(), ops[3].ToDecimal()));
                return true;
            }

            if (StringHelper.IsSame(f, "MakeTopDonor"))
            {
                value = new TVariant(MakeTopDonor(ops[1].ToDecimal(), ops[2].ToDecimal(), ops[3].ToDecimal(),
                        ops[4].ToBool(), ops[5].ToString(), ops[6].ToDate(), ops[7].ToDate(),
                        ops[8].ToInt64(), ops[9].ToString(), ops[10].ToString()));
                return true;
            }

            value = new TVariant();
            return false;
        }
Exemple #4
0
        /// <summary>
        /// format a date in a form that will be adjusted
        /// for each database in FormatQueryRDBMSSpecific;
        /// (correct order of month/day etc)
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static TVariant FormatDate(TVariant value)
        {
            String list;
            String day;
            String month;
            String year;
            String resultString;

            if (value.TypeVariant == eVariantTypes.eDateTime)
            {
                resultString = "#" + value.DateToString("yyyy/MM/dd") + "#";

                // it seems, the separators (e.g. , /, .) are not considered
                resultString = resultString.Replace(value.DateToString("yyyy/MM/dd")[4], '-');
            }
            else
            {
                list = value.ToString();

                // try all available separators, defined in Ict.Common.StringHelper
                day = StringHelper.GetNextCSV(ref list, ".", true);

                if (list.Length == 0)
                {
                    throw new Exception("Ict.Petra.Server.MReporting.FormatQuery: Cannot decode date " + value.ToString());
                }

                month = StringHelper.GetNextCSV(ref list, ".", true);
                year = StringHelper.GetNextCSV(ref list, ".", true);

                resultString = String.Format("#{0:4}-{1:2}-{2:2}#",
                    year, month, day);
            }

            return new TVariant(resultString, true); // explicit string
        }
Exemple #5
0
        /// <summary>
        /// functions need to be registered here
        /// </summary>
        /// <param name="ASituation"></param>
        /// <param name="f"></param>
        /// <param name="ops"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override Boolean FunctionSelector(TRptSituation ASituation, String f, TVariant[] ops, out TVariant value)
        {
            if (base.FunctionSelector(ASituation, f, ops, out value))
            {
                return true;
            }

            if (StringHelper.IsSame(f, "getAccountDetailAmount"))
            {
                value = GetAccountDetailAmount(ops[1].ToDecimal(), ops[2].ToBool());
                return true;
            }

            if (StringHelper.IsSame(f, "getTransactionAmount"))
            {
                value = new TVariant(GetTransactionAmount(ops[1].ToString()), "currency");
                return true;
            }

            if (StringHelper.IsSame(f, "getAssetsMinusLiabs"))
            {
                value = new TVariant(GetAssetsMinusLiabs(ops[1].ToInt(), ops[2].ToInt()), "currency");
                return true;
            }

            if (StringHelper.IsSame(f, "getNetBalance"))
            {
                value = new TVariant(GetNetBalance(ops[1].ToInt()), "currency");
                return true;
            }

            if (StringHelper.IsSame(f, "getGLMSequences"))
            {
                GetGlmSequences(ops[1].ToInt(), ops[2].ToString(), ops[3].ToString(), ops[4].ToInt());
                value = new TVariant();
                return true;
            }

            if (StringHelper.IsSame(f, "getActual"))
            {
                value = new TVariant(GetActual(ops[1].ToInt(), ops[2].ToInt(), ops[3].ToBool(), ops[4].ToString()), "currency");
                return true;
            }

            if (StringHelper.IsSame(f, "getActualPeriods"))
            {
                value = new TVariant(GetActualPeriods(ops[1].ToInt(), ops[2].ToInt(), ops[3].ToInt(), ops[4].ToBool(),
                        ops[5].ToString()), "currency");
                return true;
            }

            if (StringHelper.IsSame(f, "getActualPeriodsIE"))
            {
                value = new TVariant(GetActualPeriodsIE(ops[1].ToInt(), ops[2].ToInt(), ops[3].ToInt(), ops[4].ToBool(),
                        ops[5].ToString()), "currency");
                return true;
            }

            if (StringHelper.IsSame(f, "getActualEndOfLastYear"))
            {
                value = new TVariant(GetActualEndOfLastYear(ops[1].ToInt(), ops[2].ToInt(), ops[3].ToString()), "currency");
                return true;
            }

            if (StringHelper.IsSame(f, "GetBudgetPeriods"))
            {
                value = new TVariant(GetBudgetPeriods(ops[1].ToInt(), ops[2].ToInt(), ops[3].ToInt(), ops[4].ToBool(),
                        ops[5].ToString()), "currency");
                return true;
            }

            if (StringHelper.IsSame(f, "getLedgerName"))
            {
                value = new TVariant(TFinanceReportingWebConnector.GetLedgerName(ops[1].ToInt()));
                return true;
            }

            if (StringHelper.IsSame(f, "UnitKeyToForeignCostCentre"))
            {
                value = new TVariant(UnitKeyToForeignCostCentre(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "getCurrency"))
            {
                value = new TVariant(GetCurrency(ops[1].ToInt(), ops[2].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "getBalanceSheetType"))
            {
                value = new TVariant(GetBalanceSheetType(ops[1].ToString(), ops[2].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "getIncExpStmtType"))
            {
                value = new TVariant(GetIncExpStmtType(ops[1].ToString(), ops[2].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "getAccountingHierarchy"))
            {
                value = new TVariant(GetAccountingHierarchy(ops[1].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetLedgerPerColumn"))
            {
                value = new TVariant(GetLedgerPerColumn());
                return true;
            }

            if (StringHelper.IsSame(f, "getCurrencyPerColumn"))
            {
                value = new TVariant(GetCurrencyPerColumn());
                return true;
            }

            if (StringHelper.IsSame(f, "GetYTDPerColumn"))
            {
                value = new TVariant(GetYTDPerColumn());
                return true;
            }

            if (StringHelper.IsSame(f, "getAllAccountDescendants"))
            {
                value = new TVariant("CSV:" + GetAllAccountDescendants(ops[1].ToInt(), ops[2].ToString(), ops[3].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "ExtractPaymentNumberFromTransactionNarrative"))
            {
                value = new TVariant("CSV:" + ExtractPaymentNumberFromTransactionNarrative(ops[1].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetMonthName"))
            {
                value = new TVariant(StringHelper.GetLongMonthName(ops[1].ToInt32()));
                return true;
            }

            value = new TVariant();
            return false;
        }
Exemple #6
0
        /// <summary>
        /// functions need to be registered here
        /// </summary>
        /// <param name="ASituation"></param>
        /// <param name="f"></param>
        /// <param name="ops"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override Boolean FunctionSelector(TRptSituation ASituation, String f, TVariant[] ops, out TVariant value)
        {
            if (base.FunctionSelector(ASituation, f, ops, out value))
            {
                return true;
            }

            if (StringHelper.IsSame(f, "GetPartnerLabelValues"))
            {
                value = new TVariant(GetPartnerLabelValues());
                return true;
            }

            if (StringHelper.IsSame(f, "GetPartnerBestAddress"))
            {
                value = new TVariant(GetPartnerBestAddress(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "AddressMeetsPostCodeCriteriaOrEmpty"))
            {
                value =
                    new TVariant(AddressMeetsPostCodeCriteriaOrEmpty(ops[1].ToBool(), ops[2].ToString(), ops[3].ToString(), ops[4].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetPartnerShortname"))
            {
                value = new TVariant(GetPartnerShortName(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetFieldOfPartner"))
            {
                value = new TVariant(GetFieldOfPartner(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "CheckAccountNumber"))
            {
                value = new TVariant(CheckAccountNumber(ops[1].ToString(), ops[2].ToString(), ops[3].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetCountyPublicationStatistic"))
            {
                value = new TVariant(GetCountyPublicationStatistic(ops[1].ToString(), ops[2].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "CalculatePublicationStatisticPercentage"))
            {
                value = new TVariant(FillStatisticalReportResultTable());
                return true;
            }

            if (StringHelper.IsSame(f, "GetNumberOfAllPublications"))
            {
                value = new TVariant(GetNumberOfAllPublications());
                return true;
            }

            if (StringHelper.IsSame(f, "ConvertIntToTime"))
            {
                value = new TVariant(ConvertIntToTime(ops[1].ToInt(), ops[2].ToInt()));
                return true;
            }

            if (StringHelper.IsSame(f, "DetermineAddressDateStatus"))
            {
                value = new TVariant(DetermineAddressDateStatus(ops[1].ToString(), ops[2].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetSubscriptions"))
            {
                value = new TVariant(GetSubscriptions(ops[1].ToInt64(), ops[2].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetFirstEntryFromSQLStatement"))
            {
                value = new TVariant(GetFirstEntryFromSQLStatement(ops[1].ToString(), ops[2].ToString(), ops[3].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetPartnerTypes"))
            {
                value = new TVariant(GetPartnerTypes(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetProfession"))
            {
                value = new TVariant(GetProfession(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetOccupation"))
            {
                value = new TVariant(GetOccupation(ops[1].ToString()));
                return true;
            }

            value = new TVariant();
            return false;
        }
Exemple #7
0
        /// <summary>
        /// if the current account is a debit account xor amount is negative, then return the negative amount;
        /// else returns the positive amount
        /// </summary>
        /// <returns>void</returns>
        public TVariant GetAccountDetailAmount(decimal amount, Boolean debit_credit_indicator)
        {
            TVariant ReturnValue;

            if (debit_credit_indicator)
            {
                ReturnValue = new TVariant(amount, "currency");
            }
            else
            {
                ReturnValue = new TVariant(amount * -1, "currency");
            }

            return ReturnValue;
        }
Exemple #8
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="orig"></param>
        /// <param name="searchOpen"></param>
        /// <param name="searchClose"></param>
        /// <param name="newOpen"></param>
        /// <param name="newClose"></param>
        /// <param name="convert"></param>
        /// <returns></returns>
        protected TVariant ReplaceVariablesPattern(TVariant orig,
            String searchOpen,
            String searchClose,
            String newOpen,
            String newClose,
            TConvertProc convert)
        {
            int position = 0;
            String resultString = orig.ToString();
            TVariant ReturnValue = null;
            int bracket = resultString.IndexOf(searchOpen, position);

            if (bracket == -1)
            {
                // no brackets, therefore use the original TVariant, so that the type information is not lost
                ReturnValue = orig;
            }

            while (bracket != -1)
            {
                int firstRealChar = bracket + searchOpen.Length;
                int paramEndIdx = resultString.IndexOf(searchClose, firstRealChar);

                if (paramEndIdx <= 0)
                {
                    // missing closing bracket; can happen with e.g. #testdate; should be #testdate#
                    if (resultString.Length > bracket + 20)
                    {
                        throw new Exception("Cannot find closing bracket " + searchClose + " for " + resultString.Substring(bracket, 20));
                    }
                    else
                    {
                        throw new Exception("Cannot find closing bracket " + searchClose + " for " + resultString.Substring(bracket));
                    }
                }

                String parameter = resultString.Substring(firstRealChar, paramEndIdx - firstRealChar);
                bool ParameterExists = false;
                TVariant newvalue;

                if (parameters != null)
                {
                    if (parameter.IndexOf("GLOBAL:") == 0)
                    {
                        newvalue = parameters.Get(parameter.Substring(7), -1, -1, eParameterFit.eExact);
                    }
                    else if (parameter.IndexOf("ALLLEVELS:") == 0)
                    {
                        newvalue = parameters.Get(parameter.Substring(10), -1, depth, eParameterFit.eBestFitEvenLowerLevel);
                    }
                    else
                    {
                        newvalue = parameters.Get(parameter, column, depth, eParameterFit.eBestFitEvenLowerLevel);
                    }

                    ParameterExists = (newvalue.TypeVariant != eVariantTypes.eEmpty);
                }
                else
                {
                    newvalue = new TVariant();
                }

                if (!ParameterExists)
                {
                    // if date is given, use the parameter itself
                    if ((parameter[0] >= '0') && (parameter[0] <= '9'))
                    {
                        newvalue = new TVariant(parameter);
                    }
                    else
                    {
                        int CountWarning = 1;

                        // do not print warning too many times for the same variable
                        if (!VariablesNotFound.ContainsKey(parameter))
                        {
                            VariablesNotFound.Add(parameter, 1);
                        }
                        else
                        {
                            VariablesNotFound[parameter] = VariablesNotFound[parameter] + 1;
                            CountWarning = VariablesNotFound[parameter];
                        }

                        if (CountWarning < 5)
                        {
                            // this can be alright, for empty values; for example method of giving can be empty; for report GiftTransactions
                            TLogging.Log(
                                "Variable " + parameter + " empty or not found (column: " + column.ToString() +
                                "; level: " + depth.ToString() + "). " + resultString);
                        }
                        else if (CountWarning % 20 == 0)
                        {
                            TLogging.Log("20 times: Variable " + parameter + " empty or not found.");
                        }
                    }
                }

                try
                {
                    if (resultString.Length == (searchOpen + parameter + searchClose).Length)
                    {
                        // replace the whole value, return as a TVariant
                        ReturnValue = convert(newvalue);
                    }

                    resultString = resultString.Replace(searchOpen + parameter + searchClose, newOpen + convert(newvalue).ToString() + newClose);
                }
                catch (Exception e)
                {
                    throw new Exception(
                        "While trying to format parameter " + parameter + ", there was a problem with formatting." + Environment.NewLine + e.Message);
                }
                bracket = resultString.IndexOf(searchOpen, position);
            } // while

            if (ReturnValue == null)
            {
                // there has not been just a single value
                ReturnValue = new TVariant(resultString, true); // explicit string
            }

            return ReturnValue;
        }
Exemple #9
0
 /// <summary>
 /// create a copy
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static TVariant Id(TVariant value)
 {
     return new TVariant(value);
 }
        /// <summary>
        /// Transfers the result of the accommodation table to the report results
        /// </summary>
        /// <param name="ADetailLevel">Indicator if we have a brief, full or detail accommodation report</param>
        /// <param name="ASituation">The current report situation</param>
        /// <returns>true</returns>
        public bool FinishAccomTable(String ADetailLevel, ref TRptSituation ASituation)
        {
            ASituation.GetResults().Clear();

            if (FAccommodationTable == null)
            {
                return false;
            }

            int ChildRow = 1;
            int NumColumns = FAccommodationTable.Columns.Count / 2;

            if (ADetailLevel == "Detail")
            {
                // Don't show the cost column if we have a detailed report
                NumColumns--;
            }

            String PreviousVenueName = "";

            DataRow[] SortedRows = FAccommodationTable.Select("", "Venue DESC");

            foreach (DataRow CurrentRow in SortedRows)
            {
                if (CurrentRow[0].ToString() == NO_ACCOMMODATION)
                {
                    // ignore the row with no accomodation here
                    continue;
                }

                if (CurrentRow["Venue"].ToString() != PreviousVenueName)
                {
                    PreviousVenueName = (String)CurrentRow["Venue"];

                    if (ChildRow > 1)
                    {
                        InsertEmptyRow(NumColumns, ChildRow++, "", ref ASituation);
                    }

                    InsertEmptyRow(NumColumns, ChildRow++, PreviousVenueName, ref ASituation);
                }

                InsertDataRow(NumColumns, ChildRow++, CurrentRow, ref ASituation);

                if (ADetailLevel == "Detail")
                {
                    InsertDetailDataRow(NumColumns, ref ChildRow, CurrentRow["RoomName"].ToString(), ref ASituation);
                }
            }

            InsertEmptyRow(NumColumns, ChildRow++, "", ref ASituation);

            foreach (DataRow CurrentRow in FAccommodationTable.Rows)
            {
                if (CurrentRow[0].ToString() != NO_ACCOMMODATION)
                {
                    continue;
                }

                InsertDataRow(NumColumns, ChildRow++, CurrentRow, ref ASituation);
                break;
            }

            if (ADetailLevel == "Full")
            {
                InsertEmptyRow(NumColumns, ChildRow++, "", ref ASituation);

                TVariant[] Header = new TVariant[NumColumns];
                TVariant[] Description =
                {
                    new TVariant(), new TVariant()
                };
                TVariant[] Columns = new TVariant[NumColumns];

                for (int Counter = 0; Counter < NumColumns; ++Counter)
                {
                    Columns[Counter] = new TVariant();
                    Header[Counter] = new TVariant();
                }

                Columns[0] = new TVariant("");
                Columns[1] = new TVariant("People with accommodation not allocated for their actual time at the conference:");
                ASituation.GetResults().AddRow(0, ChildRow++, true, 1, "", "", false,
                    Header, Description, Columns);

                foreach (String NoAccom in FNoAccommodationList)
                {
                    Header = new TVariant[NumColumns];
                    Description[0] = new TVariant();
                    Description[1] = new TVariant();
                    Columns = new TVariant[NumColumns];

                    for (int Counter = 0; Counter < NumColumns; ++Counter)
                    {
                        Columns[Counter] = new TVariant();
                        Header[Counter] = new TVariant();
                    }

                    Columns[0] = new TVariant("");
                    Columns[1] = new TVariant(NoAccom);
                    ASituation.GetResults().AddRow(0, ChildRow++, true, 1, "", "", false,
                        Header, Description, Columns);
                }
            }
            else if (ADetailLevel == "Detail")
            {
                InsertDetailDataRow(NumColumns, ref ChildRow, NO_ACCOMMODATION, ref ASituation);
            }

            return true;
        }
        /// <summary>
        /// Insert the values of a data row into the report results.
        /// The data row contains for each room / venue the bookings.
        /// </summary>
        /// <param name="ANumColumns">Number of columns the report has</param>
        /// <param name="AChildRow">Index of the child row</param>
        /// <param name="ADataRow">The data row which contains the values</param>
        /// <param name="ASituation">The current report situation</param>
        /// <returns>true</returns>
        private bool InsertDataRow(int ANumColumns, int AChildRow, DataRow ADataRow, ref TRptSituation ASituation)
        {
            TVariant[] Header = new TVariant[ANumColumns];
            TVariant[] Description =
            {
                new TVariant(), new TVariant()
            };
            TVariant[] Columns = new TVariant[ANumColumns];

            for (int Counter = 0; Counter < ANumColumns; ++Counter)
            {
                Columns[Counter] = new TVariant(ADataRow[Counter * 2].ToString() + ADataRow[Counter * 2 + 1].ToString());
                Header[Counter] = new TVariant();
            }

            ASituation.GetResults().AddRow(0, AChildRow, true, 2, "", "", false,
                Header, Description, Columns);
            return true;
        }
Exemple #12
0
        /// <summary>
        /// This formats the caption of a column, into up to 3 rows
        ///
        /// </summary>
        /// <returns>void</returns>
        protected void FormatCaption(String AParameterName, TVariant ACaption, System.Int32 AColumn)
        {
            int br;
            String caption;

            // v, newValue: TVariant;
            // Counter: integer;
            // TODO: client side formatting of column captions? e.g. month names should be localised
            // problems: there can be \n inside strings;
            // need to split strings by the \n
            caption = ACaption.ToString();
            br = caption.IndexOf("\\n");

            if (br != -1)
            {
                Parameters.Add(AParameterName, new TVariant(caption.Substring(0, br), true), AColumn);

                // Tlogging.Log(parameters.Get(AParameterName).EncodeToString());
                caption = caption.Substring(br + 2, caption.Length - br - 2);
                br = caption.IndexOf("\\n");

                if (br != -1)
                {
                    Parameters.Add(AParameterName + '2', new TVariant(caption.Substring(0, br), true), AColumn);

                    // Tlogging.Log(parameters.Get(AParameterName+'2').EncodeToString());
                    caption = caption.Substring(br + 2, caption.Length - br - 2);
                    Parameters.Add(AParameterName + '3', new TVariant(caption, true), AColumn);
                }
                else
                {
                    Parameters.Add(AParameterName + '2', new TVariant(caption, true), AColumn);
                }
            }
            else
            {
                Parameters.Add(AParameterName, new TVariant(caption, true), AColumn);
            }
        }
Exemple #13
0
        /// <summary>
        /// print a currency value (actually all sorts of values, e.g. dates) into a string
        /// </summary>
        /// <param name="value">the value to be printed</param>
        /// <param name="format">the format to be used; can be dayofyear for birthdays, currency, etc</param>
        /// <returns>the formatted string</returns>
        public static String FormatCurrency(TVariant value, String format)
        {
            String ReturnValue;
            decimal d;
            DateTime ThisYearDate;

            // for partnerkey
            String OrigFormat;

            ReturnValue = "";

            if (format.ToLower() == "dayofyear")
            {
                if (value.IsZeroOrNull())
                {
                    ReturnValue = "N/A";
                }
                else
                {
                    ThisYearDate = new DateTime(DateTime.Today.Year, value.ToDate().Month, value.ToDate().Day);
                    ReturnValue = DateToStr(ThisYearDate, "dd-MMM").ToUpper();
                }

                return ReturnValue;
            }

            if (format == null)
            {
                format = "";
            }

            OrigFormat = format;

            if (value.TypeVariant == eVariantTypes.eString)
            {
                format = "";
            }
            else
            {
                format = GetFormatString(value.FormatString, format);
            }

            if (value != null)
            {
                if ((format == null) || (format.Length == 0))
                {
                    return value.ToString();
                }

                String formatPositive = GetNextCSV(ref format, ";");
                String formatNegative = GetNextCSV(ref format, ";");
                String formatZero = GetNextCSV(ref format, ";");
                String formatNil = GetNextCSV(ref format, ";");

                if ((OrigFormat.ToLower() == "partnerkey") || (value.FormatString == "partnerkey"))
                {
                    if (value.ToInt64() <= 0)
                    {
                        ReturnValue = FormatCurrencyInternal(0, "0000000000");
                    }
                    else
                    {
                        ReturnValue = FormatCurrencyInternal(value.ToDecimal(), formatPositive);
                    }
                }
                else if ((value.TypeVariant == eVariantTypes.eDecimal)
                         || (value.TypeVariant == eVariantTypes.eCurrency)
                         || (value.TypeVariant == eVariantTypes.eInteger))
                {
                    d = value.ToDecimal();

                    if (d > 0)
                    {
                        ReturnValue = FormatCurrencyInternal(d, formatPositive);
                    }
                    else if (d < 0)
                    {
                        ReturnValue = FormatCurrencyInternal(Math.Abs(d), formatNegative);
                    }
                    else
                    {
                        // (d == 0)
                        ReturnValue = FormatCurrencyInternal(d, formatZero);
                    }
                }
                else if (value.IsZeroOrNull())
                {
                    ReturnValue = FormatCurrencyInternal(0, formatNil);
                }
                else
                {
                    ReturnValue = value.ToString();
                }
            }

            return ReturnValue;
        }
Exemple #14
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;
        }
Exemple #15
0
        /// <summary>
        /// calculate the positions for the columns
        ///
        ///
        /// </summary>
        /// <returns>void</returns>
        protected void InitColumnLayout()
        {
            System.Int32 lowestlevel;
            double MostRightPosition;
            double MostRightPosition2;
            System.Int32 Counter;
            String ColumnFormat;
            TVariant ColumnPosition;
            TVariant ColumnPositionIndented;
            lowestlevel = this.Results.GetDeepestVisibleLevel();
            Parameters.Add("lowestLevel", new TVariant(lowestlevel), -1, ReportingConsts.APPLICATIONPARAMETERS);

            // use the columns of the first subreport (it always exists) to calculate the position of the columns and the width of the report
            // but setting parameters has to be done in the global settings (subreport = 1)
            Parameters.Add("CurrentSubReport", new TVariant(0), -1);

            // get the most right position of the descr columns of the lowest level
            MostRightPosition = 0;

            if (Parameters.Exists("ColumnPosition", ReportingConsts.COLUMNLEFT + 1, lowestlevel))
            {
                MostRightPosition = MostRightPosition + Parameters.Get("ColumnPosition", ReportingConsts.COLUMNLEFT + 1, lowestlevel).ToDouble();
            }

            if (Parameters.Exists("ColumnWidth", ReportingConsts.COLUMNLEFT + 1, lowestlevel))
            {
                MostRightPosition = MostRightPosition + Parameters.Get("ColumnWidth", ReportingConsts.COLUMNLEFT + 1, lowestlevel).ToDouble();
            }

            MostRightPosition2 = 0;

            if (Parameters.Exists("ColumnPosition", ReportingConsts.COLUMNLEFT + 2, lowestlevel))
            {
                MostRightPosition2 = MostRightPosition2 + Parameters.Get("ColumnPosition", ReportingConsts.COLUMNLEFT + 2, lowestlevel).ToDouble();
            }

            if (Parameters.Exists("ColumnWidth", ReportingConsts.COLUMNLEFT + 2, lowestlevel))
            {
                MostRightPosition2 = MostRightPosition2 + Parameters.Get("ColumnWidth", ReportingConsts.COLUMNLEFT + 2, lowestlevel).ToDouble();
            }

            if (MostRightPosition2 > MostRightPosition)
            {
                MostRightPosition = MostRightPosition2;
            }

            for (Counter = 0; Counter <= Results.GetMaxDisplayColumns() - 1; Counter += 1)
            {
                // space between columns
                MostRightPosition = MostRightPosition + 0.0;

                if (Parameters.Exists("ColumnPosition", Counter))
                {
                    MostRightPosition = Parameters.Get("ColumnPosition", Counter).ToDouble();
                }

                ColumnPosition = new TVariant(MostRightPosition);
                ColumnPositionIndented = Parameters.Get("ColumnPositionIndented", Counter);
                TVariant ColumnWidth = new TVariant();

                if (!Parameters.Exists("ColumnWidth", Counter))
                {
                    if (Parameters.Exists("ColumnFormat", Counter, -1, eParameterFit.eExact))
                    {
                        // todo: width of currency depends on thousandsonly, nodecimals, etc.
                        ColumnFormat = Parameters.Get("ColumnFormat", Counter, -1, eParameterFit.eExact).ToString();

                        // all measurements in cm
                        if (ColumnFormat == "percentage")
                        {
                            // was 2.0, but the caption needs space as well, so same width as currency
                            ColumnWidth = new TVariant(2.5);
                        }
                        else if (ColumnFormat == "currency")
                        {
                            ColumnWidth = new TVariant(2.5);
                        }
                        else
                        {
                            ColumnWidth = new TVariant(3);
                        }

                        ColumnPositionIndented = new TVariant(0.5);
                    }
                    else
                    {
                        ColumnWidth = new TVariant(4);
                    }
                }
                else
                {
                    ColumnWidth = Parameters.Get("ColumnWidth", Counter);
                }

                MostRightPosition = MostRightPosition + ColumnWidth.ToDouble();

                if (!ColumnPositionIndented.IsNil())
                {
                    MostRightPosition = MostRightPosition + ColumnPositionIndented.ToDouble();
                }

                // save the values to the global report level
                Parameters.Add("CurrentSubReport", new TVariant(-1), -1);
                Parameters.Add("ColumnPosition", new TVariant(ColumnPosition), Counter);
                Parameters.Add("ColumnWidth", new TVariant(ColumnWidth), Counter);

                if (!ColumnPositionIndented.IsNil())
                {
                    Parameters.Add("ColumnPositionIndented", ColumnPositionIndented, Counter);
                }

                Parameters.Add("CurrentSubReport", new TVariant(0), -1);
            }

            Parameters.Add("CurrentSubReport", new TVariant(-1), -1);
            Parameters.Add("ReportWidth", new TVariant(MostRightPosition));
        }
Exemple #16
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;
        }
Exemple #17
0
        public void TestVariantDates()
        {
            CultureInfo oldCulture;

            oldCulture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB", false);

            /* console.writeLine(CultureInfo.CurrentCulture.TwoLetterISOLanguageName); */
            Assert.AreEqual("29/03/2004", new TVariant(new DateTime(2004, 03, 29)).ToString(), "Problem A date GB");
            Assert.AreEqual("29-MAR", new TVariant(new DateTime(2004, 03, 29)).ToFormattedString("dayofyear"), "Problem A2 day of year GB");
            Assert.AreEqual("29-MAR", new TVariant(new DateTime(2004, 03, 29), "dayofyear").ToFormattedString(
                    ""), "Problem A2 day of year formatstring GB");
            Assert.AreEqual("29/03/" + DateTime.Now.Year.ToString(), new TVariant(new DateTime(2004, 03, 29)).ToFormattedString("dayofyear",
                    "CSV"), "Problem A2 day of year CSV GB");
            Assert.AreEqual(new TVariant("#20040329#").ToString(), new TVariant(new DateTime(2004, 03, 29)).ToString(), "Problem B date GB");
            Assert.AreEqual(new TVariant("#20040731#").ToString(), new TVariant(new DateTime(2004, 07, 31)).ToString(), "Problem C date GB");
            Assert.AreEqual("29-MAR-2004", StringHelper.DateToLocalizedString(new TVariant(new DateTime(2004, 03, 29)).ToDate()), "Problem D date GB");
            Assert.AreEqual("eDateTime:\"2004-07-31T00:00:00\"", new TVariant("#20040731#").EncodeToString(), "EncodeToString GB");
            Assert.AreEqual("29-MAR-2004", new TVariant(new DateTime(2004, 03, 29), "formatteddate").ToFormattedString(
                    ""), "Problem formatting dates");
            Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE", false);

            /* console.writeLine(CultureInfo.CurrentCulture.TwoLetterISOLanguageName); */
            Assert.AreEqual("29.03.2004", new TVariant(new DateTime(2004, 03, 29)).ToString(), "Problem A date DE");
            Assert.AreEqual("29-MÄR", new TVariant(new DateTime(2004, 03, 29)).ToFormattedString("dayofyear").Replace("MRZ",
                    "MÄR"), "Problem A2 day of year DE");
            Assert.AreEqual("29.03." + DateTime.Now.Year.ToString(), new TVariant(new DateTime(2004, 03, 29)).ToFormattedString("dayofyear",
                    "CSV"), "Problem A2 day of year CSV DE");

            /* Support for parsing the following sort of #<date># is obsolete: */
            Assert.AreEqual(new TVariant("#20040329#").ToString(), new TVariant(new DateTime(2004, 03, 29)).ToString(), "Problem B date DE");
            Assert.AreEqual(new TVariant("#20040731#").ToString(), new TVariant(new DateTime(2004, 07, 31)).ToString(), "Problem C date DE");

            /* To make this work, we should use short month names from local array, similar to GetLongMonthName; see the comment in Ict.Common.StringHelper, DateToLocalizedString */
            /* Assert.AreEqual('29M�R2004', DateToLocalizedString(TVariant.Create(DateTime.Create(2004,03,29)).ToDate()),'Problem D date DE'); */
            Assert.AreEqual("29-MÄR-2004", StringHelper.DateToLocalizedString(new TVariant(new DateTime(2004, 03,
                            29)).ToDate()), "Problem D date DE");
            Assert.AreEqual("eDateTime:\"2004-07-31T00:00:00\"", new TVariant("#20040731#").EncodeToString(), "EncodeToString DE");
            Assert.AreEqual("29-MÄR-2004", StringHelper.DateToLocalizedString(new TVariant("2004-03-29 00:00:00").ToDate()), "sqlite date value");
            Thread.CurrentThread.CurrentCulture = oldCulture;

            // Test Date Encoding/Decoding
            TVariant DateVar = new TVariant(new DateTime(2013, 11, 05, 16, 12, 07));

            Assert.AreEqual("eDateTime:\"2013-11-05T16:12:07\"", DateVar.EncodeToString());
            TVariant DateVar2 = TVariant.DecodeFromString("eDateTime:\"2013-11-05T16:12:07\"");
            Assert.AreEqual(new DateTime(2013, 11, 05, 16, 12, 07), DateVar2.ToDate());
        }
Exemple #18
0
        public void TestStringHelperFormatCurrency()
        {
            String DecimalSeparator;
            String ThousandsOperator;
            ArrayList cultures;
            TVariant v;

            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);

                /* Console.WriteLine('currently testing: ' + CultureInfo.CurrentCulture.Name); */
                DecimalSeparator = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;
                ThousandsOperator = CultureInfo.CurrentCulture.NumberFormat.CurrencyGroupSeparator;
                tstNr = 1;
                Assert.AreEqual("2" + DecimalSeparator + "23",
                    StringHelper.FormatCurrency(new TVariant(2.23), "Currency"), FormatTestName("variant parameter; positive; format: Currency"));
                Assert.AreEqual("0" + DecimalSeparator + "00",
                    StringHelper.FormatCurrency(new TVariant(0.00), "Currency"), FormatTestName("variant parameter; 0; format: Currency"));
                Assert.AreEqual("(2" + DecimalSeparator + "23)",
                    StringHelper.FormatCurrency(new TVariant(-2.23), "Currency"), FormatTestName("variant parameter; negative; format: Currency"));
                Assert.AreEqual('2' + DecimalSeparator + "23", StringHelper.FormatCurrency(new TVariant(
                            2.23), "#,##0.00;-#,##0.00;0.00; "), FormatTestName("variant parameter; positive; format: Access Style"));
                Assert.AreEqual('0' + DecimalSeparator + "00", StringHelper.FormatCurrency(new TVariant(
                            0.00), "#,##0.00;-#,##0.00;0.00; "), FormatTestName("variant parameter; 0; format: Access Style"));
                Assert.AreEqual("-2" + DecimalSeparator + "23", StringHelper.FormatCurrency(new TVariant(
                            -2.23), "#,##0.00;-#,##0.00; ; "), FormatTestName("variant parameter; negative; format: Access Style"));
                Assert.AreEqual("",
                    StringHelper.FormatCurrency(new TVariant(-2.23),
                        "#,##0.00; ; ; "), FormatTestName("variant parameter; negative; format: Access Style; only display positive values"));
                Assert.AreEqual("-2" + DecimalSeparator + "23",
                    StringHelper.FormatCurrency(new TVariant(-2.23),
                        ";-#,##0.00; ; "), FormatTestName("variant parameter; negative; format: Access Style; only display negative values"));
                Assert.AreEqual('2' + DecimalSeparator + "00",
                    StringHelper.FormatCurrency(new TVariant(-2.00),
                        ";#,##0.00; ; "),
                    FormatTestName(
                        "variant parameter; negative; format: Access Style; only display negative values, but without sign; also test if 0 are added"));
                Assert.AreEqual('2' + DecimalSeparator + "00",
                    StringHelper.FormatCurrency(new TVariant(-2),
                        ";#,##0.00; ; "),
                    FormatTestName(
                        "variant parameter; negative; format: Access Style; only display negative values, but without sign; also test if 0 are added; integer value"));
                Assert.AreEqual('2' + DecimalSeparator + "23",
                    StringHelper.FormatCurrency(new TVariant(2.23),
                        "->>>,>>>,>>>,>>9.99"), FormatTestName("variant parameter; positive; format: Progress Style"));
                Assert.AreEqual('0' + DecimalSeparator + "00",
                    StringHelper.FormatCurrency(new TVariant(0.00),
                        "->>>,>>>,>>>,>>9.99"), FormatTestName("variant parameter; 0; format: Progress Style"));
                Assert.AreEqual("-2" + DecimalSeparator + "23", StringHelper.FormatCurrency(new TVariant(
                            -2.23), "->>>,>>>,>>>,>>9.99"), FormatTestName("variant parameter; negative; format: Progress Style"));
                Assert.AreEqual("2",
                    StringHelper.FormatCurrency(new TVariant(2.23),
                        "->>>,>>>,>>>,>>9"), FormatTestName("variant parameter; positive; format: Progress Style, no decimals"));
                Assert.AreEqual("0",
                    StringHelper.FormatCurrency(new TVariant(0.00),
                        "->>>,>>>,>>>,>>9"), FormatTestName("variant parameter; 0; format: Progress Style, no decimals"));
                Assert.AreEqual("-2",
                    StringHelper.FormatCurrency(new TVariant(-2.23),
                        "->>>,>>>,>>>,>>9"), FormatTestName("variant parameter; negative; format: Progress Style, no decimals"));
                Assert.AreEqual("002" + DecimalSeparator + "23", StringHelper.FormatCurrency(new TVariant(
                            2.23), "->>>,>>>,>>>,999.99"), FormatTestName("variant parameter; positive; format: Progress Style, leading zeros"));
                Assert.AreEqual("000" + DecimalSeparator + "00", StringHelper.FormatCurrency(new TVariant(
                            0.00), "->>>,>>>,>>>,999.99"), FormatTestName("variant parameter; 0; format: Progress Style, leading zeros"));
                Assert.AreEqual("-002" + DecimalSeparator + "23", StringHelper.FormatCurrency(new TVariant(
                            -2.23), "->>>,>>>,>>>,999.99"), FormatTestName("variant parameter; negative; format: Progress Style, leading zeros"));
                Assert.AreEqual("2" + ThousandsOperator + "345" + DecimalSeparator + "23",
                    StringHelper.FormatCurrency(new TVariant(2345.23),
                        "->>>,>>>,>>>,>>9.99"), FormatTestName("variant parameter; positive; format: Progress Style, thousand separator"));
                Assert.AreEqual('2' + DecimalSeparator + "23",
                    StringHelper.FormatCurrency(2.23M, "->>>,>>>,>>>,>>9.99"), FormatTestName("decimal parameter"));
                Assert.AreEqual("223", StringHelper.FormatCurrency(223234, "#;(#);0;"), FormatTestName("just display the thousands"));
                Assert.AreEqual("0027045678", StringHelper.FormatCurrency(27045678, "0000000000;;;"), FormatTestName("partner key"));
                Assert.AreEqual("3%", StringHelper.FormatCurrency(3.0M, "0%;-0%;0;"), FormatTestName("percentage"));
                Assert.AreEqual("0029112233", StringHelper.FormatCurrency(29112233, "partnerkey"), FormatTestName("partnerkey"));
                Assert.AreEqual("31" + DecimalSeparator + "31%",
                    StringHelper.FormatCurrency(31.3053682781472M, "percentage2decimals"), FormatTestName("percentage2decimals"));
                Assert.AreEqual("31" + DecimalSeparator + "31%", StringHelper.FormatCurrency(new TVariant(
                            31.3053682781472), "percentage2decimals"), FormatTestName("percentage2decimals TVariant"));
                Assert.AreEqual("31" + DecimalSeparator + "31%",
                    StringHelper.FormatCurrency(TVariant.DecodeFromString(new TVariant(
                                31.3053682781472).EncodeToString()), "percentage2decimals"), FormatTestName("percentage2decimals TVariant Encoded"));
                Assert.AreEqual("31" + DecimalSeparator + "31%",
                    StringHelper.FormatCurrency(TVariant.DecodeFromString(new TVariant(31.3053682781472M,
                                "percentage2decimals").EncodeToString()),
                        "percentage2decimals"), FormatTestName("percentage2decimals TVariant Encoded 2"));
                v = new TVariant(31.3053682781472);
                v.FormatString = "percentage2decimals";
                Assert.AreEqual("eDecimal:percentage2decimals:4629504895489138888", v.EncodeToString(),
                    FormatTestName("percentage2decimals encodetostring"));
                Assert.AreEqual("31" + DecimalSeparator + "31%", StringHelper.FormatCurrency(TVariant.DecodeFromString(
                            v.EncodeToString()), ""), FormatTestName("percentage2decimals TVariant Encoded 3"));
                v = new TVariant(31);
                v.FormatString = "percentage2decimals";
                Assert.AreEqual("eInteger:percentage2decimals:31", v.EncodeToString(), FormatTestName("percentage2decimals encodetostring integer"));
            }
        }
Exemple #19
0
        /// <summary>
        /// function selection
        /// </summary>
        /// <param name="f">function name</param>
        /// <param name="ops">if ops[1] is nil, and f cannot be evaluated, return nil; otherwise if ops is not nil, print an error if f cannot be evaluated</param>
        /// <returns>void</returns>
        private TVariant FunctionSelector(String f, TVariant[] ops)
        {
            TVariant ReturnValue = null;
            TRptUserFunctions rptUserFunctions;
            String s;
            String s2;

            System.Int32 start;
            System.Int32 length;
            String logMessage;
            bool FunctionFound;
            int counter;
            f = f.ToLower();
            TLogging.SetContext("call to function " + f);
            TParameterList myParams = GetParameters();

            if ((f == "eq") || (f == "ne"))
            {
                // check if at least one of the parameters is a variable; otherwise give warning
                if ((ops[1].ToString().IndexOf('{') == -1) && (ops[2].ToString().IndexOf('{') == -1))
                {
                    TLogging.Log(
                        "Warning: comparison should contain at least one variable: " + f.ToString() + '(' + ops[1].ToString() + ',' + ops[2].ToString(
                            ) +
                        ')', TLoggingType.ToLogfile | TLoggingType.ToConsole);
                }
            }

            if ((f == "isnull") || (f == "exists") || (f == "or") || (f == "and") || (f == "iif") || (f == "assign"))
            {
                // need to replace the variables manually
                // either because we don't want them replaced at all (isnull or exists needs the variable name),
                // or because we don't want to evaluate the second parameter if the first one already defines the result (e.g. or)
            }
            else
            {
                for (counter = 1; counter <= ReportingConsts.MAX_FUNCTION_PARAMETER; counter += 1)
                {
                    ops[counter] = EvaluateOperand(ops[counter]);
                }
            }

            if (f == "eq")
            {
                ReturnValue = new TVariant(ops[1].CompareToI(ops[2]) == 0);
            }
            else if (f == "ne")
            {
                ReturnValue = new TVariant(ops[1].CompareToI(ops[2]) != 0);
            }
            else if (f == "lt")
            {
                ReturnValue = new TVariant(ops[1].CompareTo(ops[2]) < 0);
            }
            else if (f == "le")
            {
                ReturnValue = new TVariant(ops[1].CompareTo(ops[2]) <= 0);
            }
            else if (f == "gt")
            {
                ReturnValue = new TVariant(ops[1].CompareTo(ops[2]) > 0);
            }
            else if (f == "ge")
            {
                ReturnValue = new TVariant(ops[1].CompareTo(ops[2]) >= 0);
            }
            else if (f == "sub")
            {
                ReturnValue = new TVariant(ops[1].ToDecimal() - ops[2].ToDecimal());
            }
            else if (f == "adddays")
            {
                ReturnValue = new TVariant(ops[1].ToDate().AddDays(ops[2].ToDouble()));
            }
            else if (f == "add")
            {
                ReturnValue = new TVariant(ops[1].ToDecimal() + ops[2].ToDecimal());
            }
            else if (f == "additems")
            {
                length = ops[1].ToInt() + 1;

                decimal result = 0.0M;

                for (counter = 2; counter <= length; ++counter)
                {
                    result += ops[counter].ToDecimal();
                }

                ReturnValue = new TVariant(result);
            }
            else if (f == "mul")
            {
                ReturnValue = new TVariant(ops[1].ToDecimal() * ops[2].ToDecimal());
            }
            else if (f == "div")
            {
                if (ops[2].ToDecimal() == 0)
                {
                    ReturnValue = new TVariant(0.0);
                }
                else
                {
                    ReturnValue = new TVariant(ops[1].ToDecimal() / ops[2].ToDecimal());
                }
            }
            else if (f == "mod")
            {
                if (ops[2].ToDecimal() == 0)
                {
                    ReturnValue = new TVariant(0.0);
                }
                else
                {
                    ReturnValue = new TVariant(ops[1].ToInt64() % ops[2].ToInt64());
                }
            }
            else if (f == "floor")
            {
                ReturnValue = new TVariant(Math.Floor(ops[1].ToDecimal()));
            }
            else if (f == "round")
            {
                ReturnValue = new TVariant(Math.Round(ops[1].ToDecimal()));
            }
            else if (f == "not")
            {
                ReturnValue = new TVariant(!ops[1].ToBool());
            }
            else if (f == "iif")
            {
                // iif ( condition, value_if_true, value_if_false )
                ops[1] = EvaluateOperand(ops[1]);

                if (ops[1].ToBool() == true)
                {
                    ops[2] = EvaluateOperand(ops[2]);
                    ReturnValue = new TVariant(ops[2]);
                }
                else
                {
                    ops[3] = EvaluateOperand(ops[3]);
                    ReturnValue = new TVariant(ops[3]);
                }
            }
            else if (f == "or")
            {
                ops[1] = EvaluateOperand(ops[1]);

                if (ops[1].ToBool() == false)
                {
                    ops[2] = EvaluateOperand(ops[2]);
                    ReturnValue = new TVariant(ops[2].ToBool());
                }
                else
                {
                    ReturnValue = new TVariant(true);
                }
            }
            else if (f == "and")
            {
                ops[1] = EvaluateOperand(ops[1]);

                if (ops[1].ToBool() == true)
                {
                    ops[2] = EvaluateOperand(ops[2]);
                    ReturnValue = new TVariant(ops[2].ToBool());
                }
                else
                {
                    ReturnValue = new TVariant(false);
                }
            }
            else if (f == "log")
            {
                if (ops[2] != null)
                {
                    ReturnValue = new TVariant(ops[1].ToString() + " " + ops[2].ToString());
                }
                else
                {
                    if (myParams.Exists(ops[1].ToString()))
                    {
                        myParams.Debug(ops[1].ToString());
                        ReturnValue = new TVariant();
                    }
                    else
                    {
                        ReturnValue = ops[1];
                    }
                }

                if (!ReturnValue.IsNil())
                {
                    TLogging.Log(ReturnValue.ToString());
                }
            }
            else if (f == "length")
            {
                ReturnValue = new TVariant(ops[1].ToString().Length);
            }
            else if (StringHelper.IsSame(f, "ContainsCSV"))
            {
                ReturnValue = new TVariant(StringHelper.ContainsCSV(ops[1].ToString(), ops[2].ToString()));
            }
            else if (f == "replace")
            {
                ReturnValue = new TVariant(ops[1].ToString().Replace(ops[2].ToString(), ops[3].ToString()));
            }
            else if ((f == "substring") || (f == "substr"))
            {
                s = ops[1].ToString();
                start = ops[2].ToInt();
                length = ops[3].ToInt();

                if ((start < s.Length) && (start + length <= s.Length) && (length > 0))
                {
                    ReturnValue = new TVariant(s.Substring(start, length));
                }
                else
                {
                    ReturnValue = new TVariant("");
                    TLogging.Log("Text is not long enough or length is wrong: " + s + ' ' + start.ToString() + ' ' + length.ToString());
                }
            }
            else if ((f == "substringright") || (f == "substrright"))
            {
                s = ops[1].ToString();
                length = ops[2].ToInt();
                start = s.Length - length;

                if ((start < s.Length) && (start + length <= s.Length) && (length > 0))
                {
                    ReturnValue = new TVariant(s.Substring(start, length));
                }
                else
                {
                    ReturnValue = new TVariant("");
                    TLogging.Log("Text is not long enough or length is wrong: " + s + ' ' + start.ToString() + ' ' + length.ToString());
                }
            }
            else if ((f == "substringwithoutright") || (f == "substrwithoutright"))
            {
                s = ops[1].ToString();
                length = s.Length - ops[2].ToInt();
                start = 0;

                if ((start < s.Length) && (start + length <= s.Length) && (length > 0))
                {
                    ReturnValue = new TVariant(s.Substring(start, length));
                }
                else
                {
                    ReturnValue = new TVariant("");
                    TLogging.Log("Text is not long enough or length is wrong: " + s + ' ' + start.ToString() + ' ' + length.ToString());
                }
            }
            else if (f == "concatenate")
            {
                s = ops[1].ToString();

                s = s + ops[2].ToString();

                ReturnValue = new TVariant(s);
            }
            else if (f == "concatenateww")
            {
                s = ops[1].ToString();
                length = ops[3].ToInt();

                s = s.PadRight(s.Length + length);

                s = s + ops[2].ToString();

                ReturnValue = new TVariant(s);
            }
            else if (f == "concatenatewithcomma")
            {
                s = ops[1].ToString();
                s2 = ops[2].ToString();

                if ((s.Length > 0)
                    && (s2.Length > 0))
                {
                    s = s + ", ";
                }

                s = s + s2;

                ReturnValue = new TVariant(s);
            }
            else if (f == "format")
            {
                ReturnValue = new TVariant(ops[1].ToFormattedString(ops[2].ToString()));
            }
            else if (f == "formattime")
            {
                String separator = ops[1].ToString();
                String hour = ops[2].ToString();
                String min = ops[3].ToString();
                String sec = "";

                if ((ops.Length > 4) && (ops[4] != null))
                {
                    sec = ops[4].ToString();
                }

                if (hour.Length < 2)
                {
                    hour = "0" + hour;
                }

                if (min.Length < 2)
                {
                    min = "0" + min;
                }

                if ((sec.Length < 2) && (sec.Length > 0))
                {
                    sec = "0" + sec;
                }

                if (sec.Length > 0)
                {
                    ReturnValue = new TVariant(hour + separator + min + separator + sec);
                }
                else
                {
                    ReturnValue = new TVariant(hour + separator + min);
                }
            }
            else if (f == "assign")
            {
                string targetVariableName = ops[1].ToString();

                if (targetVariableName.StartsWith("{") && targetVariableName.EndsWith("}"))
                {
                    targetVariableName = targetVariableName.Substring(1, targetVariableName.Length - 2);
                }

                ops[2] = EvaluateOperand(ops[2]);

                if (myParams.Exists(targetVariableName))
                {
                    // we should overwrite the existing variable, not add on another level
                    TParameter origParameter = myParams.GetParameter(targetVariableName);
                    origParameter.value = ops[2];
                }
                else
                {
                    myParams.Add(targetVariableName, ops[2], -1, -1, null, null, ReportingConsts.CALCULATIONPARAMETERS);
                }

//              TLogging.Log("Assign: " + targetVariableName + "=" + ops[2].ToString());
                ReturnValue = ops[2];
            }
            else if (f == "exists")
            {
                ReturnValue = new TVariant(myParams.Exists(ops[1].ToString(), column, Depth));
            }
            else if (f == "isnull")
            {
                ReturnValue =
                    new TVariant((!myParams.Exists(ops[1].ToString(), column,
                                      Depth) || myParams.Get(ops[1].ToString(), column, Depth).IsZeroOrNull()));
            }
            else if (f == "template")
            {
                TRptCalculation rptTemplate = ReportStore.GetCalculation(CurrentReport, ops[1].ToString());
                TRptDataCalcCalculation rptTempCalculation = new TRptDataCalcCalculation(this);
                ReturnValue = rptTempCalculation.Calculate(rptTemplate, null);
            }
            else if (f == "columnexist")
            {
                String ColumnID = ops[1].ToString();
                bool ColumnExist = false;

                System.Data.DataTable TempTable = myParams.ToDataTable();
                int numColumns = TempTable.Columns.Count;

                foreach (System.Data.DataRow Row in TempTable.Rows)
                {
                    for (int Counter = 0; Counter < numColumns; ++Counter)
                    {
                        if (Row[Counter].ToString() == ColumnID)
                        {
                            ColumnExist = true;
                            break;
                        }
                    }

                    if (ColumnExist)
                    {
                        break;
                    }
                }

                ReturnValue = new TVariant(ColumnExist);
            }
            else if (f == "conditionrow")
            {
                ReturnValue = new TVariant(ops[1]);

                if (ReturnValue.ToBool() == false)
                {
                    // clear this row, we don't want to display it
                    // set all parameters of this row to NULL
                    myParams.Add("DONTDISPLAYROW", new TVariant(true));
                }
                else
                {
                    myParams.Add("DONTDISPLAYROW", new TVariant(false), -1, -1, null, null, ReportingConsts.CALCULATIONPARAMETERS);
                }
            }
            else if (f == "column")
            {
                if ((ops[1].ToInt() >= 0) && (ops[1].ToInt() < CurrentColumns.Length))
                {
                    ReturnValue = new TVariant(CurrentColumns[ops[1].ToInt()]);
                }
                else
                {
                    TLogging.Log("referenced column does not exist: " + ops[1].ToString());
                    ReturnValue = new TVariant();
                }
            }
            else if (f == "HasColumns".ToLower())
            {
                ReturnValue = new TVariant(Results.HasColumns(this.LineId));
            }
            else if (f == "HasChildRows".ToLower())
            {
                ReturnValue = new TVariant(Results.HasChildRows(this.LineId));
            }
            else if (f == "HasChildColumns".ToLower())
            {
                ReturnValue = new TVariant(Results.HasChildColumns(this.LineId));
            }
            else if (f == "invisible".ToLower())
            {
                // need to return true so that calculation happens.
                ReturnValue = new TVariant(true);
            }
            else if (f == "fatherColumn")
            {
                ReturnValue = GetParentValue(ParentRowId, ops[1].ToInt());
            }
            else if (f == "childColumn")
            {
                ReturnValue = GetChildValue(LineId, ops[1].ToInt());
            }
            else if (StringHelper.IsSame(f, "SecondLevelColumn"))
            {
                ReturnValue = Get2ndLevelValue(ParentRowId, ops[1].ToInt());
            }
            else if (StringHelper.IsSame(f, "FirstLevelColumn"))
            {
                ReturnValue = Get1stLevelValue(ParentRowId, ops[1].ToInt());
            }
            else if (StringHelper.IsSame(f, "GetShortCaption"))
            {
                ReturnValue = new TVariant(GetShortCaption(ops[1].ToInt()));
            }
            else if (StringHelper.IsSame(f, "GetCaption"))
            {
                ReturnValue = new TVariant(GetCaption(ops[1].ToInt()));
            }
            else if (StringHelper.IsSame(f, "getSumLower2Report"))
            {
                if (ops[3] == null)
                {
                    ReturnValue = new TVariant(GetSumLower2Report(ops[1].ToInt(), ops[2].ToInt(), true), "currency");
                }
                else
                {
                    ReturnValue = new TVariant(GetSumLower2Report(ops[1].ToInt(), ops[2].ToInt(), ops[3].ToBool()), "currency");
                }
            }
            else if (StringHelper.IsSame(f, "getSumLowerReport"))
            {
                if (ops[3] == null)
                {
                    ReturnValue = new TVariant(GetSumLowerReport(ops[1].ToInt(), ops[2].ToInt(), true), "currency");
                }
                else
                {
                    ReturnValue = new TVariant(GetSumLowerReport(ops[1].ToInt(), ops[2].ToInt(), ops[3].ToBool()), "currency");
                }
            }
            else if (StringHelper.IsSame(f, "getSumLowerReportCredit"))
            {
                ReturnValue = new TVariant(GetSumLowerReportCredit(ops[1].ToInt(), ops[2].ToInt()), "currency");
            }
            else
            {
                FunctionFound = false;

                foreach (System.Type userFunctionsClass in FUserFunctions)
                {
                    if (!FunctionFound)
                    {
                        rptUserFunctions = (TRptUserFunctions)Activator.CreateInstance(userFunctionsClass);

                        if (rptUserFunctions.FunctionSelector(this, f, ops, out ReturnValue))
                        {
                            FunctionFound = true;
                            break;
                        }

                        rptUserFunctions = null;
                    }
                }

                if (!FunctionFound)
                {
                    TRptCalculation calculation = ReportStore.GetCalculation(CurrentReport, f);

                    if (calculation != null)
                    {
                        TRptDataCalcCalculation calc = new TRptDataCalcCalculation(this);
                        ReturnValue = calc.EvaluateCalculation(calculation, null, String.Empty, -1);
                    }
                    else if (ops[1] == null)
                    {
                        // don't print an error if ops[1] is null;
                        // just return f;
                        // this is needed e.g. for HasChildRows etc, called from TRptEvaluator.evaluateOperator
                        ReturnValue = null;
                    }
                    else
                    {
                        ReturnValue = new TVariant();
                        logMessage = "unknown function " + f;

                        if (ops[1] != null)
                        {
                            logMessage = logMessage + ' ' + ops[1].ToString();
                        }

                        if (ops[2] != null)
                        {
                            logMessage = logMessage + ' ' + ops[2].ToString();
                        }

                        TLogging.Log(logMessage);
                    }
                }
            }

            TLogging.SetContext("");
            return ReturnValue;
        }
Exemple #20
0
        /// <summary>
        /// functions need to be registered here
        /// </summary>
        /// <param name="ASituation"></param>
        /// <param name="f"></param>
        /// <param name="ops"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override Boolean FunctionSelector(TRptSituation ASituation, String f, TVariant[] ops, out TVariant value)
        {
            if (base.FunctionSelector(ASituation, f, ops, out value))
            {
                return true;
            }

            if (StringHelper.IsSame(f, "GetSiteName"))
            {
                value = new TVariant(GetSiteName());
                return true;
            }

            if (StringHelper.IsSame(f, "GetCurrentCommitmentPeriod"))
            {
                value = new TVariant(GetCurrentCommitmentPeriod(ops[1].ToInt64(), ops[2].ToDate()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetType"))
            {
                value = new TVariant(GetType(ops[1].ToInt64(), ops[2].ToString(), ops[3].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "GenerateUnitHierarchy"))
            {
                value = new TVariant(GenerateUnitHierarchy(ops[1].ToInt64(), ops[2].ToString()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetMissingInfo"))
            {
                value = new TVariant(GetMissingInfo(ops[1].ToInt64(), ops[2].ToInt(), ops[3].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetPersonLanguages"))
            {
                value = new TVariant(GetPersonLanguages(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetPassport"))
            {
                value = new TVariant(GetPassport(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetNationalities"))
            {
                value = new TVariant(GetNationalities(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetChurch"))
            {
                value = new TVariant(GetChurch(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetDietary"))
            {
                value = new TVariant(GetDietary(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetMedicalInfo"))
            {
                value = new TVariant(GetMedicalInfo(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetOtherNeeds"))
            {
                value = new TVariant(GetOtherNeeds(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetPartnerContact"))
            {
                value = new TVariant(GetPartnerContact(ops[1].ToInt64()));
                return true;
            }

            if (StringHelper.IsSame(f, "CalculateAge"))
            {
                value = new TVariant(CalculateAge(ops[1].ToDate()));
                return true;
            }

            if (StringHelper.IsSame(f, "CalculateAgeAtDate"))
            {
                value = new TVariant(CalculateAgeAtDate(ops[1].ToDate(), ops[2].ToDate()));
                return true;
            }

            if (StringHelper.IsSame(f, "GetArrivalPoint"))
            {
                value = new TVariant(GetArrivalPoint(ops[1].ToString()));
                return true;
            }

            /*
             * if (isSame(f, 'doSomething')) then
             * begin
             * value := new TVariant();
             * doSomething(ops[1].ToInt(), ops[2].ToString(), ops[3].ToString());
             * exit;
             * end;
             */
            value = new TVariant();
            return false;
        }
        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;
        }
Exemple #22
0
        /// <summary>
        /// Fill one of the first five columns of one row of the publication statistical report
        /// 1. column is County name
        /// 2. column is number of donors
        /// 3. column is number of ex omers
        /// 4. column is number of churches
        /// 5. column is number of applicants
        /// </summary>
        /// <param name="AParameterLabel">defines which of the first five columns should be filled</param>
        /// <param name="AColumn">Column index in the result</param>
        /// <param name="ACountyName"></param>
        /// <param name="ADonors"></param>
        /// <param name="AExParticipants"></param>
        /// <param name="AChurches"></param>
        /// <param name="AApplicants"></param>
        private void FillFirstColumns(String AParameterLabel, int AColumn, String ACountyName,
            TVariant ADonors, TVariant AExParticipants,
            TVariant AChurches, TVariant AApplicants)
        {
            TVariant ValueToUse = null;

            if (AParameterLabel == "County")
            {
                ValueToUse = new TVariant(ACountyName);
            }
            else if (AParameterLabel == "Donors")
            {
                ValueToUse = ADonors;
            }
            else if (AParameterLabel == "ExParticipants")
            {
                ValueToUse = AExParticipants;
            }
            else if (AParameterLabel == "Churches")
            {
                ValueToUse = AChurches;
            }
            else if (AParameterLabel == "Applicants")
            {
                ValueToUse = AApplicants;
            }

            if (ValueToUse != null)
            {
                situation.GetParameters().Add(AParameterLabel,
                    ValueToUse,
                    AColumn, -1,
                    null, null, ReportingConsts.CALCULATIONPARAMETERS);
            }
        }
        /// <summary>
        /// Insert an empty row into the report results
        /// </summary>
        /// <param name="ANumColumns">Number of columns the report has</param>
        /// <param name="AChildRow">The child row index</param>
        /// <param name="AVenueName">The first column entry</param>
        /// <param name="ASituation">The current report situation</param>
        /// <returns>true</returns>
        private bool InsertEmptyRow(int ANumColumns, int AChildRow, String AVenueName, ref TRptSituation ASituation)
        {
            TVariant[] Header = new TVariant[ANumColumns];
            TVariant[] Description =
            {
                new TVariant(), new TVariant()
            };
            TVariant[] Columns = new TVariant[ANumColumns];

            for (int Counter = 0; Counter < ANumColumns; ++Counter)
            {
                Columns[Counter] = new TVariant(" ");
                Header[Counter] = new TVariant();
            }

            Columns[0] = new TVariant(AVenueName);

            ASituation.GetResults().AddRow(0, AChildRow, true, 2, "", "", false,
                Header, Description, Columns);
            return true;
        }
Exemple #24
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="child"></param>
        /// <param name="col"></param>
        /// <returns></returns>
        protected TVariant Get1stLevelValue(int child, int col)
        {
            TVariant ReturnValue;
            int master;
            decimal masterval;
            int masterlevel;

            ReturnValue = new TVariant();
            master = child;
            masterval = CurrentColumns[col].ToDecimal();
            masterlevel = Depth;

            while (masterlevel > 1)
            {
                child = master;
                GetParentLine(child, col, ref master, ref masterval, ref masterlevel);
            }

            if ((masterlevel == 1) && (masterval != 0))
            {
                ReturnValue = new TVariant(masterval);
            }

            return ReturnValue;
        }
        /// <summary>
        /// Insert the values of the detail data row if we have "Detail" as report level.
        /// The detail row contains for each partner the room bookings.
        /// </summary>
        /// <param name="ANumColumns">Number of columns the report has</param>
        /// <param name="AChildRow">Index of the child row</param>
        /// <param name="ARoomName">The room name of which to add the details to the table</param>
        /// <param name="ASituation">The current report situation</param>
        /// <returns>true</returns>
        private bool InsertDetailDataRow(int ANumColumns, ref int AChildRow, string ARoomName, ref TRptSituation ASituation)
        {
            foreach (DataRow DetailRow in FAccommodationDetailTable.Rows)
            {
                if (DetailRow["RoomName"].ToString() != ARoomName)
                {
                    continue;
                }

                TVariant[] Header = new TVariant[ANumColumns];
                TVariant[] Description =
                {
                    new TVariant(), new TVariant()
                };
                TVariant[] Columns = new TVariant[ANumColumns];

                for (int Counter = 0; Counter < ANumColumns; ++Counter)
                {
                    Columns[Counter] = new TVariant(DetailRow[Counter].ToString());
                    Header[Counter] = new TVariant();
                }

                ASituation.GetResults().AddRow(0, AChildRow++, true, 2, "", "", false,
                    Header, Description, Columns);
            }

            return true;
        }
        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);
        }
Exemple #27
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="s"></param>
        /// <param name="withQuotes"></param>
        /// <returns></returns>
        public TVariant ReplaceVariables(String s, Boolean withQuotes)
        {
            TVariant ReturnValue;

            // find all variables given in
            // name translates into "value"
            // name is changed to value
            // #name# is changed to "value" (date)
            // if the variable should be retrieved with getParameter("variablename", 1,1,true) => use GLOBAL:variablename
            // var
            // todo: Integer;  need to make it work for postgresql as well
            ReturnValue = new TVariant(s);
            ReturnValue = ReplaceVariablesPattern(ReturnValue, "{{", "}}", "", "", new TConvertProc(Id));

            ReturnValue = ReplaceVariablesPattern(ReturnValue, "{#", "#}", "", "", new TConvertProc(FormatDate));

            if (withQuotes)
            {
                ReturnValue = ReplaceVariablesPattern(ReturnValue, "{", "}", "'", "'", new TConvertProc(Id));
            }
            else
            {
                ReturnValue = ReplaceVariablesPattern(ReturnValue, "{", "}", "", "", new TConvertProc(Id));
            }

            return ReturnValue;
        }
Exemple #28
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="AKey"></param>
        /// <param name="ADefault"></param>
        /// <returns></returns>
        public static bool GetBooleanDefault(String AKey, bool ADefault)
        {
            bool ReturnValue;
            TVariant value;

            try
            {
                value = new TVariant(TInternal.GetUserDefault(AKey, ADefault.ToString()));
                ReturnValue = value.ToBool();
            }
            catch (Exception)
            {
                ReturnValue = false;
            }
            return ReturnValue;
        }
 /// <summary>
 /// Set the given DateTime control to be blank instead of
 /// DateTime.Now if the value is not specified.
 /// </summary>
 private void SetdtpControlManual(Ict.Petra.Client.CommonControls.TtxtPetraDate AControl,
     TVariant AValue)
 {
     if (AValue.IsZeroOrNull())
     {
         AControl.Date = null;
     }
 }
Exemple #30
0
        private bool GetPartnerLabelValues()
        {
            PPartnerTable PartnerTable;

            System.Data.DataTable mTable;
            System.Int32 col;
            TRptCalculation mRptCalculation;
            TRptDataCalcCalculation mRptDataCalcCalculation;
            TVariant mRptCalcResult;
            mRptCalculation = situation.GetReportStore().GetCalculation(situation.GetCurrentReport(), "PartnerLabelValue");
            mRptDataCalcCalculation = new TRptDataCalcCalculation(situation);
            mRptCalcResult = mRptDataCalcCalculation.EvaluateCalculationAll(mRptCalculation,
                null,
                mRptCalculation.rptGrpTemplate,
                mRptCalculation.rptGrpQuery);
            List <int>AddedColumns = new List <int>();

            if (mRptCalcResult.IsZeroOrNull())
            {
                return false;
            }

            mTable = situation.GetDatabaseConnection().SelectDT(mRptCalcResult.ToString(), "table", situation.GetDatabaseConnection().Transaction);

            foreach (DataRow mRow in mTable.Rows)
            {
                TVariant LabelValue = new TVariant();

                // Data Type: (char | integer | float | currency | boolean | date | time | partnerkey | lookup)
                if (mRow["LabelDataType"].ToString() == "char")
                {
                    LabelValue = new TVariant(mRow["LabelValueChar"].ToString());
                }
                else if (mRow["LabelDataType"].ToString() == "integer")
                {
                    LabelValue = new TVariant(mRow["LabelValueInt"]);
                }
                else if (mRow["LabelDataType"].ToString() == "float")
                {
                    // todo p_num_decimal_places_i
                    LabelValue = new TVariant(mRow["LabelValueNum"]);
                }
                else if (mRow["LabelDataType"].ToString() == "currency")
                {
                    LabelValue = new TVariant(StringHelper.FormatUsingCurrencyCode(
                            Convert.ToDecimal(mRow["LabelValueCurrency"]), mRow["CurrencyCode"].ToString()) +
                        ' ' + mRow["CurrencyCode"].ToString());
                }
                else if (mRow["LabelDataType"].ToString() == "boolean")
                {
                    LabelValue = new TVariant(mRow["LabelValueBool"]);
                }
                else if (mRow["LabelDataType"].ToString() == "date")
                {
                    LabelValue = new TVariant(mRow["LabelValueDate"]);
                }
                else if (mRow["LabelDataType"].ToString() == "time")
                {
                    // todo needs testing
                    LabelValue = new TVariant(Conversions.Int32TimeToDateTime(Convert.ToInt32(mRow["LabelValueTime"])).ToString("t"));
                }
                else if (mRow["LabelDataType"].ToString() == "lookup")
                {
                    // todo p_lookup_category_code_c
                    LabelValue = new TVariant(mRow["LabelValueLookup"]);
                }
                else if (mRow["LabelDataType"].ToString() == "partnerkey")
                {
                    // retrieve the shortname of this partner
                    LabelValue = new TVariant(mRow["LabelValuePartnerKey"]);
                    PartnerTable = PPartnerAccess.LoadByPrimaryKey(LabelValue.ToInt64(),
                        StringHelper.StrSplit(PPartnerTable.GetPartnerShortNameDBName(), ","), situation.GetDatabaseConnection().Transaction);

                    if (PartnerTable.Rows.Count != 0)
                    {
                        LabelValue = new TVariant(PartnerTable[0].PartnerShortName);
                    }
                }
                else
                {
                    LabelValue = new TVariant("unknown data label type");
                }

                for (col = 0; col <= situation.GetParameters().Get("MaxDisplayColumns").ToInt() - 1; col += 1)
                {
                    if (!AddedColumns.Contains(col))
                    {
                        situation.GetParameters().RemoveVariable("LabelValue", col, situation.GetDepth(), eParameterFit.eBestFit);
                    }

                    if (situation.GetParameters().Exists("param_label", col, -1, eParameterFit.eExact))
                    {
                        if (mRow["LabelName"].ToString() == situation.GetParameters().Get("param_label", col, -1, eParameterFit.eExact).ToString())
                        {
                            if (!LabelValue.IsNil())
                            {
                                situation.GetParameters().Add("LabelValue",
                                    LabelValue,
                                    col, situation.GetDepth(),
                                    null, null, ReportingConsts.CALCULATIONPARAMETERS);
                                AddedColumns.Add(col);
                            }
                        }
                    }
                }
            }

            return true;
        }