Esempio n. 1
0
 public void SmazKnihu(Kniha kniha)
 {
     using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
     {
         using (SqlCommand sqlCommand = new SqlCommand("", sqlConnection))
         {
             sqlCommand.CommandText = $"delete from Knihy where IdKnihy={kniha.Id}";
             sqlConnection.Open();
             sqlCommand.ExecuteNonQuery();
             sqlConnection.Close();
         }
     }
 }
Esempio n. 2
0
 public void StornoVypujcky(Ctenar ctenar, Kniha kniha)
 {
     using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
     {
         using (SqlCommand sqlCommand = new SqlCommand("", sqlConnection))
         {
             sqlCommand.CommandText = $"delete from Vypujcky where IdCtenari={ctenar.Id} and IdKnihy={kniha.Id} and DatumVraceni is null";
             sqlConnection.Open();
             sqlCommand.ExecuteNonQuery();
             sqlConnection.Close();
         }
     }
 }
Esempio n. 3
0
 public void VratKnihu(Ctenar ctenar, Kniha kniha)
 {
     using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
     {
         using (SqlCommand sqlCommand = new SqlCommand("", sqlConnection))
         {
             sqlCommand.CommandText = $"update Vypujcky set DatumVraceni=getdate() where IdCtenari={ctenar.Id} and IdKnihy={kniha.Id} and DatumVraceni is null";
             sqlConnection.Open();
             sqlCommand.ExecuteNonQuery();
             sqlConnection.Close();
         }
     }
 }
Esempio n. 4
0
 public void VypujcKnihu(Ctenar ctenar, Kniha kniha)
 {
     using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
     {
         using (SqlCommand sqlCommand = new SqlCommand("", sqlConnection))
         {
             sqlCommand.CommandText = $"insert into Vypujcky(IdCtenari,IdKnihy,DatumVypujceni) values({ctenar.Id},{kniha.Id},getdate())";
             sqlConnection.Open();
             sqlCommand.ExecuteNonQuery();
             sqlConnection.Close();
         }
     }
 }
Esempio n. 5
0
 public void UlozKnihu(Kniha kniha)
 {
     if (kniha.Id == 0)
     {
         // není v databázi -> budeme ho vytvářet
         using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
         {
             using (SqlCommand sqlCommand = new SqlCommand("", sqlConnection))
             {
                 sqlCommand.CommandText = $"insert into Knihy(Nazev,Autor,PocetStran,Zanr) values(@Nazev,@Autor,{kniha.PocetStran},@Zanr)";
                 sqlCommand.Parameters.AddWithValue("Nazev", kniha.Nazev);
                 sqlCommand.Parameters.AddWithValue("Autor", kniha.Autor);
                 sqlCommand.Parameters.AddWithValue("Zanr", kniha.Zanr);
                 sqlConnection.Open();
                 sqlCommand.ExecuteNonQuery();
                 sqlConnection.Close();
             }
         }
     }
     else
     {
         //pouze update
         using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
         {
             using (SqlCommand sqlCommand = new SqlCommand("", sqlConnection))
             {
                 sqlCommand.CommandText = $"update Knihy set Nazev=@Nazev ,Autor=@Autor,PocetStran={kniha.PocetStran},Zanr=@Zanr where IdKnihy={kniha.Id}";
                 sqlCommand.Parameters.AddWithValue("Nazev", kniha.Nazev);
                 sqlCommand.Parameters.AddWithValue("Autor", kniha.Autor);
                 sqlCommand.Parameters.AddWithValue("Zanr", kniha.Zanr);
                 sqlConnection.Open();
                 sqlCommand.ExecuteNonQuery();
                 sqlConnection.Close();
             }
         }
     }
 }
Esempio n. 6
0
 public FrmKnihyUpravy(Kniha kniha)
 {
     InitializeComponent();
     Kniha = kniha;
 }