private void btnPrijava_Click(object sender, EventArgs e) { string poruka = ProvjeraUnosa.ProvjeriOblik(txtKorime.Text, txtLozinka.Text); if (poruka == null) { ProvjeraKorisnika.ProvjeriKorisnika(this, txtKorime.Text, txtLozinka.Text); } else { MessageBox.Show(poruka, "Pogreška", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSpremi_Click(object sender, EventArgs e) { string administrator = ""; if (rdbDa.Checked == true) { administrator = "Da"; } else { administrator = "Ne"; } if (string.IsNullOrEmpty(txtKorime.Text) && string.IsNullOrEmpty(txtLozinka.Text)) { MessageBox.Show("Polja su prazna!", "Pogreška", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string poruka = ProvjeraUnosa.ProvjeriOblik(txtKorime.Text, txtLozinka.Text); if (poruka != null) { MessageBox.Show(poruka, "Pogreška", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (redakZaIzmjenu == null) { if (!ProvjeraKorisnika.ProvjeriKorisnickoIme(txtKorime.Text)) { using (var db = new EntitiesSettings()) { korisnik korisnik = new korisnik { korisnicko_ime = txtKorime.Text, lozinka = txtLozinka.Text, administrator = administrator }; db.korisnik.Add(korisnik); db.SaveChanges(); } MessageBox.Show("Uspješno ste dodali korisnika.", "Uspjeh", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("Korisničko ime već postoji!", "Pogreška", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { if (ProvjeraKorisnika.ProvjeriKorisnickoIme(txtKorime.Text) && redakZaIzmjenu.korisnicko_ime != txtKorime.Text) { MessageBox.Show("Korisničko ime već postoji!", "Pogreška", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { using (var db = new EntitiesSettings()) { db.korisnik.Attach(redakZaIzmjenu); redakZaIzmjenu.korisnicko_ime = txtKorime.Text; redakZaIzmjenu.lozinka = txtLozinka.Text; redakZaIzmjenu.administrator = administrator; db.SaveChanges(); } MessageBox.Show("Uspješno ste izmijenili korisnika.", "Uspjeh", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } }