Added a waiting room and now the checkouts also take the number of people waiting in count for when to open

This commit is contained in:
2023-01-11 16:06:47 +01:00
parent 780f9a8c28
commit a891033a25
5 changed files with 71 additions and 62 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ namespace Caisses
} }
public void Tick(GraphicalStore store) 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; Open = true;
} }
+18 -5
View File
@@ -44,10 +44,12 @@
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.tmrRefresh = new System.Windows.Forms.Timer(this.components); this.tmrRefresh = new System.Windows.Forms.Timer(this.components);
this.tmrDraw = 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.pbxRayons)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pbxCaisses)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pbxCaisses)).BeginInit();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pbxWaitRoom)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// pbxRayons // pbxRayons
@@ -61,9 +63,9 @@
// //
// pbxCaisses // 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.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.TabIndex = 1;
this.pbxCaisses.TabStop = false; this.pbxCaisses.TabStop = false;
// //
@@ -72,7 +74,7 @@
this.groupBox1.Controls.Add(this.btnAddTime); this.groupBox1.Controls.Add(this.btnAddTime);
this.groupBox1.Controls.Add(this.btnAddClients); this.groupBox1.Controls.Add(this.btnAddClients);
this.groupBox1.Controls.Add(this.btnStartStop); 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.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(200, 125); this.groupBox1.Size = new System.Drawing.Size(200, 125);
this.groupBox1.TabIndex = 2; this.groupBox1.TabIndex = 2;
@@ -115,7 +117,7 @@
this.groupBox2.Controls.Add(this.lblAvaiblePlaces); this.groupBox2.Controls.Add(this.lblAvaiblePlaces);
this.groupBox2.Controls.Add(this.lblClientsWithoutCheckout); this.groupBox2.Controls.Add(this.lblClientsWithoutCheckout);
this.groupBox2.Controls.Add(this.label1); 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.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(200, 120); this.groupBox2.Size = new System.Drawing.Size(200, 120);
this.groupBox2.TabIndex = 6; this.groupBox2.TabIndex = 6;
@@ -186,11 +188,20 @@
this.tmrDraw.Interval = 8; this.tmrDraw.Interval = 8;
this.tmrDraw.Tick += new System.EventHandler(this.tmrDraw_Tick); 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 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.groupBox2);
this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox1);
this.Controls.Add(this.pbxCaisses); this.Controls.Add(this.pbxCaisses);
@@ -202,6 +213,7 @@
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false); this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout(); this.groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pbxWaitRoom)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@@ -223,6 +235,7 @@
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.Timer tmrRefresh; private System.Windows.Forms.Timer tmrRefresh;
private System.Windows.Forms.Timer tmrDraw; private System.Windows.Forms.Timer tmrDraw;
private System.Windows.Forms.PictureBox pbxWaitRoom;
} }
} }
+6 -1
View File
@@ -17,7 +17,7 @@ namespace Caisses
{ {
InitializeComponent(); InitializeComponent();
DoubleBuffered = true; 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) private void btnStartStop_Click(object sender, EventArgs e)
@@ -53,8 +53,13 @@ namespace Caisses
{ {
pbxCaisses.Image.Dispose(); pbxCaisses.Image.Dispose();
} }
if (pbxWaitRoom.Image != null)
{
pbxWaitRoom.Image.Dispose();
}
pbxRayons.Image = result[0]; pbxRayons.Image = result[0];
pbxCaisses.Image = result[1]; pbxCaisses.Image = result[1];
pbxWaitRoom.Image = result[2];
lblClients.Text = "Clients : " + store.Clients.Count(); lblClients.Text = "Clients : " + store.Clients.Count();
lblClientsWithoutCheckout.Text = "Clients without checkout : "+ store.WaitingClients.Count(); lblClientsWithoutCheckout.Text = "Clients without checkout : "+ store.WaitingClients.Count();
+38 -51
View File
@@ -24,7 +24,7 @@ namespace Caisses
public Size Size { get => _size; set => _size = value; } public Size Size { get => _size; set => _size = value; }
public Rectangle Area { get => _area; set => _area = 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; Random = random;
Position = Entrance; Position = Entrance;
@@ -39,21 +39,24 @@ namespace Caisses
double val = (Random.NextDouble() * (max - min) + min); double val = (Random.NextDouble() * (max - min) + min);
return (float)val; return (float)val;
} }
public void Update(Size area) public void Update(Size StoreArea, Size WaitingRoomArea)
{ {
//base.Tick(); //base.Tick();
Position = checkBounds(Position,area); Position = checkBounds(Position, StoreArea, WaitingRoomArea);
Color = Color.FromArgb(ShoppingTime * 2, 0, 0); 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); Graphics g = Graphics.FromImage(storeImage);
if (this.State == Client.ClientState.Waiting)
g = Graphics.FromImage(waitingRoomImage);
switch (State) switch (State)
{ {
case ClientState.Shopping: case ClientState.Shopping:
g.FillEllipse(new SolidBrush(Color), new RectangleF(Position, Size)); 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; break;
case ClientState.Waiting: case ClientState.Waiting:
g.FillEllipse(new SolidBrush(Color.Red), new RectangleF(Position, Size)); g.FillEllipse(new SolidBrush(Color.Red), new RectangleF(Position, Size));
@@ -70,57 +73,41 @@ namespace Caisses
break; 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); PointF newPosition = new PointF(position.X, position.Y);
/* Size area = StoreArea;
if (position.X < 0) 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; //Its just that sometimes when transfered from the store to the waiting room, the clients ar stuck outside the bounds
Speed = new Point(Speed.X * -1, Speed.Y); newPosition = new PointF(0,0);
} }
if (position.X > area.Width) else
{ {
newPosition.X = area.Width; if (position.X + Speed.X > 0 && position.X + Size.Width + Speed.X < area.Width)
Speed = new Point(Speed.X * -1, Speed.Y); {
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; return newPosition;
} }
} }
+8 -4
View File
@@ -17,6 +17,7 @@ namespace Caisses
private int _timeOfTheDayInMinuts; private int _timeOfTheDayInMinuts;
private Bitmap _shelvesCorner; private Bitmap _shelvesCorner;
private Bitmap _checkoutCorner; private Bitmap _checkoutCorner;
private Bitmap _waitingCorner;
private Random rnd; private Random rnd;
/// Stats /// Stats
@@ -40,19 +41,21 @@ namespace Caisses
internal List<GraphicalCheckout> Checkouts { get => _checkouts; set => _checkouts = value; } internal List<GraphicalCheckout> Checkouts { get => _checkouts; set => _checkouts = value; }
public Bitmap ShelvesCorner { get => _shelvesCorner; set => _shelvesCorner = value; } public Bitmap ShelvesCorner { get => _shelvesCorner; set => _shelvesCorner = value; }
public Bitmap CheckoutCorner { get => _checkoutCorner; set => _checkoutCorner = value; } public Bitmap CheckoutCorner { get => _checkoutCorner; set => _checkoutCorner = value; }
public Bitmap WaitingCorner { get => _waitingCorner; set => _waitingCorner = value; }
public int TimeOfTheDayInHours public int TimeOfTheDayInHours
{ {
get { return _timeOfTheDayInMinuts / 60; } 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; TimeOfTheDayInMinuts = startingHour * 60;
Clients = new List<GraphicalClient>(); Clients = new List<GraphicalClient>();
Checkouts = new List<GraphicalCheckout>(); Checkouts = new List<GraphicalCheckout>();
CheckoutCorner = new Bitmap(checkoutCornerSize.Width, checkoutCornerSize.Height); CheckoutCorner = new Bitmap(checkoutCornerSize.Width, checkoutCornerSize.Height);
ShelvesCorner = new Bitmap(shelvesCornerSize.Width, shelvesCornerSize.Height); ShelvesCorner = new Bitmap(shelvesCornerSize.Width, shelvesCornerSize.Height);
WaitingCorner = new Bitmap(waitingCornerSize.Width, waitingCornerSize.Height);
rnd = new Random(); rnd = new Random();
FillStore(ATTENDANCE[TimeOfTheDayInHours]); FillStore(ATTENDANCE[TimeOfTheDayInHours]);
@@ -194,9 +197,10 @@ namespace Caisses
{ {
ShelvesCorner = new Bitmap(ShelvesCorner.Width, ShelvesCorner.Height); ShelvesCorner = new Bitmap(ShelvesCorner.Width, ShelvesCorner.Height);
CheckoutCorner = new Bitmap(CheckoutCorner.Width, CheckoutCorner.Height); CheckoutCorner = new Bitmap(CheckoutCorner.Width, CheckoutCorner.Height);
WaitingCorner = new Bitmap(WaitingCorner.Width, WaitingCorner.Height);
foreach (GraphicalClient client in Clients) foreach (GraphicalClient client in Clients)
{ {
client.Draw(ShelvesCorner); client.Draw(ShelvesCorner,WaitingCorner);
} }
foreach (GraphicalCheckout checkout in Checkouts) foreach (GraphicalCheckout checkout in Checkouts)
@@ -204,11 +208,11 @@ namespace Caisses
checkout.Draw(CheckoutCorner); checkout.Draw(CheckoutCorner);
foreach (GraphicalClient client in checkout.Clients) foreach (GraphicalClient client in checkout.Clients)
{ {
client.Draw(ShelvesCorner); client.Draw(ShelvesCorner,WaitingCorner);
} }
} }
return new List<Bitmap> { ShelvesCorner, CheckoutCorner }; return new List<Bitmap> { ShelvesCorner, CheckoutCorner, WaitingCorner};
} }
public virtual void FillStore(int amountOfNewClients) public virtual void FillStore(int amountOfNewClients)
{ {