Ejemplo n.º 1
0
        public static Zamestnanec getById(int id)
        {
            Zamestnanec zam = null;

            try
            {
                using (SqlConnection connection = new SqlConnection(conStr))
                {
                    connection.Open();
                    string sql = "SELECT * FROM Zamestnanec WHERE idZam=@id;";
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        command.Parameters.AddWithValue("@id", id);
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                zam = new Zamestnanec(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetDateTime(4));
                            }
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            return(zam);
        }
Ejemplo n.º 2
0
        public static int delete(Zamestnanec Zamestnanec)
        {
            int ret = 0;

            try
            {
                using (SqlConnection connection = new SqlConnection(conStr))
                {
                    connection.Open();

                    string sql  = "DELETE FROM Zamestnanec Where idZam = @idZam";
                    string sql2 = "UPDATE Strelba SET Zamestnanec_idZam=null WHERE Zamestnanec_idZam=@idZam";

                    using (SqlCommand command = new SqlCommand(sql2, connection))
                    {
                        command.Parameters.AddWithValue("@idZam", Zamestnanec.Id);
                        ret = command.ExecuteNonQuery();
                    }

                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        command.Parameters.AddWithValue("@idZam", Zamestnanec.Id);
                        ret = command.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(ret);
        }
Ejemplo n.º 3
0
 public Strelba()
 {
     Id          = 0;
     Zbran       = new Zbran();
     Zamestnanec = new Zamestnanec();
     Zakaznik    = new Zakaznik();
     Prostor     = new Prostor();
 }
Ejemplo n.º 4
0
 private static void PrepareCommand(SqlCommand command, Zamestnanec Zamestnanec)
 {
     command.Parameters.AddWithValue("@idZam", Zamestnanec.Id);
     command.Parameters.AddWithValue("@Jmeno", Zamestnanec.Jmeno);
     command.Parameters.AddWithValue("@Prijmeni", Zamestnanec.Prijmeni);
     command.Parameters.AddWithValue("@email", Zamestnanec.Email);
     command.Parameters.AddWithValue("@Datum_narozeni", Zamestnanec.Datum_narozeni);
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
        public static void sXML()
        {
            XmlSerializer            xSer        = new XmlSerializer(typeof(Collection <Zamestnanec>));
            Collection <Zamestnanec> zamestnanci = Zamestnanec.SelectAll();

            using (var stream = File.OpenWrite("Zamestnanci.xml"))
            {
                xSer.Serialize(stream, zamestnanci);
            }
        }
Ejemplo n.º 7
0
        public static int update(Zamestnanec Zamestnanec)
        {
            int ret = 0;

            try
            {
                using (SqlConnection connection = new SqlConnection(conStr))
                {
                    connection.Open();
                    string sql = "UPDATE Zamestnanec SET Jmeno=@Jmeno, Prijmeni=@Prijmeni, email=@email, Datum_narozeni=@Datum_narozeni WHERE idZam=@idZam";
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        PrepareCommand(command, Zamestnanec);
                        ret = command.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(ret);
        }
Ejemplo n.º 8
0
        public static int insert(Zamestnanec Zamestnanec)
        {
            int ret = 0;

            try
            {
                using (SqlConnection connection = new SqlConnection(conStr))
                {
                    connection.Open();
                    string sql = "INSERT INTO Zamestnanec (Jmeno, Prijmeni, email, Datum_narozeni) VALUES (@Jmeno, @Prijmeni, @email, @Datum_narozeni)";
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        PrepareCommand(command, Zamestnanec);
                        ret = command.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(ret);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }