415 lines
14 KiB
C#
415 lines
14 KiB
C#
namespace BLL
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Security;
|
|
using System.Web.UI.WebControls;
|
|
|
|
public class Sys_UserService
|
|
{
|
|
/// <summary>
|
|
/// 用户登陆方法
|
|
/// </summary>
|
|
/// <param name="loginname">登陆名</param>
|
|
/// <param name="password">未加密密码</param>
|
|
/// <param name="rememberMe">记住我开关</param>
|
|
/// <param name="page">调用页面</param>
|
|
/// <returns>是否登陆成功</returns>
|
|
public static bool UserLogOn(string account, string password, bool rememberMe, System.Web.UI.Page page)
|
|
{
|
|
string https = ConfigurationManager.AppSettings["Https"];
|
|
bool IsSuccess = false;
|
|
var q = from y in Funs.DB.Sys_User where y.Account == account select y;
|
|
List<Model.Sys_User> x = null;
|
|
if (q.Count() > 0)
|
|
{
|
|
x = (from y in Funs.DB.Sys_User
|
|
where y.Account == account && y.IsPost == true
|
|
&& y.Password == EncryptionPassword(password)
|
|
select y).ToList();
|
|
if (x.Any())
|
|
{
|
|
FormsAuthentication.SetAuthCookie(account, false);
|
|
Model.Sys_User s = x.First();
|
|
page.Session[SessionName.CurrUser] = s;
|
|
//if (rememberMe)
|
|
//{
|
|
// System.Web.HttpCookie u = new System.Web.HttpCookie("UserInfo");
|
|
// u["username"] = account;
|
|
// //u["password"] = null;
|
|
// // Cookies过期时间设置为一年.
|
|
// u.Expires = DateTime.Now.AddYears(1);
|
|
// if (https == "true")
|
|
// {
|
|
// u.Secure = true;
|
|
// }
|
|
// page.Response.Cookies.Add(u);
|
|
//}
|
|
//else
|
|
//{
|
|
// // 当选择不提交用户名时,Cookies过期时间设置为昨天.
|
|
// page.Response.Cookies["UserInfo"].Expires = DateTime.Now.AddDays(-1);
|
|
// page.Response.Cookies["UserInfo"].Secure = true;
|
|
//}
|
|
IsSuccess = true;
|
|
}
|
|
}
|
|
|
|
return IsSuccess;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 登陆获取用户信息
|
|
/// </summary>
|
|
/// <param name="account"></param>
|
|
/// <param name="password"></param>
|
|
/// <param name="rememberMe"></param>
|
|
/// <param name="page"></param>
|
|
/// <returns></returns>
|
|
public static bool ADUserLogOn(string account, bool rememberMe, System.Web.UI.Page page)
|
|
{
|
|
string https = ConfigurationManager.AppSettings["Https"];
|
|
bool IsSuccess = false;
|
|
var user = Funs.DB.Sys_User.FirstOrDefault(x => x.Account == account && x.IsPost == true);
|
|
if (user != null)
|
|
{
|
|
FormsAuthentication.SetAuthCookie(account, false);
|
|
page.Session[SessionName.CurrUser] = user;
|
|
//if (rememberMe)
|
|
//{
|
|
// System.Web.HttpCookie u = new System.Web.HttpCookie("UserInfo");
|
|
// u["username"] = account;
|
|
// // u["password"] = null;
|
|
// // Cookies过期时间设置为一年.
|
|
// u.Expires = DateTime.Now.AddYears(1);
|
|
// if (https == "true")
|
|
// {
|
|
// u.Secure = true;
|
|
// }
|
|
// page.Response.Cookies.Add(u);
|
|
//}
|
|
//else
|
|
//{
|
|
// // 当选择不提交用户名时,Cookies过期时间设置为昨天.
|
|
// page.Response.Cookies["UserInfo"].Expires = DateTime.Now.AddDays(-1);
|
|
//}
|
|
|
|
IsSuccess = true;
|
|
}
|
|
|
|
return IsSuccess;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加密密码
|
|
/// </summary>
|
|
/// <param name="password">加密前的密码</param>
|
|
/// <returns>加密后的密码</returns>
|
|
public static string EncryptionPassword(string password)
|
|
{
|
|
return FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户初始密码
|
|
/// </summary>
|
|
/// <param name="unitId">单位id</param>
|
|
/// <param name="phone">手机号码</param>
|
|
/// <returns></returns>
|
|
public static string GetEncryptionPassword(string account)
|
|
{
|
|
string passNo = string.Empty;
|
|
if (!string.IsNullOrEmpty(account))
|
|
{
|
|
passNo += account + ".1234";
|
|
}
|
|
return EncryptionPassword(passNo);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户信息
|
|
/// </summary>
|
|
/// <param name="userId">用户Id</param>
|
|
/// <returns>用户信息</returns>
|
|
public static Model.Sys_User GetUsersByUserId(string userId)
|
|
{
|
|
Model.Sys_User m = Funs.DB.Sys_User.FirstOrDefault(e => e.UserId == userId);
|
|
return m;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取用户账号是否存在
|
|
/// </summary>
|
|
/// <param name="userId">用户id</param>
|
|
/// <param name="account">账号</param>
|
|
/// <param name="projectId">项目ID</param>
|
|
/// <returns>是否存在</returns>
|
|
public static bool IsExistUserAccount(string userId, string account)
|
|
{
|
|
bool isExist = false;
|
|
if (!string.IsNullOrEmpty(userId))
|
|
{
|
|
var user = Funs.DB.Sys_User.FirstOrDefault(x => x.Account == account && x.UserId != userId);
|
|
if (user != null)
|
|
{
|
|
isExist = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var user = Funs.DB.Sys_User.FirstOrDefault(x => x.Account == account);
|
|
if (user != null)
|
|
{
|
|
isExist = true;
|
|
}
|
|
}
|
|
|
|
return isExist;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取同单位用户名称是否存在
|
|
/// </summary>
|
|
/// <param name="userId">用户id</param>
|
|
/// <param name="userName">账号</param>
|
|
/// <param name="unitId">项目ID</param>
|
|
/// <returns>是否存在</returns>
|
|
public static bool IsExistUserName(string userId, string userName)
|
|
{
|
|
bool isExist = false;
|
|
var name = Funs.DB.Sys_User.FirstOrDefault(x => x.UserName == userName && x.UserId != userId);
|
|
if (name != null)
|
|
{
|
|
isExist = true;
|
|
}
|
|
return isExist;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据部门获取用户信息
|
|
/// </summary>
|
|
/// <param name="departId"></param>
|
|
/// <returns></returns>
|
|
public static List<Model.Sys_User> GetUsersByDep(string departId)
|
|
{
|
|
return (from x in Funs.DB.Sys_User where x.DepartId == departId select x).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据用户ID获取名称
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <returns></returns>
|
|
public static string GetUserNameByUserId(string userId)
|
|
{
|
|
string userName = string.Empty;
|
|
Model.Sys_User m = Funs.DB.Sys_User.FirstOrDefault(e => e.UserId == userId);
|
|
if (m != null)
|
|
{
|
|
userName = m.UserName;
|
|
}
|
|
return userName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改密码
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <param name="password"></param>
|
|
public static void UpdatePassword(string userId, string password)
|
|
{
|
|
Model.Sys_User m = Funs.DB.Sys_User.FirstOrDefault(e => e.UserId == userId);
|
|
if (m != null)
|
|
{
|
|
m.Password = password;
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 增加人员信息
|
|
/// </summary>
|
|
/// <param name="user">人员实体</param>
|
|
public static void AddUser(Model.Sys_User user)
|
|
{
|
|
Model.Sys_User newUser = new Model.Sys_User();
|
|
newUser.UserId = user.UserId;
|
|
newUser.Account = user.Account;
|
|
newUser.UserCode = user.UserCode;
|
|
newUser.Password = user.Password;
|
|
newUser.UserName = user.UserName;
|
|
newUser.ChineseName = user.ChineseName;
|
|
newUser.UnitId = user.UnitId;
|
|
newUser.RoleId = user.RoleId;
|
|
newUser.IsPost = user.IsPost;
|
|
newUser.DepartId = user.DepartId;
|
|
newUser.Email = user.Email;
|
|
newUser.EmailPassword = user.EmailPassword;
|
|
newUser.Phone = user.Phone;
|
|
newUser.Remark = user.Remark;
|
|
newUser.Address = user.Address;
|
|
|
|
Funs.DB.Sys_User.InsertOnSubmit(newUser);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改人员信息
|
|
/// </summary>
|
|
/// <param name="user">人员实体</param>
|
|
public static void UpdateUser(Model.Sys_User user)
|
|
{
|
|
Model.Sys_User newUser = Funs.DB.Sys_User.FirstOrDefault(e => e.UserId == user.UserId);
|
|
if (newUser != null)
|
|
{
|
|
newUser.Account = user.Account;
|
|
newUser.UserCode = user.UserCode;
|
|
//newUser.Password = user.Password;
|
|
newUser.UserName = user.UserName;
|
|
newUser.ChineseName = user.ChineseName;
|
|
newUser.UnitId = user.UnitId;
|
|
newUser.RoleId = user.RoleId;
|
|
newUser.IsPost = user.IsPost;
|
|
newUser.DepartId = user.DepartId;
|
|
newUser.Email = user.Email;
|
|
if (!String.IsNullOrEmpty(user.EmailPassword))
|
|
{
|
|
newUser.EmailPassword = user.EmailPassword;
|
|
}
|
|
newUser.Phone = user.Phone;
|
|
newUser.Remark = user.Remark;
|
|
newUser.Address = user.Address;
|
|
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据主键删除用户信息
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
public static void DeleteUserById(string userId)
|
|
{
|
|
Model.Sys_User u = Funs.DB.Sys_User.FirstOrDefault(e => e.UserId == userId);
|
|
if (u != null)
|
|
{
|
|
Funs.DB.Sys_User.DeleteOnSubmit(u);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据帐号获取用户信息
|
|
/// </summary>
|
|
/// <param name="account">帐号</param>
|
|
/// <returns>用户信息</returns>
|
|
public static Model.Sys_User GetUserByAccount(string account)
|
|
{
|
|
Model.Sys_User m = Funs.DB.Sys_User.FirstOrDefault(e => e.Account == account);
|
|
return m;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据部门获得所有对应在岗的用户且参与流程
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static List<Model.Sys_User> GetUserListByDepartId(string departId)
|
|
{
|
|
var q = (from x in Funs.DB.Sys_User
|
|
where x.IsPost == true && x.DepartId == departId
|
|
orderby x.UserName
|
|
select x).ToList();
|
|
return q;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询所有在岗的用户
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static List<Model.Sys_User> GetUserList()
|
|
{
|
|
return (from x in Funs.DB.Sys_User where x.IsPost == true && x.Account != "gly" orderby x.UserName select x).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据角色获得最大编号的在岗用户
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static Model.Sys_User GetMaxUserByRoleId(string roleId)
|
|
{
|
|
return (from x in Funs.DB.Sys_User where x.IsPost == true && x.RoleId == roleId && (x.UserCode != "" && x.UserCode != null) orderby x.UserCode descending select x).FirstOrDefault();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户视图列表信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static List<Model.View_Sys_Users> GetUserViewList()
|
|
{
|
|
return (from x in Funs.DB.View_Sys_Users where x.IsPost == true orderby x.DepartName, x.UserName select x).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 常量表下拉框
|
|
/// </summary>
|
|
/// <param name="dropName">下拉框名字</param>
|
|
/// <param name="isShowPlease">是否显示请选择</param>
|
|
public static void InitUserDropDownList(FineUIPro.DropDownList dropName, bool isShowPlease)
|
|
{
|
|
dropName.DataGroupField = "DepartName";
|
|
dropName.DataValueField = "UserId";
|
|
dropName.DataTextField = "UserName";
|
|
dropName.DataSource = BLL.Sys_UserService.GetUserViewList();
|
|
dropName.DataBind();
|
|
if (isShowPlease)
|
|
{
|
|
Funs.FineUIPleaseSelect(dropName);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据用户名获取用户信息
|
|
/// </summary>
|
|
/// <param name="userName"></param>
|
|
/// <returns></returns>
|
|
public static Model.Sys_User getUserIdByUserName(string userName)
|
|
{
|
|
return Funs.DB.Sys_User.FirstOrDefault(e => e.UserName == userName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据角色获取用户信息
|
|
/// </summary>
|
|
/// <param name="roleId"></param>
|
|
/// <returns></returns>
|
|
public static List<Model.Sys_User> getUserListByRoleId(string roleId, bool isShowPost)
|
|
{
|
|
if (isShowPost)
|
|
{
|
|
return (from x in Funs.DB.Sys_User where x.RoleId == roleId && x.IsPost == isShowPost select x).ToList();
|
|
}
|
|
else
|
|
{
|
|
return (from x in Funs.DB.Sys_User where x.RoleId == roleId select x).ToList();
|
|
}
|
|
}
|
|
|
|
public static void UpdateUserList(Model.Sys_User user)
|
|
{
|
|
Model.Sys_User newUser = Funs.DB.Sys_User.FirstOrDefault(e => e.Account == user.Account);
|
|
if (newUser != null)
|
|
{
|
|
newUser.DepartId = user.DepartId;
|
|
newUser.ChineseName = user.ChineseName;
|
|
newUser.Email = user.Email;
|
|
newUser.Address = user.Address;
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
}
|
|
}
|
|
}
|