/// <summary> /// SQL Server生成代码 /// </summary> /// <param name="className"></param> /// <param name="nameSpace"></param> /// <param name="filePath"></param> /// <param name="dt"></param> private void BuilderCode(string className, string nameSpace, string filePath, DataTable dt) { TableHelper helper = new TableHelper(false, false, false); NormalModel model = new NormalModel(); model.NameSpace = nameSpace; model.TableName = className; model.Title = className; // model.SearchColumnsStr List <CodeModel.ColumnInfo> list = new List <CodeModel.ColumnInfo>(); foreach (DataRow row in dt.Rows) { CodeModel.ColumnInfo column = new CodeModel.ColumnInfo(); column.ColumnName = row["COLUMN_NAME"].ToString(); column.DBType = row["DATA_TYPE"].ToString(); list.Add(column); } model.ColumnList = list; string content = helper.GetClassString(model); string fileName = filePath + className + ".cs"; using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate)) { byte[] buffer = Encoding.UTF8.GetBytes(content); fs.Write(buffer, 0, buffer.Length); //fs.Flush(); //fs.Close(); } }
private void CreatCodeByPDM(string nameSpace, string filePath, TableInfo table) { string tableName = table.Code; TableHelper helper = new TableHelper(false, false, false); NormalModel model = new NormalModel(); model.NameSpace = nameSpace; model.TableName = tableName; model.Title = table.Name; //model.ColumnList = table.Columns; // model.SearchColumnsStr List <CodeModel.ColumnInfo> list = new List <CodeModel.ColumnInfo>(); foreach (var row in table.Columns) { CodeModel.ColumnInfo column = new CodeModel.ColumnInfo(); column.ColumnName = row.Code; column.DBType = row.DataType; column.Comment = row.Name; column.IsAutoIncrement = row.Identity; column.IsMainKey = row.IsPrimaryKey; list.Add(column); } model.ColumnList = list; string content = helper.GetClassString(model, true); string fileName = filePath + "\\" + tableName + ".cs"; using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate)) { byte[] buffer = Encoding.UTF8.GetBytes(content); fs.Write(buffer, 0, buffer.Length); } }