Esempio n. 1
0
        public Ciljevi ReadCiljevi(int _id)
        {
            Ciljevi ciljevi = new Ciljevi();

            this.Connect();
            using (MySqlCommand command = new MySqlCommand())
            {
                command.Connection  = connection;
                command.CommandText = "SELECT id_cilj, naziv " +
                                      "FROM ciljevi " +
                                      "WHERE id_cilj = @id ";
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@id", _id);
                connection.Open();
                using (MySqlDataReader sdr = command.ExecuteReader())
                {
                    if (sdr.HasRows)
                    {
                        while (sdr.Read())
                        {
                            ciljevi = new Ciljevi()
                            {
                                ID_cilj = Convert.ToInt32(sdr["id_cilj"]),
                                Naziv   = sdr["naziv"].ToString()
                            };
                        }
                    }
                }
                connection.Close();
            }
            return(ciljevi);
        }
Esempio n. 2
0
 public bool UpdateCiljevi(Ciljevi cilj)
 {
     try
     {
         this.Connect();
         using (MySqlCommand command = new MySqlCommand())
         {
             command.Connection  = connection;
             command.CommandText = "UPDATE ciljevi " +
                                   "SET " +
                                   "naziv = @naziv " +
                                   "WHERE id_cilj = @id_cilj";
             command.CommandType = CommandType.Text;
             command.Parameters.AddWithValue("@id_cilj", cilj.ID_cilj);
             command.Parameters.AddWithValue("@naziv", cilj.Naziv);
             connection.Open();
             command.ExecuteNonQuery();
         }
     }
     catch
     {
         connection.Close();
         return(false);
     }
     finally
     {
         connection.Close();
     }
     return(true);
 }
Esempio n. 3
0
        public List <Ciljevi> ReadCiljevi(string search_string)
        {
            List <Ciljevi> ciljevi = new List <Ciljevi>();

            this.Connect();
            using (MySqlCommand command = new MySqlCommand())
            {
                command.Connection  = connection;
                command.CommandText = "SELECT id_cilj, naziv " +
                                      "FROM ciljevi " +
                                      "WHERE naziv like '%" + search_string + "%' " +
                                      "ORDER BY id_cilj ASC";
                connection.Open();
                using (MySqlDataReader sdr = command.ExecuteReader())
                {
                    if (sdr.HasRows)
                    {
                        while (sdr.Read())
                        {
                            Ciljevi cilj = new Ciljevi()
                            {
                                ID_cilj = Convert.ToInt32(sdr["id_cilj"]),
                                Naziv   = sdr["naziv"].ToString()
                            };
                            ciljevi.Add(cilj);
                        }
                    }
                }
                connection.Close();
            }
            return(ciljevi);
        }
Esempio n. 4
0
 public bool CreateCiljevi(Ciljevi cilj)
 {
     try
     {
         this.Connect();
         using (MySqlCommand command = new MySqlCommand())
         {
             command.Connection  = connection;
             command.CommandText = "INSERT INTO ciljevi " +
                                   "(naziv) " +
                                   " VALUES (@naziv)";
             command.CommandType = CommandType.Text;
             command.Parameters.AddWithValue("@naziv", cilj.Naziv);
             connection.Open();
             command.ExecuteNonQuery();
         }
     }
     catch
     {
         connection.Close();
         return(false);
     }
     finally
     {
         connection.Close();
     }
     return(true);
 }