string prazniProstori(String s) { char[] k = new char[s.Length]; k = s.ToArray(); string novaRec = null; int m = 0; for (int i = k.Length - 1; i >= 0; i--) { if (m != 0) { break; } if (k[i].ToString().Equals(" ")) { continue; } else { for (int j = 0; j <= i; j++) { novaRec += k[j]; } m = 1; } } return(novaRec); }
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 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(); } }