private void btnSave_Click(object sender, EventArgs e) { SqlConnection sql = new SqlConnection(k.konekcija()); SqlCommand command = new SqlCommand("Update Korisnici set Lozinka=@password Where KorisnickoIme=@username", sql); try { sql.Open(); command.Parameters.AddWithValue("@password", txtNovaSifra.Text); command.Parameters.AddWithValue("@username", txtUsername.Text); command.ExecuteNonQuery(); MessageBox.Show("Sifra je uspesno promenjena!", "Ispravan unos!", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); Login lg = new Login(); lg.Show(); this.Hide(); sql.Close(); sql.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); sql.Close(); sql.Dispose(); } }
private void btnRezPosalji_Click(object sender, EventArgs e) { SqlConnection sql = new SqlConnection(k.konekcija()); if (!label1.Text.Equals(bunifuMetroTextbox1.Text)) { SqlCommand cmd = new SqlCommand("Select count(*) as cnt from Trial where Kljuc='" + bunifuMetroTextbox1.Text + "'", sql); try { sql.Open(); if (cmd.ExecuteScalar().ToString() == "1") { SqlCommand brisanje = new SqlCommand("delete from Trial where Kljuc='" + bunifuMetroTextbox1.Text + "'", sql); brisanje.ExecuteNonQuery(); Form1 f1 = new Form1(); f1.idKorisnika(id); f1.Show(); } else { MessageBox.Show("Kod je neispravan!"); } sql.Close(); sql.Dispose(); } catch (Exception er) { MessageBox.Show(er.ToString()); sql.Close(); sql.Dispose(); } } else { SqlCommand brisanje = new SqlCommand("delete from Trial where username='******'", sql); sql.Open(); try { brisanje.ExecuteNonQuery(); Form1 f1 = new Form1(); f1.idKorisnika(id); f1.Show(); sql.Close(); sql.Dispose(); } catch (Exception er) { MessageBox.Show(er.ToString()); sql.Close(); sql.Dispose(); } } }
private void Form3_Load(object sender, EventArgs e) { Konekcija k = new Konekcija(); SqlConnection sql = new SqlConnection(k.konekcija()); SqlCommand cmd = new SqlCommand("select Naziv, Slika,Id from Hotel", sql); SqlDataReader read; try { sql.Open(); read = cmd.ExecuteReader(); while (read.Read()) { slike.Add((byte[])read[1]); naziv.Add(read[0].ToString()); id.Add(int.Parse(read[2].ToString())); } if (naziv.Count != 0) { label4.Text = naziv[0]; ms = new MemoryStream(slike[0]); pictureBox3.Image = Image.FromStream(ms); } sql.Close(); sql.Dispose(); } catch (Exception er) { MessageBox.Show(er.ToString()); sql.Close(); sql.Dispose(); } }
private void btnRegSave_Click(object sender, EventArgs e) { if (!pr_korisnickoIme() | !pr_Lozinka() | !pr_Email() | !pr_StaNajviseVolite()) { return; } else { Konekcija konekcija = new Konekcija(); SqlConnection connection = new SqlConnection(konekcija.konekcija()); SqlCommand sql = new SqlCommand("select count(*) as cnt from Korisnici where KorisnickoIme='" + txtUserReg.Text + "'", connection); connection.Open(); try { if (sql.ExecuteScalar().ToString() == "1") { MessageBox.Show("Izaberite drugo Korisnicko ime!"); connection.Close(); connection.Dispose(); } else { SqlCommand upis = new SqlCommand("insert into Korisnici(KorisnickoIme,Lozinka,Email,Pitanje) values('" + txtUserReg.Text + "', '" + txtPassReg.Text + "','" + txtEmailReg.Text + "','" + txtPitanjeReg.Text + "')", connection); upis.ExecuteNonQuery(); DateTime sada = DateTime.Now; string vreme = sada.ToString("dd-MMM-yyyy"); Random r = new Random(); SqlCommand upiss = new SqlCommand("insert into Trial(Kljuc,username,datumReg) values('" + r.Next().ToString() + "', '" + txtUserReg.Text + "','" + vreme + "')", connection); upiss.ExecuteNonQuery(); connection.Close(); connection.Dispose(); MessageBox.Show("Uspesno ste kreirali nalog"); Login l = new Login(); l.Show(); Hide(); } } catch (Exception er) { MessageBox.Show(er.ToString()); connection.Close(); connection.Dispose(); } } }
private void uLokacija_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) { Konekcija k = new Konekcija(); SqlConnection sql = new SqlConnection(k.konekcija()); SqlCommand cmd = new SqlCommand("select Naziv, Slika,Id from Hotel where Lokacija='" + uLokacija.Text + "'", sql); SqlDataReader read; try { slike.Clear(); naziv.Clear(); id.Clear(); i = 0; sql.Open(); read = cmd.ExecuteReader(); while (read.Read()) { slike.Add((byte[])read[1]); naziv.Add(read[0].ToString()); id.Add(int.Parse(read[2].ToString())); } if (naziv.Count > 0) { label4.Text = naziv[0]; ms = new MemoryStream(slike[0]); pictureBox3.Image = Image.FromStream(ms); } else { label4.Text = ""; pictureBox3.Image = null; MessageBox.Show("Nemamo hotele ovog grada"); } sql.Close(); sql.Dispose(); } catch (Exception er) { MessageBox.Show(er.ToString()); sql.Close(); sql.Dispose(); } } }
private void btnRezPosalji_Click(object sender, EventArgs e) { if (rezIme.Equals("") | rezPrezime.Equals("") | rezTelefon.Equals("") | cbSoba.Text.Equals("Izaberi Sobu")) { MessageBox.Show("Morate popuniti sva polja!"); return; } if (dtVremeOd.Value > dtVremeDo.Value) { MessageBox.Show("Niste lepo uneli vreme!"); return; } string datumOd = dtVremeOd.Value.ToString("dd-MMM-yy"); string datumDo = dtVremeDo.Value.ToString("dd-MMM-yy"); SqlConnection sql = new SqlConnection(k.konekcija()); SqlCommand cmd = new SqlCommand("insert into Rezervacija(Ime,Prezime,Telefon,ZakaziOd,ZakaziDo,BrojRezSobe,HotelID) values('" + rezIme.Text + "','" + rezPrezime.Text + "','" + rezTelefon.Text + "','" + datumOd + "','" + datumDo + "','" + cbSoba.Text + "'," + id + ")", sql); try { sql.Open(); cmd.ExecuteNonQuery(); sql.Close(); List <string> obrok = new List <string>(); if (cbDorucak.Checked == true) { obrok.Add(lblDorucak.Text); } if (cbRucak.Checked == true) { obrok.Add(lblRucak.Text); } if (cbVecera.Checked == true) { obrok.Add(lblVecera.Text); } if (obrok.Count != 0) { SqlCommand idRez = new SqlCommand("select MAX(Id) from Rezervacija", sql); SqlDataReader read; int idRezervacije = 0; try { sql.Open(); read = idRez.ExecuteReader(); if (read.Read()) { idRezervacije = int.Parse(read[0].ToString()); } sql.Close(); } catch (Exception er) { MessageBox.Show(er.ToString()); sql.Close(); sql.Dispose(); } sql.Open(); for (int i = 0; i < obrok.Count; i++) { SqlCommand hrana = new SqlCommand("insert into Hrana(Period,RezervacijaID) values('" + obrok[i] + "'," + idRezervacije + ")", sql); try { hrana.ExecuteNonQuery(); if (i == obrok.Count - 1) { MessageBox.Show("Uspesna prijava!"); sql.Close(); sql.Dispose(); this.Hide(); } } catch (Exception er) { MessageBox.Show(er.ToString()); sql.Close(); sql.Dispose(); } } } else { MessageBox.Show("Uspesna prijava!"); sql.Close(); sql.Dispose(); this.Hide(); } } catch (Exception er) { MessageBox.Show(er.ToString()); sql.Close(); sql.Dispose(); } }
private void btnSave_Click(object sender, EventArgs e) { if (txtUsername.Text == "" || txtPassword.Text == "") { MessageBox.Show("Unesite podatke u prazna polja!", "Neispravan unos!", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } try { SqlConnection sql = new SqlConnection(k.konekcija()); SqlCommand command = new SqlCommand("Select * from Korisnici where KorisnickoIme=@username and Lozinka=@password", sql); command.Parameters.AddWithValue("@username", txtUsername.Text); command.Parameters.AddWithValue("@password", txtPassword.Text); sql.Open(); SqlDataAdapter adapt = new SqlDataAdapter(command); DataSet ds = new DataSet(); adapt.Fill(ds); sql.Close(); idKorisnika = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); int count = ds.Tables[0].Rows.Count; if (count == 1) { MessageBox.Show("Uspesna prijava!", "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); SqlCommand command1 = new SqlCommand("Select count(*) as cnt from Trial where username=@username", sql); command1.Parameters.AddWithValue("@username", txtUsername.Text); sql.Open(); if (command1.ExecuteScalar().ToString() == "1") { Trail tr = new Trail(); tr.idKorisnika(idKorisnika, txtUsername.Text); tr.Show(); this.Hide(); sql.Close(); sql.Dispose(); } else { Form1 f1 = new Form1(); f1.idKorisnika(idKorisnika); f1.Show(); this.Hide(); sql.Close(); sql.Dispose(); } } else { MessageBox.Show("Prijava nije uspela!", "Neispravan unos", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSacuvaj_Click(object sender, EventArgs e) { if (unosNaziv.Equals("") || unosBRSoba.Equals("") || unosLokacija.Equals("") || slika1.Image == null) { MessageBox.Show("Morate popuniti sva polja!"); return; } MemoryStream ms = new MemoryStream(); slika1.Image.Save(ms, slika1.Image.RawFormat); byte[] duzinaSlike = ms.GetBuffer(); ms.Close(); Konekcija k = new Konekcija(); SqlConnection sql = new SqlConnection(k.konekcija()); SqlCommand cmd = new SqlCommand("insert into Hotel(Naziv,Lokacija,BrojSoba,KorisnikID,Slika) values('" + unosNaziv.Text + "','" + unosLokacija.Text + "'," + unosBRSoba.Text + ",'" + id + "',@slika)", sql); try { sql.Open(); cmd.Parameters.AddWithValue("@slika", duzinaSlike); cmd.ExecuteNonQuery(); sql.Close(); SqlCommand idHotela = new SqlCommand("select MAX(Id) from Hotel", sql); SqlDataReader read; try { sql.Open(); read = idHotela.ExecuteReader(); int poslednjiID = 0; if (read.Read()) { poslednjiID = int.Parse(read[0].ToString()); } sql.Close(); for (int i = 1; i <= int.Parse(unosBRSoba.Text); i++) { SqlCommand upisSobe = new SqlCommand("insert into Sobe(BrojSobe,HotelID) values(" + i + "," + poslednjiID + ")", sql); try { sql.Open(); upisSobe.ExecuteNonQuery(); sql.Close(); if (i == int.Parse(unosBRSoba.Text)) { MessageBox.Show("Uspesan unos!"); unosNaziv.Text = ""; unosLokacija.Text = ""; unosBRSoba.Text = ""; slika1.Image = null; sql.Close(); sql.Dispose(); } } catch (Exception er) { MessageBox.Show(er.Message); sql.Close(); sql.Dispose(); } } } catch (Exception er) { MessageBox.Show(er.Message); sql.Close(); sql.Dispose(); } } catch (Exception er) { MessageBox.Show(er.Message); sql.Close(); sql.Dispose(); } }