public void TestMethod1() { ProjectInfo projectInfo = new ProjectInfo(); projectInfo.TemplatePath = @"E:\Projects\Framework\SourceCode\Master\GenCodeTool\CodeTemplate\CSWeb"; projectInfo.GenTargetPath = @"E:\TestGenCode"; projectInfo.Name = "TestProject"; projectInfo.Namespace = "NFramework.TestProject"; projectInfo.DisplayName = "测试生成"; projectInfo.CodeInfoGetter = new CSCodeInfoGetter(); projectInfo.DBInfoGetter = new MssqlDBInfoGetter(); projectInfo.IsClearTargetFolder = true; TableInfo tableInfo = null; ColumnInfo colInfo = null; #region Company tableInfo = new TableInfo(); tableInfo.Name = "Company"; tableInfo.Comment = "公司"; TableInfo comTableInfo = tableInfo; colInfo = new ColumnInfo(); colInfo.Name = "Name"; colInfo.DbType = DbType.String; colInfo.SqlType = "VarChar"; colInfo.DalType = projectInfo.DBInfoGetter.ToDalType(colInfo.SqlType, colInfo.Precision, colInfo.Scale); colInfo.CodeType = projectInfo.CodeInfoGetter.ToCodeType(colInfo.DbType); colInfo.MaxLength = 100; colInfo.IsNullable = false; colInfo.Comment = "名称"; colInfo.CurrTable = tableInfo; colInfo.IsGenSearchCondition = true; colInfo.IsGenInput = true; colInfo.IsGenSearchResult = true; colInfo.IsUnique = false; tableInfo.AddColumn(colInfo); colInfo = new ColumnInfo(); colInfo.Name = "Code"; colInfo.DbType = DbType.String; colInfo.SqlType = "VarChar"; colInfo.DalType = projectInfo.DBInfoGetter.ToDalType(colInfo.SqlType, colInfo.Precision, colInfo.Scale); colInfo.CodeType = projectInfo.CodeInfoGetter.ToCodeType(colInfo.DbType); colInfo.MaxLength = 10; colInfo.IsNullable = false; colInfo.Comment = "编号"; colInfo.CurrTable = tableInfo; colInfo.IsGenSearchCondition = true; colInfo.IsGenInput = true; colInfo.IsGenSearchResult = true; colInfo.IsUnique = true; tableInfo.AddColumn(colInfo); colInfo = new ColumnInfo(); colInfo.Name = "CompanyId"; colInfo.DbType = DbType.String; colInfo.SqlType = "VarChar"; colInfo.DalType = projectInfo.DBInfoGetter.ToDalType(colInfo.SqlType, colInfo.Precision, colInfo.Scale); colInfo.CodeType = projectInfo.CodeInfoGetter.ToCodeType(colInfo.DbType); colInfo.MaxLength = 40; colInfo.IsNullable = false; colInfo.IsPK = true; colInfo.Comment = "ID"; colInfo.CurrTable = tableInfo; colInfo.IsGenSearchCondition = false; colInfo.IsGenInput = false; colInfo.IsGenSearchResult = false; colInfo.IsUnique = true; tableInfo.AddColumn(colInfo); colInfo = new ColumnInfo(); colInfo.Name = "CreateTime"; colInfo.DbType = DbType.DateTime; colInfo.SqlType = "DateTime"; colInfo.DalType = projectInfo.DBInfoGetter.ToDalType(colInfo.SqlType, colInfo.Precision, colInfo.Scale); colInfo.CodeType = projectInfo.CodeInfoGetter.ToCodeType(colInfo.DbType); colInfo.MaxLength = 12; colInfo.IsNullable = false; colInfo.IsPK = false; colInfo.Comment = "创建时间"; colInfo.CurrTable = tableInfo; colInfo.IsGenSearchCondition = false; colInfo.IsGenInput = false; colInfo.IsGenSearchResult = false; colInfo.IsUnique = false; tableInfo.AddColumn(colInfo); colInfo = new ColumnInfo(); colInfo.Name = "Status"; colInfo.DbType = DbType.Int32; colInfo.SqlType = "Int"; colInfo.DalType = projectInfo.DBInfoGetter.ToDalType(colInfo.SqlType, colInfo.Precision, colInfo.Scale); colInfo.CodeType = projectInfo.CodeInfoGetter.ToCodeType(colInfo.DbType); colInfo.MaxLength = 8; colInfo.DefaultValue = "((1))"; colInfo.IsNullable = false; colInfo.IsPK = false; colInfo.Comment = "Status"; colInfo.CurrTable = tableInfo; colInfo.IsGenSearchCondition = true; colInfo.IsGenInput = false; colInfo.IsGenSearchResult = true; colInfo.IsUnique = false; tableInfo.AddColumn(colInfo); colInfo = new ColumnInfo(); colInfo.Name = "Col2"; colInfo.DbType = DbType.String; colInfo.SqlType = "VarChar"; colInfo.DalType = projectInfo.DBInfoGetter.ToDalType(colInfo.SqlType, colInfo.Precision, colInfo.Scale); colInfo.CodeType = projectInfo.CodeInfoGetter.ToCodeType(colInfo.DbType); colInfo.MaxLength = 50; colInfo.DefaultValue = "22"; colInfo.IsNullable = true; colInfo.IsPK = false; colInfo.Comment = "Col2的字段"; colInfo.CurrTable = tableInfo; colInfo.IsGenSearchCondition = true; colInfo.IsGenInput = false; colInfo.IsGenSearchResult = true; colInfo.IsUnique = false; tableInfo.AddColumn(colInfo); projectInfo.AddTableInfo(tableInfo); #endregion #region Department tableInfo = new TableInfo(); tableInfo.Name = "Department"; tableInfo.Comment = "部门"; colInfo = new ColumnInfo(); colInfo.Name = "Name"; colInfo.DbType = DbType.String; colInfo.SqlType = "VarChar"; colInfo.DalType = projectInfo.DBInfoGetter.ToDalType(colInfo.SqlType, colInfo.Precision, colInfo.Scale); colInfo.CodeType = projectInfo.CodeInfoGetter.ToCodeType(colInfo.DbType); colInfo.MaxLength = 100; colInfo.IsNullable = false; colInfo.Comment = "名称"; colInfo.CurrTable = tableInfo; colInfo.IsGenSearchCondition = true; colInfo.IsGenInput = true; colInfo.IsGenSearchResult = true; colInfo.IsUnique = false; tableInfo.AddColumn(colInfo); colInfo = new ColumnInfo(); colInfo.Name = "Code"; colInfo.DbType = DbType.String; colInfo.SqlType = "VarChar"; colInfo.DalType = projectInfo.DBInfoGetter.ToDalType(colInfo.SqlType, colInfo.Precision, colInfo.Scale); colInfo.CodeType = projectInfo.CodeInfoGetter.ToCodeType(colInfo.DbType); colInfo.MaxLength = 10; colInfo.IsNullable = false; colInfo.Comment = "编号"; colInfo.CurrTable = tableInfo; colInfo.IsGenSearchCondition = true; colInfo.IsGenInput = true; colInfo.IsGenSearchResult = true; colInfo.IsUnique = true; tableInfo.AddColumn(colInfo); colInfo = new ColumnInfo(); colInfo.Name = "DepartmentId"; colInfo.DbType = DbType.String; colInfo.SqlType = "VarChar"; colInfo.DalType = projectInfo.DBInfoGetter.ToDalType(colInfo.SqlType, colInfo.Precision, colInfo.Scale); colInfo.CodeType = projectInfo.CodeInfoGetter.ToCodeType(colInfo.DbType); colInfo.MaxLength = 40; colInfo.IsNullable = false; colInfo.IsPK = true; colInfo.Comment = "ID"; colInfo.CurrTable = tableInfo; colInfo.IsGenSearchCondition = false; colInfo.IsGenInput = false; colInfo.IsGenSearchResult = false; colInfo.IsUnique = true; tableInfo.AddColumn(colInfo); colInfo = new ColumnInfo(); colInfo.Name = "CompanyId"; colInfo.DbType = DbType.String; colInfo.SqlType = "VarChar"; colInfo.DalType = projectInfo.DBInfoGetter.ToDalType(colInfo.SqlType, colInfo.Precision, colInfo.Scale); colInfo.CodeType = projectInfo.CodeInfoGetter.ToCodeType(colInfo.DbType); colInfo.MaxLength = 40; colInfo.IsNullable = false; colInfo.IsPK = false; colInfo.IsFK = true; colInfo.FKName = "FK_Company_Department"; colInfo.Comment = "所属公司ID"; colInfo.CurrTable = tableInfo; colInfo.IsGenSearchCondition = false; colInfo.IsGenInput = false; colInfo.IsGenSearchResult = false; colInfo.IsUnique = false; colInfo.FKColumn = comTableInfo.PKList[0]; tableInfo.AddColumn(colInfo); projectInfo.AddTableInfo(tableInfo); #endregion #region Position tableInfo = new TableInfo(); tableInfo.Name = "Position"; projectInfo.AddTableInfo(tableInfo); #endregion #region Employee tableInfo = new TableInfo(); tableInfo.Name = "Employee"; projectInfo.AddTableInfo(tableInfo); #endregion GenCodeHandler.GenCode(projectInfo); }
private void StartGenBtn_Click(object sender, EventArgs e) { ProjectInfo projectInfo = new ProjectInfo(); projectInfo.ConnectionString = this.ConnectionStringTxt.Text; projectInfo.Name = this.ProjectNameTxt.Text; projectInfo.DisplayName = this.ProjectDisplayNameTxt.Text; projectInfo.Namespace = this.NamespaceTxt.Text; projectInfo.IsClearTargetFolder = this.IsClearTargetFolderChk.Checked; projectInfo.ReferenceRootFolder = this.ReferenceFolderTxt.Text; if (CodeTemplateCbx.SelectedValue != null) { projectInfo.TemplatePath = GenCodeHandler.CodeTemplatePool[CodeTemplateCbx.SelectedValue.ToString()]; } projectInfo.GenTargetPath = this.GenTargetFolderTxt.Text; projectInfo.DBInfoGetter = (IDBInfoGetter)DBInfoGetterCbx.SelectedItem; projectInfo.CodeInfoGetter = (ICodeInfoGetter)CodeInfoGetterCbx.SelectedItem; IList<TableInfo> tableInfoList = (IList<TableInfo>)TableInfoBSource.DataSource; projectInfo.AllDBTableInfoList = tableInfoList; foreach (TableInfo tableInfo in tableInfoList) { if (!tableInfo.IsGen) { continue; } projectInfo.AddTableInfo(tableInfo); } string errorMsg = GenCodeHandler.ValidatePreGen(projectInfo); if (!string.IsNullOrWhiteSpace(errorMsg)) { MessageBox.Show(GenCodeToolResource.GenFaild + System.Environment.NewLine + errorMsg, GenCodeToolResource.WarningTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ProgressForm progressFrm = new ProgressForm(); progressFrm.WaitGenProjectInfo = projectInfo; progressFrm.ShowDialog(); }