Ejemplo n.º 1
0
        public string CreateTypeScripModel()
        {
            using (var ctx = new ContextTest(constr))
            {
                var cmd = ctx.CreateCommand();
                cmd.CommandType = CommandType.Text;

                cmd.CommandText = string.Format(@"SELECT TABLE_SCHEMA, DATA_TYPE, COLUMN_TYPE, TABLE_NAME 
                                    FROM INFORMATION_SCHEMA.COLUMNS where
                                        `columns`.`TABLE_Schema`='{0}' group by table_name", "dbstokobat");

                IDataReader dr = cmd.ExecuteReader();
                var         s  = dr.GetSchemaTable();

                List <MySchemaInfor> list = this.GetTable(dr);
                var ns = "";
                if (!string.IsNullOrEmpty(namespacess.Text))
                {
                    ns = namespacess.Text;
                }
                else
                {
                    ns = SettingDatabase.Database;
                }

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

                foreach (var itemtable in list)
                {
                    sb.Append(string.Format("\n \n namespace {0} \n", ns));
                    sb.Append("{ \n");


                    sb.Append(string.Format("    export class {0}", itemtable.TableName));

                    sb.Append("  \n   {\n");

                    cmd.CommandText = string.Format("Select * From {0}.{1} limit 1", itemtable.Database, itemtable.TableName);
                    dr = cmd.ExecuteReader();
                    List <ColumnInfo> ReaderSchema = MappingCommon.ReadColumnInfo(dr.GetSchemaTable());

                    foreach (var item in ReaderSchema)
                    {
                        sb.Append(string.Format("public {0}: {1};\n ", item.ColumnName, DataTypeConvert.TypeScript(item.DataType)));

                        //var p = string.Format("          private {0}  _{1};\n ", this.DataTypeConvert(item.DataType), item.ColumnName.ToLower());
                        //listprivate.Add(p);
                    }

                    dr.Close();
                    sb.Append("     }\n");
                    sb.Append("}\n\n\n");
                    if (aClass1File.Checked)
                    {
                        sbview.Append(sb.ToString());
                        CreateFile(sb, Isb, itemtable, "ts");
                        sb.Clear();
                    }
                }
            }
            if (aClass1File.Checked)
            {
                return(sbview.ToString());
            }
            else
            {
                return(sb.ToString());
            }
        }
Ejemplo n.º 2
0
        //metode
        public string CreatePoco()
        {
            using (var db = new ContextTest(constr))
            {
                try
                {
                    var cmd = db.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = this.commandText;
                    IDataReader          dr   = cmd.ExecuteReader();
                    var                  s    = dr.GetSchemaTable();
                    List <MySchemaInfor> list = this.GetTable(dr);
                    dr.Close();
                    var ns = "";
                    if (!string.IsNullOrEmpty(namespacess.Text))
                    {
                        ns = namespacess.Text;
                    }
                    else
                    {
                        ns = SettingDatabase.Database;
                    }


                    //  sb.Append(Header.Text);

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

                    foreach (var itemtable in list)
                    {
                        Isb.Append("using System;\r");
                        sb.Append(string.Format("\n \n namespace {0} \n", ns));
                        sb.Append("{ \n");
                        Isb.Append(string.Format("\n \n namespace {0} \n", ns));
                        Isb.Append("{ \n\r");

                        if (OcphDal.Checked)
                        {
                            sb.Append(string.Format("     [TableName({0}{1}{2})] \n", '"', itemtable.TableName, '"'));
                        }



                        if (Inpc.Checked)
                        {
                            sb.Append(string.Format("     public class {0} :BaseNotify, I{0}", itemtable.TableName));
                        }
                        else
                        {
                            sb.Append(string.Format("     public class {0} :I{0}", itemtable.TableName));
                        }



                        Isb.Append(string.Format("     public interface {0}", itemtable.TableName));



                        sb.Append("  \n   {\n");
                        Isb.Append("  \n   {\n");

                        cmd.CommandText = string.Format("Select * From {0}.{1} limit 1", itemtable.Database, itemtable.TableName);
                        dr = cmd.ExecuteReader();
                        List <ColumnInfo> ReaderSchema = MappingCommon.ReadColumnInfo(dr.GetSchemaTable());

                        foreach (var item in ReaderSchema)
                        {
                            if (OcphDal.Checked && item.IsKey)
                            {
                                sb.Append(string.Format("          [PrimaryKey({0}{1}{2})] \n", '"', item.ColumnName, '"'));
                            }
                            if (OcphDal.Checked)
                            {
                                sb.Append(string.Format("          [DbColumn({0}{1}{2})] \n", '"', item.ColumnName, '"'));
                            }

                            Isb.Append(string.Format("         {0} {1} ", DataTypeConvert.CSharp(item.DataType), item.ColumnName));
                            Isb.Append("{  get; set;} \n\n");



                            if (Modern.Checked)
                            {
                                sb.Append(string.Format("          public {0} {1} ", DataTypeConvert.CSharp(item.DataType), item.ColumnName));
                                sb.Append("{  get; set;} \n\n");
                            }
                            else
                            {
                                sb.Append(string.Format("          public {0} {1} ", DataTypeConvert.CSharp(item.DataType), item.ColumnName));
                                sb.Append("\n          { \n               get{return ");
                                sb.Append(string.Format("_{0};", item.ColumnName.ToLower()));
                                sb.Append("} \n               set{ \n");

                                if (!Inpc.Checked)
                                {
                                    sb.Append(string.Format("                      _{0}=value;", item.ColumnName.ToLower()));
                                }
                                else
                                {
                                    sb.Append(string.Format("\n                    SetProperty(ref _{0}, value);", item.ColumnName.ToLower()));
                                }

                                sb.Append("\n                     }\n          } \n\n");
                                var p = string.Format("          private {0}  _{1};\n ", DataTypeConvert.CSharp(item.DataType), item.ColumnName.ToLower());
                                listprivate.Add(p);
                            }
                        }

                        if (Clasic.Checked)
                        {
                            foreach (var i in listprivate)
                            {
                                sb.Append(i);
                            }
                            listprivate.Clear();
                        }
                        dr.Close();


                        sb.Append("     }\n");
                        sb.Append("}\n\n\n");

                        Isb.Append("     }\n");
                        Isb.Append("}\n\n\n");


                        if (aClass1File.Checked)
                        {
                            if (OcphDal.Checked)
                            {
                                sb.Insert(0, "using Ocph.DAL;");
                            }
                            sb.Insert(0, Header.Text);
                            sbview.Append(sb.ToString());
                            CreateFile(sb, Isb, itemtable, "cs");
                            sb.Clear();
                            Isb.Clear();
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            if (aClass1File.Checked)
            {
                return(sbview.ToString());
            }
            else
            {
                return(sb.ToString());
            }
        }