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.

219 lines
9.4 KiB

2 weeks ago
  1. using NFine.Code;
  2. using NFine.Domain.Entity.SystemManage;
  3. using NFine.Domain.IRepository.SystemManage;
  4. using NFine.Repository.SystemManage;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Data;
  9. using System.Data.Common;
  10. using System.Text;
  11. using NFine.Data.Extensions;
  12. namespace NFine.Application.SystemManage
  13. {
  14. public class UserApp
  15. {
  16. private IUserRepository service = new UserRepository();
  17. private UserLogOnApp userLogOnApp = new UserLogOnApp();
  18. public List<UserEntity> GetList()
  19. {
  20. return service.IQueryable().OrderBy(t => t.F_CreatorTime).ToList();
  21. }
  22. public List<UserEntity> GetList(Pagination pagination, string keyword)
  23. {
  24. var expression = ExtLinq.True<UserEntity>();
  25. if (!string.IsNullOrEmpty(keyword))
  26. {
  27. expression = expression.And(t => t.F_Account.Contains(keyword));
  28. expression = expression.Or(t => t.F_RealName.Contains(keyword));
  29. expression = expression.Or(t => t.F_MobilePhone.Contains(keyword));
  30. }
  31. expression = expression.And(t => t.F_Account != "admin");
  32. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  33. {
  34. string UserCode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  35. expression = expression.And(t => t.F_Account== UserCode);
  36. }
  37. return service.FindList(expression, pagination);
  38. }
  39. public UserEntity GetForm(string keyValue)
  40. {
  41. if (keyValue == "SYS")
  42. keyValue = NFine.Code.OperatorProvider.Provider.GetCurrent().UserId;
  43. return service.FindEntity(keyValue);
  44. }
  45. public void DeleteForm(string keyValue)
  46. {
  47. service.DeleteForm(keyValue);
  48. }
  49. public void SubmitForm(UserEntity userEntity, UserLogOnEntity userLogOnEntity, string keyValue)
  50. {
  51. if (!string.IsNullOrEmpty(keyValue))
  52. {
  53. userEntity.Modify(keyValue);
  54. }
  55. else
  56. {
  57. userEntity.Create();
  58. }
  59. service.SubmitForm(userEntity, userLogOnEntity, keyValue);
  60. }
  61. public void UpdateForm(UserEntity userEntity)
  62. {
  63. service.Update(userEntity);
  64. }
  65. public UserEntity CheckLogin(string username, string password, string WorkPoint)
  66. {
  67. UserEntity userEntity = service.FindEntity(t => t.F_Account == username);
  68. if (userEntity != null)
  69. {
  70. if (userEntity.F_EnabledMark == true)
  71. {
  72. UserLogOnEntity userLogOnEntity = userLogOnApp.GetForm(userEntity.F_Id);
  73. string dbPassword = Md5.md5(DESEncrypt.Encrypt(password.ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower();
  74. if (dbPassword == userLogOnEntity.F_UserPassword)
  75. {
  76. DateTime lastVisitTime = DateTime.Now;
  77. int LogOnCount = (userLogOnEntity.F_LogOnCount).ToInt() + 1;
  78. if (userLogOnEntity.F_LastVisitTime != null)
  79. {
  80. userLogOnEntity.F_PreviousVisitTime = userLogOnEntity.F_LastVisitTime.ToDate();
  81. }
  82. userLogOnEntity.F_LastVisitTime = lastVisitTime;
  83. userLogOnEntity.F_LogOnCount = LogOnCount;
  84. userLogOnApp.UpdateForm(userLogOnEntity);
  85. return userEntity;
  86. }
  87. else
  88. {
  89. throw new Exception("密码不正确,请重新输入");
  90. }
  91. }
  92. else
  93. {
  94. throw new Exception("账户被系统锁定,请联系管理员");
  95. }
  96. }
  97. else
  98. {
  99. throw new Exception("账户不存在,请重新输入");
  100. }
  101. }
  102. public string ICSPOReportLimit(string username, string password, string WorkPoint, string UserCode)
  103. {
  104. string cPTCode = "";
  105. string sqlU9 = "SELECT DBIpAddress,DBName FROM dbo.Sys_DataBase WHERE DBSourceName='ERP'";
  106. DataTable dtU9 = SqlHelper.GetDataTableBySql(sqlU9);
  107. string U9IP = dtU9.Rows[0]["DBIpAddress"].ToString();
  108. string DBName = dtU9.Rows[0]["DBName"].ToString();
  109. string sql = string.Format(@"select OpeUserCode
  110. From [{0}].{1}.dbo.ICSPOReportLimit
  111. where ViewUserCode='{2}' and ORGCode='{3}'", U9IP, DBName, UserCode,WorkPoint);
  112. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  113. for (int i = 0; i < dt.Rows.Count; i++)
  114. {
  115. cPTCode += "'" + dt.Rows[i]["OpeUserCode"].ToString() + "',";
  116. }
  117. return cPTCode;
  118. }
  119. public void AgentUserAndVenCode()
  120. {
  121. string sql = @"SELECT UserCode,UserName,WorkPointCode FROM dbo.Sys_User
  122. WHERE UserCode NOT IN (SELECT F_Account FROM dbo.Sys_SRM_User)";
  123. DataTable dtUser = SqlHelper.GetDataTableBySql(sql);
  124. foreach (DataRow dr in dtUser.Rows)
  125. {
  126. string sqlUser = string.Empty;
  127. string NewGuid = Common.GuId();
  128. sqlUser = @"INSERT INTO dbo.Sys_SRM_User
  129. ( F_Id ,F_Account ,F_RealName ,F_NickName ,
  130. F_RoleId ,F_IsAdministrator , F_EnabledMark ,
  131. F_CreatorTime ,F_CreatorUserId ,F_Location ,
  132. F_VenCode)
  133. SELECT '"+ NewGuid + @"',UserCode,UserName,UserName,
  134. '5130ce87-a5ed-409f-b035-9277f65e1d7f',0,1,
  135. GETDATE(),'9f2ec079-7d0f-4fe2-90ab-8b09a8302aba','"+dr["WorkPointCode"].ToString() +@"',''
  136. FROM dbo.Sys_User WHERE UserCode='"+dr["UserCode"].ToString()+ "' and WorkPointCode='" + dr["WorkPointCode"].ToString() + @"'";
  137. try
  138. {
  139. SqlHelper.ExecuteNonQuery(sqlUser);
  140. }
  141. catch (Exception ex)
  142. {
  143. throw new Exception(ex.Message);
  144. }
  145. string UserSecretkey = Md5.md5(Common.CreateNo(), 16).ToLower();
  146. string pwd = Md5.md5(DESEncrypt.Encrypt(Md5.md5("123456", 32).ToLower(), UserSecretkey).ToLower(), 32).ToLower();
  147. sqlUser = @"INSERT INTO dbo.Sys_SRM_UserLogOn
  148. ( F_Id ,F_UserId ,F_UserPassword ,F_UserSecretkey
  149. )
  150. VALUES ( '" + NewGuid + @"','" + NewGuid + @"','"+ pwd + "','" + UserSecretkey + "')";
  151. try
  152. {
  153. SqlHelper.ExecuteNonQuery(sqlUser);
  154. }
  155. catch (Exception ex)
  156. {
  157. throw new Exception(ex.Message);
  158. }
  159. }
  160. //供应商同步
  161. sql = @"SELECT cVenCode,cVenName,WorkPoint FROM dbo.ICSVendor
  162. WHERE cVenCode NOT IN (SELECT F_Account FROM dbo.Sys_SRM_User)";
  163. DataTable dtVendor = SqlHelper.GetDataTableBySql(sql);
  164. foreach (DataRow dr in dtVendor.Rows)
  165. {
  166. string sqlUser = string.Empty;
  167. string NewGuid = Common.GuId();
  168. sqlUser = @"INSERT INTO dbo.Sys_SRM_User
  169. ( F_Id ,F_Account ,F_RealName ,F_NickName ,
  170. F_RoleId ,F_IsAdministrator , F_EnabledMark ,
  171. F_CreatorTime ,F_CreatorUserId ,F_Location ,
  172. F_VenCode)
  173. SELECT '" + NewGuid + @"',cVenCode,cVenName,cVenName,
  174. '2691AB91-3010-465F-8D92-60A97425A45E',0,1,
  175. GETDATE(),'9f2ec079-7d0f-4fe2-90ab-8b09a8302aba','" + dr["WorkPoint"].ToString() + @"',cVenCode
  176. FROM dbo.ICSVendor WHERE cVenCode='" + dr["cVenCode"].ToString() + "' and WorkPoint='" + dr["WorkPoint"].ToString() + @"'";
  177. try
  178. {
  179. SqlHelper.ExecuteNonQuery(sqlUser);
  180. }
  181. catch (Exception ex)
  182. {
  183. throw new Exception(ex.Message);
  184. }
  185. string UserSecretkey = Md5.md5(Common.CreateNo(), 16).ToLower();
  186. string pwd = Md5.md5(DESEncrypt.Encrypt(Md5.md5("123456", 32).ToLower(), UserSecretkey).ToLower(), 32).ToLower();
  187. sqlUser = @"INSERT INTO dbo.Sys_SRM_UserLogOn
  188. ( F_Id ,F_UserId ,F_UserPassword ,F_UserSecretkey
  189. )
  190. VALUES ( '" + NewGuid + @"','" + NewGuid + @"','" + pwd + "','" + UserSecretkey + "')";
  191. try
  192. {
  193. SqlHelper.ExecuteNonQuery(sqlUser);
  194. }
  195. catch (Exception ex)
  196. {
  197. throw new Exception(ex.Message);
  198. }
  199. }
  200. //供应商同步
  201. }
  202. }
  203. }