//--------BUSCAR PARA VIAJE--------------------------------------------------------------
        public Terminal BuscarParaViaje(string cod)
        {
            SqlConnection cnn = new SqlConnection(Conexion.CONEXION);
            SqlCommand    cmd = new SqlCommand("BuscarTerminalParaViaje", cnn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@codigo", cod);

            Terminal terminal = null;

            try
            {
                cnn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    dr.Read();
                    string        codigo      = (string)dr[0];
                    string        ciudad      = (string)dr[1];
                    string        pais        = (string)dr[2];
                    List <string> facilidades = PersistenciaFacilidadTerminal.CargarFacilidades(codigo);

                    terminal = new Terminal(codigo, ciudad, pais, facilidades);
                }
                dr.Close();
            }
            catch (Exception ex) { throw ex; }
            finally { cnn.Close(); }

            return(terminal);
        }
        //------------------ALTA------------------------------------------------------------------------------------------
        public void Agregar(Terminal t)
        {
            SqlConnection cnn = new SqlConnection(Conexion.CONEXION);
            SqlCommand    cmd = new SqlCommand("AgregarTerminal", cnn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@codigo", t._Codigo);
            cmd.Parameters.AddWithValue("@ciudad", t._Ciudad);
            cmd.Parameters.AddWithValue("@pais", t._Pais);

            SqlParameter retorno = new SqlParameter();

            retorno.Direction = ParameterDirection.ReturnValue;
            cmd.Parameters.Add(retorno);

            SqlTransaction tran = null;

            try
            {
                cnn.Open();
                tran            = cnn.BeginTransaction();
                cmd.Transaction = tran;
                cmd.ExecuteNonQuery();

                int ret = Convert.ToInt32(retorno.Value);
                if (ret == -1)
                {
                    throw new Exception("Ese codigo de terminal ya existe");
                }
                else if (ret == -2)
                {
                    throw new Exception("No se pudo agregar la terminal (error SQL)");
                }

                foreach (string fac in t._Facilidades)
                {
                    PersistenciaFacilidadTerminal.Agregar(fac, t._Codigo, tran);
                }

                //si llego aca sin romper es porque salio todo ok, entonces...
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();

                throw ex;
            }
            finally { cnn.Close(); }
        }
        //------------MODIFICACION---------------------------------------------------------
        public void Modificar(Terminal t)
        {
            SqlConnection cnn = new SqlConnection(Conexion.CONEXION);
            SqlCommand    cmd = new SqlCommand("ModificarTerminal", cnn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@codigo", t._Codigo);
            cmd.Parameters.AddWithValue("@ciudad", t._Ciudad);
            cmd.Parameters.AddWithValue("@pais", t._Pais);
            SqlParameter retorno = new SqlParameter();

            retorno.Direction = ParameterDirection.ReturnValue;
            cmd.Parameters.Add(retorno);

            SqlTransaction tran = null;

            try
            {
                cnn.Open();
                tran            = cnn.BeginTransaction();
                cmd.Transaction = tran;
                cmd.ExecuteNonQuery();

                int ret = Convert.ToInt32(retorno.Value);
                if (ret == -1)
                {
                    throw new Exception("Ese codigo de terminal no existe");
                }
                else if (ret == -2)
                {
                    throw new Exception("No se pudo eliminar la terminal (error SQL)");
                }

                PersistenciaFacilidadTerminal.Modificar(t, tran);

                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally { cnn.Close(); }
        }
        //------listar----------------------------------
        public List <Terminal> Listar()
        {
            List <Terminal> resp = null;
            SqlConnection   cnn  = new SqlConnection(Conexion.CONEXION);
            SqlCommand      cmd  = new SqlCommand("ListarTerminales", cnn);

            cmd.CommandType = CommandType.StoredProcedure;


            try
            {
                cnn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    resp = new List <Terminal>();
                    Terminal ter = null;
                    while (dr.Read())
                    {
                        string        codigo      = (string)dr[0];
                        string        ciudad      = (string)dr[1];
                        string        pais        = (string)dr[2];
                        List <string> facilidades = PersistenciaFacilidadTerminal.CargarFacilidades((string)dr[0]);

                        ter = new Terminal(codigo, ciudad, pais, facilidades);
                        resp.Add(ter);
                    }
                }
                dr.Close();
            }
            catch (Exception ex) { throw ex; }
            finally { cnn.Close(); }


            return(resp);
        }