public Strelba(int id, DateTime zacatek, DateTime konec, Zbran zbran, Zakaznik zakaznik, Prostor prostor, Zamestnanec zamestnanec) { Id = id; Prostor = prostor; Zakaznik = zakaznik; Zamestnanec = zamestnanec; Zbran = zbran; Zacatek = zacatek; Konec = konec; }
public static int delete(Zakaznik Zakaznik) { int ret = 0; try { using (SqlConnection connection = new SqlConnection(conStr)) { connection.Open(); string sql = "DELETE FROM Zakaznik Where idZak = @idZak"; string sql1 = "UPDATE Rezervace SET Zakaznik_idZak=null WHERE Zakaznik_idZak=@idZak"; string sql2 = "UPDATE Strelba SET Zakaznik_idZak=null WHERE Zakaznik_idZak=@idZak"; string sql3 = "DELETE FROM Zadost where Zakaznik_idZak=@idZak"; using (SqlCommand command = new SqlCommand(sql1, connection)) { command.Parameters.AddWithValue("@idZak", Zakaznik.Id); ret = command.ExecuteNonQuery(); } using (SqlCommand command = new SqlCommand(sql2, connection)) { command.Parameters.AddWithValue("@idZak", Zakaznik.Id); ret = command.ExecuteNonQuery(); } using (SqlCommand command = new SqlCommand(sql3, connection)) { command.Parameters.AddWithValue("@idZak", Zakaznik.Id); ret = command.ExecuteNonQuery(); } using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.AddWithValue("@idZak", Zakaznik.Id); ret = command.ExecuteNonQuery(); } } } catch (SqlException ex) { Console.WriteLine(ex.ToString()); } return(ret); }
public static int update(Zakaznik Zakaznik) { int ret = 0; try { using (SqlConnection connection = new SqlConnection(conStr)) { connection.Open(); string sql = "UPDATE Zakaznik SET Jmeno=@Jmeno, Prijmeni=@Prijmeni, email=@email, Datum_narozeni=@Datum_narozeni WHERE idZak=@idZak"; using (SqlCommand command = new SqlCommand(sql, connection)) { PrepareCommand(command, Zakaznik); ret = command.ExecuteNonQuery(); } } } catch (SqlException ex) { Console.WriteLine(ex.ToString()); } return(ret); }
public static int insert(Zakaznik Zakaznik) { int ret = 0; try { using (SqlConnection connection = new SqlConnection(conStr)) { connection.Open(); string sql = "INSERT INTO Zakaznik (Jmeno, Prijmeni, email, Datum_narozeni) VALUES (@Jmeno, @Prijmeni, @email, @Datum_narozeni)"; using (SqlCommand command = new SqlCommand(sql, connection)) { PrepareCommand(command, Zakaznik); ret = command.ExecuteNonQuery(); } } } catch (SqlException ex) { Console.WriteLine(ex.ToString()); } return(ret); }
public static Collection <Strelba> SelectAll() { Collection <Strelba> Strelba = new Collection <Strelba>(); try { using (SqlConnection connection = new SqlConnection(conStr)) { connection.Open(); string sql = "SELECT * FROM Strelba;"; using (SqlCommand command = new SqlCommand(sql, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Strelba.Add(new Strelba(reader.GetInt32(0), reader.GetDateTime(1), reader.GetDateTime(2), reader.IsDBNull(3) ? new Zbran() : Zbran.getById(reader.GetInt32(3)), reader.IsDBNull(4) ? new Zakaznik() : Zakaznik.getById(reader.GetInt32(4)), reader.IsDBNull(5) ? new Prostor() : Prostor.getById(reader.GetInt32(5)), reader.IsDBNull(6) ? new Zamestnanec() : Zamestnanec.getById(reader.GetInt32(5)))); } } } } } catch (SqlException ex) { Console.WriteLine(ex.ToString()); } return(Strelba); }
public static Strelba getById(int id) { Strelba str = null; try { using (SqlConnection connection = new SqlConnection(conStr)) { connection.Open(); string sql = "SELECT * FROM Strelba WHERE idStr=@id;"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.AddWithValue("@id", id); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { str = new Strelba(reader.GetInt32(0), reader.GetDateTime(1), reader.GetDateTime(2), reader.IsDBNull(3) ? new Zbran() : Zbran.getById(reader.GetInt32(3)), reader.IsDBNull(4) ? new Zakaznik() : Zakaznik.getById(reader.GetInt32(4)), reader.IsDBNull(5) ? new Prostor() : Prostor.getById(reader.GetInt32(5)), reader.IsDBNull(6) ? new Zamestnanec() : Zamestnanec.getById(reader.GetInt32(5))); } } } } } catch (SqlException ex) { Console.WriteLine(ex.ToString()); } return(str); }
public static Collection <Rezervace> SelectAll() { Collection <Rezervace> Rezervace = new Collection <Rezervace>(); try { using (SqlConnection connection = new SqlConnection(conStr)) { connection.Open(); string sql = "SELECT * FROM Rezervace;"; using (SqlCommand command = new SqlCommand(sql, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Rezervace.Add(new Rezervace(reader.GetInt32(0), reader.GetDateTime(1), reader.GetDateTime(2), Zbran.getById(reader.GetInt32(3)), Zakaznik.getById(reader.GetInt32(4)), Prostor.getById(reader.GetInt32(5)))); } } } } } catch (SqlException ex) { Console.WriteLine(ex.ToString()); } return(Rezervace); }
public static Rezervace getById(int id) { Rezervace rez = null; try { using (SqlConnection connection = new SqlConnection(conStr)) { connection.Open(); string sql = "SELECT * FROM Rezervace WHERE idRez=@id;"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.AddWithValue("@id", id); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { rez = new Rezervace(reader.GetInt32(0), reader.GetDateTime(1), reader.GetDateTime(2), Zbran.getById(reader.GetInt32(3)), Zakaznik.getById(reader.GetInt32(4)), Prostor.getById(reader.GetInt32(5))); } } } } } catch (SqlException ex) { Console.WriteLine(ex.ToString()); } return(rez); }