Ejemplo n.º 1
0
        /// <summary>
        /// Find a old RbUI in cahce or create a new one.
        /// Revision:
        /// #1.01.001 Added param rb to solve bug SL-5
        /// </summary>
        /// <returns>Free resoucebox UI</returns>
        private ResourceBoxUI findFreeResourceBoxUI(ResourceBox rb)
        {
//			foreach ( ResourceBoxUI rbui in this.resursboxuis_.Values ) #1.02.001 - row changed
            foreach (ResourceBoxUI rbui in resursboxuis_.Values)
            {
                try
                {
                    // Use only resourceboxes that are not displayed
                    if (rbui.ResourceBox.StartTime < Scheme.Instance.SelectedWeek.DateOfFirstDayInWeek ||
                        rbui.ResourceBox.StartTime > Scheme.Instance.SelectedWeek.DateOfFirstDayInWeek.AddDays(SchemaUI.DAYS_SHOWN))
                    {
                        ((ActivePersonResource)Scheme.Instance.ActivePersonsResources[rbui.ResourceBox.Name]).RemoveObserver(rbui);
                        rbui.ResourceBox.RemoveObserver(rbui);
                        return(rbui);
                    }
                }
                catch
                {
                    // #1.01.007 - cause of SL-11?
//					return rbui; -- line removed
                }
            }
            // No cahed object found, create a new
            // # 1.01.001 Row changed
//			ResourceBoxUI newrbui = new ResourceBoxUI();
            ResourceBoxUI newrbui = new ResourceBoxUI(rb, information_);

//			this.Controls.Add(newrbui); # 1.02.001 - row removed

            return(newrbui);
        }
Ejemplo n.º 2
0
        private void Sheet_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ResourceBoxUI rbui = this.findRBUI(e.X, e.Y);
                if (rbui != null)
                {
                    rbui.displayInformation();
                }

/*				SchemaUI.currentrbui = this;
 *                              Point ptCursor = Cursor.Position;
 *                              ptCursor = PointToClient(ptCursor);
 *
 *                              origo_x = Cursor.Position.X;
 *                              origo_y = Cursor.Position.Y;
 *                              origo_height = this.Height;
 *                              left_ = this.Left;
 *                              top_ = this.Top;
 *                              if ( this.Height-ptCursor.Y < PULL_AREA || ptCursor.Y < PULL_AREA )
 *                                      changesize = true;
 *                              else
 *                                      drag = true;
 *                              if ( ptCursor.Y > this.Height-PULL_AREA )
 *                              {
 *                                      pull_lower = true;
 *                                      diff_y = this.Height-ptCursor.Y;
 *                              }
 *                              if ( ptCursor.Y < PULL_AREA )
 *                              {
 *                                      pull_upper = true;
 *                                      diff_y = ptCursor.Y;
 *                              }
 *                              displayInformation(); */
            }
            if (e.Button == MouseButtons.Right)
            {
                ResourceBoxUI rbui = this.findRBUI(e.X, e.Y);
                if (rbui != null)
                {
                    this.ContextMenu = rbui.ContextMenu;
                    this.ContextMenu.Show(this, new Point(e.X, e.Y));
                }
                else
                {
                    this.ContextMenu = null;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add resourceboxUI to a schemaUI
        /// </summary>
        /// <param name="rb">ResourceBox</param>
        public void addResourcebox(ResourceBox rb)
        {
            // Check if the resoucebox already exists
//			if ( this.resursboxuis_.ContainsKey(rb.Id) ) #1.02.001 - row changed
            if (resursboxuis_.ContainsKey(rb.Id))
            {
//				((ResourceBoxUI)this.resursboxuis_[rb.Id]).Update(this); #1.02.001 - row changed
                ((ResourceBoxUI)resursboxuis_[rb.Id]).Update(this);
                return;
            }

            // Create graphics object to represent the resourcebox
            ResourceBoxUI rbui;

//			if ( this.resursboxuis_.Count < this.cacheSize ) #1.02.001 - row changed
            if (resursboxuis_.Count < this.cacheSize)
            {
                rbui = new ResourceBoxUI(rb, information_);
//				Controls.Add(rbui); #1.02.001 - row removed
//				this.resursboxuis_.Add(rb.Id, rbui); #1.02.001 - row changed
                resursboxuis_.Add(rb.Id, rbui);
            }
            else
            {
                // #1.01.001 Added param rb to solve bug SL-5
                rbui = findFreeResourceBoxUI(rb);

                // HACK: Better code please!
                try
                {
                    resursboxuis_.Remove(rbui.ResourceBox.Id);
                }
                catch
                {
                }

                rbui.ResourceBox = rb;

//				this.resursboxuis_.Add(rb.Id, rbui); #1.02.001 - row changed
                resursboxuis_.Add(rb.Id, rbui);
            }
            // #1.02.001 - row added
            rbui.Parent = this;
            rb.AddObserver(rbui);
            ((ActivePersonResource)Scheme.Instance.ActivePersonsResources[rb.Name]).AddObserver(rbui);
            rbui.Update(this);
        }
Ejemplo n.º 4
0
// #1.02.001 - Added functions - start
        private void Sheet_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (!(move || cs_up || cs_down))
                {
                    ResourceBoxUI rbui = this.findRBUI(e.X, e.Y);
                    if (rbui != null)
                    {
                        if (rbui.isChangeSizeUp(e.X, e.Y))
                        {
                            org_x            = e.X;
                            org_y            = e.Y;
                            this.currentrbui = rbui;
                            curr_rect        = org_rect = rbui.Current_Rect;
                            this.cs_up       = true;
                        }
                        else if (rbui.isChangeSizeDown(e.X, e.Y))
                        {
                            org_x            = e.X;
                            org_y            = e.Y;
                            this.currentrbui = rbui;
                            curr_rect        = org_rect = rbui.Current_Rect;
                            this.cs_down     = true;
                        }
                        else if (rbui.isMove(e.X, e.Y))
                        {
                            org_x            = e.X;
                            org_y            = e.Y;
                            this.move        = true;
                            this.currentrbui = rbui;
                            curr_rect        = org_rect = rbui.Current_Rect;
                        }
                    }
                }
            }
            if (move && e.Button == MouseButtons.Left)
            {
                //				this.Invalidate(new Rectangle(curr_rect.X-5, curr_rect.Y-5, curr_rect.Width+10, curr_rect.Height+10));
                Point     p      = PointToClient(Cursor.Position);
                int       diff_x = org_x - p.X;
                int       diff_y = org_y - p.Y;
                Rectangle rect   = new Rectangle(org_rect.X - diff_x, org_rect.Y - diff_y, org_rect.Width, org_rect.Height);

                //				Rectangle rect = curr_rect;

                prev_rect = curr_rect;
                curr_rect = rect;

//				this.Invalidate(new Rectangle(Math.Min(curr_rect.X-1,prev_rect.X-1), Math.Min(curr_rect.Y-1,prev_rect.Y-1),Math.Max(curr_rect.X+curr_rect.Width, prev_rect.X+prev_rect.Width)-Math.Min(curr_rect.X,prev_rect.X)+20,Math.Max(curr_rect.Y+curr_rect.Height, prev_rect.Y+prev_rect.Height)-Math.Min(curr_rect.Y,prev_rect.Y)+20));
                this.Invalidate(prev_rect);
//				this.Update();
            }
            else if (move)
            {
                currentrbui.setNewCoords(curr_rect);
                move = false;
//				this.Invalidate(new Rectangle(Math.Min(curr_rect.X-1,prev_rect.X-1), Math.Min(curr_rect.Y-1,prev_rect.Y-1),Math.Max(curr_rect.X+curr_rect.Width, prev_rect.X+prev_rect.Width)-Math.Min(curr_rect.X,prev_rect.X)+20,Math.Max(curr_rect.Y+curr_rect.Height, prev_rect.Y+prev_rect.Height)-Math.Min(curr_rect.Y,prev_rect.Y)+20));
                this.Invalidate();
                this.Update();
            }
            else if ((cs_up || cs_down) && e.Button == MouseButtons.Left)
            {
                Point p = PointToClient(Cursor.Position);
//				int diff_x = org_x - p.X;
                int diff_y = org_y - p.Y;

                Rectangle rect = new Rectangle(0, 0, 0, 0);
                if (cs_up)
                {
                    if (org_rect.Y - diff_y > org_rect.Y + org_rect.Height - SchemaUI.SCHEME_HOUR_PIXELS / 2)
                    {
                        diff_y = -org_rect.Height + SchemaUI.SCHEME_HOUR_PIXELS / 2;
                    }
                    rect = new Rectangle(org_rect.X, org_rect.Y - diff_y, org_rect.Width, Math.Max(SchemaUI.SCHEME_HOUR_PIXELS / 2, org_rect.Height) + diff_y);
                }
                else if (cs_down)
                {
                    rect = new Rectangle(org_rect.X, org_rect.Y, org_rect.Width, Math.Max(SchemaUI.SCHEME_HOUR_PIXELS / 2, org_rect.Height - diff_y));
                }

                //				Rectangle rect = curr_rect;

                prev_rect = curr_rect;
                curr_rect = rect;
//				this.Invalidate(new Rectangle(Math.Min(curr_rect.X-1,prev_rect.X-1), Math.Min(curr_rect.Y-1,prev_rect.Y-1),Math.Max(curr_rect.X+curr_rect.Width, prev_rect.X+prev_rect.Width)-Math.Min(curr_rect.X,prev_rect.X)+20,Math.Max(curr_rect.Y+curr_rect.Height, prev_rect.Y+prev_rect.Height)-Math.Min(curr_rect.Y,prev_rect.Y)+20));
//				this.Invalidate(new Rectangle(Math.Min(curr_rect.X,prev_rect.X), Math.Min(curr_rect.Y,prev_rect.Y),Math.Max(curr_rect.X+curr_rect.Width, prev_rect.X+prev_rect.Width)-Math.Min(curr_rect.X,prev_rect.X)+5,Math.Max(curr_rect.Y+curr_rect.Height, prev_rect.Y+prev_rect.Height)-Math.Min(curr_rect.Y,prev_rect.Y)+20));
                this.Invalidate(prev_rect);
//				this.Update();
            }
            else if (cs_up || cs_down)
            {
                if (curr_rect.Height < SchemaUI.SCHEME_HOUR_PIXELS / 2)
                {
                    curr_rect.Height = SchemaUI.SCHEME_HOUR_PIXELS / 2;
                }
                currentrbui.setNewCoords(curr_rect);
                cs_up   = false;
                cs_down = false;
//				this.Invalidate(new Rectangle(Math.Min(curr_rect.X,prev_rect.X), Math.Min(curr_rect.Y,prev_rect.Y),Math.Max(curr_rect.X+curr_rect.Width, prev_rect.X+prev_rect.Width)-Math.Min(curr_rect.X,prev_rect.X)+20,Math.Max(curr_rect.Y+curr_rect.Height, prev_rect.Y+prev_rect.Height)-Math.Min(curr_rect.Y,prev_rect.Y)+20));
                this.Invalidate();
//				this.Update();
            }
            else
            {
                ResourceBoxUI rbui = this.findRBUI(e.X, e.Y);
                if (rbui != null)
                {
                    if (rbui.isChangeSizeDown(e.X, e.Y) || rbui.isChangeSizeUp(e.X, e.Y))
                    {
                        Cursor.Current = Cursors.SizeNS;
                    }
                    else
                    {
                        Cursor.Current = Cursors.Default;
                    }
                }
            }
        }