/// <param name="parent">The parent form of this element</param> public FormBuy(FormViewBank parent) { this.WindowTitle = "Kaufen"; this.parentForm = parent; InitializeComponent(); // Gets the user Account acc = Usermanager.Instance.LoggedInAs; // Checks that the user is logged in if (acc == null) { return; } // Inserts all values this.labelBuy.Text = Usermanager.Instance.GetRandomProduct(); this.labelCosts.Text = (this.price = Usermanager.Instance.GetRandomPrice()).ToString() + "€"; this.labelMoney.Text = acc.Money.ToString() + "€"; this.labelMoneyAfter.Text = (acc.Money - (decimal)this.price).ToString() + "€"; // If the product is afordable bool afordable = (acc.Money - (decimal)this.price) > 0; this.labelMoneyAfter.ForeColor = afordable ? Color.White : Color.Red; this.buttonAccept.Enabled = afordable; }
/// <summary> /// Event handler for the register button click event /// </summary> private void OnButtonRegisterClicked(object sender, EventArgs e) { // Gets all informations string fn = this.textBoxFirstname.Text; string ln = this.textBoxLastname.Text; string pw1 = this.textBoxPasswordFirst.Text; string pw2 = this.textBoxPasswordSecond.Text; // Checks if any value is empty if (fn.Length == 0 || ln.Length == 0 || pw1.Length == 0 || pw2.Length == 0) { this.DisplayError("Bitte fülle alle Felder aus."); return; } // Tries to pass the pin if (!int.TryParse(pw1, out int pin)) { this.DisplayError("Bitte nutzen nur eine Nummer als Pin."); return; } // Checks if the passwords match if (!pw1.Equals(pw2)) { this.DisplayError("Die Pin-Felder stimmen nicht überein."); return; } // Tries to register the user and automatically log him in string optErr = Usermanager.Instance.RegisterAndLogIn(fn, ln, pin); // Checks if an error occured if (optErr != null) { this.DisplayError(optErr); return; } // Closes all windows for (int i = 0; i < Application.OpenForms.Count; i++) { Application.OpenForms[i].Close(); } // Creates the bank form Form bank = new FormViewBank(); // Opens the bankview this.OpenNextWindow(bank); }
public FormLoadMoney(FormViewBank parent) { this.WindowTitle = "Geld Aufladen"; this.parentForm = parent; InitializeComponent(); }