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 { /// /// Purview辅助类 /// public class PurviewHelper { #region 角色 /// /// 判断SeqIndex在角色表中是否存在 /// /// 要判断的SeqIndex /// 存在返回true,否则返回false 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; } /// /// 判断RoleName在角色表中是否存在 /// /// 要判断的RoleName /// 存在返回true,否则返回false 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 用户 /// /// 获取角色列表 /// /// 返回角色列表 public static DataTable GetRoleListForSelect() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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 DataTable GetClassListForSelect() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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); } /// /// 判断SeqIndex在用户表中是否存在 /// /// 要判断的SeqIndex /// 存在返回true,否则返回false 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; } /// /// 判断用户账号在用户表中是否存在 /// /// 要判断的用户账号 /// 存在返回true,否则返回false 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 /// /// 获取角色列表 /// /// 返回角色列表 public static DataTable GetRoleDataTable() { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.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 GetRoleList() { DataTable userTable = GetRoleDataTable(); List lst = new List(); 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; } } }