public void WriteTo(Modifiers Class,Modifiers Field,ClassBuilder stream) { StringBuilder sql = new StringBuilder("select"); if (!stream.IsSqlData) { sql.Append(" top 1"); } sql.Append(" * from [") .Append(Text) .Append("]"); IDbCommand command = DBFactory.Create(sql.ToString()); IDataReader reader = command.ExecuteReader(); var dataTable = reader.GetSchemaTable(); var isIdentity = dataTable.Columns["IsIdentity"]; var isUnique = dataTable.Columns["IsUnique"]; var isKey = dataTable.Columns["IsKey"]; var columnName = dataTable.Columns["ColumnName"]; var columnSize = dataTable.Columns["ColumnSize"]; var dataType = dataTable.Columns["DataType"]; var allowDBNull = dataTable.Columns["AllowDBNull"]; stream.AddBeginClass(Class,this.Text); foreach (DataRow row in dataTable.Rows) { string memberName = row[columnName].ToString(); var is_key = row[isKey]; var is_identity = row[isIdentity]; var is_unique = row[isUnique]; if (true.Equals(is_key) || true.Equals(is_identity)) { stream.IdentityMembers.Add(memberName); } stream.AddMember(Field, true.Equals(is_key) || true.Equals(is_identity), row[dataType] as Type, (bool)row[allowDBNull],(int)row[columnSize], memberName); } if (stream.IsVB) { stream.AddBeginMethod("ReadAll",new Argument(typeof(DBReader),"Reader")); for(int i=0;i<reader.FieldCount;i++) stream.AddCodeLine(reader.GetName(i),"=","Reader!",reader.GetName(i)); stream.AddEndMethod(); stream.AddBeginMethod("WriteAll",new Argument(typeof(DBWriter),"Writer")); for(int i=0;i<reader.FieldCount;i++) stream.AddCodeLine("Writer!",reader.GetName(i),"=",reader.GetName(i)); stream.AddEndMethod(); } stream.AddEndClass(); if (stream.IsSqlData) { stream.AddInsertData(reader); } DBFactory.Release(command); }
private void OnStart(object sender, System.EventArgs e) { classdef.ForeColor = Color.Red; classdef.Text = "In process..."; ClassBuilder builder = new ClassBuilder(prefix.Text,Styles[style.SelectedIndex],postfix.Text,ancestor.Text); builder.HasAutoProperty = hasAutoProps.Checked; Modifier[1] = builder.IsCNET?Modifiers.Internal:Modifiers.Friend; foreach(EntityListViewItem entity in List.SelectedItems) entity.WriteTo(Modifier[classModifier.SelectedIndex],Modifier[fieldModifier.SelectedIndex],builder); classdef.ForeColor = Color.Black; classdef.Text = builder.ToString(); }