예제 #1
0
        public string GenerateState()
        {
            switch (ThreeGen.Value())
            {
            case 1:
                return("* ");

            case 2:
                return("! ");

            case 3:
            default:
                return(String.Empty);
            }
        }
예제 #2
0
        public string GenerateXact()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Times.TimesCommon.Current.FormatDate(NextDate, FormatTypeEnum.FMT_WRITTEN));
            NextDate = NextDate.AddDays(SixGen.Value());
            if (TruthGen.Value())
            {
                sb.Append('=');
                sb.Append(Times.TimesCommon.Current.FormatDate(NextAuxDate, FormatTypeEnum.FMT_WRITTEN));
                NextAuxDate = NextAuxDate.AddDays(SixGen.Value());
            }
            sb.Append(' ');

            sb.Append(GenerateState());
            sb.Append(GenerateCode());
            sb.Append(GeneratePayee());
            if (TruthGen.Value())
            {
                sb.Append(GenerateNote());
            }
            sb.AppendLine();

            int  count          = ThreeGen.Value() * 2;
            bool hasMustBalance = false;

            for (int i = 0; i < count; i++)
            {
                if (GeneratePost(sb))
                {
                    hasMustBalance = true;
                }
            }
            if (hasMustBalance)
            {
                GeneratePost(sb, true);
            }

            sb.AppendLine();

            return(sb.ToString());
        }
예제 #3
0
        public bool GenerateAccount(StringBuilder sb, bool noVirtual = false)
        {
            bool mustBalance = true;
            bool isVirtual   = false;

            if (!noVirtual)
            {
                switch (ThreeGen.Value())
                {
                case 1:
                    sb.Append('[');
                    isVirtual = true;
                    break;

                case 2:
                    sb.Append('(');
                    mustBalance = false;
                    isVirtual   = true;
                    break;

                case 3:
                    break;
                }
            }

            sb.Append(GenerateString(StrLenGen.Value()));

            if (isVirtual)
            {
                if (mustBalance)
                {
                    sb.Append(']');
                }
                else
                {
                    sb.Append(')');
                }
            }

            return(mustBalance);
        }
예제 #4
0
        public string GenerateAmount(StringBuilder sbOut, Value notThisAmount = null, bool noNegative = false, string exclude = null)
        {
            StringBuilder sb = new StringBuilder();

            if (TruthGen.Value())
            {            // commodity goes in front
                sb.Append(GenerateCommodity(exclude));
                if (TruthGen.Value())
                {
                    sb.Append(' ');
                }
                if (noNegative || TruthGen.Value())
                {
                    sb.Append(PosNumberGen.Value().ToString("G15"));
                }
                else
                {
                    sb.Append(NegNumberGen.Value().ToString("G15"));
                }
            }
            else
            {
                if (noNegative || TruthGen.Value())
                {
                    sb.Append(PosNumberGen.Value().ToString("G15"));
                }
                else
                {
                    sb.Append(NegNumberGen.Value().ToString("G15"));
                }
                if (TruthGen.Value())
                {
                    sb.Append(' ');
                }
                sb.Append(GenerateCommodity(exclude));
            }

            // Possibly generate an annotized commodity, but make it rarer
            if (!noNegative && ThreeGen.Value() == 1)
            {
                if (ThreeGen.Value() == 1)
                {
                    sb.Append(" {");
                    GenerateAmount(sb, Value.Empty, true);
                    sb.Append('}');
                }
                if (SixGen.Value() == 1)
                {
                    sb.Append(" [");
                    sb.Append(GenerateDate());
                    sb.Append(']');
                }
                if (SixGen.Value() == 1)
                {
                    sb.Append(" (");
                    sb.Append(GenerateString(SixGen.Value()));
                    sb.Append(')');
                }
            }

            if (!Value.IsNullOrEmpty(notThisAmount) && Value.Get(sb.ToString()).AsAmount.Commodity == notThisAmount.AsAmount.Commodity)
            {
                return(String.Empty);
            }

            sbOut.Append(sb.ToString());

            return(sb.ToString());
        }
예제 #5
0
        /// <summary>
        /// Ported from void generate_posts_iterator::generate_string
        /// </summary>
        public string GenerateString(int len, bool onlyAlpha = false)
        {
            Logger.Current.Debug("generate.post.string", () => String.Format("Generating string of length {0}, only alpha {1}", len, onlyAlpha));

            StringBuilder sb = new StringBuilder();

            int  last  = -1;
            bool first = true;

            for (int i = 0; i < len; i++)
            {
                int  next   = onlyAlpha ? 3 : ThreeGen.Value();
                bool output = true;
                switch (next)
                {
                case 1:                         // colon
                    if (!first && last == 3 && StrLenGen.Value() % 10 == 0 && i + 1 != len)
                    {
                        sb.Append(':');
                    }
                    else
                    {
                        i--;
                        output = false;
                    }
                    break;

                case 2:                         // space
                    if (!first && last == 3 && StrLenGen.Value() % 20 == 0 && i + 1 != len)
                    {
                        sb.Append(' ');
                    }
                    else
                    {
                        i--;
                        output = false;
                    }
                    break;

                case 3:                         // character
                    switch (ThreeGen.Value())
                    {
                    case 1:                     // uppercase
                        sb.Append(UpcharGen.Value());
                        break;

                    case 2:                     // lowercase
                        sb.Append(DowncharGen.Value());
                        break;

                    case 3:                     // number
                        if (!onlyAlpha && !first)
                        {
                            sb.Append(NumcharGen.Value());
                        }
                        else
                        {
                            i--;
                            output = false;
                        }
                        break;
                    }
                    break;
                }
                if (output)
                {
                    last  = next;
                    first = false;
                }
            }

            return(sb.ToString());
        }