diff --git a/FunGame.Core/Api/Data/SQLHelper.cs b/FunGame.Core/Api/Data/SQLHelper.cs index b10834c..c920d67 100644 --- a/FunGame.Core/Api/Data/SQLHelper.cs +++ b/FunGame.Core/Api/Data/SQLHelper.cs @@ -1,30 +1,39 @@ -using Milimoe.FunGame.Core.Interface.Base; -using Milimoe.FunGame.Core.Library.Common.Network; +using System.Data; +using Milimoe.FunGame.Core.Interface.Base; using Milimoe.FunGame.Core.Library.Constant; +using Milimoe.FunGame.Core.Library.Server; namespace Milimoe.FunGame.Core.Api.Data { /// - /// 需要在Server中继承此类实现。 - /// Milimoe.FunGame.Core.Service.SQLManager也是 + /// 需要在Server中继承此类实现 /// public abstract class SQLHelper : ISQLHelper { - public string Script { get; set; } = ""; - - public EntityType EntityType { get; } - - public object Entity { get; } = General.EntityInstance; - - public SQLResult Result { get; } - + public abstract string Script { get; set; } + public abstract CommandType CommandType { get; set; } + public abstract SQLResult Result { get; } public abstract SQLServerInfo ServerInfo { get; } + public abstract int UpdateRows { get; } + public abstract DataSet DataSet { get; } - public int UpdateRows { get; } + /// + /// 执行一个命令 + /// + /// 执行结果 + /// 影响的行数 + public abstract int Execute(out SQLResult Result); - public virtual SQLResult Execute() - { - return SQLResult.NotFound; - } + /// + /// 查询DataSet + /// + /// 执行结果 + /// 结果集 + public abstract DataSet ExecuteDataSet(out SQLResult Result); + + /// + /// 关闭连接 + /// + public abstract void Close(); } } diff --git a/FunGame.Core/Api/Utility/General.cs b/FunGame.Core/Api/Utility/General.cs index 3001045..56dedb9 100644 --- a/FunGame.Core/Api/Utility/General.cs +++ b/FunGame.Core/Api/Utility/General.cs @@ -1,8 +1,8 @@ -using Milimoe.FunGame.Core.Library.Constant; -using System.Net.NetworkInformation; +using System.Net.NetworkInformation; using System.Security.Cryptography; using System.Text.Json; using System.Text.RegularExpressions; +using Milimoe.FunGame.Core.Library.Constant; // 通用工具类,客户端和服务器端都可以直接调用的工具方法都可以写在这里 namespace Milimoe.FunGame.Core.Api.Utility diff --git a/FunGame.Core/Entity/User/User.cs b/FunGame.Core/Entity/User/User.cs index 4cf8e0f..2e25667 100644 --- a/FunGame.Core/Entity/User/User.cs +++ b/FunGame.Core/Entity/User/User.cs @@ -1,8 +1,10 @@ +using Milimoe.FunGame.Core.Interface.Entity; + namespace Milimoe.FunGame.Core.Entity { - public class User + public class User : BaseEntity { - public int Id { get; set; } + public new long Id { get; set; } public string Username { get; set; } = ""; public string Password { get; set; } = ""; public DateTime RegTime { get; set; } @@ -35,5 +37,17 @@ namespace Milimoe.FunGame.Core.Entity Username = username; Password = password; } + + public override bool Equals(IBaseEntity? other) + { + if (other == null) return false; + if (((User)other).Id == Id) return true; + return false; + } + + public override IEnumerator GetEnumerator() + { + return GetEnumerator(); + } } } diff --git a/FunGame.Core/Interface/Base/ISQLHelper.cs b/FunGame.Core/Interface/Base/ISQLHelper.cs index 5ca08c6..0227d51 100644 --- a/FunGame.Core/Interface/Base/ISQLHelper.cs +++ b/FunGame.Core/Interface/Base/ISQLHelper.cs @@ -1,15 +1,16 @@ -using Milimoe.FunGame.Core.Library.Common.Network; -using Milimoe.FunGame.Core.Library.Constant; +using Milimoe.FunGame.Core.Library.Constant; +using Milimoe.FunGame.Core.Library.Server; +using System.Data; namespace Milimoe.FunGame.Core.Interface.Base { public interface ISQLHelper { public string Script { get; set; } - public EntityType EntityType { get; } - public object Entity { get; } + public CommandType CommandType { get; set; } public SQLResult Result { get; } - int UpdateRows { get; } public SQLServerInfo ServerInfo { get; } + public int UpdateRows { get; } + public DataSet DataSet { get; } } } diff --git a/FunGame.Core/Library/Constant/General.cs b/FunGame.Core/Library/Constant/General.cs index e21f7ad..0ad0f06 100644 --- a/FunGame.Core/Library/Constant/General.cs +++ b/FunGame.Core/Library/Constant/General.cs @@ -1,5 +1,5 @@ -using Milimoe.FunGame.Core.Entity; -using System.Text; +using System.Text; +using Milimoe.FunGame.Core.Entity; namespace Milimoe.FunGame.Core.Library.Constant { diff --git a/FunGame.Core/Library/Constant/SQLConstant.cs b/FunGame.Core/Library/Constant/SQLConstant.cs new file mode 100644 index 0000000..056e691 --- /dev/null +++ b/FunGame.Core/Library/Constant/SQLConstant.cs @@ -0,0 +1,44 @@ +namespace Milimoe.FunGame.Core.Library.Constant +{ + public class SQLConstant + { + /** + * Commands + */ + public const string Command_Select = "Select"; + public const string Command_Update = "Update"; + public const string Command_Delete = "Delete"; + public const string Command_Insert = "Insert"; + public const string Command_Set = "Set"; + public const string Command_Where = "Where"; + public const string Command_From = "From"; + public const string Command_All = "*"; + public const string Command_Into = "Into"; + public const string Command_Values = "Values"; + public const string Command_And = "And"; + public const string Command_Or = "Or"; + + /** + * Tables + */ + public const string Table_Users = "Users"; + public const string Table_ServerLoginLogs = "ServerLoginLogs"; + + /** + * Select + */ + public const string Select_Users = $"{Command_Select} {Command_All} {Command_From} {Table_Users}"; + + /** + * Update + */ + + /** + * Insert + */ + public static string Insert_ServerLoginLogs(string ServerName, string ServerKey) + { + return $"{Command_Insert} {Command_Into} {Table_ServerLoginLogs} (ServerName, ServerKey, LoginTime) {Command_Values} ('{ServerName}', '{ServerKey}', '{DateTime.Now}')"; + } + } +} diff --git a/FunGame.Core/Library/Exception/Exception.cs b/FunGame.Core/Library/Exception/Exception.cs index 9a3b751..0ea8df1 100644 --- a/FunGame.Core/Library/Exception/Exception.cs +++ b/FunGame.Core/Library/Exception/Exception.cs @@ -104,4 +104,9 @@ { public override string Message => "用户未登录 (#10021)"; } + + public class SQLQueryException : Exception + { + public override string Message => "执行SQL查询时遇到错误 (#10022)"; + } } diff --git a/FunGame.Core/Library/Common/Network/SQLConnection.cs b/FunGame.Core/Library/Server/SQLServerInfo.cs similarity index 75% rename from FunGame.Core/Library/Common/Network/SQLConnection.cs rename to FunGame.Core/Library/Server/SQLServerInfo.cs index d976617..8578dfe 100644 --- a/FunGame.Core/Library/Common/Network/SQLConnection.cs +++ b/FunGame.Core/Library/Server/SQLServerInfo.cs @@ -1,10 +1,11 @@ -namespace Milimoe.FunGame.Core.Library.Common.Network +namespace Milimoe.FunGame.Core.Library.Server { public class SQLServerInfo { public string SQLServerName { get; } = ""; public string SQLServerIP { get; } = ""; public string SQLServerPort { get; } = ""; + public string SQLServerDataBase { get; } = ""; public string SQLServerUser { get; } = ""; public string SQLServerPassword { get; } = ""; @@ -13,13 +14,14 @@ SQLServerName = builder.SQLServerName; SQLServerIP = builder.SQLServerIP; SQLServerPort = builder.SQLServerPort; + SQLServerDataBase = builder.SQLServerDataBase; SQLServerUser = builder.SQLServerUser; SQLServerPassword = builder.SQLServerPassword; } - public static SQLServerInfo Create(string name = "", string ip = "", string port = "", string user = "", string password = "") + public static SQLServerInfo Create(string name = "", string ip = "", string port = "", string database = "", string user = "", string password = "") { - return new SQLServerInfo(new InfoBuilder(name, ip, port, user, password)); + return new SQLServerInfo(new InfoBuilder(name, ip, port, database, user, password)); } internal class InfoBuilder @@ -27,14 +29,16 @@ internal string SQLServerName { get; } = ""; internal string SQLServerIP { get; } = ""; internal string SQLServerPort { get; } = ""; + internal string SQLServerDataBase { get; } = ""; internal string SQLServerUser { get; } = ""; internal string SQLServerPassword { get; } = ""; - internal InfoBuilder(string name, string ip, string port, string user, string password) + internal InfoBuilder(string name, string ip, string port, string database, string user, string password) { SQLServerName = name; SQLServerIP = ip; SQLServerPort = port; + SQLServerDataBase = database; SQLServerUser = user; SQLServerPassword = password; } diff --git a/FunGame.Core/Service/SQLManager.cs b/FunGame.Core/Service/SQLManager.cs deleted file mode 100644 index 048642e..0000000 --- a/FunGame.Core/Service/SQLManager.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Data; -using System.Text; -using Milimoe.FunGame.Core.Api.Data; -using Milimoe.FunGame.Core.Library.Constant; - -namespace Milimoe.FunGame.Core.Service -{ - /// - /// 需要在Server中继承此类实现 - /// - public abstract class SQLManager - { - public SQLHelper? SQLHelper { get; } - - public abstract int Add(StringBuilder sql, ref SQLResult result); - - public abstract int Add(string sql, ref SQLResult result); - - public abstract SQLResult Execute(); - - public abstract SQLResult Execute(StringBuilder sql); - - public abstract SQLResult Execute(string sql); - - public abstract DataSet ExecuteDataSet(StringBuilder sql); - - public abstract DataSet ExecuteDataSet(string sql); - - public abstract object Query(EntityType type, StringBuilder sql); - - public abstract object Query(EntityType type, string sql); - - public abstract int Remove(StringBuilder sql, ref SQLResult result); - - public abstract int Remove(string sql, ref SQLResult result); - - public abstract int Update(StringBuilder sql, ref SQLResult result); - - public abstract int Update(string sql, ref SQLResult result); - } -} diff --git a/FunGame.Desktop/Library/Config/Constant.cs b/FunGame.Desktop/Library/Config/Constant.cs index db469c9..8bd8586 100644 --- a/FunGame.Desktop/Library/Config/Constant.cs +++ b/FunGame.Desktop/Library/Config/Constant.cs @@ -1,5 +1,5 @@ -using Milimoe.FunGame.Core.Library.Constant; -using System.Text; +using System.Text; +using Milimoe.FunGame.Core.Library.Constant; namespace Milimoe.FunGame.Desktop.Library { diff --git a/FunGame.Desktop/UI/Main/Main.cs b/FunGame.Desktop/UI/Main/Main.cs index 469c53b..6139896 100644 --- a/FunGame.Desktop/UI/Main/Main.cs +++ b/FunGame.Desktop/UI/Main/Main.cs @@ -187,7 +187,7 @@ namespace Milimoe.FunGame.Desktop.UI if (objs[0].GetType() == typeof(string)) { WritelnSystemInfo((string)objs[0]); - ShowMessage.Message((string)objs[0], "退出登录成功", 5); + ShowMessage.Message((string)objs[0], "退出登录", 5); } } break;