示例#1
0
        public static bool dodajAdministratora(Administratori admin)
        {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream      fs;

            if (File.Exists("Administratori.bin"))
            {
                List <Administratori> administratori = Administratori.sviAdministratori();

                foreach (Administratori a in administratori)
                {
                    if (a.ToString().Equals(admin.ToString()))
                    {
                        return(false);
                    }
                }

                administratori.Add(admin);

                fs = File.OpenWrite("Administratori.bin");
                bf.Serialize(fs, administratori);
                fs.Close();
            }
            else
            {
                fs = File.OpenWrite("Administratori.bin");
                bf.Serialize(fs, admin);
                fs.Close();
            }
            return(true);
        }
        private void btnAdmin_Click(object sender, EventArgs e)
        {
            List <Administratori> admini  = Administratori.sviAdministratori();
            Administratori        prijava = new Administratori(txtKorisnickoIme.Text, txtLozinka.Text);

            foreach (Administratori a in admini)
            {
                if (a.Korisnicko_ime.Equals(prijava.Korisnicko_ime) && a.Password.Equals(prijava.Password))
                {
                    txtKorisnickoIme.ResetText();
                    txtLozinka.ResetText();
                    lblPoruka.ResetText();
                    cbPrikazLozinke.Checked = false;
                    MeniAdmin meni = new MeniAdmin(this, prijava);
                    meni.Show();
                    this.Hide();
                    return;
                }
            }

            lblPoruka.Text      = "Pogrešni podaci! Pokušajte ponovo!";
            lblPoruka.ForeColor = Color.Red;
        }
        private void btnDodaj_Click(object sender, EventArgs e)
        {
            if (rbStudent.Checked)
            {
                string index   = txtIndex.Text;
                string ime     = txtIme.Text;
                string prezime = txtPrezime.Text;
                string JMBG    = txtJMBG.Text;
                string korIme  = txtKorisnickoIme.Text;
                string pass    = txtPasswordStudent.Text;

                DateTime datum;
                bool     uspesno = DateTime.TryParse(dtDatumRodjenja.Text, out datum);

                bool   uspesno1 = true;
                string telefon  = txtTelefon.Text;
                foreach (char c in telefon)
                {
                    if (!Char.IsNumber(c))
                    {
                        uspesno = false;
                    }
                }

                Smer smer = (Smer)cmbSmer.SelectedItem;

                if (!index.Equals("") && !ime.Equals("") && !prezime.Equals("") && !JMBG.Equals("") && uspesno && uspesno1 && !smer.Ime_smera.Equals("") && !korIme.Equals("") && !pass.Equals(""))
                {
                    if (Studenti.dodajStudenta(new Studenti(index, ime, prezime, JMBG, datum, telefon, smer, korIme, pass)))
                    {
                        lblPoruka.Text      = "Dodali ste studenta";
                        lblPoruka.ForeColor = Color.Blue;
                        txtIme.ResetText();
                        txtPrezime.ResetText();
                        txtJMBG.ResetText();
                        txtKorisnickoIme.ResetText();
                        txtPasswordStudent.ResetText();
                        txtTelefon.ResetText();
                        txtJMBG.ResetText();
                        txtIndex.ResetText();
                        cmbSmer.ResetText();
                        dtDatumRodjenja.ResetText();
                    }
                    else
                    {
                        lblPoruka.Text      = "Student vec postoji!";
                        lblPoruka.ForeColor = Color.Red;
                    }
                }
                else
                {
                    lblPoruka.Text      = "Greska, niste popunili sva polja ili ste pogresili prilikom unosa!";
                    lblPoruka.ForeColor = Color.Red;
                }
            }

            else if (rbAdmin.Checked)
            {
                if (!txtImeAdmin.Equals("") && !txtPassAdmin.Equals(""))
                {
                    Administratori admin = new Administratori(txtImeAdmin.Text, txtPassAdmin.Text);
                    if (Administratori.dodajAdministratora(admin))
                    {
                        lblPoruka.Text      = "Napravili ste novi nalog.";
                        lblPoruka.ForeColor = Color.Blue;
                        txtImeAdmin.ResetText();
                        txtPassAdmin.ResetText();
                        rbAdmin.Checked   = false;
                        gbAdmin.Visible   = false;
                        gbStudent.Visible = false;
                    }
                    else
                    {
                        lblPoruka.Text      = "Greska pri dodavanju!";
                        lblPoruka.ForeColor = Color.Red;
                    }
                }
                else
                {
                    lblPoruka.Text      = "Greska, niste uneli sve podatke!";
                    lblPoruka.ForeColor = Color.Red;
                }
            }
        }
 public MeniAdmin(Logovanje log, Administratori admin)
 {
     InitializeComponent();
     this.log      = log;
     lblAdmin.Text = "Trenutno je prijavljen administarator: " + admin.Korisnicko_ime;
 }