private void PrepareCommand(SqlCommand command, Oddeleni oddeleni)
        {
            command.Parameters.Add(new SqlParameter("@id_oddeleni", SqlDbType.Int));
            command.Parameters["@id_oddeleni"].Value = oddeleni.Id_oddeleni;

            command.Parameters.Add(new SqlParameter("@nazev", SqlDbType.VarChar, oddeleni.Nazev.Length));
            command.Parameters["@nazev"].Value = oddeleni.Nazev;

            command.Parameters.Add(new SqlParameter("@zakladni_mzda", SqlDbType.Int));
            command.Parameters["@zakladni_mzda"].Value = oddeleni.Zakladni_mzda;
        }
        public int Update(Oddeleni oddeleni)
        {
            Database db = new Database();

            db.Connect();
            SqlCommand command = db.CreateCommand(SQL_UPDATE);

            PrepareCommand(command, oddeleni);
            int ret = db.ExecuteNonQuery(command);

            db.Close();
            return(ret);
        }
        private Collection <Oddeleni> Read(SqlDataReader reader)
        {
            Collection <Oddeleni> oddeleni = new Collection <Oddeleni>();

            while (reader.Read())
            {
                Oddeleni odd = new Oddeleni();
                odd.Id_oddeleni   = reader.GetInt32(0);
                odd.Nazev         = reader.GetString(1);
                odd.Zakladni_mzda = reader.GetInt32(2);

                oddeleni.Add(odd);
            }
            return(oddeleni);
        }
        public Oddeleni Select(int id_oddeleni)
        {
            Database db = new Database();

            db.Connect();
            SqlCommand command = db.CreateCommand(SQL_SELECT_ID);

            command.Parameters.Add(new SqlParameter("@id_oddeleni", SqlDbType.Int));
            command.Parameters["@id_oddeleni"].Value = id_oddeleni;
            SqlDataReader reader = db.Select(command);

            Collection <Oddeleni> oddeleni = Read(reader);
            Oddeleni odd = null;

            if (oddeleni.Count == 1)
            {
                odd = oddeleni[0];
            }
            reader.Close();
            db.Close();
            return(odd);
        }
Ejemplo n.º 5
0
 public Zamestnanec()
 {
     mId_adresa   = new Adresa();
     mId_oddeleni = new Oddeleni();
 }