Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (double.Parse(lblCena.Text) > 0)
            {
                if (File.Exists(putanjaRez))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    FileStream      fs = new FileStream(putanjaRez, FileMode.Open, FileAccess.Read);
                    listaRezervacija = bf.Deserialize(fs) as List <Rezervacija>;
                    fs.Close();
                    listaRezervacija.Add(new Rezervacija(tmpUID, kupac.UID, dateTimePicker1.Value.ToShortDateString(), dateTimePicker2.Value.ToShortDateString(), double.Parse(lblCena.Text)));
                    FileStream      fss = new FileStream(putanjaRez, FileMode.Open, FileAccess.Write);
                    BinaryFormatter bff = new BinaryFormatter();
                    bff.Serialize(fss, listaRezervacija);
                    fss.Close();
                    MessageBox.Show("Rezervacija uspesna");
                    for (int i = 0; i < listaPonuda.Count; i++)
                    {
                        if (listaPonuda[i].UID == tmpUID)
                        {
                            if (dateTimePicker1.Value >= DateTime.Parse(listaPonuda[i].DatumOd) && dateTimePicker2.Value <= DateTime.Parse(listaPonuda[i].DatumDo))
                            {
                                listaPonuda.RemoveAt(i);

                                FileStream      fs5 = new FileStream(putanjaPonude, FileMode.Open, FileAccess.Write);
                                BinaryFormatter bf5 = new BinaryFormatter();
                                bf5.Serialize(fs5, listaPonuda);
                                fs5.Close();
                            }
                        }
                    }
                    FormPrikazKorisnika frmPrikaz = new FormPrikazKorisnika(kupac);
                    frmPrikaz.Show();
                    this.Close();
                }
                else
                {
                    listaRezervacija = new List <Rezervacija>();
                    listaRezervacija.Add(new Rezervacija(tmpUID, kupac.UID, dateTimePicker1.Value.ToShortDateString(), dateTimePicker2.Value.ToShortDateString(), double.Parse(lblCena.Text)));
                    FileStream      fs2 = new FileStream(putanjaRez, FileMode.Create, FileAccess.Write);
                    BinaryFormatter bf2 = new BinaryFormatter();
                    bf2.Serialize(fs2, listaRezervacija);
                    fs2.Close();
                    MessageBox.Show("Rezervacija uspesna");
                    FormPrikazKorisnika frmPrikazKorisika = new FormPrikazKorisnika(kupac);
                    frmPrikazKorisika.Show();
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Molimo izaberite datum");
            }
        }
Exemple #2
0
        private void btnKorisnik_Click(object sender, EventArgs e)
        {
            string s = txtUsername.Text;
            string p = txtPassword.Text;

            if (s != "" && p != "" && s.Length > 3 && p.Length > 7)
            {
                foreach (char c in s)
                {
                    if (char.IsLetterOrDigit(c))
                    {
                        userFail = false;;
                    }
                    else
                    {
                        userFail = true; break;
                    }
                }
                if (userFail == false)
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    FileStream      fs = new FileStream(putanjaKupca, FileMode.Open, FileAccess.Read);
                    listaKupaca = bf.Deserialize(fs) as List <Kupac>;
                    fs.Close();

                    bool gr = false;
                    for (int i = 0; i < listaKupaca.Count; i++)
                    {
                        if (listaKupaca[i].Username.Equals(txtUsername.Text))
                        {
                            if (listaKupaca[i].Sifra.Equals(txtPassword.Text))
                            {
                                FormPrikazKorisnika fPrikazKorisnik = new FormPrikazKorisnika(listaKupaca[i]);
                                fPrikazKorisnik.Show();
                                this.Hide();
                                gr = true;
                            }
                        }
                    }

                    if (gr == false)
                    {
                        MessageBox.Show("Korisnik ne postoji");
                    }
                    // FormPrikazKorisnika fPrikzKorisnika = new FormPrikazKorisnika();
                    //fPrikzKorisnika.Show();
                    // this.Hide();
                }
                else
                {
                    MessageBox.Show("Niste uneli dobro username/password,molimo pokusajte ponovo");
                    txtUsername.Text = "";
                    txtPassword.Text = "";
                    txtUsername.Focus();
                }
            }
            else
            {
                MessageBox.Show("Niste uneli dobro username/password,molimo pokusajte ponovo");
                txtUsername.Text = "";
                txtPassword.Text = "";
                txtUsername.Focus();
            }
        }