180 lines
5.7 KiB
C#
180 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Caisses
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
// for the drag and drop of the form
|
|
public const int WM_NCLBUTTONDOWN = 0xA1;
|
|
public const int HT_CAPTION = 0x2;
|
|
[DllImportAttribute("user32.dll")]
|
|
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
|
|
[DllImportAttribute("user32.dll")]
|
|
public static extern bool ReleaseCapture();
|
|
// for the drag and drop of the form
|
|
|
|
GraphicalStore store;
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
DoubleBuffered = true;
|
|
store = new GraphicalStore(10, 12, pbxCaisses.Size);
|
|
}
|
|
|
|
private void btnStartStop_Click(object sender, EventArgs e)
|
|
{
|
|
StartSimulation();
|
|
}
|
|
public void StartSimulation()
|
|
{
|
|
if (tmrRefresh.Enabled)
|
|
{
|
|
tmrRefresh.Stop();
|
|
tmrDraw.Stop();
|
|
btnStartStop.Text = "Start";
|
|
}
|
|
else
|
|
{
|
|
tmrRefresh.Start();
|
|
tmrDraw.Start();
|
|
btnStartStop.Text = "Stop";
|
|
}
|
|
}
|
|
|
|
private void tmrRefresh_Tick(object sender, EventArgs e)
|
|
{
|
|
store.Tick();
|
|
}
|
|
|
|
private void tmrDraw_Tick(object sender, EventArgs e)
|
|
{
|
|
List<Bitmap> result = store.Draw(pbxRayons.Size, pbxWaitRoom.Size, pbxCaisses.Size);
|
|
if (pbxRayons.Image != null)
|
|
{
|
|
pbxRayons.Image.Dispose();
|
|
}
|
|
if (pbxCaisses.Image != null)
|
|
{
|
|
pbxCaisses.Image.Dispose();
|
|
}
|
|
if (pbxWaitRoom.Image != null)
|
|
{
|
|
pbxWaitRoom.Image.Dispose();
|
|
}
|
|
pbxRayons.Image = result[0];
|
|
pbxWaitRoom.Image = result[1];
|
|
pbxCaisses.Image = result[2];
|
|
|
|
lblClients.Text = "Clients : " + store.Clients.Count();
|
|
lblClientsWithoutCheckout.Text = "Clients without checkout : " + store.WaitingClients.Count();
|
|
lblAvaiblePlaces.Text = "Avaible places = " + store.TotalPlacesLeftCount;
|
|
lblAvgWaitingTime.Text = "AverageWaitingTime = " + store.AverageWaitingTime;
|
|
lblTime.Text = "Time of the day : " + store.TimeOfTheDayInHours + ":" + store.TimeOfTheDayInMinuts % 60;
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
ResizeCanvas();
|
|
pbxCaisses.MouseDown += Form1_MouseDown;
|
|
pbxRayons.MouseDown += Form1_MouseDown;
|
|
pbxWaitRoom.MouseDown += Form1_MouseDown;
|
|
|
|
this.KeyPreview = true;
|
|
}
|
|
|
|
private void pbxWaitRoom_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void pbxCaisses_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void pbxRayons_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void Form1_Resize(object sender, EventArgs e)
|
|
{
|
|
ResizeCanvas();
|
|
}
|
|
private void ResizeCanvas()
|
|
{
|
|
/*
|
|
pbxRayons.Size = new Size(this.Width, Convert.ToInt32((this.Height / 10.0) * 5.0));
|
|
pbxRayons.Location = new Point(0, 0);
|
|
pbxWaitRoom.Size = new Size(this.Width, Convert.ToInt32((this.Height / 10.0) * 2.0));
|
|
pbxWaitRoom.Location = new Point(0, pbxRayons.Height);
|
|
pbxCaisses.Size = new Size(this.Width, Convert.ToInt32((this.Height / 10.0) * 3.0));
|
|
pbxCaisses.Location = new Point(0, pbxWaitRoom.Location.Y + pbxWaitRoom.Height);
|
|
*/
|
|
pbxRayons.Size = new Size(this.Width, Convert.ToInt32((this.Height / 10.0) * 7.0));
|
|
pbxRayons.Location = new Point(0, 0);
|
|
|
|
pbxWaitRoom.Size = new Size(this.Width / 6, this.Height / 3);
|
|
pbxWaitRoom.Location = new Point(this.Width - pbxWaitRoom.Width, 0);
|
|
|
|
pbxCaisses.Size = new Size(this.Width, Convert.ToInt32((this.Height / 10.0) * 3.0));
|
|
pbxCaisses.Location = new Point(0, pbxRayons.Height);
|
|
}
|
|
|
|
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar == 'f' || e.KeyChar == 'F')
|
|
{
|
|
//We need to put the form in fullScreen
|
|
if (this.WindowState == FormWindowState.Normal)
|
|
{
|
|
this.WindowState = FormWindowState.Maximized;
|
|
}
|
|
else
|
|
{
|
|
this.WindowState = FormWindowState.Normal;
|
|
}
|
|
}
|
|
if (e.KeyChar == (char)Keys.Escape)
|
|
Application.Exit();
|
|
if (e.KeyChar == 'o' || e.KeyChar == 'O')
|
|
pnlOptions.Visible = !pnlOptions.Visible;
|
|
if (e.KeyChar == (char)Keys.Space)
|
|
StartSimulation();
|
|
}
|
|
|
|
private void Form1_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
ReleaseCapture();
|
|
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
|
|
}
|
|
}
|
|
|
|
private void btnAdd5Clients_Click(object sender, EventArgs e)
|
|
{
|
|
store.AddClients(5);
|
|
}
|
|
|
|
private void btnEmptyStore_Click(object sender, EventArgs e)
|
|
{
|
|
store.ClearStore();
|
|
}
|
|
|
|
private void btnEmptyWaitingRoom_Click(object sender, EventArgs e)
|
|
{
|
|
store.ClearWaitingRoom();
|
|
}
|
|
}
|
|
}
|