hand
_1_7_97
4
返回栏目
1k
0.2k
0.5k
0.1k
0k
0.2k
0k
0.7k
0k
0k
0.4k
0.1k
4k
0.2k
0.1k
2k
0.2k
0.2k
0k
0k
0.5k
0k
0.9k
0.1k
1k
0.9k
2k
1k
2k
0.9k
1k
0k
1k
0k
1k
1k
1k
1k
0k
1k
1k
1k
0k
3k
1k
0k
0.3k
1k
0.3k
0.9k
0k
8k
9k
6k
2k
1k
2k
1k
1k
2k
0.6k
1k
0.6k
1k
0.5k
0.2k
2k
2k
2k
1k
2k
0k
0.8k
0.8k
1k
0k
0k
0k
0k
0k
0k
0k
0k
0.3k
0.4k
0.8k
0.3k
5k
1k
3k
7k
6k
3k
3k
1k
0.2k
2k
3k
2k
0.4k
0.5k
3k
2k
7k
3k
4k
2k
1k
6k
6k
1k
1k
0.9k
0.2k
0.3k
0.9k
1k
0k
0.8k
2k
0k
0.4k
0.1k
1k
0.9k
0.2k
1k
1k
0.5k
0k
0k
0.4k
4k
0.4k
2k
3k
1k
1k
1k
3k
5k
0k
1k
2k
0.5k
0k
1k
0k
1k
0.5k
0.8k
返回Unity - 游戏引擎栏目
作者:
贺及楼
成为作者
更新日期:2023-09-17 10:58:24
class ResultDAO
{
public Result GetResultByUserid( 连接器,用户ID){}
public void UpdateOrAddResult(连接器, 数据结果){}
}
class ResultDAO
{
public Result GetResultByUserid( MySqlConnection conn,int userId){}
public void UpdateOrAddResult(MySqlConnection conn, Result res){}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GameServer.Model;
using MySql.Data.MySqlClient;
namespace GameServer.DAO
{
class ResultDAO
{
public Result GetResultByUserid( MySqlConnection conn,int userId)
{
MySqlDataReader reader = null;
try
{
MySqlCommand cmd = new MySqlCommand("select * from result where userid = @userid", conn);
cmd.Parameters.AddWithValue("userid", userId);
reader = cmd.ExecuteReader();
if (reader.Read())
{
int id = reader.GetInt32("id");
int totalCount = reader.GetInt32("totalcount");
int winCount = reader.GetInt32("wincount");
Result res = new Result(id, userId, totalCount, winCount);
return res;
}
else
{
Result res = new Result(-1, userId, 0, 0);
return res;
}
}
catch (Exception e)
{
Console.WriteLine("在GetResultByUserid的时候出现异常:" + e);
}
finally
{
if (reader != null) reader.Close();
}
return null;
}
public void UpdateOrAddResult(MySqlConnection conn, Result res)
{
try
{
MySqlCommand cmd = null;
if (res.Id <= -1)
{
cmd= new MySqlCommand("insert into result set totalcount=@totalcount,wincount=@wincount,userid=@userid", conn);
}
else
{
cmd = new MySqlCommand("update result set totalcount=@totalcount,wincount=@wincount where userid=@userid ", conn);
}
cmd.Parameters.AddWithValue("totalcount", res.TotalCount);
cmd.Parameters.AddWithValue("wincount", res.WinCount);
cmd.Parameters.AddWithValue("userid", res.UserId);
cmd.ExecuteNonQuery();
if (res.Id <= -1)
{
Result tempRes = GetResultByUserid(conn, res.UserId);
res.Id = tempRes.Id;
}
}
catch (Exception e)
{
Console.WriteLine("在UpdateOrAddResult的时候出现异常:" + e);
}
}
}
}
Unity - 游戏引擎
整章节共151节
快分享给你的小伙伴吧 ~