private void CreateClassFile(RichTextBox rtb, Tablo t) { List <Kolon> kolonlar = rtb.Tag as List <Kolon>; rtb.Text += "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace Entities\n{\n\tpublic class " + t.Name + "\n\t{\n"; foreach (Kolon kolon in kolonlar) { rtb.Text += "\t\t" + kolon.GetCSharpPropText() + Environment.NewLine; } rtb.Text += "\n\t}\n} "; }
private void btnOlustur_Click(object sender, EventArgs e) { tabControl1.TabPages.Clear(); if (clbTablolar.CheckedItems.Count > 0) { string connStr = GetConnectionString(cmbVeritabanlari.Text); foreach (object item in clbTablolar.CheckedItems) { Tablo t = item as Tablo; string query = "SELECT C.column_id, C.name AS column_name, T.name AS ctype_name, C.is_nullable, C.max_length, C.is_identity FROM sys.columns AS C INNER JOIN sys.types AS T ON T.system_type_id = C.system_type_id WHERE C.object_id = " + t.id.ToString() + " AND T.name != 'sysname'"; Database db = new Database(connStr); DataTable dt = db.GetTable(query, null); // columns bilgisi geldi. TabPage tp = new TabPage(t.Name); RichTextBox rtb = new RichTextBox(); rtb.Dock = DockStyle.Fill; List <Kolon> kolonlar = new List <Kolon>(); foreach (DataRow dr in dt.Rows) { Kolon k = new Kolon() { Id = int.Parse(dr["column_id"].ToString()), Name = dr["column_name"].ToString(), MaxLength = (dr["max_length"] == DBNull.Value) ? null : (int?)int.Parse(dr["max_length"].ToString()), TypeName = dr["ctype_name"].ToString(), IsIdentity = (bool)dr["is_identity"], IsNullable = (bool)dr["is_nullable"] }; kolonlar.Add(k); } rtb.Tag = kolonlar; CreateClassFile(rtb, t); tp.Controls.Add(rtb); tabControl1.TabPages.Add(tp); } } }
private void cmbVeritabanlari_SelectedIndexChanged(object sender, EventArgs e) { if (cmbVeritabanlari.SelectedIndex > -1) { string connStr = GetConnectionString(cmbVeritabanlari.Text); Database db = new Database(connStr); DataTable dt = db.GetTable("SELECT name, object_id FROM sys.tables", null); clbTablolar.Items.Clear(); foreach (DataRow dr in dt.Rows) { Tablo tbl = new Tablo() { id = (int)dr["object_id"], Name = dr["name"].ToString() }; clbTablolar.Items.Add(tbl); } } }