private int consultarIdUltimoCapitan() { int idUltimoCapitan = 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) { DTCapitan _capitan = new DTCapitan(); //write the line to console Console.WriteLine(line); _capitan = capitanRegistro2Objeto(line); idUltimoCapitan = Convert.ToInt32(_capitan.idCapitan); //Read the next line line = file.ReadLine(); } file.Close(); } } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); } return(idUltimoCapitan); }
public string GenerarArchivoCapitan(DTCapitan _Capitan) { DTResultadoOperacionList <DTCapitan> Resultado = new BMCapitan().GenerarArchivoCapitan(_Capitan); JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = 500000000; return(serializer.Serialize(Resultado)); }
private DTCapitan capitanRegistro2Objeto(String linea) { DTCapitan _capitan = new DTCapitan(); _capitan.idCapitan = linea.Substring(0, LONGITUD_ID_CAPITAN).TrimEnd(); _capitan.nombreCapitan = linea.Substring(5, LONGITUD_NOMBRE_CAPITAN).TrimEnd(); _capitan.cedulaCapitan = linea.Substring(75, LONGITUD_CEDULA).TrimEnd(); return(_capitan); }
private string parseCapitan2String(DTCapitan _capitan) { StringBuilder registro = new StringBuilder(); registro.Append(completarCampo(_capitan.idCapitan, LONGITUD_ID_CAPITAN)); registro.Append(completarCampo(_capitan.nombreCapitan, LONGITUD_NOMBRE_CAPITAN)); registro.Append(completarCampo(_capitan.cedulaCapitan, LONGITUD_CEDULA)); return(registro.ToString()); }
public DTResultadoOperacionList <DTCapitan> generarArchivoCapitan(DTCapitan _capitan) { CrearDirectorio(); DTResultadoOperacionList <DTCapitan> ResultList = new DTResultadoOperacionList <DTCapitan>(); List <DTCapitan> ResultadoReporte = new List <DTCapitan>(); try { ResultList.Resultado = true; //GENERAR HILO PARA LA CREACIÓN DEL ARCHIVO PLANO (SI ES NECESARIO). if (!consultarCapitanPorCedula(_capitan.cedulaCapitan)) { int ultimoCapitan = consultarIdUltimoCapitan(); using (StreamWriter file = new StreamWriter(NOMBRE_ARCHIVO, true)) //se crea el archivo { //Averiguar el último consecutivo del archivo CAPITAN ultimoCapitan++; _capitan.idCapitan = ultimoCapitan.ToString(); string cadena = parseCapitan2String(_capitan); file.WriteLine(cadena); file.Close(); cargarUnCapitanEnArbol(_capitan); //LLeva el nuevo Capitán al Abrol } ResultList.Resultado = true; } else { ResultList.Resultado = false; } } catch (Exception ex) { ResultList.Resultado = false; } return(ResultList); }
public DTResultadoOperacionList <DTCapitan> consultarCapitanes() { DTResultadoOperacionList <DTCapitan> ResultList = new DTResultadoOperacionList <DTCapitan>(); List <DTCapitan> ResultadoReporte = new List <DTCapitan>(); 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) { DTCapitan _capitan = new DTCapitan(); //write the line to console Console.WriteLine(line); _capitan = capitanRegistro2Objeto(line); ResultadoReporte.Add(_capitan); //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); }
public Boolean consultarCapitanPorCedula(string cedula) { Boolean resultado = new Boolean(); resultado = false; 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) { DTCapitan _capitan = new DTCapitan(); //write the line to console Console.WriteLine(line); _capitan = capitanRegistro2Objeto(line); if (_capitan.cedulaCapitan == cedula) { resultado = true; //Ya existe un capitán con esa cédula en el sistema break; } //Read the next line line = file.ReadLine(); } file.Close(); } } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); } return(resultado); }
public DTCapitan buscarCapitanPorCedula(string cedula) { DTCapitan _capitan = new DTCapitan(); 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) { //write the line to console Console.WriteLine(line); _capitan = capitanRegistro2Objeto(line); if (_capitan.cedulaCapitan == cedula) { break; } else { _capitan = null; } //Read the next line line = file.ReadLine(); } file.Close(); } } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); } return(_capitan); }
public DTResultadoOperacionList <DTCapitan> GenerarArchivoCapitan(DTCapitan _Capitan) { DTResultadoOperacionList <DTCapitan> informeResultado = new DTResultadoOperacionList <DTCapitan>(); //Verificar si ya existe un capitán con esa cédula bool resultadoBusqueda = ArbolCapitan.buscarNodo(Convert.ToInt32(_Capitan.cedulaCapitan)); if (resultadoBusqueda == true) { //La cédula ya existe. Retornar valor False informeResultado.Resultado = false; } else { // //Insertar nuevo capitán en archivo // DTCapitan _dtCapitan = new DTCapitan(); informeResultado = new DMCapitan().generarArchivoCapitan(_Capitan); } return(informeResultado); }
public void cargarUnCapitanEnArbol(DTCapitan _Capitan) { ArbolCapitan.Insertar(Convert.ToInt32(_Capitan.cedulaCapitan), Convert.ToInt32(_Capitan.idCapitan)); }