public List <Mjesecni_plan> ReadMjesecnePlanove() { List <Mjesecni_plan> mjesecni_planovi = new List <Mjesecni_plan>(); this.Connect(); using (MySqlCommand command = new MySqlCommand()) { command.Connection = connection; command.CommandText = "SELECT id_plan, ak_godina, naziv, opis " + "FROM mjesecni_plan " + "WHERE id_pedagog = @id_pedagog " + "ORDER BY id_plan ASC"; command.Parameters.AddWithValue("@id_pedagog", PlaniranjeSession.Trenutni.PedagogId); connection.Open(); using (MySqlDataReader sdr = command.ExecuteReader()) { if (sdr.HasRows) { while (sdr.Read()) { Mjesecni_plan plan = new Mjesecni_plan() { ID_plan = Convert.ToInt32(sdr["id_plan"]), Naziv = sdr["naziv"].ToString(), Ak_godina = sdr["ak_godina"].ToString(), Opis = sdr["opis"].ToString(), }; mjesecni_planovi.Add(plan); } } } connection.Close(); } return(mjesecni_planovi); }
public Mjesecni_plan ReadMjesecniPlanForDel(int _id) { Mjesecni_plan mjesecni_plan = new Mjesecni_plan(); this.Connect(); using (MySqlCommand command = new MySqlCommand()) { command.Connection = connection; command.CommandText = "SELECT * FROM mjesecni_plan " + "WHERE id_plan = @id_plan"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@id_plan", _id); connection.Open(); using (MySqlDataReader sdr = command.ExecuteReader()) { if (sdr.HasRows) { while (sdr.Read()) { mjesecni_plan = new Mjesecni_plan() { ID_plan = Convert.ToInt32(sdr["id_plan"]), Id_godina = Convert.ToInt32(sdr["id_godina"]), Naziv = sdr["naziv"].ToString(), Opis = sdr["opis"].ToString() }; } } } connection.Close(); } return(mjesecni_plan); }
public bool CreateMjesecniPlan(Mjesecni_plan mjesecni_plan) { try { this.Connect(); using (MySqlCommand command = new MySqlCommand()) { command.Connection = connection; command.CommandText = "INSERT INTO mjesecni_plan " + "(id_pedagog, id_godina, naziv, opis) " + " VALUES (@id_pedagog, @id_godina, @naziv, @opis)"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@id_pedagog", PlaniranjeSession.Trenutni.PedagogId); command.Parameters.AddWithValue("@id_godina", mjesecni_plan.Id_godina); command.Parameters.AddWithValue("@naziv", mjesecni_plan.Naziv); command.Parameters.AddWithValue("@opis", mjesecni_plan.Opis); connection.Open(); command.ExecuteNonQuery(); } } catch { connection.Close(); return(false); } finally { connection.Close(); } return(true); }
public Mjesecni_plan ReadMjesecniPlan(int _id) { Mjesecni_plan mjesecni_plan = new Mjesecni_plan(); this.Connect(); using (MySqlCommand command = new MySqlCommand()) { command.Connection = connection; command.CommandText = "SELECT id_plan, id_godina, naziv, opis, godisnji_plan.ak_godina as ak_godina " + "FROM mjesecni_plan " + "JOIN godisnji_plan ON mjesecni_plan.id_godina = godisnji_plan.id_god " + "WHERE id_plan = @id_plan " + "AND mjesecni_plan.id_pedagog = @id_pedagog"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@id_plan", _id); command.Parameters.AddWithValue("@id_pedagog", PlaniranjeSession.Trenutni.PedagogId); connection.Open(); using (MySqlDataReader sdr = command.ExecuteReader()) { if (sdr.HasRows) { while (sdr.Read()) { mjesecni_plan = new Mjesecni_plan() { ID_plan = Convert.ToInt32(sdr["id_plan"]), Ak_godina = sdr["ak_godina"].ToString(), Id_godina = Convert.ToInt32(sdr["id_godina"]), Naziv = sdr["naziv"].ToString(), Opis = sdr["opis"].ToString() }; } } } connection.Close(); } return(mjesecni_plan); }
public bool UpdateMjesecniPlan(Mjesecni_plan mjesecni_plan) { try { this.Connect(); using (MySqlCommand command = new MySqlCommand()) { command.Connection = connection; command.CommandText = "UPDATE mjesecni_plan " + "SET " + "id_godina = @id_godina, " + "naziv = @naziv, " + "opis = @opis " + "WHERE id_plan = @id_plan " + "AND id_pedagog = @id_pedagog"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@id_plan", mjesecni_plan.ID_plan); command.Parameters.AddWithValue("@id_pedagog", PlaniranjeSession.Trenutni.PedagogId); command.Parameters.AddWithValue("@id_godina", mjesecni_plan.Id_godina); command.Parameters.AddWithValue("@naziv", mjesecni_plan.Naziv); command.Parameters.AddWithValue("@opis", mjesecni_plan.Opis); connection.Open(); command.ExecuteNonQuery(); } } catch { connection.Close(); return(false); } finally { connection.Close(); } return(true); }