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.

142 lines
5.7 KiB

3 weeks ago
  1. using Newtonsoft.Json;
  2. using NFine.Code;
  3. using NFine.Domain._03_Entity.SystemManage;
  4. using NFine.Domain.Entity.SystemManage;
  5. using NFine.Domain.IRepository.SystemManage;
  6. using NFine.Repository;
  7. using NFine.Repository.SystemManage;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Linq;
  12. using System.Text;
  13. namespace NFine.Application.SystemManage
  14. {
  15. public class ModuleApp : RepositoryFactory<ModuleEntity>
  16. {
  17. private IModuleRepository service = new ModuleRepository();
  18. public List<ModuleEntity> GetList()
  19. {
  20. return service.IQueryable().Where(a => a.systems == "WMS").OrderBy(t => t.F_SortCode).ToList();
  21. }
  22. public List<ModuleEntity> GetListALL()
  23. {
  24. return service.IQueryable().Where(a => a.systems == "WMS" || a.systems == "SRM").OrderBy(t => t.F_SortCode).ToList();
  25. }
  26. public ModuleEntity GetForm(string keyValue)
  27. {
  28. return service.FindEntity(keyValue);
  29. }
  30. public void DeleteForm(string keyValue)
  31. {
  32. if (service.IQueryable().Count(t => t.F_ParentId.Equals(keyValue)) > 0)
  33. {
  34. throw new Exception("删除失败!操作的对象包含了下级数据。");
  35. }
  36. else
  37. {
  38. service.Delete(t => t.F_Id == keyValue);
  39. }
  40. }
  41. public void SubmitForm(ModuleEntity moduleEntity, string keyValue)
  42. {
  43. if (!string.IsNullOrEmpty(keyValue))
  44. {
  45. moduleEntity.Modify(keyValue);
  46. service.Update(moduleEntity);
  47. }
  48. else
  49. {
  50. moduleEntity.systems = "WMS";
  51. moduleEntity.Create();
  52. service.Insert(moduleEntity);
  53. }
  54. }
  55. public DataTable GetCondition(string SourceID)
  56. {
  57. string sql = @" SELECT con.ID IDStr, '0' IsNew, CSortSeq 排序,CCaption 条件名称,CFiledName 字段名称,CIndex 替代符号
  58. ,CValueBegin ,CValueEnd 2,CValueBegin ,CValueEnd ,CDataType AS ,CDataType AS Data
  59. from Sys_FormDataAction con
  60. where con.SourceID='" + SourceID + @"' order by CSortSeq";
  61. return Repository().FindTableBySql(sql);
  62. }
  63. public void SetDataAction(string SourceID, string List_Condition)
  64. {
  65. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  66. if (!string.IsNullOrEmpty(List_Condition) && List_Condition != "[]")
  67. {
  68. DataActionClass[] list = JsonConvert.DeserializeObject<DataActionClass[]>(List_Condition);
  69. if (list != null)
  70. {
  71. string sql = "";
  72. string sqldel = "";
  73. string sqldel2 = "";
  74. string sqlinsert = "";
  75. string sqlupdate = "";
  76. //@" delete from Sys_FormFilterCondition where SourceID='" + SourceID + @"' ";
  77. foreach (DataActionClass item in list)
  78. {
  79. if (item.ID == "")//insert
  80. {
  81. sqlinsert += @" INSERT INTO [Sys_FormDataAction]
  82. ([ID],[SourceID],[CSortSeq],[CCaption],[CFiledName],
  83. [CIndex],[CLogString],[CValueBegin],[CValueEnd],[CDataType])
  84. select newid(),'" + SourceID + "','" + item.CSortSeq + "','" + item.CCaption + "','" + item.CFiledName + @"'
  85. ,'" + item.CIndex + @"','" + item.CLogString + @"'
  86. ,'" + item.CValueBegin + "','" + item.CValueEnd + "','" + item.CDataType + "' ";
  87. }
  88. else//update
  89. {
  90. sqlupdate += @" update [Sys_FormDataAction]
  91. set
  92. [CSortSeq]=" + item.CSortSeq + @",
  93. [CCaption]='" + item.CCaption + @"',
  94. [CFiledName]='" + ReSetStringTosql(item.CFiledName) + @"',
  95. [CIndex]='" + item.CIndex + @"',
  96. [CLogString]='" + item.CLogString + @"',
  97. [CValueBegin]='" + item.CValueBegin + @"',
  98. [CValueEnd]='" + item.CValueEnd + @"',
  99. [CDataType]='" + item.CDataType + @"'
  100. where id = '" + item.ID + "' and SourceID = '" + SourceID + @"'
  101. ";
  102. sqldel += " and ID!='" + item.ID + "' ";
  103. }
  104. }
  105. sql = @" delete from Sys_FormDataAction where SourceID = '" + SourceID + @"' " +
  106. sqldel + sqlupdate + sqlinsert;
  107. StringBuilder sqlb = new StringBuilder(sql);
  108. Repository().ExecuteBySql(sqlb);
  109. }
  110. }
  111. else
  112. {
  113. string sql = @" delete from Sys_FormDataAction where SourceID='" + SourceID + @"'";
  114. StringBuilder sqlb = new StringBuilder(sql);
  115. Repository().ExecuteBySql(sqlb);
  116. }
  117. }
  118. private string ReSetStringTosql(string sql)
  119. {
  120. sql = sql.Replace("'", "''");
  121. sql = sql.Replace("\r", "\r ");
  122. sql = sql.Replace("\r\n", "\r\n ");
  123. sql = sql.Replace("\n", "\n ");
  124. return sql;
  125. }
  126. }
  127. }