Example #1
0
        public void ParseLines(string[] Lines)
        {
            int textcounter = 0;

            char[] chars;
            string name, len, type, dec, inout, x, y, keywords, Line = "";

            //https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/rzakc/rzakcmstpsnent.htm
            try
            {
                foreach (string TrueLine in Lines)
                {
                    Line     = TrueLine.PadRight(80);
                    chars    = Line.ToCharArray();
                    name     = buildString(chars, 18, 10).Trim();
                    len      = buildString(chars, 29, 5).Trim();
                    type     = chars[34].ToString().ToUpper();
                    dec      = buildString(chars, 35, 2).Trim();
                    inout    = chars[37].ToString().ToUpper();
                    y        = buildString(chars, 38, 3).Trim();
                    x        = buildString(chars, 41, 3).Trim();
                    keywords = Line.Substring(44).Trim();

                    switch (chars[16])
                    {
                    case 'R':
                        if (CurrentField != null)
                        {
                            CurrentFields.Add(CurrentField);
                        }
                        if (CurrentFields != null)
                        {
                            CurrentRecord.Fields = CurrentFields.ToArray();
                        }
                        if (CurrentRecord != null)
                        {
                            Formats.Add(CurrentRecord.Name, CurrentRecord);
                        }

                        CurrentRecord = new RecordInfo(name);
                        CurrentFields = new List <FieldInfo>();
                        CurrentField  = null;
                        HandleKeywords(keywords);
                        break;

                    case ' ':
                        if ((x != "" && y != "") || inout == "H")
                        {
                            if (CurrentField != null)
                            {
                                CurrentFields.Add(CurrentField);
                            }

                            if (inout == "H")
                            {
                                x = "0"; y = "0";
                            }

                            CurrentField          = new FieldInfo();
                            CurrentField.Position = new Point(Convert.ToInt32(x), Convert.ToInt32(y));
                        }
                        if (name != "")
                        {
                            CurrentField.Name   = name;
                            CurrentField.Value  = "";
                            CurrentField.Length = Convert.ToInt32(len);
                            switch (inout)
                            {
                            case "I":
                                CurrentField.fieldType = FieldInfo.FieldType.Input;
                                break;

                            case "B":
                                CurrentField.fieldType = FieldInfo.FieldType.Both;
                                break;

                            case "H":
                                CurrentField.fieldType = FieldInfo.FieldType.Hidden;
                                break;

                            case " ":
                            case "O":
                                CurrentField.fieldType = FieldInfo.FieldType.Output;
                                break;
                            }

                            CurrentField.Decimals = 0;
                            switch (type.ToUpper())
                            {
                            case "D":
                                CurrentField.dataType = FieldInfo.DataType.Decimal;
                                if (dec != "")
                                {
                                    CurrentField.Decimals = Convert.ToInt32(dec);
                                }
                                break;

                            default:
                                CurrentField.dataType = FieldInfo.DataType.Char;
                                break;
                            }
                            HandleKeywords(keywords);
                        }
                        else
                        {
                            HandleKeywords(keywords);
                            if (CurrentField != null)
                            {
                                if (CurrentField.Name == null)
                                {
                                    textcounter++;
                                    CurrentField.Name = "TEXT" + textcounter.ToString();
                                    if (CurrentField.Value == null)
                                    {
                                        CurrentField.Value = "";
                                    }
                                    CurrentField.Length    = CurrentField.Value.Length;
                                    CurrentField.fieldType = FieldInfo.FieldType.Const;
                                }
                            }
                        }
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Line error " + Line);
            }

            if (CurrentField != null)
            {
                CurrentFields.Add(CurrentField);
            }
            if (CurrentFields != null)
            {
                CurrentRecord.Fields = CurrentFields.ToArray();
            }
            if (CurrentRecord != null)
            {
                Formats.Add(CurrentRecord.Name, CurrentRecord);
            }
        }
Example #2
0
        private void ParseLines(string[] Lines)
        {
            int textcounter = 0;

            char[] chars;
            string conditionals, name, len, type, dec, inout, x, y, keywords, Line = "";

            //https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/rzakc/rzakcmstpsnent.htm
            // try
            // {
            foreach (string TrueLine in Lines)
            {
                Line         = TrueLine.PadRight(80);
                chars        = Line.ToCharArray();
                conditionals = buildString(chars, 6, 10).ToUpper();
                name         = buildString(chars, 18, 10).Trim();
                len          = buildString(chars, 29, 5).Trim();
                type         = chars[34].ToString().ToUpper();
                dec          = buildString(chars, 35, 2).Trim();
                inout        = chars[37].ToString().ToUpper();
                y            = buildString(chars, 38, 3).Trim();
                x            = buildString(chars, 41, 3).Trim();
                keywords     = Line.Substring(44).Trim();

                if (chars[6] == '*')
                {
                    continue;
                }

                switch (chars[16])
                {
                case 'R':
                    if (CurrentField != null)
                    {
                        CurrentFields.Add(CurrentField);
                    }
                    if (CurrentFields != null)
                    {
                        CurrentRecord.Fields = CurrentFields.ToArray();
                    }
                    if (CurrentRecord != null)
                    {
                        Formats.Add(CurrentRecord.Name, CurrentRecord);
                    }

                    CurrentRecord          = new RecordInfo(name);
                    CurrentRecord.Keywords = new Dictionary <string, string>();
                    CurrentFields          = new List <FieldInfo>();
                    CurrentField           = null;
                    HandleKeywords(keywords);
                    break;

                case ' ':
                    if ((x != "" && y != "") || inout == "H")
                    {
                        if (CurrentField != null)
                        {
                            CurrentFields.Add(CurrentField);
                        }

                        if (inout == "H")
                        {
                            x = "0"; y = "0";
                        }

                        CurrentField          = new FieldInfo();
                        CurrentField.Position = new System.Drawing.Point(Convert.ToInt32(x), Convert.ToInt32(y));
                    }
                    if (name != "")
                    {
                        CurrentField.Name     = name;
                        CurrentField.Value    = "";
                        CurrentField.Keywords = new Dictionary <string, string>();
                        switch (inout)
                        {
                        case "I":
                            CurrentField.fieldType = FieldInfo.FieldType.Input;
                            break;

                        case "B":
                            CurrentField.fieldType = FieldInfo.FieldType.Both;
                            break;

                        case "H":
                            CurrentField.fieldType = FieldInfo.FieldType.Hidden;
                            break;

                        case " ":
                        case "O":
                            CurrentField.fieldType = FieldInfo.FieldType.Output;
                            break;
                        }

                        CurrentField.dataType         = new DataSet(CurrentField.Name);
                        CurrentField.dataType._Length = Convert.ToInt32(len);
                        if (dec != "")
                        {
                            CurrentField.dataType._Precision = Convert.ToInt32(dec);
                        }
                        switch (type.ToUpper())
                        {
                        case "":
                            //TODO use length and dec to determine type
                            // if decimals is blank, then is a character field
                            if (dec == "")
                            {
                                CurrentField.dataType._Type = Types.Character;
                            }
                            break;

                        case "D":
                        case "S":
                            CurrentField.dataType._Type = Types.FixedDecimal;
                            break;

                        default:
                            CurrentField.dataType._Type = Types.Character;
                            break;
                        }
                        HandleConditionals(conditionals);
                        HandleKeywords(keywords);
                    }
                    else
                    {
                        HandleKeywords(keywords);
                        if (CurrentField != null)
                        {
                            HandleConditionals(conditionals);
                            if (CurrentField.Name == null)
                            {
                                textcounter++;
                                CurrentField.Name     = "TEXT" + textcounter.ToString();
                                CurrentField.dataType = new DataSet(CurrentField.Name);
                                if (CurrentField.Value == null)
                                {
                                    CurrentField.Value = "";
                                }
                                CurrentField.dataType._Length = CurrentField.Value.Length;
                                CurrentField.fieldType        = FieldInfo.FieldType.Const;
                            }
                        }
                    }
                    break;
                }
            }
            // }
            // catch (Exception e)
            // {
            //     Error.ThrowCompileError("Unable to read parse display file.");
            // }

            if (CurrentField != null)
            {
                CurrentFields.Add(CurrentField);
            }
            if (CurrentFields != null)
            {
                CurrentRecord.Fields = CurrentFields.ToArray();
            }
            if (CurrentRecord != null)
            {
                Formats.Add(CurrentRecord.Name, CurrentRecord);
            }
        }