From 94f66da84ee8044a7c6653d8b613f456c0bd424f Mon Sep 17 00:00:00 2001 From: Dekel Asaf Date: Sun, 10 Dec 2017 21:59:57 +0200 Subject: [PATCH] Added SQL Read Only option Avoid saving when SQL Read Only check box is checked --- .../Config/Connections/SqlConnectionsSaver.cs | 13 ++++++++ mRemoteV1/Properties/Settings.Designer.cs | 14 ++++++++- mRemoteV1/Properties/Settings.settings | 3 ++ .../Resources/Language/Language.Designer.cs | 11 ++++++- mRemoteV1/Resources/Language/Language.resx | 3 ++ .../OptionsPages/SqlServerPage.Designer.cs | 30 +++++++++++++++++-- .../UI/Forms/OptionsPages/SqlServerPage.cs | 28 +++++++++++------ mRemoteV1/app.config | 3 ++ 8 files changed, 92 insertions(+), 13 deletions(-) diff --git a/mRemoteV1/Config/Connections/SqlConnectionsSaver.cs b/mRemoteV1/Config/Connections/SqlConnectionsSaver.cs index 9ac227911..9997efa5f 100644 --- a/mRemoteV1/Config/Connections/SqlConnectionsSaver.cs +++ b/mRemoteV1/Config/Connections/SqlConnectionsSaver.cs @@ -33,6 +33,13 @@ namespace mRemoteNG.Config.Connections public void Save(ConnectionTreeModel connectionTreeModel) { + if (SqlUserIsReadOnly()) + { + Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, "Trying to update but the SQL read only checkbox is checked, aborting!"); + return; + } + + using (var sqlConnector = DatabaseConnectorFactory.SqlDatabaseConnectorFromSettings()) { sqlConnector.Connect(); @@ -109,5 +116,11 @@ namespace mRemoteNG.Config.Connections sqlQuery = new SqlCommand("INSERT INTO tblUpdate (LastUpdate) VALUES(\'" + MiscTools.DBDate(DateTime.Now) + "\')", sqlDatabaseConnector.SqlConnection); sqlQuery.ExecuteNonQuery(); } + + private bool SqlUserIsReadOnly() + { + return mRemoteNG.Settings.Default.SQLReadOnly; + + } } } diff --git a/mRemoteV1/Properties/Settings.Designer.cs b/mRemoteV1/Properties/Settings.Designer.cs index 3a643d334..fde72dc2b 100644 --- a/mRemoteV1/Properties/Settings.Designer.cs +++ b/mRemoteV1/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace mRemoteNG { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.3.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -2626,5 +2626,17 @@ namespace mRemoteNG { this["UseFilterSearch"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool SQLReadOnly { + get { + return ((bool)(this["SQLReadOnly"])); + } + set { + this["SQLReadOnly"] = value; + } + } } } diff --git a/mRemoteV1/Properties/Settings.settings b/mRemoteV1/Properties/Settings.settings index 89793ea1e..af2cc9ce4 100644 --- a/mRemoteV1/Properties/Settings.settings +++ b/mRemoteV1/Properties/Settings.settings @@ -653,5 +653,8 @@ False + + False + \ No newline at end of file diff --git a/mRemoteV1/Resources/Language/Language.Designer.cs b/mRemoteV1/Resources/Language/Language.Designer.cs index 932dd31b9..728fa6e10 100644 --- a/mRemoteV1/Resources/Language/Language.Designer.cs +++ b/mRemoteV1/Resources/Language/Language.Designer.cs @@ -19,7 +19,7 @@ namespace mRemoteNG { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Language { @@ -2894,6 +2894,15 @@ namespace mRemoteNG { } } + /// + /// Looks up a localized string similar to Read Only:. + /// + internal static string strLabelReadOnly { + get { + return ResourceManager.GetString("strLabelReadOnly", resourceCulture); + } + } + /// /// Looks up a localized string similar to Released under the GNU General Public License (GPL). /// diff --git a/mRemoteV1/Resources/Language/Language.resx b/mRemoteV1/Resources/Language/Language.resx index 234c26051..25772b1e0 100644 --- a/mRemoteV1/Resources/Language/Language.resx +++ b/mRemoteV1/Resources/Language/Language.resx @@ -2625,4 +2625,7 @@ This page will walk you through the process of upgrading your connections file o Test Connection + + Read Only: + \ No newline at end of file diff --git a/mRemoteV1/UI/Forms/OptionsPages/SqlServerPage.Designer.cs b/mRemoteV1/UI/Forms/OptionsPages/SqlServerPage.Designer.cs index 8eae85b87..21348a51a 100644 --- a/mRemoteV1/UI/Forms/OptionsPages/SqlServerPage.Designer.cs +++ b/mRemoteV1/UI/Forms/OptionsPages/SqlServerPage.Designer.cs @@ -42,6 +42,8 @@ namespace mRemoteNG.UI.Forms.OptionsPages this.btnTestConnection = new mRemoteNG.UI.Controls.Base.NGButton(); this.imgConnectionStatus = new System.Windows.Forms.PictureBox(); this.lblTestConnectionResults = new mRemoteNG.UI.Controls.Base.NGLabel(); + this.chkSQLReadOnly = new mRemoteNG.UI.Controls.Base.NGCheckBox(); + this.lblSQLReadOnly = new mRemoteNG.UI.Controls.Base.NGLabel(); ((System.ComponentModel.ISupportInitialize)(this.imgConnectionStatus)).BeginInit(); this.SuspendLayout(); // @@ -166,7 +168,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages // this.btnTestConnection._mice = mRemoteNG.UI.Controls.Base.NGButton.MouseState.HOVER; this.btnTestConnection.Enabled = false; - this.btnTestConnection.Location = new System.Drawing.Point(140, 208); + this.btnTestConnection.Location = new System.Drawing.Point(140, 228); this.btnTestConnection.Name = "btnTestConnection"; this.btnTestConnection.Size = new System.Drawing.Size(153, 23); this.btnTestConnection.TabIndex = 11; @@ -177,7 +179,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages // imgConnectionStatus // this.imgConnectionStatus.Image = global::mRemoteNG.Resources.Help; - this.imgConnectionStatus.Location = new System.Drawing.Point(299, 212); + this.imgConnectionStatus.Location = new System.Drawing.Point(299, 232); this.imgConnectionStatus.Name = "imgConnectionStatus"; this.imgConnectionStatus.Size = new System.Drawing.Size(16, 16); this.imgConnectionStatus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; @@ -192,10 +194,32 @@ namespace mRemoteNG.UI.Forms.OptionsPages this.lblTestConnectionResults.Size = new System.Drawing.Size(0, 13); this.lblTestConnectionResults.TabIndex = 13; // + // chkSQLReadOnly + // + this.chkSQLReadOnly._mice = mRemoteNG.UI.Controls.Base.NGCheckBox.MouseState.HOVER; + this.chkSQLReadOnly.AutoSize = true; + this.chkSQLReadOnly.Location = new System.Drawing.Point(140, 205); + this.chkSQLReadOnly.Name = "chkSQLReadOnly"; + this.chkSQLReadOnly.Size = new System.Drawing.Size(15, 14); + this.chkSQLReadOnly.TabIndex = 14; + this.chkSQLReadOnly.UseVisualStyleBackColor = true; + // + // lblSQLReadOnly + // + this.lblSQLReadOnly.Enabled = false; + this.lblSQLReadOnly.Location = new System.Drawing.Point(23, 205); + this.lblSQLReadOnly.Name = "lblSQLReadOnly"; + this.lblSQLReadOnly.Size = new System.Drawing.Size(111, 13); + this.lblSQLReadOnly.TabIndex = 15; + this.lblSQLReadOnly.Text = "Read Only:"; + this.lblSQLReadOnly.TextAlign = System.Drawing.ContentAlignment.TopRight; + // // SqlServerPage // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.lblSQLReadOnly); + this.Controls.Add(this.chkSQLReadOnly); this.Controls.Add(this.lblTestConnectionResults); this.Controls.Add(this.imgConnectionStatus); this.Controls.Add(this.btnTestConnection); @@ -233,5 +257,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages private System.Windows.Forms.PictureBox imgConnectionStatus; private System.ComponentModel.IContainer components; private Controls.Base.NGLabel lblTestConnectionResults; + private Controls.Base.NGCheckBox chkSQLReadOnly; + internal Controls.Base.NGLabel lblSQLReadOnly; } } diff --git a/mRemoteV1/UI/Forms/OptionsPages/SqlServerPage.cs b/mRemoteV1/UI/Forms/OptionsPages/SqlServerPage.cs index 80cd67003..3f708f38f 100644 --- a/mRemoteV1/UI/Forms/OptionsPages/SqlServerPage.cs +++ b/mRemoteV1/UI/Forms/OptionsPages/SqlServerPage.cs @@ -36,6 +36,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages lblSQLDatabaseName.Text = Language.strLabelSQLServerDatabaseName; lblSQLUsername.Text = Language.strLabelUsername; lblSQLPassword.Text = Language.strLabelPassword; + lblSQLReadOnly.Text = Language.strLabelReadOnly; btnTestConnection.Text = Language.TestConnection; } @@ -49,6 +50,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages txtSQLUsername.Text = Settings.Default.SQLUser; var cryptographyProvider = new LegacyRijndaelCryptographyProvider(); txtSQLPassword.Text = cryptographyProvider.Decrypt(Settings.Default.SQLPass, Runtime.EncryptionKey); + chkSQLReadOnly.Checked = Settings.Default.SQLReadOnly; } public override void SaveSettings() @@ -62,6 +64,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages Settings.Default.SQLUser = txtSQLUsername.Text; var cryptographyProvider = new LegacyRijndaelCryptographyProvider(); Settings.Default.SQLPass = cryptographyProvider.Encrypt(txtSQLPassword.Text, Runtime.EncryptionKey); + Settings.Default.SQLReadOnly = chkSQLReadOnly.Checked; if (Settings.Default.UseSQLServer) ReinitializeSqlUpdater(); @@ -87,15 +90,22 @@ namespace mRemoteNG.UI.Forms.OptionsPages private void chkUseSQLServer_CheckedChanged(object sender, EventArgs e) { - lblSQLServer.Enabled = chkUseSQLServer.Checked; - lblSQLDatabaseName.Enabled = chkUseSQLServer.Checked; - lblSQLUsername.Enabled = chkUseSQLServer.Checked; - lblSQLPassword.Enabled = chkUseSQLServer.Checked; - txtSQLServer.Enabled = chkUseSQLServer.Checked; - txtSQLDatabaseName.Enabled = chkUseSQLServer.Checked; - txtSQLUsername.Enabled = chkUseSQLServer.Checked; - txtSQLPassword.Enabled = chkUseSQLServer.Checked; - btnTestConnection.Enabled = chkUseSQLServer.Checked; + toggleSQLPageControls(chkUseSQLServer.Checked); + } + + private void toggleSQLPageControls(bool useSQLServer) + { + lblSQLServer.Enabled = useSQLServer; + lblSQLDatabaseName.Enabled = useSQLServer; + lblSQLUsername.Enabled = useSQLServer; + lblSQLPassword.Enabled = useSQLServer; + lblSQLReadOnly.Enabled = useSQLServer; + txtSQLServer.Enabled = useSQLServer; + txtSQLDatabaseName.Enabled = useSQLServer; + txtSQLUsername.Enabled = useSQLServer; + txtSQLPassword.Enabled = useSQLServer; + chkSQLReadOnly.Enabled = useSQLServer; + btnTestConnection.Enabled = useSQLServer; } private async void btnTestConnection_Click(object sender, EventArgs e) diff --git a/mRemoteV1/app.config b/mRemoteV1/app.config index 36baeece9..a7b2d33d6 100644 --- a/mRemoteV1/app.config +++ b/mRemoteV1/app.config @@ -674,6 +674,9 @@ False + + False +