Пример #1
0
        private int encontrar_registro_fila(ArchivoDatos dat)
        {
            StreamReader reader;
            int          nFila = 0;


            reader = new StreamReader(_path2);

            while (!reader.EndOfStream)
            {
                string linea = reader.ReadLine();
                ++nFila;
                if (linea != "")
                {
                    ArchivoDatos tp = new ArchivoDatos(linea.Substring(0, 4).Replace('-', ' '),
                                                       linea.Substring(4, 25).Replace('-', ' '),
                                                       linea.Substring(29, 10).Replace('-', ' '));

                    if (dat == tp)
                    {
                        break;
                    }
                }
            }

            reader.Close();
            return(nFila);
        }
Пример #2
0
        public ArchivoDatos encontrar_registro(int fila)
        {
            ArchivoDatos dat = new ArchivoDatos("", "", "");
            StreamReader reader;

            reader = new StreamReader(_path2);
            int i = 0;

            while (!reader.EndOfStream)
            {
                string linea = reader.ReadLine();
                if (linea != "")
                {
                    ArchivoDatos tp = new ArchivoDatos(linea.Substring(0, 4).Replace('-', ' ').Trim(),
                                                       linea.Substring(4, 25).Replace('-', ' ').Trim(),
                                                       linea.Substring(29, 10).Replace('-', ' ').Trim());
                    dat = new ArchivoDatos(tp.id, tp.nombre, tp.departamento);
                }
                if (++i == fila)
                {
                    break;
                }
            }
            reader.Close();
            return(dat);
        }
Пример #3
0
        public void ActualizarArchivo(int id, ArchivoDatos datos)
        {
            var lineas = File.ReadAllLines(_path2);

            lineas[id - 1] = ValidarPrametro(datos.id, 4) + ValidarPrametro(datos.nombre, 25) + ValidarPrametro(datos.departamento, 10);
            File.WriteAllLines(_path2, lineas);
        }
Пример #4
0
        private void BsucarId(string _id)
        {
            var item = indices.Where(d => d.id_archvio.ToString() == _id).FirstOrDefault();

            if (item != null)
            {
                ArchivoDatos tp = mFich.encontrar_registro(item.indice);
                txtId.Text           = tp.id;
                txtNombre.Text       = tp.nombre;
                txtDepartamento.Text = tp.departamento;
            }
        }
Пример #5
0
        private void btn_Guardar_Click(object sender, EventArgs e)
        {
            ArchivoDatos datos = new ArchivoDatos(txtId.Text,
                                                  txtNombre.Text,
                                                  txtDepartamento.Text);

            if (editar)
            {
                var tp = indices.Where(d => d.id_archvio.ToString() == txtId.Text).FirstOrDefault();

                mFich.ActualizarArchivo(tp.indice, datos);
            }
            else
            {
                mFich.GuardarArchivo(datos);
            }
            btn_Nuevo_Click(sender, e);
            Form1_Load(sender, e);
        }
Пример #6
0
        public void GuardarArchivo(ArchivoDatos ad)
        {
            try
            {
                StreamWriter escrito = File.AppendText(_path2);
                escrito.Write(Environment.NewLine + ValidarPrametro(ad.id, 4) + ValidarPrametro(ad.nombre, 25) + ValidarPrametro(ad.departamento, 10));
                escrito.Flush();
                escrito.Close();



                StreamWriter writeIndices = File.AppendText(_path1);
                writeIndices.Write(Environment.NewLine + encontrar_registro_fila(ad) + "," + ad.departamento + "," + ad.id);
                writeIndices.Flush();
                writeIndices.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }