Exemplo n.º 1
0
        public ResultModel ValidateAuth(NFMT.Common.UserModel user, Model.StockIn stockIn)
        {
            NFMT.Common.ResultModel result = new ResultModel();

            //验证权限
            //1:验证是否有己方公司权限
            //3:以上条件下是否具有内外贸权限
            //5:以上条件下是否具有品种权限

            NFMT.User.DAL.AuthGroupDAL dal = new User.DAL.AuthGroupDAL();

            result = dal.LoadByEmpId(user.EmpId);
            if (result.ResultStatus != 0)
                return result;

            List<NFMT.User.Model.AuthGroup> authGroups = result.ReturnValue as List<NFMT.User.Model.AuthGroup>;

            if (authGroups == null)
            {
                result.ResultStatus = -1;
                result.Message = "权限验证失败";
                return result;
            }

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("当前用户不拥有");

            IEnumerable<NFMT.User.Model.AuthGroup> temps = new List<User.Model.AuthGroup>();

            //验证是否有己方公司权限
            temps = authGroups.FindAll(temp => (temp.CorpId == stockIn.CorpId || temp.CorpId == 0));

            NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == stockIn.CorpId);
            if (corp == null || corp.CorpId <= 0)
            {
                result.ResultStatus = -1;
                result.Message = "己方公司不存在";
                return result;
            }

            if (temps == null || temps.Count() == 0)
            {
                result.ResultStatus = -1;
                result.Message = string.Format("当前用户不拥有[{0}]权限", corp.CorpName);
                return result;
            }

            sb.AppendFormat("[{0}]", corp.CorpName);

            NFMT.WareHouse.CustomTypeEnum customsType = (NFMT.WareHouse.CustomTypeEnum)stockIn.CustomType;
            sb.AppendFormat(" {0} ", customsType.ToString("F"));
            NFMT.Data.Model.Asset asset = NFMT.Data.BasicDataProvider.Assets.FirstOrDefault(temp => temp.AssetId == stockIn.AssetId);
            if (asset == null || asset.AssetId <= 0)
            {
                result.ResultStatus = -1;
                result.Message = "所选品种不存在";
                return result;
            }
            sb.AppendFormat(" {0} ", asset.AssetName);
            sb.Append("权限");

            //1:以上条件下是否具有内外贸权限
            //temps = temps.Where(temp => temp.TradeBorder == stockIn.CustomType || temp.TradeBorder == 0);

            authGroups = new List<User.Model.AuthGroup>();
            foreach (NFMT.User.Model.AuthGroup auth in temps)
            {
                NFMT.Contract.TradeBorderEnum tradeBorder = (NFMT.Contract.TradeBorderEnum)auth.TradeBorder;
                if (auth.TradeBorder == 0)
                    authGroups.Add(auth);
                else if (customsType == CustomTypeEnum.关外 && tradeBorder == Contract.TradeBorderEnum.外贸)
                    authGroups.Add(auth);
                else if (customsType == CustomTypeEnum.关内 && tradeBorder == Contract.TradeBorderEnum.内贸)
                    authGroups.Add(auth);
            }
            temps = authGroups;
            if (temps == null || temps.Count() == 0)
            {
                result.ResultStatus = -1;
                result.Message = sb.ToString();
                return result;
            }

            //2:以上条件下是否具有品种权限
            temps = authGroups.Where(temp => temp.AssetId == stockIn.AssetId || temp.AssetId == 0);
            if (temps == null || temps.Count() == 0)
            {
                result.ResultStatus = -1;
                result.Message = sb.ToString();
                return result;
            }

            if (temps.Count() > 0)
            {
                result.ResultStatus = 0;
                result.Message = "满足权限";
            }

            return result;
        }
Exemplo n.º 2
0
        internal ResultModel ValidateAuth(NFMT.Common.UserModel user, Contract.Model.Contract contract, List<Model.ContractCorporationDetail> outCorps, List<Model.ContractCorporationDetail> inCorps)
        {
            NFMT.Common.ResultModel result = new ResultModel();

            //验证权限
            //1:验证是否有己方公司权限
            //2:验证在第一个己方公司下是否有购销权限
            //3:以上条件下是否具有内外贸权限
            //4:以上条件下是否具有长零单权限
            //5:以上条件下是否具有品种权限
            //6:以上条件下是否具有内外部交易权限

            NFMT.User.DAL.AuthGroupDAL dal = new User.DAL.AuthGroupDAL();

            result = dal.LoadByEmpId(user.EmpId);
            if (result.ResultStatus != 0)
                return result;

            List<NFMT.User.Model.AuthGroup> authGroups = result.ReturnValue as List<NFMT.User.Model.AuthGroup>;
            List<NFMT.User.Model.AuthGroup> validates = new List<NFMT.User.Model.AuthGroup>();

            if (authGroups == null)
            {
                result.ResultStatus = -1;
                result.Message = "权限验证失败";
                return result;
            }

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("当前用户不拥有");

            IEnumerable<NFMT.User.Model.AuthGroup> temps = new List<User.Model.AuthGroup>();

            //验证是否有己方公司权限
            foreach (ContractCorporationDetail c in inCorps)
            {
                temps = authGroups.FindAll(temp => (temp.CorpId == c.CorpId || temp.CorpId == 0));

                NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == c.CorpId);
                if (corp == null || corp.CorpId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "己方公司不存在";
                    return result;
                }

                if (temps == null || temps.Count() == 0)
                {
                    result.ResultStatus = -1;
                    result.Message = string.Format("当前用户不拥有[{0}]权限", corp.CorpName);
                    return result;
                }
                else
                {
                    validates.AddRange(temps);
                    sb.AppendFormat("[{0}]", corp.CorpName);
                }
            }

            NFMT.Contract.TradeDirectionEnum tradeDirection = (TradeDirectionEnum)contract.TradeDirection;
            sb.AppendFormat(" {0} ", tradeDirection.ToString("F"));

            NFMT.Contract.TradeBorderEnum tradeBorder = (TradeBorderEnum)contract.TradeBorder;
            sb.AppendFormat(" {0} ", tradeBorder.ToString("F"));

            NFMT.Contract.ContractLimitEnum contractLimit = (ContractLimitEnum)contract.ContractLimit;
            sb.AppendFormat(" {0} ", contractLimit.ToString("G"));

            NFMT.Data.Model.Asset asset = NFMT.Data.BasicDataProvider.Assets.FirstOrDefault(temp => temp.AssetId == contract.AssetId);
            if (asset == null || asset.AssetId <= 0)
            {
                result.ResultStatus = -1;
                result.Message = "所选品种不存在";
                return result;
            }
            sb.AppendFormat(" {0} ", asset.AssetName);

            //NFMT.Contract.ContractInOutEnum contractInOut = (ContractInOutEnum)contract.ContractSide;
            //sb.AppendFormat(" {0} ", contractInOut.ToString("G"));

            sb.Append("权限");

            //验证在第一个己方公司下是否有购销权限
            temps = new List<User.Model.AuthGroup>();
            authGroups = validates;
            temps = authGroups.Where(temp => temp.TradeDirection == contract.TradeDirection || temp.TradeDirection == 0);
            if (temps == null || temps.Count() == 0)
            {
                result.ResultStatus = -1;
                result.Message = sb.ToString();
                return result;
            }
            authGroups = temps.ToList();

            //3:以上条件下是否具有内外贸权限
            temps = authGroups.Where(temp => temp.TradeBorder == contract.TradeBorder || temp.TradeBorder == 0);
            if (temps == null || temps.Count() == 0)
            {
                result.ResultStatus = -1;
                result.Message = sb.ToString();
                return result;
            }
            authGroups = temps.ToList();

            //4:以上条件下是否具有长零单权限
            temps = authGroups.Where(temp => temp.ContractLimit == contract.ContractLimit || temp.ContractLimit == 0);
            if (temps == null || temps.Count() == 0)
            {
                result.ResultStatus = -1;
                result.Message = sb.ToString();
                return result;
            }
            authGroups = temps.ToList();

            //5:以上条件下是否具有品种权限
            temps = authGroups.Where(temp => temp.AssetId == contract.AssetId || temp.AssetId == 0);
            if (temps == null || temps.Count() == 0)
            {
                result.ResultStatus = -1;
                result.Message = sb.ToString();
                return result;
            }
            authGroups = temps.ToList();

            //6:以上条件下是否具有内外部交易权限
            //temps = authGroups.Where(temp => temp.ContractInOut == contract.ContractSide || temp.ContractInOut==0);
            //if (temps == null || temps.Count() == 0)
            //{
            //    result.ResultStatus = -1;
            //    result.Message = sb.ToString();
            //    return result;
            //}
            //authGroups = temps.ToList();

            return result;
        }