/// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public CodeMemberMethod BuildSelectBE(TableViewTableTypeBase table)
        {
            CodeMemberMethod cmSelect = new CodeMemberMethod();

            cmSelect.Attributes = MemberAttributes.Public;
            cmSelect.ReturnType = new CodeTypeReference("System.Data.DataSet");
            String cp_name          = "ssp_" + table.Name;
            String PocoTypeName     = table.Name;
            String FullPocoTypeName = PocoTypeName;

            CodeParameterDeclarationExpression cpdePoco = new CodeParameterDeclarationExpression();

            cpdePoco.Name      = "query";
            cpdePoco.Type      = new CodeTypeReference(table.Name);
            cpdePoco.Direction = FieldDirection.In;
            cmSelect.Parameters.Add(cpdePoco);
            cmSelect.Attributes = MemberAttributes.Public;
            cmSelect.Name       = "Select";
            cmSelect.Statements.Add(new CodeSnippetExpression("this.Access.CreateProcedureCommand(\"" + cp_name + "\")"));

            foreach (Column c in table.Columns)
            {
                MemberGraph mGraph         = new MemberGraph(c);
                String      DotNetTypeName = TypeConvertor.ToNetType(c.DataType.SqlDataType).ToString();

                System.CodeDom.CodeConditionStatement ccsField = new CodeConditionStatement();
                if (mGraph.IsNullable)
                {
                    ccsField.Condition = new CodeSnippetExpression("query." + mGraph.PropertyName() + ".HasValue");
                    ccsField.TrueStatements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\",query." + mGraph.PropertyName() + ".Value, ParameterDirection.Input)"));
                    ccsField.FalseStatements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\", null , ParameterDirection.Input)"));
                }
                else
                {
                    ccsField.Condition = new CodeSnippetExpression("query." + mGraph.PropertyName() + " == null");
                    ccsField.TrueStatements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\", null , ParameterDirection.Input)"));
                    ccsField.FalseStatements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\",query." + mGraph.PropertyName() + ", ParameterDirection.Input)"));
                }

                cmSelect.Statements.Add(ccsField);
            }

            cmSelect.Statements.Add(new CodeSnippetExpression("return this.Access.ExecuteDataSet()"));
            cmSelect.Comments.Add(new CodeCommentStatement("Select by Object [Implements Query By Example], returns DataSet"));
            return(cmSelect);
        }
        private CodeMemberMethod BuildPocoDelete(TableViewTableTypeBase table)
        {
            CodeMemberMethod cmDelete = new CodeMemberMethod();

            cmDelete.Attributes = MemberAttributes.Public;
            cmDelete.Name       = "Delete";
            String cp_name = "cp_" + table.Name;

            cmDelete.Parameters.Add(this.PocoQueryParameter(table.Name));
            cmDelete.ReturnType = new CodeTypeReference("System.Int32");
            cmDelete.Statements.Add(new CodeSnippetExpression("this.Access.CreateProcedureCommand(\"ProcedureName\")".Replace("ProcedureName", cp_name)));
            cmDelete.Statements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"Operation\", 6, ParameterDirection.Input)"));


            foreach (Column c in table.Columns)
            {
                if (c.InPrimaryKey)
                {
                    MemberGraph mGraph = new MemberGraph(c);
                    if (mGraph.IsNullable)
                    {
                        cmDelete.Statements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\", query." + mGraph.PropertyName() + ".Value, ParameterDirection.Input)"));
                    }
                    else
                    {
                        cmDelete.Statements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\", query." + mGraph.PropertyName() + ", ParameterDirection.Input)"));
                    }
                }
            }

            cmDelete.Statements.Add(new CodeSnippetExpression("var value = this.Access.ExecuteNonQuery()"));
            cmDelete.Statements.Add(new CodeSnippetExpression("return value"));
            cmDelete.Comments.Add(new CodeCommentStatement("Delete's a record"));

            return(cmDelete);
        }
        /// <summary>
        /// Insert Query Method
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private CodeMemberMethod BuildInsert(TableViewTableTypeBase table)
        {
            CodeMemberMethod cmInsert = new CodeMemberMethod();

            cmInsert.Name = "Insert";
            String cp_name = "cp_" + table.Name;

            cmInsert.Attributes = MemberAttributes.Public;
            cmInsert.ReturnType = new CodeTypeReference("System.Int32");

            foreach (Column c in table.Columns)
            {
                MemberGraph mGraph = new MemberGraph(c);
                if (mGraph.IsReadOnly)
                {
                    // nothing yet
                }
                else
                {
                    cmInsert.Parameters.Add(mGraph.GetParameter());
                }
            }

            cmInsert.Statements.Add(new CodeSnippetExpression("this.Access.CreateProcedureCommand(\"ProcedureName\")".Replace("ProcedureName", cp_name)));
            cmInsert.Statements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"Operation\", 5, ParameterDirection.Input)"));

            foreach (Column c in table.Columns)
            {
                MemberGraph mGraph = new MemberGraph(c);
                if (mGraph.IsReadOnly)
                {
                    // nothing yet
                }
                else
                {
                    cmInsert.Statements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\", " + mGraph.ParameterName() + " , ParameterDirection.Input)"));
                }
            }

            cmInsert.Statements.Add(new CodeSnippetExpression("return this.Access.ExecuteNonQuery()"));
            cmInsert.Comments.Add(new CodeCommentStatement("Inserts a record"));
            return(cmInsert);
        }
        private CodeMemberMethod BuildFillMethod(TableViewTableTypeBase table)
        {
            // Accepts a DataRow and Returns a Poco of this type.
            CodeMemberMethod cmmFill = new CodeMemberMethod();

            cmmFill.Name       = "Fill";
            cmmFill.Attributes = MemberAttributes.Private;
            cmmFill.ReturnType = new CodeTypeReference(table.Name);
            CodeParameterDeclarationExpression cpdeDataRow = new CodeParameterDeclarationExpression();

            cpdeDataRow.Name      = "row";
            cpdeDataRow.Type      = new CodeTypeReference("System.Data.DataRow");
            cpdeDataRow.Direction = FieldDirection.In;

            cmmFill.Parameters.Add(cpdeDataRow);
            var init_Express = new CodeSnippetExpression("new " + table.Name + "()");

            var obj = new CodeVariableDeclarationStatement(new CodeTypeReference(table.Name), "obj", init_Express);

            cmmFill.Statements.Add(obj);

            foreach (Column c in table.Columns)
            {
                String      DotNetTypeName = TypeConvertor.ToNetType(c.DataType.SqlDataType).ToString();
                MemberGraph mGraph         = new MemberGraph(c);
                System.CodeDom.CodeConditionStatement ccsField = new CodeConditionStatement();
                ccsField.Condition = new CodeSnippetExpression("(row[\"" + c.Name + "\"] != System.DBNull.Value)");
                //if (!(mGraph.IsReadOnly))
                //{
                // If Field is nullable Type
                if (mGraph.IsNullable)
                {
                    if (mGraph.TypeName() == "String")
                    {
                        ccsField.TrueStatements.Add(new CodeSnippetExpression("obj." + mGraph.PropertyName() + " = row[\"" + c.Name + "\"].ToString()"));
                    }
                    else
                    {
                        ccsField.TrueStatements.Add(new CodeSnippetExpression("obj." + mGraph.PropertyName() + " = ((" + mGraph.TypeName() + ")(row[\"" + c.Name + "\"]))"));
                    }
                }
                else
                {
                    if (mGraph.TypeName() == "String")
                    {
                        ccsField.TrueStatements.Add(new CodeSnippetExpression("obj." + mGraph.PropertyName() + " = row[\"" + c.Name + "\"].ToString()"));
                    }
                    else
                    {
                        ccsField.TrueStatements.Add(new CodeSnippetExpression("obj." + mGraph.PropertyName() + " = ((" + mGraph.TypeName() + ")(row[\"" + c.Name + "\"]))"));
                    }
                }
                cmmFill.Statements.Add(ccsField);
                //}
            }

            cmmFill.Statements.Add(new CodeSnippetExpression("return obj"));
            cmmFill.Comments.Add(new CodeCommentStatement("Returns a Hydrated POCO"));
            return(cmmFill);
        }
Example #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public CodeMemberMethod BuildSelectBE(TableViewTableTypeBase table)
        {
            CodeMemberMethod cmSelect = new CodeMemberMethod();
            cmSelect.Attributes = MemberAttributes.Public;
            cmSelect.ReturnType = new CodeTypeReference("System.Data.DataSet");
            String cp_name = "ssp_" + table.Name;
            String PocoTypeName = table.Name;
            String FullPocoTypeName = PocoTypeName;

            CodeParameterDeclarationExpression cpdePoco = new CodeParameterDeclarationExpression();
            cpdePoco.Name = "query";
            cpdePoco.Type = new CodeTypeReference(table.Name);
            cpdePoco.Direction = FieldDirection.In;
            cmSelect.Parameters.Add(cpdePoco);
            cmSelect.Attributes = MemberAttributes.Public;
            cmSelect.Name = "Select";
            cmSelect.Statements.Add(new CodeSnippetExpression("this.Access.CreateProcedureCommand(\"" + cp_name + "\")"));

            foreach (Column c in table.Columns)
            {
                MemberGraph mGraph = new MemberGraph(c);
                String DotNetTypeName = TypeConvertor.ToNetType(c.DataType.SqlDataType).ToString();

                System.CodeDom.CodeConditionStatement ccsField = new CodeConditionStatement();
                if (mGraph.IsNullable)
                {
                    ccsField.Condition = new CodeSnippetExpression("query." + mGraph.PropertyName() + ".HasValue");
                    ccsField.TrueStatements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\",query." + mGraph.PropertyName() + ".Value, ParameterDirection.Input)"));
                    ccsField.FalseStatements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\", null , ParameterDirection.Input)"));
                }
                else
                {
                    ccsField.Condition = new CodeSnippetExpression("query." + mGraph.PropertyName() + " == null");
                    ccsField.TrueStatements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\", null , ParameterDirection.Input)"));
                    ccsField.FalseStatements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\",query." + mGraph.PropertyName() + ", ParameterDirection.Input)"));
                }

                cmSelect.Statements.Add(ccsField);
            }

            cmSelect.Statements.Add(new CodeSnippetExpression("return this.Access.ExecuteDataSet()"));
            cmSelect.Comments.Add(new CodeCommentStatement("Select by Object [Implements Query By Example], returns DataSet"));
            return cmSelect;
        }
Example #6
0
        /// <summary>
        /// Update Query Method
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private CodeMemberMethod BuildUpdate(TableViewTableTypeBase table)
        {
            CodeMemberMethod cmUpdate = new CodeMemberMethod();
            cmUpdate.Attributes = MemberAttributes.Public;
            cmUpdate.Name = "Update";
            String cp_name = "cp_" + table.Name;

            foreach (Column c in table.Columns)
            {
                MemberGraph mGraph = new MemberGraph(c);
                if (mGraph.IsReadOnly)
                {
                    // nothing yet
                }
                else
                {
                    cmUpdate.Parameters.Add(mGraph.GetParameter());
                }
            }

            cmUpdate.Statements.Add(new CodeSnippetExpression("this.Access.CreateProcedureCommand(\"ProcedureName\")".Replace("ProcedureName", cp_name)));
            cmUpdate.Statements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"Operation\", 4, ParameterDirection.Input)"));

            foreach (Column c in table.Columns)
            {
                MemberGraph mGraph = new MemberGraph(c);
                if (mGraph.IsReadOnly)
                {
                    // nothing yet
                }
                else
                {
                    cmUpdate.Statements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\", " + mGraph.ParameterName() + ", ParameterDirection.Input)"));
                }
            }

            cmUpdate.Statements.Add(new CodeSnippetExpression("var value  = this.Access.ExecuteNonQuery()"));
            cmUpdate.Statements.Add(new CodeSnippetExpression("return value"));
            cmUpdate.ReturnType = new CodeTypeReference("System.Int32");
            cmUpdate.Comments.Add(new CodeCommentStatement("Updates a Record"));
            return cmUpdate;
        }
Example #7
0
        private CodeMemberMethod BuildPocoDelete(TableViewTableTypeBase table)
        {
            CodeMemberMethod cmDelete = new CodeMemberMethod();
            cmDelete.Attributes = MemberAttributes.Public;
            cmDelete.Name = "Delete";
            String cp_name = "cp_" + table.Name;
            cmDelete.Parameters.Add(this.PocoQueryParameter(table.Name));
            cmDelete.ReturnType = new CodeTypeReference("System.Int32");
            cmDelete.Statements.Add(new CodeSnippetExpression("this.Access.CreateProcedureCommand(\"ProcedureName\")".Replace("ProcedureName", cp_name)));
            cmDelete.Statements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"Operation\", 6, ParameterDirection.Input)"));

            foreach (Column c in table.Columns)
            {
                if (c.InPrimaryKey)
                {
                    MemberGraph mGraph = new MemberGraph(c);
                    if (mGraph.IsNullable)
                    {

                        cmDelete.Statements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\", query." + mGraph.PropertyName() + ".Value, ParameterDirection.Input)"));
                    }
                    else
                    {
                        cmDelete.Statements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\", query." + mGraph.PropertyName() + ", ParameterDirection.Input)"));
                    }
                }
            }

            cmDelete.Statements.Add(new CodeSnippetExpression("var value = this.Access.ExecuteNonQuery()"));
            cmDelete.Statements.Add(new CodeSnippetExpression("return value"));
            cmDelete.Comments.Add(new CodeCommentStatement("Delete's a record"));

            return cmDelete;
        }
Example #8
0
        private CodeMemberMethod BuildFillMethod(TableViewTableTypeBase table)
        {
            // Accepts a DataRow and Returns a Poco of this type.
            CodeMemberMethod cmmFill = new CodeMemberMethod();
            cmmFill.Name = "Fill";
            cmmFill.Attributes = MemberAttributes.Private;
            cmmFill.ReturnType = new CodeTypeReference(table.Name);
            CodeParameterDeclarationExpression cpdeDataRow = new CodeParameterDeclarationExpression();
            cpdeDataRow.Name = "row";
            cpdeDataRow.Type = new CodeTypeReference("System.Data.DataRow");
            cpdeDataRow.Direction = FieldDirection.In;

            cmmFill.Parameters.Add(cpdeDataRow);
            var init_Express = new CodeSnippetExpression("new " + table.Name + "()");

            var obj = new CodeVariableDeclarationStatement(new CodeTypeReference(table.Name), "obj", init_Express);
            cmmFill.Statements.Add(obj);

            foreach (Column c in table.Columns)
            {
                String DotNetTypeName = TypeConvertor.ToNetType(c.DataType.SqlDataType).ToString();
                MemberGraph mGraph = new MemberGraph(c);
                System.CodeDom.CodeConditionStatement ccsField = new CodeConditionStatement();
                ccsField.Condition = new CodeSnippetExpression("(row[\"" + c.Name + "\"] != System.DBNull.Value)");
                //if (!(mGraph.IsReadOnly))
                //{
                    // If Field is nullable Type
                    if (mGraph.IsNullable)
                    {
                        if (mGraph.TypeName() == "String")
                        {
                            ccsField.TrueStatements.Add(new CodeSnippetExpression("obj." + mGraph.PropertyName() + " = row[\"" + c.Name + "\"].ToString()"));
                        }
                        else
                        {
                            ccsField.TrueStatements.Add(new CodeSnippetExpression("obj." + mGraph.PropertyName() + " = ((" + mGraph.TypeName() + ")(row[\"" + c.Name + "\"]))"));
                        }
                    }
                    else
                    {
                        if (mGraph.TypeName() == "String")
                        {
                             ccsField.TrueStatements.Add(new CodeSnippetExpression("obj." + mGraph.PropertyName() + " = row[\"" + c.Name + "\"].ToString()"));
                        }
                        else
                        {
                            ccsField.TrueStatements.Add(new CodeSnippetExpression("obj." + mGraph.PropertyName() + " = ((" + mGraph.TypeName() + ")(row[\"" + c.Name + "\"]))"));
                        }
                    }
                    cmmFill.Statements.Add(ccsField);
                //}
            }

            cmmFill.Statements.Add(new CodeSnippetExpression("return obj"));
            cmmFill.Comments.Add(new CodeCommentStatement("Returns a Hydrated POCO"));
            return cmmFill;
        }