/// <summary> /// 获取删除Table的命令 /// </summary> /// <param name="tableHeader">Table元数据</param> /// <returns>删除Table的命令</returns> protected virtual string GetDropTableCommand(ITableHeader tableHeader) { //若架构名为空则直接(DROP TABLE 表名) if (string.IsNullOrEmpty(tableHeader.SchemaName)) { return($"DROP TABLE {tableHeader.TableName}"); } //若不为空则(DROP TABLE 架构名.表名) return($"DROP TABLE {tableHeader.SchemaName}.{tableHeader.TableName}"); }
/// <summary> /// 获取重命名Table的命令 /// </summary> /// <param name="tableHeader">Table元数据</param> /// <param name="oldTableName">原来的Table名</param> /// <returns>重命名Table的命令</returns> protected virtual string GetRenameTableCommand(ITableHeader tableHeader, string oldTableName) { //若架构名为空则直接(ALTER TABLE 旧表名 RENAME TO 新表名) if (string.IsNullOrEmpty(tableHeader.SchemaName)) { return($"ALTER TABLE {oldTableName} RENAME TO {tableHeader.TableName}"); } //若不为空则(ALTER TABLE 架构名.旧表名 RENAME TO 架构名.新表名) return(string.Format("ALTER TABLE {0}.{1} RENAME TO {0}.{2}", tableHeader.SchemaName, oldTableName, tableHeader.TableName)); }
/// <summary> /// 获取update所有非主键列的sql /// </summary> /// <returns>update所有非主键列的sql</returns> private string GetUpdateAllSql() { //获取TableHeader对象 ITableHeader tableHeader = this.TableMapper.Header; //获取命令生成树 ICommandTree commandTree = this.CommandTreeFactory.GetUpdateTree(tableHeader.SchemaName, tableHeader.TableName, tableHeader.TableAlias, this.GetUpdateAllChildNodes()); //获取Insert命令 return(commandTree.Compile()); }
/// <summary> /// 创建表 /// </summary> /// <param name="dbHelper">操作数据库的Helper</param> /// <param name="commandTreeFactory">创建CommandTree的工厂</param> /// <param name="tableMapper">Table元数据解析器</param> public int CreateTable(DbHelper dbHelper, ICommandTreeFactory commandTreeFactory, ITableMapper tableMapper) { //获取TableHeader ITableHeader tableHeader = tableMapper.Header; //获取ColumnNodes IEnumerable <IColumnNode> columnNodes = tableMapper.GetColumnMappers().Select(m => m.ToColumnNode()); //获取建表语句生成树 ICommandTree buildTableTree = commandTreeFactory.GetBuildTableTree(tableHeader.SchemaName, tableHeader.TableName, columnNodes); //创建建表语句并执行 return(dbHelper.ExecuteUpdate(buildTableTree.Compile())); }
/// <summary> /// 获取根据ID统计单条记录是否存在命令生成树的子节点 /// </summary> /// <returns>根据ID统计单条记录是否存在命令生成树的子节点</returns> private IEnumerable <INodeBuilder> GetQueryCountByIdChildBuilders() { //获取Select节点的子节点集合 yield return(new NodeBuilder(SqlType.Select, "COUNT(*)")); //获取From节点的子Table表达式节点 ITableHeader tableHeader = base.TableMapper.Header; yield return(base.CommandTreeFactory.GetTableBuilder(tableHeader.TableName, tableHeader.TableAlias, tableHeader.SchemaName)); //获取Where节点的子节点集合 IColumnMapper keyColumnMapper = base.TableMapper.KeyMapper; yield return(base.CommandTreeFactory.GetEqualsBuilder(this.TableMapper.Header.TableAlias, keyColumnMapper.ColumnName, keyColumnMapper.Property.Name)); }
/// <summary> /// Creates an report object with the passed data. /// </summary> /// <returns>Returns a Report object.</returns> public Report Report() { SetupStyles(); SetupReportInfo("Document Exporter"); IBand reportHeader = section.AddBand(); IText reportHeaderText = reportHeader.AddText(); reportHeaderText.Height = new FixedHeight(30); reportHeaderText.Style.Font = headerFont; if (this.exportAllPages) { reportHeaderText.AddContent("Congratulations! You have exported all pages from the report successfully!"); } else { reportHeaderText.AddContent(string.Format("Congratulations! You have exported page {0} successfully!", this.currentPageNumber)); } ITable table = section.AddTable(); table.Borders = bordersStyle; table.Margins.Top = 5; table.Margins.Bottom = 5; table.Width = new RelativeWidth(100); table.Margins.Left = 30; // Header ITableHeader header = table.Header; header.Height = new FixedHeight(24); header.Repeat = true; this.AddHeaderCell(header, "Order ID"); this.AddHeaderCell(header, "Contact Name"); this.AddHeaderCell(header, "Shipping Address"); this.AddHeaderCell(header, "Order Date"); //Here we add all the rows of the table this.AddTableRows(table); return(report); }
/// <summary> /// 判断当前table是否存在 /// </summary> /// <param name="dbHelper">操作数据库的Helper</param> /// <param name="tableHeader">Table基础数据</param> /// <returns>当前table是否存在</returns> public override bool IsExist(DbHelper dbHelper, ITableHeader tableHeader) { //获取sql命令 StringBuilder commandText = new StringBuilder(); commandText.AppendLine("SELECT COUNT(*)"); commandText.AppendLine(" FROM information_schema.Tables t"); commandText.AppendLine(" WHERE t.Table_Name = @TableName"); commandText.AppendLine(" AND t.Table_Schema = @SchemaName"); //获取sql参数数组 IDbDataParameter[] parameters = new IDbDataParameter[] { dbHelper.Parameter("TableName", tableHeader.TableName), dbHelper.Parameter("SchemaName", "MemberSys") }; //执行获取结果 int result = TypeHelper.ConvertTo <int>(dbHelper.GetScalar(commandText.ToString(), parameters: parameters)); return(result > 0); }
/// <summary> /// 为当前实体所Mapping的Table添加没有添加的列 /// </summary> /// <param name="dbHelper">操作数据库的Helper对象</param> /// <param name="commandTreeFactory">创建CommandTree的工厂</param> /// <param name="tableMapper">Table元数据解析器</param> public void AlterTableAddColumns(DbHelper dbHelper, ICommandTreeFactory commandTreeFactory, ITableMapper tableMapper) { //获取当前实体元数据解析器中某些属性Mapping的Column未包含在Table中的属性对应的ColumnMapper,并转换获取Column节点 string[] columnNames = this.GetColumns(dbHelper, tableMapper.Header).ToArray(); IColumnNode[] columnNodes = (from columnMapper in tableMapper.GetColumnMappers() where !columnNames.Contains(columnMapper.ColumnName) select columnMapper.ToColumnNode()).ToArray(); //若实体元数据解析器中所有属性Mapping的列都在当前Table中,直接退出 if (columnNodes.Length == 0) { return; } //获取TableHeader ITableHeader tableHeader = tableMapper.Header; //创建Alter Table Columns语句生成树 ICommandTree alterTableAddColumnsTree = commandTreeFactory.GetAlterTableAddColumnsTree(tableHeader.SchemaName, tableHeader.TableName, columnNodes); //生成并执行Alter Table Columns语句,为当前实体Mapping的Table添加为注册的列 dbHelper.ExecuteUpdate(alterTableAddColumnsTree.Compile()); }
public bool Equals(ITableHeader other) { if (GetType().Equals(other.GetType()) == false) { return(false); } var subClassOther = other as SubClassTableHeader; if (subClassOther.PropertyName != PropertyName || subClassOther.ClassName != ClassName) { return(false); } if (EqualHeaders(Headers, subClassOther.Headers) == false) { return(false); } return(true); }
internal TableRow(ITableHeader header, long index) { _header = header; _index = index; _cells = new TableCellBase[header.FieldsCount]; for (int i = 0; i < _cells.Length; i++) { switch (_header.Table.Type) { case TableType.ASCII: _cells[i] = new TableCellASCII(this, (FieldInfoBase)header[i]); break; case TableType.Binary: _cells[i] = new TableCellBinary(this, (FieldInfoBase)header[i]); break; default: Utils.CheckBool(false, new TableException("Invalid table type encountered")); break; } } }
private void AddHeaderCell(ITableHeader header, string text, Width width = null) { IText headerText; ITableCell cell = header.AddCell(); Color startColor = new Color(117, 117, 117); Color endColor = new Color(84, 84, 84); cell.Borders = bordersStyle; cell.Background = new Background(new LinearGradientBrush(startColor, endColor, 90)); cell.Alignment.Vertical = Alignment.Middle; if (width != null) { cell.Width = width; } headerText = cell.AddText(); headerText.Style.Font = headerFont; headerText.Style.Brush = Brushes.White; headerText.Alignment = TextAlignment.Center; headerText.AddContent(text); }
/// <summary> /// 添加表頭組件到集合方法 /// </summary> public void AddHeaders(ITableHeader header) => Headers.Add(header);
/// <summary> /// 重命名表 /// </summary> /// <param name="dbHelper">操作数据库的Helper</param> /// <param name="tableHeader">Table头信息</param> /// <param name="oldTableName">旧的表名</param> /// <returns>受影响的行数</returns> public int RenameTable(DbHelper dbHelper, ITableHeader tableHeader, string oldTableName) { return(dbHelper.ExecuteUpdate(this.GetRenameTableCommand(tableHeader, oldTableName))); }
/// <summary> /// 删除表 /// </summary> /// <param name="dbHelper">操作数据库的Helper</param> /// <param name="tableHeader">Table头信息</param> public int DropTable(DbHelper dbHelper, ITableHeader tableHeader) { return(dbHelper.ExecuteUpdate(this.GetDropTableCommand(tableHeader))); }
/// <summary> /// 判断当前table是否存在 /// </summary> /// <param name="dbHelper">操作数据库的Helper</param> /// <param name="tableHeader">Table基本信息</param> /// <returns>当前table是否存在</returns> public abstract bool IsExist(DbHelper dbHelper, ITableHeader tableHeader);
/// <summary> /// 获取当前Table下所有的列 /// </summary> /// <param name="dbHelper">操作数据库的Helper对象</param> /// <param name="tableHeader">Table基本信息</param> /// <returns>当前Table下所有的列</returns> protected abstract IEnumerable <string> GetColumns(DbHelper dbHelper, ITableHeader tableHeader);
public bool Equals(ITableHeader other) { return(GetType().Equals(other.GetType()) && (other as PropertyTableHeader).PropertyName == PropertyName); }