Beispiel #1
0
        private void WriteMonetary(ref int roundingLevels, StringBuilder sbRoundingOption, RoundingLevel roundingMonetary, string uniformRoundingString)
        {
            //nothing to see here
            if (roundingMonetary <= RoundingLevel.NoRounding)
            {
                return;
            }

            roundingLevels++;
            string stLevel = ReportBuilder.GetRoundingLevelString(roundingMonetary);

            sbRoundingOption.Append(string.Format(uniformRoundingString, stLevel));
        }
Beispiel #2
0
        private void WritePerShare(ref int roundingLevels, StringBuilder sbRoundingOption,
                                   RoundingLevel roundingMonetary, RoundingLevel roundingShares, RoundingLevel roundingPerShare,
                                   string perShareNoRoundingString, string perShareRoundingString, string otherRoundingString)
        {
            //nothing to see here
            if (roundingPerShare == RoundingLevel.UnKnown)
            {
                return;
            }

            //still nothing to see here
            if (roundingLevels == 0)
            {
                return;
            }

            //if we are equal, this value has already been set
            if (roundingPerShare == roundingShares)
            {
                return;
            }

            if (roundingLevels == 1)
            {
                sbRoundingOption.Append(", except ");

                if (roundingPerShare == RoundingLevel.NoRounding)
                {
                    sbRoundingOption.Append(perShareNoRoundingString);
                }
                else
                {
                    string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares);
                    sbRoundingOption.Append(string.Format(perShareRoundingString, stLevel));
                }
            }
            else             //2
            {
                //if we are equal, this value has already been set
                if (roundingPerShare == roundingMonetary)
                {
                    return;
                }

                sbRoundingOption.Append(", " + otherRoundingString);
            }

            roundingLevels++;
        }
Beispiel #3
0
        private RoundingLevel GetNormalizedRoundingLevel(RoundingLevel roundingLevel)
        {
            switch (roundingLevel)
            {
            case RoundingLevel.UnKnown:
            case RoundingLevel.NoRounding:
                return(roundingLevel);
            }

            try
            {
                string levelStr = ReportBuilder.GetRoundingLevelString(roundingLevel);
                return((RoundingLevel)Enum.Parse(typeof(RoundingLevel), levelStr));
            }
            catch { }

            return(RoundingLevel.UnKnown);
        }
Beispiel #4
0
        private void WriteShares(ref int roundingLevels, StringBuilder sbRoundingOption,
                                 RoundingLevel roundingMonetary, RoundingLevel roundingShares, RoundingLevel roundingPerShare,
                                 string uniformRoundingString,
                                 string sharesNoRoundingString, string sharesRoundingString,
                                 string bothSharesNoRoundingString, string bothSharesRoundingString)
        {
            //nothing to see here
            if (roundingShares == RoundingLevel.UnKnown)
            {
                return;
            }

            //if we are equal, this value has already been set
            if (roundingShares == roundingMonetary)
            {
                return;
            }

            //if not monetary, and not shares, do not set the rounding
            if (roundingMonetary <= RoundingLevel.NoRounding &&
                roundingShares <= RoundingLevel.NoRounding)
            {
                return;
            }

            //write out the "uniform" rounding string
            if (roundingMonetary == RoundingLevel.UnKnown &&
                roundingShares > RoundingLevel.NoRounding)
            {
                roundingLevels++;
                string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares);
                sbRoundingOption.Append(string.Format(uniformRoundingString, stLevel));
                return;
            }

            if (roundingMonetary == RoundingLevel.NoRounding &&
                roundingShares > RoundingLevel.NoRounding)
            {
                if (roundingShares != roundingPerShare)
                {
                    string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares);
                    sbRoundingOption.Append(string.Format(sharesRoundingString, stLevel));
                }
                else
                {
                    string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares);
                    sbRoundingOption.Append(string.Format(bothSharesRoundingString, stLevel));
                }

                roundingLevels++;
                return;
            }

            if (roundingMonetary > RoundingLevel.NoRounding)
            {
                //the scenario where these match is covered above
                if (roundingShares > RoundingLevel.UnKnown)
                {
                    sbRoundingOption.Append(", except ");
                }

                if (roundingShares == RoundingLevel.NoRounding)
                {
                    if (roundingPerShare == RoundingLevel.NoRounding)
                    {
                        sbRoundingOption.Append(bothSharesNoRoundingString);
                    }
                    else
                    {
                        sbRoundingOption.Append(sharesNoRoundingString);
                    }
                }
                else
                {
                    if (roundingShares == roundingPerShare)
                    {
                        string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares);
                        sbRoundingOption.Append(string.Format(bothSharesRoundingString, stLevel));
                    }
                    else
                    {
                        string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares);
                        sbRoundingOption.Append(string.Format(sharesRoundingString, stLevel));
                    }
                }

                roundingLevels++;
                return;
            }
        }
Beispiel #5
0
        public void SetRoundingOption(
            string uniformRoundingString,

            string sharesNoRoundingString,
            string sharesRoundingString,

            string bothSharesNoRoundingString,
            string bothSharesRoundingString,

            string perShareNoRoundingString,
            string perShareRoundingString,

            string otherRoundingString)
        {
            if (uniformRoundingString.Split(new string[] { ROUNDING_LEVEL_PLACEHOLDER }, StringSplitOptions.None).Length > 2)
            {
                throw new Exception("Invalid format for uniformRoundingString");
            }
            else
            {
                uniformRoundingString = uniformRoundingString.Replace(ROUNDING_LEVEL_PLACEHOLDER, "{0}");
            }

            if (sharesRoundingString.Split(new string[] { ROUNDING_LEVEL_PLACEHOLDER }, StringSplitOptions.None).Length > 2)
            {
                throw new Exception("Invalid format for shareRoundingString");
            }
            else
            {
                sharesRoundingString = sharesRoundingString.Replace(ROUNDING_LEVEL_PLACEHOLDER, "{0}");
            }

            if (bothSharesRoundingString.Split(new string[] { ROUNDING_LEVEL_PLACEHOLDER }, StringSplitOptions.None).Length > 2)
            {
                throw new Exception("Invalid format for shareRoundingString");
            }
            else
            {
                bothSharesRoundingString = bothSharesRoundingString.Replace(ROUNDING_LEVEL_PLACEHOLDER, "{0}");
            }


            //Let's get the simple scenarios out of the way...
            //#1 - If all of the "known" items are of the same scale, then return that scale
            Dictionary <RoundingLevel, int> levels = new Dictionary <RoundingLevel, int>();

            //Store the normalized value

            RoundingLevel roundingMonetary = GetNormalizedRoundingLevel(this.MonetaryRoundingLevel);

            levels[roundingMonetary] = 1;                //monetary

            RoundingLevel roundingShares = GetNormalizedRoundingLevel(this.SharesRoundingLevel);

            levels[roundingShares] = 1;                //shares

            RoundingLevel roundingPerShare = GetNormalizedRoundingLevel(this.PerShareRoundingLevel);

            levels[roundingPerShare] = 1;                //per share

            levels.Remove(RoundingLevel.UnKnown);
            if (levels.Count == 0)
            {
                //All values were unknown
                this.RoundingOption = string.Empty;
                return;
            }

            //if we only have 1 distinct level, return that value in order of precedence
            if (levels.Count == 1)
            {
                RoundingLevel[] tmpLevel = new RoundingLevel[1];
                levels.Keys.CopyTo(tmpLevel, 0);

                RoundingLevel level = tmpLevel[0];
                if (level == RoundingLevel.NoRounding)
                {
                    //All values were whole numbers
                    this.RoundingOption = string.Empty;
                    return;
                }

                if (level == roundingMonetary)
                {
                    string stLevel = ReportBuilder.GetRoundingLevelString(roundingMonetary);
                    this.RoundingOption = string.Format(uniformRoundingString, stLevel);

                    if (this.HasCustomUnits)
                    {
                        this.RoundingOption += ", " + otherRoundingString;
                    }

                    return;
                }

                if (level == roundingShares)
                {
                    string stLevel = ReportBuilder.GetRoundingLevelString(roundingShares);
                    this.RoundingOption = string.Format(uniformRoundingString, stLevel);

                    if (this.HasCustomUnits)
                    {
                        this.RoundingOption += ", " + otherRoundingString;
                    }

                    return;
                }
            }

            int           roundingLevels   = 0;
            StringBuilder sbRoundingOption = new StringBuilder();

            WriteMonetary(ref roundingLevels, sbRoundingOption, roundingMonetary, uniformRoundingString);

            WriteShares(ref roundingLevels, sbRoundingOption,
                        roundingMonetary, roundingShares, roundingPerShare,
                        uniformRoundingString, sharesNoRoundingString, sharesRoundingString,
                        bothSharesNoRoundingString, bothSharesRoundingString);


            if (this.HasCustomUnits)
            {
                //The`otherRoundingString` should be the final string
                //Increasing the `roundingLevel` negates the possibility of entering the "per share" block
                //   it also negates the possibility of duplicates below

                if (roundingLevels == 2)
                {
                    roundingLevels = 3;
                    sbRoundingOption.Append(", " + otherRoundingString);
                }
                else if (roundingLevels == 1)
                {
                    if (roundingPerShare == RoundingLevel.UnKnown ||
                        roundingPerShare == roundingShares)
                    {
                        roundingLevels = 3;
                        sbRoundingOption.Append(", " + otherRoundingString);
                    }
                }
            }

            if (roundingLevels < 3)
            {
                WritePerShare(ref roundingLevels, sbRoundingOption, roundingMonetary, roundingShares, roundingPerShare,
                              perShareNoRoundingString, perShareRoundingString, otherRoundingString);
            }

            if (this.HasCustomUnits)
            {
                if (roundingLevels == 2)
                {
                    sbRoundingOption.Append(", " + otherRoundingString);
                }
            }

            this.RoundingOption = sbRoundingOption.ToString();
        }