private void btnNext_Click(object sender, EventArgs e) { while (true) { Account account = GetFromForm(); try { if (DatabaseManager.InsertItem(account)) { Account = DatabaseManager.ContainsItem(account, new[] {"Username", "Password"}); if ( DatabaseManager.InsertItem(new Person(txtFirstname.Text, txtLastname.Text) { Account = Account.ID, MainTenant = "Y" })) { DialogResult = DialogResult.OK; } else { if ( MessageBox.Show("Kon account niet aanmaken. Probeer het opnieuw", "Account aanmaken", MessageBoxButtons.RetryCancel) == DialogResult.Retry) { continue; } Close(); } } else { if ( MessageBox.Show("Kon account niet aanmaken. Probeer het opnieuw", "Account aanmaken", MessageBoxButtons.RetryCancel) == DialogResult.Retry) { continue; } Close(); } } catch (Exception ex) { MessageBox.Show("Gebruikersnaam is al in gebruik. Probeer een andere"); return; } break; } Close(); }
private Account GetFromForm() { Account account = new Account(); foreach (PropertyInfo propInfo in typeof (Account).GetProperties().Where(propInfo => propInfo != null)) { if (!propInfo.CanWrite) continue; if (propInfo.Name == "ID") { propInfo.SetValue(account, -1); continue; } foreach (Control c in Controls) { if (c.Name != $"txt{propInfo.Name}") continue; dynamic control = null; if (c is TextBox) { control = c as TextBox; } if (c is MaskedTextBox) { control = c as MaskedTextBox; } propInfo.SetValue(account, control.Text); } } return account; }
private void btnNext_Click(object sender, EventArgs e) { if (radioExisting.Checked) //Show login { frmLogin frmLogin = new frmLogin() { Location = Location, StartPosition = FormStartPosition.CenterParent }; if (frmLogin.ShowDialog(this) == DialogResult.OK) { Account = frmLogin.Account; } else { MessageBox.Show("Geen geldig account, begin opnieuw."); return; } } if (radioNew.Checked) //Show new { frmNewAccount frmAccount = new frmNewAccount() { Location = Location, StartPosition = FormStartPosition.CenterParent}; if (frmAccount.ShowDialog(this) == DialogResult.OK) { Account = frmAccount.Account; } else { MessageBox.Show("Geen geldig account, begin opnieuw."); return; } } frmDatum frmDatum = new frmDatum() { Location = Location, StartPosition = FormStartPosition.CenterParent }; if (frmDatum.ShowDialog(this) != DialogResult.OK) { MessageBox.Show("Geen geldige datum ingevoerd. Probeer het opnieuw"); return; } frmKaart frmKaart = new frmKaart() {Location = Location, StartPosition = FormStartPosition.CenterParent }; if (frmKaart.ShowDialog(this) != DialogResult.OK) { MessageBox.Show("Geen plek gekozen! Probeer het opnieuw."); return; } frmSelectMaterial frmMaterial = new frmSelectMaterial(SelectedEvenement, frmDatum.From, frmDatum.Till) { Location = Location, StartPosition = FormStartPosition.CenterParent }; if (frmMaterial.ShowDialog(this) == DialogResult.OK) { //TODO RICK FIX DEZE SHIZZLE } try { if (DatabaseManager.InsertItem(new LeasePlace() { Account = Account.ID, Arrival = frmDatum.From, Departure = frmDatum.Till, Event = SelectedEvenement.ID, Place = frmKaart.SpotID })) { MessageBox.Show("U bent aangemeld! RFID word klaar gezet", "Succes", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch { Console.WriteLine("Error insterting item"); } }