📄 cuser.cs
字号:
using System;
using System.Data;
using System.Collections;
using System.Data.OracleClient;
using DataMiddleware;
using System.Windows.Forms;
using ICT.CARS.DataFactroy;
namespace ICT.CARS.GlobalProperty.BackgroudManager
{
/// <summary>
/// 用户相关信息
/// Author:wxl
/// Date: 2007-04-06
/// </summary>
public class CUser
{
private static string strRoleName = string.Empty;
/// <summary>
/// 设置、获取角色名称
/// Author:wxl
/// Date: 2007-04-10
/// </summary>
public static string RoleName
{
get
{
return strRoleName;
}
set
{
if(strRoleName !=value)
{
strRoleName = value;
}
}
}
private static string m_DeptName = string.Empty;
/// <summary>
/// 部门名称
/// </summary>
public static string DeptName
{
get
{
return m_DeptName;
}
}
private static string m_FiliationDept = string.Empty;
/// <summary>
/// 分支部门编号
/// </summary>
public static string FiliationDept
{
get
{
return m_FiliationDept;
}
}
private static string m_FiliationDeptName = string.Empty;
/// <summary>
/// 分支部门编号
/// </summary>
public static string FiliationDeptName
{
get
{
return m_FiliationDeptName;
}
}
private static string m_CardID = string.Empty;
/// <summary>
/// 磁卡编号
/// </summary>
public static string CardID
{
get
{
return m_CardID;
}
}
private static string m_WorktypePath = string.Empty;
/// <summary>
/// 作业路径
/// </summary>
public static string WorkTypePath
{
get { return m_WorktypePath; }
}
#region 身份验证 CheckUser()
/// <summary>
/// 身份验证
/// </summary>
/// <param name="userName">用户名称</param>
/// <param name="Password">用户密码</param>
public static bool CheckUser(TextBox txtUserName, TextBox txtPassword)
{
bool isCheck = false;
object obj = string.Empty;
if (txtUserName.Text.Trim() == "" && txtPassword.Text.Trim() == "")
{
MessageBox.Show("用户名或密码不能为空");
SetTextBox(txtUserName); //设置TextBox
isCheck = false;
}
else if(txtUserName.Text.Trim() == "admin" && txtPassword.Text.Trim() == System.DateTime.Now.Date.ToString("yyyyMMdd"))
{
isCheck = true;//维护人员专用
}
else
{
IDataAccess DB = null;
try
{
DB = StaticAccess.GetAccess();
DB.Open();
string sql = "SELECT s_Password FROM P$SYS_USER_DICT WHERE s_UserName='" + txtUserName.Text + "'";
obj = DB.ExecuteScalar(sql);
if (obj == null)
{
MessageBox.Show("用户名不存在!");
SetTextBox(txtUserName); //设置TextBox
isCheck = false;
}
if (obj != null && obj.ToString().Trim() != txtPassword.Text.Trim().ToString())
{
MessageBox.Show("密码错误!");
SetTextBox(txtPassword);
isCheck = false;
}
else
{
if(txtUserName.Text.Trim().Length !=0 && txtUserName.Text.Trim() !="" && obj != null) //如果用户名不为空
{
isCheck = true;
}
}
}
catch
{
}
finally
{
DB.Close();
}
}
return isCheck;
}
/// <summary>
/// 设置TextBox
/// </summary>
/// <param name="textBox"></param>
private static void SetTextBox(TextBox textBox)
{
textBox.SelectAll();
textBox.Focus();
}
#endregion
#region 获取用户ID GetUserID
/// <summary>
/// 获取用户ID(职工编号)
/// </summary>
/// <param name="userName">用户名称</param>
/// <returns>用户ID编号</returns>
public static string GetUserID(string userName)
{
string result = "";
IDataAccess DB = null;
try
{
DB = StaticAccess.GetAccess();
DB.Open();
string strSql = "SELECT s_StuffCode FROM P$SYS_USER_DICT WHERE s_UserName='" + userName + "'";
object obj = DB.ExecuteScalar(strSql);
if (obj != null)
{
result = obj.ToString();
}
}
catch
{
throw new Exception("获取用户信息出错!请重试!");
}
finally
{
DB.Close();
}
return result;
}
#endregion
#region 获取角色编号 GetActorCode
/// <summary>
/// 获取某个用户所具有的角色Code,与用户表关联获取得出角色Code
/// Modify Date: 2007-04-10
/// </summary>
/// <param name="userName">用户名称</param>
/// <returns>角色编号</returns>
public static string GetActorCode(string userName)
{
string strRoleID = "";
IDataAccess DB = null;
DataTable dt = null;
try
{
DB = StaticAccess.GetAccess();
DB.Open();
string strSql = "SELECT c_RoleCode,S_ROLENAME, B.S_workroute FROM P$SYS_ROLE_DICT A INNER JOIN " +
"P$SYS_USER_DICT B ON trim(B.s_Role) = trim(A.c_RoleCode) WHERE s_UserName='" + userName + "'";
dt = DB.GetDataTableBySQL(strSql);
if(dt !=null)
{
foreach(DataRow row in dt.Rows)
{
strRoleID = row["c_RoleCode"].ToString();
strRoleName=row["S_ROLENAME"].ToString(); //将调度员添加到属性实体
m_WorktypePath = row["S_workroute"].ToString();
}
}
#region Comment
//object obj = DB.ExecuteScalar(strSql);
//
//actors = obj.ToString();
// //判断是否为空
//if (actors.Length == 0)
//{
// actors = "''";
//}
#endregion
}
catch(Exception ex)
{
throw ex;
}
finally
{
DB.Close();
}
return strRoleID;
}
#endregion
#region 获取模块编号列表及各个模块具有的相关权限
private static Hashtable _hashTable = new Hashtable();
/// <summary>
/// 定义一个HashTable,存储模块名称与模块权限
/// </summary>
public static Hashtable hashTable
{
get
{
return _hashTable;
}
}
/// <summary>
/// 根据角色获取分配的模块列表
/// </summary>
/// <param name="roleCode">角色编号</param>
/// <returns>模块编号列表</returns>
public static string GetModuleCode(string roleCode)
{
string moduleCode = "";
IDataAccess DB = null;
DataTable dt = null;
try
{
DB = StaticAccess.GetAccess();
DB.Open();
string strSql = "select * from P$SYS_ROLE_GRANT_DICT where C_Rolecode ='" + roleCode + "'";
dt = DB.GetDataTableBySQL(strSql);
if (dt != null)
{
foreach (DataRow row in dt.Rows)
{
string code = row["c_ModuleCode"].ToString();
string permCode = row["c_PermCode"].ToString(); //权限编号
string opr = PermOperator(permCode); //获取模块的操作权限,因为
if (moduleCode.Length == 0)
{
moduleCode = code;
}
else
{
moduleCode += "," + code;
}
string strName = GetModuleNames(code); //选择单个模块名称
_hashTable.Add(strName, opr); //将各个模块的操作权限装到HasTable中
}
}
}
catch
{
}
finally
{
DB.Close();
}
return moduleCode;
}
/// <summary>
/// 获取具体模块所具有的操作权限,如增、删、改、查
/// </summary>
/// <param name="moduleCode">模块编号</param>
/// <returns>操作名称</returns>
private static string PermOperator(string moduleCode)
{
string canOperator = "";
IDataAccess DB = null;
try
{
DB = StaticAccess.GetAccess();
DB.Open();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -