Ejemplo n.º 1
0
        /// <summary>
        /// Set the system in a new week
        /// </summary>
        /// <param name="date">A date within the week to be changed to</param>
        /// #1.04 - New index for week list (week number)
        public int changeWeek(DateTime date)
        {
            SelectedWeek oldweek  = new SelectedWeek(selweek_.DateOfFirstDayInWeek);
            SelectedWeek oldweek2 = new SelectedWeek(selweek_.DateOfFirstDayInWeek.AddDays(7));
            SelectedWeek nextweek = new SelectedWeek(date.AddDays(7));

            this.selweek_.setDate(date);

            // #1.04 - start
            // Update all resourceboxes of the old week
            if (weeks_.ContainsKey(oldweek.Week))
            {
                NotifyAll((SortedList)weeks_[oldweek.Week]);
            }
            if (weeks_.ContainsKey(oldweek2.Week))
            {
                NotifyAll((SortedList)weeks_[oldweek2.Week]);
            }


            // Update all resourceboxes of the new week
            if (weeks_.ContainsKey(selweek_.Week))
            {
                NotifyAll((SortedList)weeks_[selweek_.Week]);
            }
            if (weeks_.ContainsKey(nextweek.Week))
            {
                NotifyAll((SortedList)weeks_[nextweek.Week]);
            }
            // #1.04 - stop
            Notify();
            return(0);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates the scheme object which is the center of this system
 /// </summary>
 private Scheme()
 {
     loggedin_ = false;
     // Select current week
     this.selweek_ = new SelectedWeek(DateTime.Now);
     checkFiles();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Get all resourceboxes from the database
        /// </summary>
        /// <returns>0 - If all is Ok, else a database error</returns>
        /// #1.04 - New index for week list (week number)
        private int updateResourceBoxes()
        {
            // Get all resourceboxes from database
            int fel = db_.getResourceBoxes(new DateTime(0), this.selweek_.DateOfFirstDayInWeek.AddDays(7), out this.resourceBoxes_);

            if (fel != 0)
            {
                return(fel);
            }
            // Set correct id-list in each resourcebox

//			updateIdsNextTo(this.resourceBoxes_); #1.01.003 - removed line, this is done in db_.getResourceBoxes

            // Sort each resourcebox into the week-list
            weeks_ = new SortedList();
            // #1.04 - start
            foreach (ResourceBox rb in resourceBoxes_.Values)
            {
                SelectedWeek selweek = new SelectedWeek(rb.StartTime);
                if (!weeks_.ContainsKey(selweek.Week))
                {
                    weeks_[selweek.Week] = new SortedList();
                }
                ((SortedList)weeks_[selweek.Week]).Add(rb.Id, rb);
                ((ActivePersonResource)this.activePersonResources_[rb.Name]).AddObserver(rb);
            }
            // #1.04 - stop
            // #1.01.003 - moved line
            this.Notify();

            return(0);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Compares selectedweek to an other selectedweek
        /// </summary>
        /// <param name="obj1">An other selectedweek</param>
        /// <returns>0, if they are the same week, 1 if this week is after, -1 if this week is before</returns>
        public int CompareTo(object obj1)
        {
            SelectedWeek selweek  = (SelectedWeek)obj1;
            SelectedWeek selweek2 = (SelectedWeek)this;

            if (selweek2.Week == selweek.Week && selweek2.Year == selweek.Year)
            {
                return(0);
            }
            if (selweek2.Year == selweek.Year)
            {
                if (selweek2.Week > selweek.Week)
                {
                    return(1);
                }
                else
                {
                    return(-1);
                }
            }
            if (selweek2.Year > selweek.Year)
            {
                return(1);
            }
            else
            {
                return(-1);
            }
            return(0);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates or adds resourcebox to system
        /// </summary>
        /// <param name="resourcebox">Resourcebox to be updated or added</param>
        /// <param name="add">True if the resourcebox is to be added</param>
        /// <returns>0 - If all Ok, else a database error</returns>
        /// #1.04 - New index for week list (week number)
        public int setResourceBox(ResourceBox resourcebox, bool add)
        {
            try
            {
                // Save the current id-list
                SortedList oldids = new SortedList(resourcebox.IdsNextTo);
                int        fel    = db_.setResourceBox(resourcebox, add);
                if (fel != 0)
                {
                    return(fel);
                }
                if (add == true)
                {
                    // Add the resourcebox to the list
                    this.resourceBoxes_.Add(resourcebox.Id, resourcebox);
                    SelectedWeek selweek = new SelectedWeek(resourcebox.StartTime);
                    // #1.04 - start
                    if (!weeks_.ContainsKey(selweek.Week))
                    {
                        weeks_[selweek.Week] = new SortedList();
                    }
                    ((SortedList)weeks_[selweek.Week]).Add(resourcebox.Id, resourcebox);
                    // #1.04 - stop
                    ((ActivePersonResource)this.activePersonResources_[resourcebox.Name]).AddObserver(resourcebox);
                }
                // Update alla resourceboxes with the old id-list
                fel = this.updateIdsNextTo(oldids);

                // Update id-list of the resourcebox itself
                resourcebox.updateIdsNextTo(db_);

                // Update alla resourceboxes with the new id-list
                fel += this.updateIdsNextTo(resourcebox.IdsNextTo);
                resourcebox.Notify();
                if (fel != 0)
                {
                    return(fel);
                }
                return(0);
            }
            catch
            {
                // If there was en error update alla resourceboxes
                this.updateResourceBoxes();
            }
            return(ErrorHandler.ERR_UNEXPECTED_RESOURCEBOX_ADD);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initiate scheme, get all data from database.
        /// </summary>
        /// <param name="clu">Gui object that shows persons/resources</param>
        public void initScheme(Observer clu)
        {
            SortedList prl;

            // Get and setup all persons and resources
            ErrorHandler.ShowError(db_.getPersonsResources(out prl));
            setupPersonResourceList(prl, clu);
            clu.Update(this);

            // Get all resourceboxes
            this.selweek_ = new SelectedWeek(DateTime.Now);
            ErrorHandler.ShowError(db_.getActivitys(new DateTime(0), new DateTime(0), out activitys_));
            ErrorHandler.ShowError(db_.getSettings(out settings_));

            ErrorHandler.ShowError(updateResourceBoxes());
            this.Notify();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Removes a resourcebox from system.
        /// </summary>
        /// <param name="resourcebox">Resourcebox to remove</param>
        /// <returns>0 - If all Ok, else a database error</returns>
        /// #1.04 - New index for week list (week number)
        public int removeResourceBox(ResourceBox resourcebox)
        {
            // If the resourcebox just is locked, then just zero it, by setting end and startime to the same thing
            if (resourcebox.Locked == true)
            {
                resourcebox.EndTime   = resourcebox.LockedStartTime;
                resourcebox.StartTime = resourcebox.LockedStartTime;
                this.setResourceBox(resourcebox, false);
                resourcebox.Notify();
                return(0);
            }
            else
            {
                try
                {
                    // Get old id-list
                    SortedList oldids = new SortedList(resourcebox.IdsNextTo);
                    int        fel    = db_.removeResourceBox(resourcebox);
                    if (fel != 0)
                    {
                        return(fel);
                    }
                    // Update with old id-list
                    fel = this.updateIdsNextTo(oldids);

                    // HACK: är denna rad nödvändig?
                    fel += this.updateIdsNextTo(resourcebox.IdsNextTo);

                    this.resourceBoxes_.Remove(resourcebox.Id);

                    // Remove for week-lists (this week and next)
                    SelectedWeek selweek = new SelectedWeek(resourcebox.StartTime);
                    // #1.04 - start
                    if (weeks_.ContainsKey(selweek.Week))
                    {
                        ((SortedList)weeks_[selweek.Week]).Remove(resourcebox.Id);
                    }
                    selweek = new SelectedWeek(selweek.DateOfFirstDayInWeek.AddDays(7));
                    if (weeks_.ContainsKey(selweek.Week))
                    {
                        ((SortedList)weeks_[selweek.Week]).Remove(resourcebox.Id);
                    }
                    // #1.04 - stop
                    // Hide graphics
                    resourcebox.StartTime = new DateTime(0);
                    resourcebox.EndTime   = new DateTime(0);
                    resourcebox.Notify();

                    if (fel != 0)
                    {
                        return(fel);
                    }
                    return(0);
                }
                catch
                {
                    this.updateResourceBoxes();
                }
                return(ErrorHandler.ERR_UNEXPECTED_RESOURCEBOX_REM);
            }
        }