using ICSSoft.Common; using ICSSoft.Entity; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; namespace ICSSoft.DataProject { /// /// 使用中 /// 获取用户权限 /// public class ICSUserPowerService { private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"]; private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"]; public DataTable GetUserPower(ICSUserPower info) { DataTable dt = null; //string json = ""; var language = LanguageHelper.GetName("WMSAPIInfo"); if (info == null) { throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!" } string res = string.Empty; SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString); conn.Open(); SqlTransaction sqlTran = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Transaction = sqlTran; cmd.Connection = conn; try { string sql = string.Empty; if (string.IsNullOrWhiteSpace(info.UserId)) throw new Exception(language.GetNameByCode("WMSAPIInfo176"));//"用户不能为空!"); if (string.IsNullOrWhiteSpace(info.MenuCode)) throw new Exception(language.GetNameByCode("WMSAPIInfo177"));//"菜单不能为空!"); if (string.IsNullOrWhiteSpace(info.WorkPoint)) throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!" sql = @"IF EXISTS(SELECT F_Id FROM Sys_SRM_User WHERE F_IsAdministrator='1' AND F_Id='{0}' AND F_Location='{2}') BEGIN SELECT d.F_EnCode AS ButtonName,d.F_FullName AS ButtonText FROM Sys_SRM_ModuleButton d INNER JOIN Sys_SRM_Module e ON d.F_ModuleId=e.F_Id WHERE e.F_FullName='{1}' END ELSE BEGIN SELECT d.F_EnCode AS ButtonName,d.F_FullName AS ButtonText FROM Sys_SRM_User a INNER JOIN Sys_SRM_Role b ON a.F_RoleId=b.F_Id INNER JOIN Sys_SRM_RoleAuthorize c ON a.F_RoleId=c.F_ObjectId INNER JOIN Sys_SRM_ModuleButton d ON c.F_ItemId=d.F_Id INNER JOIN Sys_SRM_Module e ON d.F_ModuleId=e.F_Id WHERE a.F_Id='{0}' AND e.F_FullName='{1}' AND a.F_Location='{2}' END"; sql = string.Format(sql, info.UserId, info.MenuCode, info.WorkPoint); dt = DBHelper.SQlReturnData(sql, cmd); //json = JsonConvert.SerializeObject(dt); cmd.Transaction.Commit(); return dt; } catch (Exception ex) { if (cmd.Transaction != null) cmd.Transaction.Rollback(); log.Error(ex.Message); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } public DataTable GetExtensionEnable(ICSWorkPoint info) { DataTable dt = null; //string json = ""; var language = LanguageHelper.GetName("WMSAPIInfo"); if (info == null) { throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!" } string res = string.Empty; SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString); conn.Open(); SqlTransaction sqlTran = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Transaction = sqlTran; cmd.Connection = conn; try { string sql = string.Empty; if (string.IsNullOrWhiteSpace(info.WorkPointCode)) throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!" sql = @"SELECT ID,ColCode,ColName,Enable,MTIME,MUSER,MUSERName,WorkPoint,EATTRIBUTE1 FROM ICSExtensionEnable WHERE WorkPoint='{0}'and Enable='1'"; sql = string.Format(sql, info.WorkPointCode); dt = DBHelper.SQlReturnData(sql, cmd); //json = JsonConvert.SerializeObject(dt); cmd.Transaction.Commit(); return dt; } catch (Exception ex) { if (cmd.Transaction != null) cmd.Transaction.Rollback(); log.Error(ex.Message); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } } }