一厂MES,含注塑,喷涂,冲孔
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

388 lines
13 KiB

using MESClassLibrary.BLL.Log;
using MESClassLibrary.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
namespace MESClassLibrary.DAL.User
{
public class UserDAL : BasicDAL
{
public static string TableName = "tb_User";
public string GetTableName()
{
return TableName;
}
/// <summary>
/// 获取全部用户信息
/// </summary>
/// <returns></returns>
public DataTable Search_UserInfo()
{
try
{
string sql = @"select * from T_Sys_Users where IsEnabled='1'";
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 根据登录名密码查询用户信息
/// </summary>
/// <param name="username"></param>
/// <param name="password"></param>
/// <returns></returns>
public DataTable Search_UserInfoByUP(string username, string password)
{
try
{
string sql = @"SELECT [UserID]
,[UserName]
,[Password]
,[IsEnabled]
,[RealName]
,[Sex]
,[Tel]
,[LastLoginTime]
,[LastLoginIP]
,[DepartmentID]
,[OpName]
,[OpTime]
FROM [T_Sys_Users]
where UserName = @Username and Password = @Password and IsEnabled = '1'";
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter("@Username", SqlDbType.VarChar);
param[0].Value = username;
param[1] = new SqlParameter("@Password", SqlDbType.VarChar);
param[1].Value = password;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 根据id查询用户信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataTable Search_UserInfoByID(string id)
{
try
{
string sql = @"select c.*,r.RoleName from tb_User c
left join tb_Role r on c.RoleID = r.id where c.IsUseing=1 and c.ID=@ID";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@ID", SqlDbType.VarChar);
param[0].Value = id;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 根据id查询用户信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataTable Search_UserInfoByID_v2(string id)
{
try
{
string sql = @"select * from T_Sys_Users c where c.IsEnabled=1 and c.UserID=@UserID";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@UserID", SqlDbType.VarChar);
param[0].Value = id;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 根据登录账号查询用户信息
/// </summary>
/// <param name="username">登录账号</param>
/// <returns></returns>
public DataTable Search_UserInfoByUserName(string username)
{
try
{
string sql = @"SELECT [UserID]
,[UserName]
,[Password]
,[IsEnabled]
,[RealName]
,[Sex]
,[Tel]
,[LastLoginTime]
,[LastLoginIP]
,[DepartmentID]
,[OpName]
,[OpTime]
FROM [T_Sys_Users]
where UserName = @Username and IsEnabled = '1'";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@Username", SqlDbType.VarChar);
param[0].Value = username;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 根据角色ID查询该角色的用户信息
/// </summary>
/// <param name="roleID">角色主键ID</param>
/// <returns></returns>
public DataTable Search_UserInfoByRoleID(string roleID)
{
try
{
string sql = @"select c.*,r.RoleName,r.RoleJurisdiction from tb_User c
left join tb_Role r on c.RoleID = r.id where c.IsUseing=1 and c.RoleID=@RoleID";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@RoleID", SqlDbType.VarChar);
param[0].Value = roleID;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 添加用户信息
/// </summary>
/// <param name="mod">用户模型</param>
/// <returns></returns>
public bool Add_UserInfo(UserModel mod)
{
try
{
#region 添加数据
string sql = "";
SqlParameter[] param = null;
sql = "INSERT INTO tb_User (ID,Username,Password,TrueName,FaceURL,RoleID,CreateUserID";
sql += ") VALUES (";
sql += "@ID,";
sql += "@Username,";
sql += "@Password,";
sql += "@TrueName,";
sql += "@FaceURL,";
sql += "@RoleID,";
sql += "@CreateUserID)";
#region 添加参数
param = new SqlParameter[7];
param[0] = new SqlParameter("@ID", SqlDbType.VarChar);
param[0].Value = mod.ID;
param[1] = new SqlParameter("@Username", SqlDbType.VarChar);
param[1].Value = mod.Username;
param[2] = new SqlParameter("@Password", SqlDbType.VarChar);
param[2].Value = mod.Password;
param[3] = new SqlParameter("@TrueName", SqlDbType.VarChar);
param[3].Value = mod.TrueName;
param[4] = new SqlParameter("@FaceURL", SqlDbType.VarChar);
param[4].Value = mod.FaceURL;
param[5] = new SqlParameter("@RoleID", SqlDbType.VarChar);
param[5].Value = mod.RoleID;
param[6] = new SqlParameter("@CreateUserID", SqlDbType.VarChar);
param[6].Value = mod.CreateUserID;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
/// <summary>
/// 更新用户信息
/// </summary>
/// <param name="md">用户模型对象</param>
/// <returns></returns>
public bool Update_UserInfo(UserModel md)
{
try
{
string sql = @"update T_Sys_Users set LastLoginTime=(select getdate()),ErrTimes=" + md.ErrTimes + @" where UserName='" + md.Username + "'";
if (SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, null) > 0)
{
return true;
}
return false;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
/// <summary>
/// 查询用户登录日志
/// </summary>
/// <returns></returns>
public DataTable Search_UserLoginInfo()
{
try
{
string sql = @"select l.*,u.TrueName,r.RoleName from tb_UserLoginLog l
left join tb_User u on l.UserID = u.ID
left join tb_Role r on u.RoleID = r.ID order by l.LoginTime desc";
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 添加用户登录日志
/// </summary>
/// <param name="userid">用户主键ID</param>
/// <returns></returns>
public bool Add_UserLoginInfo(string userid)
{
try
{
#region 添加数据
string sql = "";
SqlParameter[] param = null;
sql = "INSERT INTO tb_UserLoginLog (ID,UserID";
sql += ") VALUES (";
sql += "@ID,";
sql += "@UserID)";
#region 添加参数
param = new SqlParameter[2];
param[0] = new SqlParameter("@ID", SqlDbType.VarChar);
param[0].Value = Guid.NewGuid().ToString();
param[1] = new SqlParameter("@UserID", SqlDbType.VarChar);
param[1].Value = userid;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public bool Update_Password(string userid, string oldpassword, string newpassword)
{
try
{
string sql = @"update T_Sys_Users set
Password = @New_Password
where UserID=@UserID and Password=@Old_Password";
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@New_Password", SqlDbType.VarChar);
param[0].Value = newpassword;
param[1] = new SqlParameter("@UserID", SqlDbType.VarChar);
param[1].Value = userid;
param[2] = new SqlParameter("@Old_Password", SqlDbType.VarChar);
param[2].Value = oldpassword;
if (SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param) > 0)
{
return true;
}
return false;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
}
}