Esempio n. 1
0
        private string ChildPropertyName(DataRelation relation, out bool usesAnnotations)
        {
            usesAnnotations = true;
            string str = (string)relation.ExtendedProperties["typedChildren"];

            if (!StringUtil.Empty(str))
            {
                return(str);
            }
            string str2 = (string)relation.ChildTable.ExtendedProperties["typedPlural"];

            if (StringUtil.Empty(str2))
            {
                str2 = (string)relation.ChildTable.ExtendedProperties["typedName"];
                if (StringUtil.Empty(str2))
                {
                    usesAnnotations = false;
                    str             = "Get" + relation.ChildTable.TableName + "Rows";
                    if (1 < TablesConnectedness(relation.ParentTable, relation.ChildTable))
                    {
                        str = str + "By" + relation.RelationName;
                    }
                    return(NameHandler.FixIdName(str));
                }
                str2 = str2 + "Rows";
            }
            return("Get" + str2);
        }
Esempio n. 2
0
        private string RowColumnPropertyName(DataColumn column, out bool usesAnnotations)
        {
            usesAnnotations = true;
            string str = (string)column.ExtendedProperties["typedName"];

            if (StringUtil.Empty(str))
            {
                usesAnnotations = false;
                str             = NameHandler.FixIdName(column.ColumnName);
            }
            return(str);
        }
Esempio n. 3
0
        private string RowClassName(DataTable table, out bool usesAnnotations)
        {
            usesAnnotations = true;
            string str = (string)table.ExtendedProperties["typedName"];

            if (StringUtil.Empty(str))
            {
                usesAnnotations = false;
                str             = NameHandler.FixIdName(table.TableName) + "Row";
            }
            return(str);
        }
Esempio n. 4
0
        private string TablePropertyName(DataTable table, out bool usesAnnotations)
        {
            usesAnnotations = true;
            string str = (string)table.ExtendedProperties["typedPlural"];

            if (!StringUtil.Empty(str))
            {
                return(str);
            }
            str = (string)table.ExtendedProperties["typedName"];
            if (StringUtil.Empty(str))
            {
                usesAnnotations = false;
                return(NameHandler.FixIdName(table.TableName));
            }
            return(str + "Table");
        }
Esempio n. 5
0
        private string ParentPropertyName(DataRelation relation, out bool usesAnnotations)
        {
            usesAnnotations = true;
            string str = null;

            str = (string)relation.ExtendedProperties["typedParent"];
            if (StringUtil.Empty(str))
            {
                str = this.RowClassName(relation.ParentTable, out usesAnnotations);
                if ((relation.ChildTable == relation.ParentTable) || (relation.ChildColumns.Length != 1))
                {
                    str = str + "Parent";
                }
                if (1 < TablesConnectedness(relation.ParentTable, relation.ChildTable))
                {
                    str = str + "By" + NameHandler.FixIdName(relation.RelationName);
                }
            }
            return(str);
        }
Esempio n. 6
0
 internal void ProcessDataSourceName(DesignDataSource dataSource)
 {
     if (StringUtil.Empty(dataSource.Name))
     {
         throw new DataSourceGeneratorException(System.Design.SR.GetString("CG_EmptyDSName"));
     }
     if (!StringUtil.EqualValue(dataSource.Name, dataSource.UserDataSetName, this.languageCaseInsensitive) || StringUtil.Empty(dataSource.GeneratorDataSetName))
     {
         dataSource.GeneratorDataSetName = NameHandler.FixIdName(dataSource.Name);
     }
     else
     {
         dataSource.GeneratorDataSetName = this.validator.GenerateIdName(dataSource.GeneratorDataSetName);
     }
     dataSource.UserDataSetName = dataSource.Name;
     if (!StringUtil.EqualValue(NameHandler.FixIdName(dataSource.Name), dataSource.GeneratorDataSetName))
     {
         dataSource.NamingPropertyNames.Add(DesignDataSource.EXTPROPNAME_USER_DATASETNAME);
         dataSource.NamingPropertyNames.Add(DesignDataSource.EXTPROPNAME_GENERATOR_DATASETNAME);
     }
 }
        private CodeMemberMethod RemoveRowMethod()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.GlobalType(typeof(void)), NameHandler.FixIdName("Remove" + this.rowClassName), MemberAttributes.Public | MemberAttributes.Final);

            method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.Type(this.rowConcreteClassName), "row"));
            method.Statements.Add(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), "Rows"), "Remove", CodeGenHelper.Argument("row")));
            return(method);
        }
        private CodeMemberMethod NewTypedRowMethod()
        {
            CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.Type(this.rowConcreteClassName), NameHandler.FixIdName("New" + this.rowClassName), MemberAttributes.Public | MemberAttributes.Final);

            method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.Cast(CodeGenHelper.Type(this.rowConcreteClassName), CodeGenHelper.MethodCall(CodeGenHelper.This(), "NewRow"))));
            return(method);
        }
        private void AddFindByMethods(CodeTypeDeclaration dataTableClass)
        {
            DataTable dataTable = this.designTable.DataTable;

            for (int i = 0; i < dataTable.Constraints.Count; i++)
            {
                if ((dataTable.Constraints[i] is UniqueConstraint) && ((UniqueConstraint)dataTable.Constraints[i]).IsPrimaryKey)
                {
                    DataColumn[] columns   = ((UniqueConstraint)dataTable.Constraints[i]).Columns;
                    string       inVarName = "FindBy";
                    bool         flag      = true;
                    for (int j = 0; j < columns.Length; j++)
                    {
                        inVarName = inVarName + this.codeGenerator.TableHandler.Tables[columns[j].Table.TableName].DesignColumns[columns[j].ColumnName].GeneratorColumnPropNameInRow;
                        if (columns[j].ColumnMapping != MappingType.Hidden)
                        {
                            flag = false;
                        }
                    }
                    if (!flag)
                    {
                        CodeMemberMethod method = CodeGenHelper.MethodDecl(CodeGenHelper.Type(this.rowClassName), NameHandler.FixIdName(inVarName), MemberAttributes.Public | MemberAttributes.Final);
                        for (int k = 0; k < columns.Length; k++)
                        {
                            method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.Type(columns[k].DataType), this.codeGenerator.TableHandler.Tables[columns[k].Table.TableName].DesignColumns[columns[k].ColumnName].GeneratorColumnPropNameInRow));
                        }
                        CodeArrayCreateExpression par = new CodeArrayCreateExpression(typeof(object), columns.Length);
                        for (int m = 0; m < columns.Length; m++)
                        {
                            par.Initializers.Add(CodeGenHelper.Argument(this.codeGenerator.TableHandler.Tables[columns[m].Table.TableName].DesignColumns[columns[m].ColumnName].GeneratorColumnPropNameInRow));
                        }
                        method.Statements.Add(CodeGenHelper.Return(CodeGenHelper.Cast(CodeGenHelper.Type(this.rowClassName), CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), "Rows"), "Find", par))));
                        dataTableClass.Members.Add(method);
                    }
                }
            }
        }
        private void AddTypedRowByColumnsMethods(CodeTypeDeclaration dataTableClass)
        {
            DataTable dataTable = this.designTable.DataTable;
            ArrayList list      = new ArrayList();
            bool      flag      = false;

            for (int i = 0; i < dataTable.Columns.Count; i++)
            {
                if (!dataTable.Columns[i].AutoIncrement)
                {
                    list.Add(dataTable.Columns[i]);
                }
            }
            string             name    = NameHandler.FixIdName("Add" + this.rowClassName);
            GenericNameHandler handler = new GenericNameHandler(new string[] { name, columnValuesArrayName }, this.codeGenerator.CodeProvider);
            CodeMemberMethod   method  = CodeGenHelper.MethodDecl(CodeGenHelper.Type(this.rowConcreteClassName), name, MemberAttributes.Public | MemberAttributes.Final);
            CodeMemberMethod   method2 = CodeGenHelper.MethodDecl(CodeGenHelper.Type(this.rowConcreteClassName), name, MemberAttributes.Public | MemberAttributes.Final);

            DataColumn[] array = new DataColumn[list.Count];
            list.CopyTo(array, 0);
            for (int j = 0; j < array.Length; j++)
            {
                Type         dataType = array[j].DataType;
                DataRelation relation = this.FindParentRelation(array[j]);
                if (this.ChildRelationFollowable(relation))
                {
                    string generatorRowClassName = this.codeGenerator.TableHandler.Tables[relation.ParentTable.TableName].GeneratorRowClassName;
                    string originalName          = NameHandler.FixIdName("parent" + generatorRowClassName + "By" + relation.RelationName);
                    method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.Type(generatorRowClassName), handler.AddNameToList(originalName)));
                    method2.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.Type(generatorRowClassName), handler.GetNameFromList(originalName)));
                }
                else
                {
                    method.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.Type(dataType), handler.AddNameToList(this.codeGenerator.TableHandler.Tables[array[j].Table.TableName].DesignColumns[array[j].ColumnName].GeneratorColumnPropNameInRow)));
                    if (StringUtil.Empty(array[j].Expression))
                    {
                        method2.Parameters.Add(CodeGenHelper.ParameterDecl(CodeGenHelper.Type(dataType), handler.GetNameFromList(this.codeGenerator.TableHandler.Tables[array[j].Table.TableName].DesignColumns[array[j].ColumnName].GeneratorColumnPropNameInRow)));
                    }
                    else
                    {
                        flag = true;
                    }
                }
            }
            CodeStatement statement = CodeGenHelper.VariableDecl(CodeGenHelper.Type(this.rowConcreteClassName), NameHandler.FixIdName("row" + this.rowClassName), CodeGenHelper.Cast(CodeGenHelper.Type(this.rowConcreteClassName), CodeGenHelper.MethodCall(CodeGenHelper.This(), "NewRow")));

            method.Statements.Add(statement);
            method2.Statements.Add(statement);
            CodeExpression      exp        = CodeGenHelper.Variable(NameHandler.FixIdName("row" + this.rowClassName));
            CodeAssignStatement statement2 = new CodeAssignStatement {
                Left = CodeGenHelper.Property(exp, "ItemArray")
            };
            CodeArrayCreateExpression initExpr = new CodeArrayCreateExpression {
                CreateType = CodeGenHelper.GlobalType(typeof(object))
            };
            CodeArrayCreateExpression expression3 = new CodeArrayCreateExpression {
                CreateType = CodeGenHelper.GlobalType(typeof(object))
            };

            array = new DataColumn[dataTable.Columns.Count];
            dataTable.Columns.CopyTo(array, 0);
            for (int k = 0; k < array.Length; k++)
            {
                if (array[k].AutoIncrement)
                {
                    initExpr.Initializers.Add(CodeGenHelper.Primitive(null));
                    expression3.Initializers.Add(CodeGenHelper.Primitive(null));
                }
                else
                {
                    DataRelation relation2 = this.FindParentRelation(array[k]);
                    if (this.ChildRelationFollowable(relation2))
                    {
                        initExpr.Initializers.Add(CodeGenHelper.Primitive(null));
                        expression3.Initializers.Add(CodeGenHelper.Primitive(null));
                    }
                    else
                    {
                        initExpr.Initializers.Add(CodeGenHelper.Argument(handler.GetNameFromList(this.codeGenerator.TableHandler.Tables[array[k].Table.TableName].DesignColumns[array[k].ColumnName].GeneratorColumnPropNameInRow)));
                        if (StringUtil.Empty(array[k].Expression))
                        {
                            expression3.Initializers.Add(CodeGenHelper.Argument(handler.GetNameFromList(this.codeGenerator.TableHandler.Tables[array[k].Table.TableName].DesignColumns[array[k].ColumnName].GeneratorColumnPropNameInRow)));
                        }
                        else
                        {
                            expression3.Initializers.Add(CodeGenHelper.Primitive(null));
                        }
                    }
                }
            }
            method.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(object), 1), columnValuesArrayName, initExpr));
            method2.Statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(object), 1), columnValuesArrayName, expression3));
            for (int m = 0; m < array.Length; m++)
            {
                if (!array[m].AutoIncrement)
                {
                    DataRelation relation3 = this.FindParentRelation(array[m]);
                    if (this.ChildRelationFollowable(relation3))
                    {
                        string        str5       = NameHandler.FixIdName("parent" + this.codeGenerator.TableHandler.Tables[relation3.ParentTable.TableName].GeneratorRowClassName + "By" + relation3.RelationName);
                        CodeStatement statement3 = CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Argument(handler.GetNameFromList(str5)), CodeGenHelper.Primitive(null)), CodeGenHelper.Assign(CodeGenHelper.Indexer(CodeGenHelper.Variable(columnValuesArrayName), CodeGenHelper.Primitive(m)), CodeGenHelper.Indexer(CodeGenHelper.Argument(handler.GetNameFromList(str5)), CodeGenHelper.Primitive(relation3.ParentColumns[0].Ordinal))));
                        method.Statements.Add(statement3);
                        method2.Statements.Add(statement3);
                    }
                }
            }
            statement2.Right = CodeGenHelper.Variable(columnValuesArrayName);
            method.Statements.Add(statement2);
            method2.Statements.Add(statement2);
            CodeExpression expression4 = CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), "Rows"), "Add", exp);

            method.Statements.Add(expression4);
            method2.Statements.Add(expression4);
            method.Statements.Add(CodeGenHelper.Return(exp));
            method2.Statements.Add(CodeGenHelper.Return(exp));
            dataTableClass.Members.Add(method);
            if (flag)
            {
                dataTableClass.Members.Add(method2);
            }
        }
Esempio n. 11
0
 private string RelationVariableName(DataRelation relation)
 {
     return(NameHandler.FixIdName("relation" + relation.RelationName));
 }