Esempio n. 1
0
        private int consultarIdUltimoViaje()
        {
            int idUltimoViaje = 0;

            try
            {
                using (StreamReader file = new StreamReader(NOMBRE_ARCHIVO, true))   //se crea el archivo
                {
                    String line;

                    line = file.ReadLine();
                    //Continue to read until you reach end of file
                    while (line != null)
                    {
                        DTViaje _viaje = new DTViaje();
                        //write the line to console
                        Console.WriteLine(line);
                        _viaje        = viajeRegistro2Objeto(line);
                        idUltimoViaje = _viaje.idViaje;


                        //Read the next line
                        line = file.ReadLine();
                    }
                    file.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }
            return(idUltimoViaje);
        }
Esempio n. 2
0
        public string GenerarArchivoViaje(DTViaje _Viaje)
        {
            DTResultadoOperacionList <DTViaje> Resultado = new BMViaje().GenerarArchivoViaje(_Viaje);

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            serializer.MaxJsonLength = 500000000;
            return(serializer.Serialize(Resultado));
        }
Esempio n. 3
0
        private string parseViaje2String(DTViaje _barco)
        {
            StringBuilder registro = new StringBuilder();

            registro.Append(completarCampo(_barco.idViaje.ToString(), LONGITUD_ID_VIAJE));
            registro.Append(completarCampo(_barco.idBarco.ToString(), LONGITUD_ID_BARCO));
            registro.Append(completarCampo(_barco.idPuertoOrigen.ToString(), LONGITUD_ID_PUERTO_ORIGEN));
            registro.Append(completarCampo(_barco.idPuertoDestino.ToString(), LONGITUD_ID_PUERTO_DESTINO));
            registro.Append(completarCampo(_barco.cedulaCapitan.ToString(), LONGITUD_CEDULA_CAPITAN));

            return(registro.ToString());
        }
Esempio n. 4
0
        private DTViaje viajeRegistro2Objeto(string linea)
        {
            DTViaje _viaje = new DTViaje();

            _viaje.idViaje         = Convert.ToInt32(linea.Substring(0, LONGITUD_ID_VIAJE).TrimEnd());
            _viaje.idBarco         = Convert.ToInt32(linea.Substring(10, LONGITUD_ID_BARCO).TrimEnd());
            _viaje.idPuertoOrigen  = Convert.ToInt32(linea.Substring(20, LONGITUD_ID_PUERTO_ORIGEN).TrimEnd());
            _viaje.idPuertoDestino = Convert.ToInt32(linea.Substring(30, LONGITUD_ID_PUERTO_DESTINO).TrimEnd());
            _viaje.cedulaCapitan   = linea.Substring(40, LONGITUD_CEDULA_CAPITAN).TrimEnd();

            return(_viaje);
        }
Esempio n. 5
0
        public DTResultadoOperacionList <DTViaje> consultarViajes()
        {
            DTResultadoOperacionList <DTViaje> ResultList = new DTResultadoOperacionList <DTViaje>();
            List <DTViaje> ResultadoReporte = new List <DTViaje>();
            DMPuerto       _puerto          = new DMPuerto();
            DMBarco        _barco           = new DMBarco();
            DMCapitan      _capitan         = new DMCapitan();

            try
            {
                using (StreamReader file = new StreamReader(NOMBRE_ARCHIVO, true))   //se crea el archivo
                {
                    String line;
                    line = file.ReadLine();
                    //Continue to read until you reach end of file
                    while (line != null)
                    {
                        DTViaje _viaje = new DTViaje();
                        //write the line to console
                        Console.WriteLine(line);
                        _viaje = viajeRegistro2Objeto(line);
                        //_viaje.PuertoOrigen = dmPuerto.consultarPuertoPorId(_viaje.idPuertoOrigen);
                        _viaje.PuertoOrigen  = _puerto.consultarPuertoPorId(_viaje.idPuertoOrigen).nombrePuerto;
                        _viaje.PuertoDestino = _puerto.consultarPuertoPorId(_viaje.idPuertoDestino).nombrePuerto;
                        _viaje.NombreBarco   = _barco.consultarBarcoPorId(_viaje.idBarco).nombreBarco;
                        _viaje.Capitan       = _capitan.buscarCapitanPorCedula(_viaje.cedulaCapitan).nombreCapitan;
                        ResultadoReporte.Add(_viaje);
                        //Read the next line
                        line = file.ReadLine();
                    }
                    file.Close();
                    ResultList.Resultado = true;
                }
                ResultList.Datos = ResultadoReporte;
            }
            catch (Exception ex)
            {
                ResultList.Resultado = false;
                Console.WriteLine("Exception: " + ex.Message);
            }
            return(ResultList);
        }
Esempio n. 6
0
        public Boolean verificarSiBarcoZarpo(DTViaje dtViaje)
        {
            Boolean respuesta = false;

            DTViaje _viaje = new DTViaje();
            DTResultadoOperacionList <DTDlleViaje> ReViajeLista = new DTResultadoOperacionList <DTDlleViaje>();
            List <DTDlleViaje> _listDlleViaje = new List <DTDlleViaje>();

            try
            {
                using (StreamReader file = new StreamReader(NOMBRE_ARCHIVO, true))   //se crea el archivo
                {
                    String line;
                    line = file.ReadLine();
                    //Continue to read until you reach end of file
                    while (line != null)
                    {
                        _viaje = viajeRegistro2Objeto(line);
                        if (_viaje.idBarco == dtViaje.idBarco)
                        {
                            respuesta = true; //El barco ya zarpó en otro viaje

                            break;
                        }

                        //Read the next line
                        line = file.ReadLine();
                    }
                    file.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }

            return(respuesta);
        }
Esempio n. 7
0
        public DTViaje consultarViajePorId(int idViaje)
        {
            DMPuerto _puerto = new DMPuerto();
            DTViaje  _viaje  = new DTViaje();

            try
            {
                using (StreamReader file = new StreamReader(NOMBRE_ARCHIVO, true))   //se crea el archivo
                {
                    String line;
                    line = file.ReadLine();
                    //Continue to read until you reach end of file
                    while (line != null)
                    {
                        _viaje = viajeRegistro2Objeto(line);
                        if (_viaje.idViaje == idViaje)
                        {
                            _viaje.PuertoOrigen  = _puerto.consultarPuertoPorId(_viaje.idPuertoOrigen).nombrePuerto;
                            _viaje.PuertoDestino = _puerto.consultarPuertoPorId(_viaje.idPuertoDestino).nombrePuerto;
                            break;
                        }
                        else
                        {
                            _viaje = null;
                        }
                        //Read the next line
                        line = file.ReadLine();
                    }
                    file.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }

            return(_viaje);
        }
Esempio n. 8
0
        public DTResultadoOperacionList <DTViaje> generarArchivoViaje(DTViaje _viaje)
        {
            CrearDirectorio();
            DTResultadoOperacionList <DTViaje> ResultList = new DTResultadoOperacionList <DTViaje>();
            List <DTViaje> ResultadoReporte = new List <DTViaje>();

            try
            {
                ResultList.Resultado = true;
                //GENERAR HILO PARA LA CREACIÓN DEL ARCHIVO PLANO (SI ES NECESARIO).

                //if (!consultarBarcoPorNombre(_viaje.nombreBarco))
                //{
                int idUltimoViaje = consultarIdUltimoViaje();
                _viaje.idViaje = idUltimoViaje + 1;
                using (StreamWriter file = new StreamWriter(NOMBRE_ARCHIVO, true))       //se crea el archivo
                {
                    string cadena = parseViaje2String(_viaje);

                    file.WriteLine(cadena);
                    file.Close();
                }
                ResultList.Resultado = true;
                //}
                //else
                //{
                //    ResultList.Resultado = false;
                //}
            }
            catch (Exception ex)
            {
                ResultList.Resultado = false;
            }

            return(ResultList);
        }