Beispiel #1
0
        public void CreateClass()
        {
            ClassTableName ctname = new ClassTableName(tableName)
            {
                Option = Option
            };

            ClassName cname = new ClassName(Option.NameSpace, Option.Modifier, ctname);

            ITable schema = new TableSchema(tableName);

            var dpoClass = new DpoClass(schema, cname, Option);

            var sourceCode = dpoClass.Generate(cname.Modifier, ctname);

            string fileName = string.Format("{0}\\{1}.cs", Option.OutputPath, cname.Class);

            if (!Directory.Exists(Option.OutputPath))
            {
                Directory.CreateDirectory(Option.OutputPath);
            }

            StreamWriter sw = new StreamWriter(fileName);
            sw.Write(sourceCode);
            sw.Close();
        }
Beispiel #2
0
        public void CreateClass()
        {
            ClassTableName ctname = new ClassTableName(tableName)
            {
                Option = Option
            };

            ClassName cname = new ClassName(Option.NameSpace, Option.Modifier, ctname);

            ITableSchema schema = new TableSchema(tableName);

            var dpoClass = new DpoClass(schema, cname, Option);

            var sourceCode = dpoClass.Generate(cname.Modifier, ctname);

            string fileName = string.Format("{0}\\{1}.cs", Option.OutputPath, cname.Class);

            if (!Directory.Exists(Option.OutputPath))
            {
                Directory.CreateDirectory(Option.OutputPath);
            }

            StreamWriter sw = new StreamWriter(fileName);

            sw.Write(sourceCode);
            sw.Close();
        }
Beispiel #3
0
 public ClassName(string nameSpace, Modifier modifier, ClassTableName tname, bool subNamespace)
     : this(nameSpace, modifier, tname)
 {
     if (subNamespace)  //create sub-namespace for each database
     {
         this.nameSpace = string.Format("{0}.{1}", nameSpace, tname.SubNamespace);
     }
 }
Beispiel #4
0
        public string Generate(Modifier modifier, ClassTableName ctname)
        {
            //must run it first to form Dictionary
            Fields();

            string comment = @"//
// Machine Generated Code
//
";


            if (nonvalized.Count > 0)
            {
                this.code.AddUsing("Tie");
                comment += "using Tie;";
            }


            this.clss.AddConstructor();
            var cons = this.clss.AddConstructor();

            cons.Params.Add <DataRow>("row");
            cons.BaseArgs = new Arguments("row");

            SQL_CREATE_TABLE_STRING = TableClause.GenerateCREATE_TABLE(metaTable);

            if (option.HasTableAttribute)
            {
                var attr = clss.AddAttribute <TableAttribute>();
                GetTableAttribute(attr, metaTable, ctname);
            }

            PrimaryConstructor();
            DPObjectId();
            PrimaryKeys();
            IdentitiyKeys();
            FillAndCollect();

            ConstStringColumnNames();

            clss.AddUtilsMethod(UtilsThisMethod.Copy | UtilsThisMethod.Clone | UtilsThisMethod.Compare);

            return(code.ToString());
        }
Beispiel #5
0
        public DataTableDpoClass(DataTable table)
        {
            DatabaseName dname = new DatabaseName(ConnectionProviderManager.DefaultProvider, "MEM");

            this.table = table;

            this.tableName = new ClassTableName(new TableName(dname, TableName.dbo, table.TableName));

            this._columns = new ColumnCollection(this);
            foreach (DataColumn c in table.Columns)
            {
                this._columns.Add(new DtColumn(c));
            }

            this._identity = new IdentityKeys(this._columns);
            this._computedColumns = new ComputedColumns(this._columns);

            this._columns.UpdatePrimary(this.PrimaryKeys);
            this._columns.UpdateForeign(this.ForeignKeys);
        }
Beispiel #6
0
        public DataTableDpoClass(DataTable table)
        {
            DatabaseName dname = new DatabaseName(ConnectionProviderManager.DefaultProvider, "MEM");

            this.table = table;

            this.tableName = new ClassTableName(new TableName(dname, SchemaName.dbo, table.TableName));



            this._columns = new ColumnCollection(this);
            foreach (DataColumn c in table.Columns)
            {
                this._columns.Add(new DtColumn(c));
            }

            this._identity        = new IdentityKeys(this._columns);
            this._computedColumns = new ComputedColumns(this._columns);

            this._columns.UpdatePrimary(this.PrimaryKeys);
            this._columns.UpdateForeign(this.ForeignKeys);
        }
Beispiel #7
0
 public ClassName(string nameSpace, Modifier modifier, ClassTableName tname)
     : this(nameSpace, modifier, tname.ClassName)
 {
 }
Beispiel #8
0
        /// <summary>
        /// [TableName.Level] is not updated in [this.tname], then parameter [level] must be passed in
        /// </summary>
        /// <param name="level"></param>
        /// <returns></returns>
        internal static void GetTableAttribute(AttributeInfo attr, ITableSchema metaTable, ClassTableName ctname)
        {
            attr.Comment = new Comment(string.Format("Primary Keys = {0};  Identity = {1};", metaTable.PrimaryKeys, metaTable.Identity));

            List <string> args = new List <string>();

            TableName tableName = metaTable.TableName;

            switch (ctname.Option.Level)
            {
            case Level.Application:
                args.Add($"\"{tableName.Name}\"");
                args.Add("Level.Application");
                break;

            case Level.System:
                args.Add($"\"{tableName.Name}\"");
                args.Add("Level.System");
                break;

            case Level.Fixed:
                args.Add($"\"{tableName.DatabaseName.Name}\"");
                args.Add("Level.Fixed");
                break;
            }


            if (ctname.Option.HasProvider)
            {
                if (!tableName.Provider.Equals(ConnectionProviderManager.DefaultProvider))
                {
                    args.Add(string.Format("Provider = {0}", (int)tableName.Provider));
                }
            }

            if (!ctname.Option.IsPack)
            {
                args.Add("Pack = false");
            }

            attr.Args = args.ToArray();
            return;
        }
Beispiel #9
0
 public ClassName(string nameSpace, Modifier modifier, ClassTableName tname, bool subNamespace)
     : this(nameSpace, modifier, tname)
 {
     if (subNamespace)  //create sub-namespace for each database
         this.nameSpace = string.Format("{0}.{1}", nameSpace, tname.SubNamespace);
 }
Beispiel #10
0
 public ClassName(string nameSpace, Modifier modifier, ClassTableName tname)
     : this(nameSpace, modifier, tname.ClassName)
 {
 }
Beispiel #11
0
        /// <summary>
        /// [TableName.Level] is not updated in [this.tname], then parameter [level] must be passed in
        /// </summary>
        /// <param name="level"></param>
        /// <returns></returns>
        internal static void GetTableAttribute(AttributeInfo attr, ITable metaTable, ClassTableName ctname)
        {
            attr.comment = new Comment(string.Format("Primary Keys = {0};  Identity = {1};", metaTable.PrimaryKeys, metaTable.Identity));

            List<string> args = new List<string>();

            TableName tableName = metaTable.TableName;
            switch (ctname.Option.Level)
            {

                case Level.Application:
                    args.Add($"\"{tableName.Name}\"");
                    args.Add("Level.Application");
                    break;

                case Level.System:
                    args.Add($"\"{tableName.Name}\"");
                    args.Add("Level.System");
                    break;

                case Level.Fixed:
                    args.Add($"\"{tableName.DatabaseName.Name}\"");
                    args.Add("Level.Fixed");
                    break;
            }

            if (ctname.Option.HasProvider)
            {
                if (!tableName.Provider.Equals(ConnectionProviderManager.DefaultProvider))
                {

                    args.Add(string.Format("Provider = {0}", (int)tableName.Provider));
                }
            }

            if (!ctname.Option.IsPack)
                args.Add("Pack = false");

            attr.args = args.ToArray();
            return;
        }
Beispiel #12
0
        public string Generate(Modifier modifier, ClassTableName ctname)
        {
            //must run it first to form Dictionary
            Fields();

            string comment = @"//
            // Machine Generated Code
            //
            ";

            if (nonvalized.Count > 0)
            {
                this.code.AddUsing("Tie");
                comment += "using Tie;";
            }

            this.clss.AddConstructor();
            var cons = this.clss.AddConstructor();
            cons.args.Add<DataRow>("row");
            cons.baseArgs = new string[] { "row" };

            SQL_CREATE_TABLE_STRING = TableClause.GenerateCREATE_TABLE(metaTable);

            if (option.HasTableAttribute)
            {
                var attr = clss.AddAttribute<TableAttribute>();
                GetTableAttribute(attr, metaTable, ctname);
            }

            PrimaryConstructor();
            DPObjectId();
            PrimaryKeys();
            IdentitiyKeys();
            FillAndCollect();

            ConstStringColumnNames();

            clss.AddCopyCloneEqualsFunc();
            //var utils = new Utils(clss.name, metaTable.Columns.Select(column => column.ColumnName.FieldName()));
            //clss.Add(utils.Copy());
            //clss.Add(utils.Clone());
            //clss.Add(utils.Equals());

            return code.ToString();
        }