Exemple #1
0
        private string GetPrimaryKeyTableColumnRow(string input, Entities.MetaDataSchema.Table table)
        {
            StringBuilder result = new StringBuilder();
            int           index  = 0;

            foreach (Entities.MetaDataSchema.Column col in table.Columns)
            {
                if (col.IsPrimary)
                {
                    string tempValue = input;
                    string dataType  = GetDataType(col);
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.DataTypeCommand, GeneratorCommands.PrimaryKeyOption, "", dataType);
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.LibraryTypeCommand, GeneratorCommands.PrimaryKeyOption, "", col.ColumnDataType.LibraryType);
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.DataTypeLengthCommand, GeneratorCommands.PrimaryKeyOption, "", GetDataTypeLength(col));
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.NameCommand, GeneratorCommands.PrimaryKeyOption, "", col.Name);
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.NameCommand, GeneratorCommands.PrimaryKeyOption, GeneratorCommands.LowerCaseOption, col.Name.ToLower());
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.NameCommand, GeneratorCommands.PrimaryKeyOption, GeneratorCommands.UpperCaseOption, col.Name.ToUpper());
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.NameCommand, GeneratorCommands.PrimaryKeyOption, GeneratorCommands.FirstLowerOption, FirstLetterLower(col.Name));
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.NameCommand, GeneratorCommands.PrimaryKeyOption, GeneratorCommands.FirstUpperOption, FirstLetterUpper(col.Name));

                    tempValue = RemoveEnvelope(tempValue);
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.NewLineCommand, GeneratorCommands.NewLineValue);
                    result.Append(tempValue);
                    index++;
                }
            }
            return(result.ToString());
        }
Exemple #2
0
        private string GetForeignKeyTableColumnRow(string input, Entities.MetaDataSchema.Table table)
        {
            StringBuilder result = new StringBuilder();
            int           index  = 0;

            foreach (Entities.MetaDataSchema.Column col in table.Columns)
            {
                if (col.IsForeign)
                {
                    string tempValue = input;
                    string dataType  = GetDataType(col);
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.DataTypeCommand, GeneratorCommands.ForeignKeyOption, "", dataType);
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.LibraryTypeCommand, GeneratorCommands.ForeignKeyOption, "", col.ColumnDataType.LibraryType);
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.DataTypeLengthCommand, GeneratorCommands.ForeignKeyOption, "", GetDataTypeLength(col));
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.NameCommand, GeneratorCommands.ForeignKeyOption, "", col.Name);
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.NameCommand, GeneratorCommands.ForeignKeyOption, GeneratorCommands.LowerCaseOption, col.Name.ToLower());
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.NameCommand, GeneratorCommands.ForeignKeyOption, GeneratorCommands.UpperCaseOption, col.Name.ToUpper());
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.NameCommand, GeneratorCommands.ForeignKeyOption, GeneratorCommands.FirstLowerOption, FirstLetterLower(col.Name));
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnCommand, GeneratorCommands.NameCommand, GeneratorCommands.ForeignKeyOption, GeneratorCommands.FirstUpperOption, FirstLetterUpper(col.Name));

                    var fkParent = (from x in col.ParentTable.ParentRelationShips where x.ChildColumn.Name == col.Name && x.ChildTable.Name == col.ParentTable.Name select x).FirstOrDefault();
                    if (fkParent != null)
                    {
                        tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.ParentTableColumnCommand, GeneratorCommands.NameCommand, "", GeneratorCommands.FirstUpperOption, FirstLetterUpper(fkParent.MasterTable.Name));
                        tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.ParentTableColumnCommand, GeneratorCommands.NameCommand, "", GeneratorCommands.FirstLowerOption, FirstLetterLower(fkParent.MasterTable.Name));
                    }

                    tempValue = RemoveEnvelope(tempValue);
                    tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.NewLineCommand, GeneratorCommands.NewLineValue);
                    result.Append(tempValue);
                    index++;
                }
            }
            return(result.ToString());
        }
Exemple #3
0
        private string GetNormalParameters(string input, Entities.MetaDataSchema.Table table)
        {
            StringBuilder result = new StringBuilder();
            int           index  = 0;

            foreach (Entities.MetaDataSchema.Column col in table.Columns)
            {
                string tempValue = input;

                string dataType = GetDataType(col);

                tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnParamCommand, GeneratorCommands.DataTypeCommand, "", "", dataType);
                tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnParamCommand, GeneratorCommands.NameCommand, "", "", col.Name);
                tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnParamCommand, GeneratorCommands.NameCommand, "", GeneratorCommands.LowerCaseOption, col.Name.ToLower());
                tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnParamCommand, GeneratorCommands.NameCommand, "", GeneratorCommands.UpperCaseOption, col.Name.ToUpper());
                tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnParamCommand, GeneratorCommands.NameCommand, "", GeneratorCommands.FirstLowerOption, FirstLetterLower(col.Name));
                tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnParamCommand, GeneratorCommands.NameCommand, "", GeneratorCommands.FirstUpperOption, FirstLetterUpper(col.Name));

                tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnParamCommand, GeneratorCommands.LibraryTypeCommand, "", "", col.ColumnDataType.LibraryType);
                tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.TableColumnParamCommand, GeneratorCommands.DataTypeLengthCommand, "", "", GetDataTypeLength(col));


                if (index < (table.Columns.Count - 1))
                {
                    tempValue += parameterSeperator;
                }
                tempValue = GeneratorCommands.ReplaceCommand(tempValue, GeneratorCommands.NewLineCommand, GeneratorCommands.NewLineValue);
                tempValue = RemoveEnvelope(tempValue);
                result.Append(tempValue);
                index++;
            }
            return(result.ToString());
        }
Exemple #4
0
        public string GetCode(string input, string namespaceName, string className, string authorName, Entities.MetaDataSchema.Table table)
        {
            StringBuilder result = new StringBuilder(input);

            result = GeneratorCommands.ReplaceCommandBuilder(result, GeneratorCommands.NameSpaceCommand, namespaceName);
            result = GeneratorCommands.ReplaceCommandBuilder(result, GeneratorCommands.ClassNameCommand, className);
            result = GeneratorCommands.ReplaceCommandBuilder(result, GeneratorCommands.TableNameCommand, table.Name);
            result = GeneratorCommands.ReplaceCommandBuilder(result, GeneratorCommands.AuthorNameCommand, authorName);
            result = GeneratorCommands.ReplaceCommandBuilder(result, GeneratorCommands.CurrentDateCommand, DateTime.Now.ToShortDateString());
            result = new StringBuilder(GetCodeConditioned(result.ToString(), namespaceName, className, authorName, table));
            Regex  reg = new Regex(@"(\[\$\$.*?\$\$\])", RegexOptions.Singleline);
            Match  match; //= reg.Match(input);
            string value = "";

            for (match = reg.Match(input); match.Success; match = match.NextMatch())
            {
                value = match.Groups[0].Value;
                #region Parameters

                Regex regInternal   = new Regex(String.Format(@"<%\$\$\s*{0}\s*{1}", GeneratorCommands.TableColumnParamCommand, GeneratorCommands.PrimaryKeyOption), RegexOptions.IgnoreCase);
                Match matchInternal = regInternal.Match(value);
                bool  isNormal      = true;
                if (matchInternal.Success)
                {
                    string currentValue = GetPrimaryKeyParameters(value, table);
                    result   = result.Replace(value, currentValue);
                    isNormal = false;
                    continue;
                }
                regInternal   = new Regex(String.Format(@"<%\$\$\s*{0}\s*{1}", GeneratorCommands.TableColumnParamCommand, GeneratorCommands.ForeignKeyOption), RegexOptions.IgnoreCase);
                matchInternal = regInternal.Match(value);
                if (matchInternal.Success)
                {
                    string currentValue = GetForeignKeyParameters(value, table);
                    result   = result.Replace(value, currentValue);
                    isNormal = false;
                    continue;
                }
                if (isNormal)
                {
                    regInternal   = new Regex(@"<%\$\$\s*" + GeneratorCommands.TableColumnParamCommand, RegexOptions.IgnoreCase);
                    matchInternal = regInternal.Match(value);
                    if (matchInternal.Success)
                    {
                        string currentValue = GetNormalParameters(value, table);
                        result = result.Replace(value, currentValue);
                        continue;
                    }
                }
                #endregion

                #region Normal Columns
                regInternal   = new Regex(String.Format(@"<%\$\$\s*{0}\s*{1}", GeneratorCommands.TableColumnCommand, GeneratorCommands.PrimaryKeyOption), RegexOptions.IgnoreCase);
                matchInternal = regInternal.Match(value);
                isNormal      = true;
                if (matchInternal.Success)
                {
                    string currentValue = GetPrimaryKeyTableColumnRow(value, table);
                    result   = result.Replace(value, currentValue);
                    isNormal = false;
                    continue;
                }

                regInternal   = new Regex(String.Format(@"<%\$\$\s*{0}\s*{1}", GeneratorCommands.TableColumnCommand, GeneratorCommands.ForeignKeyOption), RegexOptions.IgnoreCase);
                matchInternal = regInternal.Match(value);
                if (matchInternal.Success)
                {
                    string currentValue = GetForeignKeyTableColumnRow(value, table);
                    result   = result.Replace(value, currentValue);
                    isNormal = false;
                    continue;
                }

                if (isNormal)
                {
                    regInternal   = new Regex(@"<%\$\$\s*" + GeneratorCommands.TableColumnCommand, RegexOptions.IgnoreCase);
                    matchInternal = regInternal.Match(value);
                    if (matchInternal.Success)
                    {
                        string currentValue = GetNormalTableColumnRow(value, table);
                        result = result.Replace(value, currentValue);
                        continue;
                    }
                }

                regInternal   = new Regex(String.Format(@"<%\$\$\s*{0}\s*{1}", GeneratorCommands.ParentTableColumnCommand, GeneratorCommands.ForeignKeyOption), RegexOptions.IgnoreCase);
                matchInternal = regInternal.Match(value);
                if (matchInternal.Success)
                {
                    string currentValue = GetForeignKeyTableColumnRow(value, table);
                    result   = result.Replace(value, currentValue);
                    isNormal = false;
                    continue;
                }
                #endregion
            }
            return(result.ToString());
        }