纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
5.3 KiB

3 years ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Net.Http;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace ICSSoft.DataProject
  13. {
  14. /// <summary>
  15. /// 使用中
  16. /// 获取用户权限
  17. /// </summary>
  18. public class ICSUserPowerService
  19. {
  20. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  21. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
  22. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  23. public DataTable GetUserPower(ICSUserPower info)
  24. {
  25. DataTable dt = null;
  26. //string json = "";
  27. if (info == null)
  28. {
  29. throw new Exception("传送数据为空!");
  30. }
  31. string res = string.Empty;
  32. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  33. conn.Open();
  34. SqlTransaction sqlTran = conn.BeginTransaction();
  35. SqlCommand cmd = new SqlCommand();
  36. cmd.Transaction = sqlTran;
  37. cmd.Connection = conn;
  38. try
  39. {
  40. string sql = string.Empty;
  41. if (string.IsNullOrWhiteSpace(info.UserId))
  42. throw new Exception("用户不能为空!");
  43. if (string.IsNullOrWhiteSpace(info.MenuCode))
  44. throw new Exception("菜单不能为空!");
  45. if (string.IsNullOrWhiteSpace(info.WorkPoint))
  46. throw new Exception("站点不能为空!");
  47. sql = @"IF EXISTS(SELECT F_Id FROM Sys_SRM_User WHERE F_IsAdministrator='1' AND F_Id='{0}' AND F_Location='{2}')
  48. BEGIN
  49. SELECT d.F_EnCode AS ButtonName,d.F_FullName AS ButtonText
  50. FROM Sys_SRM_ModuleButton d
  51. INNER JOIN Sys_SRM_Module e ON d.F_ModuleId=e.F_Id
  52. WHERE e.F_FullName='{1}'
  53. END
  54. ELSE
  55. BEGIN
  56. SELECT d.F_EnCode AS ButtonName,d.F_FullName AS ButtonText
  57. FROM Sys_SRM_User a
  58. INNER JOIN Sys_SRM_Role b ON a.F_RoleId=b.F_Id
  59. INNER JOIN Sys_SRM_RoleAuthorize c ON a.F_RoleId=c.F_ObjectId
  60. INNER JOIN Sys_SRM_ModuleButton d ON c.F_ItemId=d.F_Id
  61. INNER JOIN Sys_SRM_Module e ON d.F_ModuleId=e.F_Id
  62. WHERE a.F_Id='{0}' AND e.F_FullName='{1}' AND a.F_Location='{2}'
  63. END";
  64. sql = string.Format(sql, info.UserId, info.MenuCode, info.WorkPoint);
  65. dt = DBHelper.SQlReturnData(sql, cmd);
  66. //json = JsonConvert.SerializeObject(dt);
  67. cmd.Transaction.Commit();
  68. return dt;
  69. }
  70. catch (Exception ex)
  71. {
  72. if (cmd.Transaction != null)
  73. cmd.Transaction.Rollback();
  74. log.Error(ex.Message);
  75. throw new Exception(ex.Message);
  76. }
  77. finally
  78. {
  79. if (conn.State == ConnectionState.Open)
  80. {
  81. conn.Close();
  82. }
  83. conn.Dispose();
  84. }
  85. }
  86. public DataTable GetExtensionEnable(ICSWorkPoint info)
  87. {
  88. DataTable dt = null;
  89. //string json = "";
  90. if (info == null)
  91. {
  92. throw new Exception("传送数据为空!");
  93. }
  94. string res = string.Empty;
  95. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  96. conn.Open();
  97. SqlTransaction sqlTran = conn.BeginTransaction();
  98. SqlCommand cmd = new SqlCommand();
  99. cmd.Transaction = sqlTran;
  100. cmd.Connection = conn;
  101. try
  102. {
  103. string sql = string.Empty;
  104. if (string.IsNullOrWhiteSpace(info.WorkPointCode))
  105. throw new Exception("站点不能为空!");
  106. sql = @"SELECT ID,ColCode,ColName,Enable,MTIME,MUSER,MUSERName,WorkPoint,EATTRIBUTE1
  107. FROM ICSExtensionEnable WHERE WorkPoint='{0}'";
  108. sql = string.Format(sql, info.WorkPointCode);
  109. dt = DBHelper.SQlReturnData(sql, cmd);
  110. //json = JsonConvert.SerializeObject(dt);
  111. cmd.Transaction.Commit();
  112. return dt;
  113. }
  114. catch (Exception ex)
  115. {
  116. if (cmd.Transaction != null)
  117. cmd.Transaction.Rollback();
  118. log.Error(ex.Message);
  119. throw new Exception(ex.Message);
  120. }
  121. finally
  122. {
  123. if (conn.State == ConnectionState.Open)
  124. {
  125. conn.Close();
  126. }
  127. conn.Dispose();
  128. }
  129. }
  130. }
  131. }