private void AddTransactionMembers(CodeTypeDeclaration dataComponentClass) { Type transactionType = this.designTable.PropertyCache.TransactionType; if (transactionType != null) { CodeTypeReference type = CodeGenHelper.GlobalType(transactionType); dataComponentClass.Members.Add(CodeGenHelper.FieldDecl(type, DataComponentNameHandler.TransactionVariableName)); CodeMemberProperty property = CodeGenHelper.PropertyDecl(type, DataComponentNameHandler.TransactionPropertyName, MemberAttributes.Assembly | MemberAttributes.Final); property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.TransactionVariableName))); property.SetStatements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.TransactionVariableName), CodeGenHelper.Argument("value"))); CodeStatement initStmt = CodeGenHelper.VariableDecl(CodeGenHelper.Type(typeof(int)), "i", CodeGenHelper.Primitive(0)); CodeExpression testExpression = CodeGenHelper.Less(CodeGenHelper.Variable("i"), CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionPropertyName), "Length")); CodeStatement incrementStmt = CodeGenHelper.Assign(CodeGenHelper.Variable("i"), CodeGenHelper.BinOperator(CodeGenHelper.Variable("i"), CodeBinaryOperatorType.Add, CodeGenHelper.Primitive(1))); CodeExpression transaction = CodeGenHelper.Property(CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionPropertyName), CodeGenHelper.Variable("i")), "Transaction"); CodeExpression oldTransaction = CodeGenHelper.Variable("oldTransaction"); CodeExpression newTransaction = CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.TransactionVariableName); CodeStatement statement3 = this.GenerateSetTransactionStmt(transaction, oldTransaction, newTransaction); property.SetStatements.Add(CodeGenHelper.ForLoop(initStmt, testExpression, incrementStmt, new CodeStatement[] { statement3 })); CodeExpression exp = CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName); CodeExpression expression6 = CodeGenHelper.Property(exp, "DeleteCommand"); transaction = CodeGenHelper.Property(expression6, "Transaction"); property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.And(CodeGenHelper.IdNotEQ(exp, CodeGenHelper.Primitive(null)), CodeGenHelper.IdNotEQ(expression6, CodeGenHelper.Primitive(null))), this.GenerateSetTransactionStmt(transaction, oldTransaction, newTransaction))); expression6 = CodeGenHelper.Property(exp, "InsertCommand"); transaction = CodeGenHelper.Property(expression6, "Transaction"); property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.And(CodeGenHelper.IdNotEQ(exp, CodeGenHelper.Primitive(null)), CodeGenHelper.IdNotEQ(expression6, CodeGenHelper.Primitive(null))), this.GenerateSetTransactionStmt(transaction, oldTransaction, newTransaction))); expression6 = CodeGenHelper.Property(exp, "UpdateCommand"); transaction = CodeGenHelper.Property(expression6, "Transaction"); property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.And(CodeGenHelper.IdNotEQ(exp, CodeGenHelper.Primitive(null)), CodeGenHelper.IdNotEQ(expression6, CodeGenHelper.Primitive(null))), this.GenerateSetTransactionStmt(transaction, oldTransaction, newTransaction))); dataComponentClass.Members.Add(property); } }
private bool AddExecuteCommandStatementsForPaging(IList statements) { if (base.containerParamType == typeof(DataTable)) { statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.Type(base.codeGenerator.DataSourceName), base.nameHandler.AddNameToList("dataSet"), CodeGenHelper.New(CodeGenHelper.Type(base.codeGenerator.DataSourceName), new CodeExpression[0]))); } CodeExpression[] parameters = new CodeExpression[4]; if (base.containerParamType == typeof(DataTable)) { parameters[0] = CodeGenHelper.Variable(base.nameHandler.GetNameFromList("dataSet")); } else { parameters[0] = CodeGenHelper.Argument(base.ContainerParameterName); } parameters[1] = CodeGenHelper.Argument(base.nameHandler.GetNameFromList(QueryGeneratorBase.startRecordParameterName)); parameters[2] = CodeGenHelper.Argument(base.nameHandler.GetNameFromList(QueryGeneratorBase.maxRecordsParameterName)); parameters[3] = CodeGenHelper.Str("Table"); if (!base.getMethod) { statements.Add(CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(int)), QueryGeneratorBase.returnVariableName, CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "Fill", parameters))); } else { statements.Add(CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "Fill", parameters))); } if ((base.containerParamType == typeof(DataTable)) && !base.getMethod) { CodeStatement initStmt = CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(int)), "i", CodeGenHelper.Primitive(0)); CodeExpression testExpression = CodeGenHelper.Less(CodeGenHelper.Variable("i"), CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Variable(base.nameHandler.GetNameFromList("dataSet")), base.DesignTable.GeneratorName), "Rows"), "Count")); CodeStatement incrementStmt = CodeGenHelper.Assign(CodeGenHelper.Variable("i"), CodeGenHelper.BinOperator(CodeGenHelper.Variable("i"), CodeBinaryOperatorType.Add, CodeGenHelper.Primitive(1))); CodeStatement statement3 = CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.Argument(base.ContainerParameterName), "ImportRow", new CodeExpression[] { CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Variable(base.nameHandler.GetNameFromList("dataSet")), base.DesignTable.GeneratorName), "Rows"), CodeGenHelper.Variable("i")) })); statements.Add(CodeGenHelper.ForLoop(initStmt, testExpression, incrementStmt, new CodeStatement[] { statement3 })); } return(true); }
private void AddConnectionMembers(CodeTypeDeclaration dataComponentClass) { Type type = this.providerFactory.CreateConnection().GetType(); MemberAttributes modifier = ((DesignConnection)this.designTable.Connection).Modifier; dataComponentClass.Members.Add(CodeGenHelper.FieldDecl(CodeGenHelper.GlobalType(type), DataComponentNameHandler.DefaultConnectionVariableName)); CodeMemberProperty property = CodeGenHelper.PropertyDecl(CodeGenHelper.GlobalType(type), DataComponentNameHandler.DefaultConnectionPropertyName, modifier | MemberAttributes.Final); property.GetStatements.Add(CodeGenHelper.If(CodeGenHelper.IdEQ(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.DefaultConnectionVariableName), CodeGenHelper.Primitive(null)), new CodeStatement[] { CodeGenHelper.Stm(CodeGenHelper.MethodCall(CodeGenHelper.This(), DataComponentNameHandler.InitConnection, new CodeExpression[0])) })); property.GetStatements.Add(CodeGenHelper.Return(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.DefaultConnectionVariableName))); property.SetStatements.Add(CodeGenHelper.Assign(CodeGenHelper.Field(CodeGenHelper.This(), DataComponentNameHandler.DefaultConnectionVariableName), CodeGenHelper.Argument("value"))); property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "InsertCommand"), CodeGenHelper.Primitive(null)), CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "InsertCommand"), "Connection"), CodeGenHelper.Argument("value")))); property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "DeleteCommand"), CodeGenHelper.Primitive(null)), CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "DeleteCommand"), "Connection"), CodeGenHelper.Argument("value")))); property.SetStatements.Add(CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "UpdateCommand"), CodeGenHelper.Primitive(null)), CodeGenHelper.Assign(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.AdapterPropertyName), "UpdateCommand"), "Connection"), CodeGenHelper.Argument("value")))); int count = this.designTable.Sources.Count; CodeStatement initStmt = CodeGenHelper.VariableDecl(CodeGenHelper.GlobalType(typeof(int)), "i", CodeGenHelper.Primitive(0)); CodeExpression testExpression = CodeGenHelper.Less(CodeGenHelper.Variable("i"), CodeGenHelper.Property(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionPropertyName), "Length")); CodeStatement incrementStmt = CodeGenHelper.Assign(CodeGenHelper.Variable("i"), CodeGenHelper.BinOperator(CodeGenHelper.Variable("i"), CodeBinaryOperatorType.Add, CodeGenHelper.Primitive(1))); CodeExpression left = CodeGenHelper.Property(CodeGenHelper.Cast(CodeGenHelper.GlobalType(this.providerFactory.CreateCommand().GetType()), CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionPropertyName), CodeGenHelper.Variable("i"))), "Connection"); CodeStatement statement3 = CodeGenHelper.If(CodeGenHelper.IdNotEQ(CodeGenHelper.Indexer(CodeGenHelper.Property(CodeGenHelper.This(), DataComponentNameHandler.SelectCmdCollectionPropertyName), CodeGenHelper.Variable("i")), CodeGenHelper.Primitive(null)), CodeGenHelper.Assign(left, CodeGenHelper.Argument("value"))); property.SetStatements.Add(CodeGenHelper.ForLoop(initStmt, testExpression, incrementStmt, new CodeStatement[] { statement3 })); dataComponentClass.Members.Add(property); }