📄 db.cs
字号:
using System;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
using System.Data;
namespace PlayCardServer
{
public class DB
{
private DB()
{
}
public static SqlDataReader LoginDB(string UserID, string Password)
{
SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
string sql = "select * from PlayerList where UserID=@UserID and Password=@Password and isLogin='0'";
SqlCommand myCommand = new SqlCommand(sql, myConnection);
SqlParameter parameterUserID = new SqlParameter("@UserID", SqlDbType.VarChar);
parameterUserID.Value = UserID;
myCommand.Parameters.Add(parameterUserID);
SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.VarChar);
parameterPassword.Value = Password;
myCommand.Parameters.Add(parameterPassword);
myConnection.Open();
SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
return dr;
}
public static void UpdateStatus(string UserID, string Status)
{
SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
string sql = "update PlayerList set isLogin=@Status where UserID=@UserID";
SqlCommand myCommand = new SqlCommand(sql, myConnection);
SqlParameter parameterUserID = new SqlParameter("@UserID", SqlDbType.VarChar);
parameterUserID.Value = UserID;
myCommand.Parameters.Add(parameterUserID);
SqlParameter parameterStatus = new SqlParameter("@Status", SqlDbType.Char, 1);
parameterStatus.Value = Status;
myCommand.Parameters.Add(parameterStatus);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
public static void UpdateScore(string UserID, int Score)
{
SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
string sql = "update PlayerList set Score=Score + @Score where UserID=@UserID";
SqlCommand myCommand = new SqlCommand(sql, myConnection);
SqlParameter parameterUserID = new SqlParameter("@UserID", SqlDbType.VarChar);
parameterUserID.Value = UserID;
myCommand.Parameters.Add(parameterUserID);
SqlParameter parameterScore = new SqlParameter("@Score", SqlDbType.Int);
parameterScore.Value = Score;
myCommand.Parameters.Add(parameterScore);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -