Update MiscTools.cs

- add GetBooleanValue method for getting bool from databases
- use universal time for db time
This commit is contained in:
BlueBlock
2023-03-23 16:22:38 -04:00
parent 3180f38a1d
commit 5f56477123

View File

@@ -8,12 +8,9 @@ using System.IO;
using System.Security;
using mRemoteNG.App;
using mRemoteNG.Messages;
using mRemoteNG.Properties;
using mRemoteNG.UI.Forms;
using MySql.Data.Types;
using mRemoteNG.Resources.Language;
using static System.String;
using System.Windows;
using System.Runtime.Versioning;
namespace mRemoteNG.Tools
@@ -65,6 +62,26 @@ namespace mRemoteNG.Tools
return Number;
}
public static bool GetBooleanValue(object dataObject)
{
Type type = dataObject.GetType();
if (type == typeof(bool))
{
return (bool)dataObject;
}
if (type == typeof(string))
{
return (string)dataObject == "1";
}
if (type == typeof(sbyte))
{
return (sbyte)dataObject == 1;
}
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, $"Conversion of object to boolean failed because the type, {type}, is not handled.");
return false;
}
public static string DBDate(DateTime Dt)
{
@@ -95,10 +112,10 @@ namespace mRemoteNG.Tools
switch (Properties.OptionsDBsPage.Default.SQLServerType)
{
case "mysql":
return new MySqlDateTime(DateTime.Now);
return new MySqlDateTime(DateTime.Now.ToUniversalTime());
case "mssql":
default:
return DateTime.Now;
return DateTime.Now.ToUniversalTime();
}
}
@@ -117,7 +134,7 @@ namespace mRemoteNG.Tools
var message = ex.Message;
if (ex.InnerException == null) return message;
var innerMessage = GetExceptionMessageRecursive(ex.InnerException, separator);
message = Join(separator, message, innerMessage);
message = String.Join(separator, message, innerMessage);
return message;
}