Beispiel #1
0
        /// <summary>
        /// 计算当前这一行的数据,判断是否有指定权限
        /// </summary>
        /// <param name="fieldName">指定权限字段</param>
        /// <param name="table">权限配置数据</param>
        /// <param name="destBillDataRight">目标权限</param>s
        /// <param name="aEntity">数据行实体</param>
        /// <returns></returns>
        private static BillDataRight CalcCurrentEntityBillDataRight(string fieldName, BillRightInfo billRight, BillDataRight destBillDataRight, IEntityBase entity)
        {
            bool temp = false;
            int CreatedBy = -1;
            if (entity.FieldIsExists(BillRightInfo.CreatedByField) && !entity.FieldIsNull(BillRightInfo.CreatedByField) && entity.GetFieldValue<int>(BillRightInfo.CreatedByField) > 0)
            {
                CreatedBy = entity.GetFieldValue<int>(BillRightInfo.CreatedByField);
            }

            int OrganizationId = -1;
            if (entity.FieldIsExists(BillRightInfo.OrganizationIdField) && !entity.FieldIsNull(BillRightInfo.OrganizationIdField))
            {
                OrganizationId = entity.GetFieldValue<int>(BillRightInfo.OrganizationIdField);
            }

            string OrganizationCode = "XXXXXX";
            if (entity.FieldIsExists(BillRightInfo.OrganizationCodeField) && !entity.FieldIsNull(BillRightInfo.OrganizationCodeField))
            {
                OrganizationCode = entity.GetFieldValue<string>(BillRightInfo.OrganizationCodeField);
            }

            foreach (DataRow dr in billRight.DataRights.Rows)
            {
                //部门为空,则表示针对所有部门都是此角色
                bool bAllOrganization = dr.IsNull(RES.OrganizationId);

                bool bSameCreator = false;
                if (!dr.IsNull(RES.CreatedBy))
                {
                    bSameCreator = (CreatedBy == Convert.ToInt32(dr[RES.CreatedBy]));
                }

                bool bSameOrganizationId = false;
                if (!dr.IsNull(RES.OrganizationId))
                {
                    bSameOrganizationId = (OrganizationId == Convert.ToInt32(dr[RES.OrganizationId]));
                }

                bool bSameOrganizationCode = false;
                if (!dr.IsNull(RES.OrganizationCode))
                {
                    bSameOrganizationCode = OrganizationCode.StartsWith(dr[RES.OrganizationCode].ToString(), StringComparison.OrdinalIgnoreCase);
                }
                switch ((BillRightType)Convert.ToInt32(dr[fieldName]))
                {
                    case BillRightType.None: continue;
                    case BillRightType.OnlyOwner: temp = bSameCreator && (bAllOrganization || bSameOrganizationCode || bSameOrganizationId); break;
                    case BillRightType.OnlyDepartment: temp = bSameCreator || bAllOrganization || bSameOrganizationId; break;
                    case BillRightType.DepartmentAndChild: temp = bSameCreator || bAllOrganization || bSameOrganizationCode; break;
                    case BillRightType.All: temp = true; break;
                }
                if (temp)
                    return destBillDataRight;
            }
            return BillDataRight.None;
        }
Beispiel #2
0
        public void Assign(IEntityBase entity)
        {
            if (entity == null)
            {
                this.Clear();
                return;
            }
            if (entity.FieldIsExists("Iden"))
                this.UserId = entity.GetFieldValue<int>("Iden", -1);

            if (entity.FieldIsExists("UserName"))
                this.UserName = entity.GetFieldValue<string>("UserName", string.Empty);

            if (entity.FieldIsExists("Password"))
                this.Password = entity.GetFieldValue<string>("Password", string.Empty);

            if (entity.FieldIsExists("UserFullName"))
                this.UserFullName = entity.GetFieldValue<string>("UserFullName", string.Empty);

            if (entity.FieldIsExists("Email"))
                this.Email = entity.GetFieldValue<string>("Email", string.Empty);

            if (entity.FieldIsExists("TelephoneNo"))
                this.TelephoneNo = entity.GetFieldValue<string>("TelephoneNo", string.Empty);

            this.UserImage = null;
            if (entity.FieldIsExists("UserImage") && !entity.FieldIsNull("UserImage"))
                this.UserImage = new Bitmap(new MemoryStream(entity.GetFieldValue<byte[]>("UserImage")));

            this.UserSignImage = null;
            if (entity.FieldIsExists("UserSignImage") && !entity.FieldIsNull("UserSignImage"))
                this.UserSignImage = new Bitmap(new MemoryStream(entity.GetFieldValue<byte[]>("UserSignImage")));

        }
Beispiel #3
0
        /// <summary>
        /// 计算实体单据数据权限值
        /// </summary>
        /// <param name="aEntity">实体对象</param>
        /// <param name="billRights">单据权限数据集</param>
        /// <returns>合并的单据数据权限值</returns>
        public static BillDataRight CalcEntityBillDataRight(IEntityBase entity, BillRightInfo billRightInfo)
        {
            if (entity == null)
                return BillDataRight.None;
            string sTableName = entity.TableName;
            if (billRightInfo == null || billRightInfo.BillTypeId <= 0 || !billRightInfo.UseDataRight)
                return BillDataRight.All;
            if (!entity.FieldIsExists(BillRightInfo.CreatedByField))
                throw new ArgumentNullException("数据集[{0}]中缺少字段[{1}],无法应用单据权限".FormatWith(sTableName, BillRightInfo.CreatedByField));

            if (!entity.FieldIsExists(BillRightInfo.OrganizationIdField))
                throw new ArgumentNullException("数据集[{0}]中缺少字段[{1}],无法应用单据权限".FormatWith(sTableName, BillRightInfo.OrganizationIdField));

            if (!entity.FieldIsExists(BillRightInfo.OrganizationCodeField))
                throw new ArgumentNullException("数据集[{0}]中缺少字段[{1}],无法应用单据权限".FormatWith(sTableName, BillRightInfo.OrganizationCodeField));

            return CalcCurrentEntityBillDataRight("UpdateRight", billRightInfo, BillDataRight.Edit, entity)
                | CalcCurrentEntityBillDataRight("DeleteRight", billRightInfo, BillDataRight.Delete, entity)
                | CalcCurrentEntityBillDataRight("AuditRight", billRightInfo, BillDataRight.SendToAudit, entity)
                | CalcCurrentEntityBillDataRight("PrintRight", billRightInfo, BillDataRight.Print, entity)
                | CalcCurrentEntityBillDataRight("ExtendRight1", billRightInfo, BillDataRight.Extend1, entity)
                | CalcCurrentEntityBillDataRight("ExtendRight2", billRightInfo, BillDataRight.Extend2, entity)
                | CalcCurrentEntityBillDataRight("ExtendRight3", billRightInfo, BillDataRight.Extend3, entity)
                | CalcCurrentEntityBillDataRight("ExtendRight4", billRightInfo, BillDataRight.Extend4, entity)
                | CalcCurrentEntityBillDataRight("ExtendRight5", billRightInfo, BillDataRight.Extend5, entity)
                | CalcCurrentEntityBillDataRight("ExtendRight6", billRightInfo, BillDataRight.Extend6, entity)
                | CalcCurrentEntityBillDataRight("ExtendRight7", billRightInfo, BillDataRight.Extend7, entity)
                | CalcCurrentEntityBillDataRight("ExtendRight8", billRightInfo, BillDataRight.Extend8, entity)
                | CalcCurrentEntityBillDataRight("ExtendRight9", billRightInfo, BillDataRight.Extend9, entity)
                | CalcCurrentEntityBillDataRight("ExtendRight10", billRightInfo, BillDataRight.Extend10, entity);
        }