diff --git a/Caisses/Checkout.cs b/Caisses/Checkout.cs index 8b8f742..70b4a97 100644 --- a/Caisses/Checkout.cs +++ b/Caisses/Checkout.cs @@ -23,7 +23,7 @@ namespace Caisses } public void Tick(GraphicalStore store) { - if (!Open && store.AverageWaitingTime > GraphicalStore.CROSSOVER_TIME && store.GetEmptyCheckoutCount() == 0 || store.OpenCheckoutCount == 0) + if (!Open && store.AverageWaitingTime > GraphicalStore.CROSSOVER_TIME && store.GetEmptyCheckoutCount() == 0 || store.OpenCheckoutCount == 0 || store.WaitingClients.Count > MAX_CAPACITY * 2 && store.GetEmptyCheckoutCount() == 0) { Open = true; } diff --git a/Caisses/Form1.Designer.cs b/Caisses/Form1.Designer.cs index c3c44fa..b8977ca 100644 --- a/Caisses/Form1.Designer.cs +++ b/Caisses/Form1.Designer.cs @@ -44,10 +44,12 @@ this.label1 = new System.Windows.Forms.Label(); this.tmrRefresh = new System.Windows.Forms.Timer(this.components); this.tmrDraw = new System.Windows.Forms.Timer(this.components); + this.pbxWaitRoom = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(this.pbxRayons)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pbxCaisses)).BeginInit(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pbxWaitRoom)).BeginInit(); this.SuspendLayout(); // // pbxRayons @@ -61,9 +63,9 @@ // // pbxCaisses // - this.pbxCaisses.Location = new System.Drawing.Point(12, 375); + this.pbxCaisses.Location = new System.Drawing.Point(12, 575); this.pbxCaisses.Name = "pbxCaisses"; - this.pbxCaisses.Size = new System.Drawing.Size(838, 246); + this.pbxCaisses.Size = new System.Drawing.Size(1044, 246); this.pbxCaisses.TabIndex = 1; this.pbxCaisses.TabStop = false; // @@ -72,7 +74,7 @@ this.groupBox1.Controls.Add(this.btnAddTime); this.groupBox1.Controls.Add(this.btnAddClients); this.groupBox1.Controls.Add(this.btnStartStop); - this.groupBox1.Location = new System.Drawing.Point(856, 375); + this.groupBox1.Location = new System.Drawing.Point(856, 12); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(200, 125); this.groupBox1.TabIndex = 2; @@ -115,7 +117,7 @@ this.groupBox2.Controls.Add(this.lblAvaiblePlaces); this.groupBox2.Controls.Add(this.lblClientsWithoutCheckout); this.groupBox2.Controls.Add(this.label1); - this.groupBox2.Location = new System.Drawing.Point(856, 501); + this.groupBox2.Location = new System.Drawing.Point(856, 138); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(200, 120); this.groupBox2.TabIndex = 6; @@ -186,11 +188,20 @@ this.tmrDraw.Interval = 8; this.tmrDraw.Tick += new System.EventHandler(this.tmrDraw_Tick); // + // pbxWaitRoom + // + this.pbxWaitRoom.Location = new System.Drawing.Point(12, 375); + this.pbxWaitRoom.Name = "pbxWaitRoom"; + this.pbxWaitRoom.Size = new System.Drawing.Size(1044, 194); + this.pbxWaitRoom.TabIndex = 7; + this.pbxWaitRoom.TabStop = false; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1062, 623); + this.ClientSize = new System.Drawing.Size(1062, 833); + this.Controls.Add(this.pbxWaitRoom); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Controls.Add(this.pbxCaisses); @@ -202,6 +213,7 @@ this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pbxWaitRoom)).EndInit(); this.ResumeLayout(false); } @@ -223,6 +235,7 @@ private System.Windows.Forms.Label label1; private System.Windows.Forms.Timer tmrRefresh; private System.Windows.Forms.Timer tmrDraw; + private System.Windows.Forms.PictureBox pbxWaitRoom; } } diff --git a/Caisses/Form1.cs b/Caisses/Form1.cs index 2e52721..cc47ec7 100644 --- a/Caisses/Form1.cs +++ b/Caisses/Form1.cs @@ -17,7 +17,7 @@ namespace Caisses { InitializeComponent(); DoubleBuffered = true; - store = new GraphicalStore(20,12,pbxRayons.Size,pbxCaisses.Size); + store = new GraphicalStore(10,12,pbxRayons.Size,pbxCaisses.Size,pbxWaitRoom.Size); } private void btnStartStop_Click(object sender, EventArgs e) @@ -53,8 +53,13 @@ namespace Caisses { pbxCaisses.Image.Dispose(); } + if (pbxWaitRoom.Image != null) + { + pbxWaitRoom.Image.Dispose(); + } pbxRayons.Image = result[0]; pbxCaisses.Image = result[1]; + pbxWaitRoom.Image = result[2]; lblClients.Text = "Clients : " + store.Clients.Count(); lblClientsWithoutCheckout.Text = "Clients without checkout : "+ store.WaitingClients.Count(); diff --git a/Caisses/GraphicalClient.cs b/Caisses/GraphicalClient.cs index 3cacd93..cbf78d1 100644 --- a/Caisses/GraphicalClient.cs +++ b/Caisses/GraphicalClient.cs @@ -24,7 +24,7 @@ namespace Caisses public Size Size { get => _size; set => _size = value; } public Rectangle Area { get => _area; set => _area = value; } - public GraphicalClient(Point Entrance,Random random):base(random) + public GraphicalClient(Point Entrance, Random random) : base(random) { Random = random; Position = Entrance; @@ -39,21 +39,24 @@ namespace Caisses double val = (Random.NextDouble() * (max - min) + min); return (float)val; } - public void Update(Size area) + public void Update(Size StoreArea, Size WaitingRoomArea) { //base.Tick(); - Position = checkBounds(Position,area); + Position = checkBounds(Position, StoreArea, WaitingRoomArea); Color = Color.FromArgb(ShoppingTime * 2, 0, 0); } - public void Draw(Bitmap storeImage) + public void Draw(Bitmap storeImage, Bitmap waitingRoomImage) { - Update(storeImage.Size); + Update(storeImage.Size, waitingRoomImage.Size); Graphics g = Graphics.FromImage(storeImage); + if (this.State == Client.ClientState.Waiting) + g = Graphics.FromImage(waitingRoomImage); + switch (State) { case ClientState.Shopping: g.FillEllipse(new SolidBrush(Color), new RectangleF(Position, Size)); - g.DrawString(ShoppingTime.ToString(), new Font("Arial", 16), new SolidBrush(Color.White),new PointF(Position.X,Position.Y)); + g.DrawString(ShoppingTime.ToString(), new Font("Arial", 16), new SolidBrush(Color.White), new PointF(Position.X, Position.Y)); break; case ClientState.Waiting: g.FillEllipse(new SolidBrush(Color.Red), new RectangleF(Position, Size)); @@ -70,57 +73,41 @@ namespace Caisses break; } } - public PointF checkBounds(PointF position, Size area) + public PointF checkBounds(PointF position, Size StoreArea, Size WaitingArea) { - PointF newPosition = new PointF(position.X,position.Y); - /* - if (position.X < 0) + PointF newPosition = new PointF(position.X, position.Y); + Size area = StoreArea; + if (this.State == Client.ClientState.Waiting) + area = WaitingArea; + if (Position.X + Size.Width / 2 > area.Width || Position.Y + Size.Height / 2 > area.Height) { - newPosition.X = 0; - Speed = new Point(Speed.X * -1, Speed.Y); + //Its just that sometimes when transfered from the store to the waiting room, the clients ar stuck outside the bounds + newPosition = new PointF(0,0); } - if (position.X > area.Width) + else { - newPosition.X = area.Width; - Speed = new Point(Speed.X * -1, Speed.Y); + if (position.X + Speed.X > 0 && position.X + Size.Width + Speed.X < area.Width) + { + newPosition.X = position.X + Speed.X; + } + else + { + float diff = Math.Abs(position.X + Speed.X); + newPosition.X = diff; + Speed = new PointF(Speed.X * -1, Speed.Y); + } + if (position.Y + Speed.Y > 0 && position.Y + Size.Height + Speed.Y < area.Height) + { + newPosition.Y = position.Y + Speed.Y; + } + else + { + float diff = Math.Abs(position.Y + Speed.Y); + newPosition.Y = diff; + Speed = new PointF(Speed.X, Speed.Y * -1); + } } - if (position.Y < 0) - { - newPosition.Y = 0; - Speed = new Point(Speed.X, Speed.Y * -1); - } - if (position.Y > area.Height) - { - newPosition.Y = area.Height; - Speed = new Point(Speed.X, Speed.Y * -1); - }*/ - - if (position.X + Speed.X > 0 && position.X + Size.Width + Speed.X < area.Width) - { - newPosition.X = position.X + Speed.X; - } - else - { - float diff = Math.Abs(position.X + Speed.X); - newPosition.X = diff; - //newPosition = new Point(0, position.Y); - Speed = new PointF(Speed.X * -1,Speed.Y); - //speed.X += -1; - } - if (position.Y + Speed.Y > 0 && position.Y + Size.Height + Speed.Y < area.Height) - { - newPosition.Y = position.Y + Speed.Y; - } - else - { - float diff = Math.Abs(position.Y + Speed.Y); - newPosition.Y = diff; - //newPosition = new Point(position.X, 0); - Speed = new PointF(Speed.X,Speed.Y * -1); - //speed.Y *= -1; - } - return newPosition; } } diff --git a/Caisses/GraphicalStore.cs b/Caisses/GraphicalStore.cs index db3d52a..7cd55bd 100644 --- a/Caisses/GraphicalStore.cs +++ b/Caisses/GraphicalStore.cs @@ -17,6 +17,7 @@ namespace Caisses private int _timeOfTheDayInMinuts; private Bitmap _shelvesCorner; private Bitmap _checkoutCorner; + private Bitmap _waitingCorner; private Random rnd; /// Stats @@ -40,19 +41,21 @@ namespace Caisses internal List Checkouts { get => _checkouts; set => _checkouts = value; } public Bitmap ShelvesCorner { get => _shelvesCorner; set => _shelvesCorner = value; } public Bitmap CheckoutCorner { get => _checkoutCorner; set => _checkoutCorner = value; } + public Bitmap WaitingCorner { get => _waitingCorner; set => _waitingCorner = value; } public int TimeOfTheDayInHours { get { return _timeOfTheDayInMinuts / 60; } } - public GraphicalStore(int startingHour, int checkoutNumber, Size shelvesCornerSize, Size checkoutCornerSize) + public GraphicalStore(int startingHour, int checkoutNumber, Size shelvesCornerSize, Size checkoutCornerSize, Size waitingCornerSize) { TimeOfTheDayInMinuts = startingHour * 60; Clients = new List(); Checkouts = new List(); CheckoutCorner = new Bitmap(checkoutCornerSize.Width, checkoutCornerSize.Height); ShelvesCorner = new Bitmap(shelvesCornerSize.Width, shelvesCornerSize.Height); + WaitingCorner = new Bitmap(waitingCornerSize.Width, waitingCornerSize.Height); rnd = new Random(); FillStore(ATTENDANCE[TimeOfTheDayInHours]); @@ -194,9 +197,10 @@ namespace Caisses { ShelvesCorner = new Bitmap(ShelvesCorner.Width, ShelvesCorner.Height); CheckoutCorner = new Bitmap(CheckoutCorner.Width, CheckoutCorner.Height); + WaitingCorner = new Bitmap(WaitingCorner.Width, WaitingCorner.Height); foreach (GraphicalClient client in Clients) { - client.Draw(ShelvesCorner); + client.Draw(ShelvesCorner,WaitingCorner); } foreach (GraphicalCheckout checkout in Checkouts) @@ -204,11 +208,11 @@ namespace Caisses checkout.Draw(CheckoutCorner); foreach (GraphicalClient client in checkout.Clients) { - client.Draw(ShelvesCorner); + client.Draw(ShelvesCorner,WaitingCorner); } } - return new List { ShelvesCorner, CheckoutCorner }; + return new List { ShelvesCorner, CheckoutCorner, WaitingCorner}; } public virtual void FillStore(int amountOfNewClients) {