private void InitReferenceDiagram(String Cell) { tableFlow1.Clear(); SheetReference Reference = CellType.ReferenceInfo as SheetReference; if (Reference != null && !String.IsNullOrEmpty(Reference.ReferenceXml)) { TableName = Reference.TableName; ColumnName = Reference.ColumnName; DataFilter = Reference.DataFilter; LoadFromXml(Reference.ReferenceXml); } else { DataTableSchema DataTable = SheetConfiguration.DataTableSchema; bool HaveItem = DataTable.HaveDataItem(Cell); if (HaveItem) { FieldDefineInfo FieldInfo = DataTable.GetDataItem(Cell); if (FieldInfo != null && DataTable.Schema != null) { TableName = DataTable.Schema.Name; ColumnName = FieldInfo.FieldName; AppendTableByTableName(TableName, false); } else { MessageBox.Show("表单‘" + SheetConfiguration.Description + "’没有设置数据项!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
/// <summary> /// 取得数据库名称 /// </summary> /// <param name="tableName">数据表</param> /// <returns>数据库名称</returns> public DataTableSchema GetTable(string databaseName, string ownerName, string tableName) { DataTableSchema table = null; List <DataColumnSchema> list = null; list = GetColumns(databaseName, ownerName, tableName); if (list.Count > 0) { table = new DataTableSchema(tableName); table.Name = tableName; table.Description = GetTableDescription(databaseName, ownerName, tableName); foreach (DataColumnSchema item in list) { table.Columns.Add(item); } } // 设置主键 list = GetPrimaryKeyColumns(databaseName, ownerName, tableName); if (list.Count > 0) { foreach (DataColumnSchema item in list) { for (int i = 0; i < table.Columns.Count; i++) { if (table.Columns[i].Name == item.Name) { table.Columns[i].PrimaryKey = true; break; } } } } // 设置外键 list = GetForeignKeyColumns(databaseName, ownerName, tableName); if (list.Count > 0) { foreach (DataColumnSchema item in list) { for (int i = 0; i < table.Columns.Count; i++) { if (table.Columns[i].Name == item.Name) { table.Columns[i].ForeignKey = true; break; } } } } return(table); }
public override void Init(string taskName, CodeBuilderConfiguration configuration) { // 作者 this.Author = configuration.Author; // 名称空间前缀 this.DataTableName = configuration.Tasks[taskName].Properties["DataTable"].Value; // 名称空间 this.Package = ((string.IsNullOrEmpty(configuration.NamespaceRoot)) ? string.Empty : (configuration.NamespaceRoot + ".")) + configuration.Tasks[taskName].Properties["Package"].Value; // 类名称 this.ClassName = configuration.Tasks[taskName].Properties["ClassName"] == null ? "" : configuration.Tasks[taskName].Properties["ClassName"].Value; // 实体类所在的包名称 this.EntityClassPackage = configuration.Tasks[taskName].Properties["EntityClassPackage"] == null ? "" : configuration.Tasks[taskName].Properties["EntityClassPackage"].Value; // 实体类名称 this.EntityClass = configuration.Tasks[taskName].Properties["EntityClass"].Value; // 应用名称 this.ApplicationName = configuration.Tasks[taskName].Properties["ApplicationName"] == null ? "" : configuration.Tasks[taskName].Properties["ApplicationName"].Value; // 数据层接口 this.DataAccessInterface = configuration.Tasks[taskName].Properties["DataAccessInterface"] == null ? "" : configuration.Tasks[taskName].Properties["DataAccessInterface"].Value; // 数据层接口 this.SupportAuthorization = configuration.Tasks[taskName].Properties["SupportAuthorization"] == null ? "" : configuration.Tasks[taskName].Properties["SupportAuthorization"].Value; //设置 table 信息 IDbSchemaProvider provider = (IDbSchemaProvider)Assembly.Load(configuration.DatabaseProvider.Assembly).CreateInstance(configuration.DatabaseProvider.ClassName, false, BindingFlags.Default, null, new object[] { configuration.DatabaseProvider.ConnectionString }, null, null); DatabaseSchema database = new DatabaseSchema(); database.Name = provider.GetDatabaseName(); database.OwnerName = configuration.DatabaseProvider.OwnerName; table = provider.GetTable(database.Name, database.OwnerName, this.DataTableName); var noPrimaryKeyColumns = provider.GetNoPrimaryKeyColumns(table); this.fields = GetFields(table); // 设置 输出文件 if (configuration.Tasks[taskName].Properties["File"] == null) { configuration.Tasks[taskName].Properties.Add(new X3Platform.CodeBuilder.Configuration.TaskProperty("File", this.ClassName + ".cs")); } else if (string.IsNullOrEmpty(configuration.Tasks[taskName].Properties["File"].Value)) { configuration.Tasks[taskName].Properties["File"].Value = this.ClassName + ".cs"; } }
public override void Init(string taskName, CodeBuilderConfiguration configuration) { provider = (X3Platform.CodeBuilder.Data.IDbSchemaProvider)Assembly.Load(configuration.DatabaseProvider.Assembly).CreateInstance(configuration.DatabaseProvider.ClassName, false, BindingFlags.Default, null, new object[] { configuration.DatabaseProvider.ConnectionString }, null, null); database = new X3Platform.CodeBuilder.Data.DatabaseSchema(); database.Name = provider.GetDatabaseName(); database.OwnerName = configuration.DatabaseProvider.OwnerName; string dataTables = configuration.Tasks[taskName].Properties["DataTables"].Value; string[] tableNames = dataTables.Split(','); this.tables = new List <DataTableSchema>(); // List<DataTableSchema> foreach (string tableName in tableNames) { DataTableSchema table = provider.GetTable(database.Name, database.OwnerName, tableName); this.tables.Add(table); } // 补全 for (int i = 0; i < tables.Count; i++) { DataTableSchema table = this.tables[i]; Dictionary <string, int> dict = GetDisplayLength(table); for (int j = 0; j < table.Columns.Count; j++) { DataColumnSchema column = table.Columns[j]; column.Name = Padding(column.Name, dict["Name"]); column.NativeType = Padding(column.NativeType, dict["NativeType"]); column.Description = Padding(column.Description, dict["Description"]); } } //设置 输出文件 if (configuration.Tasks[taskName].Properties["File"] == null) { configuration.Tasks[taskName].Properties.Add(new TaskProperty("File", taskName + ".md")); } else if (string.IsNullOrEmpty(configuration.Tasks[taskName].Properties["File"].Value)) { configuration.Tasks[taskName].Properties["File"].Value = taskName + ".md"; } }
/// <summary> /// Constructs the column information with the details /// </summary> /// <param name="table">The table schema</param> /// <param name="column">The column schema</param> public QueryColumnInfo ( DataTableSchema table, DataColumnSchema column ) { Validate.IsNotNull(table); Validate.IsNotNull(column); this.Table = table; this.Column = column; }
/// <summary> /// 取得数据库名称 /// </summary> /// <param name="tableName">数据表</param> /// <returns>数据库名称</returns> public DataColumnSchemaCollection GetNoPrimaryKeyColumns(DataTableSchema table) { DataColumnSchemaCollection list = new DataColumnSchemaCollection(); for (int i = 0; i < table.Columns.Count; i++) { if (!table.Columns[i].PrimaryKey) { list.Add(table.Columns[i]); } } return(list); }
public IList <CSharpField> GetFields(DataTableSchema table) { IList <CSharpField> list = new List <CSharpField>(); for (int i = 0; i < table.Columns.Count; i++) { list.Add(new CSharpField { Name = FieldHelper.FormatName(table.Columns[i].Name), // Type = ConvertType(table.Columns[i].Type), // DefaultValue = GetDefaultValue(table.Columns[i].Type), }); } return(list); }
/// <summary> /// 通过列顺序号获取列临时数据对象 /// </summary> /// <param name="columnNo"></param> /// <returns></returns> protected ColumnInfo GetColumnInfo(int columnNo) { ColumnInfo columnInfo = new ColumnInfo(); XmlNode item = DataTableSchema.SelectSingleNode(string.Format("DataTableSchema/Columns/Column[@ColumnNumber='{0}']", columnNo)); if (item != null) { columnInfo.DataType = ((item.Attributes["Type"] == null) ? String.Empty : item.Attributes["Type"].Value); columnInfo.ColumnName = ((item.Attributes["Name"] == null) ? String.Empty : item.Attributes["Name"].Value); columnInfo.Length = ((item.Attributes["Length"] == null) ? String.Empty : item.Attributes["Length"].Value); columnInfo.Unique = ((item.Attributes["Unique"] == null) ? false : Convert.ToBoolean(item.Attributes["Unique"].Value)); columnInfo.ColumnNumber = ((item.Attributes["ColumnNumber"] == null) ? 0 : Convert.ToInt32(item.Attributes["ColumnNumber"].Value)); columnInfo.Description = ((item.Attributes["Description"] == null) ? String.Empty : item.Attributes["Description"].Value); } else { return(null); } return(columnInfo); }
/// <summary>查询数据库中多个表的信息</summary> /// <param name="databaseName">数据库</param> /// <param name="ownerName">所有者</param> /// <param name="tableNames">表名, 多个以半角逗号隔开</param> /// <returns>多个数据表信息的列表</returns> public IList <DataTableSchema> GetTables(string databaseName, string ownerName, string tableNames) { IList <DataTableSchema> tables = new List <DataTableSchema>(); string[] list = tableNames.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string tableName in list) { DataTableSchema table = this.GetTable(databaseName, ownerName, tableName); if (table == null) { continue; } tables.Add(table); } return(tables); }
public IList <CSharpField> GetFields(DataTableSchema table) { IList <CSharpField> list = new List <CSharpField>(); for (int i = 0; i < table.Columns.Count; i++) { list.Add(new CSharpField { Name = FieldHelper.FormatName(table.Columns[i].Name), DataColumnName = table.Columns[i].Name, Type = ConvertType(table.Columns[i].Type), Length = table.Columns[i].Length, DefaultValue = GetDefaultValue(table.Columns[i].Type), Nullable = table.Columns[i].Nullable, Description = table.Columns[i].Description }); } return(list); }
public IList<PythonField> GetFields(DataTableSchema table) { IList<PythonField> list = new List<PythonField>(); for (int i = 0; i < table.Columns.Count; i++) { list.Add(new PythonField { Name = StringHelper.ToFirstLower(FieldHelper.FormatName(table.Columns[i].Name)), DataColumnName = table.Columns[i].Name, Type = ConvertType(table.Columns[i].Type), Length = table.Columns[i].Length, DefaultValue = GetDefaultValue(table.Columns[i].Type), Nullable = table.Columns[i].Nullable, Description = table.Columns[i].Description }); } return list; }
public IList <JavaField> GetFields(DataTableSchema table) { IList <JavaField> list = new List <JavaField>(); for (int i = 0; i < table.Columns.Count; i++) { list.Add(new JavaField { Name = X3Platform.Util.StringHelper.ToFirstLower(FieldHelper.FormatName(table.Columns[i].Name)), NameFirstUpperCase = FieldHelper.FormatName(table.Columns[i].Name), DataColumnName = table.Columns[i].Name, Type = ConvertType(table.Columns[i].Type), JdbcType = ConvertJdbcType(table.Columns[i].Type), Length = table.Columns[i].Length, DefaultValue = GetDefaultValue(table.Columns[i].Type), Nullable = table.Columns[i].Nullable, Description = table.Columns[i].Description }); } return(list); }
/// <summary> /// 取得常用 Where 信息 /// </summary> /// <returns>Where Clause</returns> private string GetWhereClause(DataTableSchema table) { StringBuilder outString = new StringBuilder(); bool firstClause = true; for (int i = 0; i < table.Columns.Count; i++) { if (table.Columns[i].PrimaryKey) { outString.Append("\t\t"); if (!firstClause) { outString.Append("AND "); } outString.AppendLine(table.Columns[i].Name + " = @" + table.Columns[i].Name); firstClause = false; } } return(outString.ToString()); }
private Dictionary <string, int> GetDisplayLength(DataTableSchema table) { Dictionary <string, int> dict = new Dictionary <string, int>() { { "Name", 0 }, { "NativeType", 0 }, { "Description", 0 } }; int maxlength = 0; for (int j = 0; j < table.Columns.Count; j++) { DataColumnSchema column = table.Columns[j]; maxlength = GetTextLength(column.Name); if (dict["Name"] < maxlength) { dict["Name"] = maxlength; } maxlength = GetTextLength(column.NativeType); if (dict["NativeType"] < maxlength) { dict["NativeType"] = maxlength; } maxlength = GetTextLength(column.Description); if (dict["Description"] < maxlength) { dict["Description"] = maxlength; } } return(dict); }
public override void Init(string generatorName, CodeBuilderConfiguration configuration) { provider = (X3Platform.CodeBuilder.Data.IDatabaseProvider)Assembly.Load(configuration.DatabaseProvider.Assembly).CreateInstance(configuration.DatabaseProvider.ClassName, false, BindingFlags.Default, null, new object[] { configuration.DatabaseProvider.ConnectionString }, null, null); database = new X3Platform.CodeBuilder.Data.DatabaseSchema(); database.Name = provider.GetDatabaseName(); database.OwnerName = configuration.DatabaseProvider.OwnerName; table = provider.GetTable(database.Name, database.OwnerName, configuration.Tasks[generatorName].Properties["DataTable"].Value); //设置 输出文件 if (configuration.Tasks[generatorName].Properties["File"] == null) { configuration.Tasks[generatorName].Properties.Add(new X3Platform.CodeBuilder.Configuration.TaskProperty("File", configuration.Tasks[generatorName].Properties["DataTable"].Value + ".StorageProcedure.sql")); } else if (string.IsNullOrEmpty(configuration.Tasks[generatorName].Properties["File"].Value)) { configuration.Tasks[generatorName].Properties["File"].Value = configuration.Tasks[generatorName].Properties["DataTable"].Value + ".StorageProcedure.sql"; } }
/// <summary> /// Populates the table schema using a database context /// </summary> /// <param name="context">The database context</param> private void PopulateSchema ( DbContext context ) { try { var entityMaps = context.Db(); var tableSchemas = new List <DataTableSchema>(); foreach (var map in entityMaps) { var columnSchemas = MapTableProperties(map); var table = new DataTableSchema ( map.TableName, columnSchemas ); // Set the primary key details if (map.Pks != null) { var pkColumns = new List <DataColumnSchema>(); foreach (var property in map.Pks) { var column = new DataColumnSchema ( property.ColumnName, property.Type ); pkColumns.Add(column); } table = table.WithPrimaryKey ( pkColumns.ToArray() ); } // Set the foreign key details if (map.Fks != null) { var foreignKeys = new List <DataForeignKey>(); foreach (var property in map.Fks) { var referencedProperty = property.FkTargetColumn; var fkMap = referencedProperty.EntityMap; var fkTableColumns = MapTableProperties(map); var key = new DataForeignKey ( new DataColumnSchema[] { new DataColumnSchema ( property.ColumnName, property.Type ) }, new DataTableSchema ( fkMap.TableName, fkTableColumns ), new DataColumnSchema[] { new DataColumnSchema ( referencedProperty.ColumnName, referencedProperty.Type ) } ); foreignKeys.Add(key); } table = table.WithForeignKeys ( foreignKeys.ToArray() ); } tableSchemas.Add(table); } _schema = tableSchemas.ToArray(); this.DateSchemaResolved = DateTime.UtcNow; } catch (Exception ex) { _schema = new DataTableSchema[] { }; MarkSchemaAsUnresolvable ( ex.Message ); } }
/// <summary> ///加载模板中所有表单的数据项值 /// </summary> /// <param name="Schemas"></param> public void InitDataItems() { foreach (SheetConfiguration Sheet in Module.Sheets) { DataTableSchema DataTable = Sheet.DataTableSchema; TreeView treeView = WriteToTable_Value_Editor.DropDownControl; treeView.Nodes.Clear(); if (DataTable.Schema != null) { TableDefineInfo TableInfo = DataTable.Schema; DropDownNode Node = new DropDownNode(TableInfo.GetHashCode(), TableInfo.Description); Node.Name = TableInfo.Name; treeView.Nodes.Add(Node); #region 时间戳字段 DropDownNode SubNode = new DropDownNode((int)DateTime.Now.Ticks, "时间戳"); SubNode.Name = "scts"; FieldInfo fieldInfo = new FieldInfo(); fieldInfo.Name = "scts"; fieldInfo.Text = "时间戳"; SubNode.Tag = fieldInfo; Node.Nodes.Add(SubNode); #endregion 时间戳字段 foreach (FieldDefineInfo FieldInfo in TableInfo.FieldInfos) { if (!ColumnRegular.JudgeColumnName(FieldInfo.Description)) { SubNode = new DropDownNode(FieldInfo.GetHashCode(), FieldInfo.Description); SubNode.Name = FieldInfo.FieldName; fieldInfo = new FieldInfo(); fieldInfo.Name = FieldInfo.FieldName; fieldInfo.Text = FieldInfo.Description; SubNode.Tag = fieldInfo; Node.Nodes.Add(SubNode); } } } treeView.ExpandAll(); treeView = ModificationValue_Editor.DropDownControl; treeView.Nodes.Clear(); if (DataTable.Schema != null) { TableDefineInfo TableInfo = DataTable.Schema; DropDownNode Node = new DropDownNode(TableInfo.GetHashCode(), TableInfo.Description); Node.Name = TableInfo.Name; treeView.Nodes.Add(Node); #region 时间戳字段 DropDownNode SubNode = new DropDownNode((int)DateTime.Now.Ticks, "时间戳"); SubNode.Name = "scts"; FieldInfo fieldInfo = new FieldInfo(); fieldInfo.Name = "scts"; fieldInfo.Text = "时间戳"; SubNode.Tag = fieldInfo; Node.Nodes.Add(SubNode); #endregion 时间戳字段 foreach (FieldDefineInfo FieldInfo in TableInfo.FieldInfos) { if (!ColumnRegular.JudgeColumnName(FieldInfo.Description)) { SubNode = new DropDownNode(FieldInfo.GetHashCode(), FieldInfo.Description); SubNode.Name = FieldInfo.FieldName; fieldInfo = new FieldInfo(); fieldInfo.Name = FieldInfo.FieldName; fieldInfo.Text = FieldInfo.Description; SubNode.Tag = fieldInfo; Node.Nodes.Add(SubNode); } } } treeView.ExpandAll(); } }