|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Data;
|
|
|
using ICSharpCode.Core;
|
|
|
using Mesnac.Codd.Session;
|
|
|
|
|
|
namespace Mesnac.Action.Default.Purview
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// Purview辅助类
|
|
|
/// </summary>
|
|
|
public class PurviewHelper
|
|
|
{
|
|
|
|
|
|
#region 角色
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断SeqIndex在角色表中是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="shiftID">要判断的SeqIndex</param>
|
|
|
/// <returns>存在返回true,否则返回false</returns>
|
|
|
public static bool IsExistsSeqIndex(string seqIndex)
|
|
|
{
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
}
|
|
|
string sqlstr = "SELECT COUNT(GUID) FROM BasRole WHERE SeqIndex = @SeqIndex";
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
dbHelper.AddParameter("@SeqIndex", seqIndex);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
int intResult = 0;
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
{
|
|
|
if (intResult > 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断RoleName在角色表中是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="shiftID">要判断的RoleName</param>
|
|
|
/// <returns>存在返回true,否则返回false</returns>
|
|
|
public static bool IsExistsRoleName(string roleName)
|
|
|
{
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
}
|
|
|
string sqlstr = "SELECT COUNT(GUID) FROM BasRole WHERE RoleName = @RoleName";
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
dbHelper.AddParameter("@RoleName", roleName);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
int intResult = 0;
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
{
|
|
|
if (intResult > 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 用户
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取角色列表
|
|
|
/// </summary>
|
|
|
/// <returns>返回角色列表</returns>
|
|
|
public static DataTable GetRoleListForSelect()
|
|
|
{
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService<PurviewHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
}
|
|
|
string sqlstr = @"SELECT '' AS GUID, '0' AS SeqIndex, '{0}' AS RoleName
|
|
|
UNION ALL
|
|
|
SELECT GUID, SeqIndex, RoleName FROM BasRole WHERE DeleteFlag = '0' ORDER BY SeqIndex";
|
|
|
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
|
|
|
return dbHelper.GetDataTableBySql(sqlstr);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取班组列表
|
|
|
/// </summary>
|
|
|
/// <returns>返回班组列表</returns>
|
|
|
public static DataTable GetClassListForSelect()
|
|
|
{
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService<PurviewHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
}
|
|
|
string sqlstr = @"SELECT '' AS GUID, 0 AS ClassID, '{0}' AS ClassName
|
|
|
UNION ALL
|
|
|
SELECT GUID, ClassID, ClassName FROM PptClass WHERE UseFlag = '1' ORDER BY ClassID";
|
|
|
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
|
|
|
return dbHelper.GetDataTableBySql(sqlstr);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断SeqIndex在用户表中是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="shiftID">要判断的SeqIndex</param>
|
|
|
/// <returns>存在返回true,否则返回false</returns>
|
|
|
public static bool IsExistsSeqIndex2(string seqIndex)
|
|
|
{
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
}
|
|
|
string sqlstr = "SELECT COUNT(GUID) FROM BasUser WHERE SeqIndex = @SeqIndex";
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
dbHelper.AddParameter("@SeqIndex", seqIndex);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
int intResult = 0;
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
{
|
|
|
if (intResult > 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断用户账号在用户表中是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="shiftID">要判断的用户账号</param>
|
|
|
/// <returns>存在返回true,否则返回false</returns>
|
|
|
public static bool IsExistsUserName(string userName)
|
|
|
{
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
}
|
|
|
string sqlstr = "SELECT COUNT(GUID) FROM BasUser WHERE UserName = @UserName";
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
dbHelper.AddParameter("@UserName", userName);
|
|
|
object result = dbHelper.ToScalar();
|
|
|
if (result != null && result != System.DBNull.Value)
|
|
|
{
|
|
|
int intResult = 0;
|
|
|
if (int.TryParse(result.ToString(), out intResult))
|
|
|
{
|
|
|
if (intResult > 0)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取角色列表
|
|
|
/// </summary>
|
|
|
/// <returns>返回角色列表</returns>
|
|
|
public static DataTable GetRoleDataTable()
|
|
|
{
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService<PurviewHelper>.Error("获取数据连接失败,请检查数据库连接字符串是否正确!");
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
}
|
|
|
string sqlstr = @"SELECT '' AS GUID, '0' AS SeqIndex, '{0}' AS RoleName
|
|
|
UNION ALL
|
|
|
SELECT GUID, SeqIndex, RoleName FROM BasRole WHERE DeleteFlag = '0' ORDER BY SeqIndex";
|
|
|
sqlstr = String.Format(sqlstr, Mesnac.Basic.LanguageHelper.PleaseSelect);
|
|
|
return dbHelper.GetDataTableBySql(sqlstr);
|
|
|
|
|
|
|
|
|
}
|
|
|
public static List<BasUserModel> GetRoleList()
|
|
|
{
|
|
|
DataTable userTable = GetRoleDataTable();
|
|
|
List<BasUserModel> lst = new List<BasUserModel>();
|
|
|
|
|
|
foreach (DataRow row in userTable.Rows)
|
|
|
{
|
|
|
BasUserModel user = new BasUserModel
|
|
|
{
|
|
|
UID = Mesnac.Basic.DataProcessor.RowValue(row, "SeqIndex", String.Empty),
|
|
|
RoleGUID = Mesnac.Basic.DataProcessor.RowValue(row, "GUID", String.Empty),
|
|
|
RoleName = Mesnac.Basic.DataProcessor.RowValue(row, "RoleName", String.Empty)
|
|
|
};
|
|
|
lst.Add(user);
|
|
|
}
|
|
|
return lst;
|
|
|
}
|
|
|
}
|
|
|
}
|