📄 user.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Security.Cryptography;
using Oracle.DataAccess.Client;
using Qeb.Control;
using Qeb.Support;
using Qeb.Support.Common;
using Qeb.DBProxy;
namespace Qeb.GY
{
public class User
{
#region Logon
public bool Logon(string gh,string password,string appId,out string errText)
{
errText = "";
#region 参数检查
if (string.IsNullOrEmpty(gh.Trim()))
{
AppError err = new AppError("入参错误,用户名不能为空", this.GetType());
AppLog.Add(err);
throw new Exception("入参错误,用户名不能为空");
}
if (string.IsNullOrEmpty(password.Trim()))
{
AppError err = new AppError("入参错误,密码不能为空", this.GetType());
AppLog.Add(err);
throw new Exception("入参错误,密码不能为空");
}
if (string.IsNullOrEmpty(appId.Trim()))
{
AppError err = new AppError("入参错误,应用ID不能为空", this.GetType());
AppLog.Add(err);
throw new Exception("入参错误,应用ID不能为空");
}
#endregion
//创建代理服务
DbProxyClient proxy = new DbProxyClient();
#region 取用户信息并校验密码和帐户信息
QDataStore dsUser = new QDataStore();
try
{
dsUser.LibraryList = PBL.GyPbl;
dsUser.DataWindowObject = GyDataObjects.D_Gy_YhXx;
proxy.Clear();
proxy.AddRetrieveParam("p_gh", gh);
proxy.Retrieve(dsUser);
}
catch(Exception ex)
{
dsUser.Dispose();
throw new Exception("校验密码和帐户信息发生异常:" + ex.Message);
}
//检查是否存在用户信息
if (dsUser.RowCount == 0)
{
errText = "没有找到您的用户信息!";
AppLog.Add(errText + "(用户工号:" + gh + ")", LogEntryType.Warning, this.GetType());
dsUser.Dispose();
return false;
}
//检查帐户是否被停用
if (dsUser.IsItemNull(1, "TyBz"))
{
//DbNull 正常
}
else
{
int stopFlag = (int)dsUser.GetItemDecimal(1, "TyBz");
if (stopFlag == 1)
{
errText = "您的帐号已被停用!";
dsUser.Dispose();
return false;
}
}
//检查是否空密码
string dbPassword = "";
if (!dsUser.IsItemNull(1, "mm"))
{
dbPassword = dsUser.GetItemString(1, "mm");
}
if (string.IsNullOrEmpty(dbPassword))
{
errText = "您的密码未设置,不允许登陆,请联系信息设置密码后再登陆系统!";
AppLog.Add(errText + "(用户工号:" + gh + ")", LogEntryType.Warning, this.GetType());
dsUser.Dispose();
return false;
}
//检查密码是否匹配
if (!dbPassword.Equals(CreatePassword(password)))
{
errText = "您的密码不正确!";
dsUser.Dispose();
return false;
}
//设置用户信息
//工号
App.gh = gh;
//职工ID
App.zgid = GetZgIdByGh(gh);
if (string.IsNullOrEmpty(App.zgid))
{
errText = "在职工信息表中没有取到用户信息!";
dsUser.Dispose();
return false;
}
//应用ID
App.yyId = appId;
//系统ID
App.xtId = appId.Substring(0, 2);
//登陆时间
App.logonTime = DateHelper.GetServerTime().ToString("yyyy-MM-dd HH:mm:ss");
//用户名称
if (!dsUser.IsItemNull(1,"YhMc"))
App.yhMc = dsUser.GetItemString(1, "YhMc");
//默认输入码
string mrSrm = "";
if (!dsUser.IsItemNull(1,"mrsrm"))
{
mrSrm = dsUser.GetItemString(1, "mrsrm");
}
if (string.IsNullOrEmpty(mrSrm) || (mrSrm != "SRM1" && mrSrm != "SRM2" && mrSrm != "SRM3"))
{
mrSrm = "SRM1";
}
//取库房类型
try
{
string sql = "SELECT KFLX FROM GY_YYXX WHERE YYID='" + appId + "'";
proxy.Clear();
string kfLx = proxy.ExecuteScalar(sql);
if ((App.xtId == "02" || App.xtId == "03") && (kfLx == null || kfLx == "0000" ||kfLx.Trim() ==""))
{
errText = "药库或药房必须设置库房类型,请与信息中心联系!";
AppLog.Add(errText, LogEntryType.Warning, this.GetType());
dsUser.Dispose();
return false;
}
App.kfLx = kfLx;
}
catch(Exception ex)
{
throw new Exception("取库房类型出错:"+ex.Message);
}
dsUser.Dispose();
#endregion
#region 取用户角色并缓存
QDataStore dsUserRole = null;
try
{
dsUserRole = this.GetUserRole(proxy, gh);
}
catch
{
if (dsUserRole != null)
dsUserRole.Dispose();
throw;
}
if (dsUserRole.RowCount == 0)
{
errText = "系统管理员没有为您设置任何角色,无法登陆,请联系信息中心!";
return false;
}
else
{
//加入缓存
App.cache.AddObject("DataStore/YhJs",dsUserRole,true);
}
#endregion
#region 检查是否有权限使用当前系统 ...
#endregion
return true;
}
#endregion
#region 用户密码加密
/// <summary>
/// 密码加密
/// </summary>
/// <param name="password"></param>
/// <returns></returns>
public static string CreatePassword(string password)
{
MD5 md5 = MD5.Create();
byte[] encryptBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(password));
return Convert.ToBase64String(encryptBytes);
}
#endregion
#region GetUserRole
public QDataStore GetUserRole(DbProxyClient proxy,string userId)
{
QDataStore dsUserRole = new QDataStore();
dsUserRole.LibraryList = PBL.GyPbl;
dsUserRole.DataWindowObject = GyDataObjects.D_Gy_YhJs;
proxy.AddRetrieveParam("p_gh", userId);
proxy.Retrieve(dsUserRole);
return dsUserRole;
}
public QDataStore GetUserRole(string userId)
{
DbProxyClient proxy = new DbProxyClient();
try
{
return this.GetUserRole(proxy, userId);
}
finally
{
if (proxy != null)
proxy.Dispose();
}
}
#endregion
#region GetUserName
public string GetUserName(string userId)
{
string userName = "";
QDataStore ds = null;
try
{
ds = new QDataStore();
ds.LibraryList = PBL.GyPbl;
ds.DataWindowObject = GyDataObjects.D_Gy_YhMc;
DbProxyClient proxy = App.DbProxy;
proxy.Clear();
proxy.AddRetrieveParam("p_gh", userId);
proxy.Retrieve(ds);
if (ds.RowCount >0)
{
if (!ds.IsItemNull(1, "YhMc"))
userName = ds.GetItemString(1, "YhMc");
}
}
finally
{
ds.Dispose();
}
return userName;
}
#endregion
#region 根据工号取职工ID
public string GetZgIdByGh(string gh)
{
//在职职工
string sql = "SELECT ZGID FROM GY_ZGXX WHERE GH='"+gh+"' AND ZT='0'";
try
{
DbProxyClient proxy = App.DbProxy;
proxy.Clear();
return proxy.ExecuteScalar(sql);
}
catch(Exception ex)
{
throw new Exception("取职工ID发生异常:"+ex.Message);
}
}
#endregion
#region 根据应用ID取库房类型
public string GetKfLxByYyId(string yyId)
{
string sql = "SELECT KFLX FROM GY_YYXX WHERE YYID='" + yyId + "'";
try
{
DbProxyClient proxy = App.DbProxy;
proxy.Clear();
return proxy.ExecuteScalar(sql);
}
catch (Exception ex)
{
throw new Exception("取职工ID发生异常:" + ex.Message);
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -