Esempio n. 1
0
        public void saveCreatedObject(BizEntitySchema obj)
        {
            Contract.Requires <DataLogicException>(_dbContext != null,
                                                   "DbContext不能为空");
            Contract.Requires <DataLogicException>(obj.BizEntity != null,
                                                   "BizEntitySchema的父级BizEntity不能为空");

            BizEntity bizEntity = obj.BizEntity;

            // 只有multiBizEntitySchemaMode和multliOrgSchemaMode模式下,
            // BizEntity有多个BizEntitySchema
            if (OrgMgmtDBHelper.schemeMode == SchemeMode.simpleMode ||
                OrgMgmtDBHelper.schemeMode == SchemeMode.multiDepartmentForOneUserMode)
            {
                if (bizEntity.bizEntitySchemas.ToList().Count() > 0)
                {
                    throw new DataLogicException(
                              "目前模式下一个BizEntity下只有一个BizEntitySchema.");
                }
            }

            //一个BizEntity下只能有一个默认BizEntitySchema
            if (bizEntity.bizEntitySchemas.ToList().Exists(
                    bs => bs.isDefault &&
                    bs.bizEntitySchemaId != obj.bizEntitySchemaId))
            {
                obj.isDefault = false;
            }

            bizEntity.bizEntitySchemas.Add(obj);
            _dbContext.SaveChanges();
        }
Esempio n. 2
0
        public static BizEntityDTO convertBizEntity2DTO(BizEntity obj)
        {
            var firstbizEntitySchema = obj.bizEntitySchemas.ToList().Where(
                bizEntitySchema => bizEntitySchema.isVisible).ToList().FirstOrDefault();

            return(new BizEntityDTO()
            {
                bizEntityId = obj.bizEntityId,
                guid = obj.guid,
                name = obj.name,
                englishName = obj.englishName,
                shortName = obj.shortName,
                displayName = obj.displayName,
                code = obj.code,
                indexNumber = obj.indexNumber,
                createTime = obj.createTime,
                url = obj.url,
                DunsNumber = obj.DunsNumber,
                isVisible = obj.isVisible,
                firstbizEntitySchemaId = (firstbizEntitySchema != null ?
                                          firstbizEntitySchema.bizEntitySchemaId : 0),
                firstbizEntitySchemaName = (firstbizEntitySchema != null ?
                                            firstbizEntitySchema.name : null)
            });
        }
Esempio n. 3
0
        private bool InitBindableControls(Control control)
        {
            foreach (Binding binding in control.DataBindings)
            {
                BizEntity item = binding.BindingManagerBase.Current as BizEntity;

                if (item != null)
                {
                    string key = GetBindingKey(item, binding, control);

                    if (_keyToControl.ContainsKey(key))
                    {
                        continue;
                    }

                    string[]           str = null;
                    PropertyDescriptor pd  = null;

                    ITypedList typedList = binding.DataSource as ITypedList;

                    if (typedList != null)
                    {
                        pd = typedList.GetItemProperties(null).Find(
                            binding.BindingMemberInfo.BindingField, false);

                        if (pd != null)
                        {
                            str = Validator.GetErrorMessages(item, pd);
                        }
                    }

                    if (str == null)
                    {
                        str = item.GetErrorMessages(binding.BindingMemberInfo.BindingField);
                    }

                    if (str.Length > 0)
                    {
                        Array.Sort(str);
                    }

                    ControlInfo ci = new ControlInfo(control, str.Length > 0, pd);

                    _bindableControls.Add(ci);
                    _keyToControl.Add(key, ci);

                    if (ci.IsValidatable)
                    {
                        _toolTip.SetToolTip(control, string.Join("\r\n", str));
                    }

                    control.LostFocus      += ValidateControl;
                    control.Validated      += ValidateControl;
                    control.EnabledChanged += ValidateControl;
                }
            }

            return(true);
        }
Esempio n. 4
0
        private void Init(BizEntity entity, SaveHandler saveHandler)
        {
            if (AcceptButton is Button)
            {
                ((Button)AcceptButton).Click += SaveEntity;
            }

            _entity      = entity;
            _saveHandler = saveHandler;
        }
Esempio n. 5
0
        public static bool isBizEntityChangeAllowed(int id, BizEntity value, EnouFlowOrgMgmtContext db)
        {
            if (db.bizEntities.AsNoTracking().Where(
                    bizEntity => bizEntity.bizEntityId == id).ToList().FirstOrDefault().guid
                != value.guid)
            {
                throw new GuidNotAllowedToChangeException("不能修改对象GUID!");
            }

            return(true);
        }
Esempio n. 6
0
        public void saveCreatedObject_validObjWithInvalidParent_willThrows()
        {
            BizEntityHelper o         = new BizEntityHelper(db);
            BizEntity       bizEntity = o.createObject();

            bizEntity.name = "Integration_Test_XXXYYYZZZ";
            OrgSchema orgSchema       = db.orgSchemas.FirstOrDefault();
            BizEntity bizParentEntity = o.createObject();

            Assert.Throws <DataLogicException>(
                () => o.saveCreatedObject(orgSchema, bizEntity, bizParentEntity));
        }
Esempio n. 7
0
        public void convert2DTO_hasBizEntitySchemaObj_willSetfirstbizEntitySchemaIdNotTo0()
        {
            BizEntityHelper o         = new BizEntityHelper(db);
            OrgSchema       orgSchema = db.orgSchemas.FirstOrDefault();
            BizEntity       bizEntity = orgSchema.
                                        bizEntityRelationOnOrgSchemas.FirstOrDefault().bizEntityChild;

            BizEntityDTO bizEntityDTO = o.convert2DTO(bizEntity);

            Assert.AreNotEqual(0, bizEntityDTO.firstbizEntitySchemaId);
            Assert.IsNotNull(bizEntityDTO.firstbizEntitySchemaName);
        }
Esempio n. 8
0
        public void saveCreatedObject_duplicateObjUnderBizEntityWithNotValidModes_willThrows(SchemeMode schemeMode)
        {
            BizEntitySchemaHelper o               = new BizEntitySchemaHelper(db);
            OrgSchema             orgSchema       = db.orgSchemas.FirstOrDefault();
            BizEntity             bizParentEntity = orgSchema.
                                                    bizEntityRelationOnOrgSchemas.FirstOrDefault().bizEntityChild;
            BizEntitySchema bizEntitySchema = new BizEntitySchema();

            bizEntitySchema.BizEntity  = bizParentEntity;
            OrgMgmtDBHelper.schemeMode = schemeMode;

            Assert.Throws <DataLogicException>(
                () => o.saveCreatedObject(bizEntitySchema));
        }
Esempio n. 9
0
        public void saveCreatedObject_validObjWithNoParent_willExist()
        {
            BizEntityHelper o         = new BizEntityHelper(db);
            BizEntity       bizEntity = o.createObject();

            bizEntity.name = "Integration_Test_XXXYYYZZZ";
            OrgSchema orgSchema = db.orgSchemas.FirstOrDefault();

            o.saveCreatedObject(orgSchema, bizEntity, null);

            Assert.True(o.isObjectExists(bizEntity.bizEntityId));
            Assert.AreEqual(1, db.bizEntityRelationOnOrgSchemas.Where(
                                ber => ber.assistOrgSchemaId == orgSchema.orgSchemaId &&
                                ber.bizEntityIdChild == bizEntity.bizEntityId).Count());
        }
Esempio n. 10
0
        public void removeObject_objWithChild_willThrows()
        {
            BizEntityHelper o         = new BizEntityHelper(db);
            BizEntity       bizEntity = o.createObject();

            bizEntity.name = "Integration_Test_XXXYYYZZZ";
            OrgSchema orgSchema       = db.orgSchemas.FirstOrDefault();
            BizEntity bizParentEntity = orgSchema.
                                        bizEntityRelationOnOrgSchemas.FirstOrDefault().bizEntityChild;

            o.saveCreatedObject(orgSchema, bizEntity, bizParentEntity);

            Assert.Throws <DataLogicException>(
                () => o.removeObject(bizParentEntity.bizEntityId));
        }
Esempio n. 11
0
        public void removeObject_obj_willSetVibleToFalse()
        {
            BizEntityHelper o         = new BizEntityHelper(db);
            BizEntity       bizEntity = o.createObject();

            bizEntity.name = "Integration_Test_XXXYYYZZZ";
            OrgSchema orgSchema       = db.orgSchemas.FirstOrDefault();
            BizEntity bizParentEntity = orgSchema.
                                        bizEntityRelationOnOrgSchemas.FirstOrDefault().bizEntityChild;

            o.saveCreatedObject(orgSchema, bizEntity, bizParentEntity);

            o.removeObject(bizEntity.bizEntityId);

            Assert.False(bizEntity.isVisible);
        }
Esempio n. 12
0
        public void convert2DTO_noBizEntitySchemaObj_willSetfirstbizEntitySchemaIdTo0()
        {
            BizEntityHelper o         = new BizEntityHelper(db);
            BizEntity       bizEntity = o.createObject();

            bizEntity.name = "Integration_Test_XXXYYYZZZ";
            OrgSchema orgSchema       = db.orgSchemas.FirstOrDefault();
            BizEntity bizParentEntity = orgSchema.
                                        bizEntityRelationOnOrgSchemas.FirstOrDefault().bizEntityChild;

            o.saveCreatedObject(orgSchema, bizEntity, bizParentEntity);

            BizEntityDTO bizEntityDTO = o.convert2DTO(bizEntity);

            Assert.AreEqual(0, bizEntityDTO.firstbizEntitySchemaId);
            Assert.IsNull(bizEntityDTO.firstbizEntitySchemaName);
        }
Esempio n. 13
0
        public static void saveCreatedBizEntity(OrgSchema orgSchema,
                                                BizEntity bizEntity, BizEntity bizEntityParent,
                                                EnouFlowOrgMgmtContext db, bool removeExistingRelation = false)
        {
            if (!db.bizEntities.ToList().Contains(bizEntity)) //新创建尚未存入DB的BizEntity
            {
                db.bizEntities.Add(bizEntity);
            }

            var hasExistingRelation = orgSchema.bizEntityRelationOnOrgSchemas.ToList().Where(
                bro => bro.bizEntityIdChild == bizEntity.bizEntityId
                ).ToList().Count() > 0;

            //验证不能属于同一OrgSchema下的多于一个Parent BizEntity
            if (hasExistingRelation)
            {
                if (!removeExistingRelation)
                {
                    throw new Exception(
                              string.Format("业务实体'{0}'在组织结构方案'{1}'内已有所属父实体.",
                                            bizEntity.name, orgSchema.name));
                }
                else //Remove Existing Relation
                {
                    orgSchema.bizEntityRelationOnOrgSchemas.Remove(
                        orgSchema.bizEntityRelationOnOrgSchemas.Where(
                            bro => bro.bizEntityIdChild == bizEntity.bizEntityId)
                        .FirstOrDefault());
                }
            }

            BizEntityRelationOnOrgSchema bizEntityRelationOnOrgSchema
                = db.bizEntityRelationOnOrgSchemas.Create();

            bizEntityRelationOnOrgSchema.assistOrgSchemaId = orgSchema.orgSchemaId;
            bizEntityRelationOnOrgSchema.bizEntityChild    = bizEntity;
            if (bizEntityParent != null)
            {
                bizEntityRelationOnOrgSchema.bizEntityParent = bizEntityParent;
            }
            orgSchema.bizEntityRelationOnOrgSchemas.Add(bizEntityRelationOnOrgSchema);

            db.SaveChanges();
        }
Esempio n. 14
0
        public void saveCreatedObject_validObj_willExists(SchemeMode schemeMode)
        {
            OrgMgmtDBHelper.schemeMode = schemeMode;
            BizEntityHelper o         = new BizEntityHelper(db);
            BizEntity       bizEntity = o.createObject();

            bizEntity.name = "Integration_Test_XXXYYYZZZ";
            OrgSchema orgSchema       = db.orgSchemas.FirstOrDefault();
            BizEntity bizParentEntity = orgSchema.
                                        bizEntityRelationOnOrgSchemas.FirstOrDefault().bizEntityChild;

            o.saveCreatedObject(orgSchema, bizEntity, bizParentEntity);
            BizEntitySchemaHelper bizEntitySchemaHelper = new BizEntitySchemaHelper(db);
            BizEntitySchema       bizEntitySchema       = new BizEntitySchema();

            bizEntitySchema.BizEntity = bizEntity;

            bizEntitySchemaHelper.saveCreatedObject(bizEntitySchema);

            Assert.True(bizEntitySchemaHelper.isObjectExists(bizEntitySchema.bizEntitySchemaId));
        }
Esempio n. 15
0
        public static void setParentBizEntity(int id, BizEntity bizEntityParent,
                                              int orgSchemaId, EnouFlowOrgMgmtContext db)
        {
            var orgSchema = db.orgSchemas.Find(orgSchemaId);
            var bizEntity = db.bizEntities.Find(id);

            #region check validity
            if (!isBizEntitySetParentAllowed(id, bizEntityParent, orgSchemaId, db))
            {
                return;
            }
            #endregion

            #region Delete current existing parent-child relation
            var currentbizEntityRelationOnOrgSchema = db.bizEntityRelationOnOrgSchemas
                                                      .Where(r => r.assistOrgSchemaId == orgSchemaId &&
                                                             r.bizEntityIdChild == id).ToList().FirstOrDefault();
            //if (currentbizEntityRelationOnOrgSchema != null)
            //{
            //  db.bizEntityRelationOnOrgSchemas.Remove(currentbizEntityRelationOnOrgSchema);
            //}
            db.bizEntityRelationOnOrgSchemas.Remove(currentbizEntityRelationOnOrgSchema);
            #endregion

            #region construct new parent-child relation
            BizEntityRelationOnOrgSchema bizEntityRelationOnOrgSchema
                = db.bizEntityRelationOnOrgSchemas.Create();
            bizEntityRelationOnOrgSchema.assistOrgSchemaId = orgSchema.orgSchemaId;
            bizEntityRelationOnOrgSchema.bizEntityChild    = bizEntity;
            if (bizEntityParent != null)
            {
                bizEntityRelationOnOrgSchema.bizEntityParent = bizEntityParent;
            }
            orgSchema.bizEntityRelationOnOrgSchemas.Add(bizEntityRelationOnOrgSchema);
            #endregion

            db.SaveChanges();
        }
Esempio n. 16
0
        public IHttpActionResult Put(int id, BizEntity value)
        {
            if (value == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != value.bizEntityId)
            {
                return(BadRequest());
            }

            var bizEntityHelper = new BizEntityHelper(db);

            if (!bizEntityHelper.isObjectExists(id))
            {
                return(NotFound());
            }

            try
            {
                if (!bizEntityHelper.isObjectChangeAllowed(id, value))
                {
                    return(BadRequest("不允许修改对象!"));
                }
                ;
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            db.Entry(value).State = EntityState.Modified;

            db.SaveChanges();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 17
0
        public IHttpActionResult Post([FromUri] int orgSchemaId,
                                      [FromUri] int bizEntityParentId, BizEntity value)
        {
            var bizEntityParent = db.bizEntities.Find(bizEntityParentId);

            if (value == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var orgSchemaHelper = new OrgSchemaHelper(db);

            //if (!OrgMgmtDBHelper.isOrgSchemaExists(orgSchemaId, db) ||
            if (!orgSchemaHelper.isObjectExists(orgSchemaId) ||
                (bizEntityParentId > 0 && bizEntityParent == null))
            {
                ModelState.AddModelError(
                    string.Empty,
                    "数据错误(invalid orgSchemaId or bizEntityParentId>0 && bizEntityParent==null)!");
                return(BadRequest(ModelState));
            }

            var bizEntityHelper = new BizEntityHelper(db);

            try
            {
                //OrgMgmtDBHelper.saveCreatedBizEntity(
                //  db.orgSchemas.Find(orgSchemaId), value, bizEntityParent, db);
                bizEntityHelper.saveCreatedObject(db.orgSchemas.Find(orgSchemaId), value, bizEntityParent);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok(bizEntityHelper.convert2DTO(value)));
        }
Esempio n. 18
0
        private static bool isBizEntitySetParentAllowed(int id, BizEntity parent,
                                                        int orgSchemaId, EnouFlowOrgMgmtContext db)
        {
            #region Cannot be the parent of self
            if (parent != null)
            {
                if (id == parent.bizEntityId)
                {
                    throw new DataLogicException("Cannot be the parent of self!");
                }
            }
            #endregion

            #region Parent不能为自己的子孙,判断方法为从parent开始逐级找祖先,判断bizEntityId是否为id
            BizEntity currentParent = parent;
            while (currentParent != null)
            {
                if (currentParent.bizEntityId == id)
                {
                    throw new DataLogicException("设置的祖先不能为自己的子孙节点!");
                }
                var currentbizEntityRelationOnOrgSchema = db.bizEntityRelationOnOrgSchemas
                                                          .Where(r => r.assistOrgSchemaId == orgSchemaId &&
                                                                 r.bizEntityIdChild == currentParent.bizEntityId).ToList().FirstOrDefault();
                if (currentbizEntityRelationOnOrgSchema != null)
                {
                    currentParent = currentbizEntityRelationOnOrgSchema.bizEntityParent;
                }
                else
                {
                    currentParent = null;
                }
            }
            #endregion

            return(true);
        }
Esempio n. 19
0
        public static void saveCreatedBizEntitySchema(BizEntitySchema bizEntitySchema,
                                                      BizEntity bizEntity, EnouFlowOrgMgmtContext db)
        {
            // 只有multiBizEntitySchemaMode和multliOrgSchemaMode模式下,
            // BizEntity有多个BizEntitySchema
            if (schemeMode == SchemeMode.simpleMode ||
                schemeMode == SchemeMode.multiDepartmentForOneUserMode)
            {
                if (bizEntity.bizEntitySchemas.ToList().Count() > 0)
                {
                    throw new Exception("目前模式下一个BizEntity下只有一个BizEntitySchema.");
                }
            }

            //一个BizEntity下只能有一个默认BizEntitySchema
            if (bizEntity.bizEntitySchemas.ToList().Exists(
                    bs => bs.isDefault && bs.bizEntitySchemaId != bizEntitySchema.bizEntitySchemaId))
            {
                bizEntitySchema.isDefault = false;
            }

            bizEntity.bizEntitySchemas.Add(bizEntitySchema);
            db.SaveChanges();
        }
Esempio n. 20
0
 private static string GetBindingKey(BizEntity entity, Binding binding, Control control)
 {
     return(string.Format("{0}.{1}.{2}",
                          entity.GetHashCode(), binding.BindingMemberInfo.BindingField, control.Name));
 }
Esempio n. 21
0
        protected bool Validate(Control control, bool validateCombines)
        {
            bool result = true;

            foreach (Binding binding in control.DataBindings)
            {
                if (binding.BindingManagerBase == null || binding.BindingManagerBase.Count == 0)
                {
                    continue;
                }

                BizEntity item = binding.BindingManagerBase.Current as BizEntity;

                if (item != null)
                {
                    string key = GetBindingKey(item, binding, control);

                    if (!_keyToControl.ContainsKey(key))
                    {
                        continue;
                    }

                    ControlInfo ci        = _keyToControl[key];
                    string      fieldName = binding.BindingMemberInfo.BindingField;

                    bool isValid = ci.IsValidatable?
                                   ci.PropertyDescriptor != null?
                                   Validator.IsValid(item, ci.PropertyDescriptor):
                                   item.IsValid(fieldName) :
                                       true;

                    if (isValid)
                    {
                        if (item.IsDirtyMember(fieldName))
                        {
                            SetDirty(control);
                        }
                        else
                        {
                            ResetControl(control);
                        }
                    }
                    else
                    {
                        SetInvalid(control);

                        result = false;
                    }

                    /*
                     * if (validateCombines)
                     * {
                     *      PropertyInfo pi =
                     *              item.GetType().GetProperty(binding.BindingMemberInfo.BindingField);
                     *
                     *      if (pi != null)
                     *      {
                     *              object[] attrs = pi.GetCustomAttributes(typeof(CombineAttribute), true);
                     *
                     *              foreach (CombineAttribute a in attrs)
                     *              {
                     *                      string key = GetBindingKey(item, binding, control);
                     *                      string key = item.GetHashCode() + "." + a.Name;
                     *
                     *                      ControlInfo ci = (ControlInfo)nameToControl[key];
                     *
                     *                      if (ci != null)
                     *                              result = Validate(ci.Control, false) && result;
                     *              }
                     *      }
                     * }
                     */
                }
            }

            return(result);
        }