using MESClassLibrary.BLL.Log; using MESClassLibrary.DAL.User; using MESClassLibrary.EFModel; using MESClassLibrary.Model; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Text; namespace MESClassLibrary.BLL.User { public class UserBLL { UserDAL db = new UserDAL(); //用户登录 public bool Login(UserModel md) { try { #region 入参校验 if (string.IsNullOrWhiteSpace(md.Username) || string.IsNullOrWhiteSpace(md.Password)) { return false; } #endregion #region 登陆 //DataTable dt = db.Search_UserInfoByUP(md.Username, Tool.MD5encryption(md.Password)); DataTable dt = db.Search_UserInfoByUP(md.Username, md.Password); if (dt != null && dt.Rows.Count > 0) { #region 记录用户登录日志-暂注销 md.ID = dt.Rows[0][0].ToString(); //md.TrueName = dt.Rows[0]["TrueName"].ToString(); //md.FaceURL = dt.Rows[0]["FaceURL"].ToString(); //md.RoleID = dt.Rows[0]["RoleID"].ToString(); //md.RoleName = dt.Rows[0]["RoleName"].ToString(); //md.RoleJurisdiction = dt.Rows[0]["RoleJurisdiction"].ToString(); //md.CompanyPost = dt.Rows[0]["CompanyPost"].ToString(); //md.ContactWay = dt.Rows[0]["ContactWay"].ToString(); //md.CreateUserID = dt.Rows[0]["CreateUserID"].ToString(); //md.IsUseing = (int)dt.Rows[0]["IsUseing"]; db.Add_UserLoginInfo(md.ID); #endregion return true; } else { return false; } #endregion } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 新增用户信息 /// /// /// public bool AddUserInfo(UserModel md) { //try //{ // DataTable dt = db.Search_UserInfoByUserName(md.ID, md.Username); // if (dt != null && dt.Rows.Count > 0) // { // return false; // } // md.Password = Tool.MD5encryption(md.Password); // return db.Add_UserInfo(md); //} //catch (Exception ex) //{ // LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); // return false; //} return false; } /// /// 修改用户信息 /// /// /// /// public bool UpdateUserInfo(UserModel md) { try { return db.Update_UserInfo(md); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// 修改用户密码 /// /// /// /// /// public bool UpdateUserPassword(string oldpassword, string newpassword, string id) { try { DataTable dt = db.Search_UserInfoByID_v2(id); if (dt != null && dt.Rows.Count > 0) { if (dt.Rows[0]["Password"].ToString() == oldpassword) { return db.Update_Password(id, oldpassword, newpassword); } } return false; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } /// /// /// /// /// /// public bool DelUserInfoByID(string id, string userid) { try { return db.Del_Info(db.GetTableName(), id, userid); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return false; } } #region 查询用户信息 /// /// 查询全部用户信息 /// /// public DataTable SearchUserInfo() { try { return db.Search_UserInfo(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } /// /// 根据ID查询用户信息 /// /// /// public DataTable SearchUserInfoByID(string id) { try { return db.Search_UserInfoByID(id); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } /// /// 根据登录账号查询用户信息 /// /// /// public DataTable SearchUserInfoByUserName(string username) { try { DataTable dt = db.Search_UserInfoByUserName(username); if (dt != null && dt.Rows.Count > 0) { return dt; } return null; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } /// /// 根据角色ID查询用户信息 /// /// 角色主键ID /// public DataTable SearchUserInfoByRoleID(string roleid) { try { DataTable dt = db.Search_UserInfoByRoleID(roleid); if (dt != null && dt.Rows.Count > 0) { return dt; } return null; } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } /// /// 查询用户登录记录 /// /// public DataTable SearchUserLoginInfo() { try { return db.Search_UserLoginInfo(); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); return null; } } public string GetComboboxData() { try { string jsonStr = "[]"; DataTable dt = db.Search_UserInfo(); if (dt!=null && dt.Rows.Count>0) { List list = new List(); for (int i = 0; i < dt.Rows.Count; i++) { T_Sys_Users md = new T_Sys_Users(); md.UserID = (Guid)dt.Rows[i]["UserID"]; md.RealName = dt.Rows[i]["RealName"].ToString(); list.Add(md); } jsonStr = JSONTools.ScriptSerialize>(list); } return jsonStr; } catch (Exception ex) { return ""; } } #endregion } }