Пример #1
0
 /// <summary>
 /// Creates the persons and resources list.
 /// </summary>
 /// <param name="prl">SortedList with all Persons and Resources objects in system</param>
 /// <param name="clu">Graphic object with all persons and resources</param>
 private void setupPersonResourceList(SortedList prl, Observer clu)
 {
     activePersonResources_ = new SortedList();
     for (int i = 0; i < prl.Count; i++)
     {
         ActivePersonResource apr = new ActivePersonResource((Entity)prl[i], false, true);
         activePersonResources_.Add(((Entity)prl[i]).Name, apr);
         apr.AddObserver(clu);
     }
     checklistUI_ = clu;
 }
Пример #2
0
        /// <summary>
        /// Updates or adds a person/resource in system.
        /// </summary>
        /// <param name="entity">Person or Resource (class) to update or add</param>
        /// <param name="add">True if the person/resource is to be added to system</param>
        /// <returns>0 - If all Ok, else a database error</returns>
        public int setEntity(Entity entity, bool add)
        {
            int ok = ErrorHandler.ERR_WRONGTYPE_ADD;

            // Check if it is a person or Resource
            if (entity.GetType().Name == "Person")
            {
                if (entity.Name == "")
                {
                    return(ErrorHandler.ERR_NONAME_ON_PERSON);
                }
                ok = db_.setPerson((Person)entity, add);
            }
            else if (entity.GetType().Name == "Resource")
            {
                if (entity.Name == "")
                {
                    return(ErrorHandler.ERR_NONAME_ON_RESOURCE);
                }
                ok = db_.setResource((Resource)entity, add);
            }
            if (ok == 0)
            {
                // Add person to the activepersonlist
                if (add == false)
                {
                    if (entity.Name != "admin")
                    {
                        ActivePersonResource apr = (ActivePersonResource)activePersonResources_[entity.Name];
                        apr.Entity.Color = entity.Color;
                        if (entity.GetType().ToString() == "SchemaLite.Person")
                        {
                            ((Person)apr.Entity).Password = ((Person)entity).Password;
                        }
                    }
                }
                else
                {
                    ActivePersonResource apr = new ActivePersonResource(entity, false, true);
                    activePersonResources_.Add(entity.Name, apr);
                    apr.AddObserver(checklistUI_);
                }

                // Update the resourcebox, if the name or color is changed
                if (entity.Name != "admin")
                {
                    ((ActivePersonResource)activePersonResources_[entity.Name]).Notify();
                }
                return(0);
            }
            return(ok);
        }