public override void AddItem(EntityObject item)
 {
     base.AddItem(item);
     var saleitem = item as SaleItem;
     if (saleitem != null && !saleitem.ProductReference.IsLoaded)
             saleitem.ProductReference.Load();
 }
示例#2
0
 public static void AttachInserted(this ObjectContext context, EntityObject objectDetached, string entitySetName)
 {
     if (objectDetached.EntityState == EntityState.Detached)
     {
         context.AddObject(entitySetName, objectDetached);
     }
 }
示例#3
0
 public EditWindowPro(DataManager _manager, Type EditWindowClass,EntityObject item)
 {
     InitializeComponent();
     manager = _manager;
     IsNewEntity = false;
     grContent.Children.Add((UserControl)Activator.CreateInstance(EditWindowClass));
 }
示例#4
0
文件: BaseBLL.cs 项目: jjg0519/OA
        /// <summary>
        /// 通知MVC缓存更新缓存的实体
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="action"></param>
        public void MvcCacheClear(TEntity entity, string action)
        {
            string strModelCode = entity.GetType().Name;

            BLLCommonServices.MVCCacheSV.EntityAction act;
            switch (action)
            {
            case "Add": act = BLLCommonServices.MVCCacheSV.EntityAction.Add; break;

            case "Modify": act = BLLCommonServices.MVCCacheSV.EntityAction.Modify; break;

            case "Delete": act = BLLCommonServices.MVCCacheSV.EntityAction.Delete; break;

            default: act = BLLCommonServices.MVCCacheSV.EntityAction.None; break;
            }
            if (entity is System.Data.Objects.DataClasses.EntityObject)
            {
                System.Data.Objects.DataClasses.EntityObject ent = entity as System.Data.Objects.DataClasses.EntityObject;
                string strFormId = entity.GetType().GetProperties().FirstOrDefault().GetValue(entity, null).ToString();
                if (strFormId != "" || strFormId != null)
                {
                    BLLCommonServices.Utility.MvcCacheClearAsync(strModelCode, strFormId, act);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Detaches the Entity.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="entityToCheck">The entity to check.</param>
        /// <returns></returns>
        public static bool PreDelete(this CoreEntitiesContainer container, EntityObject entityToCheck)
        {
            if (entityToCheck == null ||entityToCheck.EntityState == EntityState.Deleted) 
                return false;

            container.Detach(entityToCheck);
            return true;
        }
示例#6
0
 public static bool isAttach( ObjectContext context, EntityObject entity )
 {
     var entry = context.ObjectStateManager.GetObjectStateEntry( entity );
     if ( entry.State == EntityState.Detached )
         return false;
     else
         return true;
 }
    internal QueryEntityDetailsEventArgs( EntityObject parentItem )
      : base()
    {
      if( parentItem == null )
        throw new ArgumentNullException( "parentItem" );

      this.ParentItem = parentItem;
    }
示例#8
0
 public EditWindowPro(DataManager _manager, Type EditWindowClass,EntityObject item)
 {
     InitializeComponent();
      manager = _manager;
     IsNewEntity = false;
     FormContent = (UserControl)Activator.CreateInstance(EditWindowClass);
     grContent.Children.Add(FormContent);
     this.Title = manager.Name;
     FillFormContent(item);
 }
示例#9
0
 private void ApplyValue(DataRow dataRow, EntityObject entityObject)
 {
     var properties = entityObject.GetType().GetProperties()
         .Where(c => (!typeof(IList).IsAssignableFrom(c.PropertyType) && !typeof(EntityObject).IsAssignableFrom(c.PropertyType)) && !typeof(EntityKey).IsAssignableFrom(c.PropertyType));
     foreach (var property in properties) {
         if (dataRow.Table.Columns[property.Name] != null) {
             dataRow[property.Name] = entityObject.GetValue(property.Name);
         }
     }
 }
示例#10
0
 public bool Modify(EntityObject entity)
 {
     if(entity is Value)
     {
         return ConnectionHelper.ModifyWithHistory((Value)entity);
     }
     else
     {
         return ConnectionHelper.Modify(entity);
     }
 }
        public static void GetBrokenRulesString(IBusinessObject currentObj,
                                                List <IBusinessObject> checkEntities,
                                                List <string> errorMessages,
                                                System.Data.Objects.DataClasses.EntityObject parent)
        {
            if (checkEntities.Contains(currentObj))
            {
                return;
            }

            checkEntities.Add(currentObj);

            if (parent == null)
            {
                errorMessages.Add(currentObj.GetCurrentBrokenRules());
            }
            else
            {
                errorMessages.Add(currentObj.GetCurrentBrokenRules());
            }

            if (IsNew(currentObj))
            {
                return;
            }

            foreach (Adage.EF.Interfaces.RelatedObject eachObj in currentObj.RelatedObjects)
            {
                IRelatedEnd childColl;
                if (eachObj.RelatedType == RelatedEnum.Many)
                {
                    childColl = eachObj.GetRelatedEnd((EntityObject)currentObj);
                    if (childColl == null || childColl.IsLoaded == false)
                    {
                        continue;
                    }
                }
                else
                {
                    if (eachObj.GetReference((EntityObject)currentObj).IsLoaded == false)
                    {
                        continue;
                    }

                    childColl = eachObj.GetRelatedEnd((EntityObject)currentObj);
                }

                foreach (Adage.EF.Interfaces.IBusinessObject eachChild in childColl)
                {
                    eachChild.FindBrokenRules(checkEntities,
                                              errorMessages, (EntityObject)currentObj);
                }
            }
        }
示例#12
0
        public static void Test(EntityObject obj)
        {
            T_FB_TRAVELEXPAPPLYMASTER bb = obj as T_FB_TRAVELEXPAPPLYMASTER;
            BaseBll<T_FB_TRAVELEXPAPPLYMASTER> b = new BaseBll<T_FB_TRAVELEXPAPPLYMASTER>();
            T_FB_TRAVELEXPAPPLYMASTER t = b.GetTable().First();
            T_FB_TRAVELEXPAPPLYDETAIL t1 = new T_FB_TRAVELEXPAPPLYDETAIL();

            T_FB_TRAVELEXPAPPLYDETAIL t2 = bb.T_FB_TRAVELEXPAPPLYDETAIL.ToList()[0];
            t.T_FB_TRAVELEXPAPPLYDETAIL.Add(t1);
            t.T_FB_TRAVELEXPAPPLYDETAIL.Add(t2);
            b.dal.GetDataContext().SaveChanges();
        }
示例#13
0
文件: DAO.cs 项目: bashiry/enturnador
        /// <summary>
        /// Persiste en la base de datos el objeto que le llega y retorna el id del registro recien creado
        /// </summary>
        /// <param name="entidad">Entidad que debe estar relacionada en la clase Enumeraciones</param>
        /// <param name="obj">objeto que se recibe y se inserta en la DB</param>
        /// <param name="idUsuario">Si no se requiere usuario se puede recibir null</param>
        /// <returns>retorno del id delregistro insertado</returns>
        public int Crear(Enumeraciones.Entidad entidad, EntityObject obj)
        {          
            this._ent.AddObject(entidad.ToString(), obj);
            this._ent.SaveChanges();

            if (obj == null)
                throw new Exception("El objeto no puede ser null");

            if (obj.EntityKey.EntityKeyValues.Count() == 1)
                return Convert.ToInt32(obj.EntityKey.EntityKeyValues[0].Value.ToString());
            else
                return 0;            
        }
示例#14
0
文件: DAO.cs 项目: bashiry/enturnador
        /// <summary>
        ///  Persiste en la base de datos las modificaciones al objeto que le llega
        /// </summary>
        /// <param name="entidad">Objeto entidad que se va a insertar</param>
        /// <param name="obj">Objeto que se recibe  y se inserta en la DB</param>
        /// <param name="idRegistro">Corresponde al id del registro que se va actualizar</param>
        /// <param name="idUsuario">Si no se requiere usuario se puede recibir null</param>
        public void Actualizar(Enumeraciones.Entidad entidad, EntityObject obj, int idRegistro, int? idUsuario)
        {
            if (obj == null)
                throw new Exception("El objeto no puede ser null");

            //Agrega el entity key
            if (obj.EntityKey == null)
                obj.EntityKey = this.GetEntityKey(entidad, idRegistro);


            Utilidades.DAOUtil.AttachUpdated(this._ent, obj);
            this._ent.SaveChanges();
        }
示例#15
0
        public EntityObject UpdateEntityObject(EntityObject obj, Action<COATEntities, EntityObject> attachRelated)
        {
            if (obj.EntityState == EntityState.Detached)
            {
                Entities.Attach(obj);
                Entities.ObjectStateManager.ChangeObjectState(obj, EntityState.Modified);

                if (attachRelated != null)
                {
                    attachRelated(Entities, obj);
                }
            }
            return obj;
        }
        public static string GetEntitySetName(this ObjectContext context, EntityObject entity)
        {
            Type entityType = ObjectContext.GetObjectType(entity.GetType());
            if (entityType == null)
            {
                throw new InvalidOperationException("not an entity");
            }

            EntityContainer container = context.MetadataWorkspace.GetEntityContainer(context.DefaultContainerName, DataSpace.CSpace);
            return container.BaseEntitySets
                            .Where(anEntitySet => anEntitySet.ElementType.Name.Equals(entityType.Name))
                            .Select(anEntitySet => anEntitySet.Name)
                            .Single();
        }
示例#17
0
 public static void AttachUpdated(this ObjectContext objContext, EntityObject objDetached)
 {
     if (objDetached.EntityState == EntityState.Detached)
     {
         object original = null;
         if (objContext.TryGetObjectByKey(objDetached.EntityKey, out original))
         {
             objContext.ApplyCurrentValues(objDetached.EntityKey.EntitySetName, objDetached);
         }
         else
         {
             throw new ObjectNotFoundException();
         }
     }
 }
示例#18
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Initializes a new instance of the <c>DataObject</c> class.
        /// </summary>
        protected DataObject(EntityObject entity)
        {
            Debug.Assert(entity != null);

            _InitValidation();

            // set entity's data object reference
            IWrapDataAccess wda = entity as IWrapDataAccess;
            if (wda == null)
                Debug.Assert(false, "Entity object does not implement IWrapDataAccess.");

            wda.DataObject = this;

            _entity = entity;
        }
示例#19
0
文件: BaseBll.cs 项目: jjg0519/OA
        ///// <summary>
        ///// 根据权限过滤
        ///// </summary>
        ///// <param name="filterString"></param>
        ///// <param name="queryParas"></param>
        ///// <param name="userID"></param>
        ///// <param name="entityName"></param>
        //protected void SetOrganizationFilter(ref string filterString, ref List<object> queryParas, string employeeID, string entityName)
        //{
        //    //获取用户
        //    T_SYS_USER user = permissionclient.GetUserByEmployeeID(employeeID);

        //    //EmployeeBLL bll = new EmployeeBLL();

        //    //T_HR_EMPLOYEE emp = bll.GetEmployeeByID(user.EMPLOYEEID);
        //    V_EMPLOYEEPOST vemp = personnelclient.GetEmployeeDetailByID(user.EMPLOYEEID);
        //    if (vemp == null) return;
        //    T_HR_EMPLOYEE emp = vemp.EMPLOYEEPOSTS[0].T_HR_EMPLOYEE;


        //    //获取正常的角色用户权限

        //    V_Permission[] perms = permissionclient.GetUserMenuPerms(entityName, user.SYSUSERID);
        //    if (perms == null)
        //        return;

        //    //获取查询的权限,值越小,权限越大
        //    int maxPerm = -1;
        //    var permlist = perms.Where(p => p.Permission.PERMISSIONVALUE == "3");
        //    if (permlist.Count() > 0)
        //    {
        //        maxPerm = permlist.Min(p => Convert.ToInt32(p.RoleMenuPermission.DATARANGE));
        //    }
        //    //perms.Where(p => p.Permission.PERMISSIONVALUE == "3").Min(p => Convert.ToInt32(p.RoleMenuPermission.DATARANGE));
        //    //var maxPerm = "2";



        //    //if (!emp.T_HR_EMPLOYEEPOST.IsLoaded)
        //    //{
        //    //    emp.T_HR_EMPLOYEEPOST.Load();
        //    //}

        //    //获取自定义权限
        //    int custPerm = GetCustomPerms(entityName, emp);
        //    if (custPerm < maxPerm)
        //        maxPerm = custPerm;

        //    //看整个公司的
        //    if (Convert.ToInt32(maxPerm) == Convert.ToInt32(AssignObjectType.Company))
        //    {
        //        if (!string.IsNullOrEmpty(filterString))
        //            filterString += " AND ";

        //        filterString += " (";
        //        int i = 0;
        //        foreach (T_HR_EMPLOYEEPOST ep in emp.T_HR_EMPLOYEEPOST)
        //        {

        //            if (i > 0)
        //                filterString += " OR ";

        //            filterString += "OWNERCOMPANYID==@" + queryParas.Count().ToString();


        //            //暂时先去掉
        //            //if (!ep.T_HR_POSTReference.IsLoaded)
        //            //    ep.T_HR_POSTReference.Load();

        //            //if (ep.T_HR_POST != null && ep.T_HR_POST.T_HR_DEPARTMENTReference.IsLoaded == false)
        //            //    ep.T_HR_POST.T_HR_DEPARTMENTReference.Load();

        //            //if (ep.T_HR_POST != null && ep.T_HR_POST.T_HR_DEPARTMENT != null && ep.T_HR_POST.T_HR_DEPARTMENT.T_HR_COMPANYReference.IsLoaded == false)
        //            //    ep.T_HR_POST.T_HR_DEPARTMENT.T_HR_COMPANYReference.Load();

        //            queryParas.Add(ep.T_HR_POST.T_HR_DEPARTMENT.T_HR_COMPANY.COMPANYID);

        //            i++;
        //        }
        //        filterString += ") ";
        //    }


        //    //看部门的
        //    if (Convert.ToInt32(maxPerm) == Convert.ToInt32(AssignObjectType.Department))
        //    {
        //        if (!string.IsNullOrEmpty(filterString))
        //            filterString += " AND ";

        //        filterString += " (";
        //        int i = 0;
        //        foreach (T_HR_EMPLOYEEPOST ep in emp.T_HR_EMPLOYEEPOST)
        //        {

        //            if (i > 0)
        //                filterString += " OR ";

        //            filterString += "OWNERDEPARTMENTID==@" + queryParas.Count().ToString();

        //            if (!ep.T_HR_POSTReference.IsLoaded)
        //                ep.T_HR_POSTReference.Load();

        //            if (ep.T_HR_POST != null && ep.T_HR_POST.T_HR_DEPARTMENTReference.IsLoaded == false)
        //                ep.T_HR_POST.T_HR_DEPARTMENTReference.Load();

        //            queryParas.Add(ep.T_HR_POST.T_HR_DEPARTMENT.DEPARTMENTID);

        //            i++;
        //        }
        //        filterString += ") ";
        //    }


        //    //看岗位的
        //    if (Convert.ToInt32(maxPerm) == Convert.ToInt32(AssignObjectType.Post))
        //    {
        //        if (!string.IsNullOrEmpty(filterString))
        //            filterString += " AND ";

        //        filterString += " (";
        //        int i = 0;
        //        foreach (T_HR_EMPLOYEEPOST ep in emp.T_HR_EMPLOYEEPOST)
        //        {

        //            if (i > 0)
        //                filterString += " OR ";

        //            filterString += "OWNERPOSTID==@" + queryParas.Count().ToString();

        //            if (!ep.T_HR_POSTReference.IsLoaded)
        //                ep.T_HR_POSTReference.Load();

        //            queryParas.Add(ep.T_HR_POST.POSTID);

        //            i++;
        //        }
        //        filterString += ") ";
        //    }

        //    //看员工
        //    if (Convert.ToInt32(maxPerm) == Convert.ToInt32(AssignObjectType.Employee))
        //    {
        //        if (!string.IsNullOrEmpty(filterString))
        //            filterString += " AND ";

        //        filterString += "OWNERID==@" + queryParas.Count().ToString();
        //        queryParas.Add(employeeID);
        //    }

        //}

        //private int GetCustomPerms(string menuCode, T_HR_EMPLOYEE emp)
        //{
        //    int perm = 99;

        //    return perm;     //暂时未实现

        //    //过滤自定义的权限
        //    //emp =
        //    //if (!emp.T_HR_EMPLOYEEPOST.IsLoaded)
        //    //{
        //    //    emp.T_HR_EMPLOYEEPOST.Load();
        //    //}
        //    if (emp != null)
        //    {
        //        foreach (T_HR_EMPLOYEEPOST ep in emp.T_HR_EMPLOYEEPOST)
        //        {
        //            if (!ep.T_HR_POSTReference.IsLoaded)
        //                ep.T_HR_POSTReference.Load();

        //            if (ep.T_HR_POST != null && ep.T_HR_POST.T_HR_DEPARTMENTReference.IsLoaded == false)
        //                ep.T_HR_POST.T_HR_DEPARTMENTReference.Load();

        //            if (ep.T_HR_POST != null && ep.T_HR_POST.T_HR_DEPARTMENT != null && ep.T_HR_POST.T_HR_DEPARTMENT.T_HR_COMPANYReference.IsLoaded == false)
        //                ep.T_HR_POST.T_HR_DEPARTMENT.T_HR_COMPANYReference.Load();

        //            T_SYS_ENTITYMENUCUSTOMPERM[] custPerms;
        //            //查看有没有岗位的特别权限
        //            custPerms = permissionclient.GetCustomPostMenuPerms(menuCode, ep.T_HR_POST.POSTID);
        //            if (custPerms != null && custPerms.Count() > 0)
        //                perm = Convert.ToInt32(AssignObjectType.Post);

        //            //查看有没有部门的特别权限
        //            custPerms = permissionclient.GetCustomDepartMenuPerms(menuCode, ep.T_HR_POST.T_HR_DEPARTMENT.DEPARTMENTID);
        //            if (custPerms != null && custPerms.Count() > 0)
        //                perm = Convert.ToInt32(AssignObjectType.Department);

        //            //查看有没有公司的特别权限
        //            custPerms = permissionclient.GetCustomCompanyMenuPerms(menuCode, ep.T_HR_POST.T_HR_DEPARTMENT.T_HR_COMPANY.COMPANYID);
        //            if (custPerms != null && custPerms.Count() > 0)
        //                perm = Convert.ToInt32(AssignObjectType.Company);
        //        }
        //    }

        //    return perm;
        //}

        //private int GetCustomPerms(string menuCode, T_HR_EMPLOYEE emp)
        //{
        //    int perm = 99;

        //    //过滤自定义的权限
        //    if (!emp.T_HR_EMPLOYEEPOST.IsLoaded)
        //    {
        //        emp.T_HR_EMPLOYEEPOST.Load();
        //    }

        //    foreach (T_HR_EMPLOYEEPOST ep in emp.T_HR_EMPLOYEEPOST)
        //    {
        //        if (!ep.T_HR_POSTReference.IsLoaded)
        //            ep.T_HR_POSTReference.Load();

        //        if (ep.T_HR_POST != null && ep.T_HR_POST.T_HR_DEPARTMENTReference.IsLoaded == false)
        //            ep.T_HR_POST.T_HR_DEPARTMENTReference.Load();

        //        if (ep.T_HR_POST != null && ep.T_HR_POST.T_HR_DEPARTMENT != null && ep.T_HR_POST.T_HR_DEPARTMENT.T_HR_COMPANYReference.IsLoaded == false)
        //            ep.T_HR_POST.T_HR_DEPARTMENT.T_HR_COMPANYReference.Load();

        //        PermissionWS.T_SYS_ENTITYMENUCUSTOMPERM[] custPerms;
        //        //查看有没有岗位的特别权限
        //        custPerms = PermClient.GetCustomPostMenuPerms(menuCode, ep.T_HR_POST.POSTID);
        //        if (custPerms != null && custPerms.Count() > 0)
        //            perm = Convert.ToInt32(AssignObjectType.Post);

        //        //查看有没有部门的特别权限
        //        custPerms = PermClient.GetCustomDepartMenuPerms(menuCode, ep.T_HR_POST.T_HR_DEPARTMENT.DEPARTMENTID);
        //        if (custPerms != null && custPerms.Count() > 0)
        //            perm = Convert.ToInt32(AssignObjectType.Department);

        //        //查看有没有公司的特别权限
        //        custPerms = PermClient.GetCustomCompanyMenuPerms(menuCode, ep.T_HR_POST.T_HR_DEPARTMENT.T_HR_COMPANY.COMPANYID);
        //        if (custPerms != null && custPerms.Count() > 0)
        //            perm = Convert.ToInt32(AssignObjectType.Company);
        //    }

        //    return perm;
        //}

        #endregion

        #region 克隆实体1
        public static void CloneEntity <T>(T sourceObj, T targetObj) where T : class
        {
            Type a = sourceObj.GetType();

            PropertyInfo[] infos = a.GetProperties();
            foreach (PropertyInfo prop in infos)
            {
                //System.Data.Objects.DataClasses.
                if (prop.PropertyType.BaseType == typeof(System.Data.Objects.DataClasses.EntityReference) ||
                    prop.PropertyType.BaseType == typeof(System.Data.Objects.DataClasses.RelatedEnd) ||
                    prop.PropertyType == typeof(System.Data.EntityState) ||
                    prop.PropertyType == typeof(System.Data.EntityKey))
                {
                    continue;
                }
                if (sourceObj is System.Data.Objects.DataClasses.EntityObject)
                {
                    System.Data.Objects.DataClasses.EntityObject ent = sourceObj as System.Data.Objects.DataClasses.EntityObject;

                    if (ent != null && ent.EntityKey != null && ent.EntityKey.EntityKeyValues != null && ent.EntityKey.EntityKeyValues.Count() > 0)
                    {
                        bool isKeyField = false;
                        foreach (var key in ent.EntityKey.EntityKeyValues)
                        {
                            if (key.Key == prop.Name)
                            {
                                isKeyField = true;
                                break;
                            }
                        }
                        if (isKeyField)
                        {
                            continue;
                        }
                    }
                }
                //prop.Name
                object value = prop.GetValue(sourceObj, null);
                try
                {
                    prop.SetValue(targetObj, value, null);
                }
                catch (Exception ex)
                {
                    string e = ex.Message;
                }
            }
        }
        /// <summary>
        /// Helper provisorio para realizar um update no entity sem precisar de ir ao banco de dados.
        /// </summary>
        /// <param name="context">Contexto do Entity.</param>
        /// <param name="entitySetName">Nome do EntitySet.</param>
        /// <param name="entity">Entity Object.</param>
        public static void Update(this ObjectContext context, string entitySetName, EntityObject entity)
        {
            if (entity.EntityKey == null)
                entity.EntityKey = context.CreateEntityKey(entitySetName, entity);

            if (entity.EntityState == EntityState.Detached)
                context.Attach(entity);

            var stateEntry = context.ObjectStateManager.GetObjectStateEntry(entity.EntityKey);
            var propertyNameList = stateEntry.CurrentValues.DataRecordInfo.FieldMetadata.Select(pn => pn.FieldType.Name);
            foreach (var propName in propertyNameList)
            {
                stateEntry.SetModifiedProperty(propName);
            }

            //var relatedEntities = context.ObjectStateManager.GetObjectStateEntries(System.Data.EntityState.Added).Where(
        }
        public static string GetEntitySetFullName(this ObjectContext context, EntityObject entity)
        {
            // If the EntityKey exists, simply get the Entity Set name from the key
            if (entity.EntityKey != null)
            {
                return entity.EntityKey.EntitySetName;
            }
            else
            {
                string entityTypeName = entity.GetType().Name;
                var container = context.MetadataWorkspace.GetEntityContainer(context.DefaultContainerName, DataSpace.CSpace);
                string entitySetName = (from meta in container.BaseEntitySets
                                        where meta.ElementType.Name == entityTypeName
                                        select meta.Name).First();

                return container.Name + "." + entitySetName;
            }
        }
        public static void AttachUpdated(this ObjectContext context, EntityObject detachedEntity)
        {
            #region EntityKey is null
            if (detachedEntity.EntityKey == null)
            {
                //String entitySetName = GetEntitySetFullName(context, detachedEntity);
                //int objectId = (int)detachedEntity.GetType().GetProperty("Id").GetValue(detachedEntity, null);
                ////detachedEntity.EntityKey = new System.Data.EntityKey(entitySetName, "Id", objectId);
                //detachedEntity.EntityKey = new EntityKey(context.GetEntitySetName(detachedEntity.GetType()));
                ////  create a new primary key
                //Guid newPk = Guid.NewGuid();

                ////  create new entity key
                //EntityKey entityKey = new EntityKey(context.GetType().Name + "." + detachedEntity.ToString(), pkName, newPk);

                ////  get type name of new entity
                //String typeName = oc.GetType().Namespace + "." + entityKey.EntitySetName;

                ////  create a new entity

            }
            #endregion
            if (detachedEntity.EntityState == EntityState.Detached)
            {
                object currentEntity = null;

                if (context.TryGetObjectByKey(detachedEntity.EntityKey, out currentEntity))
                {
                    context.ApplyCurrentValues(detachedEntity.EntityKey.EntitySetName, detachedEntity);

                    var newEntity = detachedEntity as IEntityWithRelationships;
                    var oldEntity = currentEntity as IEntityWithRelationships;

                    if (newEntity != null && oldEntity != null)
                    {
                        context.ApplyReferencePropertyChanges(newEntity, oldEntity);
                    }
                }
                else
                {
                    throw new ObjectNotFoundException();
                }
            }
        }
示例#23
0
 public static void AttachUpdated(this ObjectContext context, EntityObject objectDetached)
 {
     if (objectDetached.EntityState == EntityState.Detached)
     {
         object currentEntityInDb = null;
         if (context.TryGetObjectByKey(objectDetached.EntityKey, out currentEntityInDb))
         {
             context.ApplyCurrentValues(objectDetached.EntityKey.EntitySetName, objectDetached);
             //context.ApplyPropertyChanges(objectDetached.EntityKey.EntitySetName, objectDetached);
             //(CDLTLL)Apply property changes to all referenced entities in context
             context.ApplyReferencePropertyChanges((IEntityWithRelationships)objectDetached,
                 (IEntityWithRelationships)currentEntityInDb); //Custom extensor method
         }
         else
         {
             throw new ObjectNotFoundException();
         }
     }
 }
        /// <summary>
        /// Helper provisorio para realizar um update no entity que possuir relacionamentos.
        /// </summary>
        /// <param name="context">Contexto do Entity.</param>
        /// <param name="entitySetName">Nome do EntitySet.</param>
        /// <param name="entity">Entity Object.</param>
        public static void UpdateWithReference(this ObjectContext context, string entitySetName, EntityObject entity)
        {
            if (entity.EntityKey == null)
                entity.EntityKey = context.CreateEntityKey(context.DefaultContainerName + "." + entitySetName, entity);

            if (entity.EntityState == EntityState.Detached)
            {
                object currentEntityInDb;
                if (context.TryGetObjectByKey(entity.EntityKey, out currentEntityInDb))
                {
                    context.ApplyPropertyChanges(entity.EntityKey.EntitySetName, entity);
                    context.ApplyReferencePropertyChanges(entity,
                                                      (IEntityWithRelationships)currentEntityInDb);  //extension
                }
                else
                {
                    throw new ObjectNotFoundException();
                }
            }
        }
示例#25
0
        public static void Insert(EntityObject item)
        {
            EntityModelContainer context = GetContext();

            if (item.EntityState != EntityState.Added)
                context.AddObject(item.GetType().Name + "s", item);
        }
示例#26
0
 private EntityState GetState(EntityObject entityObject, Dictionary<EntityKey, EntityState> states, DataRow parentRow)
 {
     if (parentRow != null && parentRow.RowState == DataRowState.Deleted)
     {
         return EntityState.Deleted;
     }
     else if (entityObject.EntityKey == null)
     {
         return EntityState.Added;
     }
     else if (states.ContainsKey(entityObject.EntityKey))
     {
         return states[entityObject.EntityKey];
     }
     else
     {
         return EntityState.Unchanged;
     }
 }
示例#27
0
        private void CreateRow(EntityObject entityObject, DataRow parentRow, Dictionary<EntityKey, EntityState> states, DataSet dataset)
        {
            var tableName = entityObject.GetType().Name;
            var dataTable = dataset.Tables[tableName];
            var state = GetState(entityObject, states,  parentRow);
            DataRow dataRow = null;

            if (state == EntityState.Added) {
                dataRow = dataTable.NewRow();
                ApplyValue(dataRow, entityObject);
                dataTable.Rows.Add(dataRow);
                ApplyRelationValue(dataRow, parentRow, dataset);
                if (parentRow != null && parentRow.RowState == DataRowState.Unchanged)
                {
                    parentRow.SetModified();
                }
            }
            else {
                dataRow = dataTable.Rows.Find(entityObject.EntityKey.EntityKeyValues.Select(c => c.Value).ToArray());
                if (dataRow != null)
                {
                    if (state == EntityState.Deleted)
                    {
                        dataRow.Delete();
                    }
                    else
                    {
                        ApplyValue(dataRow, entityObject);
                    }
                }
            }

            var navigationProperties = entityObject.GetType().GetProperties().Where(c => typeof(IList).IsAssignableFrom(c.PropertyType));
            foreach (var navigationProperty in navigationProperties) {
                var navigationValue = (IList)navigationProperty.GetValue(entityObject, null);
                foreach (EntityObject childObject in navigationValue) {
                    CreateRow(childObject, dataRow, states, dataset);
                }
            }
        }
示例#28
0
 public static bool IsEntityObjectLoadable( EntityObject entityObject )
 {
   return
     ( ( entityObject.EntityState & EntityState.Added ) != EntityState.Added ) &&
     ( ( entityObject.EntityState & EntityState.Detached ) != EntityState.Detached );
 }
示例#29
0
文件: SystemBLL.cs 项目: JuRogn/OA
 public static string GetTableName(EntityObject entity)
 {
     string tableName = entity.GetType().Name;
     //T_FB_CHARGEAPPLYMASTER entityCharge = entity as T_FB_CHARGEAPPLYMASTER;
     //if (entityCharge != null)
     //{
     //    entityCharge.T_FB_EXTENSIONALORDERReference.Load();
     //    entityCharge.T_FB_EXTENSIONALORDER.T_FB_EXTENSIONALTYPEReference.Load();
     //    if (entityCharge.T_FB_EXTENSIONALORDER.T_FB_EXTENSIONALTYPE.EXTENSIONALTYPECODE == "CCBX")
     //    {
     //        tableName = typeof(T_FB_TRAVELEXPAPPLYMASTER).Name;
     //    }
     //}
     return tableName;
     
 }
示例#30
0
文件: SystemBLL.cs 项目: JuRogn/OA
        public static void AddAutoOrderCode(EntityObject entity)
        {

            string tablename = GetTableName(entity);

            T_FB_ORDERCODE orderCode = listOrderCode.FirstOrDefault(item =>
            {
                return item.TABLENAME == tablename;
            });
            if (orderCode == null)
            {
                Tracer.Debug("生成编号失败:在T_FB_ORDERCODE表中未找到此表配置项目:" + tablename);
                return;
            }

            //string code = GetOrderCode(orderCode);张秉福旧方法
            //新方法
            string code = string.Empty;
            using (OrderCodeBLL bll = new OrderCodeBLL())
            {
                code = bll.GetAutoOrderCode(tablename);
            } 
            string codePropertyName = orderCode.FIELDNAME;
            entity.SetValue(codePropertyName, code);
            
            //开始更新元数据单号
            string Formid = string.Empty;
            Tracer.Debug("开始更新元数据:"+tablename);
            try
            {
                  switch (tablename)
                    {

                        case "T_FB_TRAVELEXPAPPLYMASTER":
                            //T_FB_TRAVELEXPAPPLYMASTER item = (T_FB_TRAVELEXPAPPLYMASTER)entity;
                            //Formid = item.T_FB_EXTENSIONALORDER.ORDERID;
                            //出差报销在OA中出差报销审核的业务逻辑中处理
                            break;
                        default:
                            Formid =entity.EntityKey.EntityKeyValues[0].Value.ToString();

                            SMT.SaaS.BLLCommonServices.FlowWFService.ServiceClient client =
                                new SaaS.BLLCommonServices.FlowWFService.ServiceClient();
                            Tracer.Debug("开始调用元数据获取接口:FlowWFService.GetMetadataByFormid("+Formid+")");
                            string xml=string.Empty;
                            xml=client.GetMetadataByFormid(Formid);
                            if (string.IsNullOrEmpty(xml))
                            {
                                Tracer.Debug("XML元数据为空,跳过:" + xml);
                                break;
                            }
                            Tracer.Debug("获取到的元数据:"+xml);
                            xml=xml.Replace("自动生成", code);
                            Tracer.Debug("替换单号后的XML:"+xml);
                            client.UpdateMetadataByFormid(Formid, xml);
                            break;
                    }
            }
            catch (Exception ex)
            {
                Tracer.Debug(ex.ToString());
            }
        }
示例#31
0
 public abstract EntityObject PopulateItem(EntityObject item);       
示例#32
0
        public static bool Remove(EntityObject item)
        {
            EntityModelContainer context = GetContext();

            try
            {
                context.DeleteObject(item);
            }
            catch
            {
                Methods.ShowStandardMsgBox(FormMessageType.Error, RscError.ErrorTitle, RscError.EntityDelete);
                context.ObjectStateManager.ChangeObjectState(item, System.Data.EntityState.Modified);
                return false;
            }
            return true;
        }
示例#33
0
 public static void ChangeEntityState(EntityObject item, EntityState entityState)
 {
     EntityModelContainer context = GetContext();
     context.ObjectStateManager.ChangeObjectState(item, entityState);
 }