Added SQL Read Only option

Avoid saving when SQL Read Only check box is checked
This commit is contained in:
Dekel Asaf
2017-12-10 21:59:57 +02:00
parent 384399c1c8
commit 94f66da84e
8 changed files with 92 additions and 13 deletions

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -653,5 +653,8 @@
<Setting Name="UseFilterSearch" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="SQLReadOnly" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@@ -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 {
}
}
/// <summary>
/// Looks up a localized string similar to Read Only:.
/// </summary>
internal static string strLabelReadOnly {
get {
return ResourceManager.GetString("strLabelReadOnly", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Released under the GNU General Public License (GPL).
/// </summary>

View File

@@ -2625,4 +2625,7 @@ This page will walk you through the process of upgrading your connections file o
<data name="TestConnection" xml:space="preserve">
<value>Test Connection</value>
</data>
<data name="strLabelReadOnly" xml:space="preserve">
<value>Read Only:</value>
</data>
</root>

View File

@@ -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;
}
}

View File

@@ -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)

View File

@@ -674,6 +674,9 @@
<setting name="UseFilterSearch" serializeAs="String">
<value>False</value>
</setting>
<setting name="SQLReadOnly" serializeAs="String">
<value>False</value>
</setting>
</mRemoteNG.Settings>
</userSettings>
<applicationSettings>