forked from project-redbud/FunGame-Core
添加SQLHelper,SQL处理器
This commit is contained in:
parent
f679c1884e
commit
81d5903751
@ -1,30 +1,39 @@
|
|||||||
using Milimoe.FunGame.Core.Interface.Base;
|
using System.Data;
|
||||||
using Milimoe.FunGame.Core.Library.Common.Network;
|
using Milimoe.FunGame.Core.Interface.Base;
|
||||||
using Milimoe.FunGame.Core.Library.Constant;
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
|
using Milimoe.FunGame.Core.Library.Server;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Api.Data
|
namespace Milimoe.FunGame.Core.Api.Data
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 需要在Server中继承此类实现。
|
/// 需要在Server中继承此类实现
|
||||||
/// Milimoe.FunGame.Core.Service.SQLManager也是
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class SQLHelper : ISQLHelper
|
public abstract class SQLHelper : ISQLHelper
|
||||||
{
|
{
|
||||||
public string Script { get; set; } = "";
|
public abstract string Script { get; set; }
|
||||||
|
public abstract CommandType CommandType { get; set; }
|
||||||
public EntityType EntityType { get; }
|
public abstract SQLResult Result { get; }
|
||||||
|
|
||||||
public object Entity { get; } = General.EntityInstance;
|
|
||||||
|
|
||||||
public SQLResult Result { get; }
|
|
||||||
|
|
||||||
public abstract SQLServerInfo ServerInfo { get; }
|
public abstract SQLServerInfo ServerInfo { get; }
|
||||||
|
public abstract int UpdateRows { get; }
|
||||||
|
public abstract DataSet DataSet { get; }
|
||||||
|
|
||||||
public int UpdateRows { get; }
|
/// <summary>
|
||||||
|
/// 执行一个命令
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Result">执行结果</param>
|
||||||
|
/// <returns>影响的行数</returns>
|
||||||
|
public abstract int Execute(out SQLResult Result);
|
||||||
|
|
||||||
public virtual SQLResult Execute()
|
/// <summary>
|
||||||
{
|
/// 查询DataSet
|
||||||
return SQLResult.NotFound;
|
/// </summary>
|
||||||
}
|
/// <param name="Result">执行结果</param>
|
||||||
|
/// <returns>结果集</returns>
|
||||||
|
public abstract DataSet ExecuteDataSet(out SQLResult Result);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 关闭连接
|
||||||
|
/// </summary>
|
||||||
|
public abstract void Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
using Milimoe.FunGame.Core.Library.Constant;
|
using System.Net.NetworkInformation;
|
||||||
using System.Net.NetworkInformation;
|
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
|
|
||||||
// 通用工具类,客户端和服务器端都可以直接调用的工具方法都可以写在这里
|
// 通用工具类,客户端和服务器端都可以直接调用的工具方法都可以写在这里
|
||||||
namespace Milimoe.FunGame.Core.Api.Utility
|
namespace Milimoe.FunGame.Core.Api.Utility
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
|
using Milimoe.FunGame.Core.Interface.Entity;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Core.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 Username { get; set; } = "";
|
||||||
public string Password { get; set; } = "";
|
public string Password { get; set; } = "";
|
||||||
public DateTime RegTime { get; set; }
|
public DateTime RegTime { get; set; }
|
||||||
@ -35,5 +37,17 @@ namespace Milimoe.FunGame.Core.Entity
|
|||||||
Username = username;
|
Username = username;
|
||||||
Password = password;
|
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<IBaseEntity> GetEnumerator()
|
||||||
|
{
|
||||||
|
return GetEnumerator();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
namespace Milimoe.FunGame.Core.Interface.Base
|
||||||
{
|
{
|
||||||
public interface ISQLHelper
|
public interface ISQLHelper
|
||||||
{
|
{
|
||||||
public string Script { get; set; }
|
public string Script { get; set; }
|
||||||
public EntityType EntityType { get; }
|
public CommandType CommandType { get; set; }
|
||||||
public object Entity { get; }
|
|
||||||
public SQLResult Result { get; }
|
public SQLResult Result { get; }
|
||||||
int UpdateRows { get; }
|
|
||||||
public SQLServerInfo ServerInfo { get; }
|
public SQLServerInfo ServerInfo { get; }
|
||||||
|
public int UpdateRows { get; }
|
||||||
|
public DataSet DataSet { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
namespace Milimoe.FunGame.Core.Library.Constant
|
||||||
{
|
{
|
||||||
|
|||||||
44
FunGame.Core/Library/Constant/SQLConstant.cs
Normal file
44
FunGame.Core/Library/Constant/SQLConstant.cs
Normal file
@ -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}')";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -104,4 +104,9 @@
|
|||||||
{
|
{
|
||||||
public override string Message => "用户未登录 (#10021)";
|
public override string Message => "用户未登录 (#10021)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SQLQueryException : Exception
|
||||||
|
{
|
||||||
|
public override string Message => "执行SQL查询时遇到错误 (#10022)";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
namespace Milimoe.FunGame.Core.Library.Common.Network
|
namespace Milimoe.FunGame.Core.Library.Server
|
||||||
{
|
{
|
||||||
public class SQLServerInfo
|
public class SQLServerInfo
|
||||||
{
|
{
|
||||||
public string SQLServerName { get; } = "";
|
public string SQLServerName { get; } = "";
|
||||||
public string SQLServerIP { get; } = "";
|
public string SQLServerIP { get; } = "";
|
||||||
public string SQLServerPort { get; } = "";
|
public string SQLServerPort { get; } = "";
|
||||||
|
public string SQLServerDataBase { get; } = "";
|
||||||
public string SQLServerUser { get; } = "";
|
public string SQLServerUser { get; } = "";
|
||||||
public string SQLServerPassword { get; } = "";
|
public string SQLServerPassword { get; } = "";
|
||||||
|
|
||||||
@ -13,13 +14,14 @@
|
|||||||
SQLServerName = builder.SQLServerName;
|
SQLServerName = builder.SQLServerName;
|
||||||
SQLServerIP = builder.SQLServerIP;
|
SQLServerIP = builder.SQLServerIP;
|
||||||
SQLServerPort = builder.SQLServerPort;
|
SQLServerPort = builder.SQLServerPort;
|
||||||
|
SQLServerDataBase = builder.SQLServerDataBase;
|
||||||
SQLServerUser = builder.SQLServerUser;
|
SQLServerUser = builder.SQLServerUser;
|
||||||
SQLServerPassword = builder.SQLServerPassword;
|
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
|
internal class InfoBuilder
|
||||||
@ -27,14 +29,16 @@
|
|||||||
internal string SQLServerName { get; } = "";
|
internal string SQLServerName { get; } = "";
|
||||||
internal string SQLServerIP { get; } = "";
|
internal string SQLServerIP { get; } = "";
|
||||||
internal string SQLServerPort { get; } = "";
|
internal string SQLServerPort { get; } = "";
|
||||||
|
internal string SQLServerDataBase { get; } = "";
|
||||||
internal string SQLServerUser { get; } = "";
|
internal string SQLServerUser { get; } = "";
|
||||||
internal string SQLServerPassword { 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;
|
SQLServerName = name;
|
||||||
SQLServerIP = ip;
|
SQLServerIP = ip;
|
||||||
SQLServerPort = port;
|
SQLServerPort = port;
|
||||||
|
SQLServerDataBase = database;
|
||||||
SQLServerUser = user;
|
SQLServerUser = user;
|
||||||
SQLServerPassword = password;
|
SQLServerPassword = password;
|
||||||
}
|
}
|
||||||
@ -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
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 需要在Server中继承此类实现
|
|
||||||
/// </summary>
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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
|
namespace Milimoe.FunGame.Desktop.Library
|
||||||
{
|
{
|
||||||
|
|||||||
@ -187,7 +187,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
if (objs[0].GetType() == typeof(string))
|
if (objs[0].GetType() == typeof(string))
|
||||||
{
|
{
|
||||||
WritelnSystemInfo((string)objs[0]);
|
WritelnSystemInfo((string)objs[0]);
|
||||||
ShowMessage.Message((string)objs[0], "退出登录成功", 5);
|
ShowMessage.Message((string)objs[0], "退出登录", 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user