/InterfazGrafico/LibreriaClases/Propiedades/PEstructura.cs
http://vdata.codeplex.com · C# · 195 lines · 154 code · 13 blank · 28 comment · 7 complexity · 9682c5c3c2dfb853111347bccc634aa7 MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Xml;
- using InterfazGrafico.LibreriaClases.Clases;
- using InterfazGrafico.LibreriaConstantes;
- using InterfazGrafico.LibreriaConstantes.Elementos;
-
- namespace InterfazGrafico.LibreriaClases.Propiedades
- {
- /// <summary>
- /// Almacena las propiedades de una estructura.
- /// </summary>
- public class PEstructura : Propiedades
- {
- /// <summary>
- /// Nombre.
- /// </summary>
- public string Nombre
- {
- get
- {
- return this.getPropiedadString(CEstructura.Nombre);
- }
- set
- {
- this.setOrAddPropiedad(CEstructura.Nombre, value);
- }
- }
-
- /// <summary>
- /// Lista de nombres de los campos.
- /// </summary>
- public List<string> ListaNombresCampos
- {
- get
- {
- return this.getPropiedadListaString(CEstructura.NombreCampos);
- }
- set
- {
- this.setOrAddPropiedad(CEstructura.NombreCampos, value);
- }
- }
-
- /// <summary>
- /// Lista de las posiciones iniciales de los campos.
- /// </summary>
- public List<int> ListaPosicionInicialCampos
- {
- get
- {
- return this.getPropiedadListaInt(CEstructura.PosicionCampos);
- }
- set
- {
- this.setOrAddPropiedad(CEstructura.PosicionCampos, value);
- }
- }
-
- /// <summary>
- /// Lista de las longitudes de los campos.
- /// </summary>
- public List<int> ListaLongitudCampos
- {
- get
- {
- return this.getPropiedadListaInt(CEstructura.LongitudCampos);
- }
- set
- {
- this.setOrAddPropiedad(CEstructura.LongitudCampos, value);
- }
- }
-
- /// <summary>
- /// Constructor por defecto.
- /// </summary>
- public PEstructura()
- : base()
- {
- }
-
- /// <summary>
- /// Obtiene los parámetros a partir del fichero XML indicado.
- /// </summary>
- /// <param name="fichero">Fichero de configuración XML</param>
- override public void leer(string fichero)
- {
- try
- {
- base.leer(fichero);
- XmlDocument xml = LeerXml.AbrirFicheroParametros(fichero);
-
- try
- { this.Nombre = LeerXml.ObtenerValorCampo(xml, CEstructura.RutaNombre); }
- catch (Exception)
- { this.Nombre = string.Empty; };
-
- try
- {
- int numeroCampos = LeerXml.ObtenerNumeroNodosCampo(xml, CEstructura.RutaCampos);
- for (int indiceCampo = 0; indiceCampo < numeroCampos; indiceCampo++)
- {
- string nombre = string.Empty;
- try
- { nombre = LeerXml.ObtenerValorCampo(xml, CEstructura.RutaCampos, indiceCampo, CEstructura.NodoCamposCampoNombre); }
- catch (Exception)
- { continue; }
- this.ListaNombresCampos.Add(nombre);
-
- // Posicion inicial
- int posicion = 0;
- try
- { posicion = Int32.Parse(LeerXml.ObtenerValorCampo(xml, CEstructura.RutaCampos, indiceCampo, CEstructura.NodoCamposCampoPosicion));
- if (posicion < 0)
- {
- if (this.ListaNombresCampos.Count == 0)
- posicion = 0;
- else
- posicion = this.ListaPosicionInicialCampos[this.ListaPosicionInicialCampos.Count - 1] + this.ListaLongitudCampos[this.ListaLongitudCampos.Count - 1];
- }
-
- }
- catch (Exception)
- {
- if (this.ListaNombresCampos.Count == 0)
- posicion = 0;
- else
- posicion = this.ListaPosicionInicialCampos[this.ListaPosicionInicialCampos.Count - 1] + this.ListaLongitudCampos[this.ListaLongitudCampos.Count - 1];
- }
- this.ListaPosicionInicialCampos.Add(posicion);
-
- // Longitud
- int longitud = 0;
- try
- {
- longitud = Int32.Parse(LeerXml.ObtenerValorCampo(xml, CEstructura.RutaCampos, indiceCampo, CEstructura.NodoCamposCampoLongitud));
- if (longitud <= 0)
- longitud = 1;
- }
- catch (Exception)
- { longitud = 1; }
- this.ListaLongitudCampos.Add(longitud);
- }
- }
- catch (Exception)
- {
- this.ListaNombresCampos = new List<string>();
- this.ListaPosicionInicialCampos = new List<int>();
- this.ListaLongitudCampos = new List<int>();
- }
- }
- catch (Exception ex)
- {
- throw new ApplicationException(Constantes.ERROR_LECTURA_FICHERO_ESTRUCTURAS, ex);
- }
- }
-
- /// <summary>
- /// Escribe los parámetros al fichero XML indicado.
- /// </summary>
- /// <param name="fichero">Fichero de configuración XML</param>
- public override void escribir(string fichero)
- {
- try
- {
- base.escribir(fichero);
- XmlWriter xml = EscribirXml.AbrirFicheroParametros(fichero);
- EscribirXml.InicioElemento(xml, CEstructura.NodoRaiz);
- EscribirXml.EscribeNodo(xml, CEstructura.NodoNombre, Nombre);
- EscribirXml.InicioElemento(xml, CEstructura.NodoCampos);
- int i = 0;
- foreach (string nombre in ListaNombresCampos)
- {
- EscribirXml.InicioElemento(xml, CEstructura.NodoCamposCampo);
- EscribirXml.EscribeNodo(xml, CEstructura.NodoCamposCampoNombre, nombre);
- EscribirXml.EscribeNodo(xml, CEstructura.NodoCamposCampoPosicion, ListaPosicionInicialCampos[i].ToString());
- EscribirXml.EscribeNodo(xml, CEstructura.NodoCamposCampoLongitud, ListaLongitudCampos[i].ToString());
- EscribirXml.FinElemento(xml);
- i++;
- }
- EscribirXml.FinElemento(xml);
- EscribirXml.FinElemento(xml);
- EscribirXml.Flush(xml);
- EscribirXml.Close(xml);
- }
- catch (Exception ex)
- {
- throw new ApplicationException(Constantes.ERROR_ESCRITURA_FICHERO_ESTRUCTURAS, ex);
- }
- }
- }
- }