LicenceCheck.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using Sugar.Enties;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace WebAPIBase.NetCore.BusinessCore
  9. {
  10. public class LicenceCheck : DbContext<SystemUser>
  11. {
  12. public void InitLicence(string connString, string VerName, string VerMsg, string LicenceType)
  13. {
  14. RightModel.InitRightModelList(VerName, VerMsg);
  15. string commandText = "IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[LicenceInfo]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\r\nCREATE TABLE [dbo].[LicenceInfo](\r\n LicenceVerMsg varchar(2000)\r\n)\r\n";
  16. Db.Ado.ExecuteCommand(commandText);
  17. commandText = "select LicenceVerMsg from LicenceInfo";
  18. var dataTable = Db.Ado.GetDataTable(commandText);
  19. if (dataTable.Rows.Count != 0 && !(string.Concat(dataTable.Rows[0]["LicenceVerMsg"], "") != VerMsg))
  20. {
  21. return;
  22. }
  23. commandText = ((dataTable.Rows.Count != 0) ? string.Format("update LicenceInfo set LicenceVerMsg = '{0}'", VerMsg.Replace("'", "''")) : string.Format("insert into LicenceInfo (LicenceVerMsg) values ('{0}')", VerMsg.Replace("'", "''")));
  24. Db.Ado.ExecuteCommand(commandText);
  25. ArrayList arrayList = new ArrayList();
  26. ArrayList rootFunctionStructureByValid = RightModel.GetRootFunctionStructureByValid(isValid: true);
  27. foreach (string item in rootFunctionStructureByValid)
  28. {
  29. commandText = string.Format("update Functionstructure set IsAvailable = {0} where FunctionStructureCode like '{1}%' and isnull(IsAvailable,0) <> {0} and FunctionStructureCode not in ('{2}')", 0, item.Replace("'", "''"), RightModel.UnavailableFunctionStructureCodes.Replace(",", "','"));
  30. arrayList.Add(commandText);
  31. }
  32. rootFunctionStructureByValid = RightModel.GetRootFunctionStructureByValid(isValid: false);
  33. foreach (string item2 in rootFunctionStructureByValid)
  34. {
  35. commandText = string.Format("update Functionstructure set IsAvailable = {0} where FunctionStructureCode like '{1}%' and isnull(IsAvailable,0) <> {0} and FunctionStructureCode not in ('{2}')", 1, item2.Replace("'", "''"), RightModel.UnavailableFunctionStructureCodes.Replace(",", "','"));
  36. arrayList.Add(commandText);
  37. }
  38. if (VerName.ToLower() == "v35")
  39. {
  40. RightModelItem itemByKey = RightModel.GetItemByKey("UJ");
  41. RightModelItem itemByKey2 = RightModel.GetItemByKey("UO");
  42. if (itemByKey != null && itemByKey2 != null && !itemByKey.IsValid && itemByKey2.IsValid)
  43. {
  44. commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('62','6200','620001')";
  45. arrayList.Add(commandText);
  46. }
  47. }
  48. if (VerName.ToLower() == "v50")
  49. {
  50. RightModelItem itemByKey = RightModel.GetItemByKey("UJ");
  51. RightModelItem itemByKey2 = RightModel.GetItemByKey("UO");
  52. if (itemByKey != null && itemByKey2 != null && !itemByKey.IsValid && itemByKey2.IsValid)
  53. {
  54. commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('62','6200','620001')";
  55. arrayList.Add(commandText);
  56. }
  57. }
  58. if (VerName.ToLower() == "v55")
  59. {
  60. RightModelItem itemByKey = RightModel.GetItemByKey("UJ");
  61. RightModelItem itemByKey2 = RightModel.GetItemByKey("UO");
  62. if (itemByKey != null && itemByKey2 != null && !itemByKey.IsValid && itemByKey2.IsValid)
  63. {
  64. commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('62','6200','620001')";
  65. arrayList.Add(commandText);
  66. }
  67. RightModelItem itemByKey3 = RightModel.GetItemByKey("UQ");
  68. if (itemByKey3 != null && itemByKey3.IsValid)
  69. {
  70. commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('670204')";
  71. arrayList.Add(commandText);
  72. }
  73. }
  74. if (VerName.ToLower() == "v56")
  75. {
  76. RightModelItem itemByKey = RightModel.GetItemByKey("UJ");
  77. RightModelItem itemByKey2 = RightModel.GetItemByKey("UO");
  78. if (itemByKey != null && itemByKey2 != null && !itemByKey.IsValid && itemByKey2.IsValid)
  79. {
  80. commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('62','6200','620001')";
  81. arrayList.Add(commandText);
  82. }
  83. RightModelItem itemByKey3 = RightModel.GetItemByKey("UQ");
  84. if (itemByKey3 != null && itemByKey3.IsValid)
  85. {
  86. commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('670204')";
  87. arrayList.Add(commandText);
  88. }
  89. }
  90. if (VerName.ToLower() == "v561")
  91. {
  92. RightModelItem itemByKey = RightModel.GetItemByKey("UJ");
  93. RightModelItem itemByKey2 = RightModel.GetItemByKey("UO");
  94. if (itemByKey != null && itemByKey2 != null && !itemByKey.IsValid && itemByKey2.IsValid)
  95. {
  96. commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('62','6200','620001')";
  97. arrayList.Add(commandText);
  98. }
  99. RightModelItem itemByKey3 = RightModel.GetItemByKey("UQ");
  100. if (itemByKey3 != null && itemByKey3.IsValid)
  101. {
  102. commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('670204')";
  103. arrayList.Add(commandText);
  104. }
  105. }
  106. if (VerName.ToLower() == "v60")
  107. {
  108. RightModelItem itemByKey = RightModel.GetItemByKey("UJ");
  109. RightModelItem itemByKey2 = RightModel.GetItemByKey("UO");
  110. if (itemByKey != null && itemByKey2 != null && !itemByKey.IsValid && itemByKey2.IsValid)
  111. {
  112. commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('62','6200','620001')";
  113. arrayList.Add(commandText);
  114. }
  115. RightModelItem itemByKey3 = RightModel.GetItemByKey("UQ");
  116. if (itemByKey3 != null && itemByKey3.IsValid)
  117. {
  118. commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('670204')";
  119. arrayList.Add(commandText);
  120. }
  121. }
  122. commandText = "update Functionstructure set IsAvailable=1 where FunctionStructureCode in ('{0}')";
  123. commandText = string.Format(commandText, RightModel.UnavailableFunctionStructureCodes.Replace(",", "','"));
  124. arrayList.Add(commandText);
  125. string value = "delete roleoperation where operationcode not in (select functionstructurecode from functionstructure where isAvailable = 0)\r\ndelete stationfunctionarea where stationfunctioncode in (select stationfunctioncode from stationfunction where functionstructurecode not in (select functionstructurecode from functionstructure where isAvailable = 0))\r\ndelete stationfunction where functionstructurecode not in (select functionstructurecode from functionstructure where isAvailable = 0)";
  126. arrayList.Add(value);
  127. try
  128. {
  129. Db.BeginTran();
  130. foreach (var item in arrayList)
  131. {
  132. Db.Ado.ExecuteCommand(item.ToString());
  133. }
  134. Db.CommitTran();
  135. }
  136. catch (Exception ex)
  137. {
  138. Db.RollbackTran();
  139. throw;
  140. }
  141. }
  142. public static void DeleteInvalidFunctionStructure(string VerMsg)
  143. {
  144. ArrayList arrayList = new ArrayList();
  145. ArrayList rootFunctionStructureByValid = RightModel.GetRootFunctionStructureByValid(isValid: false);
  146. foreach (KeyValuePair<string, FdcFunction> function in FdcUnitStructure.Instance.FunctionList)
  147. {
  148. foreach (string item in rootFunctionStructureByValid)
  149. {
  150. if (function.Key.StartsWith(item))
  151. {
  152. arrayList.Add(function.Key);
  153. break;
  154. }
  155. }
  156. }
  157. foreach (string item2 in arrayList)
  158. {
  159. if (VerMsg.IndexOf("UO") < 0 || (!(item2 == "62") && !(item2 == "6200") && !(item2 == "620001")))
  160. {
  161. FdcUnitStructure.Instance.FunctionList.Remove(item2);
  162. }
  163. }
  164. }
  165. }
  166. }