123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- using Sugar.Enties;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace WebAPIBase.NetCore.BusinessCore
- {
- public class LicenceCheck : DbContext<SystemUser>
- {
- public void InitLicence(string connString, string VerName, string VerMsg, string LicenceType)
- {
- RightModel.InitRightModelList(VerName, VerMsg);
- 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";
- Db.Ado.ExecuteCommand(commandText);
- commandText = "select LicenceVerMsg from LicenceInfo";
- var dataTable = Db.Ado.GetDataTable(commandText);
- if (dataTable.Rows.Count != 0 && !(string.Concat(dataTable.Rows[0]["LicenceVerMsg"], "") != VerMsg))
- {
- return;
- }
- commandText = ((dataTable.Rows.Count != 0) ? string.Format("update LicenceInfo set LicenceVerMsg = '{0}'", VerMsg.Replace("'", "''")) : string.Format("insert into LicenceInfo (LicenceVerMsg) values ('{0}')", VerMsg.Replace("'", "''")));
- Db.Ado.ExecuteCommand(commandText);
- ArrayList arrayList = new ArrayList();
- ArrayList rootFunctionStructureByValid = RightModel.GetRootFunctionStructureByValid(isValid: true);
- foreach (string item in rootFunctionStructureByValid)
- {
- 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(",", "','"));
- arrayList.Add(commandText);
- }
- rootFunctionStructureByValid = RightModel.GetRootFunctionStructureByValid(isValid: false);
- foreach (string item2 in rootFunctionStructureByValid)
- {
- 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(",", "','"));
- arrayList.Add(commandText);
- }
- if (VerName.ToLower() == "v35")
- {
- RightModelItem itemByKey = RightModel.GetItemByKey("UJ");
- RightModelItem itemByKey2 = RightModel.GetItemByKey("UO");
- if (itemByKey != null && itemByKey2 != null && !itemByKey.IsValid && itemByKey2.IsValid)
- {
- commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('62','6200','620001')";
- arrayList.Add(commandText);
- }
- }
- if (VerName.ToLower() == "v50")
- {
- RightModelItem itemByKey = RightModel.GetItemByKey("UJ");
- RightModelItem itemByKey2 = RightModel.GetItemByKey("UO");
- if (itemByKey != null && itemByKey2 != null && !itemByKey.IsValid && itemByKey2.IsValid)
- {
- commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('62','6200','620001')";
- arrayList.Add(commandText);
- }
- }
- if (VerName.ToLower() == "v55")
- {
- RightModelItem itemByKey = RightModel.GetItemByKey("UJ");
- RightModelItem itemByKey2 = RightModel.GetItemByKey("UO");
- if (itemByKey != null && itemByKey2 != null && !itemByKey.IsValid && itemByKey2.IsValid)
- {
- commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('62','6200','620001')";
- arrayList.Add(commandText);
- }
- RightModelItem itemByKey3 = RightModel.GetItemByKey("UQ");
- if (itemByKey3 != null && itemByKey3.IsValid)
- {
- commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('670204')";
- arrayList.Add(commandText);
- }
- }
- if (VerName.ToLower() == "v56")
- {
- RightModelItem itemByKey = RightModel.GetItemByKey("UJ");
- RightModelItem itemByKey2 = RightModel.GetItemByKey("UO");
- if (itemByKey != null && itemByKey2 != null && !itemByKey.IsValid && itemByKey2.IsValid)
- {
- commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('62','6200','620001')";
- arrayList.Add(commandText);
- }
- RightModelItem itemByKey3 = RightModel.GetItemByKey("UQ");
- if (itemByKey3 != null && itemByKey3.IsValid)
- {
- commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('670204')";
- arrayList.Add(commandText);
- }
- }
- if (VerName.ToLower() == "v561")
- {
- RightModelItem itemByKey = RightModel.GetItemByKey("UJ");
- RightModelItem itemByKey2 = RightModel.GetItemByKey("UO");
- if (itemByKey != null && itemByKey2 != null && !itemByKey.IsValid && itemByKey2.IsValid)
- {
- commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('62','6200','620001')";
- arrayList.Add(commandText);
- }
- RightModelItem itemByKey3 = RightModel.GetItemByKey("UQ");
- if (itemByKey3 != null && itemByKey3.IsValid)
- {
- commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('670204')";
- arrayList.Add(commandText);
- }
- }
- if (VerName.ToLower() == "v60")
- {
- RightModelItem itemByKey = RightModel.GetItemByKey("UJ");
- RightModelItem itemByKey2 = RightModel.GetItemByKey("UO");
- if (itemByKey != null && itemByKey2 != null && !itemByKey.IsValid && itemByKey2.IsValid)
- {
- commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('62','6200','620001')";
- arrayList.Add(commandText);
- }
- RightModelItem itemByKey3 = RightModel.GetItemByKey("UQ");
- if (itemByKey3 != null && itemByKey3.IsValid)
- {
- commandText = "update Functionstructure set IsAvailable = 0 where FunctionStructureCode in ('670204')";
- arrayList.Add(commandText);
- }
- }
- commandText = "update Functionstructure set IsAvailable=1 where FunctionStructureCode in ('{0}')";
- commandText = string.Format(commandText, RightModel.UnavailableFunctionStructureCodes.Replace(",", "','"));
- arrayList.Add(commandText);
- 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)";
- arrayList.Add(value);
- try
- {
- Db.BeginTran();
- foreach (var item in arrayList)
- {
- Db.Ado.ExecuteCommand(item.ToString());
- }
- Db.CommitTran();
- }
- catch (Exception ex)
- {
- Db.RollbackTran();
- throw;
- }
- }
- public static void DeleteInvalidFunctionStructure(string VerMsg)
- {
- ArrayList arrayList = new ArrayList();
- ArrayList rootFunctionStructureByValid = RightModel.GetRootFunctionStructureByValid(isValid: false);
- foreach (KeyValuePair<string, FdcFunction> function in FdcUnitStructure.Instance.FunctionList)
- {
- foreach (string item in rootFunctionStructureByValid)
- {
- if (function.Key.StartsWith(item))
- {
- arrayList.Add(function.Key);
- break;
- }
- }
- }
- foreach (string item2 in arrayList)
- {
- if (VerMsg.IndexOf("UO") < 0 || (!(item2 == "62") && !(item2 == "6200") && !(item2 == "620001")))
- {
- FdcUnitStructure.Instance.FunctionList.Remove(item2);
- }
- }
- }
- }
- }
|