diff --git a/VendingMachine/App.config b/VendingMachine/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/VendingMachine/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/VendingMachine/Automat.cs b/VendingMachine/Automat.cs new file mode 100644 index 0000000..792c2d1 --- /dev/null +++ b/VendingMachine/Automat.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VendingMachine +{ + class Automat + { + Dictionary zawartosc; + float stan; + float stanKarty; + bool isCard; + public Automat(Produkt[] a,Portfel b) + { + zawartosc = new Dictionary(); + foreach(Produkt i in a) + { + zawartosc.Add(i.getNazwa(), 10); + } + stan = 0; + stanKarty = b.getBalance(); + isCard = false; + } + public void addDictValue(string key, int value) + { + zawartosc.Add(key, value); + } + public void setDictValue(string key, int value) + { + zawartosc[key] = value; + } + public Dictionary getDict() + { + return zawartosc; + } + public void setBalance(float a) + { + stan = a; + } + public float buyProduct(Produkt i,Portfel b) + { + if(isCard == true) + { + isCard = false; + if (zawartosc[i.getNazwa()] <= 0) + { + return -2; + } + if (i.getCena() < b.getBalance()) + { + zawartosc[i.getNazwa()] = zawartosc[i.getNazwa()] - 1; + float rest = stanKarty - i.getCena(); + stanKarty = stanKarty - i.getCena(); + b.setBalance(stanKarty); + stan = 0; + return rest; + } + else + { + return -1; + } + } + else + { + if (zawartosc[i.getNazwa()] <= 0) + { + return -2; + } + if (i.getCena() < stan) + { + zawartosc[i.getNazwa()] = zawartosc[i.getNazwa()] - 1; + float rest = stan - i.getCena(); + stan = 0; + return rest; + } + else + { + return -1; + } + } + } + + public void restock() + { + try + { + foreach (KeyValuePair i in zawartosc) + { + zawartosc[i.Key] = 10; + } + } + catch (InvalidOperationException) + { + + } + } + public float getBalance() + { + return stan; + } + public void setCardBalance(float a) + { + stanKarty = a; + } + public float getCardBalance() + { + return stanKarty; + } + public bool getCard() + { + return isCard; + } + public void setCard(bool a) + { + isCard = a; + } + } +} diff --git a/VendingMachine/Form1.Designer.cs b/VendingMachine/Form1.Designer.cs new file mode 100644 index 0000000..29c9ffa --- /dev/null +++ b/VendingMachine/Form1.Designer.cs @@ -0,0 +1,473 @@ +namespace VendingMachine +{ + partial class Form1 + { + /// + /// Wymagana zmienna projektanta. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Wyczyść wszystkie używane zasoby. + /// + /// prawda, jeżeli zarządzane zasoby powinny zostać zlikwidowane; Fałsz w przeciwnym wypadku. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Kod generowany przez Projektanta formularzy systemu Windows + + /// + /// Metoda wymagana do obsługi projektanta — nie należy modyfikować + /// jej zawartości w edytorze kodu. + /// + private void InitializeComponent() + { + this.BalanceLabel = new System.Windows.Forms.Label(); + this.balanceBox = new System.Windows.Forms.TextBox(); + this.screen = new System.Windows.Forms.TextBox(); + this.fiveButton = new System.Windows.Forms.Button(); + this.twoButton = new System.Windows.Forms.Button(); + this.oneButton = new System.Windows.Forms.Button(); + this.fiftyButton = new System.Windows.Forms.Button(); + this.twentyButton = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); + this.button6 = new System.Windows.Forms.Button(); + this.button7 = new System.Windows.Forms.Button(); + this.button8 = new System.Windows.Forms.Button(); + this.button9 = new System.Windows.Forms.Button(); + this.button10 = new System.Windows.Forms.Button(); + this.button11 = new System.Windows.Forms.Button(); + this.button12 = new System.Windows.Forms.Button(); + this.button13 = new System.Windows.Forms.Button(); + this.button14 = new System.Windows.Forms.Button(); + this.button15 = new System.Windows.Forms.Button(); + this.button16 = new System.Windows.Forms.Button(); + this.button17 = new System.Windows.Forms.Button(); + this.button18 = new System.Windows.Forms.Button(); + this.button19 = new System.Windows.Forms.Button(); + this.button20 = new System.Windows.Forms.Button(); + this.button21 = new System.Windows.Forms.Button(); + this.cardButton = new System.Windows.Forms.Button(); + this.button22 = new System.Windows.Forms.Button(); + this.restBox = new System.Windows.Forms.TextBox(); + this.restTextBox = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // BalanceLabel + // + this.BalanceLabel.AutoSize = true; + this.BalanceLabel.Location = new System.Drawing.Point(351, 19); + this.BalanceLabel.Name = "BalanceLabel"; + this.BalanceLabel.Size = new System.Drawing.Size(59, 13); + this.BalanceLabel.TabIndex = 1; + this.BalanceLabel.Text = "Stan konta"; + this.BalanceLabel.Click += new System.EventHandler(this.label2_Click); + // + // balanceBox + // + this.balanceBox.Location = new System.Drawing.Point(349, 38); + this.balanceBox.Name = "balanceBox"; + this.balanceBox.ReadOnly = true; + this.balanceBox.Size = new System.Drawing.Size(63, 20); + this.balanceBox.TabIndex = 2; + this.balanceBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // screen + // + this.screen.Location = new System.Drawing.Point(12, 12); + this.screen.Name = "screen"; + this.screen.ReadOnly = true; + this.screen.Size = new System.Drawing.Size(318, 20); + this.screen.TabIndex = 4; + this.screen.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // fiveButton + // + this.fiveButton.Location = new System.Drawing.Point(340, 64); + this.fiveButton.Name = "fiveButton"; + this.fiveButton.Size = new System.Drawing.Size(35, 23); + this.fiveButton.TabIndex = 5; + this.fiveButton.Text = "5zl"; + this.fiveButton.UseVisualStyleBackColor = true; + this.fiveButton.Click += new System.EventHandler(this.fiveButton_Click); + // + // twoButton + // + this.twoButton.Location = new System.Drawing.Point(384, 64); + this.twoButton.Name = "twoButton"; + this.twoButton.Size = new System.Drawing.Size(35, 23); + this.twoButton.TabIndex = 6; + this.twoButton.Text = "2zl"; + this.twoButton.UseVisualStyleBackColor = true; + this.twoButton.Click += new System.EventHandler(this.twoButton_Click); + // + // oneButton + // + this.oneButton.Location = new System.Drawing.Point(340, 93); + this.oneButton.Name = "oneButton"; + this.oneButton.Size = new System.Drawing.Size(35, 23); + this.oneButton.TabIndex = 7; + this.oneButton.Text = "1zl"; + this.oneButton.UseVisualStyleBackColor = true; + this.oneButton.Click += new System.EventHandler(this.oneButton_Click); + // + // fiftyButton + // + this.fiftyButton.Location = new System.Drawing.Point(384, 93); + this.fiftyButton.Name = "fiftyButton"; + this.fiftyButton.Size = new System.Drawing.Size(35, 23); + this.fiftyButton.TabIndex = 8; + this.fiftyButton.Text = "50gr"; + this.fiftyButton.UseVisualStyleBackColor = true; + this.fiftyButton.Click += new System.EventHandler(this.button1_Click); + // + // twentyButton + // + this.twentyButton.Location = new System.Drawing.Point(340, 122); + this.twentyButton.Name = "twentyButton"; + this.twentyButton.Size = new System.Drawing.Size(35, 23); + this.twentyButton.TabIndex = 9; + this.twentyButton.Text = "20gr"; + this.twentyButton.UseVisualStyleBackColor = true; + this.twentyButton.Click += new System.EventHandler(this.twentyButton_Click); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(384, 122); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(35, 23); + this.button1.TabIndex = 10; + this.button1.Text = "10gr"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click_1); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(12, 42); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(75, 74); + this.button2.TabIndex = 11; + this.button2.Text = "button2"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(93, 42); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(75, 74); + this.button3.TabIndex = 12; + this.button3.Text = "button3"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(174, 42); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(75, 74); + this.button4.TabIndex = 13; + this.button4.Text = "button4"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); + // + // button5 + // + this.button5.Location = new System.Drawing.Point(255, 42); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(75, 74); + this.button5.TabIndex = 14; + this.button5.Text = "button5"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.button5_Click); + // + // button6 + // + this.button6.Location = new System.Drawing.Point(255, 122); + this.button6.Name = "button6"; + this.button6.Size = new System.Drawing.Size(75, 74); + this.button6.TabIndex = 15; + this.button6.Text = "button6"; + this.button6.UseVisualStyleBackColor = true; + this.button6.Click += new System.EventHandler(this.button6_Click); + // + // button7 + // + this.button7.Location = new System.Drawing.Point(174, 122); + this.button7.Name = "button7"; + this.button7.Size = new System.Drawing.Size(75, 74); + this.button7.TabIndex = 16; + this.button7.Text = "button7"; + this.button7.UseVisualStyleBackColor = true; + this.button7.Click += new System.EventHandler(this.button7_Click); + // + // button8 + // + this.button8.Location = new System.Drawing.Point(93, 122); + this.button8.Name = "button8"; + this.button8.Size = new System.Drawing.Size(75, 74); + this.button8.TabIndex = 17; + this.button8.Text = "button8"; + this.button8.UseVisualStyleBackColor = true; + this.button8.Click += new System.EventHandler(this.button8_Click); + // + // button9 + // + this.button9.Location = new System.Drawing.Point(12, 122); + this.button9.Name = "button9"; + this.button9.Size = new System.Drawing.Size(75, 74); + this.button9.TabIndex = 18; + this.button9.Text = "button9"; + this.button9.UseVisualStyleBackColor = true; + this.button9.Click += new System.EventHandler(this.button9_Click); + // + // button10 + // + this.button10.Location = new System.Drawing.Point(12, 202); + this.button10.Name = "button10"; + this.button10.Size = new System.Drawing.Size(75, 74); + this.button10.TabIndex = 19; + this.button10.Text = "button10"; + this.button10.UseVisualStyleBackColor = true; + this.button10.Click += new System.EventHandler(this.button10_Click); + // + // button11 + // + this.button11.Location = new System.Drawing.Point(93, 202); + this.button11.Name = "button11"; + this.button11.Size = new System.Drawing.Size(75, 74); + this.button11.TabIndex = 20; + this.button11.Text = "button11"; + this.button11.UseVisualStyleBackColor = true; + this.button11.Click += new System.EventHandler(this.button11_Click); + // + // button12 + // + this.button12.Location = new System.Drawing.Point(174, 202); + this.button12.Name = "button12"; + this.button12.Size = new System.Drawing.Size(75, 74); + this.button12.TabIndex = 21; + this.button12.Text = "button12"; + this.button12.UseVisualStyleBackColor = true; + this.button12.Click += new System.EventHandler(this.button12_Click); + // + // button13 + // + this.button13.Location = new System.Drawing.Point(255, 202); + this.button13.Name = "button13"; + this.button13.Size = new System.Drawing.Size(75, 74); + this.button13.TabIndex = 22; + this.button13.Text = "button13"; + this.button13.UseVisualStyleBackColor = true; + this.button13.Click += new System.EventHandler(this.button13_Click); + // + // button14 + // + this.button14.Location = new System.Drawing.Point(12, 282); + this.button14.Name = "button14"; + this.button14.Size = new System.Drawing.Size(75, 74); + this.button14.TabIndex = 23; + this.button14.Text = "button14"; + this.button14.UseVisualStyleBackColor = true; + this.button14.Click += new System.EventHandler(this.button14_Click); + // + // button15 + // + this.button15.Location = new System.Drawing.Point(93, 282); + this.button15.Name = "button15"; + this.button15.Size = new System.Drawing.Size(75, 74); + this.button15.TabIndex = 24; + this.button15.Text = "button15"; + this.button15.UseVisualStyleBackColor = true; + this.button15.Click += new System.EventHandler(this.button15_Click); + // + // button16 + // + this.button16.Location = new System.Drawing.Point(174, 282); + this.button16.Name = "button16"; + this.button16.Size = new System.Drawing.Size(75, 74); + this.button16.TabIndex = 25; + this.button16.Text = "button16"; + this.button16.UseVisualStyleBackColor = true; + this.button16.Click += new System.EventHandler(this.button16_Click); + // + // button17 + // + this.button17.Location = new System.Drawing.Point(255, 282); + this.button17.Name = "button17"; + this.button17.Size = new System.Drawing.Size(75, 74); + this.button17.TabIndex = 26; + this.button17.Text = "button17"; + this.button17.UseVisualStyleBackColor = true; + this.button17.Click += new System.EventHandler(this.button17_Click); + // + // button18 + // + this.button18.Location = new System.Drawing.Point(12, 362); + this.button18.Name = "button18"; + this.button18.Size = new System.Drawing.Size(75, 74); + this.button18.TabIndex = 28; + this.button18.Text = "button18"; + this.button18.UseVisualStyleBackColor = true; + this.button18.Click += new System.EventHandler(this.button18_Click); + // + // button19 + // + this.button19.Location = new System.Drawing.Point(93, 362); + this.button19.Name = "button19"; + this.button19.Size = new System.Drawing.Size(75, 74); + this.button19.TabIndex = 29; + this.button19.Text = "button19"; + this.button19.UseVisualStyleBackColor = true; + this.button19.Click += new System.EventHandler(this.button19_Click); + // + // button20 + // + this.button20.Location = new System.Drawing.Point(174, 364); + this.button20.Name = "button20"; + this.button20.Size = new System.Drawing.Size(75, 74); + this.button20.TabIndex = 30; + this.button20.Text = "button20"; + this.button20.UseVisualStyleBackColor = true; + this.button20.Click += new System.EventHandler(this.button20_Click); + // + // button21 + // + this.button21.Location = new System.Drawing.Point(255, 362); + this.button21.Name = "button21"; + this.button21.Size = new System.Drawing.Size(75, 74); + this.button21.TabIndex = 31; + this.button21.Text = "button21"; + this.button21.UseVisualStyleBackColor = true; + this.button21.Click += new System.EventHandler(this.button21_Click); + // + // cardButton + // + this.cardButton.Location = new System.Drawing.Point(344, 163); + this.cardButton.Name = "cardButton"; + this.cardButton.Size = new System.Drawing.Size(75, 45); + this.cardButton.TabIndex = 32; + this.cardButton.Text = "Karta"; + this.cardButton.UseVisualStyleBackColor = true; + this.cardButton.Click += new System.EventHandler(this.cardButton_Click); + // + // button22 + // + this.button22.Location = new System.Drawing.Point(344, 217); + this.button22.Name = "button22"; + this.button22.Size = new System.Drawing.Size(75, 45); + this.button22.TabIndex = 33; + this.button22.Text = "Uzupełnij produkty"; + this.button22.UseVisualStyleBackColor = true; + this.button22.Click += new System.EventHandler(this.button22_Click); + // + // restBox + // + this.restBox.Location = new System.Drawing.Point(349, 292); + this.restBox.Name = "restBox"; + this.restBox.ReadOnly = true; + this.restBox.Size = new System.Drawing.Size(65, 20); + this.restBox.TabIndex = 34; + // + // restTextBox + // + this.restTextBox.AutoSize = true; + this.restTextBox.Location = new System.Drawing.Point(360, 276); + this.restTextBox.Name = "restTextBox"; + this.restTextBox.Size = new System.Drawing.Size(40, 13); + this.restTextBox.TabIndex = 35; + this.restTextBox.Text = "Reszta"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(431, 450); + this.Controls.Add(this.restTextBox); + this.Controls.Add(this.restBox); + this.Controls.Add(this.button22); + this.Controls.Add(this.cardButton); + this.Controls.Add(this.button21); + this.Controls.Add(this.button20); + this.Controls.Add(this.button19); + this.Controls.Add(this.button18); + this.Controls.Add(this.button17); + this.Controls.Add(this.button16); + this.Controls.Add(this.button15); + this.Controls.Add(this.button14); + this.Controls.Add(this.button13); + this.Controls.Add(this.button12); + this.Controls.Add(this.button11); + this.Controls.Add(this.button10); + this.Controls.Add(this.button9); + this.Controls.Add(this.button8); + this.Controls.Add(this.button7); + this.Controls.Add(this.button6); + this.Controls.Add(this.button5); + this.Controls.Add(this.button4); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.twentyButton); + this.Controls.Add(this.fiftyButton); + this.Controls.Add(this.oneButton); + this.Controls.Add(this.twoButton); + this.Controls.Add(this.fiveButton); + this.Controls.Add(this.screen); + this.Controls.Add(this.balanceBox); + this.Controls.Add(this.BalanceLabel); + this.Name = "Form1"; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.Form1_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.Label BalanceLabel; + private System.Windows.Forms.TextBox balanceBox; + private System.Windows.Forms.TextBox screen; + private System.Windows.Forms.Button fiveButton; + private System.Windows.Forms.Button twoButton; + private System.Windows.Forms.Button oneButton; + private System.Windows.Forms.Button fiftyButton; + private System.Windows.Forms.Button twentyButton; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.Button button6; + private System.Windows.Forms.Button button7; + private System.Windows.Forms.Button button8; + private System.Windows.Forms.Button button9; + private System.Windows.Forms.Button button10; + private System.Windows.Forms.Button button11; + private System.Windows.Forms.Button button12; + private System.Windows.Forms.Button button13; + private System.Windows.Forms.Button button14; + private System.Windows.Forms.Button button15; + private System.Windows.Forms.Button button16; + private System.Windows.Forms.Button button17; + private System.Windows.Forms.Button button18; + private System.Windows.Forms.Button button19; + private System.Windows.Forms.Button button20; + private System.Windows.Forms.Button button21; + private System.Windows.Forms.Button cardButton; + private System.Windows.Forms.Button button22; + private System.Windows.Forms.TextBox restBox; + private System.Windows.Forms.Label restTextBox; + } +} + diff --git a/VendingMachine/Form1.cs b/VendingMachine/Form1.cs new file mode 100644 index 0000000..79e4062 --- /dev/null +++ b/VendingMachine/Form1.cs @@ -0,0 +1,477 @@ +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 VendingMachine +{ + public partial class Form1 : Form + { + Automat vendor; + Portfel wallet; + Produkt[] products = { new Produkt("Pepsi", 2.0f), new Produkt("Coca-Cola", 2.50f), new Produkt("M&Ms", 3.50f), new Produkt("Grzesiek", 1.89f), new Produkt("Prince Polo", 3.50f), + new Produkt("7 Days", 3.80f), new Produkt("Oshee", 1.50f), new Produkt("Żywiec zdrój", 3.50f), new Produkt("Tiger", 2.0f), new Produkt("WW", 2.0f), + new Produkt("Bułka z serem", 1.20f), new Produkt("Bułka z szynką", 1.7f), new Produkt("Corny", 2.30f), new Produkt("Lay's", 2.89f), new Produkt("Jeżyki", 3.20f), + new Produkt("Maxi King", 3.10f), new Produkt("Cappy", 2.70f), new Produkt("7Up", 2.10f), new Produkt("Monster", 4.0f), new Produkt("Snickers", 2.5f)}; + List