diff --git a/.cr/personal/FavoritesList/List.xml b/.cr/personal/FavoritesList/List.xml new file mode 100644 index 0000000000000000000000000000000000000000..a60e5ed6c75e5f1f16120fbd8c09278826b77993 --- /dev/null +++ b/.cr/personal/FavoritesList/List.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SmartSQL/SmartSQL.Framework/Exporter/SqlServerExporter.cs b/SmartSQL/SmartSQL.Framework/Exporter/SqlServerExporter.cs index 9446b54107d8b769c94aedabdc432b5ae95f8f1a..eaa6002a62d394700d2bfe7718d631388dfbd44e 100644 --- a/SmartSQL/SmartSQL.Framework/Exporter/SqlServerExporter.cs +++ b/SmartSQL/SmartSQL.Framework/Exporter/SqlServerExporter.cs @@ -143,7 +143,7 @@ namespace SmartSQL.Framework.Exporter } /// - /// 根据表名获取表信息 + /// 根据表名获取表信息(支持 schema.tableName 格式) /// /// /// @@ -151,6 +151,27 @@ namespace SmartSQL.Framework.Exporter { #region MyRegion Tables tables = new Tables(10); + string filterSchemaName = null; + string pureTableName = tableName; + + if (!string.IsNullOrEmpty(tableName) && tableName.Contains('.')) + { + var parts = tableName.Split('.'); + if (parts.Length == 2) + { + filterSchemaName = parts[0]; + pureTableName = parts[1]; + } + else + { + pureTableName = parts[parts.Length - 1]; + } + } + + string schemaFilter = filterSchemaName != null + ? $"AND s.name = '{filterSchemaName}'" + : ""; + string sqlCmd = $@"SELECT sy.[name], [object_id], CASE @@ -167,8 +188,9 @@ namespace SmartSQL.Framework.Exporter AND minor_id = 0 LEFT JOIN sys.schemas s ON s.schema_id = sy.schema_id WHERE sy.type = 'U' - AND sy.name = '{tableName}' + AND sy.name = '{pureTableName}' AND sy.name <> 'sysdiagrams' + {schemaFilter} ORDER BY sy.name ASC;"; SqlDataReader dr = SqlHelper.ExecuteReader(DbConnectString, CommandType.Text, sqlCmd); while (dr.Read()) @@ -387,8 +409,8 @@ namespace SmartSQL.Framework.Exporter { #region MyRegion var columns = new Columns(); - int objId = 0; - if (!int.TryParse(objectId, out objId)) + int parsedId = 0; + if (!int.TryParse(objectId, out parsedId)) { var tableInfo = GetTableByName(objectId); if (!tableInfo.Values.Any()) diff --git a/SmartSQL/SmartSQL/Models/ColumnDiffInfoModel.cs b/SmartSQL/SmartSQL/Models/ColumnDiffInfoModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..00a5b6d7e91491616d631da5e7630ed04039fd57 --- /dev/null +++ b/SmartSQL/SmartSQL/Models/ColumnDiffInfoModel.cs @@ -0,0 +1,76 @@ +using System.Windows.Media; + +namespace SmartSQL.Models +{ + public class ColumnDiffInfoModel : NotifyPropertyBase + { + public string SourceColumnName { get; set; } + public string SourceDataType { get; set; } + public string SourceLength { get; set; } + public string SourceNullable { get; set; } + public string SourceIsPrimaryKey { get; set; } + public string SourceIsIdentity { get; set; } + public string SourceDefaultValue { get; set; } + public string SourceComment { get; set; } + + public string TargetColumnName { get; set; } + public string TargetDataType { get; set; } + public string TargetLength { get; set; } + public string TargetNullable { get; set; } + public string TargetIsPrimaryKey { get; set; } + public string TargetIsIdentity { get; set; } + public string TargetDefaultValue { get; set; } + public string TargetComment { get; set; } + + public bool IsColumnExistsInSource { get; set; } + public bool IsColumnExistsInTarget { get; set; } + + public SolidColorBrush DiffForeground { get; set; } + public SolidColorBrush DiffBackground { get; set; } + + /// + /// 任意一项属性存在差异 + /// + public bool IsDifferent { get; set; } + + /// + /// 字段名是否有差异 + /// + public bool IsColumnNameDiff { get; set; } + + /// + /// 数据类型是否有差异 + /// + public bool IsDataTypeDiff { get; set; } + + /// + /// 长度是否有差异 + /// + public bool IsLengthDiff { get; set; } + + /// + /// 是否可空是否有差异 + /// + public bool IsNullableDiff { get; set; } + + /// + /// 是否主键是否有差异 + /// + public bool IsPrimaryKeyDiff { get; set; } + + /// + /// 是否自增是否有差异 + /// + public bool IsIdentityDiff { get; set; } + + /// + /// 默认值是否有差异 + /// + public bool IsDefaultValueDiff { get; set; } + + /// + /// 备注说明是否有差异 + /// + public bool IsCommentDiff { get; set; } + } +} diff --git a/SmartSQL/SmartSQL/Models/TableFieldDiffItemModel.cs b/SmartSQL/SmartSQL/Models/TableFieldDiffItemModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..81e0d2fac2331559714209955cb92d9c67c3a548 --- /dev/null +++ b/SmartSQL/SmartSQL/Models/TableFieldDiffItemModel.cs @@ -0,0 +1,60 @@ +using System.Windows.Media; + +namespace SmartSQL.Models +{ + /// + /// 批量表字段对比明细项(扁平展示:一行 = 一个差异属性) + /// + public class TableFieldDiffItemModel : NotifyPropertyBase + { + /// + /// 表名(含 schema,如 dbo.orders) + /// + public string TableName { get; set; } + + /// + /// 字段名 + /// + public string ColumnName { get; set; } + + /// + /// 差异类型描述(字段名/数据类型/长度/可空/主键/自增/默认值/备注) + /// + public string DiffType { get; set; } + + /// + /// 源表值 + /// + public string SourceValue { get; set; } + + /// + /// 目标表值 + /// + public string TargetValue { get; set; } + + /// + /// 差异行背景色(基于 DiffType 分类) + /// + public SolidColorBrush DiffBackground { get; set; } + + /// + /// 差异状态文本(仅源表存在 / 仅目标表存在 / 属性有差异) + /// + public string DiffStatus { get; set; } + + /// + /// 源表是否存在此字段 + /// + public bool IsSourceExists { get; set; } + + /// + /// 目标表是否存在此字段 + /// + public bool IsTargetExists { get; set; } + + /// + /// 以源表为基准生成的修复SQL语句(修改目标表使其与源表一致) + /// + public string SqlStatement { get; set; } + } +} diff --git a/SmartSQL/SmartSQL/SmartSQL.csproj b/SmartSQL/SmartSQL/SmartSQL.csproj index fae01263932048caaf9bfcad6f4575531a30e460..ee3a29ebdc7b5ed61181513cda9f5c8af554b5bd 100644 --- a/SmartSQL/SmartSQL/SmartSQL.csproj +++ b/SmartSQL/SmartSQL/SmartSQL.csproj @@ -1,4 +1,4 @@ - + @@ -184,6 +184,8 @@ + + @@ -437,6 +439,12 @@ SettingWindow.xaml + + TableFieldDiffWindow.xaml + + + BatchTableFieldDiffWindow.xaml + MSBuild:Compile Designer @@ -814,6 +822,14 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + diff --git a/SmartSQL/SmartSQL/UserControl/Main/UcMainDbCompare.xaml b/SmartSQL/SmartSQL/UserControl/Main/UcMainDbCompare.xaml index 84ca36f0ab7b629f4c42cd0987e3f98e2d0deac2..129810909ef3e5bbcd3d70689ca263b290b2c043 100644 --- a/SmartSQL/SmartSQL/UserControl/Main/UcMainDbCompare.xaml +++ b/SmartSQL/SmartSQL/UserControl/Main/UcMainDbCompare.xaml @@ -112,6 +112,16 @@ Cursor="Hand" FontSize="13" Style="{StaticResource ButtonPrimary}" /> +