コード例 #1
0
        public Subjekti ReadSubjekti(int _id)
        {
            Subjekti subjekti = new Subjekti();

            this.Connect();
            using (MySqlCommand command = new MySqlCommand())
            {
                command.Connection  = connection;
                command.CommandText = "SELECT id_subjekt, naziv " +
                                      "FROM subjekti " +
                                      "WHERE id_subjekt = @id ";
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@id", _id);
                //command.Parameters.AddWithValue("@id_pedagog", PlaniranjeSession.Trenutni.PedagogId);
                connection.Open();
                using (MySqlDataReader sdr = command.ExecuteReader())
                {
                    if (sdr.HasRows)
                    {
                        while (sdr.Read())
                        {
                            subjekti = new Subjekti()
                            {
                                ID_subjekt = Convert.ToInt32(sdr["id_subjekt"]),
                                Naziv      = sdr["naziv"].ToString()
                            };
                        }
                    }
                }
                connection.Close();
            }
            return(subjekti);
        }
コード例 #2
0
 public bool UpdateSubjekti(Subjekti subjekti)
 {
     try
     {
         this.Connect();
         using (MySqlCommand command = new MySqlCommand())
         {
             command.Connection  = connection;
             command.CommandText = "UPDATE subjekti " +
                                   "SET " +
                                   "naziv = @naziv " +
                                   "WHERE id_subjekt = @id_subjekt";
             command.CommandType = CommandType.Text;
             command.Parameters.AddWithValue("@id_subjekt", subjekti.ID_subjekt);
             command.Parameters.AddWithValue("@naziv", subjekti.Naziv);
             connection.Open();
             command.ExecuteNonQuery();
         }
     }
     catch
     {
         connection.Close();
         return(false);
     }
     finally
     {
         connection.Close();
     }
     return(true);
 }
コード例 #3
0
        public List <Subjekti> ReadSubjekti(string search_string)
        {
            List <Subjekti> subjekti = new List <Subjekti>();

            this.Connect();
            using (MySqlCommand command = new MySqlCommand())
            {
                command.Connection  = connection;
                command.CommandText = "SELECT id_subjekt, naziv " +
                                      "FROM subjekti " +
                                      "WHERE naziv like '%" + search_string + "%' " +
                                      "ORDER BY id_subjekt ASC";
                command.Parameters.AddWithValue("@id_pedagog", PlaniranjeSession.Trenutni.PedagogId);
                connection.Open();
                using (MySqlDataReader sdr = command.ExecuteReader())
                {
                    if (sdr.HasRows)
                    {
                        while (sdr.Read())
                        {
                            Subjekti subj = new Subjekti()
                            {
                                ID_subjekt = Convert.ToInt32(sdr["id_subjekt"]),
                                Naziv      = sdr["naziv"].ToString()
                            };
                            subjekti.Add(subj);
                        }
                    }
                }
                connection.Close();
            }
            return(subjekti);
        }
コード例 #4
0
 public bool CreateSubjekti(Subjekti subjekt)
 {
     try
     {
         this.Connect();
         using (MySqlCommand command = new MySqlCommand())
         {
             command.Connection  = connection;
             command.CommandText = "INSERT INTO subjekti " +
                                   "(naziv) " +
                                   " VALUES (@naziv)";
             command.CommandType = CommandType.Text;
             command.Parameters.AddWithValue("@naziv", subjekt.Naziv);
             connection.Open();
             command.ExecuteNonQuery();
         }
     }
     catch
     {
         connection.Close();
         return(false);
     }
     finally
     {
         connection.Close();
     }
     return(true);
 }