From 99aca4929015662c15571352ec66220cb8935528 Mon Sep 17 00:00:00 2001 From: maxluli Date: Mon, 2 Jan 2023 11:27:38 +0100 Subject: [PATCH] first commit because I dont want to lose this project --- .gitignore | 402 +++++++++++++++++++++++ Caisses.sln | 25 ++ Caisses/App.config | 6 + Caisses/Caisses.csproj | 89 +++++ Caisses/Checkout.cs | 53 +++ Caisses/Client.cs | 69 ++++ Caisses/Form1.Designer.cs | 227 +++++++++++++ Caisses/Form1.cs | 66 ++++ Caisses/Form1.resx | 126 +++++++ Caisses/GraphicalCheckout.cs | 45 +++ Caisses/GraphicalClient.cs | 122 +++++++ Caisses/Program.cs | 22 ++ Caisses/Properties/AssemblyInfo.cs | 36 ++ Caisses/Properties/Resources.Designer.cs | 71 ++++ Caisses/Properties/Resources.resx | 117 +++++++ Caisses/Properties/Settings.Designer.cs | 30 ++ Caisses/Properties/Settings.settings | 7 + Caisses/Store.cs | 227 +++++++++++++ 18 files changed, 1740 insertions(+) create mode 100644 .gitignore create mode 100644 Caisses.sln create mode 100644 Caisses/App.config create mode 100644 Caisses/Caisses.csproj create mode 100644 Caisses/Checkout.cs create mode 100644 Caisses/Client.cs create mode 100644 Caisses/Form1.Designer.cs create mode 100644 Caisses/Form1.cs create mode 100644 Caisses/Form1.resx create mode 100644 Caisses/GraphicalCheckout.cs create mode 100644 Caisses/GraphicalClient.cs create mode 100644 Caisses/Program.cs create mode 100644 Caisses/Properties/AssemblyInfo.cs create mode 100644 Caisses/Properties/Resources.Designer.cs create mode 100644 Caisses/Properties/Resources.resx create mode 100644 Caisses/Properties/Settings.Designer.cs create mode 100644 Caisses/Properties/Settings.settings create mode 100644 Caisses/Store.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4507fc7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,402 @@ +# Created by https://www.toptal.com/developers/gitignore/api/csharp +# Edit at https://www.toptal.com/developers/gitignore?templates=csharp + +### Csharp ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +# End of https://www.toptal.com/developers/gitignore/api/csharp \ No newline at end of file diff --git a/Caisses.sln b/Caisses.sln new file mode 100644 index 0000000..8ef70fe --- /dev/null +++ b/Caisses.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32526.322 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Caisses", "Caisses\Caisses.csproj", "{210D00A1-C688-4053-9C6F-8939E30B01E3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {210D00A1-C688-4053-9C6F-8939E30B01E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {210D00A1-C688-4053-9C6F-8939E30B01E3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {210D00A1-C688-4053-9C6F-8939E30B01E3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {210D00A1-C688-4053-9C6F-8939E30B01E3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6EB33172-EFA4-46DC-8079-F28C13A24B7F} + EndGlobalSection +EndGlobal diff --git a/Caisses/App.config b/Caisses/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/Caisses/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Caisses/Caisses.csproj b/Caisses/Caisses.csproj new file mode 100644 index 0000000..ac9707e --- /dev/null +++ b/Caisses/Caisses.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {210D00A1-C688-4053-9C6F-8939E30B01E3} + WinExe + Caisses + Caisses + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/Caisses/Checkout.cs b/Caisses/Checkout.cs new file mode 100644 index 0000000..11344ca --- /dev/null +++ b/Caisses/Checkout.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Caisses +{ + internal class Checkout + { + public const int MAX_CAPACITY = 5; + + private List clients; + private bool open; + private int crossoverTime; + + public List Clients { get => clients; set => clients = value; } + public bool Open { get => open; set => open = value; } + + public Checkout() + { + Clients = new List(); + Open = false; + } + public void Tick(int averageWaitingTime, int CrossoverTime) + { + if (!Open && averageWaitingTime > CrossoverTime) + { + Open = true; + } + if (Open && averageWaitingTime < CrossoverTime && Clients.Count == 0) + { + Open = false; + } + /* + if (Clients.Count != 0) + { + //This is the first client inline + Client client = Clients[0]; + if (client.State == Client.ClientState.Inline) + client.State = Client.ClientState.Checkout; + + + if (client.CheckoutTime <= 0) + { + I think we need to do this processing in the store + } + + } + */ + } + } +} diff --git a/Caisses/Client.cs b/Caisses/Client.cs new file mode 100644 index 0000000..204d534 --- /dev/null +++ b/Caisses/Client.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Caisses +{ + public class Client + { + public const int MAX_SHOPPING_TIME = 100; //Original 100 + public const int MIN_SHOPPING_TIME = 10; //Original 10 + + public enum ClientState + { + Shopping, + Waiting, + Inline, + Checkout, + } + + private int _shoppingTime; + private int _waitingTime; + private int _checkoutTime; + private ClientState _state; + protected static Random Random; + public int ShoppingTime + { + get { return _shoppingTime; } + //set { _shoppingTime = value; if (_shoppingTime <= 0) { State = ClientState.Waiting; } } + set { _shoppingTime = value; } + } + public int WaitingTime { get => _waitingTime; set => _waitingTime = value; } + public ClientState State { get => _state; set => _state = value; } + public int CheckoutTime { get => _checkoutTime; set => _checkoutTime = value; } + + public Client(Random random) + { + Random = random; + ShoppingTime = Random.Next(MIN_SHOPPING_TIME,MAX_SHOPPING_TIME); + CheckoutTime = ShoppingTime / 5; + State = ClientState.Shopping; + } + public void Tick() + { + switch (State) + { + case ClientState.Shopping: + ShoppingTime -= 1; + if (ShoppingTime <= 0) + { + State = ClientState.Waiting; + } + break; + case ClientState.Waiting: + WaitingTime += 1; + break; + case ClientState.Inline: + //We dont do anything when he is in a checkoutLine + break; + case ClientState.Checkout: + CheckoutTime -= 1; + break; + default: + break; + } + } + } +} diff --git a/Caisses/Form1.Designer.cs b/Caisses/Form1.Designer.cs new file mode 100644 index 0000000..0209d93 --- /dev/null +++ b/Caisses/Form1.Designer.cs @@ -0,0 +1,227 @@ +namespace Caisses +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.pbxRayons = new System.Windows.Forms.PictureBox(); + this.pbxCaisses = new System.Windows.Forms.PictureBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.btnAddTime = new System.Windows.Forms.Button(); + this.btnAddClients = new System.Windows.Forms.Button(); + this.btnStartStop = new System.Windows.Forms.Button(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.lblTime = new System.Windows.Forms.Label(); + this.lblAvgWaitingTime = new System.Windows.Forms.Label(); + this.lblClients = new System.Windows.Forms.Label(); + this.lblAvaiblePlaces = new System.Windows.Forms.Label(); + this.lblClientsWithoutCheckout = new System.Windows.Forms.Label(); + 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); + ((System.ComponentModel.ISupportInitialize)(this.pbxRayons)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pbxCaisses)).BeginInit(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.SuspendLayout(); + // + // pbxRayons + // + this.pbxRayons.Location = new System.Drawing.Point(12, 12); + this.pbxRayons.Name = "pbxRayons"; + this.pbxRayons.Size = new System.Drawing.Size(1044, 357); + this.pbxRayons.TabIndex = 0; + this.pbxRayons.TabStop = false; + // + // pbxCaisses + // + this.pbxCaisses.Location = new System.Drawing.Point(12, 375); + this.pbxCaisses.Name = "pbxCaisses"; + this.pbxCaisses.Size = new System.Drawing.Size(838, 246); + this.pbxCaisses.TabIndex = 1; + this.pbxCaisses.TabStop = false; + // + // groupBox1 + // + 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.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(200, 125); + this.groupBox1.TabIndex = 2; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "controls"; + // + // btnAddTime + // + this.btnAddTime.Location = new System.Drawing.Point(6, 91); + this.btnAddTime.Name = "btnAddTime"; + this.btnAddTime.Size = new System.Drawing.Size(188, 29); + this.btnAddTime.TabIndex = 5; + this.btnAddTime.Text = "Passer une heure"; + this.btnAddTime.UseVisualStyleBackColor = true; + // + // btnAddClients + // + this.btnAddClients.Location = new System.Drawing.Point(6, 56); + this.btnAddClients.Name = "btnAddClients"; + this.btnAddClients.Size = new System.Drawing.Size(188, 29); + this.btnAddClients.TabIndex = 4; + this.btnAddClients.Text = "Ajouter 5 clients"; + this.btnAddClients.UseVisualStyleBackColor = true; + // + // btnStartStop + // + this.btnStartStop.Location = new System.Drawing.Point(6, 21); + this.btnStartStop.Name = "btnStartStop"; + this.btnStartStop.Size = new System.Drawing.Size(188, 29); + this.btnStartStop.TabIndex = 3; + this.btnStartStop.Text = "Start"; + this.btnStartStop.UseVisualStyleBackColor = true; + this.btnStartStop.Click += new System.EventHandler(this.btnStartStop_Click); + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.lblTime); + this.groupBox2.Controls.Add(this.lblAvgWaitingTime); + this.groupBox2.Controls.Add(this.lblClients); + 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.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(200, 120); + this.groupBox2.TabIndex = 6; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "infos"; + // + // lblTime + // + this.lblTime.AutoSize = true; + this.lblTime.Location = new System.Drawing.Point(6, 98); + this.lblTime.Name = "lblTime"; + this.lblTime.Size = new System.Drawing.Size(139, 16); + this.lblTime.TabIndex = 5; + this.lblTime.Text = "Time of the day : 13:00"; + // + // lblAvgWaitingTime + // + this.lblAvgWaitingTime.AutoSize = true; + this.lblAvgWaitingTime.Location = new System.Drawing.Point(6, 82); + this.lblAvgWaitingTime.Name = "lblAvgWaitingTime"; + this.lblAvgWaitingTime.Size = new System.Drawing.Size(117, 16); + this.lblAvgWaitingTime.TabIndex = 4; + this.lblAvgWaitingTime.Text = "average wait : 0:03"; + // + // lblClients + // + this.lblClients.AutoSize = true; + this.lblClients.Location = new System.Drawing.Point(6, 66); + this.lblClients.Name = "lblClients"; + this.lblClients.Size = new System.Drawing.Size(67, 16); + this.lblClients.TabIndex = 3; + this.lblClients.Text = "Clients: 50"; + // + // lblAvaiblePlaces + // + this.lblAvaiblePlaces.AutoSize = true; + this.lblAvaiblePlaces.Location = new System.Drawing.Point(6, 50); + this.lblAvaiblePlaces.Name = "lblAvaiblePlaces"; + this.lblAvaiblePlaces.Size = new System.Drawing.Size(113, 16); + this.lblAvaiblePlaces.TabIndex = 2; + this.lblAvaiblePlaces.Text = "Avaible places : 8"; + // + // lblClientsWithoutCheckout + // + this.lblClientsWithoutCheckout.AutoSize = true; + this.lblClientsWithoutCheckout.Location = new System.Drawing.Point(6, 34); + this.lblClientsWithoutCheckout.Name = "lblClientsWithoutCheckout"; + this.lblClientsWithoutCheckout.Size = new System.Drawing.Size(160, 16); + this.lblClientsWithoutCheckout.TabIndex = 1; + this.lblClientsWithoutCheckout.Text = "Clients without checkout: 0"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 18); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(143, 16); + this.label1.TabIndex = 0; + this.label1.Text = "checkout opening : 10s"; + // + // tmrRefresh + // + this.tmrRefresh.Interval = 1000; + this.tmrRefresh.Tick += new System.EventHandler(this.tmrRefresh_Tick); + // + // tmrDraw + // + this.tmrDraw.Interval = 17; + this.tmrDraw.Tick += new System.EventHandler(this.tmrDraw_Tick); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1062, 630); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.pbxCaisses); + this.Controls.Add(this.pbxRayons); + this.Name = "Form1"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.pbxRayons)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pbxCaisses)).EndInit(); + this.groupBox1.ResumeLayout(false); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.PictureBox pbxRayons; + private System.Windows.Forms.PictureBox pbxCaisses; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Button btnAddTime; + private System.Windows.Forms.Button btnAddClients; + private System.Windows.Forms.Button btnStartStop; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Label lblTime; + private System.Windows.Forms.Label lblAvgWaitingTime; + private System.Windows.Forms.Label lblClients; + private System.Windows.Forms.Label lblAvaiblePlaces; + private System.Windows.Forms.Label lblClientsWithoutCheckout; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Timer tmrRefresh; + private System.Windows.Forms.Timer tmrDraw; + } +} + diff --git a/Caisses/Form1.cs b/Caisses/Form1.cs new file mode 100644 index 0000000..2ed2f38 --- /dev/null +++ b/Caisses/Form1.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Caisses +{ + public partial class Form1 : Form + { + GraphicalStore store; + public Form1() + { + InitializeComponent(); + DoubleBuffered = true; + store = new GraphicalStore(10,12,pbxRayons.Size,pbxCaisses.Size); + } + + private void btnStartStop_Click(object sender, EventArgs e) + { + 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 result = store.Draw(); + if (pbxRayons.Image != null) + { + pbxRayons.Image.Dispose(); + } + if (pbxCaisses.Image != null) + { + pbxCaisses.Image.Dispose(); + } + pbxRayons.Image = result[0]; + pbxCaisses.Image = result[1]; + + lblClients.Text = "Clients : " + store.Clients.Count(); + lblClientsWithoutCheckout.Text = "Clients without checkout : "+ store.GetClientsWithoutCheckout().Count(); + lblAvaiblePlaces.Text = "Avaible places = " + store.GetAmountOfPlacesLeft(); + lblAvgWaitingTime.Text = "AverageWaitingTime = " + store.GetAverageWaitingTime(); + lblTime.Text = "Time of the day : "+store.TimeOfTheDayInHours + ":"+store.TimeOfTheDayInMinuts % 60; + } + } +} diff --git a/Caisses/Form1.resx b/Caisses/Form1.resx new file mode 100644 index 0000000..f327b51 --- /dev/null +++ b/Caisses/Form1.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 148, 17 + + \ No newline at end of file diff --git a/Caisses/GraphicalCheckout.cs b/Caisses/GraphicalCheckout.cs new file mode 100644 index 0000000..06027b3 --- /dev/null +++ b/Caisses/GraphicalCheckout.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Caisses +{ + internal class GraphicalCheckout : Checkout + { + private Point _position; + private Color _color; + private Size _size; + private Rectangle _area; + private Random Random; + + public Point Position { get => _position; set => _position = value; } + public Color Color { get => _color; set => _color = value; } + public Size Size { get => _size; set => _size = value; } + public Rectangle Area { get => _area; set => _area = value; } + public GraphicalCheckout(Point position,Rectangle area,int checkoutNumber) + { + Random = new Random(); + Position = position; + Color = Color.FromArgb(Random.Next(0, 255), Random.Next(0, 255), Random.Next(0, 255)); + Size = new Size(area.Width / checkoutNumber + 1,area.Height-area.Height/10); + } + public void Draw(Bitmap checkoutAreaImage) + { + Graphics g = Graphics.FromImage(checkoutAreaImage); + //g.DrawRectangle(new Pen(Color.FromArgb(Random.Next(0,255),Random.Next(0,255),Random.Next(0,255))),new Rectangle(Position,Size)); + g.DrawRectangle(new Pen(Color.Black),new Rectangle(Position,Size)); + if (Open) + { + g.FillRectangle(new SolidBrush(Color.Green),new Rectangle(Position, Size)); + g.DrawString(Clients.Count().ToString(), new Font("Arial", 16), new SolidBrush(Color.White), new PointF(Position.X, Position.Y)); + } + else + { + g.FillRectangle(new SolidBrush(Color.Red), new Rectangle(Position, Size)); + } + } + } +} diff --git a/Caisses/GraphicalClient.cs b/Caisses/GraphicalClient.cs new file mode 100644 index 0000000..4a6321d --- /dev/null +++ b/Caisses/GraphicalClient.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Caisses +{ + public class GraphicalClient : Client + { + const int MAX_CLIENT_SPEED = 5; + const int MIN_CLIENT_SPEED = -5; + + private Point _speed; + private Point _position; + private Color _color; + private Size _size; + private Rectangle _area; + + public Point Speed { get => _speed; set => _speed = value; } + public Point Position { get => _position; set => _position = value; } + public Color Color { get => _color; set => _color = value; } + public Size Size { get => _size; set => _size = value; } + public Rectangle Area { get => _area; set => _area = value; } + + public GraphicalClient(Point Entrance,Random random):base(random) + { + Random = random; + Position = Entrance; + Position = new Point(Random.Next(0, 100), Random.Next(0, 100)); + Speed = new Point(Random.Next(MIN_CLIENT_SPEED, MAX_CLIENT_SPEED), Random.Next(MIN_CLIENT_SPEED, MAX_CLIENT_SPEED)); + Color = Color.FromArgb(ShoppingTime * 2, 0, 0); + int clientWidth = Random.Next(20, 30); + Size = new Size(clientWidth, clientWidth); + } + public void Update(Size area) + { + //base.Tick(); + Position = checkBounds(Position,area); + Color = Color.FromArgb(ShoppingTime * 2, 0, 0); + } + public void Draw(Bitmap storeImage) + { + Update(storeImage.Size); + Graphics g = Graphics.FromImage(storeImage); + switch (State) + { + case ClientState.Shopping: + g.FillEllipse(new SolidBrush(Color), new Rectangle(Position, Size)); + 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 Rectangle(Position, Size)); + g.DrawString(WaitingTime.ToString(), new Font("Arial", 16), new SolidBrush(Color.White), new PointF(Position.X, Position.Y)); + break; + case ClientState.Inline: + g.FillEllipse(new SolidBrush(Color.Violet), new Rectangle(Position, Size)); + break; + case ClientState.Checkout: + g.FillEllipse(new SolidBrush(Color.Green), new Rectangle(Position, Size)); + g.DrawString(CheckoutTime.ToString(), new Font("Arial", 16), new SolidBrush(Color.Black), new PointF(Position.X, Position.Y)); + break; + default: + break; + } + } + public Point checkBounds(Point position, Size area) + { + Point newPosition = new Point(position.X,position.Y); + /* + if (position.X < 0) + { + newPosition.X = 0; + Speed = new Point(Speed.X * -1, Speed.Y); + } + if (position.X > area.Width) + { + newPosition.X = area.Width; + Speed = new Point(Speed.X * -1, Speed.Y); + } + + 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 + { + int diff = Math.Abs(position.X + Speed.X); + newPosition.X = diff; + //newPosition = new Point(0, position.Y); + Speed = new Point(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 + { + int diff = Math.Abs(position.Y + Speed.Y); + newPosition.Y = diff; + //newPosition = new Point(position.X, 0); + Speed = new Point(Speed.X,Speed.Y * -1); + //speed.Y *= -1; + } + + return newPosition; + } + } +} diff --git a/Caisses/Program.cs b/Caisses/Program.cs new file mode 100644 index 0000000..8d1c84d --- /dev/null +++ b/Caisses/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Caisses +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Caisses/Properties/AssemblyInfo.cs b/Caisses/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..df2984f --- /dev/null +++ b/Caisses/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Caisses")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Caisses")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("210d00a1-c688-4053-9c6f-8939e30b01e3")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Caisses/Properties/Resources.Designer.cs b/Caisses/Properties/Resources.Designer.cs new file mode 100644 index 0000000..98494c0 --- /dev/null +++ b/Caisses/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Caisses.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Caisses.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Caisses/Properties/Resources.resx b/Caisses/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Caisses/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Caisses/Properties/Settings.Designer.cs b/Caisses/Properties/Settings.Designer.cs new file mode 100644 index 0000000..d98f5c1 --- /dev/null +++ b/Caisses/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Caisses.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Caisses/Properties/Settings.settings b/Caisses/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Caisses/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Caisses/Store.cs b/Caisses/Store.cs new file mode 100644 index 0000000..73143fb --- /dev/null +++ b/Caisses/Store.cs @@ -0,0 +1,227 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Caisses +{ + internal class GraphicalStore + { + private List _checkouts; + private List _clients; + private int _timeOfTheDayInMinuts; + private Bitmap _shelvesCorner; + private Bitmap _checkoutCorner; + private Random rnd; + + public static readonly int[] ATTENDANCE = { 0, 0, 0, 0, 0, 0, 0, 30, 30, 40, 50, 60, 100, 80, 50, 30, 80, 100, 50, 50, 80, 0, 0, 0 }; + const int CROSSOVER_TIME = 10; + + public int TimeOfTheDayInMinuts { get => _timeOfTheDayInMinuts; set => _timeOfTheDayInMinuts = value; } + public List Clients { get => _clients; set => _clients = value; } + 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 int TimeOfTheDayInHours + { + get { return _timeOfTheDayInMinuts / 60; } + } + + public GraphicalStore(int startingHour,int checkoutNumber, Size shelvesCornerSize,Size checkoutCornerSize) + { + TimeOfTheDayInMinuts = startingHour * 60; + Clients = new List(); + Checkouts = new List(); + CheckoutCorner = new Bitmap(checkoutCornerSize.Width,checkoutCornerSize.Height); + ShelvesCorner = new Bitmap(shelvesCornerSize.Width,shelvesCornerSize.Height); + rnd = new Random(); + + FillStore(ATTENDANCE[TimeOfTheDayInHours]); + populateCheckouts(checkoutNumber); + Tick(); + } + public void populateCheckouts(int numberOfCheckouts) + { + int checkoutWidth = CheckoutCorner.Width / numberOfCheckouts + 1; + for (int i = 0; i < numberOfCheckouts; i++) + { + Point position = new Point(i * checkoutWidth + checkoutWidth / numberOfCheckouts, 0); + Checkouts.Add(new GraphicalCheckout(position, new Rectangle(new Point(0, 0), new Size(CheckoutCorner.Width, CheckoutCorner.Height)), numberOfCheckouts)); + } + } + + public void Tick() + { + TimeOfTheDayInMinuts++; + if (TimeOfTheDayInMinuts % 60 == 0) + { + //Its a new Hour so we can send the new clients + int amountOfNewCLients = ATTENDANCE[TimeOfTheDayInHours]; + FillStore(amountOfNewCLients); + } + + int cumulatedWaitingTime = 0; + int averageWaitingTime = 0; + + foreach (GraphicalClient client in Clients) + { + client.Tick(); + cumulatedWaitingTime += client.WaitingTime; + } + if (Clients.Count == 0) + { + averageWaitingTime = 0; + } + else + { + averageWaitingTime = cumulatedWaitingTime / Clients.Count; + } + foreach (GraphicalCheckout checkout in Checkouts) + { + checkout.Tick(averageWaitingTime,CROSSOVER_TIME); + } + + //Processing the checkout mechanism + int openPlacesAmount = GetAmountOfPlacesLeft(); + + List clientsToRemove = new List(); + foreach (GraphicalClient client in Clients) + { + if (client.State == Client.ClientState.Waiting) + { + if (openPlacesAmount > 0) + { + List checkoutsWithFreeSpace = GetNotFullCheckouts(); + if (checkoutsWithFreeSpace.Count > 0) + { + //Now we select a random one to put our waiting client + int index = 0; + int count = checkoutsWithFreeSpace.Count - 1; + if (count > 0) + { + index = rnd.Next(0, checkoutsWithFreeSpace.Count - 1); + } + else + { + index = 0; + } + checkoutsWithFreeSpace[index].Clients.Add(client); + //Clients.Remove(client); + clientsToRemove.Add(client); + client.State = Client.ClientState.Inline; + } + } + } + } + foreach (GraphicalClient client in clientsToRemove) + { + Clients.Remove(client); + } + + foreach (GraphicalCheckout checkout in Checkouts) + { + if (checkout.Open && checkout.Clients.Count > 0) + { + Client cClient = checkout.Clients[0]; + if (cClient.State != Client.ClientState.Checkout) + cClient.State = Client.ClientState.Checkout; + + if (cClient.CheckoutTime <= 0) + { + checkout.Clients.Remove(cClient); + //We dont load the next because he should be loaded the next time this function is loaded + } + + foreach (GraphicalClient ccClient in checkout.Clients) + { + ccClient.Tick(); + } + } + } + } + public List Draw() + { + ShelvesCorner = new Bitmap(ShelvesCorner.Width,ShelvesCorner.Height); + CheckoutCorner = new Bitmap(CheckoutCorner.Width,CheckoutCorner.Height); + foreach (GraphicalClient client in Clients) + { + client.Draw(ShelvesCorner); + } + + foreach (GraphicalCheckout checkout in Checkouts) + { + checkout.Draw(CheckoutCorner); + foreach (GraphicalClient client in checkout.Clients) + { + client.Draw(ShelvesCorner); + } + } + + return new List { ShelvesCorner, CheckoutCorner }; + } + public virtual void FillStore(int amountOfNewClients) + { + for (int i = 0; i < amountOfNewClients; i++) + { + Clients.Add(new GraphicalClient(new Point(0,0),rnd)); + } + } + public List GetClientsWithoutCheckout() + { + List result = new List(); + foreach (GraphicalClient client in Clients) + { + if (client.State == Client.ClientState.Waiting) + result.Add(client); + } + return result; + } + public List GetNotFullCheckouts() + { + List result = new List(); + foreach (GraphicalCheckout checkout in Checkouts) + { + if (checkout.Clients.Count < Checkout.MAX_CAPACITY && checkout.Open) + { + result.Add(checkout); + } + } + return result; + } + public int GetAmountOfPlacesLeft() + { + int result = 0; + foreach(GraphicalCheckout checkout in Checkouts) + { + if (checkout.Open) + { + result += Checkout.MAX_CAPACITY - checkout.Clients.Count(); + } + } + return result; + } + public int GetAverageWaitingTime() + { + int cumulatedWaitingTime = 0; + int averageWaitingTime = 0; + + foreach (GraphicalClient client in Clients) + { + cumulatedWaitingTime += client.WaitingTime; + } + if (Clients.Count == 0) + { + averageWaitingTime = 0; + } + else + { + averageWaitingTime = cumulatedWaitingTime / Clients.Count; + } + + return averageWaitingTime; + } + } +}