コード例 #1
0
ファイル: Form1.cs プロジェクト: amitdumka/AprajitaRetails
        private void button1_Click(object sender, EventArgs e)
        {
            //call table creatot
            //MainProgram.CreatTable (textBox1.Text, richTextBox1);
            Employee ds = new Employee();


            TableClass tab = new TableClass(typeof(Employee));

            richTextBox1.Text = tab.CreateTableScript();
        }
コード例 #2
0
        public static void CreatTable(string tableName, RichTextBox ta)
        {
            List <TableClass> tables = new List <TableClass> ();

            // Pass assembly name via argument
            Assembly a = Assembly.LoadFile(tableName);

            Type [] types = a.GetTypes();

            // Get Types in the assembly.
            foreach (Type t in types)
            {
                TableClass tc = new TableClass(t);
                tables.Add(tc);
            }

            // Create SQL for each table
            foreach (TableClass table in tables)
            {
                Console.WriteLine((ta.Text = ta.Text + "\n" + table.CreateTableScript()).TrimEnd());
                Console.WriteLine();
            }

            // Total Hacked way to find FK relationships! Too lazy to fix right now
            foreach (TableClass table in tables)
            {
                foreach (KeyValuePair <String, Type> field in table.Fields)
                {
                    foreach (TableClass t2 in tables)
                    {
                        if (field.Value.Name == t2.ClassName)
                        {
                            // We have a FK Relationship!
                            Console.WriteLine("GO");
                            Console.WriteLine("ALTER TABLE " + table.ClassName + " WITH NOCHECK");
                            Console.WriteLine("ADD CONSTRAINT FK_" + field.Key + " FOREIGN KEY (" + field.Key + ") REFERENCES " + t2.ClassName + "(ID)");
                            Console.WriteLine("GO");
                        }
                    }
                }
            }
        }