public List <OS_Plan_2> ReadOS_Plan_2() { List <OS_Plan_2> os_plan_2 = new List <OS_Plan_2>(); this.Connect(); using (MySqlCommand command = new MySqlCommand()) { command.Connection = connection; command.CommandText = "SELECT id_plan, ak_godina, naziv, opis " + "FROM os_plan_2 " + "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()) { OS_Plan_2 plan = new OS_Plan_2() { Id_plan = Convert.ToInt32(sdr["id_plan"]), Naziv = sdr["naziv"].ToString(), Ak_godina = sdr["ak_godina"].ToString(), Opis = sdr["opis"].ToString(), }; os_plan_2.Add(plan); } } } connection.Close(); } return(os_plan_2); }
public bool CreateOS_Plan_2(OS_Plan_2 os_plan_2) { try { this.Connect(); using (MySqlCommand command = new MySqlCommand()) { command.Connection = connection; command.CommandText = "INSERT INTO os_plan_2 " + "(id_pedagog, ak_godina, naziv, opis) " + " VALUES (@id_pedagog, @ak_godina, @naziv, @opis)"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@id_pedagog", PlaniranjeSession.Trenutni.PedagogId); command.Parameters.AddWithValue("@ak_godina", os_plan_2.Ak_godina); command.Parameters.AddWithValue("@naziv", os_plan_2.Naziv); command.Parameters.AddWithValue("@opis", os_plan_2.Opis); connection.Open(); command.ExecuteNonQuery(); } } catch { connection.Close(); return(false); } finally { connection.Close(); } return(true); }
public bool UpdateOS_Plan_2(OS_Plan_2 os_plan_2) { try { this.Connect(); using (MySqlCommand command = new MySqlCommand()) { command.Connection = connection; command.CommandText = "UPDATE os_plan_2 " + "SET " + "ak_godina = @ak_godina, " + "naziv = @naziv, " + "opis = @opis " + "WHERE id_plan = @id_plan " + "AND id_pedagog = @id_pedagog"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@id_plan", os_plan_2.Id_plan); command.Parameters.AddWithValue("@id_pedagog", PlaniranjeSession.Trenutni.PedagogId); command.Parameters.AddWithValue("@ak_godina", os_plan_2.Ak_godina); command.Parameters.AddWithValue("@naziv", os_plan_2.Naziv); command.Parameters.AddWithValue("@opis", os_plan_2.Opis); connection.Open(); command.ExecuteNonQuery(); } } catch { connection.Close(); return(false); } finally { connection.Close(); } return(true); }