using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Login.DAL
{
using System.Data;
using System.Data.SqlClient;
using Login.Model;
using Newtonsoft.Json;
public class UserDal
{
/// <summary>
/// 注册用户
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
public int AddUser(User user)
{
SqlParameter[] parameters = new SqlParameter[]
{
new SqlParameter("@UserName",user.UserName),
new SqlParameter("@UserPassword",user.UserPassword)
};
return DBhelper.SqlExecuteNonQuery("p_Add", CommandType.StoredProcedure, parameters);
}
/// <summary>
/// 登陆
/// </summary>
/// <param name="Name"></param>
/// <param name="Password"></param>
/// <returns></returns>
public int UserLogin(string Name, string Password)
{
SqlParameter[] parameters = new SqlParameter[]
{
new SqlParameter("@UserName",Name),
new SqlParameter("@UserPassword",Password)
};
var dt = DBhelper.GetTable("p_Login", CommandType.StoredProcedure, parameters);
if (dt.Rows.Count > 0)
{
return (int)dt.Rows[0]["UserID"];
}
else {
//修改user表的用户名的错误字段+1
var ero = DBhelper.SqlExecuteNonQuery("p_Error", CommandType.StoredProcedure, new SqlParameter("@UserName", Name));
}
return 0;
}
/// <summary>
/// 修改密码
/// </summary>
/// <param name="ID"></param>
/// <param name="Password"></param>
/// <returns></returns>
public int UserUpdate(int ID, string Password)
{
SqlParameter[] parameters = new SqlParameter[]
{
new SqlParameter("@UserID",ID),
new SqlParameter("@UserPassword",Password)
};
var result = DBhelper.SqlExecuteNonQuery("p_Update", CommandType.StoredProcedure, parameters);
return result;
}
/// <summary>
/// 获取数据
/// </summary>
/// <returns></returns>
public List<User> GetUser()
{
var result = DBhelper.GetTable("p_Get", CommandType.StoredProcedure);
var jar = JsonConvert.DeserializeObject<List<User>>(JsonConvert.SerializeObject(result));
return jar;
}
}
}