Пример #1
0
        //----------------------------------------------------------------------BUSQUEDAS------------------------------------------------------------------------------------


        //LISTAR VIAJES INTERNACICONALES
        public List <Viaje> ListarViajesInternacionales()
        {
            //conexion
            SqlConnection conect = new SqlConnection(Conexion.Cnn);

            //sp
            SqlCommand sp = new SqlCommand("ListarViajesInternacionales", conect);

            sp.CommandType = CommandType.StoredProcedure;

            //reader
            SqlDataReader reader;
            //Lista
            List <Viaje> lista = new List <Viaje>();

            try
            {
                conect.Open();
                reader = sp.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ViajeInternacional viaje = new ViajeInternacional(Convert.ToInt32(reader[0]), ((PersistenciaCompania.getInstance()).BuscarCompania(reader[1].ToString())), ((PersistenciaTerminal.getInstance()).BuscarTerminal(reader[2].ToString())), ((PersistenciaEmpleado.getInstance().BuscarEmpleado(Convert.ToInt32(reader[3])))), Convert.ToDateTime(reader[4]), Convert.ToDateTime(reader[5]), Convert.ToInt32(reader[6]), Convert.ToBoolean(reader[7]), reader[8].ToString());
                        lista.Add(viaje);
                    }
                }
                return(lista);
            }
            catch (Exception ex) { throw ex; }

            finally { conect.Close(); }
        }
Пример #2
0
        //BUSCAR VIAJE INTERNACIONAL
        public ViajeInternacional BuscarViajeInternacional(int NViaje)
        {
            //conexion
            SqlConnection conect = new SqlConnection(Conexion.Cnn);

            //sp
            SqlCommand sp = new SqlCommand("BuscarViajeInternacional", conect);

            sp.CommandType = CommandType.StoredProcedure;

            //parametro
            sp.Parameters.Add("@NViaje", NViaje);
            //reader
            SqlDataReader reader;

            ViajeInternacional viaje = null;

            try
            {
                conect.Open();
                reader = sp.ExecuteReader();

                if (reader.HasRows)
                {
                    reader.Read();
                    viaje = new ViajeInternacional(Convert.ToInt32(reader[0]), ((PersistenciaCompania.getInstance()).BuscarCompania(reader[1].ToString())), ((PersistenciaTerminal.getInstance()).BuscarTerminal(reader[2].ToString())), ((PersistenciaEmpleado.getInstance().BuscarEmpleado(Convert.ToInt32(reader[3])))), Convert.ToDateTime(reader[4]), Convert.ToDateTime(reader[5]), Convert.ToInt32(reader[6]), Convert.ToBoolean(reader[7]), reader[8].ToString());
                }
                return(viaje);
            }
            catch (Exception ex) { throw ex; }
        }
Пример #3
0
        public List <ViajeInternacional> ListadoSinPartirInter()
        {
            int      numViaje;
            Compania nomCompania;
            Destino  destino;
            DateTime fSalida;
            DateTime fArribo;
            int      CantAsientos;
            Empleado ultEmpleado;
            bool     servAbordo;
            string   documentos;

            List <ViajeInternacional> _Lista    = new List <ViajeInternacional>();
            SqlConnection             _Conexion = new SqlConnection(Conexion.MiConexion);
            SqlCommand _Comando = new SqlCommand("ListadoSinPartirInter", _Conexion);

            _Comando.CommandType = CommandType.StoredProcedure;

            SqlDataReader _Reader;

            try
            {
                _Conexion.Open();
                _Reader = _Comando.ExecuteReader();
                while (_Reader.Read())
                {
                    numViaje     = (int)_Reader["numViaje"];
                    nomCompania  = PersistenciaCompanias.GetInstancia().BuscarCompaniaTodas(_Reader["nomCompania"].ToString());
                    destino      = PersistenciaDestinos.GetInstancia().BuscarDestinoTodos(_Reader["destino"].ToString());
                    fSalida      = (DateTime)_Reader["fSalida"];
                    fArribo      = (DateTime)_Reader["fArribo"];
                    CantAsientos = (int)_Reader["CantAsientos"];
                    ultEmpleado  = PersistenciaEmpleados.GetInstancia().BuscarEmpleadoTodos(_Reader["ultEmpleado"].ToString());
                    servAbordo   = (bool)_Reader["servAbordo"];
                    documentos   = (string)_Reader["documentos"];

                    ViajeInternacional VI = new ViajeInternacional(numViaje, fSalida, fArribo, CantAsientos, ultEmpleado, destino, nomCompania, servAbordo, documentos);
                    _Lista.Add(VI);
                }
                _Reader.Close();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Problemas con la base de datos:" + ex.Message);
            }
            finally
            {
                _Conexion.Close();
            }
            return(_Lista);
        }
Пример #4
0
        public ViajeInternacional BuscarViajeInter(int pNumero)
        {
            int      numViaje;
            Compania nomCompania;
            Destino  destino;
            DateTime fSalida;
            DateTime fArribo;
            int      CantAsientos;
            Empleado ultEmpleado;
            bool     servAbordo;
            string   documentos;

            ViajeInternacional VI        = null;
            SqlConnection      oConexion = new SqlConnection(Conexion.MiConexion);
            SqlCommand         oComando  = new SqlCommand("BuscarViajeInter", oConexion);

            oComando.CommandType = CommandType.StoredProcedure;
            oComando.Parameters.AddWithValue("@numViaje", pNumero);
            SqlDataReader oReader;

            try
            {
                oConexion.Open();
                oReader = oComando.ExecuteReader();
                if (oReader.Read())
                {
                    numViaje     = (int)oReader["numViaje"];
                    nomCompania  = PersistenciaCompanias.GetInstancia().BuscarCompaniaTodas(oReader["nomCompania"].ToString());
                    destino      = PersistenciaDestinos.GetInstancia().BuscarDestinoTodos(oReader["destino"].ToString());
                    fSalida      = (DateTime)oReader["fSalida"];
                    fArribo      = (DateTime)oReader["fArribo"];
                    CantAsientos = (int)oReader["CantAsientos"];
                    ultEmpleado  = PersistenciaEmpleados.GetInstancia().BuscarEmpleadoTodos(oReader["ultEmpleado"].ToString());
                    servAbordo   = (bool)oReader["servAbordo"];
                    documentos   = (string)oReader["documentos"];

                    VI = new ViajeInternacional(numViaje, fSalida, fArribo, CantAsientos, ultEmpleado, destino, nomCompania, servAbordo, documentos);
                }
                oReader.Close();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Problemas con la base de datos:" + ex.Message);
            }
            finally
            {
                oConexion.Close();
            }
            return(VI);
        }
Пример #5
0
        //BAJA VIAJE INTERNACIONAL
        public void BajaViajeInternacional(ViajeInternacional viajeInternacional)
        {
            //conexion
            SqlConnection conect = new SqlConnection(Conexion.Cnn);

            //sp
            SqlCommand sp = new SqlCommand("BajaViajeInternacional", conect);

            sp.CommandType = CommandType.StoredProcedure;

            //parametros
            sp.Parameters.Add("@NViaje", viajeInternacional.pNumeroViaje);

            //retorno
            SqlParameter retorno = new SqlParameter("@retorno", SqlDbType.Int);

            retorno.Direction = ParameterDirection.ReturnValue;
            sp.Parameters.Add("@retorno", retorno);


            try
            {
                conect.Open();
                sp.ExecuteNonQuery();

                //retorno
                if ((int)retorno.Value == 1)
                {
                    throw new Exception("viaje internacional eliminado.");
                }
                else if ((int)retorno.Value == -2)
                {
                    throw new Exception("El viaje internacional " + viajeInternacional.pNumeroViaje + " no existe.");
                }
                else if ((int)retorno.Value == -3)
                {
                    throw new Exception("Error inesperado.");
                }
            }
            catch { throw; }

            finally { conect.Close(); }
        }
Пример #6
0
        public void EliminarViajeInternacional(ViajeInternacional VI)
        {
            SqlConnection oConexion = new SqlConnection(Conexion.MiConexion);
            SqlCommand    oComando  = new SqlCommand("EliminarInter", oConexion);

            oComando.CommandType = CommandType.StoredProcedure;

            SqlParameter numViaje = new SqlParameter("@numViaje", VI.Numero);
            SqlParameter _Retorno = new SqlParameter("@Retorno", SqlDbType.Int);

            _Retorno.Direction = ParameterDirection.ReturnValue;

            int oAfectados = -1;

            oComando.Parameters.Add(numViaje);
            oComando.Parameters.Add(_Retorno);

            try
            {
                oConexion.Open();
                oComando.ExecuteNonQuery();
                oAfectados = (int)oComando.Parameters["@Retorno"].Value;
                if (oAfectados == -1)
                {
                    throw new Exception("No existe el viaje internacional ingresado.");
                }
                if (oAfectados == -6)
                {
                    throw new Exception("Error en Sql.");
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Problemas con la base de datos:" + ex.Message);
            }
            finally
            {
                oConexion.Close();
            }
        }
Пример #7
0
        //MODIFICAR VIAJE INTERNACIONAL
        public void ModificarViajeInternacional(ViajeInternacional viajeInternacional)
        {
            //conexion
            SqlConnection conect = new SqlConnection(Conexion.Cnn);

            //sp
            SqlCommand sp = new SqlCommand("ModificarViajeInternacional", conect);

            sp.CommandType = CommandType.StoredProcedure;

            //parametros
            sp.Parameters.Add("@NViaje", viajeInternacional.pNumeroViaje);
            sp.Parameters.Add("@NCompania", viajeInternacional.pCompania.pNombre);
            sp.Parameters.Add("@Destino", viajeInternacional.pDestino.pCiudad);
            sp.Parameters.Add("@EmpleadoMOG", viajeInternacional.pEmpleado.pCedula);
            sp.Parameters.Add("@FPartida", viajeInternacional.pFPartida);
            sp.Parameters.Add("@FDestino", viajeInternacional.pFDestino);
            sp.Parameters.Add("@CantAsientos", viajeInternacional.pCantAsientos);
            sp.Parameters.Add("@ServicioABordo", viajeInternacional.pServicioAbordo);
            sp.Parameters.Add("@Documentacion", viajeInternacional.pDocumentacion);

            //retorno
            SqlParameter retorno = new SqlParameter("@retorno", SqlDbType.Int);

            retorno.Direction = ParameterDirection.ReturnValue;
            sp.Parameters.Add("@retorno", retorno);


            try
            {
                conect.Open();
                sp.ExecuteNonQuery();

                //retorno
                if ((int)retorno.Value == 1)
                {
                    throw new Exception("viaje internacional modificado.");
                }
                else if ((int)retorno.Value == -4)
                {
                    throw new Exception("El viaje internacional " + viajeInternacional.pNumeroViaje + " no existe.");
                }
                else if ((int)retorno.Value == -3)
                {
                    throw new Exception("La compania " + viajeInternacional.pCompania.pNombre + " no existe.");
                }
                else if ((int)retorno.Value == -2)
                {
                    throw new Exception("La terminal " + viajeInternacional.pDestino.pCodigo + " no existe.");
                }
                else if ((int)retorno.Value == -1)
                {
                    throw new Exception("El empleado " + viajeInternacional.pEmpleado.pCedula + " no existe.");
                }
                else if ((int)retorno.Value == -7)
                {
                    throw new Exception("Ya existe un viaje al mismo destino que parte con menos de 2 horas de diferencia.");
                }
                else if ((int)retorno.Value == -6)
                {
                    throw new Exception("Error inesperado.");
                }
            }
            catch { throw; }

            finally { conect.Close(); }
        }
Пример #8
0
 public void ParaQueSeVean(ViajeInternacional vi, ViajeNacional vn)
 {
 }
Пример #9
0
        //Validaciones
        private void txtNumero_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                epErrores.Clear();
                lblError.Text = "";

                int num = 0;
                if (!int.TryParse(txtNumero.Text.Trim(), out num))
                {
                    throw new Exception("El numero debe estar compuesto unicamente por digitos.");
                }

                Viaje v = new ServicioTerminal().BuscarViaje(num);

                if (v == null)
                {
                    EstadoAgregar();
                    lblError.Text = "No se ha encontrado un viaje con el numero " + num + ", puede agregarlo si lo desea.";
                }
                if (v is ViajeNacional)
                {
                    throw new Exception("El numero " + num + " corresponde a un viaje Nacional.");
                }

                if (v is ViajeInternacional)
                {
                    unViajeInternacional = (ViajeInternacional)v;
                    EstadoEliminarModificar();

                    txtDestino.Text           = v.Destino.Cod;
                    txtDestinoCiudad.Text     = v.Destino.Ciudad;
                    txtCompania.Text          = v.Compania.Nombre;
                    txtCapacidad.Text         = v.CantidadAsientos.ToString();
                    dtpSalida.Value           = v.FechaSalida;
                    dtpArribo.Value           = v.FechaArribo;
                    txtDocumentos.Text        = ((ViajeInternacional)v).Documentos;
                    cbxServicioABordo.Checked = ((ViajeInternacional)v).ServicioABordo;
                    lblError.Text             = "Se ha encontrado el viaje.";
                }
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                if (ex.Detail.InnerText == "")
                {
                    if (ex.Message.Length > 263)
                    {
                        lblError.Text = ex.Message.Substring(183, 80);
                    }
                    else if (ex.Message.Length > 80)
                    {
                        lblError.Text = ex.Message.Substring(ex.Message.Length - 80, 80);
                    }
                    else
                    {
                        lblError.Text = ex.Message;
                    }
                }
                else
                {
                    if (ex.Detail.InnerText.Length > 80)
                    {
                        lblError.Text = ex.Detail.InnerText.Substring(0, 80);
                    }
                    else
                    {
                        lblError.Text = ex.Detail.InnerText;
                    }
                }
            }
            catch (Exception ex)
            {
                epErrores.SetError(txtNumero, ex.Message);
                if (ex.Message.Length > 80)
                {
                    lblError.Text = ex.Message.Substring(0, 80);
                }
                else
                {
                    lblError.Text = ex.Message;
                }
            }
        }
Пример #10
0
        private void btnModificar_Click(object sender, EventArgs e)
        {
            try
            {
                if (unViajeInternacional == null)
                {
                    throw new Exception("No existe el viaje ingresado.");
                }

                unViajeInternacional.FechaSalida      = dtpSalida.Value;
                unViajeInternacional.FechaArribo      = dtpArribo.Value;
                unViajeInternacional.CantidadAsientos = Convert.ToInt32(txtCapacidad.Text);

                //Creo variable por si la modificacion falla y quiero eliminar el viaje luego.
                ViajeInternacional unVI = new ViajeInternacional();
                unVI.CantidadAsientos = unViajeInternacional.CantidadAsientos;
                unVI.Compania         = unViajeInternacional.Compania;
                unVI.Destino          = unViajeInternacional.Destino;
                unVI.Documentos       = unViajeInternacional.Documentos;
                unVI.FechaArribo      = unViajeInternacional.FechaArribo;
                unVI.FechaSalida      = unViajeInternacional.FechaSalida;
                unVI.Numero           = unViajeInternacional.Numero;
                unVI.ServicioABordo   = unViajeInternacional.ServicioABordo;
                unVI.Usuario          = unViajeInternacional.Usuario;

                //**********************************************************
                unVI.Destino = new ServicioTerminal().BuscarDestino(txtDestino.Text);
                if (unVI.Destino == null)
                {
                    throw new Exception("No existe el destino ingresado");
                }

                unVI.Compania = new ServicioTerminal().BuscarCompaniaActiva(txtCompania.Text);
                if (unVI.Compania == null)
                {
                    throw new Exception("No existe la compania ingresada");
                }
                //**********************************************************

                unVI.ServicioABordo = cbxServicioABordo.Checked;
                unVI.Documentos     = txtDocumentos.Text;
                unVI.Usuario        = usuLogueado;
                new ServicioTerminal().ModificarViaje(unVI);
                Limpiar();
                lblError.Text = "Viaje Internacional " + unVI.Numero + " modificado correctamente.";
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                if (ex.Detail.InnerText == "")
                {
                    if (ex.Message.Length > 263)
                    {
                        lblError.Text = ex.Message.Substring(183, 80);
                    }
                    else if (ex.Message.Length > 80)
                    {
                        lblError.Text = ex.Message.Substring(ex.Message.Length - 80, 80);
                    }
                    else
                    {
                        lblError.Text = ex.Message;
                    }
                }
                else
                {
                    if (ex.Detail.InnerText.Length > 80)
                    {
                        lblError.Text = ex.Detail.InnerText.Substring(0, 80);
                    }
                    else
                    {
                        lblError.Text = ex.Detail.InnerText;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Length > 80)
                {
                    lblError.Text = ex.Message.Substring(0, 80);
                }
                else
                {
                    lblError.Text = ex.Message;
                }
            }
        }
Пример #11
0
        //Botones
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            try
            {
                //*********************************************************
                Destino destino = new ServicioTerminal().BuscarDestino(txtDestino.Text);
                if (destino == null)
                {
                    throw new Exception("No existe el destino ingresado");
                }

                Compania compania = new ServicioTerminal().BuscarCompaniaActiva(txtCompania.Text);
                if (compania == null)
                {
                    throw new Exception("No existe la compania ingresada");
                }
                //*********************************************************


                DateTime salida = dtpSalida.Value;
                DateTime arribo = dtpArribo.Value;

                ViajeInternacional _inter = new ViajeInternacional();

                _inter.CantidadAsientos = Convert.ToInt32(txtCapacidad.Text.Trim());
                _inter.Compania         = compania;
                _inter.Destino          = destino;
                _inter.Documentos       = txtDocumentos.Text.Trim();
                _inter.FechaArribo      = arribo;
                _inter.FechaSalida      = salida;
                _inter.Numero           = Convert.ToInt32(txtNumero.Text.Trim());
                _inter.ServicioABordo   = cbxServicioABordo.Checked;
                _inter.Usuario          = usuLogueado;
                new ServicioTerminal().AgregarViaje(_inter);
                Limpiar();
                lblError.Text = "Viaje Internacional " + _inter.Numero + " agregado correctamente";
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                if (ex.Detail.InnerText == "")
                {
                    if (ex.Message.Length > 263)
                    {
                        lblError.Text = ex.Message.Substring(183, 80);
                    }
                    else if (ex.Message.Length > 80)
                    {
                        lblError.Text = ex.Message.Substring(ex.Message.Length - 80, 80);
                    }
                    else
                    {
                        lblError.Text = ex.Message;
                    }
                }
                else
                {
                    if (ex.Detail.InnerText.Length > 80)
                    {
                        lblError.Text = ex.Detail.InnerText.Substring(0, 80);
                    }
                    else
                    {
                        lblError.Text = ex.Detail.InnerText;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Length > 80)
                {
                    lblError.Text = ex.Message.Substring(0, 80);
                }
                else
                {
                    lblError.Text = ex.Message;
                }
            }
        }
Пример #12
0
        //******************************************************

        public void AgregarViajeInternacional(ViajeInternacional VI)
        {
            SqlConnection oConexion = new SqlConnection(Conexion.MiConexion);
            SqlCommand    oComando  = new SqlCommand("AgregarInter", oConexion);

            oComando.CommandType = CommandType.StoredProcedure;

            SqlParameter numViaje     = new SqlParameter("@numViaje", VI.Numero);
            SqlParameter nomCompania  = new SqlParameter("@nomCompania", VI.Compania.Nombre);
            SqlParameter destino      = new SqlParameter("@destino", VI.Destino.Cod);
            SqlParameter fSalida      = new SqlParameter("@fSalida", VI.FechaSalida);
            SqlParameter fArribo      = new SqlParameter("@fArribo", VI.FechaArribo);
            SqlParameter CantAsientos = new SqlParameter("@CantAsientos", VI.CantidadAsientos);
            SqlParameter ultEmpleado  = new SqlParameter("@ultEmpleado", VI.Usuario.Ci);
            SqlParameter servAbordo   = new SqlParameter("@servAbordo", VI.ServicioABordo);
            SqlParameter documentos   = new SqlParameter("@documentos", VI.Documentos);

            SqlParameter _Retorno = new SqlParameter("@Retorno", SqlDbType.Int);

            _Retorno.Direction = ParameterDirection.ReturnValue;

            int oAfectados = -1;

            oComando.Parameters.Add(numViaje);
            oComando.Parameters.Add(nomCompania);
            oComando.Parameters.Add(destino);
            oComando.Parameters.Add(fSalida);
            oComando.Parameters.Add(fArribo);
            oComando.Parameters.Add(CantAsientos);
            oComando.Parameters.Add(ultEmpleado);
            oComando.Parameters.Add(servAbordo);
            oComando.Parameters.Add(documentos);

            oComando.Parameters.Add(_Retorno);

            try
            {
                oConexion.Open();
                oComando.ExecuteNonQuery();
                oAfectados = (int)oComando.Parameters["@Retorno"].Value;
                if (oAfectados == -1)
                {
                    throw new Exception("El viaje internacional ya existe.");
                }
                if (oAfectados == -2)
                {
                    throw new Exception("Debe haber una diferencia de 2 horas entre llegada y salida a un mismo destino.");
                }
                if (oAfectados == -6)
                {
                    throw new Exception("Error en Sql.");
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Problemas con la base de datos:" + ex.Message);
            }
            finally
            {
                oConexion.Close();
            }
        }