Пример #1
0
        private void btnLoginAdmin_Click(object sender, EventArgs e)
        {
            int flag = 0;

            if (Globalne.GlavniAdmin.Telefon == txtLoginTelefon.Text && Globalne.GlavniAdmin.Password == txtLoginPassword.Text)
            {
                Globalne.TrenutniAdmin = Globalne.GlavniAdmin;
                flag = 1;
                FormAdmin frm = new FormAdmin();
                frm.MdiParent = this.ParentForm;
                frm.Show();
                frm.Dock = DockStyle.Fill;
                Close();
            }
            if (flag == 0)
            {
                List <Administrator> listaAdmina = new List <Administrator>();
                listaAdmina = Globalne.procitajAdmine(Globalne.DatAdmin);
                if (!File.Exists(Globalne.DatAdmin))
                {
                    MessageBox.Show("Ne postoji fajl sa adminima!");
                }

                foreach (Administrator a in listaAdmina)
                {
                    if (a.Telefon == txtLoginTelefon.Text && a.Password == txtLoginPassword.Text)
                    {
                        Globalne.TrenutniAdmin = a;
                        flag = 1;
                        FormAdmin frm = new FormAdmin();
                        frm.MdiParent = this.ParentForm;
                        frm.Show();
                        frm.Dock = DockStyle.Fill;
                        Close();
                    }
                }
            }
            if (flag == 0 && File.Exists(Globalne.DatAdmin))
            {
                txtLoginTelefon.Text  = "";
                txtLoginPassword.Text = "";
                txtLoginTelefon.Focus();
                MessageBox.Show("Telefon i lozinka se ne poklapaju", "Login greska!");
            }
        }
Пример #2
0
        private void btnKreiraj_Click(object sender, EventArgs e)
        {
            string pogresanUnos = "";
            int    flag         = 0;

            if (txtIme.Text.Trim() == "")
            {
                pogresanUnos += "Morate uneti ime!" + Environment.NewLine;
                flag          = 1;
            }
            if (txtPrezime.Text.Trim() == "")
            {
                pogresanUnos += "Morate uneti prezime!" + Environment.NewLine;
                flag          = 1;
            }
            if (!txtJmbg.Text.All(char.IsDigit) || txtJmbg.Text.Trim() == "")
            {
                pogresanUnos += "Morate uneti ispravan JMBG!" + Environment.NewLine;
                flag          = 1;
            }
            if (!txtTelefon.Text.All(char.IsDigit) || txtTelefon.Text.Trim() == "")
            {
                pogresanUnos += "Morate uneti ispravan telefon!" + Environment.NewLine;
                flag          = 1;
            }
            if (Globalne.PraviAdmina)
            {
                List <Administrator> administrators = new List <Administrator>();
                administrators = Globalne.procitajAdmine(Globalne.DatAdmin);
                foreach (Administrator a in administrators)
                {
                    if (a.Telefon == txtTelefon.Text)
                    {
                        pogresanUnos += "Uneti telefon vec postoji!" + Environment.NewLine;
                        flag          = 1;
                    }
                }
            }
            else
            {
                List <Kupac> kupci = new List <Kupac>();
                kupci = Globalne.procitajKupce(Globalne.DatKupac);
                foreach (Kupac k in kupci)
                {
                    if (k.Telefon == txtTelefon.Text)
                    {
                        pogresanUnos += "Uneti telefon vec postoji!" + Environment.NewLine;
                        flag          = 1;
                    }
                }
            }
            if (txtLozinka.Text.Trim() == "")
            {
                pogresanUnos += "Morate uneti lozinku!" + Environment.NewLine;
                flag          = 1;
            }
            if (flag == 1)
            {
                MessageBox.Show(pogresanUnos, "Pogresan unos podataka!");
            }
            else
            {
                if (Globalne.PraviAdmina)
                {
                    Administrator noviAdmin = new Administrator(txtIme.Text, txtPrezime.Text, txtJmbg.Text, dateDatumRodjenja.Value, txtTelefon.Text, txtLozinka.Text);
                    noviAdmin.upisiAdmina(Globalne.DatAdmin);
                    MessageBox.Show(txtIme.Text + " " + txtPrezime.Text + " je uspesno dodat kao administrator!", "Uspesno dodat novi administrator");
                    Globalne.PraviAdmina = false;
                    FormAdmin frm = new FormAdmin();
                    frm.MdiParent = this.ParentForm;
                    frm.Show();
                    frm.Dock = DockStyle.Fill;
                    Close();
                }
                else
                {
                    Kupac noviKupac = new Kupac(txtIme.Text, txtPrezime.Text, txtJmbg.Text, dateDatumRodjenja.Value, txtTelefon.Text, txtLozinka.Text);
                    noviKupac.upisiKupca(Globalne.DatKupac);
                    MessageBox.Show("Nalog kupca " + txtIme.Text + " " + txtPrezime.Text + " je uspesno kreiran!", "Uspesno kreiran nalog");
                    if (Globalne.AdminPraviKupca)
                    {
                        Globalne.AdminPraviKupca = false;
                        FormAdmin frm = new FormAdmin();
                        frm.MdiParent = this.ParentForm;
                        frm.Show();
                        frm.Dock = DockStyle.Fill;
                        Close();
                    }
                    else
                    {
                        FormIzbor frm = new FormIzbor();
                        frm.MdiParent = this.ParentForm;
                        frm.Show();
                        frm.Dock = DockStyle.Fill;
                        Close();
                    }
                }
            }
        }