/// <summary> /// Dohvaca sve vozace /// </summary> /// /// <returns> /// List<vozac> or null /// </returns> public static List <vozac> getAllVozaci() { List <vozac> filler = new List <vozac>(); using (SqlConnection c = new SqlConnection(CONNECTION_STRING)) { c.Open(); using (SqlDataAdapter a = new SqlDataAdapter("select * from vozac", c)) { DataTable t = new DataTable(); a.Fill(t); if (t.Rows.Count > 0) { foreach (DataRow dr in t.Rows) { vozac v = new vozac { id = Convert.ToInt16(dr["id"]), broj_mobitela = Convert.ToString(dr["broj_mobitela"]), broj_vozacke = Convert.ToString(dr["broj_vozacke"]), ime = Convert.ToString(dr["ime"]), prezime = Convert.ToString(dr["prezime"]) }; filler.Add(v); } return(filler); } else { return(null); } } } }
public ActionResult DodajVozaca(vozac v) { if (ModelState.IsValid) { DatabaseHandler.insertVozac(v.ime, v.prezime, v.broj_mobitela, v.broj_vozacke); return(RedirectToAction("Index")); } return(View()); }
private void dodajButton_Click(object sender, RoutedEventArgs e) { if (!String.IsNullOrEmpty(imeTextBox.Text) || !String.IsNullOrEmpty(prezimeTextBox.Text) || !String.IsNullOrEmpty(idTextBox.Text) || !String.IsNullOrEmpty(passwordTextBox.Password)) { int id; if (Int32.TryParse(idTextBox.Text, out id)) { if (passwordTextBox.Password.Equals(passwordTextBox_Copy.Password)) { vozac v = new vozac(imeTextBox.Text, prezimeTextBox.Text, id, passwordTextBox.Password); using (FamiliaContextClass db = new FamiliaContextClass()) { db.vozac.Add(v); try { db.SaveChanges(); } catch (Exception ex) { Console.Write(ex.StackTrace); Console.WriteLine(ex.InnerException); } Page dash = new Dashboard(service); NavigationService.Navigate(dash); } } else { MessageBox.Show("Unijete lozinke se ne poklapaju!"); passwordTextBox.Clear(); passwordTextBox_Copy.Clear(); } } else { MessageBox.Show("Nekorektan tip identifikacijske oznake vozača!"); idTextBox.Clear(); } } else { MessageBox.Show("Unesite sve potrebne parametre!"); } }
/// <summary> /// Dohvaca vozac /// </summary> /// <param name="ID">Vozac ID</param> /// /// <returns> /// vozac or null /// </returns> public static vozac getVozac(int ID) { if (!Validators.validID(ID)) { return(null); } using (SqlConnection c = new SqlConnection(CONNECTION_STRING)) { c.Open(); using (SqlDataAdapter a = new SqlDataAdapter("select * from vozac where id=@ID", c)) { a.SelectCommand.Parameters.Add(new SqlParameter { ParameterName = "@ID", Value = ID, SqlDbType = SqlDbType.Int }); DataTable t = new DataTable(); a.Fill(t); if (t.Rows.Count > 0) { vozac v = new vozac { id = Convert.ToInt16(t.Rows[0]["id"]), broj_mobitela = Convert.ToString(t.Rows[0]["broj_mobitela"]), broj_vozacke = Convert.ToString(t.Rows[0]["broj_vozacke"]), ime = Convert.ToString(t.Rows[0]["ime"]), prezime = Convert.ToString(t.Rows[0]["prezime"]) }; return(v); } else { return(null); } } } }