From ff74fc44c81f4e49145e153deccd9baa9f624c57 Mon Sep 17 00:00:00 2001 From: Alex Bochkov Date: Sun, 1 Dec 2019 13:06:34 -0800 Subject: [PATCH] WIP --- Addin.SSMS2018/Addin.SSMS2018.vbproj | 5 +- Addin.SSMS2018/My Project/AssemblyInfo.vb | 10 ++- .../My Project/Resources.Designer.vb | 10 +++ Addin.SSMS2018/My Project/Resources.resx | 24 +++++++ Addin.SSMS2018/Resources/sql-icon.png | Bin 0 -> 1215 bytes Addin.SSMS2018/SSMS2018AddinPackage.vsct | 2 +- Addin.SSMS2018/SettingForm.Designer.vb | 30 +++++--- Addin.SSMS2018/SettingForm.vb | 10 ++- Addin.SSMS2018/SettingManager.vb | 65 ++++++++++++++---- Addin.SSMS2018/ToolWindow1Control.xaml | 4 +- Addin.SSMS2018/ToolWindow1Control.xaml.vb | 53 +++++++------- Addin.SSMS2018/source.extension.vsixmanifest | 10 +-- 12 files changed, 161 insertions(+), 62 deletions(-) create mode 100644 Addin.SSMS2018/Resources/sql-icon.png diff --git a/Addin.SSMS2018/Addin.SSMS2018.vbproj b/Addin.SSMS2018/Addin.SSMS2018.vbproj index 8739b6d..f210fbb 100644 --- a/Addin.SSMS2018/Addin.SSMS2018.vbproj +++ b/Addin.SSMS2018/Addin.SSMS2018.vbproj @@ -191,7 +191,10 @@ - + + Always + + diff --git a/Addin.SSMS2018/My Project/AssemblyInfo.vb b/Addin.SSMS2018/My Project/AssemblyInfo.vb index 2258bf8..ba9a361 100644 --- a/Addin.SSMS2018/My Project/AssemblyInfo.vb +++ b/Addin.SSMS2018/My Project/AssemblyInfo.vb @@ -7,12 +7,16 @@ Imports System.Runtime.InteropServices ' set of attributes. Change these attribute values to modify the information ' associated with an assembly. - - + - + diff --git a/Addin.SSMS2018/My Project/Resources.Designer.vb b/Addin.SSMS2018/My Project/Resources.Designer.vb index 726ce9f..d0ce9fe 100644 --- a/Addin.SSMS2018/My Project/Resources.Designer.vb +++ b/Addin.SSMS2018/My Project/Resources.Designer.vb @@ -69,5 +69,15 @@ Namespace My.Resources Return CType(obj,System.Drawing.Icon) End Get End Property + + ''' + ''' Looks up a localized resource of type System.Drawing.Bitmap. + ''' + Friend ReadOnly Property sql_icon() As System.Drawing.Bitmap + Get + Dim obj As Object = ResourceManager.GetObject("sql_icon", resourceCulture) + Return CType(obj,System.Drawing.Bitmap) + End Get + End Property End Module End Namespace diff --git a/Addin.SSMS2018/My Project/Resources.resx b/Addin.SSMS2018/My Project/Resources.resx index f1df4fe..fe0fc4d 100644 --- a/Addin.SSMS2018/My Project/Resources.resx +++ b/Addin.SSMS2018/My Project/Resources.resx @@ -121,4 +121,28 @@ ..\Resources\sql-file-format.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + + iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAAALEAAACxAcYtSY0AAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwa + AAADsUlEQVRYR92XSUxTURSGjQuX7ti5djYxYjCKqCSKjKIhKGJAUQkRSR1CVDBoRQ2VKUqhzELBgtIq + UwqCGlJFIyqKQpShICKGwQGNEaW2/b3vlhZqb9tHqRsX3+Kd83L+7953+9rOAcAbnwws8M3CSnu4p8LH + LRnBHhlwYc2ZDrPIYms23LyzoCfAHqtEwMJE4GQVdAfK4ceaZ4RZZOGdiRBWGAujgKgRKHgEvS0JZpGF + owK32mxLWBSsMRsBWxJmF7aYrYA1CbMQWzhDgCVhEWQNZwn8LcEMY+GIQGI9W4DDKMEMY+GIgHs6EFMB + CORswkugYYaxcESAD8wwFv9WQCici70ZfgjLPGqNx0eU0pyENhhRRt/Gw30KJk1hCtwJneJyVDOWntNZ + EQi7shxh4l6Ei8lDmQHeF4H1Cbz57ZmI6GNdDIFwcTEdeDKTHE0Jf2RxwM3D/BCcohLvtmUyBX5RgYFc + 4KMBPWHknQzD/WUU7Wi+qUf7o3kY7TwOdG+2YPwN+Xhb1H0NO+Fxhilg2NLJ4U2t93Cg5KvZoRKUj9Ke + jgSXNLVie+5vetBWXNQir0ZqCqpuTMKS8zqoVPHTwieZfBQ2BX4OFSIob4KG7pd+w8GSMUr+3Ze0X6Z6 + apJyS9HSAYsIDU3kPJCQFPl1WsutLnBM4HVnFR0eXvQd/eoKfBq4RutGQgt/0P6DF3fwszcKAeIPdEhQ + 1lvnCHDPPpKs2LhKH0K84j0G+65jfOgqre3I1RiE+iMgVebTIe6p350jwDHUX46cxnZElo5hd+E4DU1T + dmFiuAA+Ej0CsrX0nrWpGriKftEhm9LGnCfwdVCKgb4bFNXzu1SAOw9c75DsM71OqlXD9ZLeNCSm+ImZ + QNINOXqfReBt6z7ourbwF+jrkcOXrJILmY6MHD6u39quNPWnv249079g/LU/0hRlZsM5BEUq/gLfyOrj + b75HtOwTJbZiCHUt98n2F9I+R2dXJUS1PQiUfERIthpLLxh2QiSvQcfjQwiRdCBQrKZsF/egvO6yXQEN + FRg0BPCGHEJucPOD09id0403T6INQUy8DQIebIEyKpBAXsUy7hXLk8oTQH0UP+LIvURg0D+DIbD3iisR + GKESM2GGX0a6jULECtoZAhzBwnnk63gPGSy0RltMpeJaXAuM3I+swqvQUibPdpWiZecUpRENWHl2wiJ8 + SoAH//kvIh54SeBKhmv/DmPBV2DZBUwww6xB/p67eImx2B7rUrFhdTJ87bFGiPl/AOoRilFYTVaKAAAA + AElFTkSuQmCC + + \ No newline at end of file diff --git a/Addin.SSMS2018/Resources/sql-icon.png b/Addin.SSMS2018/Resources/sql-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..8b6943a57cf711e2d093504a43434be209a5e751 GIT binary patch literal 1215 zcmV;w1VHpMeGZw}`Ge#D1 zYS=VJ!;7dHCIk(M62BNVAzK_Kew$%T5+Ej+C@RS!B8mb_1bmws5rr}~lvf*Iuie_N z+imZ?eyCek+OBu%=JV}5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ibiTO dojlApe*wHGdEJB?sFnZ#002ovPDHLkV1ikw8-4%) literal 0 HcmV?d00001 diff --git a/Addin.SSMS2018/SSMS2018AddinPackage.vsct b/Addin.SSMS2018/SSMS2018AddinPackage.vsct index 129894e..5629935 100644 --- a/Addin.SSMS2018/SSMS2018AddinPackage.vsct +++ b/Addin.SSMS2018/SSMS2018AddinPackage.vsct @@ -56,7 +56,7 @@ - SSMS2018 Addin (C) Alex Bochkov + DBA Helper © Alex Bochkov diff --git a/Addin.SSMS2018/SettingForm.Designer.vb b/Addin.SSMS2018/SettingForm.Designer.vb index 19f66b4..e99803d 100644 --- a/Addin.SSMS2018/SettingForm.Designer.vb +++ b/Addin.SSMS2018/SettingForm.Designer.vb @@ -27,11 +27,12 @@ Partial Class SettingForm Me.Label1 = New System.Windows.Forms.Label() Me.Label2 = New System.Windows.Forms.Label() Me.TextBoxScriptFolder = New System.Windows.Forms.TextBox() + Me.ComboBoxParserVersion = New System.Windows.Forms.ComboBox() Me.SuspendLayout() ' 'Button1 ' - Me.Button1.Location = New System.Drawing.Point(178, 86) + Me.Button1.Location = New System.Drawing.Point(179, 63) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(141, 34) Me.Button1.TabIndex = 0 @@ -40,7 +41,7 @@ Partial Class SettingForm ' 'Button2 ' - Me.Button2.Location = New System.Drawing.Point(335, 85) + Me.Button2.Location = New System.Drawing.Point(326, 62) Me.Button2.Name = "Button2" Me.Button2.Size = New System.Drawing.Size(126, 35) Me.Button2.TabIndex = 1 @@ -50,7 +51,7 @@ Partial Class SettingForm 'Label1 ' Me.Label1.AutoSize = True - Me.Label1.Location = New System.Drawing.Point(20, 33) + Me.Label1.Location = New System.Drawing.Point(11, 10) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(119, 13) Me.Label1.TabIndex = 2 @@ -59,24 +60,34 @@ Partial Class SettingForm 'Label2 ' Me.Label2.AutoSize = True - Me.Label2.Location = New System.Drawing.Point(19, 56) + Me.Label2.Location = New System.Drawing.Point(10, 33) Me.Label2.Name = "Label2" - Me.Label2.Size = New System.Drawing.Size(39, 13) + Me.Label2.Size = New System.Drawing.Size(106, 13) Me.Label2.TabIndex = 3 - Me.Label2.Text = "Label2" + Me.Label2.Text = "TSQL Parser Version" ' 'TextBoxScriptFolder ' - Me.TextBoxScriptFolder.Location = New System.Drawing.Point(145, 30) + Me.TextBoxScriptFolder.Location = New System.Drawing.Point(136, 7) Me.TextBoxScriptFolder.Name = "TextBoxScriptFolder" Me.TextBoxScriptFolder.Size = New System.Drawing.Size(316, 20) Me.TextBoxScriptFolder.TabIndex = 4 ' + 'ComboBoxParserVersion + ' + Me.ComboBoxParserVersion.FormattingEnabled = True + Me.ComboBoxParserVersion.Items.AddRange(New Object() {"SQL Server 2008", "SQL Server 2012", "SQL Server 2014", "SQL Server 2016", "SQL Server 2017", "SQL Server 2019"}) + Me.ComboBoxParserVersion.Location = New System.Drawing.Point(136, 30) + Me.ComboBoxParserVersion.Name = "ComboBoxParserVersion" + Me.ComboBoxParserVersion.Size = New System.Drawing.Size(316, 21) + Me.ComboBoxParserVersion.TabIndex = 5 + ' 'SettingForm ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font - Me.ClientSize = New System.Drawing.Size(475, 132) + Me.ClientSize = New System.Drawing.Size(460, 105) + Me.Controls.Add(Me.ComboBoxParserVersion) Me.Controls.Add(Me.TextBoxScriptFolder) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label1) @@ -84,7 +95,7 @@ Partial Class SettingForm Me.Controls.Add(Me.Button1) Me.Name = "SettingForm" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent - Me.Text = "SettingForm" + Me.Text = "DBA Helper Setting" Me.ResumeLayout(False) Me.PerformLayout() @@ -95,4 +106,5 @@ Partial Class SettingForm Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents TextBoxScriptFolder As System.Windows.Forms.TextBox + Friend WithEvents ComboBoxParserVersion As System.Windows.Forms.ComboBox End Class diff --git a/Addin.SSMS2018/SettingForm.vb b/Addin.SSMS2018/SettingForm.vb index a85781a..946808b 100644 --- a/Addin.SSMS2018/SettingForm.vb +++ b/Addin.SSMS2018/SettingForm.vb @@ -5,6 +5,7 @@ InitializeComponent() TextBoxScriptFolder.Text = SettingManager.GetTemplatesFolder() + ComboBoxParserVersion.SelectedItem = SettingManager.GetSQLParserVersion() End Sub @@ -16,9 +17,16 @@ Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click - SettingManager.SaveTemplatesFolder(TextBoxScriptFolder.Text) + If Not String.IsNullOrEmpty(TextBoxScriptFolder.Text) Then + SettingManager.SaveTemplatesFolder(TextBoxScriptFolder.Text) + End If + + If Not String.IsNullOrEmpty(ComboBoxParserVersion.SelectedItem) Then + SettingManager.SaveSQLParserVersion(ComboBoxParserVersion.SelectedItem) + End If Close() End Sub + End Class \ No newline at end of file diff --git a/Addin.SSMS2018/SettingManager.vb b/Addin.SSMS2018/SettingManager.vb index 7422e3c..5f9162f 100644 --- a/Addin.SSMS2018/SettingManager.vb +++ b/Addin.SSMS2018/SettingManager.vb @@ -15,38 +15,29 @@ Namespace SettingManager End Function + Private Function GetRegisterValue(Parameter As String) As String - Function GetTemplatesFolder() As String - - Dim Folder As String = "" + Dim RegisterValue As String = "" Try Dim RootKey = GetRoot() - Folder = RootKey.GetValue("ScriptTemplatesFolder").ToString + RegisterValue = RootKey.GetValue(Parameter).ToString Catch ex As Exception End Try - If String.IsNullOrEmpty(Folder) Then - - Folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "dba-helper-scripts") - - End If - - - Return Folder + Return RegisterValue End Function - - Function SaveTemplatesFolder(Folder As String) As Boolean + Private Function SaveRegisterValue(ParameterName As String, ParameterValue As String) As Boolean Try Dim RootKey = GetRoot() - RootKey.SetValue("ScriptTemplatesFolder", Folder) + RootKey.SetValue(ParameterName, ParameterValue) RootKey.Close() Catch ex As Exception @@ -57,6 +48,50 @@ Namespace SettingManager End Function + '*********************************************************************************** + + Function GetTemplatesFolder() As String + + Dim Folder As String = GetRegisterValue("ScriptTemplatesFolder") + + If String.IsNullOrEmpty(Folder) Then + + Folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "dba-helper-scripts") + + End If + + Return Folder + + End Function + + Function GetSQLParserVersion() As String + + Dim TSQLParserVersion As String = GetRegisterValue("TSQLParserVersion") + + If String.IsNullOrEmpty(TSQLParserVersion) Then + + TSQLParserVersion = "SQL Server 2017" 'default value + + End If + + Return TSQLParserVersion + + End Function + + + + Function SaveTemplatesFolder(Folder As String) As Boolean + + Return SaveRegisterValue("ScriptTemplatesFolder", Folder) + + End Function + + Function SaveSQLParserVersion(TSQLParserVersion As String) As Boolean + + Return SaveRegisterValue("TSQLParserVersion", TSQLParserVersion) + + End Function + 'Function GetExcelExportFolder() As String ' Dim Folder As String = "" diff --git a/Addin.SSMS2018/ToolWindow1Control.xaml b/Addin.SSMS2018/ToolWindow1Control.xaml index bffd57a..b6b3b0d 100644 --- a/Addin.SSMS2018/ToolWindow1Control.xaml +++ b/Addin.SSMS2018/ToolWindow1Control.xaml @@ -17,9 +17,9 @@ - + - + diff --git a/Addin.SSMS2018/ToolWindow1Control.xaml.vb b/Addin.SSMS2018/ToolWindow1Control.xaml.vb index e580dda..8544f9d 100644 --- a/Addin.SSMS2018/ToolWindow1Control.xaml.vb +++ b/Addin.SSMS2018/ToolWindow1Control.xaml.vb @@ -103,7 +103,7 @@ Partial Public Class ToolWindow1Control AddFiles() - System.Windows.MessageBox.Show("Templates have been refreshed!") + System.Windows.MessageBox.Show("The template list has been refreshed!") End Sub @@ -113,22 +113,30 @@ Partial Public Class ToolWindow1Control Dim FileName As String = sender.ToolTip - Dim FileContent = My.Computer.FileSystem.ReadAllText(FileName) + If My.Computer.FileSystem.FileExists(FileName) Then - Dim dte As DTE = TryCast(Package.GetGlobalService(GetType(DTE)), DTE) + Dim FileContent = My.Computer.FileSystem.ReadAllText(FileName) - Dim selection As TextSelection = DirectCast(dte.ActiveDocument.Selection, TextSelection) + Dim dte As DTE = TryCast(Package.GetGlobalService(GetType(DTE)), DTE) - selection.Delete() + If Not dte.ActiveDocument Is Nothing Then - selection.Insert(FileContent.Trim) + Dim selection As TextSelection = DirectCast(dte.ActiveDocument.Selection, TextSelection) + + selection.Delete() + + selection.Insert(FileContent.Trim) + + End If + Else + System.Windows.MessageBox.Show("File " + FileName + " doesn't exist!") + End If Catch ex As Exception System.Windows.MessageBox.Show(ex.Message) End Try - End Sub @@ -146,11 +154,6 @@ Partial Public Class ToolWindow1Control End Sub - Private Sub ComboBox_SelectionChanged(sender As Object, e As System.Windows.Controls.SelectionChangedEventArgs) - - End Sub - - Private Sub FormatSelection() @@ -169,18 +172,18 @@ Partial Public Class ToolWindow1Control Dim SqlParser As TSqlParser = Nothing - Dim TargetVersion As String = "2019" 'SettingManager.GetTSQLFormatVersion() - If TargetVersion = "2008" Then + Dim TargetVersion As String = SettingManager.GetSQLParserVersion() + If TargetVersion = "SQL Server 2008" Then SqlParser = New TSql100Parser(False) - ElseIf TargetVersion = "2012" Then + ElseIf TargetVersion = "SQL Server 2012" Then SqlParser = New TSql110Parser(False) - ElseIf TargetVersion = "2014" Then + ElseIf TargetVersion = "SQL Server 2014" Then SqlParser = New TSql120Parser(False) - ElseIf TargetVersion = "2016" Then + ElseIf TargetVersion = "SQL Server 2016" Then SqlParser = New TSql130Parser(False) - ElseIf TargetVersion = "2017" Then + ElseIf TargetVersion = "SQL Server 2017" Then SqlParser = New TSql140Parser(False) - ElseIf TargetVersion = "2019" Then + ElseIf TargetVersion = "SQL Server 2019" Then SqlParser = New TSql150Parser(False) Else SqlParser = New TSql140Parser(False) @@ -205,17 +208,17 @@ Partial Public Class ToolWindow1Control Dim StrAdd2 = "" Dim Gen As SqlScriptGenerator = Nothing - If TargetVersion = "2008" Then + If TargetVersion = "SQL Server 2008" Then Gen = New Sql100ScriptGenerator - ElseIf TargetVersion = "2012" Then + ElseIf TargetVersion = "SQL Server 2012" Then Gen = New Sql110ScriptGenerator - ElseIf TargetVersion = "2014" Then + ElseIf TargetVersion = "SQL Server 2014" Then Gen = New Sql120ScriptGenerator - ElseIf TargetVersion = "2016" Then + ElseIf TargetVersion = "SQL Server 2016" Then Gen = New Sql130ScriptGenerator - ElseIf TargetVersion = "2017" Then + ElseIf TargetVersion = "SQL Server 2017" Then Gen = New Sql140ScriptGenerator - ElseIf TargetVersion = "2019" Then + ElseIf TargetVersion = "SQL Server 2019" Then Gen = New Sql150ScriptGenerator Else Gen = New Sql140ScriptGenerator diff --git a/Addin.SSMS2018/source.extension.vsixmanifest b/Addin.SSMS2018/source.extension.vsixmanifest index 01c4a9b..fc1d8f2 100644 --- a/Addin.SSMS2018/source.extension.vsixmanifest +++ b/Addin.SSMS2018/source.extension.vsixmanifest @@ -1,9 +1,9 @@  - - SSMS2018Addin - Empty VSIX Project. + + DBA-Helper.SSMS2018 + SQL Server Management Studio 2018 Productivity ToolProducti @@ -17,6 +17,6 @@ - - + +